Solved Needing help with a ItemTP Plugin. Not what you think!

Discussion in 'Plugin Development' started by wiredbrother, Sep 1, 2016.

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

    ZP18

    Give me an exact example of the command you are using, if your item name is not a number it will throw errors. If it is a number it should work.

    EDIT: I'm working on a plugin very similar to this one when I finish I'll give you a copy to check out


    Sent from my iPhone using Tapatalk
     
  2. Offline

    Zombie_Striker

    @wiredbrother
    Your issue is that you provided the wrong argument to your command. It should be "/itemTP <A number>". If you want something that is not a number, do not parse the arg and change "num" to a string.
     
  3. Offline

    wiredbrother

    @ZP18
    /itemtp dirt
    as one of the locations in the config is dirt. Oh also i gave u a huggle.

    @Zombie_Striker
    As I am very new to plugins what would be the exact fix for this? As in replace this with this. Or you can just let me learn either way! XD
     
  4. Offline

    ZP18

    You are trying to convert a string to a number. Change your num field to a String and change the name(if you want). You can't covert "dirt" to a number which is why you're getting an error


    Sent from my iPhone using Tapatalk
     
  5. Offline

    wiredbrother

    @ZP18
    So like this?

    Code:
    //Tp to item!
           if (cmd.getName().equalsIgnoreCase("itemtp") && sender instanceof Player) {
                 
             if(args.length==1) {
             
      if (config.contains(args[0])) {
                
    HERE-----> String find = args[0];
         int x = getConfig().getInt(sender.getName() + "." + find + ".x");
         int y = getConfig().getInt(sender.getName() + "." + find + ".y");
         int z = getConfig().getInt(sender.getName() + "." + find + ".z");
         
         String worldname = player.getWorld().getName();
                 
                 Object licks = worldname;
         
         Location hi = new Location((World) licks,x,y,z);
         
         if(sender instanceof Player){
           Player p = (Player)sender;
           p.teleport(hi);
           p.sendMessage(ChatColor.GOLD + "You have been teleported to the item!");
           
         } else player.sendMessage(ChatColor.RED + "You are a console! You do not have a home!");
         
               } else player.sendMessage(ChatColor.RED + "Item Not Found! Make sure to use capital if you used caps!");
               
               
             } else player.sendMessage(ChatColor.RED + "Invalid Entry! Need More Then That!");
               
               
            return true;
           }
     
  6. Offline

    ZP18

    That should work. If not you have to fix up another part of your code


    Sent from my iPhone using Tapatalk
     
  7. Offline

    wiredbrother

    @ZP18 MAN MY CODE IS SCREWY! We got another one.

    Code:
    [18:32:18] [Server thread/INFO]: Starting minecraft server version 1.8.8
    [18:32:18] [Server thread/INFO]: Loading properties
    [18:32:18] [Server thread/INFO]: Default game type: SURVIVAL
    [18:32:18] [Server thread/INFO]: Generating keypair
    [18:32:19] [Server thread/INFO]: Starting Minecraft server on *:25565
    [18:32:19] [Server thread/INFO]: Using default channel type
    [18:32:19] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-e1ebe52 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT)
    [18:32:20] [Server thread/INFO]: [ItemTP] Loading ItemTP v1.2
    [18:32:20] [Server thread/INFO]: Preparing level "world"
    [18:32:20] [Server thread/INFO]: Preparing start region for level 0 (Seed: 3304873887225295798)
    [18:32:21] [Server thread/INFO]: Preparing spawn area: 12%
    [18:32:22] [Server thread/INFO]: Preparing spawn area: 78%
    [18:32:22] [Server thread/INFO]: Preparing start region for level 1 (Seed: 3304873887225295798)
    [18:32:23] [Server thread/INFO]: Preparing spawn area: 73%
    [18:32:24] [Server thread/INFO]: Preparing start region for level 2 (Seed: 3304873887225295798)
    [18:32:24] [Server thread/INFO]: [ItemTP] Enabling ItemTP v1.2
    [18:32:24] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [18:32:24] [Server thread/INFO]: Done (4.377s)! For help, type "help" or "?"
    [18:32:50] [User Authenticator #1/INFO]: UUID of player cyborgtwins is blank
    [18:32:50] [Server thread/INFO]: cyborgtwins[/127.0.0.1:60042] logged in with entity id 93 at ([world]-71.96409366885925, 71.0, 77.30000001192093)
    [18:32:57] [Server thread/INFO]: cyborgtwins issued server command: /itemlist
    [18:33:08] [Server thread/INFO]: cyborgtwins issued server command: /itemadd Stone
    [18:33:15] [Server thread/INFO]: cyborgtwins issued server command: /itemlist
    [18:33:25] [Server thread/INFO]: cyborgtwins issued server command: /itemtp Stone
    [18:33:25] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'itemtp' in plugin ItemTP v1.2
       at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_101]
       at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_101]
       at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at java.lang.Thread.run(Unknown Source) [?:1.8.0_101]
    Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to org.bukkit.World
       at me.cyborgtwins.ItemTP.onCommand(ItemTP.java:111) ~[?:?]
       at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       ... 15 more
    line 46 is this.

    Code:
    //Joining items
         if (cmd.getName().equalsIgnoreCase("itemadd") && sender instanceof Player) {
             
           if (args.length >= 1) {
           
             String list = "";
             
               for (String arg : args) {
                list = list + arg;
              }
               
               String locks = "";
               
               int x = player.getLocation().getBlockX();
               int y = player.getLocation().getBlockY();
               int z = player.getLocation().getBlockZ();
    46      String worldname = player.getWorld().getName();
                 
               locks = locks +" x" + x + " y" + y + " z" + z + " " + worldname + " ";
               
                //Handling arguments
                if (!config.contains(list)) {
                   config.set(list, locks);
                   player.sendMessage(ChatColor.GREEN + "Item Has Now Been Added!");
                   saveConfig();
                } else player.sendMessage(ChatColor.RED + "This Item Has Already Been Added!");
                 
           } else player.sendMessage(ChatColor.RED + "Please Enter the name of the item after /additem");
           
           return true;
           
         }
     
  8. Offline

    Zombie_Striker

    @wiredbrother
    Line 46 is not your issue.
    What is line 111? On that line, you are trying to turn a String into a world.

    To convert a worldname to a world, use Bukkit.getWorld(String);
     
  9. Offline

    wiredbrother

    @Zombie_Striker

    Would this work?

    Code:
    //Tp to item!
           if (cmd.getName().equalsIgnoreCase("itemtp") && sender instanceof Player) {
                 
             if(args.length==1) {
             
      if (config.contains(args[0])) {
                 
         String find = args[0];
         int x = getConfig().getInt(sender.getName() + "." + find + ".x");
         int y = getConfig().getInt(sender.getName() + "." + find + ".y");
         int z = getConfig().getInt(sender.getName() + "." + find + ".z");
         
    HERE------> World worldname = Bukkit.getWorld(getName());
                 
                 Object licks = worldname;
         
         Location hi = new Location((World) licks,x,y,z);
         
         if(sender instanceof Player){
           Player p = (Player)sender;
           p.teleport(hi);
           p.sendMessage(ChatColor.GOLD + "You have been teleported to the item!");
           
         } else player.sendMessage(ChatColor.RED + "You are a console! You do not have a home!");
         
               } else player.sendMessage(ChatColor.RED + "Item Not Found! Make sure to use capital if you used caps!");
               
               
             } else player.sendMessage(ChatColor.RED + "Invalid Entry! Need More Then That!");
               
               
            return true;
           }
     
  10. Offline

    Zombie_Striker

    @wiredbrother
    As long as "getName" is actually a method that returns a world name, yes, this should work.
     
  11. Offline

    wiredbrother

    @Zombie_Striker i shall try this and really really hope this work's! XD

    @Zombie_Striker Nope Another one bites the dust.

    Code:
    [19:52:01] [Server thread/INFO]: Starting minecraft server version 1.8.8
    [19:52:01] [Server thread/INFO]: Loading properties
    [19:52:01] [Server thread/INFO]: Default game type: SURVIVAL
    [19:52:01] [Server thread/INFO]: Generating keypair
    [19:52:01] [Server thread/INFO]: Starting Minecraft server on *:25565
    [19:52:01] [Server thread/INFO]: Using default channel type
    [19:52:02] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-e1ebe52 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT)
    [19:52:02] [Server thread/INFO]: [ItemTP] Loading ItemTP v1.2
    [19:52:02] [Server thread/INFO]: Preparing level "world"
    [19:52:03] [Server thread/INFO]: Preparing start region for level 0 (Seed: 3304873887225295798)
    [19:52:04] [Server thread/INFO]: Preparing spawn area: 16%
    [19:52:05] [Server thread/INFO]: Preparing spawn area: 90%
    [19:52:05] [Server thread/INFO]: Preparing start region for level 1 (Seed: 3304873887225295798)
    [19:52:06] [Server thread/INFO]: Preparing spawn area: 73%
    [19:52:06] [Server thread/INFO]: Preparing start region for level 2 (Seed: 3304873887225295798)
    [19:52:07] [Server thread/INFO]: [ItemTP] Enabling ItemTP v1.2
    [19:52:07] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [19:52:07] [Server thread/INFO]: Done (4.253s)! For help, type "help" or "?"
    [19:52:23] [User Authenticator #1/INFO]: UUID of player cyborgtwins is f8c39491-a323-4708-8b6b-cae0cb8ed058
    [19:52:23] [Server thread/INFO]: cyborgtwins[/127.0.0.1:49545] logged in with entity id 88 at ([world]-71.92789108900784, 72.0, 60.26929749575511)
    [19:52:26] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 2084ms behind, skipping 41 tick(s)
    [19:52:36] [Server thread/INFO]: cyborgtwins issued server command: /itemlist
    [19:52:42] [Server thread/INFO]: cyborgtwins issued server command: /itemtp Stone
    [19:52:42] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'itemtp' in plugin ItemTP v1.2
       at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_101]
       at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_101]
       at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at java.lang.Thread.run(Unknown Source) [?:1.8.0_101]
    Caused by: java.lang.NullPointerException
       at org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer.teleport(CraftPlayer.java:460) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity.teleport(CraftEntity.java:226) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at me.cyborgtwins.ItemTP.onCommand(ItemTP.java:115) ~[?:?]
       at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 8, 2016
  12. Offline

    Zombie_Striker

    Something is null on line 115. If the code from above is the current version, then this should be the line with the null value.
    What is licks? Whatever it is, replace it with "worldname"
     
  13. Offline

    wiredbrother

    @Zombie_Striker
    Well here is the whole code. It already has a lot of worldname. But I shall do it and hope it works.
    (current)
    Code:
    package me.cyborgtwins;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class ItemTP extends JavaPlugin {
      
       @Override
       public void onEnable() {
        
       }
      
       @Override
       public void onDisable() {
        
       }
      
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        
         Player player = (Player) sender;
        
         FileConfiguration config = this.getConfig();
        
         //Joining items
         if (cmd.getName().equalsIgnoreCase("itemadd") && sender instanceof Player) {
            
           if (args.length >= 1) {
          
             String list = "";
            
               for (String arg : args) {
                list = list + arg;
              }
              
               String locks = "";
              
               int x = player.getLocation().getBlockX();
               int y = player.getLocation().getBlockY();
               int z = player.getLocation().getBlockZ();
               String worldname = player.getWorld().getName();
                
               locks = locks +" x" + x + " y" + y + " z" + z + " " + worldname + " ";
              
                //Handling arguments
                if (!config.contains(list)) {
                   config.set(list, locks);
                   player.sendMessage(ChatColor.GREEN + "Item Has Now Been Added!");
                   saveConfig();
                } else player.sendMessage(ChatColor.RED + "This Item Has Already Been Added!");
                
           } else player.sendMessage(ChatColor.RED + "Please Enter the name of the item after /additem");
          
           return true;
          
         }  
          
           //Deleting items
           if (cmd.getName().equalsIgnoreCase("itemdelete") && sender instanceof Player) {
            
             if (args.length == 1) {
              
               if (config.contains(args[0])) {
                
                 config.set(args[0], null);
                 saveConfig();
                 player.sendMessage(ChatColor.GREEN + "Item deleted!");
                
               } else player.sendMessage(ChatColor.RED + "Item Not Found! Make sure to use capital if you used caps!");
              
             } else player.sendMessage(ChatColor.RED + "Invalid Entry! Need More Then That!");
            
             return true;
           }
          
           //Viewing Items
           if (cmd.getName().equalsIgnoreCase("itemlist") && sender instanceof Player) {
                
               //Loop for stuff? you will never know.
               for (String key : config.getKeys(false)) {
                 player.sendMessage(ChatColor.YELLOW + key + ": " + config.getString(key));
               }
                 if (config.getKeys(false).isEmpty()) {
                   player.sendMessage(ChatColor.RED + "No items are here!");
                 }
              
               return true;
             }
          
           //Tp to item!
           if (cmd.getName().equalsIgnoreCase("itemtp") && sender instanceof Player) {
                
             if(args.length==1) {
            
      if (config.contains(args[0])) {
                
         String find = args[0];
         int x = getConfig().getInt(sender.getName() + "." + find + ".x");
         int y = getConfig().getInt(sender.getName() + "." + find + ".y");
         int z = getConfig().getInt(sender.getName() + "." + find + ".z");
        
         World worldname = Bukkit.getWorld(getName());
        
         Location hi = new Location((World) worldname,x,y,z);
        
         if(sender instanceof Player){
           player.teleport(hi);
           player.sendMessage(ChatColor.GOLD + "You have been teleported to the item!");
          
         } else player.sendMessage(ChatColor.RED + "You are a console! You do not have a home!");
        
               } else player.sendMessage(ChatColor.RED + "Item Not Found! Make sure to use capital if you used caps!");
              
              
             } else player.sendMessage(ChatColor.RED + "Invalid Entry! Need More Then That!");
              
              
            return true;
           }
          
          
           //The guy who made this
        if (cmd.getName().equalsIgnoreCase("iteminfo") && sender instanceof Player) {
            
             player.sendMessage(ChatColor.GREEN + "Made by your master and ruler CYBORGTWINS!");
              
        } else player.sendMessage(ChatColor.RED + "Invalid permissions!");
        
        
         return true;
        
       }
    
    }
    Nope spits the same error as last time.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 8, 2016
  14. Offline

    Zombie_Striker

    This is most likely your problem then. You do not have a method called "getName()". Replace this with the name of your world. If the name is from the config, load it out of the config and replace "getName()" with that string instance.
     
  15. Offline

    wiredbrother

    @Zombie_Striker So would this be it since the only world that players need to go to is in the vanila world.
    World worldname = Bukkit.getWorld("world");
    Maybe? If not How would I load the correct world from the config. That kinda confuses me. Also thank you for sticking with me this far most people would have given up!
     
  16. Offline

    Zombie_Striker

    @wiredbrother
    If you have the world stored like those other variables, it should look like
    Code:
      ....getWorld(getConfig().getInt(sender.getName() + "." + find + ".world"));
    
    Edit: Looking at your code, It seems you are using the wrong format for saving objects.
    This is the only string that seems to be saved to the config. In this, you are not saving multiple variables, but instead one variable that has all the data in it. Since this will be harder to decode, I would recommend changing this format to match what you are trying to retrieve. In other words, replace this with
    Code:
    getConfig().set(sender.getName() + "." + find + ".x",x);
    getConfig().set(sender.getName() + "." + find + ".y",y);
    getConfig().set(sender.getName() + "." + find + ".z",z);
    getConfig().set(sender.getName() + "." + find + ".world",worldname);
     
  17. Offline

    wiredbrother

    @Zombie_Striker So just to make sure XD
    Is this it?
    also sorry for how hard this is for me still new.

    Code:
    //Tp to item!
           if (cmd.getName().equalsIgnoreCase("itemtp") && sender instanceof Player) {
                 
             if(args.length==1) {
             
      if (config.contains(args[0])) {
                 
         String find = args[0];
         int x = getConfig().getInt(sender.getName() + "." + find + ".x");
         int y = getConfig().getInt(sender.getName() + "." + find + ".y");
         int z = getConfig().getInt(sender.getName() + "." + find + ".z");
         int worldname = getConfig().getInt(sender.getName() + "." + find + ".world");
         
         Location hi = new Location((World) worldname,x,y,z);
         
         if(sender instanceof Player){
           player.teleport(hi);
           player.sendMessage(ChatColor.GOLD + "You have been teleported to the item!");
           
         } else player.sendMessage(ChatColor.RED + "You are a console! You do not have a home!");
         
               } else player.sendMessage(ChatColor.RED + "Item Not Found! Make sure to use capital if you used caps!");
               
               
             } else player.sendMessage(ChatColor.RED + "Invalid Entry! Need More Then That!");
               
               
            return true;
           }
     
  18. Offline

    ZP18

    Why are you getting world as an integer? You should be getting and setting it as a string


    Sent from my iPhone using Tapatalk
     
  19. Offline

    wiredbrother

    @ZP18 OHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!!!!!!!!!!!!!!!!!
    Ha lol its late
     
  20. Offline

    Zombie_Striker

    @wiredbrother
    Replace "int" with "String" for worldname, since worldname is a String and not a number.

    Also, make sure you use Bukkit.getWorld(worldname) to convert the String to a world. The location should look like.
    Code:
    Location hi = new Location(Bukkit.getWorld(worldname),x,y,z);
     
  21. Offline

    wiredbrother

    @Zombie_Striker Hey man i am very sorry but i am now confused would you be so kind as to just put the code in the script please? That would help me so much!
     
  22. Offline

    Zombie_Striker

    @wiredbrother
    Replace the original line "hi" with the line I provided. Just copy and paste it right after you create the "worldname" variable, and remove the line that comes after it. (It should be the one that now is red/underlined)
     
  23. Offline

    wiredbrother

    @Zombie_Striker
    So if i am understanding you correctly the correct code would be this? Im sorry if i mess this up. :)

    Code:
    package me.cyborgtwins;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class ItemTP extends JavaPlugin {
       
       @Override
       public void onEnable() {
         
       }
       
       @Override
       public void onDisable() {
         
       }
       
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         
         Player player = (Player) sender;
         
         FileConfiguration config = this.getConfig();
         
         //Joining items
         if (cmd.getName().equalsIgnoreCase("itemadd") && sender instanceof Player) {
             
           if (args.length >= 1) {
           
             String list = "";
             
               for (String arg : args) {
                list = list + arg;
              }
               
               String locks = "";
               
               int x = player.getLocation().getBlockX();
               int y = player.getLocation().getBlockY();
               int z = player.getLocation().getBlockZ();
               World worldname = Bukkit.getWorld(getName());
               
               getConfig().set(sender.getName() + "." + locks + ".x",x);
               getConfig().set(sender.getName() + "." + locks + ".y",y);
               getConfig().set(sender.getName() + "." + locks + ".z",z);
               getConfig().set(sender.getName() + "." + locks + ".world",worldname);
               
               locks = locks +" x" + x + " y" + y + " z" + z + " " + worldname + " ";
               
                //Handling arguments
                if (!config.contains(list)) {
                   config.set(list, locks);
                   player.sendMessage(ChatColor.GREEN + "Item Has Now Been Added!");
                   saveConfig();
                } else player.sendMessage(ChatColor.RED + "This Item Has Already Been Added!");
                 
           } else player.sendMessage(ChatColor.RED + "Please Enter the name of the item after /additem");
           
           return true;
           
         }   
           
           //Deleting items
           if (cmd.getName().equalsIgnoreCase("itemdelete") && sender instanceof Player) {
             
             if (args.length == 1) {
               
               if (config.contains(args[0])) {
                 
                 config.set(args[0], null);
                 saveConfig();
                 player.sendMessage(ChatColor.GREEN + "Item deleted!");
                 
               } else player.sendMessage(ChatColor.RED + "Item Not Found! Make sure to use capital if you used caps!");
               
             } else player.sendMessage(ChatColor.RED + "Invalid Entry! Need More Then That!");
             
             return true;
           }
           
           //Viewing Items
           if (cmd.getName().equalsIgnoreCase("itemlist") && sender instanceof Player) {
                 
               //Loop for stuff? you will never know.
               for (String key : config.getKeys(false)) {
                 player.sendMessage(ChatColor.YELLOW + key + ": " + config.getString(key));
               }
                 if (config.getKeys(false).isEmpty()) {
                   player.sendMessage(ChatColor.RED + "No items are here!");
                 }
               
               return true;
             }
           
           //Tp to item!
           if (cmd.getName().equalsIgnoreCase("itemtp") && sender instanceof Player) {
                 
             if(args.length==1) {
             
      if (config.contains(args[0])) {
                 
         String find = args[0];
         int x = getConfig().getInt(sender.getName() + "." + find + ".x");
         int y = getConfig().getInt(sender.getName() + "." + find + ".y");
         int z = getConfig().getInt(sender.getName() + "." + find + ".z");
         int worldname = getConfig().getInt(sender.getName() + "." + find + ".world");   
         
         Location hi = new Location(Bukkit.getWorld(worldname),x,y,z);
         
         if(sender instanceof Player){
           player.teleport(hi);
           player.sendMessage(ChatColor.GOLD + "You have been teleported to the item!");
           
         } else player.sendMessage(ChatColor.RED + "You are a console! You do not have a home!");
         
               } else player.sendMessage(ChatColor.RED + "Item Not Found! Make sure to use capital if you used caps!");
               
               
             } else player.sendMessage(ChatColor.RED + "Invalid Entry! Need More Then That!");
               
               
            return true;
           }
           
           
           //The guy who made this
        if (cmd.getName().equalsIgnoreCase("iteminfo") && sender instanceof Player) {
             
             player.sendMessage(ChatColor.GREEN + "Made by your master and ruler CYBORGTWINS!");
               
        } else player.sendMessage(ChatColor.RED + "Invalid permissions!");
         
         
         return true;
         
       }
    
    }
     
  24. Offline

    Zombie_Striker

  25. Offline

    wiredbrother

    @Zombie_Striker Slight problem just realized that the getWorld part of the hi line is underlined red. Why would this do that!?
     
  26. Offline

    Zombie_Striker

    That is because worldname is still an int. Replace the two "int" with "String" at this line (the line above the "hi" location)
     
  27. Derp. Chrome didn't want to show the last 20 replies for some reason..
     
  28. Offline

    ZP18

    This thread has really racked up the replies! All for a pretty simple task.
    @wiredbrother have you managed to get your code working yet? If so please mark the thread as solved


    Sent from my iPhone using Tapatalk
     
  29. Offline

    wiredbrother

    @ZP18 @Zombie_Striker and @AlvinB
    Lol still haven't got it working quit yet but i think we might have it now because of zombie strikers last post. :)

    @Zombie_Striker
    OOOOOOOOOOOOHHHHHHHHHHHH!!!!!!!!!!!!!!!!! I GET WHAT YOU ARE SAYING XD!
    Like this? :)
    String worldname = getConfig().getString(sender.getName() + "." + find + ".world");

    @Zombie_Striker @AlvinB @ZP18
    I Didn't know making a little TP plugin would be that hard but for my tinny little brain it must be. So here is the problem now. If i have understood you guys i needed the line above the hi line to be a string and that there where two int inside of that. That needed to become a string. Well I did that. The code looks like this But it still spits out a error. Is this really this hard or does my code just suck? Maybe i should add a poll lol. Anyway here it is.

    My current code.
    Code:
    package me.cyborgtwins;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class ItemTP extends JavaPlugin {
      
       @Override
       public void onEnable() {
        
       }
      
       @Override
       public void onDisable() {
        
       }
      
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        
         Player player = (Player) sender;
        
         FileConfiguration config = this.getConfig();
        
         //Joining items
         if (cmd.getName().equalsIgnoreCase("itemadd") && sender instanceof Player) {
            
           if (args.length >= 1) {
          
             String list = "";
            
               for (String arg : args) {
                list = list + arg;
              }
              
               String locks = "";
              
               int x = player.getLocation().getBlockX();
               int y = player.getLocation().getBlockY();
               int z = player.getLocation().getBlockZ();
               World worldname = Bukkit.getWorld(getName());
              
               getConfig().set(sender.getName() + "." + locks + ".x",x);
               getConfig().set(sender.getName() + "." + locks + ".y",y);
               getConfig().set(sender.getName() + "." + locks + ".z",z);
               getConfig().set(sender.getName() + "." + locks + ".world",worldname);
              
               locks = locks +" x" + x + " y" + y + " z" + z + " " + worldname + " ";
              
                //Handling arguments
                if (!config.contains(list)) {
                   config.set(list, locks);
                   player.sendMessage(ChatColor.GREEN + "Item Has Now Been Added!");
                   saveConfig();
                } else player.sendMessage(ChatColor.RED + "This Item Has Already Been Added!");
                
           } else player.sendMessage(ChatColor.RED + "Please Enter the name of the item after /additem");
          
           return true;
          
         }  
          
           //Deleting items
           if (cmd.getName().equalsIgnoreCase("itemdelete") && sender instanceof Player) {
            
             if (args.length == 1) {
              
               if (config.contains(args[0])) {
                
                 config.set(args[0], null);
                 saveConfig();
                 player.sendMessage(ChatColor.GREEN + "Item deleted!");
                
               } else player.sendMessage(ChatColor.RED + "Item Not Found! Make sure to use capital if you used caps!");
              
             } else player.sendMessage(ChatColor.RED + "Invalid Entry! Need More Then That!");
            
             return true;
           }
          
           //Viewing Items
           if (cmd.getName().equalsIgnoreCase("itemlist") && sender instanceof Player) {
                
               //Loop for stuff? you will never know.
               for (String key : config.getKeys(false)) {
                 player.sendMessage(ChatColor.YELLOW + key + ": " + config.getString(key));
               }
                 if (config.getKeys(false).isEmpty()) {
                   player.sendMessage(ChatColor.RED + "No items are here!");
                 }
              
               return true;
             }
          
           //Tp to item!
           if (cmd.getName().equalsIgnoreCase("itemtp") && sender instanceof Player) {
                
             if(args.length==1) {
            
      if (config.contains(args[0])) {
                
         String find = args[0];
         int x = getConfig().getInt(sender.getName() + "." + find + ".x");
         int y = getConfig().getInt(sender.getName() + "." + find + ".y");
         int z = getConfig().getInt(sender.getName() + "." + find + ".z");
         String worldname = getConfig().getString(sender.getName() + "." + find + ".world");  
            
         Location hi = new Location(Bukkit.getWorld(worldname),x,y,z);
        
         if(sender instanceof Player){
           player.teleport(hi);
           player.sendMessage(ChatColor.GOLD + "You have been teleported to the item!");
          
         } else player.sendMessage(ChatColor.RED + "You are a console! You do not have a home!");
        
               } else player.sendMessage(ChatColor.RED + "Item Not Found! Make sure to use capital if you used caps!");
              
              
             } else player.sendMessage(ChatColor.RED + "Invalid Entry! Need More Then That!");
              
              
            return true;
           }
          
          
           //The guy who made this
        if (cmd.getName().equalsIgnoreCase("iteminfo") && sender instanceof Player) {
            
             player.sendMessage(ChatColor.GREEN + "Made by your master and ruler CYBORGTWINS!");
              
        } else player.sendMessage(ChatColor.RED + "Invalid permissions!");
        
        
         return true;
        
       }
    
    }
    
    [code]
    [07:50:07] [Server thread/INFO]: Starting minecraft server version 1.8.8
    [07:50:07] [Server thread/INFO]: Loading properties
    [07:50:07] [Server thread/INFO]: Default game type: SURVIVAL
    [07:50:07] [Server thread/INFO]: Generating keypair
    [07:50:08] [Server thread/INFO]: Starting Minecraft server on *:25565
    [07:50:08] [Server thread/INFO]: Using default channel type
    [07:50:10] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-e1ebe52 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT)
    [07:50:10] [Server thread/INFO]: [ItemTP] Loading ItemTP v1.2
    [07:50:10] [Server thread/INFO]: Preparing level "world"
    [07:50:10] [Server thread/INFO]: Preparing start region for level 0 (Seed: 3304873887225295798)
    [07:50:11] [Server thread/INFO]: Preparing spawn area: 5%
    [07:50:12] [Server thread/INFO]: Preparing spawn area: 49%
    [07:50:13] [Server thread/INFO]: Preparing start region for level 1 (Seed: 3304873887225295798)
    [07:50:14] [Server thread/INFO]: Preparing spawn area: 91%
    [07:50:14] [Server thread/INFO]: Preparing start region for level 2 (Seed: 3304873887225295798)
    [07:50:14] [Server thread/INFO]: [ItemTP] Enabling ItemTP v1.2
    [07:50:14] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [07:50:14] [Server thread/INFO]: Done (4.569s)! For help, type "help" or "?"
    [07:50:41] [User Authenticator #1/INFO]: UUID of player cyborgtwins is blank
    [07:50:41] [Server thread/INFO]: cyborgtwins[/127.0.0.1:65433] logged in with entity id 85 at ([world]0.0, -242.59026307821657, 0.0)
    [07:50:57] [Server thread/INFO]: cyborgtwins issued server command: /itemadd dirt
    [07:51:04] [Server thread/INFO]: cyborgtwins issued server command: /itemlist
    [07:51:29] [Server thread/INFO]: cyborgtwins issued server command: /itemtp dirt
    [07:51:29] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'itemtp' in plugin ItemTP v1.2
       at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_101]
       at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_101]
       at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit.jar:git-Bukkit-e1ebe52]
       at java.lang.Thread.run(Unknown Source) [?:1.8.0_101]
    Caused by: java.lang.IllegalArgumentException: Name cannot be null
       at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at org.bukkit.craftbukkit.v1_8_R3.CraftServer.getWorld(CraftServer.java:968) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at org.bukkit.Bukkit.getWorld(Bukkit.java:505) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       at me.cyborgtwins.ItemTP.onCommand(ItemTP.java:114) ~[?:?]
       at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-e1ebe52]
       ... 15 more
    [07:51:53] [Server thread/INFO]: cyborgtwins lost connection: Disconnected
    [07:51:54] [Server thread/INFO]: cyborgtwins left the game.
    Maybe the 60th reply will be the solution? XD

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Sep 9, 2016
  30. Offline

    ZP18

    What's line 114 in ItemTP.java?


    Sent from my iPhone using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page