本文整理汇总了Java中org.bukkit.inventory.meta.Repairable类的典型用法代码示例。如果您正苦于以下问题:Java Repairable类的具体用法?Java Repairable怎么用?Java Repairable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Repairable类属于org.bukkit.inventory.meta包,在下文中一共展示了Repairable类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: repairInfo
import org.bukkit.inventory.meta.Repairable; //导入依赖的package包/类
@SubCommand(value = "info", permission = "nu.repair")
public void repairInfo(CommandSender sender, Arguments args) {
ItemStack item = getItemInHand(sender);
RepairInstance info = new RepairInstance(item, plugin.cfg.repair, plugin);
new Message(I18n.format("user.repair.info_1")).append(item).send(asPlayer(sender));
msg(sender, "user.repair.info_2", item.getType().name());
if (info.stat != REPAIRABLE) {
msg(sender, "user.repair.info_3", I18n.format("user.repair.unrepairable." + info.stat.name()));
}
if (info.stat == UNREPAIRABLE) return;
int fullDur = item.getType().getMaxDurability();
int currDur = fullDur - item.getDurability();
msg(sender, "user.repair.info_4", currDur, fullDur, (double) currDur / (double) fullDur * 100);
new Message(I18n.format("user.repair.info_5")).append(new ItemStack(info.repairMaterial)).send(asPlayer(sender));
msg(sender, "user.repair.info_6", info.expConsumption);
msg(sender, "user.repair.info_7", info.durRecovered, (double) info.durRecovered / (double) fullDur * 100);
if (info.repairLimit <= 0) {
msg(sender, "user.repair.info_8");
} else {
int repairTime = ((Repairable) item.getItemMeta()).getRepairCost();
msg(sender, "user.repair.info_9", repairTime, info.repairLimit);
}
if (info.stat == REPAIRABLE) {
msg(sender, "user.repair.info_10", (int) Math.ceil(item.getDurability() / (double) info.durRecovered));
}
}
开发者ID:NyaaCat,项目名称:NyaaUtils,代码行数:27,代码来源:RepairCommands.java
示例2: increaseReapirCount
import org.bukkit.inventory.meta.Repairable; //导入依赖的package包/类
private void increaseReapirCount(ItemStack item, int x) {
if (x == 0) return;
ItemMeta meta = item.getItemMeta();
if (meta instanceof Repairable) {
Repairable r = (Repairable) meta;
int count = r.getRepairCost() + x;
if (count < 0) count = 0;
r.setRepairCost(count);
item.setItemMeta(meta);
}
}
开发者ID:NyaaCat,项目名称:NyaaUtils,代码行数:12,代码来源:RepairCommands.java
示例3: RepairInstance
import org.bukkit.inventory.meta.Repairable; //导入依赖的package包/类
public RepairInstance(ItemStack item, RepairConfig config, NyaaUtils plugin) {
if (item == null || item.getType() == Material.AIR) return;
RepairConfig.RepairConfigItem cfg = config.getRepairConfig(item.getType());
if (cfg == null) return;
if (!(item.getItemMeta() instanceof Repairable)) return;
if (item.hasItemMeta() && item.getItemMeta().hasLore()) {
if (!plugin.cfg.globalLoreBlacklist.canRepair(item.getItemMeta().getLore())) {
stat = RepairStat.UNREPAIRABLE;
return;
}
}
stat = RepairStat.REPAIRABLE;
if (item.getItemMeta().isUnbreakable()) {
stat = RepairStat.UNREPAIRABLE_UNBREAKABLE;
}
Repairable repairableMeta = (Repairable) item.getItemMeta();
repairLimit = cfg.repairLimit;
if (repairLimit > 0 && repairableMeta.getRepairCost() >= repairLimit) {
stat = RepairStat.UNREPAIRABLE_RLE;
}
Material toolMaterial = item.getType();
repairMaterial = cfg.material;
int currentDurability = item.getDurability();
if (currentDurability <= 0) {
stat = RepairStat.UNREPAIRABLE_REPAIRED;
}
int enchLevel = 0;
for (Integer i : item.getEnchantments().values()) enchLevel += i;
int fullDurability = toolMaterial.getMaxDurability();
durRecovered = (int) Math.floor((double) fullDurability / ((double) cfg.fullRepairCost + (double) enchLevel * cfg.enchantCostPerLv));
expConsumption = (int) Math.floor(cfg.expCost + cfg.enchantCostPerLv * enchLevel);
if (durRecovered <= 0) {
stat = RepairStat.UNREPAIRABLE_LOWRECOVER;
}
}
开发者ID:NyaaCat,项目名称:NyaaUtils,代码行数:39,代码来源:RepairInstance.java
示例4: repairCost
import org.bukkit.inventory.meta.Repairable; //导入依赖的package包/类
/**
* Sets this item's repair cost.
*
* @param cost repair cost
*
* @return this item builder instance, for chaining
*/
public ItemBuilder repairCost(int cost) {
try {
((Repairable) this.itemMeta).setRepairCost(cost);
} catch (Exception e) {
if (!this.failSilently) {
e.printStackTrace();
}
}
return this;
}
开发者ID:SupaHam,项目名称:SupaCommons,代码行数:18,代码来源:ItemBuilder.java
示例5: matches
import org.bukkit.inventory.meta.Repairable; //导入依赖的package包/类
public boolean matches(ItemStack anotherItem) {
ItemStack base = itemTemplate.clone();
ItemStack given = anotherItem.clone();
base.setAmount(1);
given.setAmount(1);
if (requireExact) return base.equals(given);
if (!base.getType().equals(given.getType())) return false;
if (repairCostMatch == MatchingMode.EXACT &&
base.getItemMeta() instanceof Repairable && given.getItemMeta() instanceof Repairable &&
!(((Repairable) given.getItemMeta()).getRepairCost() == ((Repairable) base.getItemMeta()).getRepairCost())) {
return false;
}
int baseDamage = base.getDurability();
int givenDamage = given.getDurability();
if (minDamageValue == -2 && givenDamage < baseDamage) return false;
if (minDamageValue >= 0 && givenDamage < minDamageValue) return false;
if (maxDamageValue == -2 && givenDamage > baseDamage) return false;
if (maxDamageValue >= 0 && givenDamage > maxDamageValue) return false;
String baseDisplay = getDisplayName(base);
String givenDisplay = getDisplayName(given);
if (nameMatch == MatchingMode.EXACT && !baseDisplay.equals(givenDisplay)) return false;
if (nameMatch == MatchingMode.EXACT_TEXT && !ChatColor.stripColor(baseDisplay).equals(ChatColor.stripColor(givenDisplay)))
return false;
if (nameMatch == MatchingMode.CONTAINS && !givenDisplay.contains(baseDisplay)) return false;
if (nameMatch == MatchingMode.CONTAINS_TEXT && !ChatColor.stripColor(givenDisplay).contains(ChatColor.stripColor(baseDisplay)))
return false;
Map<Enchantment, Integer> baseEnch = base.getEnchantments();
Map<Enchantment, Integer> givenEnch = given.getEnchantments();
if (enchantMatch == MatchingMode.EXACT || enchantMatch == MatchingMode.EXACT_TEXT) {
if (!baseEnch.equals(givenEnch)) return false;
} else if (enchantMatch == MatchingMode.CONTAINS || enchantMatch == MatchingMode.CONTAINS_TEXT) {
for (Map.Entry<Enchantment, Integer> e : baseEnch.entrySet()) {
if (!givenEnch.containsKey(e.getKey()) || givenEnch.get(e.getKey()) < e.getValue())
return false;
}
}
String[] baseLore = getLore(base);
String[] givenLore = getLore(given);
if (loreMatch == MatchingMode.EXACT && !Arrays.deepEquals(baseLore, givenLore)) return false;
if (loreMatch == MatchingMode.CONTAINS && !containStrArr(givenLore, baseLore, false)) return false;
if (loreMatch == MatchingMode.EXACT_TEXT) {
for (int i = 0; i < baseLore.length; i++) baseLore[i] = ChatColor.stripColor(baseLore[i]);
for (int i = 0; i < givenLore.length; i++) givenLore[i] = ChatColor.stripColor(givenLore[i]);
if (!Arrays.deepEquals(baseLore, givenLore)) return false;
}
if (loreMatch == MatchingMode.CONTAINS_TEXT && !containStrArr(givenLore, baseLore, true)) return false;
return true;
}
开发者ID:NyaaCat,项目名称:NyaaCore,代码行数:55,代码来源:BasicItemMatcher.java
示例6: matches
import org.bukkit.inventory.meta.Repairable; //导入依赖的package包/类
public boolean matches(ItemStack anotherItem) {
ItemStack base = itemTemplate.clone();
ItemStack given = anotherItem.clone();
base.setAmount(1);
given.setAmount(1);
if (requireExact) return base.equals(given);
if (!base.getType().equals(given.getType())) return false;
if (repairCostMatch == MatchingMode.EXACT) {
if (base.getItemMeta() instanceof Repairable && given.getItemMeta() instanceof Repairable) {
int cost1 = ((Repairable) given.getItemMeta()).getRepairCost();
int cost2 = ((Repairable) base.getItemMeta()).getRepairCost();
if (cost1 != cost2) return false;
} else if (base.getItemMeta() instanceof Repairable || given.getItemMeta() instanceof Repairable) {
return false;
}
}
int baseDamage = base.getDurability();
int givenDamage = given.getDurability();
if (minDamageValue == -2 && givenDamage < baseDamage) return false;
if (minDamageValue >= 0 && givenDamage < minDamageValue) return false;
if (maxDamageValue == -2 && givenDamage > baseDamage) return false;
if (maxDamageValue >= 0 && givenDamage > maxDamageValue) return false;
String baseDisplay = getDisplayName(base);
String givenDisplay = getDisplayName(given);
if (nameMatch == MatchingMode.EXACT && !baseDisplay.equals(givenDisplay)) return false;
if (nameMatch == MatchingMode.EXACT_TEXT && !ChatColor.stripColor(baseDisplay).equals(ChatColor.stripColor(givenDisplay)))
return false;
if (nameMatch == MatchingMode.CONTAINS && !givenDisplay.contains(baseDisplay)) return false;
if (nameMatch == MatchingMode.CONTAINS_TEXT && !ChatColor.stripColor(givenDisplay).contains(ChatColor.stripColor(baseDisplay)))
return false;
Map<Enchantment, Integer> baseEnch = base.getEnchantments();
Map<Enchantment, Integer> givenEnch = given.getEnchantments();
if (enchantMatch == MatchingMode.EXACT || enchantMatch == MatchingMode.EXACT_TEXT) {
if (!baseEnch.equals(givenEnch)) return false;
} else if (enchantMatch == MatchingMode.CONTAINS || enchantMatch == MatchingMode.CONTAINS_TEXT) {
for (Map.Entry<Enchantment, Integer> e : baseEnch.entrySet()) {
if (!givenEnch.containsKey(e.getKey()) || givenEnch.get(e.getKey()) < e.getValue())
return false;
}
}
String[] baseLore = getLore(base);
String[] givenLore = getLore(given);
if (loreMatch == MatchingMode.EXACT && !Arrays.deepEquals(baseLore, givenLore)) return false;
if (loreMatch == MatchingMode.CONTAINS && !containStrArr(givenLore, baseLore, false)) return false;
if (loreMatch == MatchingMode.EXACT_TEXT) {
for (int i = 0; i < baseLore.length; i++) baseLore[i] = ChatColor.stripColor(baseLore[0]);
for (int i = 0; i < baseLore.length; i++) baseLore[i] = ChatColor.stripColor(baseLore[0]);
if (!Arrays.deepEquals(baseLore, givenLore)) return false;
}
if (loreMatch == MatchingMode.CONTAINS_TEXT && !containStrArr(givenLore, baseLore, true)) return false;
return true;
}
开发者ID:NyaaCat,项目名称:HamsterEcoHelper,代码行数:59,代码来源:RequisitionSpecification.java
示例7: apply
import org.bukkit.inventory.meta.Repairable; //导入依赖的package包/类
@Override
public boolean apply(@Nullable ItemStack item1, @Nullable ItemStack item2) {
Boolean b = precondition(item1, item2, true);
return b != null ? b : ((Repairable) item1.getItemMeta()).getRepairCost()
== ((Repairable) item2.getItemMeta()).getRepairCost();
}
开发者ID:SupaHam,项目名称:SupaCommons,代码行数:7,代码来源:ItemMatcher.java
示例8: initModule
import org.bukkit.inventory.meta.Repairable; //导入依赖的package包/类
/**
* initModule enables the module called by {@link TerraCraftTools}
*/
public void initModule(TerraCraftTools sst) {
plugin = sst;
kits = new HashMap<String, List<ItemStack>>();
cooldowns = new HashMap<Player, Long>();
File[] kitFiles = plugin.getDataFolder().listFiles(new IsYML());
if (kitFiles.length == 0) {
return;
}
//This is prone to throw some exceptions if the config is poorly written.
//If you feel like cleaning it up, feel free to Pull Request.
for (File kit : kitFiles) {
FileConfiguration kitConf = YamlConfiguration.loadConfiguration(kit);
List<String> desc = kitConf.getStringList("description");
List<ItemStack> items = new LinkedList<ItemStack>();
List<String> itemConfs = kitConf.getStringList("items");
for (String itemConf : itemConfs) {
ItemStack itemStack = null;
String[] bits = itemConf.split(" ");
for (String bit : bits) {
if (bit.startsWith("id:")) {
itemStack = new ItemStack(Integer.valueOf(bit.substring(3)), 1);
}
if (itemStack == null) {
continue;
}
if (bit.startsWith("count:")) {
itemStack.setAmount(Integer.valueOf(bit.substring(6)));
} else if (bit.startsWith("!tagged")) {
ItemMeta im = itemStack.getItemMeta();
im.setLore(desc);
itemStack.setItemMeta(im);
} else if (bit.startsWith("data:")) {
itemStack.setDurability(Short.valueOf(bit.substring(5)));
} else if (bit.startsWith("ench:")) {
String ench = bit.substring(5);
String[] bites = ench.split(":");
//I don't want to deal with cosmetic names.
itemStack.addUnsafeEnchantment(Enchantment.getByName(bites[0]), Integer.valueOf(bites[1]));
} else if (bit.startsWith("anvilCost:")) {
Repairable r = (Repairable) itemStack.getItemMeta();
r.setRepairCost(Integer.valueOf(bit.substring(10)));
itemStack.setItemMeta((ItemMeta) r);
}
}
items.add(itemStack);
}
kits.put(kitConf.getString("kitName").toLowerCase(), items);
}
plugin.commandRegistrar.registerCommand("kit", this);
plugin.commandRegistrar.registerCommand("identify", this);
plugin.logger.info("[TerraCraftTools][GuardKits] GuardKits Module Enabled!");
}
开发者ID:CoderMonkeys,项目名称:TerraCraftTools,代码行数:56,代码来源:GuardKits.java
示例9: onInventoryClick
import org.bukkit.inventory.meta.Repairable; //导入依赖的package包/类
@EventHandler
public static void onInventoryClick(InventoryClickEvent e){
if(e.isCancelled()) return;
HumanEntity ent = e.getWhoClicked();
if(!(ent instanceof Player)) return;
Player player = (Player)ent;
Inventory inv = e.getInventory();
if(!(inv instanceof AnvilInventory)) return;
EpicPlayer epicPlayer = EpicSystem.getEpicPlayer(player.getUniqueId());
List<EpicQuestTask> taskList = epicPlayer.getTasksByType(TaskTypes.REPAIR_ITEM);
for(EpicQuestTask task : taskList){
AnvilInventory anvil = (AnvilInventory)inv;
InventoryView view = e.getView();
int rawSlot = e.getRawSlot();
if(rawSlot == view.convertSlot(rawSlot)){
// 2 = result slot
if(rawSlot != 2) return;
ItemStack[] items = anvil.getContents();
ItemStack item1 = items[0];
ItemStack item3 = e.getCurrentItem();
//if(item1 == null || item2 == null || item3 == null) return;
Material id1 = item1.getType();
Material id3 = item3.getType();
if(id1 != id3) return;
//See if correct item is repaired
if(id3 == Material.matchMaterial(task.getTaskID())){
ItemMeta meta = item3.getItemMeta();
if(meta == null) return;
if(meta instanceof Repairable){
Repairable repairable = (Repairable)meta;
int repairCost = repairable.getRepairCost();
if(player.getLevel() >= repairCost){
task.ProgressTask(1, epicPlayer, true);
}
}
}
}
}
}
开发者ID:Randehh,项目名称:EpicQuest,代码行数:54,代码来源:TypeRepair.java
示例10: NonrepairableItemStack
import org.bukkit.inventory.meta.Repairable; //导入依赖的package包/类
/**
* Instantiates an ItemStack with a display name, lore, enchantments, and a cost for repairing.
*
* @param type material
* @param amount amount
* @param durability damage / durability
* @param displayName name of item
* @param lore lore for item
* @param enchantments enchantments for item
* @param cost experience level cost to repair
*/
public NonrepairableItemStack(Material type, int amount, short durability, String displayName,
List<String> lore,
Map<Enchantment, Integer> enchantments, int cost) {
super(type, amount, durability, displayName, lore, enchantments);
if (this.getItemMeta() instanceof Repairable) {
Repairable repairable = (Repairable) this.getItemMeta();
repairable.setRepairCost(cost);
setItemMeta((ItemMeta) repairable);
}
}
开发者ID:Nunnery,项目名称:MythicDrops,代码行数:22,代码来源:NonrepairableItemStack.java
示例11: clone
import org.bukkit.inventory.meta.Repairable; //导入依赖的package包/类
Repairable clone();
开发者ID:deathcap,项目名称:BedrockAPI,代码行数:2,代码来源:Repairable.java
注:本文中的org.bukkit.inventory.meta.Repairable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论