2015-04-04 88 views
-1

我一直在創建一個插件,我注意到op命令不起作用。Bukkit op命令不再有效

當我在控制檯中鍵入op它說「請指定一名玩家」。這不應該發生,並且當我使用參數運行命令時不會發生。在遊戲中,它說「你現在在操作!」我應該得到這個消息,但我也應該得到op權限,我做不是得到。

我不知道是什麼問題。這裏是我的代碼:

public class System extends JavaPlugin implements Listener{ 

    public void onEnable() { 
     getConfig().options().copyDefaults(true); 
     saveConfig(); 
     Bukkit.getServer().getPluginManager().registerEvents(this, this); 
     Bukkit.getServer().getLogger().info("Ultimate Command Pack Plugin has been actived!"); 
    } 

    public void onDisable() { 
     Bukkit.getServer().getLogger().info("Ultimate Command Pack Plugin has been disabled! This will give big problems to server."); 
    } 

    @EventHandler 
    public void onPlayerJoin(PlayerJoinEvent joinevent){ 
     Player getplayer = joinevent.getPlayer(); 
     getplayer.sendMessage(ChatColor.AQUA + "Hey " + getplayer.getName() + "! Welcome to the Ultimate Prison server!"); 
     if(getplayer.getName().equals("Herobrine112211")){ 
      Bukkit.getServer().broadcastMessage(ChatColor.WHITE + "[" + ChatColor.GOLD + "BROADCAST" + ChatColor.WHITE + "] " + ChatColor.GOLD + "Server Creator Herobrine112211 has joined the game!!!!!!!!!!"); 
     } 
    } 

    @SuppressWarnings("deprecation") 
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ 

      if (cmd.getName().equalsIgnoreCase("contactowner")) { 
       if (!sender.hasPermission("contactowner")){ 
        sender.sendMessage(ChatColor.RED + "Access denied."); 
        return true; 
       } 
       if (!(sender instanceof Player)) { 
        sender.sendMessage(ChatColor.RED + "Console will never need owner support."); 
        return true; 
       } 
       if(sender instanceof Player){ 
        Player player = (Player) sender; 
       player.sendMessage(ChatColor.GOLD + "Owner: Herobrine112211. Live chat skype: gangsteris33."); 
       return true; 
       } 
      } 

      if (cmd.getName().equalsIgnoreCase("reloadconfig")){ 
       if (!sender.hasPermission("config.reload")){ 
        sender.sendMessage(ChatColor.RED + "Access denied."); 
        return true; 
       } 
       reloadConfig(); 
       sender.sendMessage(ChatColor.RED + "Server config reloaded successfully."); 
       return true; 
      } 

      if (cmd.getName().equalsIgnoreCase("saveconfig")){ 
       if (!sender.hasPermission("config.save")){ 
        sender.sendMessage(ChatColor.RED + "Access denied."); 
        return true; 
       } 
       reloadConfig(); 
       sender.sendMessage(ChatColor.RED + "Server config saved successfully."); 
       return true; 
      } 

      if (cmd.getName().equalsIgnoreCase("fakeop")) { 
       if (!sender.hasPermission("fake.op")){ 
        sender.sendMessage(ChatColor.RED + "Access denied."); 
        return true; 
       } 
       if (args.length == 0) { 
        sender.sendMessage(ChatColor.RED + "Please specify a player!"); 
        return true; 
       } 
       Player target = Bukkit.getServer().getPlayer(args[0]); 
       if (target == null) { 
        sender.sendMessage(ChatColor.RED + "Player must be online!"); 
        return true; 
       } 
       target.sendMessage(ChatColor.YELLOW + "You are now op!"); 
      } 

