2016-08-04 77 views
0

無法實例類型rankup - 線61 我不明白爲什麼這種情況正在發生:無法實例類型rankup

package net.minebloxmc.main; 

import java.util.logging.Logger; 

import org.bukkit.ChatColor; 
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.PluginDescriptionFile; 
import org.bukkit.plugin.java.JavaPlugin; 

import commands.rankup; 



public class Main extends JavaPlugin { 



    public FileConfiguration config = getConfig(); 
    public void onEnable() { 
     registerCommands(); 



     config.options().copyDefaults(true); 
     saveConfig(); 

    } 

    public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { 
     if (commandLabel.equalsIgnoreCase("ranks")) { 
      if (sender instanceof Player) { 
       Player player = (Player) sender; 
       player.sendMessage("[" + ChatColor.GOLD + "Ranks" + ChatColor.WHITE + "]"); 

       if (args.length == 0) { 
        String[] classes = getConfig().getString("Ranks.Names").split(","); 
        String[] prices = getConfig().getString("Ranks.Prices").split(","); 

        for(int i = 0; i< classes.length;i++){ 
         sender.sendMessage("[" + ChatColor.GOLD + classes[i] + ChatColor.WHITE + "] " + ChatColor.BLUE + "This gives you the " + classes[i] + " rank!" + " Price: $" + prices[i]); 
        } 
       } 
      } 
     } 
     return false; 

    } 

    public void onDisable() { 
     PluginDescriptionFile pdfFile = getDescription(); 
     Logger logger = Logger.getLogger("Minecraft"); 

     logger.info(pdfFile.getName() + " is now disabled (V." + pdfFile.getVersion() + ")"); 


    } 
    public void registerCommands() { 
     getCommand("rankup").setExecutor(new rankup(this)); 

    } 
} 

這裏的rankup.java:

package commands; 

import java.util.logging.Logger; 

import org.bukkit.ChatColor; 
import org.bukkit.OfflinePlayer; 
import org.bukkit.World; 
import org.bukkit.command.Command; 
import org.bukkit.command.CommandExecutor; 
import org.bukkit.command.CommandSender; 
import org.bukkit.entity.Player; 
import org.bukkit.permissions.PermissionAttachment; 
import org.bukkit.permissions.PermissionAttachmentInfo; 
import org.bukkit.plugin.Plugin; 

import com.earth2me.essentials.api.Economy; 
import com.earth2me.essentials.api.UserDoesNotExistException; 

import net.minebloxmc.main.Main; 


public abstract class rankup implements CommandExecutor { 

    public Main pluginn; 

    public rankup(Main plugin) { 
     this.pluginn = plugin; 
    } 

    protected static final Logger log = Logger.getLogger("Minecraft"); 
    protected Plugin plugin = null; 


    abstract public String getName(); 


    abstract public boolean isEnabled(); 


    abstract public boolean hasSuperPermsCompat(); 


    @Deprecated 
    public boolean has(String world, String player, String permission) { 
     if (world == null) { 
      return playerHas((String) null, player, permission); 
     } 
     return playerHas(world, player, permission); 
    } 


    @Deprecated 
    public boolean has(World world, String player, String permission) { 
     if (world == null) { 
      return playerHas((String) null, player, permission); 
     } 
     return playerHas(world.getName(), player, permission); 
    } 


    public boolean has(CommandSender sender, String permission) { 
     return sender.hasPermission(permission); 
    } 


    public boolean has(Player player, String permission) { 
     return player.hasPermission(permission); 
    } 


    @Deprecated 
    abstract public boolean playerHas(String world, String player, String permission); 


    @Deprecated 
    public boolean playerHas(World world, String player, String permission) { 
     if (world == null) { 
      return playerHas((String) null, player, permission); 
     } 
     return playerHas(world.getName(), player, permission); 
    } 


    public boolean playerHas(String world, OfflinePlayer player, String permission) { 
     if (world == null) { 
      return has((String) null, player.getName(), permission); 
     } 
     return has(world, player.getName(), permission); 
    } 


    public boolean playerHas(Player player, String permission) { 
     return has(player, permission); 
    } 


    @Deprecated 
    abstract public boolean playerAdd(String world, String player, String permission); 


    @Deprecated 
    public boolean playerAdd(World world, String player, String permission) { 
     if (world == null) { 
      return playerAdd((String) null, player, permission); 
     } 
     return playerAdd(world.getName(), player, permission); 
    } 


    public boolean playerAdd(String world, OfflinePlayer player, String permission) { 
     if (world == null) { 
      return playerAdd((String) null, player.getName(), permission); 
     } 
     return playerAdd(world, player.getName(), permission); 
    } 


    public boolean playerAdd(Player player, String permission) { 
     return playerAdd(player.getWorld().getName(), player, permission); 
    } 


