本帖最后由 1582952890 于 2017-9-16 17:50 编辑 
或者你可以直接复制这些东西到一个新的java类里
如果你要做一个带自定义描述和名称的物品一般情况是这样的
ItemStack item = new ItemStack(1);或者ItemStack item = new ItemStack(Material.STONE);ItemMeta meta = item.getItemMeta();meta.setDisplayName("石头");List<String>list = new ArrayList<String>();list.add("这是一个普通的石头");list.add("我编不下去了...");meta.setLore(list);item.setItemMeta(meta);
这种代码量简直烦得要死啊,尤其是当你弄好之后,在其他的地方想要“突发奇想”再给它加一行描述行的时候...你还得这样
ItemMeta meta = item.getItemMeta();List<String>lore = meta.getLore();lore.add("这块石头又添加了一个描述行");meta.setLore(lore);Item.setItemMeta(meta);
这么多行就算我打字快也感觉很烦。。。因此,寡人的懒人化JAVA小工具出场了~它能让你少打一些代码比如创建一块石头变成了这么简单的几行字:
ItemBuilder item = new ItemBuilder(1).setDisplay("石头");item.addLore("这是一个普通的石头");item.addLore("我编不下去了...");
你也可以连起来写,不过看起来不太规整。。
ItemBuilder item = new ItemBuilder(1).setDisplay("石头").addLore("这是一个普通的石头").addLore("我编不下去了...");
附魔也是可以的:
item.enchant(Enchantment.ARROW_DAMAGE, 2);item.removeEnchant(Enchantment.ARROW_DAMAGE);
最后等你添加好自己喜欢的东西之后在用它的时候把它换成item.create()就可以了举个例子:player.getInventory().addItem(item.create());是不是很简单?如果你想修改一个已有的ItemStack,也是可以的ItemStack item = new ItemStack(Material.STONE, 1, (short) 1);ItemBuilder builder = new ItemBuilder(item);然后去修改你的东西吧~~
下载地址:
链接:http://pan.baidu.com/s/1boHNw3X 密码:0vsr
(注意:下载下来是一个.java后缀的源码,直接扔到你的插件所在的的包里,再改一下package声明就行了)
或者你可以直接复制这些东西到一个新的java类里
详细使用说明:
要创建一个ItemBuilder有很多种方法1.用物品id创建:new ItemBuilder(物品id);如果你想创建像染料一样有分号后面id的物品new ItemBuilder(物品id, 分号后面那个物品id);2.用Material创建new ItemBuilder(Material.方块名称);3.用已有的ItemStack创建new ItemBuilder(你的ItemStack);
给你的物品设置数量(如果不设置默认是一个):ItemBuilder item = new ItemBuilder(1);(下面我都用item表示itembuilder的实例,就不创建新的了)item.setCount(数量);
设置名称:item.setDisplay(随便写);
设置描述行:1.添加一个描述行:item.add(随便写);2.添加一群描述行:List<String>lore = new ArrayList<String>();lore.add(第一行);lore.add(第二行);item.addLore(lore);无特殊情况的话这种方法不如第一种简单3.设置描述行:item.setLore(lore);这会清空原有描述行,设置成新的
获取各种数据:
String name = item.getDisplay();int count = item.getCount();List<String>lore = item.getLore();String loreline = item.getLore(2);(2为索引,如果是第3行应该填2,以此类推)
附魔相关:
判断是否有附魔:1.是否有附魔:boolean hasench = item.hasEnchant();2.是否有指定类型的附魔boolean hasench = item.hasEnchant(附魔种类);3.获取指定附魔的等级(没有的话就为0)int level = item.getEnchantLevel(附魔种类);
添加附魔:1.增加一级特定种类的附魔(如果原来没有就升到一级)item.enchant(附魔种类);2.设定这个种类的附魔的等级item.enchant(附魔种类, 等级);3.删除一个种类的附魔item.removeEnchant(附魔种类);
消耗物品:ItemBuilder.consumeItem(player);这个功能是给我自己的服务器用的,用来让一个玩家手中的物品数量-1
而且所有方法都可以连起来写:item.setDisplay(名字).addLore(描述).enchant(某附魔).create();一气呵成
使用方法就是这些,感谢那些把所有内容看完再关掉网页的人。
这是一个轻量的小插件
能让插件开发者更方便创建物品。
如果你要做一个带自定义描述和名称的物品
一般情况是这样的
ItemStack item = new ItemStack(1);或者ItemStack item = new ItemStack(Material.STONE);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("石头");
List<String>list = new ArrayList<String>();
list.add("这是一个普通的石头");
list.add("我编不下去了...");
meta.setLore(list);
item.setItemMeta(meta);
这种代码量简直烦得要死啊,尤其是当你弄好之后,在其他的地方想要“突发奇想”再给它加一行描述行的时候...
你还得这样
ItemMeta meta = item.getItemMeta();
List<String>lore = meta.getLore();
lore.add("这块石头又添加了一个描述行");
meta.setLore(lore);
Item.setItemMeta(meta);
这么多行就算我打字快也感觉很烦。。。
因此,寡人的懒人化JAVA小工具出场了~
它能让你少打一些代码
比如创建一块石头变成了这么简单的几行字:
ItemBuilder item = new ItemBuilder(1).setDisplay("石头");
item.addLore("这是一个普通的石头");
item.addLore("我编不下去了...");
你也可以连起来写,不过看起来不太规整。。
ItemBuilder item = new ItemBuilder(1).setDisplay("石头").addLore("这是一个普通的石头").addLore("我编不下去了...");
附魔也是可以的:
item.enchant(Enchantment.ARROW_DAMAGE, 2);
item.removeEnchant(Enchantment.ARROW_DAMAGE);
最后等你添加好自己喜欢的东西之后
在用它的时候把它换成item.create()就可以了
举个例子:
player.getInventory().addItem(item.create());
是不是很简单?
如果你想修改一个已有的ItemStack,也是可以的
ItemStack item = new ItemStack(Material.STONE, 1, (short) 1);
ItemBuilder builder = new ItemBuilder(item);
然后去修改你的东西吧~~
下载地址:
链接:http://pan.baidu.com/s/1boHNw3X 密码:0vsr
(注意:下载下来是一个.java后缀的源码,直接扔到你的插件所在的的包里,再改一下package声明就行了)
或者你可以直接复制这些东西到一个新的java类里
详细使用说明:
要创建一个ItemBuilder有很多种方法
1.用物品id创建:
new ItemBuilder(物品id);
如果你想创建像染料一样有分号后面id的物品
new ItemBuilder(物品id, 分号后面那个物品id);
2.用Material创建
new ItemBuilder(Material.方块名称);
3.用已有的ItemStack创建
new ItemBuilder(你的ItemStack);
给你的物品设置数量(如果不设置默认是一个):
ItemBuilder item = new ItemBuilder(1);
(下面我都用item表示itembuilder的实例,就不创建新的了)
item.setCount(数量);
设置名称:
item.setDisplay(随便写);
设置描述行:
1.添加一个描述行:
item.add(随便写);
2.添加一群描述行:
List<String>lore = new ArrayList<String>();
lore.add(第一行);
lore.add(第二行);
item.addLore(lore);
无特殊情况的话这种方法不如第一种简单
3.设置描述行:
item.setLore(lore);
这会清空原有描述行,设置成新的
获取各种数据:
String name = item.getDisplay();
int count = item.getCount();
List<String>lore = item.getLore();
String loreline = item.getLore(2);(2为索引,如果是第3行应该填2,以此类推)
附魔相关:
判断是否有附魔:
1.是否有附魔:
boolean hasench = item.hasEnchant();
2.是否有指定类型的附魔
boolean hasench = item.hasEnchant(附魔种类);
3.获取指定附魔的等级(没有的话就为0)
int level = item.getEnchantLevel(附魔种类);
添加附魔:
1.增加一级特定种类的附魔(如果原来没有就升到一级)
item.enchant(附魔种类);
2.设定这个种类的附魔的等级
item.enchant(附魔种类, 等级);
3.删除一个种类的附魔
item.removeEnchant(附魔种类);
消耗物品:
ItemBuilder.consumeItem(player);
这个功能是给我自己的服务器用的,用来让一个玩家手中的物品数量-1
而且所有方法都可以连起来写:
item.setDisplay(名字).addLore(描述).enchant(某附魔).create();
一气呵成
使用方法就是这些,感谢那些把所有内容看完再关掉网页的人。
2021.12 数据,可能有更多内容
这是一个轻量的小插件能让插件开发者更方便创建物品。如果你要做一个带自定义描述和名称的物品一般情况是这样的
ItemStack item = new ItemStack(1);或者ItemStack item = new ItemStack(Material.STONE);ItemMeta meta = item.getItemMeta();meta.setDisplayName("石头");List<String>list = new ArrayList<String>();list.add("这是一个普通的石头");list.add("我编不下去了...");meta.setLore(list);item.setItemMeta(meta);
这种代码量简直烦得要死啊,尤其是当你弄好之后,在其他的地方想要“突发奇想”再给它加一行描述行的时候...你还得这样
ItemMeta meta = item.getItemMeta();List<String>lore = meta.getLore();lore.add("这块石头又添加了一个描述行");meta.setLore(lore);Item.setItemMeta(meta);
这么多行就算我打字快也感觉很烦。。。因此,寡人的懒人化JAVA小工具出场了~它能让你少打一些代码比如创建一块石头变成了这么简单的几行字:
ItemBuilder item = new ItemBuilder(1).setDisplay("石头");item.addLore("这是一个普通的石头");item.addLore("我编不下去了...");
你也可以连起来写,不过看起来不太规整。。
ItemBuilder item = new ItemBuilder(1).setDisplay("石头").addLore("这是一个普通的石头").addLore("我编不下去了...");
附魔也是可以的:
item.enchant(Enchantment.ARROW_DAMAGE, 2);item.removeEnchant(Enchantment.ARROW_DAMAGE);
最后等你添加好自己喜欢的东西之后在用它的时候把它换成item.create()就可以了举个例子:player.getInventory().addItem(item.create());是不是很简单?如果你想修改一个已有的ItemStack,也是可以的ItemStack item = new ItemStack(Material.STONE, 1, (short) 1);ItemBuilder builder = new ItemBuilder(item);然后去修改你的东西吧~~
下载地址:
链接:http://pan.baidu.com/s/1boHNw3X 密码:0vsr
(注意:下载下来是一个.java后缀的源码,直接扔到你的插件所在的的包里,再改一下package声明就行了)
或者你可以直接复制这些东西到一个新的java类里
代码:
- <div>package woPH.function;</div><div>
 
