gpt4 book ai didi

java - 无法实例化类型Rankup

转载 作者:行者123 更新时间:2023-12-01 09:37:17 41 4
gpt4 key购买 nike

无法实例化类型Rankup - 第 61 行我不太明白为什么会发生这种情况:

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 插件,我试图让它找到运行命令/rankup 的用户组。

最佳答案

您已将“rankup”类声明为抽象类。这意味着您无法像在 registerCommand 方法中尝试那样通过“new”实例化它。您需要创建一个Rankup的具体子类来实现您的抽象方法并实例化它。

关于java - 无法实例化类型Rankup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38770844/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com