0% found this document useful (0 votes)
14 views8 pages

KillEffectPlugin: God Potion Commands

The KillEffectPlugin is a Minecraft plugin that allows players to receive and manage potion effects, including a command to give a 'god potion' with specified effects. It includes features for handling player deaths, respawns, and interactions with potions, as well as a GUI for selecting effects. The plugin also implements crafting recipes for creating god potions using specific materials.

Uploaded by

urtoohotbro
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

KillEffectPlugin: God Potion Commands

The KillEffectPlugin is a Minecraft plugin that allows players to receive and manage potion effects, including a command to give a 'god potion' with specified effects. It includes features for handling player deaths, respawns, and interactions with potions, as well as a GUI for selecting effects. The plugin also implements crafting recipes for creating god potions using specific materials.

Uploaded by

urtoohotbro
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

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);
}

Common questions

Powered by AI

When a player dies, the KillEffectPlugin invokes the onPlayerDeath event handler. This method removes one random permanent good effect from the player, or if no good effects exist, it applies a random bad effect for 30 seconds. This dynamic adds a strategic element, encouraging players to maintain their good effects while introducing a penalty risk upon death, thereby affecting their approach to combat and survival tactics .

Reapplying effects on respawn is necessary to maintain gameplay continuity and ensure that any permanent effects a player had are still active after death. This is achieved in the KillEffectPlugin by scheduling a task to call the applyEffects method shortly after the player's respawn using the Bukkit scheduler. This ensures that any previously existing permanent effects are re-enforced on the player, preserving their game status .

The KillEffectPlugin manages permanent effects for players using a combination of utility methods and event handlers. Permanent effects are stored in a map keyed by player UUIDs. Methods like addEffect and removeEffect modify these effects by adding or removing effects from this map. When a player dies, removeRandomEffectOrGiveBad is called to handle effect removal or penalty. Permanent effects are reapplied on respawn through a delayed task in onPlayerRespawn, ensuring consistency of effects throughout a player's session .

The KillEffectPlugin uses a permission system that ties the execution of the /godpot command to a specific permission node, killeffect.godpot. This permission is set to default to 'op', meaning only players with operator status or those specifically granted this permission can use the command. This ensures control over who can distribute God Potions within the game environment .

The KillEffectPlugin identifies a God Potion by checking the item's meta for the presence of a custom key ('godpot') in its PersistentDataContainer. If this key is present, the item is identified as a God Potion . When a player attempts to consume a God Potion, the consume event is canceled, and a GUI is opened for the player to select an effect from the available good effects, which will then be applied permanently to them .

When interacting with a God Potion, the KillEffectPlugin opens a GUI that presents an inventory interface titled 'Choose an Effect'. It displays available good effects as potions, indicating whether a player already has them with distinct color coding and enchant glows. This intuitive interface enhances user interaction by providing a straightforward way to choose effects visually, emphasizing accessibility and user-friendly design .

The KillEffectPlugin initiates an animated sequence for potion effect rolls through the startRollAnimation method. This animation consists of rolling text messages ('Roll.', 'Roll..', 'Roll...') sent sequentially to the player, followed by the assignment of a random good effect. The purpose of this animation is to build suspense and enhance the player's engagement when they receive a new effect after killing another player .

To craft a God Potion in the KillEffectPlugin, a player must use a shaped recipe requiring specific materials arranged in a 3x3 formation: two diamond blocks, one iron ingot, one emerald block, one prismarine crystal (used as a blue shard replacement), and one water bottle. These materials, when placed correctly, create a potion with default effect properties, which are then altered by the plugin's mechanisms .

Tab completion for the /godpot command is implemented using the onTabComplete method. When a player starts typing the command, the method checks if the first argument is 'give'. It then provides available online player names as suggestions for the second argument and valid potion effects as suggestions for the third argument. The suggestions are filtered based on what the player has already typed .

A player might receive a bad effect after a death if they have no existing good effects at the time of their death. The plugin checks a player's permanent effects; if none are found, a bad effect is randomly selected from a list of bad effects (e.g., Poison, Wither, Slow, Blindness) and applied to the player for 30 seconds .

You might also like