このような他の質問があることは知っていますが、このケースには完全に役立つものはありません。コンストラクタのコマンド()は未定義です - Java/SpigotMC
そこで、基本的
getCommand("minealchemy").setExecutor(new Commands());
を言うライン上で私はこのエラーを取得する:
The constructor Commands() is undefined
任意のヘルプ?私はコマンド...コマンド(ヌル)のために()で「ヌル」を入れると...それから私はNullPointerExceptionエラーを取得...ここ
は私のクラスのすべてです:
メインクラス:
package me.zachbears27;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import me.zachbears27.utils.Commands;
public class Main extends JavaPlugin implements Listener {
@Override
public void onDisable() {
}
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
registerConfig();
getCommand("minealchemy").setExecutor(new Commands());
}
public void registerConfig() {
saveDefaultConfig();
}
}
コマンドクラス:
package me.zachbears27.utils;
import java.io.File;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import me.zachbears27.utils.Methods;
import net.md_5.bungee.api.ChatColor;
public class Commands implements CommandExecutor {
private final Methods methods;
public Commands(Methods methods) {
this.methods = methods;
}
public boolean onCommand(CommandSender sender, Command label, String cmd, String[] args) {
Player p = (Player) sender;
if (cmd.equalsIgnoreCase("minealchemy")) {
if(args.length > 0) {
//Get File
File file = methods.getPlayerFile(p.getUniqueId());
FileConfiguration fileSettings = YamlConfiguration.loadConfiguration(file);
//Make Sure It's False
fileSettings.set("Enabled", false);
//Save Inventory
methods.savePlayerInv(p.getUniqueId(), p.getInventory().getContents());
//Clear It
p.getInventory().clear();
//Put In God Mode
p.setInvulnerable(true);
//Open Inventory
p.openWorkbench(p.getLocation(), true);
} else {
p.sendMessage(ChatColor.RED + "Incorrect Arguments... Please use \"start\" or \"list\".");
}
}
return true;
}
}
のメソッドクラス:
package me.zachbears27.utils;
import java.io.File;
import java.util.ArrayList;
import java.util.UUID;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import me.zachbears27.Main;
import net.md_5.bungee.api.ChatColor;
public class Methods {
private final Main plugin;
public Methods(Main plugin) {
this.plugin = plugin;
}
public ArrayList<String> getAllItems() {
ArrayList<String> allItems = new ArrayList<String>();
//Basics
String Air = ChatColor.GREEN + "Air" + ChatColor.RESET;
String Earth = ChatColor.GREEN + "Earth" + ChatColor.RESET;
String Fire = ChatColor.GREEN + "Fire" + ChatColor.RESET;
String Metal = ChatColor.GREEN + "Metal" + ChatColor.RESET;
String Water = ChatColor.GREEN + "Water" + ChatColor.RESET;
String Motion = ChatColor.GREEN + "Motion" + ChatColor.RESET;
String Big = ChatColor.GREEN + "Big" + ChatColor.RESET;
String Time = ChatColor.GREEN + "Time" + ChatColor.RESET;
String Small = ChatColor.GREEN + "Small" + ChatColor.RESET;
allItems.add(Air);
allItems.add(Earth);
allItems.add(Fire);
allItems.add(Metal);
allItems.add(Water);
allItems.add(Motion);
allItems.add(Big);
allItems.add(Time);
allItems.add(Small);
//Animals
String Cat = ChatColor.GOLD + "Cat" + ChatColor.RESET;
allItems.add(Cat);
return allItems;
}
public String addItems(String item1, String item2) {
String returnStatement = ChatColor.RED + "X";
if(item1.equals("Air") && item2.equals("Fire")) {
returnStatement = "Mist";
}
return returnStatement;
}
public File getPlayerFile(UUID playerUUID) {
//Creates The Player File
File playerFile = new File (plugin.getDataFolder() + File.separator + "Player Data", playerUUID + ".yml");
return playerFile;
}
public void savePlayerInv(UUID playerUUID, ItemStack[] inv) {
File playerFile = getPlayerFile(playerUUID);
FileConfiguration playerData = YamlConfiguration.loadConfiguration(playerFile);
playerData.set("SavedInventory", inv);
}
}
を使用して、新しい '新しいコマンド(新しいメソッド(この))'代わりに。 'thisはあなたの' Main extends JavaPlugin'です。 – i0xHeX
ああ..すごい!それは動作するように見えます!お返事ありがとうございます。 –