Bukkit 创建自定义方法。问题
Bukkit creating a custom method. Problems
我正在尝试创建一种方法,让我可以更轻松地添加项目并更轻松地创建库存。这是我的代码。
每当我右键单击我的荧石粉时,就会出现一个问题,它会抛出一个 eventexception 错误,我不确定为什么。每当有人右键单击萤石粉时,它应该执行以下操作,它应该打开一个名为 "Gadgets" 的绿色物品栏。库存中有一件名为 "HidePlayers"
的物品
错误
[01:25:55 ERROR]: Could not pass event PlayerInteractEvent to KnoxHub v1.0
org.bukkit.event.EventException
at org.bukkit.plugin.java.JavaPluginLoader.execute(JavaPluginLoader.ja
va:310) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
a:62) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
ava:502) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
ava:487) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInte
ractEvent(CraftEventFactory.java:227) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git
-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInte
ractEvent(CraftEventFactory.java:194) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git
-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInte
ractEvent(CraftEventFactory.java:190) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git
-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
:694) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlo
ckPlace.java:52) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91ae
d8]
at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlo
ckPlace.java:1) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed
8]
at net.minecraft.server.v1_8_R3.PlayerConnectionUtils.run(SourceFile:1
3) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
?:1.8.0_51]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_51]
at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [spig
ot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:7
18) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
67) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
57) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
:560) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
Caused by: java.lang.IllegalArgumentException: Chests must have a size that is a
multiple of 9!
at org.apache.commons.lang.Validate.isTrue(Validate.java:136) ~[spigot-1
.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.createInventory(CraftServe
r.java:1525) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.Bukkit.createInventory(Bukkit.java:937) ~[spigot-1.8.7-R0.
1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at crypted.knoxhub.Gadgets.GadgetCore.KInventoryCreate(GadgetCore.java:3
5) ~[?:?]
at crypted.knoxhub.Gadgets.GadgetCore.AddGadget(GadgetCore.java:42) ~[?:
?]
at crypted.knoxhub.Gadgets.GadgetCore.Interact(GadgetCore.java:66) ~[?:?
]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
.8.0_51]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51]
at org.bukkit.plugin.java.JavaPluginLoader.execute(JavaPluginLoader.ja
va:306) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
... 18 more
>
GadgetCore.Java
private Core Plugin;
public GadgetCore(Core p){ this.Plugin = p; }
//Inventories
public Inventory GadgetMenu;
// Simple Inventory Creation
public Inventory KInventoryCreate( int slots, String invname ) throws IOException {
return Bukkit.createInventory(null, slots, invname);
}
// Simple Gadget Creation
public void AddGadget(Player player,int position ,String permission, ItemStack item, String GadgetItemName, String lore) throws IOException {
GadgetMenu = KInventoryCreate(10, ChatColor.GREEN + "Gadgets");
if ( !player.hasPermission(permission) ) {
player.sendMessage( ChatColor.RED + GadgetItemName.toUpperCase() + ChatColor.YELLOW + " can only be used by specific Ranks");
return;
}
GadgetMenu.setItem(position, Plugin.applyLore(item, GadgetItemName, lore));
}
@EventHandler
public void Interact(PlayerInteractEvent e) throws IOException{
Player p = e.getPlayer();
ItemStack item = p.getItemInHand();
if ( e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK) ) {
if ( item.getType().equals(Material.GLOWSTONE_DUST)) {
e.setCancelled(true);
AddGadget(p, 3, "gadget.hide", new ItemStack(Material.GLOWSTONE_DUST), "HidePlayers", ChatColor.GRAY + "d");
p.openInventory(GadgetMenu);
p.sendMessage("Debug");
}
}
}
@EventHandler
public void Debug(PlayerInteractEvent e) throws IOException{
Player p = e.getPlayer();
ItemStack item = p.getItemInHand();
if ( e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK) ) {
if ( item.getType().equals(Material.REDSTONE) ) {
e.setCancelled(true);
p.openInventory(GadgetMenu);
p.sendMessage("Debug");
}
}
}
Core.Java
public class Core extends JavaPlugin implements Listener {
public Core plugin;
public GadgetCore gc;
public ItemStack applyLore(ItemStack stack, String name, String lore1){
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(name);
ArrayList<String> lore = new ArrayList<String>();
lore.add(lore1);
meta.setLore(lore);
stack.setItemMeta(meta);
return stack;
}
public void onEnable(){
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[KnoxHub] created by 2hash");
// Bukkit.getPluginManager().registerEvents(new );
getServer().getPluginManager().registerEvents(new GadgetCore(this), this);
}
}
在堆栈跟踪中:
Caused by: java.lang.IllegalArgumentException: Chests must have a size that is a
multiple of 9!
Stacktraces 是您的朋友!如果您想了解如何理解错误消息并自行调试,请阅读此文:。
不过,要解决您的具体问题,您可能只需要将 AddGadget
方法这一行中的 10
更改为 9
或另一个数量的倍数作为库存总是有 9 列,因此创建大小为 9 的清单将使 9 列乘 1 行,如果有 18 个插槽,则为 9x2,27 为 9x3,依此类推。
GadgetMenu = KInventoryCreate(10, ChatColor.GREEN + "Gadgets");
不过更好的是,只需修改您的 KInventoryCreate
方法和 return 像这样 Bukkit.createInventory(null, 9*rows, invname);
而不是原始插槽编号,这样您就可以安全地制作它又是同样的错误。
我正在尝试创建一种方法,让我可以更轻松地添加项目并更轻松地创建库存。这是我的代码。 每当我右键单击我的荧石粉时,就会出现一个问题,它会抛出一个 eventexception 错误,我不确定为什么。每当有人右键单击萤石粉时,它应该执行以下操作,它应该打开一个名为 "Gadgets" 的绿色物品栏。库存中有一件名为 "HidePlayers"
的物品错误
[01:25:55 ERROR]: Could not pass event PlayerInteractEvent to KnoxHub v1.0
org.bukkit.event.EventException
at org.bukkit.plugin.java.JavaPluginLoader.execute(JavaPluginLoader.ja
va:310) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
a:62) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
ava:502) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
ava:487) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInte
ractEvent(CraftEventFactory.java:227) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git
-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInte
ractEvent(CraftEventFactory.java:194) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git
-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInte
ractEvent(CraftEventFactory.java:190) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git
-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
:694) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlo
ckPlace.java:52) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91ae
d8]
at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlo
ckPlace.java:1) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed
8]
at net.minecraft.server.v1_8_R3.PlayerConnectionUtils.run(SourceFile:1
3) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
?:1.8.0_51]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_51]
at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [spig
ot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:7
18) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
67) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
57) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
:560) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
Caused by: java.lang.IllegalArgumentException: Chests must have a size that is a
multiple of 9!
at org.apache.commons.lang.Validate.isTrue(Validate.java:136) ~[spigot-1
.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.createInventory(CraftServe
r.java:1525) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.Bukkit.createInventory(Bukkit.java:937) ~[spigot-1.8.7-R0.
1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at crypted.knoxhub.Gadgets.GadgetCore.KInventoryCreate(GadgetCore.java:3
5) ~[?:?]
at crypted.knoxhub.Gadgets.GadgetCore.AddGadget(GadgetCore.java:42) ~[?:
?]
at crypted.knoxhub.Gadgets.GadgetCore.Interact(GadgetCore.java:66) ~[?:?
]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
.8.0_51]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51]
at org.bukkit.plugin.java.JavaPluginLoader.execute(JavaPluginLoader.ja
va:306) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
... 18 more
>
GadgetCore.Java
private Core Plugin;
public GadgetCore(Core p){ this.Plugin = p; }
//Inventories
public Inventory GadgetMenu;
// Simple Inventory Creation
public Inventory KInventoryCreate( int slots, String invname ) throws IOException {
return Bukkit.createInventory(null, slots, invname);
}
// Simple Gadget Creation
public void AddGadget(Player player,int position ,String permission, ItemStack item, String GadgetItemName, String lore) throws IOException {
GadgetMenu = KInventoryCreate(10, ChatColor.GREEN + "Gadgets");
if ( !player.hasPermission(permission) ) {
player.sendMessage( ChatColor.RED + GadgetItemName.toUpperCase() + ChatColor.YELLOW + " can only be used by specific Ranks");
return;
}
GadgetMenu.setItem(position, Plugin.applyLore(item, GadgetItemName, lore));
}
@EventHandler
public void Interact(PlayerInteractEvent e) throws IOException{
Player p = e.getPlayer();
ItemStack item = p.getItemInHand();
if ( e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK) ) {
if ( item.getType().equals(Material.GLOWSTONE_DUST)) {
e.setCancelled(true);
AddGadget(p, 3, "gadget.hide", new ItemStack(Material.GLOWSTONE_DUST), "HidePlayers", ChatColor.GRAY + "d");
p.openInventory(GadgetMenu);
p.sendMessage("Debug");
}
}
}
@EventHandler
public void Debug(PlayerInteractEvent e) throws IOException{
Player p = e.getPlayer();
ItemStack item = p.getItemInHand();
if ( e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK) ) {
if ( item.getType().equals(Material.REDSTONE) ) {
e.setCancelled(true);
p.openInventory(GadgetMenu);
p.sendMessage("Debug");
}
}
}
Core.Java
public class Core extends JavaPlugin implements Listener {
public Core plugin;
public GadgetCore gc;
public ItemStack applyLore(ItemStack stack, String name, String lore1){
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(name);
ArrayList<String> lore = new ArrayList<String>();
lore.add(lore1);
meta.setLore(lore);
stack.setItemMeta(meta);
return stack;
}
public void onEnable(){
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[KnoxHub] created by 2hash");
// Bukkit.getPluginManager().registerEvents(new );
getServer().getPluginManager().registerEvents(new GadgetCore(this), this);
}
}
在堆栈跟踪中:
Caused by: java.lang.IllegalArgumentException: Chests must have a size that is a
multiple of 9!
Stacktraces 是您的朋友!如果您想了解如何理解错误消息并自行调试,请阅读此文:。
不过,要解决您的具体问题,您可能只需要将 AddGadget
方法这一行中的 10
更改为 9
或另一个数量的倍数作为库存总是有 9 列,因此创建大小为 9 的清单将使 9 列乘 1 行,如果有 18 个插槽,则为 9x2,27 为 9x3,依此类推。
GadgetMenu = KInventoryCreate(10, ChatColor.GREEN + "Gadgets");
不过更好的是,只需修改您的 KInventoryCreate
方法和 return 像这样 Bukkit.createInventory(null, 9*rows, invname);
而不是原始插槽编号,这样您就可以安全地制作它又是同样的错误。