- </div><div>import java.util.ArrayList;
 
- import java.util.HashMap;
 
- import java.util.List;
 
- import java.util.Map;</div><div>import org.bukkit.Material;
 
- import org.bukkit.enchantments.Enchantment;
 
- import org.bukkit.entity.Player;
 
- import org.bukkit.inventory.ItemStack;
 
- import org.bukkit.inventory.PlayerInventory;
 
- import org.bukkit.inventory.meta.ItemMeta;</div><div>
 
- </div><div>public class ItemBuilder{
 
-  List<String>lore = new ArrayList<String>();
 
-  String name = null;
 
-  int id;
 
-  int count = 1;
 
-  short id2 = 0;
 
-  Map<Enchantment, Integer>ench = null;
 
-  
 
-  public ItemBuilder(int id){
 
- this.id = id;
 
-  }
 
-  @SuppressWarnings("deprecation")
 
-  public ItemBuilder(Material material){
 
- this.id = material.getId();
 
-  }
 
-  public ItemBuilder(int id, int id2){
 
- this.id = id;
 
- this.id2 = (short) id2;
 
-  }
 
-  @SuppressWarnings("deprecation")
 
-  public ItemBuilder(ItemStack item){
 
- id = item.getTypeId();
 
- id2 = item.getDurability();
 
- ItemMeta meta = item.getItemMeta();
 
- if(meta.hasDisplayName()){
 
-    name = meta.getDisplayName();
 
- }else{
 
-    name = null;
 
- }
 
- if(meta.hasLore()){
 
-    lore = meta.getLore();
 
- }else{
 
-    lore = new ArrayList<String>();
 
- }
 
- if(item.getItemMeta().hasEnchants()){
 
-    ench = meta.getEnchants();
 
- }
 
-  }
 
-  public ItemStack create(){
 
- @SuppressWarnings("deprecation")
 
- ItemStack item = new ItemStack(id, count, (short) id2);
 
- ItemMeta meta = item.getItemMeta();
 
- if(!(name == null)){
 
-    meta.setDisplayName(name);
 
- }
 
- if(!lore.isEmpty()){
 
-    meta.setLore(lore);
 
- }
 
- item.setItemMeta(meta);
 
- if(!(ench == null)){
 
-    item.addEnchantments(ench);
 
- }
 
- return item;
 
-  }
 
-  public int getCount(){
 
- return count;
 
-  }
 
-  public ItemBuilder setCount(int count){
 
- if(count > 0){
 
-    this.count = count;
 
- }
 
- return this;
 
-  }
 
-  public String getDisplay(){
 
- return name;
 
-  }
 
-  public ItemBuilder setDisplay(String Display){
 
- name = Display;
 
- return this;
 
-  }
 
-  public List<String> getLore(){
 
- return lore;
 
-  }
 
-  public String getLore(int index){
 
- if(lore.size() >= index - 1){
 
-    return lore.get(index);
 
- }else{
 
-    return null;
 
- }
 
-  }
 
-  public ItemBuilder setLore(List<String> Lore){
 
- this.lore = Lore;
 
- return this;
 
-  }
 
-  public ItemBuilder addLore(List<String> Lore){
 
- lore.addAll(Lore);
 
- return this;
 
-  }
 
-  public ItemBuilder addLore(String Line){
 
- lore.add(Line);
 
- return this;
 
-  }
 
-  public Map<Enchantment, Integer> getEnchant(){
 
- return this.ench;
 
-  }
 
-  public boolean hasEnchant(Enchantment enchant){
 
- if(!hasEnchant()){
 
-    return false;
 
- }else{
 
-    return ench.containsKey(enchant);
 
- }
 
-  }
 
-  public boolean hasEnchant(){
 
- if(ench == null){
 
-    return false;
 
- }else{
 
-    return !ench.isEmpty();
 
- }
 
-  }
 
-  public int getEnchantLevel(Enchantment enchant){
 
- if(!hasEnchant(enchant)){
 
-    return 0;
 
- }else{
 
-    return ench.get(enchant);
 
- }
 
-  }
 
-  public ItemBuilder enchant(Enchantment enchant, int level){
 
- if(ench == null){
 
-    ench = new HashMap<Enchantment, Integer>();
 
- }
 
- ench.put(enchant, level);
 
- return this;
 
-  }
 
-  public ItemBuilder enchant(Enchantment enchant){
 
- if(ench == null){
 
-    ench = new HashMap<Enchantment, Integer>();
 
- }else if(ench.containsKey(enchant)){
 
-    ench.put(enchant, ench.get(enchant) + 1);
 
- }else{
 
-    ench.put(enchant, 1);
 
- }
 
- return this;
 
-  }
 
-  public ItemBuilder removeEnchant(Enchantment enchant){
 
- if(ench == null){
 
-    return this;
 
- }
 
- ench.remove(enchant);
 
- return this;
 
-  }
 
-  public static void consumeItem(Player player){
 
- PlayerInventory inv = player.getInventory();
 
- ItemStack item = inv.getItemInHand();
 
- short amount = (short) (item.getAmount() - 1);
 
- if(amount <= 0){
 
-    inv.clear(inv.getHeldItemSlot());
 
- }else{
 
-    item.setAmount(amount);
 
-    inv.setItem(inv.getHeldItemSlot(), item);
 
- }
 
-  }
 
- }</div>
详细使用说明:
要创建一个ItemBuilder有很多种方法1.用物品id创建:new ItemBuilder(物品id);如果你想创建像染料一样有分号后面id的物品new ItemBuilder(物品id, 分号后面那个物品id);2.用Material创建new ItemBuilder(Material.方块名称);3.用已有的ItemStack创建new ItemBuilder(你的ItemStack);
给你的物品设置数量(如果不设置默认是一个):ItemBuilder item = new ItemBuilder(1);(下面我都用item表示itembuilder的实例,就不创建新的了)item.setCount(数量);
设置名称:item.setDisplay(随便写);
设置描述行:1.添加一个描述行:item.add(随便写);2.添加一群描述行:List<String>lore = new ArrayList<String>();lore.add(第一行);lore.add(第二行);item.addLore(lore);无特殊情况的话这种方法不如第一种简单3.设置描述行:item.setLore(lore);这会清空原有描述行,设置成新的
获取各种数据:
String name = item.getDisplay();int count = item.getCount();List<String>lore = item.getLore();String loreline = item.getLore(2);(2为索引,如果是第3行应该填2,以此类推)
附魔相关:
判断是否有附魔:1.是否有附魔:boolean hasench = item.hasEnchant();2.是否有指定类型的附魔boolean hasench = item.hasEnchant(附魔种类);3.获取指定附魔的等级(没有的话就为0)int level = item.getEnchantLevel(附魔种类);
添加附魔:1.增加一级特定种类的附魔(如果原来没有就升到一级)item.enchant(附魔种类);2.设定这个种类的附魔的等级item.enchant(附魔种类, 等级);3.删除一个种类的附魔item.removeEnchant(附魔种类);
消耗物品:ItemBuilder.consumeItem(player);这个功能是给我自己的服务器用的,用来让一个玩家手中的物品数量-1
而且所有方法都可以连起来写:item.setDisplay(名字).addLore(描述).enchant(某附魔).create();一气呵成
使用方法就是这些,感谢那些把所有内容看完再关掉网页的人。
不错哦~支持
世界之冠 发表于 2017-1-7 11:12
不错哦~支持
谢谢支持~刚发帖就有人回,感谢感谢
支持原创插件!
 本帖最后由 Java_command 于 2017-1-6 15:34 编辑 
也就是说直接跟自己的插件源码放在一起就可以了~
算是一个不错的“插件”吧
也就是说直接跟自己的插件源码放在一起就可以了~
算是一个不错的“插件”吧