Witam po wpisaniu komendy wyskakuje mi blad "An internal error occured while attempting to perform this command", zamiast wiadomosci z klasy Lang. Co zrobic?
Kod pluginu:
package pl.unixhc.tools.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import pl.unixhc.tools.config.Lang;
import pl.unixhc.tools.managers.CommandManager;
import pl.unixhc.tools.utils.Util;
public class InvseeCommand extends CommandManager{
public InvseeCommand(){
super("invsee", true, "unixhc.invsee", "Otwiera ekwipunek gracza", "/invsee [nick]", new String[0]);
}
public boolean exe(CommandSender sender, String command, String[] args){
if (args.length < 1){
Util.sendUsage(sender, getUsage());
return false;
}
Player playerInv = Bukkit.getPlayer(args[0]);
if (playerInv == null){
sender.sendMessage(Lang.getInst().PLAYER_NOT_EXISTS);
return false;
}
Player player = (Player)sender;
player.openInventory(playerInv.getInventory());
return true;
}
}
Main:
package pl.unixhc.tools;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import pl.unixhc.tools.commands.*;
import pl.unixhc.tools.listeners.*;
public class Main extends JavaPlugin{
private static Main inst;
public void onEnable(){
registerCommands();
registerListeners();
saveDefaultConfig();
}
public static Main getInst(){
return inst;
}
public void registerCommands(){
new InvseeCommand().register();
}
public void registerListeners(){
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new ProtectPluginsListener(), this);
pm.registerEvents(new AsyncPlayerChatListener(), this);;
pm.registerEvents(new BlockPlaceListener(), this);
pm.registerEvents(new SignColorListener(), this);
}
}
Lang:
package pl.unixhc.tools.config;
public class Lang{
private static Lang inst;
public String USAGE;
public String PERMISSION;
public String PLAYER_NOT_EXISTS;
public String INVENTORY_OPENED;
public String COMMAND_PLAYER;
public static Lang getInst(){
if(inst == null){
new Lang();
}
return inst;
}
public Lang(){
this.PERMISSION = "&4Nie masz uprawnien.";
this.PLAYER_NOT_EXISTS = "&4Ten gracz jest offline.";
this.INVENTORY_OPENED = "&aOtworzono ekwipunek gracza {PLAYER}";
this.USAGE = "&cPoprawne uzycie: {USAGE}.";
this.COMMAND_PLAYER = "&4Ta komenda jest dostepna tylko dla gracza.";
}
}
Util:
package pl.unixhc.tools.utils;
import org.bukkit.command.CommandSender;
import pl.unixhc.tools.config.Lang;
public class Util {
public static boolean sendMessage(CommandSender sender, String message)
{
sender.sendMessage(message);
return true;
}
public static boolean sendPermission(CommandSender sender, String permission)
{
sender.sendMessage(Lang.getInst().PERMISSION.replace("{PERM}", permission));
return true;
}
public static boolean sendUsage(CommandSender sender, String usage)
{
sender.sendMessage(Lang.getInst().USAGE.replace("{USAGE}", usage));
return true;
}
}
null
org.bukkit.command.CommandException: Unhandled exception executing 'invsee' in pl.unixhc.tools.commands.InvseeCommand(invsee)
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:148) ~[Silnik.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[Silnik.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [Silnik.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [Silnik.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [Silnik.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [Silnik.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [Silnik.jar:git-Spigot-db6de12-18fbb24]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_161]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_161]
at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [Silnik.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [Silnik.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [Silnik.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [Silnik.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [Silnik.jar:git-Spigot-db6de12-18fbb24]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_161]
Caused by: java.lang.NullPointerException
at pl.unixhc.tools.utils.Util.sendPermission(Util.java:20) ~[?:?]
at pl.unixhc.tools.managers.CommandManager.execute(CommandManager.java:41) ~[?:?]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[Silnik.jar:git-Spigot-db6de12-18fbb24]
... 14 more
Pytanie
4RNI 13
Witam po wpisaniu komendy wyskakuje mi blad "An internal error occured while attempting to perform this command", zamiast wiadomosci z klasy Lang. Co zrobic?
Kod pluginu:
package pl.unixhc.tools.commands; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import pl.unixhc.tools.config.Lang; import pl.unixhc.tools.managers.CommandManager; import pl.unixhc.tools.utils.Util; public class InvseeCommand extends CommandManager{ public InvseeCommand(){ super("invsee", true, "unixhc.invsee", "Otwiera ekwipunek gracza", "/invsee [nick]", new String[0]); } public boolean exe(CommandSender sender, String command, String[] args){ if (args.length < 1){ Util.sendUsage(sender, getUsage()); return false; } Player playerInv = Bukkit.getPlayer(args[0]); if (playerInv == null){ sender.sendMessage(Lang.getInst().PLAYER_NOT_EXISTS); return false; } Player player = (Player)sender; player.openInventory(playerInv.getInventory()); return true; } }
Main:
package pl.unixhc.tools; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import pl.unixhc.tools.commands.*; import pl.unixhc.tools.listeners.*; public class Main extends JavaPlugin{ private static Main inst; public void onEnable(){ registerCommands(); registerListeners(); saveDefaultConfig(); } public static Main getInst(){ return inst; } public void registerCommands(){ new InvseeCommand().register(); } public void registerListeners(){ PluginManager pm = Bukkit.getPluginManager(); pm.registerEvents(new ProtectPluginsListener(), this); pm.registerEvents(new AsyncPlayerChatListener(), this);; pm.registerEvents(new BlockPlaceListener(), this); pm.registerEvents(new SignColorListener(), this); } }
Lang:
package pl.unixhc.tools.config; public class Lang{ private static Lang inst; public String USAGE; public String PERMISSION; public String PLAYER_NOT_EXISTS; public String INVENTORY_OPENED; public String COMMAND_PLAYER; public static Lang getInst(){ if(inst == null){ new Lang(); } return inst; } public Lang(){ this.PERMISSION = "&4Nie masz uprawnien."; this.PLAYER_NOT_EXISTS = "&4Ten gracz jest offline."; this.INVENTORY_OPENED = "&aOtworzono ekwipunek gracza {PLAYER}"; this.USAGE = "&cPoprawne uzycie: {USAGE}."; this.COMMAND_PLAYER = "&4Ta komenda jest dostepna tylko dla gracza."; } }
Util:
package pl.unixhc.tools.utils; import org.bukkit.command.CommandSender; import pl.unixhc.tools.config.Lang; public class Util { public static boolean sendMessage(CommandSender sender, String message) { sender.sendMessage(message); return true; } public static boolean sendPermission(CommandSender sender, String permission) { sender.sendMessage(Lang.getInst().PERMISSION.replace("{PERM}", permission)); return true; } public static boolean sendUsage(CommandSender sender, String usage) { sender.sendMessage(Lang.getInst().USAGE.replace("{USAGE}", usage)); return true; } }
CommandManager:
Log z konsoli:
null org.bukkit.command.CommandException: Unhandled exception executing 'invsee' in pl.unixhc.tools.commands.InvseeCommand(invsee) at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:148) ~[Silnik.jar:git-Spigot-db6de12-18fbb24] at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[Silnik.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [Silnik.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [Silnik.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [Silnik.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [Silnik.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [Silnik.jar:git-Spigot-db6de12-18fbb24] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_161] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_161] at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [Silnik.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [Silnik.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [Silnik.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [Silnik.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [Silnik.jar:git-Spigot-db6de12-18fbb24] at java.lang.Thread.run(Unknown Source) [?:1.8.0_161] Caused by: java.lang.NullPointerException at pl.unixhc.tools.utils.Util.sendPermission(Util.java:20) ~[?:?] at pl.unixhc.tools.managers.CommandManager.execute(CommandManager.java:41) ~[?:?] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[Silnik.jar:git-Spigot-db6de12-18fbb24] ... 14 more
Odnośnik do komentarza
Udostępnij na innych stronach
1 odpowiedź na to pytanie
Rekomendowane odpowiedzi