forked from Slimefun/Slimefun4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Slimefun:master' into master
- Loading branch information
Showing
12 changed files
with
300 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemSpawnEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package io.github.thebusybiscuit.slimefun4.api.events; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import org.apache.commons.lang.Validate; | ||
import org.bukkit.Location; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSpawnReason; | ||
|
||
/** | ||
* This {@link Event} is fired whenever slimefun drops an {@link ItemStack}. | ||
* Creating a custom {@link Event} for this allows other plugins to provide | ||
* compatibility with auto-pickup options or similar. | ||
* | ||
* @author TheBusyBiscuit | ||
* | ||
* @see ItemSpawnReason | ||
*/ | ||
public class SlimefunItemSpawnEvent extends Event implements Cancellable { | ||
|
||
private static final HandlerList handlers = new HandlerList(); | ||
|
||
private Location location; | ||
private ItemStack itemStack; | ||
private boolean cancelled; | ||
private final ItemSpawnReason itemSpawnReason; | ||
|
||
@ParametersAreNonnullByDefault | ||
public SlimefunItemSpawnEvent(Location location, ItemStack itemStack, ItemSpawnReason itemSpawnReason) { | ||
this.location = location; | ||
this.itemStack = itemStack; | ||
this.itemSpawnReason = itemSpawnReason; | ||
this.cancelled = false; | ||
} | ||
|
||
/** | ||
* This returns the {@link ItemSpawnReason} why we dropped an {@link ItemStack}. | ||
* | ||
* @return the {@link ItemSpawnReason}. | ||
*/ | ||
public @Nonnull ItemSpawnReason getItemSpawnReason() { | ||
return itemSpawnReason; | ||
} | ||
|
||
/** | ||
* This returns the {@link Location} where we will drop the item. | ||
* | ||
* @return The {@link Location} where the item will be dropped | ||
*/ | ||
public @Nonnull Location getLocation() { | ||
return location; | ||
} | ||
|
||
/** | ||
* This sets the {@link Location} on where to drop this item. | ||
* | ||
* @param location | ||
* The {@link Location} where to drop the {@link ItemStack} | ||
*/ | ||
public void setLocation(@Nonnull Location location) { | ||
Validate.notNull(location, "The Location cannot be null!"); | ||
|
||
this.location = location; | ||
} | ||
|
||
/** | ||
* This returns the {@link ItemStack} that will be dropped. | ||
* | ||
* @return The {@link ItemStack} that will be dropped | ||
*/ | ||
public @Nonnull ItemStack getItemStack() { | ||
return itemStack; | ||
} | ||
|
||
/** | ||
* This method sets the {@link ItemStack} that should be dropped. | ||
* | ||
* @param itemStack | ||
* The {@link ItemStack} to drop | ||
*/ | ||
public void setItemStack(@Nonnull ItemStack itemStack) { | ||
Validate.notNull(itemStack, "Cannot drop null."); | ||
Validate.isTrue(!itemStack.getType().isAir(), "Cannot drop air."); | ||
|
||
this.itemStack = itemStack; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return cancelled; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean cancelled) { | ||
this.cancelled = cancelled; | ||
} | ||
|
||
public static @Nonnull HandlerList getHandlerList() { | ||
return handlers; | ||
} | ||
|
||
@Override | ||
public @Nonnull HandlerList getHandlers() { | ||
return getHandlerList(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSpawnReason.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.github.thebusybiscuit.slimefun4.api.items; | ||
|
||
import org.bukkit.block.Block; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import io.github.thebusybiscuit.slimefun4.api.events.SlimefunItemSpawnEvent; | ||
import io.github.thebusybiscuit.slimefun4.core.networks.cargo.CargoNet; | ||
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal; | ||
import io.github.thebusybiscuit.slimefun4.implementation.items.seasonal.ChristmasPresent; | ||
import io.github.thebusybiscuit.slimefun4.implementation.items.seasonal.EasterEgg; | ||
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GoldPan; | ||
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.PickaxeOfContainment; | ||
|
||
/** | ||
* This enum holds the different reasons as to why we may need to spawn an item. | ||
* | ||
* @author TheBusyBiscuit | ||
* | ||
* @see SlimefunItemSpawnEvent | ||
* | ||
*/ | ||
public enum ItemSpawnReason { | ||
|
||
/** | ||
* The item is spawned on top of an {@link AncientPedestal}. | ||
*/ | ||
ANCIENT_PEDESTAL_PLACE_ITEM, | ||
|
||
/** | ||
* This {@link ItemStack} is dropped as a result of the {@link PickaxeOfContainment} | ||
* breaking a monster spawner. | ||
*/ | ||
BROKEN_SPAWNER_DROP, | ||
|
||
/** | ||
* The {@link ItemStack} is dropped as the result of a {@link CargoNet} | ||
* overflowing. | ||
*/ | ||
CARGO_OVERFLOW, | ||
|
||
/** | ||
* THe {@link ItemStack} is dropped as the result of an opened {@link ChristmasPresent}. | ||
*/ | ||
CHRISTMAS_PRESENT_OPENED, | ||
|
||
/** | ||
* THe {@link ItemStack} is dropped as the result of an opened {@link EasterEgg}. | ||
*/ | ||
EASTER_EGG_OPENED, | ||
|
||
/** | ||
* The {@link ItemStack} is dropped as the result of a {@link GoldPan} being used | ||
* on a {@link Block} which yields drops. | ||
*/ | ||
GOLD_PAN_USE, | ||
|
||
/** | ||
* Other reasons we did not account for. | ||
*/ | ||
MISC; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.