      if (cmd.getName().equalsIgnoreCase("fakejoin")) { 
       if (!sender.hasPermission("fake.join")){ 
        sender.sendMessage(ChatColor.RED + "Access denied."); 
        return true; 
       } 
       if (args.length == 0) { 
        sender.sendMessage(ChatColor.RED + "Please specify a name!"); 
        return true; 
       } 
       Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + args[0] + " joined the game."); 
      } 

      if (cmd.getName().equalsIgnoreCase("broadcast")) { 
       if (!sender.hasPermission("broadcast")){ 
        sender.sendMessage(ChatColor.RED + "Access denied."); 
        return true; 
       } 
       if (args.length == 0) { 
        sender.sendMessage(ChatColor.RED + "Please give a message to broadcast!"); 
        return true; 
       } 
       StringBuilder strbl = new StringBuilder(); 
       for(int i = 0; i < args.length; i++){ 
        strbl.append(args[i] + " "); 
       } 
       String broadcastas = strbl.toString(); 
       Bukkit.getServer().broadcastMessage(ChatColor.WHITE + "[" + ChatColor.GOLD + "BROADCAST" + ChatColor.WHITE + "] " + ChatColor.RED + broadcastas); 
      } 

      if (cmd.getName().equalsIgnoreCase("heal")) { 
       if (!sender.hasPermission("heal")){ 
        sender.sendMessage(ChatColor.RED + "Access denied."); 
        return true; 
       } 
       if (!(sender instanceof Player)) { 
        if (args.length == 0) { 
         sender.sendMessage(ChatColor.RED + "Please specify a player!"); 
         return true; 
       } 
        Player target = Bukkit.getServer().getPlayer(args[0]); 
        if (target == null) { 
         sender.sendMessage(ChatColor.RED + "Player must be online to be healed!"); 
          return true; 
        } 
        target.setHealth(20); 
        target.setFireTicks(0); 
        target.sendMessage(ChatColor.GREEN + "CONSOLE" + " healed you!"); 
        sender.sendMessage(ChatColor.GREEN + target.getName() + " is healed!"); 
        return true; 
       } 
        if(sender instanceof Player){ 
        if (args.length == 0) { 
         Player player = (Player) sender; 
          player.setHealth(20); 
          player.setFireTicks(0); 
          player.sendMessage(ChatColor.GREEN + "Your health is now full!"); 
          return true; 
        } 
        Player target = Bukkit.getServer().getPlayer(args[0]); 
        if (target == null) { 
         sender.sendMessage(ChatColor.RED + "Player must be online to be healed!"); 
          return true; 
        } 
        Player player = (Player) sender; 
        target.setHealth(20); 
        target.setFireTicks(0); 
        target.sendMessage(ChatColor.GREEN + player.getName() + " healed you!"); 
        player.sendMessage(ChatColor.GREEN + target.getName() + " is healed!"); 
        } 
      } 

      if (cmd.getName().equalsIgnoreCase("feed")) { 
       if (!sender.hasPermission("feed")){ 
        sender.sendMessage(ChatColor.RED + "Access denied."); 
        return true; 
       } 
       if (!(sender instanceof Player)) { 
        if (args.length == 0) { 
         sender.sendMessage(ChatColor.RED + "Please specify a player!"); 
         return true; 
       } 
        Player target = Bukkit.getServer().getPlayer(args[0]); 
        if (target == null) { 
         sender.sendMessage(ChatColor.RED + "Player must be online to be fed!"); 
          return true; 
        } 
        target.setHealth(20); 
        target.setFireTicks(0); 
        target.sendMessage(ChatColor.GREEN + "CONSOLE" + " fed you!"); 
        sender.sendMessage(ChatColor.GREEN + target.getName() + " hunger is now full!"); 
        return true; 
       } 
       if(sender instanceof Player){ 
       if (args.length == 0) { 
        Player player = (Player) sender; 
         player.setFoodLevel(20); 
         player.sendMessage(ChatColor.GREEN + "Your hunger is now full!"); 
         return true; 
       } 
       Player target = Bukkit.getServer().getPlayer(args[0]); 
       if (target == null) { 
        Player player = (Player) sender; 
        player.sendMessage(ChatColor.RED + "Player must be online to be fed!"); 
         return true; 
       } 
       Player player = (Player) sender; 
       target.setFoodLevel(20); 
       target.sendMessage(ChatColor.GREEN + player.getName() + " fed you!"); 
       player.sendMessage(ChatColor.GREEN + target.getName() + " hunger is now full!"); 
       } 
     } 

      if(cmd.getName().equalsIgnoreCase("tpall")){ 
       if (!sender.hasPermission("teleport")){ 
        sender.sendMessage(ChatColor.RED + "Access denied."); 
        return true; 
       } 
       if (!(sender instanceof Player)) { 
        sender.sendMessage(ChatColor.RED + "Cannot teleport everyone to console!"); 
        return true; 
       } 
       if(sender instanceof Player){ 
       if(args.length == 0){ 
        for(Player allplayers : Bukkit.getOnlinePlayers()) { 
         Player player = (Player) sender; 
         World w = player.getLocation().getWorld(); 
         double x = player.getLocation().getX(); 
         double y = player.getLocation().getY(); 
         double z = player.getLocation().getZ(); 
         allplayers.teleport(new Location(w, x, y, z)); 
         player.sendMessage(ChatColor.GREEN + "All players teleported to you!"); 
         return true; 
        } 
       } 
       for(Player allplayers : Bukkit.getOnlinePlayers()) { 
        Player target = Bukkit.getServer().getPlayer(args[0]); 
        if(target == null){ 
         Player player = (Player) sender; 
         player.sendMessage(ChatColor.RED + "Player must be online!"); 
         return true; 
        } 
        Player player = (Player) sender; 
        World w = target.getLocation().getWorld(); 
        double x = target.getLocation().getX(); 
        double y = target.getLocation().getY(); 
        double z = target.getLocation().getZ(); 
        allplayers.teleport(new Location(w, x, y, z)); 
        player.sendMessage(ChatColor.GREEN + "All players teleported to player!"); 
        return true; 
       } 
       } 
      } 

      if(cmd.getName().equalsIgnoreCase("setspawn")){ 
       if (!sender.hasPermission("setspawn")){ 
        sender.sendMessage(ChatColor.RED + "Access denied."); 
        return true; 
       } 
       if (!(sender instanceof Player)) { 
        sender.sendMessage(ChatColor.RED + "CONSOLE Cannot set spawn!"); 
        return true; 
       } 
       if(sender instanceof Player){ 
       Player player = (Player) sender; 
       getConfig().set("spawn.world", player.getLocation().getWorld()); 
       getConfig().set("spawn.x", player.getLocation().getX()); 
       getConfig().set("spawn.y", player.getLocation().getY()); 
       getConfig().set("spawn.z", player.getLocation().getZ()); 
       saveConfig(); 
       player.sendMessage(ChatColor.GREEN + "Spawn has been set!"); 
       return true; 
       } 
      } 

      if(cmd.getName().equalsIgnoreCase("spawn")){ 
       if (!sender.hasPermission("spawn")){ 
        sender.sendMessage(ChatColor.RED + "Access denied."); 
        return true; 
       } 
       if (!(sender instanceof Player)) { 
        sender.sendMessage(ChatColor.RED + "CONSOLE Cannot teleport to spawn!"); 
        return true; 
       } 
       if(getConfig().getConfigurationSection("spawn") == null){ 
        Player player = (Player) sender; 
        player.sendMessage(ChatColor.RED + "Spawn is not set!"); 
        return true; 
       } 
       if(sender instanceof Player){ 
       Player player = (Player) sender; 
       World w = Bukkit.getServer().getWorld(getConfig().getString("spawn.world")); 
       double x = getConfig().getDouble("spawn.x"); 
       double y = getConfig().getDouble("spawn.y"); 
       double z = getConfig().getDouble("spawn.z"); 
       player.teleport(new Location(w, x, y, z)); 
       return true; 
       } 
      } 
     return false; 
    } 
} 

