过去的几周我一直在研究插件,使用该工具包时遇到了问题。每个套件都有其自己的“功能”,当您右键单击库存中的某个项目时,它会被激活。例如,当您右键单击粘液球时,“射手座”工具包将变成岩浆膏,并为弓箭附魔,直到射出箭筒耗尽岩浆。我希望获得一些帮助,所以在此先谢谢您。
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Archer extends Kit implements Listener {
public ArrayList<Player> fireArrows = new ArrayList<Player>();
public HashMap<Player, Integer> arrowCount = new HashMap<Player, Integer>();
public Archer() {
super("Archer", "kitpvp.Archer");
}
@Override
public ItemStack displayItem() {
ItemStack itemStack = new ItemStack(Material.BOW);
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(ChatColor.GOLD + getName() + " Kit");
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public ItemStack displayItemShop() {
ItemStack shop = new ItemStack(Material.BOW);
ItemMeta shopmeta = shop.getItemMeta();
shopmeta.setDisplayName(ChatColor.GOLD + getName() + " Kit");
List<String> price = new ArrayList<String>();
price.add(ChatColor.YELLOW + "0 Coins");
price.add(ChatColor.YELLOW + "");
price.add(ChatColor.YELLOW + "Left-Click to Buy");
price.add(ChatColor.YELLOW + "Right-Click to Preview");
shopmeta.setLore(price);
shop.setItemMeta(shopmeta);
return shop;
}
public ItemStack Bow() {
ItemStack Bow = new ItemStack(Material.BOW);
ItemMeta BowMeta = Bow.getItemMeta();
BowMeta.setDisplayName(ChatColor.WHITE + "Archer Bow");
Bow.setItemMeta(BowMeta);
return Bow;
}
public ItemStack MagmaCream() {
ItemStack MagmaCream = new ItemStack(Material.MAGMA_CREAM, 1);
ItemMeta MagmaCreamMeta = MagmaCream.getItemMeta();
MagmaCreamMeta.setDisplayName(ChatColor.YELLOW + "Right Click for Regular Arrows");
MagmaCream.setItemMeta(MagmaCreamMeta);
return MagmaCream;
}
public ItemStack SLIME_BALL() {
ItemStack SLIME_BALL = new ItemStack(Material.SLIME_BALL, 1);
ItemMeta SLIME_BALLMeta = SLIME_BALL.getItemMeta();
SLIME_BALLMeta.setDisplayName(ChatColor.YELLOW + "Right Click for Fire Arrows");
SLIME_BALL.setItemMeta(SLIME_BALLMeta);
return SLIME_BALL;
}
@Override
public Inventory kitPreview() {
Inventory inventory = Bukkit.createInventory(null, 18, getName() + " Kit Preview");
inventory.addItem(new ItemStack(Material.WOOD_SWORD));
inventory.addItem(new ItemStack(Material.BOW));
inventory.addItem(new ItemStack(Material.SULPHUR));
inventory.addItem(new ItemStack(Material.ARROW));
inventory.addItem(new ItemStack(Material.LEATHER_HELMET));
inventory.addItem(new ItemStack(Material.LEATHER_CHESTPLATE));
inventory.addItem(new ItemStack(Material.LEATHER_LEGGINGS));
inventory.addItem(new ItemStack(Material.LEATHER_BOOTS));
return inventory;
}
@Override
public void apply(Player player) {
player.removePotionEffect(PotionEffectType.JUMP);
player.removePotionEffect(PotionEffectType.SPEED);
player.removePotionEffect(PotionEffectType.REGENERATION);
player.removePotionEffect(PotionEffectType.FIRE_RESISTANCE);
player.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
ItemStack sword = new ItemStack(Material.WOOD_SWORD);
sword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
player.getInventory().setItem(0, sword);
player.getInventory().setItem(2, SLIME_BALL());
player.getInventory().setItem(1, Bow());
player.getInventory().setItem(16, new ItemStack(Material.ARROW, 32));
player.getInventory().setHelmet(new ItemStack(Material.LEATHER_HELMET));
player.getInventory().setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE));
player.getInventory().setLeggings(new ItemStack(Material.LEATHER_LEGGINGS));
player.getInventory().setBoots(new ItemStack(Material.LEATHER_BOOTS));
for (int i = 0; i < player.getInventory().getSize(); i++) {
if (player.getInventory().getItem(i) == null || player.getInventory().getItem(i).getType().equals(Material.AIR)) {
player.getInventory().setItem(i, new ItemStack(Material.MUSHROOM_SOUP));
}
}
}
@EventHandler
public void onInteract(PlayerInteractEvent e) {
Player player = e.getPlayer();
Action action = e.getAction();
if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
if (e.getItem().equals(MagmaCream())) {
if (player.getInventory().contains(MagmaCream())) {
player.getInventory().removeItem(MagmaCream());
player.updateInventory();
}
fireArrows.remove(player);
//Bow().removeEnchantment(Enchantment.ARROW_FIRE);
player.updateInventory();
player.getInventory().setItem(2, SLIME_BALL());
} else if (e.getItem().equals(SLIME_BALL())) {
if (player.getInventory().contains(Bow())) {
Bow().addEnchantment(Enchantment.ARROW_FIRE, 5);
}
player.updateInventory();
player.getInventory().setItem(2, MagmaCream());
fireArrows.add(player);
if (player.getInventory().contains(Material.BOW)) {
Bow().getEnchantments();
Bow().addEnchantment(Enchantment.ARROW_FIRE, 5);
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cYou now have a fire bow!"));
if (!(arrowCount.containsKey(player))) {
arrowCount.put(player, 0);
}
int firearrowcount = arrowCount.get(player);
arrowCount.put(player, firearrowcount + 1);
if (firearrowcount == 10) {
fireArrows.remove(player);
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cYour fire arrows have ran out."));
}
}
}
}
}
}