Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package us.thezircon.play.autopickup.events;

import org.bukkit.entity.Player;
import us.thezircon.play.autopickup.utils.events.CancellableEvent;

import javax.annotation.Nullable;

public class AutoPickUpEvent extends CancellableEvent {

private final @Nullable Player player;

public AutoPickUpEvent(@Nullable Player player) {
this.player = player;
}

public @Nullable Player getPlayer() {
return player;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable;
import us.thezircon.play.autopickup.AutoPickup;
import us.thezircon.play.autopickup.events.AutoPickUpEvent;
import us.thezircon.play.autopickup.utils.HexFormat;
import us.thezircon.play.autopickup.utils.Mendable;
import us.thezircon.play.autopickup.utils.PickupObjective;
Expand Down Expand Up @@ -145,6 +146,13 @@ public void run() {
}
}.runTaskLater(PLUGIN, 1);

// Call event and check for cancel
AutoPickUpEvent autoPickUpEvent = new AutoPickUpEvent(player);
autoPickUpEvent.call();

if (autoPickUpEvent.isCancelled())
return;

// Mend Items & Give Player XP
int xp = e.getExpToDrop();
player.giveExp(xp); // Give player XP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.inventory.ItemStack;
import us.thezircon.play.autopickup.AutoPickup;
import us.thezircon.play.autopickup.events.AutoPickUpEvent;
import us.thezircon.play.autopickup.utils.AutoSmelt;
import us.thezircon.play.autopickup.utils.HexFormat;

Expand Down Expand Up @@ -44,6 +45,14 @@ public void onDrop(BlockDropItemEvent e) {
return;
}

// Call event and check for cancel
AutoPickUpEvent autoPickUpEvent = new AutoPickUpEvent(player);
autoPickUpEvent.call();

if (autoPickUpEvent.isCancelled())
return;


// if (block.getState() instanceof Container) {
// return; // Containers are handled in block break event
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import us.thezircon.play.autopickup.AutoPickup;
import us.thezircon.play.autopickup.events.AutoPickUpEvent;

import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -62,6 +63,12 @@ public void run() {
}
}

// Call event and check for cancel
AutoPickUpEvent autoPickUpEvent = new AutoPickUpEvent(player);
autoPickUpEvent.call();

if (autoPickUpEvent.isCancelled())
return;


// Mend Items & Give Player XP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.inventory.ItemStack;
import us.thezircon.play.autopickup.AutoPickup;
import us.thezircon.play.autopickup.events.AutoPickUpEvent;

import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -33,6 +34,13 @@ public void onDrop(EntityDropItemEvent e) {
return;
}

// Call event and check for cancel
AutoPickUpEvent autoPickUpEvent = new AutoPickUpEvent(null);
autoPickUpEvent.call();

if (autoPickUpEvent.isCancelled())
return;

UUID sheep = e.getEntity().getUniqueId();
if (player_sheep_map.containsKey(sheep)) {
Player player = Bukkit.getPlayer(player_sheep_map.get(sheep));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import us.thezircon.play.autopickup.AutoPickup;
import us.thezircon.play.autopickup.events.AutoPickUpEvent;

import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -52,6 +53,13 @@ public void onDeath(MythicMobDeathEvent e) {
}
}

// Call event and check for cancel
AutoPickUpEvent autoPickUpEvent = new AutoPickUpEvent(player);
autoPickUpEvent.call();

if (autoPickUpEvent.isCancelled())
return;


// Drops
Iterator<ItemStack> iter = e.getDrops().iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import us.thezircon.play.autopickup.AutoPickup;
import us.thezircon.play.autopickup.events.AutoPickUpEvent;

import java.util.HashMap;

Expand All @@ -38,6 +39,13 @@ public void onClick(PlayerInteractEvent e) {
return;
}

// Call event and check for cancel
AutoPickUpEvent autoPickUpEvent = new AutoPickUpEvent(player);
autoPickUpEvent.call();

if (autoPickUpEvent.isCancelled())
return;

if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if(e.getClickedBlock().getType() == Material.SWEET_BERRY_BUSH) {
new BukkitRunnable() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package us.thezircon.play.autopickup.utils.events;

import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

public class CallableEvent extends Event {
private static final HandlerList handlers = new HandlerList();

private boolean isCalled = false;

public static HandlerList getHandlerList() {
return handlers;
}

public CallableEvent call() {
if (!this.isCalled) {
Bukkit.getPluginManager().callEvent(this);
this.isCalled = true;
}
return this;
}

public HandlerList getHandlers() {
return handlers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package us.thezircon.play.autopickup.utils.events;

import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;

public class CancellableEvent extends CallableEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();

private boolean isCancelled = false;

public static HandlerList getHandlerList() {
return handlers;
}

public HandlerList getHandlers() {
return handlers;
}

public boolean isCancelled() {
return this.isCancelled;
}

public void setCancelled(boolean b) {
this.isCancelled = b;
}
}