Printing multiple arguments

Status
This thread has been locked.

Charlie

Developer & Designer
Supreme
Feedback score
1
Posts
950
Reactions
635
Resources
0
No no I didn't loop through the players at all. I just forgot to remove it. The broadcast methods sends the message to ALL players online with the permission. I realized that it was looping through the players still when he tagged me.
I know what the broadcast method does but what I was asking is if you basically forgot to remove the loop, in which you just answered above. And in that code he tagged you in, you clearly did loop through all online players...
 

rchy

Premium
Feedback score
1
Posts
716
Reactions
258
Resources
0
Still not working
Why are you looping through all online players & broadcasting while doing so...also what's line 29


EDIT: The looping and broadcasting is my fault remove the for loop around Bukkit.broadcast
 

rchy

Premium
Feedback score
1
Posts
716
Reactions
258
Resources
0
You sure the error is corresponding with the updated code...?
Yep just tried:

org.bukkit.command.CommandException: Unhandled exception executing command 'report' in plugin MCKitPvPReport v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[minecraft_server.jar:git-Bukkit-2642f9b]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[minecraft_server.jar:git-Bukkit-2642f9b]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:619) ~[minecraft_server.jar:git-Bukkit-2642f9b]
at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1101) [minecraft_server.jar:git-Bukkit-2642f9b]
at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:961) [minecraft_server.jar:git-Bukkit-2642f9b]
at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [minecraft_server.jar:git-Bukkit-2642f9b]
at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [minecraft_server.jar:git-Bukkit-2642f9b]
at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [minecraft_server.jar:git-Bukkit-2642f9b]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_65]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_65]
at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [minecraft_server.jar:git-Bukkit-2642f9b]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:672) [minecraft_server.jar:git-Bukkit-2642f9b]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [minecraft_server.jar:git-Bukkit-2642f9b]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:628) [minecraft_server.jar:git-Bukkit-2642f9b]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:536) [minecraft_server.jar:git-Bukkit-2642f9b]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_65]
Caused by: java.lang.NullPointerException
at me.rchy.reports.Reports.onCommand(Reports.java:27) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[minecraft_server.jar:git-Bukkit-2642f9b]
... 15 more
 

_Ug

Premium
Feedback score
1
Posts
261
Reactions
184
Resources
0
This is taking way too long. Just going to chime in real quick before I go to bed with some issues with your code:

- Player target = Bukkit.getPlayer(args[1]); As with any index the values start at 0. You should change this to args[0] to get the name of the player if I understand the hoped for syntax.

- For the above code you should surround it with a catch block looking for NullPointerException which is, by a quick look at the error, what was called when you put the wrong name in. In the catch you can just tell that he/she put a invalid name in.

Good luck, and if you have more issues, feel free to PM me. Again, this was just from a quick glance.
 

rchy

Premium
Feedback score
1
Posts
716
Reactions
258
Resources
0
Code:
package me.rchy.reports;


import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class Reports extends JavaPlugin {
 
    @SuppressWarnings({ "deprecation" })
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
     
        if(label.equalsIgnoreCase("report")) {
            if(!(sender instanceof Player)) {
                return false;
            }
         
            Player p = (Player) sender;
         
            if(args.length < 2) {
                p.sendMessage("§6MCKitPvP » §7Please specify a player & a reason.");
            }else if(args.length == 2) {
                Player target = Bukkit.getPlayer(args[0]);
               
                StringBuilder str = new StringBuilder();
                for (int i = 1; i < args.length; i++) {
                        str.append(args[i] + " ");
                }
                String reason = str.toString();
             
               
                if(target != null){
                    Bukkit.broadcast("§6MCKitPvP » §7  " + p.getName() + " has reported " + target.getName() + " for " + reason + "!", "mckitpvp.staff");
                    p.sendMessage("§6MCKitPvP » §7You have reported " + target.getName() + "!");
                } else {
                    p.sendMessage("§6MCKitPvP » §7Please specify a player & a reason.");
                }
             
            }
        }
        return false;
    }
}

Any ideas why it doesn't broadcast to online people with the perm?
 

Tyler

Developer
Supreme
Feedback score
14
Posts
2,589
Reactions
2,238
Resources
0
Code:
package me.rchy.reports;


import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class Reports extends JavaPlugin {

    @SuppressWarnings({ "deprecation" })
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
   
        if(label.equalsIgnoreCase("report")) {
            if(!(sender instanceof Player)) {
                return false;
            }
       
            Player p = (Player) sender;
       
            if(args.length < 2) {
                p.sendMessage("§6MCKitPvP » §7Please specify a player & a reason.");
            }else if(args.length == 2) {
                Player target = Bukkit.getPlayer(args[0]);
             
                StringBuilder str = new StringBuilder();
                for (int i = 1; i < args.length; i++) {
                        str.append(args[i] + " ");
                }
                String reason = str.toString();
           
             
                if(target != null){
                    Bukkit.broadcast("§6MCKitPvP » §7  " + p.getName() + " has reported " + target.getName() + " for " + reason + "!", "mckitpvp.staff");
                    p.sendMessage("§6MCKitPvP » §7You have reported " + target.getName() + "!");
                } else {
                    p.sendMessage("§6MCKitPvP » §7Please specify a player & a reason.");
                }
           
            }
        }
        return false;
    }
}