    @Deprecated 
    public boolean playerAddTransient(String player, String permission) throws UnsupportedOperationException { 
     Player p = plugin.getServer().getPlayer(player); 
     if (p == null) { 
      throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!"); 
     } 
     return playerAddTransient(p, permission); 
    } 


    public boolean playerAddTransient(OfflinePlayer player, String permission) throws UnsupportedOperationException { 
     if (player.isOnline()) { 
      return playerAddTransient((Player) player, permission); 
     } 
     throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!"); 
    } 


    public boolean playerAddTransient(Player player, String permission) { 
     for (PermissionAttachmentInfo paInfo : player.getEffectivePermissions()) { 
      if (paInfo.getAttachment() != null && paInfo.getAttachment().getPlugin().equals(plugin)) { 
       paInfo.getAttachment().setPermission(permission, true); 
       return true; 
      } 
     } 

     PermissionAttachment attach = player.addAttachment(plugin); 
     attach.setPermission(permission, true); 

     return true; 
    } 


    public boolean playerAddTransient(String worldName, OfflinePlayer player, String permission) { 
     return playerAddTransient(worldName, player.getName(), permission); 
    } 


    public boolean playerAddTransient(String worldName, Player player, String permission) { 
     return playerAddTransient(player, permission); 
    } 


    @Deprecated 
    public boolean playerAddTransient(String worldName, String player, String permission) { 
     Player p = plugin.getServer().getPlayer(player); 
     if (p == null) { 
      throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!"); 
     } 
     return playerAddTransient(p, permission); 
    } 


    @Deprecated 
    public boolean playerRemoveTransient(String worldName, String player,  String permission) { 
     Player p = plugin.getServer().getPlayer(player); 
     if (p == null) 
      return false; 

     return playerRemoveTransient(p, permission); 
    } 


    public boolean playerRemoveTransient(String worldName, OfflinePlayer player, String permission) { 
     return playerRemoveTransient(worldName, player.getName(), permission); 
    } 


    public boolean playerRemoveTransient(String worldName, Player player, String permission) { 
     return playerRemoveTransient(worldName, (OfflinePlayer) player, permission); 
    } 


    @Deprecated 
    abstract public boolean playerRemove(String world, String player, String permission); 


    public boolean playerRemove(String world, OfflinePlayer player, String permission) { 
     if (world == null) { 
      return playerRemove((String) null, player.getName(), permission); 
     } 
     return playerRemove(world, player.getName(), permission); 
    } 


    @Deprecated 
    public boolean playerRemove(World world, String player, String permission) { 
     if (world == null) { 
      return playerRemove((String) null, player, permission); 
     } 
     return playerRemove(world.getName(), player, permission); 
    } 

    public boolean playerRemove(Player player, String permission) { 
     return playerRemove(player.getWorld().getName(), player, permission); 
    } 


    @Deprecated 
    public boolean playerRemoveTransient(String player, String permission) { 
     Player p = plugin.getServer().getPlayer(player); 
     if (p == null) 
      return false; 

     return playerRemoveTransient(p, permission); 
    } 


    public boolean playerRemoveTransient(OfflinePlayer player, String permission) { 
     if (player.isOnline()) { 
      return playerRemoveTransient((Player) player, permission); 
     } else { 
      return false; 
     } 
    } 


    public boolean playerRemoveTransient(Player player, String permission) { 
     for (PermissionAttachmentInfo paInfo : player.getEffectivePermissions()) { 
      if (paInfo.getAttachment() != null && paInfo.getAttachment().getPlugin().equals(plugin)) { 
       paInfo.getAttachment().unsetPermission(permission); 
       return true; 
      } 
     } 
     return false; 
    } 


    abstract public boolean groupHas(String world, String group, String permission); 


    public boolean groupHas(World world, String group, String permission) { 
     if (world == null) { 
      return groupHas((String) null, group, permission); 
     } 
     return groupHas(world.getName(), group, permission); 
    } 


    abstract public boolean groupAdd(String world, String group, String permission); 


    public boolean groupAdd(World world, String group, String permission) { 
     if (world == null) { 
      return groupAdd((String) null, group, permission); 
     } 
     return groupAdd(world.getName(), group, permission); 
    } 


    abstract public boolean groupRemove(String world, String group, String permission); 


    public boolean groupRemove(World world, String group, String permission) { 
     if (world == null) { 
      return groupRemove((String) null, group, permission); 
     } 
     return groupRemove(world.getName(), group, permission); 
    } 


    @Deprecated 
    abstract public boolean playerInGroup(String world, String player, String group); 


    @Deprecated 
    public boolean playerInGroup(World world, String player, String group) { 
     if (world == null) { 
      return playerInGroup((String) null, player, group); 
     } 
     return playerInGroup(world.getName(), player, group); 
    } 