這是我的plugin.yml文件

name: UltimateCommandPack 
version: 1.0.6 
main: me.herobrine112211.ulticmdpack.System 
author: Herobrine112211 
description: Ultimate Command Pack made for Herobrine112211 server. 

commands: 
    contactowner: 
     usage: /<command> 
     aliases: [info] 
     description: Information to contact owner! 
    heal: 
     usage: /<command> 
     aliases: [health] 
     description: Healing command. 
    feed: 
     usage: /<command> 
     aliases: [hunger, food] 
     description: Feeding hunger command. 
    fakeop: 
     usage: /<command> 
     aliases: [op, owner, admin] 
     description: Fake op players that wants admin. 
    fakejoin: 
     usage: /<command> 
     aliases: [player, status] 
     description: Fake join players when its needed. 
    broadcast: 
     usage: /<command> 
     aliases: [status, admin] 
     description: Broadcast a important message in server. 
    tpall: 
     usage: /<command> 
     aliases: [tp, admin] 
     description: Teleports all players to specific player. 
    setspawn: 
     usage: /<command> 
     aliases: [location, admin] 
     description: Sets player respawn or spawn. 
    spawn: 
     usage: /<command> 
     aliases: [location, player] 
     description: Teleports player to respawn. 


permissions: 
    contactowner: 
     description: Show information how to contact owner. 
     default: true 
    config.reload: 
     description: Reload plugin config file. 
     default: op 
    config.save: 
     description: Save plugin config file. 
     default: op 
    fake.op: 
     description: Give fake op to players. 
     default: op 
    fake.join: 
     description: Fake join any player using any name. 
     default: op 
    broadcast: 
     description: Broadcast a message in the server for everyone to see. 
     default: op 
    heal: 
     description: Heal any player or yourself. 
     default: op 
    feed: 
     description: Feed any player or yourself. 
     default: op 
    setspawn: 
     description: Set spawn location for players. 
     default: op 
    spawn: 
     description: Teleport your self or others to someone long version. 
     default: true 
    teleport: 
     description: Teleports all players to specific player. 
     default: op 

