Files
src
Code
3 668
src/main/java/com/kodari/tntboost/TNTBoostPlugin.java
package com.kodari.tntboost;
import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public final class TNTBoostPlugin extends JavaPlugin implements Listener, CommandExecutor, TabCompleter {
private static final long TNT_COOLDOWN_MILLIS = 60_000L;
private static final String TNT_ITEM_ID = "tnt_sword";
private static final String EUREON_ITEM_ID = "eureon";
private NamespacedKey itemKey;
private NamespacedKey explosiveKey;
private NamespacedKey ownerKey;
private NamespacedKey eureonKillsKey;
private final Map<UUID, Long> tntCooldowns = new HashMap<>();
private final Map<UUID, Long> eureonCooldowns = new HashMap<>();
private final Map<UUID, AssassinState> assassinStates = new HashMap<>();
private final Set<UUID> trueDamageTargets = new HashSet<>();
@Override
public void onEnable() {
saveDefaultConfig();
itemKey = new NamespacedKey(this, "item_id");
explosiveKey = new NamespacedKey(this, "tntboost_explosive");
ownerKey = new NamespacedKey(this, "tntboost_owner");
eureonKillsKey = new NamespacedKey(this, "eureon_kills");
Bukkit.getPluginManager().registerEvents(this, this);
getCommand("tntboost").setExecutor(this);
getCommand("tntboost").setTabCompleter(this);
getCommand("eureon").setExecutor(this);
getCommand("eureon").setTabCompleter(this);
Bukkit.getScheduler().runTaskTimer(this, this::updateCooldowns, 20L, 20L);
}
@Override
public void onDisable() {
for (UUID playerId : new HashSet<>(assassinStates.keySet())) {
Player player = Bukkit.getPlayer(playerId);
if (player != null) {
finishAssassinMode(player, null);
} else {
assassinStates.remove(playerId);
}
}
tntCooldowns.clear();
eureonCooldowns.clear();
assassinStates.clear();
trueDamageTargets.clear();
}
private ItemStack createTntSword() {
ItemStack item = XMaterial.matchXMaterial("IRON_SWORD")
.map(XMaterial::parseItem)
.orElseThrow(() -> new IllegalStateException("Iron sword material is unavailable"));
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(color("&c&lMIECZ &f&lTNT"));
meta.setLore(List.of(
color("&c»»» &fTyp przedmiotu: &cPrzedmiot mityczny"),
color("&c»»» &fRzadkość: &c★★★★"),
"",
color("&c»»» &fBroń stworzona do walki wśród eksplozji"),
"",
color("&c»»» &fUmiejętność: &cWyrzut TNT"),
color("&c» &fWystrzel TNT zadające &c5 serc"),
color("&c» &fPromień eksplozji: &c10 bloków"),
color("&c» &fOdnowienie: &c1 minuta"),
"",
color("&c»»» &fItem z wydarzenia startu serwera &c2027r")
));
meta.getPersistentDataContainer().set(itemKey, PersistentDataType.STRING, TNT_ITEM_ID);
item.setItemMeta(meta);
return item;
}
private ItemStack createEureon() {
ItemStack item = XMaterial.matchXMaterial("IRON_SWORD")
.map(XMaterial::parseItem)
.orElseThrow(() -> new IllegalStateException("Iron sword material is unavailable"));
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(color("&5&lEureon"));
meta.getPersistentDataContainer().set(itemKey, PersistentDataType.STRING, EUREON_ITEM_ID);
meta.getPersistentDataContainer().set(eureonKillsKey, PersistentDataType.INTEGER, 0);
XEnchantment.matchXEnchantment("SHARPNESS")
.ifPresent(enchantment -> meta.addEnchant(enchantment.getEnchant(), 7, true));
updateEureonLore(meta, 0);
item.setItemMeta(meta);
return item;
}
private void updateEureonLore(ItemMeta meta, int kills) {
double effectiveSharpness = 7.0 + kills * 0.01;
double damageBonusPercent = kills * 0.05;
meta.setLore(List.of(
color("&5»»» &dTyp: &bPrzedmiot legendarny"),
color("&5> &dRzadkość: &b★★★★★"),
"",
color("&5»»» &dOstrość: &bVII"),
color("&5> &dZabójstwa: &b" + kills),
color("&5> &dEfektywna ostrość: &b" + String.format(Locale.US, "%.2f", effectiveSharpness)),
color("&5> &dBonus obrażeń: &b+" + String.format(Locale.US, "%.2f", damageBonusPercent) + "%"),
color("&5> &dKażde zabójstwo: &b+0,01 ostrości"),
"",
color("&5»»» &dUmiejętność: &bTryb zabójcy"),
color("&5> &dNiewidzialność: &b" + getEureonDurationSeconds() + " s"),
color("&5> &dKończy się po: &b" + getEureonRequiredHits() + " trafieniach graczy"),
color("&5> &dOdnowienie: &b" + getEureonCooldownSeconds() + " s")
));
}
private boolean isItem(ItemStack item, String expectedId) {
if (item == null || !item.hasItemMeta()) {
return false;
}
String id = item.getItemMeta().getPersistentDataContainer().get(itemKey, PersistentDataType.STRING);
return expectedId.equals(id);
}
private boolean isTntSword(ItemStack item) {
return isItem(item, TNT_ITEM_ID);
}
private boolean isEureon(ItemStack item) {
return isItem(item, EUREON_ITEM_ID);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
public void onSwordUse(PlayerInteractEvent event) {
Action action = event.getAction();
if (event.getHand() != EquipmentSlot.HAND
|| (action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK)) {
return;
}
Player player = event.getPlayer();
ItemStack heldItem = player.getInventory().getItemInMainHand();
if (isTntSword(heldItem)) {
event.setCancelled(true);
fireTnt(player);
} else if (isEureon(heldItem)) {
event.setCancelled(true);
activateEureon(player);
}
}
private void fireTnt(Player player) {
long now = System.currentTimeMillis();
long readyAt = tntCooldowns.getOrDefault(player.getUniqueId(), 0L);
if (readyAt > now) {
updateCooldownActionBar(player, now);
return;
}
Vector direction = player.getEyeLocation().getDirection().normalize();
Location launchLocation = findTntLaunchLocation(player, direction);
if (launchLocation == null) {
player.sendMessage(color("&cNie ma wystarczająco miejsca, aby wystrzelić TNT."));