Move Player To World Not Working ?!

Discussion in 'Plugin Development' started by projectwoosh, Jun 23, 2016.

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

    projectwoosh

    Hello guys,
    I am a Bukkit plugin maker beginner,
    and I have a server and I wanna create just a simple plugin to move players.
    (In future more things)
    And I don't know what I am doing wrong!?

    This is my error:

    Code:
    [22:10:02 INFO]: UMADSON issued server command: /skyblock
    [22:10:02 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'skyblock' in plugin ServerPlugin v0.1
      at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at org.bukkit.craftbukkit.v1_10_R1.CraftServer.dispatchCommand(CraftServer.java:625) ~[minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at net.minecraft.server.v1_10_R1.PlayerConnection.handleCommand(PlayerConnection.java:1296) [minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1156) [minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(SourceFile:37) [minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(SourceFile:9) [minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_92]
      at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_92]
      at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:690) [minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:360) [minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:646) [minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:550) [minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at java.lang.Thread.run(Unknown Source) [?:1.8.0_92]
    Caused by: java.lang.NullPointerException
      at org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer.teleport(CraftPlayer.java:460) ~[minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity.teleport(CraftEntity.java:226) ~[minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      at net.woosh.hub.main.Main.onCommand(Main.java:64) ~[?:?]
      at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[minecraft_server.1.9.jar:git-Bukkit-10c10b3]
      ... 15 more
    
    And this is My Main File:
    Code:
    package net.woosh.hub.main;
    
    import java.util.logging.Logger;
    
    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.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.milkbowl.vault.economy.Economy;
    
    public class Main extends JavaPlugin implements Listener {
      
       public static final String Prefix = ChatColor.DARK_GRAY+ "[" + ChatColor.DARK_PURPLE + ChatColor.BOLD + "Woosh" + ChatColor.RESET + ChatColor.DARK_GRAY + "] " + ChatColor.DARK_PURPLE;
      public static Economy econ = null;
      
    
       public void onEnable(){    
         Bukkit.getServer().getPluginManager().registerEvents(this, this);
       }
      
      
       @Override
       public void onDisable(){
        
       }
      
       @EventHandler
       public void onPlayerJoin(PlayerJoinEvent e){
         Player user = e.getPlayer();
         String message = Prefix + "Welcome, " + ChatColor.GOLD + user.getName() + ChatColor.DARK_PURPLE + "!";
         user.sendMessage(message);
       }
      
      @SuppressWarnings("unused")
      public int onlinePlayers() {
      int a = 0;
      
      for (Player player : getServer().getOnlinePlayers()) {
      a++;
      }
      
      return a;
      }
      Logger log = Logger.getLogger("minecraft");
      
      @Override
      public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
         if(!(sender instanceof Player)){
           sender.sendMessage(Prefix + "You aren't a player!");
           return false;
         }
      if(cmd.getName().equalsIgnoreCase("skyblock") && args.length == 0){
      Player player = (Player) sender;
      World p = Bukkit.getWorld("skyblock");
      player.teleport(new Location(p, -232, 51, -8.5));
      player.sendMessage(Prefix + "You're now in the Skyblock!");
      return true;
      }else if(args.length == 1){
         Player player = (Player) sender;
         String vip = args[1];
        
         if(vip.equalsIgnoreCase("VIP")){
        
         for (Player all : Bukkit.getOnlinePlayers()) {
      if (all.hasPermission("woosh.perm")){
      World p = Bukkit.getWorld("skyblock");
      player.teleport(new Location(p, -232, 51, -8.5));
      player.sendMessage(Prefix + "You're now in the Skyblock!");
      }else{
      player.sendMessage(ChatColor.RED + "You don't have permissions to use this command!");
      }
         }
         }else{
           player.sendMessage(Prefix + "Unknow argument!");
         }
      }else if(args.length > 1){
         Player player = (Player) sender;
         player.sendMessage(Prefix + "Too much arguments!");
         }
      return false;
       }
    }
    And here is my plugin.yml file:
    Code:
    name: ServerPlugin
    main: net.woosh.hub.main.Main
    version: 0.1
    author: UMADSON
    prefix: Woosh
    commands:
      skyblock:
      description: Goto VIP Skyblock!
      usage: /<command>
    
    I hope that you know!
    Sorry for bad English ;)
    Sorry for long question!
     
    Last edited by a moderator: Jun 23, 2016
  2. Offline

    timtower Administrator Administrator Moderator

    @projectwoosh
    • Please don't use static, you don't need it.
    • You never set the value of econ
    • To get the amount of online players use getServer().getOnlinePlayers().size()
    • Don't use that logger, use getLogger instead.
    • Check if the world is null before you use it.
     
Thread Status:
Not open for further replies.

Share This Page