服务器所有者要我为服务器编写一个简单的插件。它需要的是,如果你手持书面书点击书架,它将打开一个箱子。当这个人关闭那个胸部时,放在里面的所有书都会被摧毁。
我理解bukkit插件开发的基础知识,但是website上的说明非常复杂。我知道我必须注意手中的玩家项目确实是一本带有此代码的书:
Player player = event.getPlayer();
if (player.getItemInHand().getType() == Material.WRITTEN_BOOK) {
// Do other stuff in here
}
但是,如果插件更容易成为按下的按钮并且手中的书被销毁,请您告诉我并帮助我完成这些步骤。
答案 0 :(得分:0)
你可以听PlayerInteractEvent
,检查他们是否右键点击书架,然后打开一个箱子GUI
......你可以这样做:
@EventHandler //ALWAYS use this before events
public void playerInteract(PlayerInteractEvent e){ //listen for PlayerInteractEvent
if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK){ //make sure the player right-clicked a block
if(e.getClickedBlock().getType().equals(Material.BOOKSHELF)){ //make sure the player right-clicked a bookshelf
Player p = e.getPlayer(); //get the player
if(p.getItemInHand() != null){ //make sure the player has something in their hand
if(p.getItemInHand().getType().equals(Material.WRITTEN_BOOK)){ //check if the player has a written book in their inventory
//Inventory inv = Bukkit.createInventory(null, <size (should be divisible by 9)>, "name"); //create the inventory
//An example of creating the inventory would be:
Inventory inv = Bukkit.createInventory(null, 36, "Disposal");
}
}
}
}
}
这应该就是你需要做的一切。只需确保使用以下方法在onEnable()
方法中注册事件:
this.getServer().getPluginManager().registerEvents(new HandlerClassName(), this);
并确保处理程序类implements Listener
。
基本上,上面的第一个代码是:
PlayerInteractEvent
Right Clicked
阻止Book Shelf
null
Written Book
Disposal
个广告位或36
广告位创建名为9 x 4
的新广告资源。然后,当玩家将物品放入胸部并关闭时,物品将被摧毁!
如果您希望在用户右键单击胸部时删除该书,只需使用:
p.setItemInHand(new ItemStack(Material.AIR));
而不是:
Inventory inv = Bukkit.createInventory(null, 36, "Disposal");