Teleport to point not working

Discussion in 'Plugin Help/Development/Requests' started by phil14052, Mar 23, 2015.

Thread Status:
Not open for further replies.
  1. Hey iam making a plugin where you come to a court to get a reason why the player comes in jail.
    But with my plugin i cant teleport to the spot i set.

    Code (open)

    Code:
    package me.Phil14052.CourtJugde;
    
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class CourtJugde extends JavaPlugin implements Listener{
       
        public Logger logger = Logger.getLogger("Minecraft");
       
        @Override
        public void onEnable(){
            saveDefaultConfig();
            Bukkit.getServer().getPluginManager().registerEvents(this,this);
        }
       
        @Override
        public void onDisable(){
            saveDefaultConfig();
        }
       
        @EventHandler
        public void OnPlayerJoin(PlayerJoinEvent e){
            if(!(e.getPlayer().hasPlayedBefore())){
                //Coming Soon
    
            }
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(cmd.getName().equalsIgnoreCase("court")){
                Player p = (Player)sender;
                if(args.length < 1){
                    sender.sendMessage("Usage: /court settp");
                }else if(args[0].equalsIgnoreCase("settp")){
                    if(sender instanceof Player){
                        try {
                            BufferedWriter bw = new BufferedWriter(new FileWriter(new File(getDataFolder(), "Point.yml"))); //Making a point.yml file.
                            bw.write(p.getLocation().getWorld().getName() + ", " + p.getLocation().getX() + ", " + p.getLocation().getY() + ", " + p.getLocation().getZ());
                            bw.close();
                        }catch (Exception e) {
                            // TODO: handle exception
                        }
                    }
                   
                   
                }else if(args[0].equalsIgnoreCase("tp")){
                    if(sender instanceof Player){
                        {
                            String[] Point = null;
                            try {
                                Point = new BufferedReader(new FileReader(new File(getDataFolder(), "Point.yml"))).readLine().split(", ");
                            }catch (Exception e) {
                                // TODO: handle exception
                            }
                                Location PTP = new Location (getServer().getWorld(Point[0]),
                                        Integer.parseInt(Point[1]), Integer.parseInt(Point[2]), Integer.parseInt(Point[3]));
                            p.teleport(PTP);
                            sender.sendMessage("Teleporting!");
                        }
                    }
                }
            }
            return false;
        }
       
    
    }
    


    In-game error (open)
    Code:
    An internal error occurred while attempting to perform this command


    Log error: (open)

    Code:
    [16:50:54] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'court' in plugin CourtJugde v0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-529ff99-7f52bd6]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-529ff99-7f52bd6]
        at org.bukkit.craftbukkit.v1_8_R2.CraftServer.dispatchCommand(CraftServer.java:646) ~[spigot.jar:git-Spigot-529ff99-7f52bd6]
        at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1133) [spigot.jar:git-Spigot-529ff99-7f52bd6]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot.jar:git-Spigot-529ff99-7f52bd6]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-529ff99-7f52bd6]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-529ff99-7f52bd6]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-529ff99-7f52bd6]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_40]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_40]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot.jar:git-Spigot-529ff99-7f52bd6]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot.jar:git-Spigot-529ff99-7f52bd6]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot.jar:git-Spigot-529ff99-7f52bd6]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot.jar:git-Spigot-529ff99-7f52bd6]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot.jar:git-Spigot-529ff99-7f52bd6]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_40]
    Caused by: java.lang.NumberFormatException: For input string: "20.604287066046822"
        at java.lang.NumberFormatException.forInputString(Unknown Source) ~[?:1.8.0_40]
        at java.lang.Integer.parseInt(Unknown Source) ~[?:1.8.0_40]
        at java.lang.Integer.parseInt(Unknown Source) ~[?:1.8.0_40]
        at me.Phil14052.CourtJugde.CourtJugde.onCommand(CourtJugde.java:69) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-529ff99-7f52bd6]
        ... 15 more
     
  2. Offline

    mine-care

    Caused by: java.lang.NumberFormatException: For input string: "20.604287066046822"
    at me.Phil14052.CourtJugde.CourtJugde.onCommand(CourtJugde.java:69)


    Also Player p =(Player)sender; - dont cast without checking. See my signature

    public Logger logger = Logger.getLogger("Minecraft");
    Dont. jsut Dont, (stop watching BcBroz) use getLogger();

    Essentially your problem is that you parse an Integer from a Double string...

    Oh and in your tp command body, dont open a file every time a player uses it also dont forget to close streams,
     
  3. Offline

    mrCookieSlime

    Moved to Alternatives Section.
     
  4. So i just dont get it. Can u you give some eksamples? (With the tp) (
    )
    and how shoud i fix the
    Fixed.

    1 i did not see BcBroz 2 Kinda fixed
     
  5. Offline

    mine-care

    @phil14052 Use Double.parseDouble(String paramstring) instead of Integer
    Remember that Integer has no decimal points whereas Double has
    int X = 11;
    double XX = 11.11111111111...111;

    and about TP, dont open the file every time, just use an alternative method such as loading onEnable and save onDisable
     
Thread Status:
Not open for further replies.

Share This Page