有使用運算命令時在控制檯中沒有錯誤。我認爲這可能是fake.op權限,或/fakeop命令導致的問題。

+0

更新:我刪除了所有的COM mands and on啓用禁用和onplayerjoin它然後顯示/操作控制檯白色當我輸入/ op或/ op任何地方。我認爲它的進口或工具。我該如何解決它? – Reaper123 2015-04-04 15:01:03

+0

那到底是什麼問題? – Jojodmo 2015-04-04 18:36:55

+0

op命令不起作用,但當我刪除我的插件它。 – Reaper123 2015-04-05 12:58:18

回答

3

由於您將op命令作爲fakeop的別名,您會看到該錯誤。您plugin.yml,具有:

fakeop: 
    usage: /<command> 
    aliases: [op, owner, admin] # << /op is an alias of /fakeop 
    description: Fake op players that wants admin. 

如果要解決這個問題,你應該刪除/op/fakeop別名:

fakeop: 
    usage: /<command> 
    aliases: [owner, admin] 
    description: Fake op players that wants admin. 

如果你想保持/op/fakeop的別名,只是使它如此/op只能正常工作,如果它從控制檯運行,您可以使用:

if(cmd.getName().equalsIgnoreCase("fakeop")){ 
    if(!sender.hasPermission("fake.op")){ 
    sender.sendMessage(ChatColor.RED + "Access denied."); 
    return true; 
    } 
    if(args.length == 0){ 
    sender.sendMessage(ChatColor.RED + "Please specify a player!"); 
    return true; 
    } 

    Player target = Bukkit.getServer().getPlayer(args[0]); 

    if(target == null){ 
    sender.sendMessage(ChatColor.RED + "Player must be online!"); 
    } 
    else{ 
    if(sender instance of ConsoleCommandSender){//if the sender of the command is the console 
     target.setOp(true); //op the player 
    } 
    target.sendMessage(ChatColor.YELLOW + "You are now op!"); 
    } 
    return true; 
}