Untitled
unknown
plain_text
8 months ago
2.5 kB
1
Indexable
Never
import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; public class StickHealthPlugin extends JavaPlugin implements Listener { @Override public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (label.equalsIgnoreCase("stick_health") && sender instanceof Player) { Player player = (Player) sender; giveHealingStick(player); return true; } return false; } @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); ItemStack item = player.getInventory().getItemInMainHand(); if (item != null && item.getType() == Material.STICK) { // Проверяем, что это палка, которую дал наш плагин if (item.hasItemMeta() && item.getItemMeta().getDisplayName().equals("Healing Stick")) { // Исцеляем другого игрока, если возможно if (event.getRightClicked() instanceof Player) { Player target = (Player) event.getRightClicked(); healPlayer(target, 3); player.sendMessage("Вы исцелили игрока " + target.getName()); } } } } private void giveHealingStick(Player player) { ItemStack stick = new ItemStack(Material.STICK); stick.setCustomModelData(123); // Уникальный идентификатор модели для вашей палки (можно пропустить) stick.setDisplayName("Healing Stick"); player.getInventory().addItem(stick); player.sendMessage("Вы получили палку исцеления."); } private void healPlayer(Player player, int amount) { // Логика исцеления игрока double currentHealth = player.getHealth(); double maxHealth = player.getMaxHealth(); double newHealth = Math.min(currentHealth + amount, maxHealth); player.setHealth(newHealth); } }
Leave a Comment