Setting WorldBorder From Console

Discussion in 'Plugin Development' started by technerder, Feb 20, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    technerder

    i am trying to make a worldborder plugin that will set the worldborder for a specified world using a command however when i do so i get this specific error in the console:

    Code:
    [14:36:07 WARN]: Unexpected exception while parsing console command "dms World"
    org.bukkit.command.CommandException: Unhandled exception executing command 'dms' in plugin WorldBorder v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[Server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[Server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[Server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchServerCommand(CraftServer.java:753) [Server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.DedicatedServer.aB(DedicatedServer.java:326) [Server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:290) [Server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [Server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [Server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [Server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    Caused by: java.lang.NoSuchMethodError: org.bukkit.World.getWorldBorder()Lorg/bukkit/WorldBorder;
            at technerder.kurion.worldborder.Main.onCommand(Main.java:27) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[Server.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            ... 8 more
    i get no errors in my ide. full code:

    Code:
    package technerder.kurion.worldborder;
    
    import org.bukkit.Bukkit;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
       
        public void onEnable()  {     }
    
        public void onDisable() {    }
       
       
        public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
           
            if (alias.equalsIgnoreCase("dms")) {
               
            if (args.length == 0) {
               
            } else  {
               
                World world = Bukkit.getServer().getWorld(args[0]);
               
                world.getWorldBorder().setSize(60,1);
           
            }
           
            }
           
           
            if (alias.equalsIgnoreCase("gmb")) {
               
            if (args.length == 0) {
               
            } else  {
               
                World world = Bukkit.getServer().getWorld(args[0]);
               
                world.getWorldBorder().setSize(1000,1);
           
            }
           
            }
           
            return false;
           
            }
       
    }
     
  2. Offline

    Zombie_Striker

    If your ondisable and onEnable method do nothing ,remove them/

    Heres the thing, alias actually does not account for aliases! Don't use command label (its actual name). Instead, use command.getName() when checking the command's name.

    Instead of using this empty if statement, invert the boolean and remove the else statement.

    The world can be null, null check before using it.

    Main problem: You're using a 1.7.9 server. No one should be using it anymore, since it is outdated and no longer supported. Not only that, but the worldboarder method (If I remember correctly) is a 1.8+ method. Update your server to 1.11.

    BTW: Why are you still using it? It came out over three years ago, and most plugins today no longer support it.
     
  3. Offline

    technerder

    i appreciate your response, i am using 1.8.8 server even though 1.11 is out because my player base enjoy 1.8 more than 1.11. i am confused on why the worldborder method is not working, h
     
  4. @technerder
    We can see from your stacktrace that you aren't running it on a 1.8.8 server. You're running it on a later version of 1.7 (I'd guess 1.7.4?).
     
  5. Offline

    Zombie_Striker

    @AlvinB
    Nope. 1.7.9

    @technerder
    As has been said on many threads before, there are tons of plugins out there for 1.11+ that revert the combat to pre 1.9. We are only pushing this as most plugin devs are planning on no longer supporting 1.8 and lower servers, as 1.9+ fixed a lot of bugs and is generally preferred by everyone else (Minigames hosts, developers, and anyone using those services). I am only recommending you update so you are not stuck in the past, not being able to be helped or having plugin support.
     
  6. Offline

    technerder

    @Zombie_Striker @AlvinB mind my stupidity, i was accidentally using a 1.7/1.8 compatible version of spigot when i meant to use 1.8, i have fixed this and now i am getting this error:

    Code:
    [15:58:54 WARN]: Unexpected exception while parsing console command "dms World"
    org.bukkit.command.CommandException: Unhandled exception executing command 'dms' in plugin WorldBorder v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[SG.jar:git-Bukkit-33d5de3]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[SG.jar:git-Bukkit-33d5de3]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:625) ~[SG.jar:git-Bukkit-33d5de3]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchServerCommand(CraftServer.java:611) [SG.jar:git-Bukkit-33d5de3]
            at net.minecraft.server.v1_8_R1.DedicatedServer.aM(DedicatedServer.java:320) [SG.jar:git-Bukkit-33d5de3]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:285) [SG.jar:git-Bukkit-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:609) [SG.jar:git-Bukkit-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:517) [SG.jar:git-Bukkit-33d5de3]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.NullPointerException
            at technerder.kurion.worldborder.Main.onCommand(Main.java:18) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[SG.jar:git-Bukkit-33d5de3]
            ... 8 more

    @Zombie_Striker i 100% understand that 1.11 is the latest update and the most stable version, i have tried changing versions from 1.8 to 1.11 and reverting the combat update effects, however as a experienced gamer, and minecraft pvper i feel the changes and so do my players. the logical thing to do is to update to 1.11 however i do have to take into considerations the gameplay, and my player base.
    ---------------on topic again------------
    i have changed my code to this now:

    Code:
    package technerder.kurion.worldborder;
    
    import org.bukkit.Bukkit;
    import org.bukkit.WorldBorder;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
       
        public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
           
            if (alias.equalsIgnoreCase("dms")) {
               
                    {
               
                        WorldBorder world = Bukkit.getWorld(args[0]).getWorldBorder();
               
                        world.setSize(60);
           
            }
           
        }
           
            if (args.length == 0) {
               
                sender.sendMessage("Please Specify the World!");
           
            if (alias.equalsIgnoreCase("gmb")) {
               
                    {
                       
                        WorldBorder world = Bukkit.getWorld(args[0]).getWorldBorder();
               
                        world.setSize(60);
           
            }
           
        }
           
    }
            return false;
           
        }
    
       
    }
     
  7. Offline

    timtower Administrator Administrator Moderator

    @technerder My bet:
    Bukkit.getWorld(args[0]) returns null.
    getWorldBorder returns null (if that is a thing)
    And please check the command.getName() and not the alias
     
  8. Offline

    Zombie_Striker

    If you don't mind me asking, can you explain what actually changed between those two versions, even with the pvp fix plugins? I was going to write a thread describing what happened between those two versions (Pvp-wise) and explain how to fix them.

    Your issue is that the world is null. Make sure the world is not null before doing anything with it.

    Also, you are no longer checking for the args length. Make sure the args exists before trying to get the first one.
     
  9. Offline

    technerder

    @Zombie_Striker
    note: most of these things have been mentioned by my player base, the rest are personally things i have noticed
    1- Block Hitting (This has been attmepted to be fixed using shields however doesent feel the same)
    2- Bow Firing (The Accuracy is only good if you are on the gorund when firing)
    3- Water Bucketing (Feels Different Also makes MLG'ing Harder)
    4- Lava Bucketing (feels different)
    5- Dual Wielding (makes certain things in duels harder, such as if you block-hit and try to lava bucket it is easier, essentially hitting and placing lava without needing to hotkey)
    6- Regeneration (No need to go into detail, its just broken, regeneration is too quick)
     
  10. Offline

    Zombie_Striker

    @technerder
    Just so these post stay slightly ontopic, have you fixed the problem?

    Now, off-topic again, I understand 1,2 and 6 , but 3,4,and 5 I do not.
    (Lumping these two together since they are mostly the same) What do you mean by this? Are you saying that placing waterbuckets is different, or that the effects caused by placing them down are different. Also, what is MLG'ing ?
    But Duel wielding is only a 1.9+ thing. What do you mean by this?
     
  11. Offline

    technerder

    @Zombie_Striker

    on topic: no the problem has still no gotten fixed. i am using 1.8 bukkit and when executing dms i get this error:
    Code:
    >dms
    [17:17:19 WARN]: Unexpected exception while parsing console command "dms"
    org.bukkit.command.CommandException: Unhandled exception executing command 'dms' in plugin WorldBorder v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[SG.jar:git-Bukkit-33d5de3]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[SG.jar:git-Bukkit-33d5de3]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:625) ~[SG.jar:git-Bukkit-33d5de3]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchServerCommand(CraftServer.java:611) [SG.jar:git-Bukkit-33d5de3]
            at net.minecraft.server.v1_8_R1.DedicatedServer.aM(DedicatedServer.java:320) [SG.jar:git-Bukkit-33d5de3]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:285) [SG.jar:git-Bukkit-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:609) [SG.jar:git-Bukkit-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:517) [SG.jar:git-Bukkit-33d5de3]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
            at technerder.kurion.worldborder.Main.onCommand(Main.java:18) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[SG.jar:git-Bukkit-33d5de3]
            ... 8 more
    >
    off topic:

    MLG'ing means jumping off of a high point and precisely before hitting the ground, placing a water bucket and preventing the fall damage.

    by lava bucketing i meant placing lava under a players feet so that they can not move as fast and also take fire tick damage. (a very well known/used tactic in minecraft pvp)

    by duel wielding i meant if someone has a sword in their main hand, and place a lava bucket in the off hand, the player could simply press the right and left mouse keys, and be able to place lava under a player and hit them at the same time.
     
  12. The problem is the null pointer of the worldname. Maybe try this:

    String worldname = Bukkit.getServer().getWorld(args[0]);
    int number = Integer.parseInt(args[1]);

    Bukkit.getWorld(worldname).getWorldBorder().setSize(number);
     
  13. Offline

    Zombie_Striker

    The indexes in the args are only equal to the amount of args given. If there are no args (such as what you have), then trying to get the first arg will throw this error because there are no args. What you need to do is check if the args length is greater than 0 first before getting the first arg.
     
  14. Maybe you can also use a instanceof that can also make some problems I think.
     
  15. Offline

    technerder

    @Zombie_Striker so something like this?

    Code:
    package technerder.kurion.worldborder;
    
    import org.bukkit.Bukkit;
    import org.bukkit.WorldBorder;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
       
        public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
           
            if (args.length < 3) {    
           
            if (alias.equalsIgnoreCase("dms")) {
               
                    {
               
                        WorldBorder world = Bukkit.getWorld(args[0]).getWorldBorder();
               
                        world.setSize(60);
           
            }
           
        }
           
            if (args.length == 0) {
               
                sender.sendMessage("Please Specify the World!");
               
            }
           
            if (alias.equalsIgnoreCase("gmb")) {
               
                    {
                       
                        WorldBorder world = Bukkit.getWorld(args[0]).getWorldBorder();
               
                        world.setSize(60);
           
            }
           
        }
           
           
        }
            return false;
        }
    }
     
  16. Offline

    Zombie_Striker

    @technerder
    Remember to encapsulate properly. Your first arg check encompasses the other command as-well.

    Also, you are making sure the length is less than 3. You not checking if it is greater than 0.
     
Thread Status:
Not open for further replies.

Share This Page