1
所以我正在製作一個插件,並且一切工作到目前爲止。丟棄被清除,但仍然下降
我唯一的問題是胸板絕殺溼巾,物品有時會掉落兩次,其中一次是耐用性破壞和相同的統計數據。任何幫助表示讚賞
package me.impatheimpaler.mmo;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
public class Mobdrops extends JavaPlugin implements Listener {
public List<String> t1h = new ArrayList<String>();
public List<String> t1c = new ArrayList<String>();
public List<String> t1l = new ArrayList<String>();
public List<String> t1b = new ArrayList<String>();
public List<String> t1s = new ArrayList<String>();
public static me.impatheimpaler.mmo.Main plugin;
public Mobdrops(Main main) {
plugin = main;
}
@EventHandler
public void onDeath(EntityDeathEvent e) {
Skeleton s = (Skeleton) e.getEntity();
if (!(e.getEntity() instanceof Player)) {
e.getDrops().clear();
e.setDroppedExp(0);
}
if ((e.getEntity() instanceof Skeleton)) {
Skeleton sk = (Skeleton)e.getEntity();
if (sk.getCustomName() == null) {
return;
}
}
Random random = new Random();
int rarity = random.nextInt(3) + 1;
int chestdrop = random.nextInt(20) + 1;
int legsdrop = random.nextInt(17) + 1;
int helmdrop = random.nextInt(6) + 1;
int bootsdrop = random.nextInt(11) + 1;
int swordDrop = random.nextInt(15) + 1;
if (helmdrop == 3) {
ItemStack t1helm = new ItemStack(Material.LEATHER_HELMET);
ItemMeta t1helmMeta = t1helm.getItemMeta();
t1helmMeta.setDisplayName(ChatColor.WHITE + "Renegade's Torn Helmet");
if (rarity == 3) {
int hp = random.nextInt(20) + 33;
t1h.add(ChatColor.RED + "HP: +" + hp);
t1h.add(ChatColor.GOLD + "Legendary");
}
if (rarity == 2) {
int hp = random.nextInt(10) + 20;
t1h.add(ChatColor.RED + "HP: +" + hp);
t1h.add(ChatColor.AQUA + "Normal");
}
if (rarity == 1) {
int hp = random.nextInt(15) + 6;
t1h.add(ChatColor.RED + "HP: +" + hp);
t1h.add(ChatColor.GRAY + "Poor");
}
t1helmMeta.setLore(t1h);
t1helm.setItemMeta(t1helmMeta);
s.getEquipment().setHelmet(t1helm);
e.getDrops().add(t1helm);
t1h.clear();
}
if (chestdrop == 7) {
ItemStack t1chest = new ItemStack(Material.LEATHER_CHESTPLATE);
ItemMeta t1chestMeta = t1chest.getItemMeta();
t1chestMeta.setDisplayName(ChatColor.WHITE + "Renegade's Torn Chestplate");
if (rarity == 3) {
int hp = random.nextInt(20) + 72;
t1c.add(ChatColor.RED + "HP: +" + hp);
t1c.add(ChatColor.GOLD + "Legendary");
}
if (rarity == 2) {
int hp = random.nextInt(30) + 33;
t1c.add(ChatColor.RED + "HP: +" + hp);
t1c.add(ChatColor.AQUA + "Normal");
}
if (rarity == 1) {
int hp = random.nextInt(10) + 20;
t1c.add(ChatColor.RED + "HP: +" + hp);
t1c.add(ChatColor.GRAY + "Poor");
}
t1chestMeta.setLore(t1c);
t1chest.setItemMeta(t1chestMeta);
s.getEquipment().setChestplate(t1chest);
e.getDrops().add(t1chest);
t1c.clear();
}
if (legsdrop == 2) {
ItemStack t1legs = new ItemStack(Material.LEATHER_LEGGINGS);
ItemMeta t1legsMeta = t1legs.getItemMeta();
t1legsMeta.setDisplayName(ChatColor.WHITE + "Renegade's Torn Leggings");
if (rarity == 3) {
int hp = random.nextInt(20) + 61;
t1l.add(ChatColor.RED + "HP: +" + hp);
t1l.add(ChatColor.YELLOW + "Legendary");
}
if (rarity == 2) {
int hp = random.nextInt(20) + 33;
t1l.add(ChatColor.RED + "HP: +" + hp);
t1l.add(ChatColor.AQUA + "Normal");
}
if (rarity == 1) {
int hp = random.nextInt(10) + 10;
t1l.add(ChatColor.RED + "HP: +" + hp);
t1l.add(ChatColor.GRAY + "Poor");
}
t1legsMeta.setLore(t1l);
t1legs.setItemMeta(t1legsMeta);
s.getEquipment().setLeggings(t1legs);
e.getDrops().add(t1legs);
t1l.clear();
}
if (bootsdrop == 1) {
ItemStack t1boots = new ItemStack(Material.LEATHER_BOOTS);
ItemMeta t1bootsMeta = t1boots.getItemMeta();
t1bootsMeta.setDisplayName(ChatColor.WHITE + "Renegade's Torn Boots");
if (rarity == 3) {
int hp = random.nextInt(20) + 23;
t1b.add(ChatColor.RED + "HP: +" + hp);
t1b.add(ChatColor.YELLOW + "Legendary");
}
if (rarity == 2) {
int hp = random.nextInt(10) + 10;
t1b.add(ChatColor.RED + "HP: +" + hp);
t1b.add(ChatColor.AQUA + "Normal");
}
if (rarity == 1) {
int hp = random.nextInt(5) + 6;
t1b.add(ChatColor.RED + "HP: +" + hp);
t1b.add(ChatColor.GRAY + "Poor");
}
t1bootsMeta.setLore(t1b);
t1boots.setItemMeta(t1bootsMeta);
s.getEquipment().setBoots(t1boots);
e.getDrops().add(t1boots);
t1b.clear();
}
if (swordDrop == 3) {
ItemStack t1sword = new ItemStack(Material.WOOD_SWORD);
ItemMeta t1swordMeta = t1sword.getItemMeta();
if (rarity == 3) {
int min = random.nextInt(20) + 11;
int max = random.nextInt(20) + 21;
t1s.add(ChatColor.RED + "DMG: " + min + " - " + max);
t1s.add(ChatColor.YELLOW + "Legendary");
}
if (rarity == 2) {
int max = random.nextInt(10) + 21;
int min = random.nextInt(10) + 11;
t1s.add(ChatColor.RED + "DMG: " + min + " - " + max);
t1s.add(ChatColor.AQUA + "Normal");
}
if (rarity == 1) {
int min = random.nextInt(5) + 6;
int max = random.nextInt(10) + 11;
t1s.add(ChatColor.RED + "DMG: " + min + " - " + max);
t1s.add(ChatColor.GRAY + "Poor");
}
t1swordMeta.setLore(t1s);
t1sword.setItemMeta(t1swordMeta);
s.getEquipment().setItemInHand(t1sword);
e.getDrops().add(t1sword);
t1s.clear();
}
}
}
您可以創建一個[MCVE](http://stackoverflow.com/help/mcve)嗎? –
不知道代碼的意圖是什麼,不可能提供有用的建議來解決「修復」問題。通過您的代碼格式化和評論。運行一個__debugger__。如果你不知道那是什麼,請閱讀__book__。 – Unihedron
這裏有很多問題(假設你想讓特殊物品從骨架上掉落下來)你的代碼顯示「關於任何實體死亡,丟棄物品」(包括玩家),只有在沒有自定義名稱的骨架時纔會被取消。你應該在'if(稀有==#)'之間使用一些「else if」,因爲沒有必要浪費資源來再次檢查。你也有't1helmMeta.setLore(th1)'這樣的東西,其中'th1'只是** **甚至如果其中一個if語句是真的,你應該'返回' 我真的不能看到問題與其他許多人一樣,我很抱歉..也許清理你的意圖? – zfb