name: KillEffectPlugin
version: 1.0
main: [Link]
api-version: 1.19
commands:
godpot:
description: Give a god potion
usage: /godpot give <player> <effect>
permission: [Link]
permissions:
[Link]:
description: Allows use of /godpot command
default: op
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
public class KillEffectPlugin extends JavaPlugin implements Listener, TabExecutor {
private final Map<UUID, Set<PotionEffectType>> permanentEffects = new
HashMap<>();
private final List<PotionEffectType> goodEffects = [Link](
PotionEffectType.INCREASE_DAMAGE,
[Link],
[Link],
PotionEffectType.FAST_DIGGING,
[Link],
[Link],
PotionEffectType.DOLPHINS_GRACE,
PotionEffectType.FIRE_RESISTANCE
);
private final List<PotionEffectType> badEffects = [Link](
[Link],
[Link],
[Link],
[Link]
);
private final String EFFECT_KEY = "[Link]";
private final Map<PotionEffectType, String> effectNames = new HashMap<>();
private final Random random = new Random();
private final Map<UUID, String> killRollMessages = new HashMap<>();
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
[Link](PotionEffectType.INCREASE_DAMAGE, "Strength");
[Link]([Link], "Speed");
[Link]([Link], "Invisibility");
[Link](PotionEffectType.FAST_DIGGING, "Haste");
[Link]([Link], "Regeneration");
[Link]([Link], "Saturation");
[Link](PotionEffectType.DOLPHINS_GRACE, "Dolphin's Grace");
[Link](PotionEffectType.FIRE_RESISTANCE, "Fire Resistance");
[Link]([Link], "Poison");
[Link]([Link], "Wither");
[Link]([Link], "Slowness");
[Link]([Link], "Blindness");
}
// ... The rest of the code will be in next parts
}
// Utility: Add a permanent effect to a player
private void addEffect(Player player, PotionEffectType effect) {
UUID uuid = [Link]();
[Link](uuid, k -> new HashSet<>()).add(effect);
applyEffects(player);
}
// Utility: Remove a permanent effect from a player
private void removeEffect(Player player, PotionEffectType effect) {
UUID uuid = [Link]();
Set<PotionEffectType> effects = [Link](uuid);
if (effects != null) {
[Link](effect);
if ([Link]()) {
[Link](uuid);
}
}
applyEffects(player);
}
// Apply all permanent effects to player
private void applyEffects(Player player) {
[Link]().forEach(e ->
[Link]([Link]()));
Set<PotionEffectType> effects = [Link]([Link]());
if (effects != null) {
for (PotionEffectType effect : effects) {
[Link](new PotionEffect(effect, Integer.MAX_VALUE,
0, false, false));
}
}
}
// Remove a random effect or give bad effect if none
private void removeRandomEffectOrGiveBad(Player player) {
UUID uuid = [Link]();
Set<PotionEffectType> effects = [Link](uuid);
if (effects == null || [Link]()) {
// Give bad effect for 30 seconds
PotionEffectType badEffect =
[Link]([Link]([Link]()));
[Link](new PotionEffect(badEffect, 20 * 30, 0));
[Link]([Link] + "You had no good effects, so you got
" + [Link](badEffect) + " as penalty!");
} else {
List<PotionEffectType> effectList = new ArrayList<>(effects);
PotionEffectType removed =
[Link]([Link]([Link]()));
removeEffect(player, removed);
[Link]([Link] + "You lost your " +
[Link](removed) + " effect on death.");
}
}
// Handle player death event
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
Player player = [Link]();
removeRandomEffectOrGiveBad(player);
}
// Handle respawn: reapply effects
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event) {
Player player = [Link]();
[Link]().runTaskLater(this, () -> applyEffects(player), 2L);
}
// Handle player killing another entity (only players)
@EventHandler
public void onPlayerKill(PlayerDeathEvent event) {
if ([Link]().getKiller() != null) {
Player killer = [Link]().getKiller();
// Give random good effect with roll animation
startRollAnimation(killer);
}
}
// Start the rolling "Roll... Roll... Roll..." chat animation then give effect
private void startRollAnimation(Player player) {
UUID uuid = [Link]();
List<String> rollStages = [Link]("Roll.", "Roll..", "Roll...");
new BukkitRunnable() {
int count = 0;
@Override
public void run() {
if (count < [Link]()) {
[Link]([Link] + [Link](count));
count++;
} else {
cancel();
PotionEffectType effect =
[Link]([Link]([Link]()));
addEffect(player, effect);
[Link]([Link] + "+1 Good effect: " +
[Link] + [Link](effect) + "!");
}
}
}.runTaskTimer(this, 0L, 20L);
}
// Handle player drinking a potion
@EventHandler
public void onPlayerDrinkPotion(PlayerItemConsumeEvent event) {
Player player = [Link]();
ItemStack item = [Link]();
if (isGodPotion(item)) {
[Link](true);
openPotionEffectGUI(player);
}
}
// Check if item is a god potion (custom meta key)
private boolean isGodPotion(ItemStack item) {
if (item == null) return false;
if ([Link]() != [Link]) return false;
if (![Link]()) return false;
ItemMeta meta = [Link]();
if (meta == null) return false;
return [Link]().has(new NamespacedKey(this,
"godpot"), [Link]);
}
import [Link];
import [Link];
import [Link];
// ... inside KillEffectPlugin class
private final NamespacedKey GOD_POT_KEY = new NamespacedKey(this, "godpot");
private final int GUI_SIZE = 9;
// Opens the GUI to pick one of the good effects
private void openPotionEffectGUI(Player player) {
Inventory gui = [Link](null, GUI_SIZE, ChatColor.DARK_PURPLE +
"Choose an Effect");
Set<PotionEffectType> playerEffects =
[Link]([Link](), new HashSet<>());
for (int i = 0; i < [Link]() && i < GUI_SIZE; i++) {
PotionEffectType effect = [Link](i);
ItemStack item = new ItemStack([Link]);
PotionMeta meta = (PotionMeta) [Link]();
[Link](new PotionData([Link])); // just base
water
String name = [Link](effect, [Link]());
[Link]([Link](effect) ?
[Link] + name : [Link] + name);
if ([Link](effect)) {
[Link](ItemFlag.HIDE_ENCHANTS);
[Link]([Link], 1, true);
// Glow gray: enchant but gray name
}
[Link](meta);
[Link](i, item);
}
[Link](gui);
}
// Handle GUI clicks
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if ([Link]().getTitle().equals(ChatColor.DARK_PURPLE + "Choose an
Effect")) {
[Link](true);
if ([Link]() == null) return;
Player player = (Player) [Link]();
ItemStack clicked = [Link]();
if ([Link]() != [Link]) return;
PotionMeta meta = (PotionMeta) [Link]();
if (meta == null) return;
String name = [Link]([Link]());
// Find effect by name
PotionEffectType chosen = null;
for ([Link]<PotionEffectType, String> entry : [Link]()) {
if ([Link]().equalsIgnoreCase(name)) {
chosen = [Link]();
break;
}
}
if (chosen == null) return;
Set<PotionEffectType> playerEffects =
[Link]([Link](), new HashSet<>());
if ([Link](chosen)) {
[Link]([Link] + "You already have that effect!");
return;
}
addEffect(player, chosen);
[Link]([Link] + "You gained the " +
[Link](chosen) + " effect permanently!");
[Link]();
}
}
// Command handler
@Override
public boolean onCommand(CommandSender sender, Command command, String label,
String[] args) {
if ([Link]().equalsIgnoreCase("godpot")) {
if ([Link] != 3 || !args[0].equalsIgnoreCase("give")) {
[Link]([Link] + "Usage: /godpot give <player>
<effect>");
return true;
}
Player target = [Link](args[1]);
if (target == null) {
[Link]([Link] + "Player not found");
return true;
}
PotionEffectType effect = null;
for (PotionEffectType e : goodEffects) {
if ([Link](e).equalsIgnoreCase(args[2])) {
effect = e;
break;
}
}
if (effect == null) {
[Link]([Link] + "Invalid effect. Valid: " +
[Link]());
return true;
}
ItemStack potion = createGodPotion(effect);
[Link]().addItem(potion);
[Link]([Link] + "Given god potion of " +
[Link](effect) + " to " + [Link]());
return true;
}
return false;
}
// Create a god potion item with effect data
private ItemStack createGodPotion(PotionEffectType effect) {
ItemStack potion = new ItemStack([Link]);
PotionMeta meta = (PotionMeta) [Link]();
[Link](new PotionData([Link]));
[Link]([Link] + "God Potion of " +
[Link](effect));
[Link]([Link], 1, true);
[Link](ItemFlag.HIDE_ENCHANTS);
[Link]().set(GOD_POT_KEY, [Link],
(byte)1);
[Link](meta);
return potion;
}
// Tab completer for /godpot give <player> <effect>
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String
alias, String[] args) {
if ([Link]().equalsIgnoreCase("godpot")) {
if ([Link] == 1) {
return [Link]("give");
} else if ([Link] == 2) {
List<String> names = new ArrayList<>();
for (Player p : [Link]()) {
if ([Link]().toLowerCase().startsWith(args[1].toLowerCase()))
[Link]([Link]());
}
return names;
} else if ([Link] == 3) {
List<String> effects = new ArrayList<>();
for (PotionEffectType e : goodEffects) {
[Link]([Link](e));
}
List<String> filtered = new ArrayList<>();
for (String e : effects) {
if ([Link]().startsWith(args[2].toLowerCase()))
[Link](e);
}
return filtered;
}
}
return [Link]();
}
import [Link];
import [Link];
import [Link];
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
// existing initialization code...
addCraftingRecipe();
}
private void addCraftingRecipe() {
NamespacedKey key = new NamespacedKey(this, "god_potion_recipe");
ShapedRecipe recipe = new ShapedRecipe(key,
createGodPotion([Link](0))); // base god potion (strength by default)
[Link](
"DDD",
"IEB",
" B "
);
// Legend:
// D = Diamond Block
// I = Iron Ingot
// E = Emerald Block
// B = Water Bottle (use as bottle)
// 'S' = Blue shard replaced with Prismarine Crystal
// Since you want 2 diamond blocks, 1 iron ingot, 1 emerald block, 1 blue
shard, and 1 bottle:
// Let's fix the shape with these ingredients
[Link](
" D ",
"IEB",
" D "
);
[Link]('D', Material.DIAMOND_BLOCK);
[Link]('I', Material.IRON_INGOT);
[Link]('E', Material.EMERALD_BLOCK);
[Link]('B', [Link]); // water bottle or regular potion
[Link]('S', Material.PRISMARINE_CRYSTALS); // Blue shard
replacement (not in shape here yet)
// Because shaped recipe requires a shape of 3x3 or 2x2
// Let's do a 3x3 shape with 2 diamond blocks, 1 iron, 1 emerald block, 1
prismarine crystal, 1 bottle
[Link](
" D ",
"IES",
" B "
);
[Link]('D', Material.DIAMOND_BLOCK);
[Link]('I', Material.IRON_INGOT);
[Link]('E', Material.EMERALD_BLOCK);
[Link]('S', Material.PRISMARINE_CRYSTALS);
[Link]('B', [Link]);
getServer().addRecipe(recipe);
}