need help with an command

Discussion in 'BungeeCord Plugin Development' started by _DutchGamernl_, Oct 12, 2017.

  1. hello
    i am making now an /helpopmsg <player> <message>. comnmand
    bu i tested it and the command works not good...
    here's the build of the class:
    Code (Text):
    public class helpopmsg extends Command{

        public helpopmsg() {
            super("helpopmsg");
        }

        @Override
        public void execute(CommandSender sender, String[] args) {
            Configuration conf = null;
            try {
                conf = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(Main.getInstance().getDataFolder(), "config.yml"));
            } catch (IOException e) {
                e.printStackTrace();
           
            }
            ProxiedPlayer pp = (ProxiedPlayer) sender;
            if (!pp.hasPermission("sc.helpop.msg") && !pp.hasPermission("sc.*")){
                pp.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpop") + conf.getString("NoPermHelpopMSG"))));
                return;
            }
            if (args.length == 0){
                pp.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpop") + "&cUsage /helpopmsg <player> <message>")));
                return;
            }
            if (args.length == 1) {
                ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[0]);
                if (target == null) {
                    pp.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpop") + "&cThat's not a player! or is that player offline?")));
                    return;
                }
                else if (args.length > 1) {
                    String message = "";
                    for(int i = 0; i < args.length; i++) {
                        message = message + args[i] + " ";
                    }
                    if (target.hasPermission("sc.helpop.use")){
                        target.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpopMSGplayer").replace("%msg%", message))));
                    }
                    pp.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpopMSGstaff").replace("%msg%", message).replace("%player%", target.getDisplayName()))));
                    return;
                }
            }
        }
    }
    and the worst part is that i get NO errors in console. i have the command registered in the plugin.yml and in the main class
     
  2. ok i changed the build a little and i got now an error
    Code (Text):
    10:15:06 [WARNING] Error in dispatching command
    java.lang.NullPointerException
        at bsc.helpopmsg.execute(helpopmsg.java:53)
        at net.md_5.bungee.api.plugin.PluginManager.dispatchCommand(PluginManager.java:169)
        at net.md_5.bungee.api.plugin.PluginManager.dispatchCommand(PluginManager.java:116)
        at net.md_5.bungee.connection.UpstreamBridge.handle(UpstreamBridge.java:140)
        at net.md_5.bungee.protocol.packet.Chat.handle(Chat.java:50)
        at net.md_5.bungee.netty.HandlerBoss.channelRead(HandlerBoss.java:103)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
        at java.lang.Thread.run(Unknown Source)
    and this is line 53:
    Code (Text):
    target.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpopMSGplayer").replace("%msg%", message))));
    and this is my changed build:
    Code (Text):
    public class helpopmsg extends Command{

        public helpopmsg() {
            super("helpopmsg");
        }

        @Override
        public void execute(CommandSender sender, String[] args) {
            Configuration conf = null;
            try {
                conf = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(Main.getInstance().getDataFolder(), "config.yml"));
            } catch (IOException e) {
                e.printStackTrace();
           
            }
            ProxiedPlayer pp = (ProxiedPlayer) sender;
            if (!pp.hasPermission("sc.helpop.msg") && !pp.hasPermission("sc.*")){
                pp.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpop") + conf.getString("NoPermHelpopMSG"))));
                return;
            }
            if (args.length == 0){
                pp.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpop") + "&cUsage /helpopmsg <player> <message>")));
                return;
            }
            if (args.length == 1) {
                ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[0]);
                if (target == null) {
                    pp.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpop") + "&cThat's not a player! or is that player offline?")));
                    return;
                }
            }
            if (args.length > 1) {
                ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[0]);
                String message = "";
                for(int i = 0; i < args.length; i++) {
                    message = message + args[i] + " ";
                }
                target.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpopMSGplayer").replace("%msg%", message))));
                pp.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpopMSGstaff").replace("%msg%", message).replace("%player%", target.getDisplayName()))));
                return;
            }
        }
    }
     
  3. i making an bungee plugin (not bukkit/spigot) and i tried implement that but it wont let me do that
     
  4. I was in the wrong forum and I didn't know *facepalm*
     
  5. no problem at all
     
  6. Your code make no sense.
    Code (Text):
    if (args.length == 1) { //Only if is equal to 1
    ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[0]);
    if (target == null) {
    pp.sendMessage(/*the message*/);
    return;
    } else if (args.length > 1) {} //Because it's equal just to 1, this part will never be visible.
    }
     
  7. so i have it now changed again with your code:
    Code (Text):
            if (args.length == 1) {
                ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[0]);
                if (target == null) {
                    pp.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpop") + "&cThat's not a player! or is that player offline?")));
                    return;
                } else if (args.length > 1) {
                    String message = "";
                    for(int i = 0; i < args.length; i++) {
                        message = message + args[i] + " ";
                    }
                    target.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpopMSGplayer").replace("%msg%", message))));
                    pp.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', conf.getString("PrefixHelpopMSGstaff").replace("%msg%", message).replace("%player%", target.getDisplayName()))));
                    return;
                }
    and i don't know what i'm doing wrong
     
  8. That code it's your code, and I just changed where the bracets are...
    Code (Text):
    if (args.length > 1) {
    ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[0]);
    if (target == null) {
    pp.sendMessage(/*message*/);
    return;
    } else {
    This is what or how you should do.
     
  9. ok it is working now but i want that you can use [TAB] to get the players name or isn't that possible in bungee?
     
    • Agree Agree x 1

Share This Page