    public boolean playerInGroup(String world, OfflinePlayer player, String group) { 
     if (world == null) { 
      return playerInGroup((String) null, player.getName(), group); 
     } 
     return playerInGroup(world, player.getName(), group); 
    } 


    public boolean playerInGroup(Player player, String group) { 
     return playerInGroup(player.getWorld().getName(), player, group); 
    } 


    @Deprecated 
    abstract public boolean playerAddGroup(String world, String player, String group); 


    @Deprecated 
    public boolean playerAddGroup(World world, String player, String group) { 
     if (world == null) { 
      return playerAddGroup((String) null, player, group); 
     } 
     return playerAddGroup(world.getName(), player, group); 
    } 


    public boolean playerAddGroup(String world, OfflinePlayer player, String group) { 
     if (world == null) { 
      return playerAddGroup((String) null, player.getName(), group); 
     } 
     return playerAddGroup(world, player.getName(), group); 
    } 


    public boolean playerAddGroup(Player player, String group) { 
     return playerAddGroup(player.getWorld().getName(), player, group); 
    } 


    @Deprecated 
    abstract public boolean playerRemoveGroup(String world, String player, String group); 


    @Deprecated 
    public boolean playerRemoveGroup(World world, String player, String group) { 
     if (world == null) { 
      return playerRemoveGroup((String) null, player, group); 
     } 
     return playerRemoveGroup(world.getName(), player, group); 
    } 


    public boolean playerRemoveGroup(String world, OfflinePlayer player, String group) { 
     if (world == null) { 
      return playerRemoveGroup((String) null, player.getName(), group); 
     } 
     return playerRemoveGroup(world, player.getName(), group); 
    } 


    public boolean playerRemoveGroup(Player player, String group) { 
     return playerRemoveGroup(player.getWorld().getName(), player, group); 
    } 

    /** 
    * @deprecated As of VaultAPI 1.4 use {@link #getPlayerGroups(String, OfflinePlayer)} instead. 
    */ 
    @Deprecated 
    abstract public String[] getPlayerGroups(String world, String player); 


    @Deprecated 
    public String[] getPlayerGroups(World world, String player) { 
     if (world == null) { 
      return getPlayerGroups((String) null, player); 
     } 
     return getPlayerGroups(world.getName(), player); 
    } 


    public String[] getPlayerGroups(String world, OfflinePlayer player) { 
     return getPlayerGroups(world, player.getName()); 
    } 


    public String[] getPlayerGroups(Player player) { 
     return getPlayerGroups(player.getWorld().getName(), player); 
    } 


    @Deprecated 
    abstract public String getPrimaryGroup(String world, String player); 


    @Deprecated 
    public String getPrimaryGroup(World world, String player) { 
     if (world == null) { 
      return getPrimaryGroup((String) null, player); 
     } 
     return getPrimaryGroup(world.getName(), player); 
    } 


    public String getPrimaryGroup(String world, OfflinePlayer player) { 
     return getPrimaryGroup(world, player.getName()); 
    } 


    public String getPrimaryGroup(Player player) { 
     return getPrimaryGroup(player.getWorld().getName(), player); 
    } 


    abstract public String[] getGroups(); 


    abstract public boolean hasGroupSupport(); 

    @SuppressWarnings("deprecation") 
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 
     if (!(sender instanceof Player)) { 
      sender.sendMessage("You must be a player"); 
      return false; 
     } 

     Player player = (Player) sender; 
     String playere = player.getName(); 
     String world = plugin.getConfig().getString("World.World"); 
     @SuppressWarnings("unused") 
     String A = "A"; 
    if (player.getLocation().getWorld().getName().equals(world)) { 
     player.sendMessage(ChatColor.BLUE + "Correct world: " + world + "!"); 
     try { 
      if (Economy.hasEnough(playere, 100)) { 
       player.sendMessage(ChatColor.BLUE + "You have enough!"); 

       getPrimaryGroup(world, playere); 

      } 
     } catch (UserDoesNotExistException e) { 

      e.printStackTrace(); 
     } 
    } else { 
     player.sendMessage(ChatColor.RED + "Incorrect world! You need to be in world: " + world + "!"); 
    } 
    return true; 
} 
} 

這是一個我正在開發的bukkit插件,我試圖讓它找到運行命令/等級的用戶組。

+0

rankup是抽象的,不能被實例化。 – PeterS

+1

你爲什麼要聲明'rankup'抽象?抽象類意味着被其他類擴展。此外,按照慣例和可讀性,類名應以大寫字母開頭。 – Momo

回答

1

您已將您的「排名」類聲明爲抽象類。這意味着你不能通過「new」來實例化它,就像你試圖在你的registerCommand方法中做的那樣。您需要創建一個實現抽象方法的具體子類,然後實例化它。

+0

我該怎麼做(我知道這是一個非常愚蠢的問題,但正如他們所說...代碼學習) –