Skip to content

Commit

Permalink
Add original PR
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD authored Dec 7, 2023
2 parents c0cd77e + 3c6803e commit a294e54
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package io.github.thebusybiscuit.slimefun4.api.events;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack;

import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.Talisman;

/**
*
* This {@link PlayerEvent} is called when a {@link Player} activates a {@link Talisman}
*
* @author cworldstar
*
*/

public class TalismanActivatedEvent extends PlayerEvent implements Cancellable {

private static HandlerList Handlers = new HandlerList();
private Talisman talisman;
private ItemStack talismanItemStack;
private boolean cancelled = false;


/**
*
* @param player
* The {@link Player} who activated the talisman.
*
* @param talisman
* The {@link Talisman} that was activated.
*
* @param talismanItem
* The {@link ItemStack} corresponding to the Talisman.
*/
@ParametersAreNonnullByDefault
public TalismanActivatedEvent(Player player, Talisman talisman, ItemStack talismanItem) {
super(player);
this.talisman = talisman;
this.talismanItemStack = talismanItem;
}
/**
*
* @return The {@link Talisman} used.
*
*/
@Nonnull
public Talisman getTalisman() {
return this.talisman;
}
/**
*
* @return The {@link ItemStack} of the used {@link Talisman}.
*/
@Nonnull
public ItemStack getTalismanItem() {
return this.talismanItemStack;
}

public static HandlerList getHandlerList() {
return Handlers;
}

@Override
public HandlerList getHandlers() {
return getHandlerList();
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.annotation.ParametersAreNonnullByDefault;

import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
Expand All @@ -27,6 +28,7 @@

import io.github.bakedlibs.dough.items.CustomItemStack;
import io.github.bakedlibs.dough.items.ItemUtils;
import io.github.thebusybiscuit.slimefun4.api.events.TalismanActivatedEvent;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
Expand Down Expand Up @@ -203,12 +205,17 @@ public static boolean trigger(Event e, SlimefunItem item, boolean sendMessage) {

@ParametersAreNonnullByDefault
private static void activateTalisman(Event e, Player p, Inventory inv, Talisman talisman, ItemStack talismanItem, boolean sendMessage) {
consumeItem(inv, talisman, talismanItem);
applyTalismanEffects(p, talisman);
cancelEvent(e, talisman);
TalismanActivatedEvent TalismanEvent = new TalismanActivatedEvent(p, talisman, talismanItem);
Bukkit.getPluginManager().callEvent(TalismanEvent);
if (!TalismanEvent.isCancelled()) {
consumeItem(inv, talisman, talismanItem);
applyTalismanEffects(p, talisman);
cancelEvent(e, talisman);

if (sendMessage) {
talisman.sendMessage(p);

if (sendMessage) {
talisman.sendMessage(p);
}
}
}

Expand Down

0 comments on commit a294e54

Please sign in to comment.