Any ideas why it doesn't broadcast to online people with the perm?
Any errors? Does it send the message to the player? Also did you add a check for the perm? I didn't see one when I skimmed the code.[DOUBLEPOST=1452586343,1452586233][/DOUBLEPOST]Oh I see where you checked for the perm. I've never done it like that I've just used p.hasPermission()
 

rchy

Premium
Feedback score
1
Posts
716
Reactions
258
Resources
0
Any errors? Does it send the message to the player? Also did you add a check for the perm? I didn't see one when I skimmed the code.[DOUBLEPOST=1452586343,1452586233][/DOUBLEPOST]Oh I see where you checked for the perm. I've never done it like that I've just used p.hasPermission()

fixed now like this:

Code:
package me.rchy.reports;


import java.util.ArrayList;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class Reports extends JavaPlugin {
 
    @SuppressWarnings({ "deprecation" })
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
     
        if(label.equalsIgnoreCase("report")) {
            if(!(sender instanceof Player)) {
                return false;
            }
         
            Player p = (Player) sender;
         
            if(args.length < 2) {
                p.sendMessage("§6MCKitPvP » §7Please specify a player & a reason.");
            }else if(args.length == 2) {
                Player target = Bukkit.getPlayer(args[0]);
               
                StringBuilder str = new StringBuilder();
                for (int i = 1; i < args.length; i++) {
                        str.append(args[i] + " ");
                }
                String reason = str.toString();
             
               
                if(target != null){
                    for(Player player : Bukkit.getOnlinePlayers()){
                        if(player.hasPermission("mckitpvp.staff")){
                            List<String> staff = new ArrayList<String>();
                            staff.add(player.getName());
                           
                            for(String name : staff){
                                player.sendMessage("§6MCKitPvP » §7" + p.getName() + " has reported " + target.getName() + " for " + reason + "!");
                               
                            }
                        }
                    }
                    p.sendMessage("§6MCKitPvP » §7You have reported " + target.getName() + "!");
                } else {
                    p.sendMessage("§6MCKitPvP » §7Please specify a player & a reason.");
                }
             
            }
        }
        return false;
    }
}
[DOUBLEPOST=1452620776][/DOUBLEPOST]
fixed now like this:

Code:
package me.rchy.reports;


import java.util.ArrayList;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class Reports extends JavaPlugin {

    @SuppressWarnings({ "deprecation" })
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
        if(label.equalsIgnoreCase("report")) {
            if(!(sender instanceof Player)) {
                return false;
            }
        
            Player p = (Player) sender;
        
            if(args.length < 2) {
                p.sendMessage("§6MCKitPvP » §7Please specify a player & a reason.");
            }else if(args.length == 2) {
                Player target = Bukkit.getPlayer(args[0]);
              
                StringBuilder str = new StringBuilder();
                for (int i = 1; i < args.length; i++) {
                        str.append(args[i] + " ");
                }
                String reason = str.toString();
            
              
                if(target != null){
                    for(Player player : Bukkit.getOnlinePlayers()){
                        if(player.hasPermission("mckitpvp.staff")){
                            List<String> staff = new ArrayList<String>();
                            staff.add(player.getName());
                          
                            for(String name : staff){
                                player.sendMessage("§6MCKitPvP » §7" + p.getName() + " has reported " + target.getName() + " for " + reason + "!");
                              
                            }
                        }
                    }
                    p.sendMessage("§6MCKitPvP » §7You have reported " + target.getName() + "!");
                } else {
                    p.sendMessage("§6MCKitPvP » §7Please specify a player & a reason.");
                }
            
            }
        }
        return false;
    }
}
Forget this, now it doesn't do anything if there's more than 1 word for the reason.
 

TheNewTao

Java Developer
Premium
Feedback score
0
Posts
654
Reactions
274
Resources
0
fixed now like this:

Code:
package me.rchy.reports;


import java.util.ArrayList;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class Reports extends JavaPlugin {

    @SuppressWarnings({ "deprecation" })
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
        if(label.equalsIgnoreCase("report")) {
            if(!(sender instanceof Player)) {
                return false;
            }
        
            Player p = (Player) sender;
        
            if(args.length < 2) {
                p.sendMessage("§6MCKitPvP » §7Please specify a player & a reason.");
            }else if(args.length == 2) {
                Player target = Bukkit.getPlayer(args[0]);
              
                StringBuilder str = new StringBuilder();
                for (int i = 1; i < args.length; i++) {
                        str.append(args[i] + " ");
                }
                String reason = str.toString();
            
              
                if(target != null){
                    for(Player player : Bukkit.getOnlinePlayers()){
                        if(player.hasPermission("mckitpvp.staff")){
                            List<String> staff = new ArrayList<String>();
                            staff.add(player.getName());
                          
                            for(String name : staff){
                                player.sendMessage("§6MCKitPvP » §7" + p.getName() + " has reported " + target.getName() + " for " + reason + "!");
                              
                            }
                        }
                    }
                    p.sendMessage("§6MCKitPvP » §7You have reported " + target.getName() + "!");
                } else {
                    p.sendMessage("§6MCKitPvP » §7Please specify a player & a reason.");
                }
            
            }
        }
        return false;
    }
}
[DOUBLEPOST=1452620776][/DOUBLEPOST]
Forget this, now it doesn't do anything if there's more than 1 word for the reason.
This looks like a pretty easy plugin to debug with a few System.out.println(), checking which parts of the code work and which parts don't, adjusting the code accordingly to the issue. One of the most important skills of a developer is learning how to debug their own plugins.
 
Status
This thread has been locked.
Top