Renamed flags to Flag because it was confusing.

Had to rename the class to FlagType as a result.

Rewrote FireListener to be simpler.

Wrote test case for fire listener.
This commit is contained in:
Tastybento 2018-02-20 14:06:09 -08:00
parent 58b1867b0d
commit b25d17fa78
35 changed files with 520 additions and 479 deletions

View File

@ -17,7 +17,7 @@ import us.tastybento.bskyblock.Constants.GameType;
import us.tastybento.bskyblock.api.configuration.ConfigEntry;
import us.tastybento.bskyblock.api.configuration.ISettings;
import us.tastybento.bskyblock.api.configuration.StoreAt;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.FlagType;
import us.tastybento.bskyblock.database.BSBDatabase.DatabaseType;
import us.tastybento.bskyblock.database.objects.adapters.Adapter;
import us.tastybento.bskyblock.database.objects.adapters.PotionEffectListAdapter;
@ -207,7 +207,7 @@ public class Settings implements ISettings<Settings> {
private int togglePvPCooldown;
private Map<Flag, Boolean> defaultFlags = new HashMap<>();
private Map<FlagType, Boolean> defaultFlags = new HashMap<>();
//TODO transform these options below into flags
private boolean allowEndermanGriefing;
@ -374,7 +374,7 @@ public class Settings implements ISettings<Settings> {
/**
* @return the defaultFlags
*/
public Map<Flag, Boolean> getDefaultFlags() {
public Map<FlagType, Boolean> getDefaultFlags() {
return defaultFlags;
}
/**
@ -925,7 +925,7 @@ public class Settings implements ISettings<Settings> {
/**
* @param defaultFlags the defaultFlags to set
*/
public void setDefaultFlags(Map<Flag, Boolean> defaultFlags) {
public void setDefaultFlags(Map<FlagType, Boolean> defaultFlags) {
this.defaultFlags = defaultFlags;
}
/**

View File

@ -75,7 +75,7 @@ public class User {
// ----------------------------------------------------
private final BSkyBlock plugin = BSkyBlock.getInstance();
private BSkyBlock plugin = BSkyBlock.getInstance();
private final Player player;
private final UUID playerUUID;
@ -99,6 +99,14 @@ public class User {
this.playerUUID = playerUUID;
sender = null;
}
/**
* Used for testing
* @param plugin
*/
public void setPlugin(BSkyBlock plugin) {
this.plugin = plugin;
}
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
return sender.getEffectivePermissions();

View File

@ -3,7 +3,7 @@ package us.tastybento.bskyblock.api.events.island;
import java.util.UUID;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.FlagType;
import us.tastybento.bskyblock.database.objects.Island;
/**
@ -16,7 +16,7 @@ import us.tastybento.bskyblock.database.objects.Island;
*/
public class FlagChangeEvent extends IslandBaseEvent {
private final UUID player;
private final Flag editedFlag;
private final FlagType editedFlag;
private final boolean setTo;
/**
@ -25,7 +25,7 @@ public class FlagChangeEvent extends IslandBaseEvent {
* @param editedFlag
* @param setTo
*/
public FlagChangeEvent(Island island, UUID player, Flag editedFlag, boolean setTo) {
public FlagChangeEvent(Island island, UUID player, FlagType editedFlag, boolean setTo) {
super(island);
this.player = player;
this.editedFlag = editedFlag;
@ -42,7 +42,7 @@ public class FlagChangeEvent extends IslandBaseEvent {
/**
* @return the edited flag
*/
public Flag getFlag() {
public FlagType getFlag() {
return editedFlag;
}

View File

@ -1,60 +0,0 @@
package us.tastybento.bskyblock.api.flags;
import java.util.Optional;
import org.bukkit.event.Listener;
import us.tastybento.bskyblock.api.panels.PanelItem;
public class Flag implements Comparable<Flag> {
public enum FlagType {
PROTECTION,
SETTING
}
private final String id;
private final PanelItem icon;
private final Listener listener;
private final FlagType type;
private boolean defaultSetting;
public Flag(String id2, PanelItem icon, Listener listener, boolean defaultSetting, FlagType type) {
id = id2;
this.icon = icon;
this.listener = listener;
this.type = type;
}
public String getID() {
return id;
}
public PanelItem getIcon() {
return icon;
}
public Optional<Listener> getListener() {
return Optional.ofNullable(listener);
}
public boolean isDefaultSetting() {
return defaultSetting;
}
public void setDefaultSetting(boolean defaultSetting) {
this.defaultSetting = defaultSetting;
}
/**
* @return the type
*/
public FlagType getType() {
return type;
}
@Override
public int compareTo(Flag o) {
return id.compareTo(o.getID());
}
}

View File

@ -4,7 +4,7 @@ import org.bukkit.Material;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import us.tastybento.bskyblock.api.flags.Flag.FlagType;
import us.tastybento.bskyblock.api.flags.FlagType.Type;
import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
@ -14,7 +14,7 @@ public class FlagBuilder {
private PanelItem icon;
private Listener listener;
private boolean defaultSetting;
private FlagType type = FlagType.PROTECTION;
private Type type = Type.PROTECTION;
public FlagBuilder id(String string) {
id = string;
@ -39,8 +39,8 @@ public class FlagBuilder {
return this;
}
public Flag build() {
return new Flag(id, icon, listener, defaultSetting, type);
public FlagType build() {
return new FlagType(id, icon, listener, defaultSetting, type);
}
/**
@ -55,10 +55,10 @@ public class FlagBuilder {
/**
* Set the type of this flag
* @param type {@link FlagType}
* @param type {@link Type}
* @return FlagBuilder
*/
public FlagBuilder type(FlagType type) {
public FlagBuilder type(Type type) {
this.type = type;
return this;
}

View File

@ -0,0 +1,103 @@
package us.tastybento.bskyblock.api.flags;
import java.util.Optional;
import org.bukkit.event.Listener;
import us.tastybento.bskyblock.api.panels.PanelItem;
public class FlagType {
public enum Type {
PROTECTION,
SETTING
}
private final String id;
private final PanelItem icon;
private final Listener listener;
private final Type type;
private boolean defaultSetting;
public FlagType(String id2, PanelItem icon, Listener listener, boolean defaultSetting, Type type) {
id = id2;
this.icon = icon;
this.listener = listener;
this.type = type;
}
public String getID() {
return id;
}
public PanelItem getIcon() {
return icon;
}
public Optional<Listener> getListener() {
return Optional.ofNullable(listener);
}
/**
* @return - true means it is allowed. false means it is not allowed
*/
public boolean isDefaultSetting() {
return defaultSetting;
}
/**
* Set the status of this flag for locations outside of island spaces
* @param defaultSetting - true means it is allowed. false means it is not allowed
*/
public void setDefaultSetting(boolean defaultSetting) {
this.defaultSetting = defaultSetting;
}
/**
* @return the type
*/
public Type getType() {
return type;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof FlagType)) {
return false;
}
FlagType other = (FlagType) obj;
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (type != other.type) {
return false;
}
return true;
}
}

View File

@ -25,7 +25,7 @@ import us.tastybento.bskyblock.api.events.island.IslandEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandLockEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandUnlockEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.FlagType;
import us.tastybento.bskyblock.database.objects.adapters.Adapter;
import us.tastybento.bskyblock.database.objects.adapters.FlagSerializer;
import us.tastybento.bskyblock.managers.RanksManager;
@ -89,7 +89,7 @@ public class Island implements DataObject {
//// Protection flags ////
@Adapter(FlagSerializer.class)
private Map<Flag, Integer> flags = new HashMap<>();
private Map<FlagType, Integer> flags = new HashMap<>();
private int levelHandicap;
@ -164,7 +164,7 @@ public class Island implements DataObject {
* @param flag
* @return the rank needed to bypass this flag. Players must have at least this rank to bypass this flag.
*/
public int getFlag(Flag flag){
public int getFlag(FlagType flag){
if(flags.containsKey(flag)) {
return flags.get(flag);
} else {
@ -176,7 +176,7 @@ public class Island implements DataObject {
/**
* @return the flags
*/
public Map<Flag, Integer> getFlags() {
public Map<FlagType, Integer> getFlags() {
return flags;
}
@ -428,7 +428,7 @@ public class Island implements DataObject {
* @param flag
* @return true if allowed, false if not
*/
public boolean isAllowed(Flag flag) {
public boolean isAllowed(FlagType flag) {
return getFlag(flag) >= 0;
}
@ -438,7 +438,7 @@ public class Island implements DataObject {
* @param flag - flag
* @return true if allowed, false if not
*/
public boolean isAllowed(User user, Flag flag) {
public boolean isAllowed(User user, FlagType flag) {
//Bukkit.getLogger().info("DEBUG: " + flag.getID() + " user score = " + getRank(user) + " flag req = "+ this.getFlagReq(flag));
return getRank(user) >= getFlag(flag);
}
@ -515,14 +515,14 @@ public class Island implements DataObject {
* @param flag
* @param value - rank value. If the flag applies to the island, a positive number = true, negative = false
*/
public void setFlag(Flag flag, int value){
public void setFlag(FlagType flag, int value){
flags.put(flag, value);
}
/**
* @param flags the flags to set
*/
public void setFlags(Map<Flag, Integer> flags) {
public void setFlags(Map<FlagType, Integer> flags) {
this.flags = flags;
}

View File

@ -8,7 +8,7 @@ import org.bukkit.Bukkit;
import org.bukkit.configuration.MemorySection;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.FlagType;
/**
* Serializes the {@link us.tastybento.bskyblock.database.objects.Island#getFlags() getFlags()} and
@ -17,12 +17,12 @@ import us.tastybento.bskyblock.api.flags.Flag;
* @author tastybento
*
*/
public class FlagSerializer implements AdapterInterface<Map<Flag, Integer>, Map<String, Integer>> {
public class FlagSerializer implements AdapterInterface<Map<FlagType, Integer>, Map<String, Integer>> {
@SuppressWarnings("unchecked")
@Override
public Map<Flag, Integer> serialize(Object object) {
Map<Flag, Integer> result = new HashMap<>();
public Map<FlagType, Integer> serialize(Object object) {
Map<FlagType, Integer> result = new HashMap<>();
if (object == null) {
return result;
}
@ -49,8 +49,8 @@ public class FlagSerializer implements AdapterInterface<Map<Flag, Integer>, Map<
if (object == null) {
return result;
}
Map<Flag, Integer> flags = (Map<Flag, Integer>)object;
for (Entry<Flag, Integer> en: flags.entrySet()) {
Map<FlagType, Integer> flags = (Map<FlagType, Integer>)object;
for (Entry<FlagType, Integer> en: flags.entrySet()) {
result.put(en.getKey().getID(), en.getValue());
}
return result;

View File

@ -16,8 +16,8 @@ import org.bukkit.event.Listener;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.Flag.FlagType;
import us.tastybento.bskyblock.api.flags.FlagType;
import us.tastybento.bskyblock.api.flags.FlagType.Type;
import us.tastybento.bskyblock.database.managers.island.IslandsManager;
import us.tastybento.bskyblock.database.objects.Island;
@ -66,7 +66,7 @@ public abstract class AbstractFlagListener implements Listener {
}
/**
* Explicitly set the user for the next {@link #checkIsland(Event, Location, Flag)} or {@link #checkIsland(Event, Location, Flag, boolean)}
* Explicitly set the user for the next {@link #checkIsland(Event, Location, FlagType)} or {@link #checkIsland(Event, Location, FlagType, boolean)}
* @param user - the User
*/
public AbstractFlagListener setUser(User user) {
@ -106,7 +106,8 @@ public abstract class AbstractFlagListener implements Listener {
}
/**
* Check if loc is in the island worlds
* Check if loc is in the island worlds.
* (If you are here because of an NPE in your test, then you need to do setPlugin(plugin) for your listener)
* @param loc - location
* @return true if the location is in the island worlds
*/
@ -141,7 +142,7 @@ public abstract class AbstractFlagListener implements Listener {
* @param breakBlocks
* @return true if the check is okay, false if it was disallowed
*/
public boolean checkIsland(Event e, Location loc, Flag breakBlocks) {
public boolean checkIsland(Event e, Location loc, FlagType breakBlocks) {
return checkIsland(e, loc, breakBlocks, false);
}
@ -154,7 +155,7 @@ public abstract class AbstractFlagListener implements Listener {
* @param silent - if true, no attempt is made to tell the user
* @return true if the check is okay, false if it was disallowed
*/
public boolean checkIsland(Event e, Location loc, Flag flag, boolean silent) {
public boolean checkIsland(Event e, Location loc, FlagType flag, boolean silent) {
// If this is not an Island World, skip
if (!inWorld(loc)) {
return true;
@ -162,9 +163,8 @@ public abstract class AbstractFlagListener implements Listener {
// Get the island and if present
Optional<Island> island = getIslands().getIslandAt(loc);
// Handle Settings Flag
if (flag.getType().equals(FlagType.SETTING)) {
if (flag.getType().equals(Type.SETTING)) {
// If the island exists, return the setting, otherwise return the default setting for this flag
return island.map(x -> x.isAllowed(flag)).orElse(flag.isDefaultSetting());
}
@ -181,7 +181,8 @@ public abstract class AbstractFlagListener implements Listener {
return false;
}
}
// Check if the plugin is set in User (required for testing)
user.setPlugin(plugin);
if (island.isPresent()) {
if (!island.get().isAllowed(user, flag)) {
@ -194,7 +195,6 @@ public abstract class AbstractFlagListener implements Listener {
return true;
}
}
// The player is in the world, but not on an island, so general world settings apply
if (!flag.isDefaultSetting()) {
noGo(e, silent);
@ -211,7 +211,7 @@ public abstract class AbstractFlagListener implements Listener {
* @param id
* @return Flag denoted by the id
*/
protected Flag id(String id) {
protected FlagType id(String id) {
return plugin.getFlagsManager().getFlagByID(id);
}

View File

@ -8,7 +8,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* @author ben
@ -27,17 +27,17 @@ public class BlockInteractionListener extends AbstractFlagListener {
}
switch (e.getClickedBlock().getType()) {
case ANVIL:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.ANVIL);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.ANVIL);
break;
case BEACON:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.BEACON);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.BEACON);
break;
case BED_BLOCK:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.BED);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.BED);
break;
case BREWING_STAND:
case CAULDRON:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.BREWING);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.BREWING);
break;
case CHEST:
case STORAGE_MINECART:
@ -63,7 +63,7 @@ public class BlockInteractionListener extends AbstractFlagListener {
case HOPPER:
case HOPPER_MINECART:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.CHEST);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.CHEST);
break;
case ACACIA_DOOR:
@ -77,7 +77,7 @@ public class BlockInteractionListener extends AbstractFlagListener {
case TRAP_DOOR:
case WOODEN_DOOR:
case WOOD_DOOR:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.DOOR);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.DOOR);
break;
case ACACIA_FENCE_GATE:
case BIRCH_FENCE_GATE:
@ -85,29 +85,29 @@ public class BlockInteractionListener extends AbstractFlagListener {
case FENCE_GATE:
case JUNGLE_FENCE_GATE:
case SPRUCE_FENCE_GATE:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.GATE);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.GATE);
break;
case BURNING_FURNACE:
case FURNACE:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.FURNACE);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.FURNACE);
break;
case ENCHANTMENT_TABLE:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.ENCHANTING);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.ENCHANTING);
break;
case ENDER_CHEST:
break;
case JUKEBOX:
case NOTE_BLOCK:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.MUSIC);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.MUSIC);
break;
case WORKBENCH:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.CRAFTING);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.CRAFTING);
break;
case STONE_BUTTON:
case WOOD_BUTTON:
case LEVER:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.LEVER_BUTTON);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.LEVER_BUTTON);
break;
case DIODE:
case DIODE_BLOCK_OFF:
@ -116,7 +116,7 @@ public class BlockInteractionListener extends AbstractFlagListener {
case REDSTONE_COMPARATOR_OFF:
case DAYLIGHT_DETECTOR:
case DAYLIGHT_DETECTOR_INVERTED:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.REDSTONE);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.REDSTONE);
break;
default:
break;
@ -125,10 +125,10 @@ public class BlockInteractionListener extends AbstractFlagListener {
if (e.getItem() != null) {
switch (e.getItem().getType()) {
case ENDER_PEARL:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.ENDER_PEARL);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.ENDER_PEARL);
break;
case MONSTER_EGG:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.SPAWN_EGGS);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.SPAWN_EGGS);
break;
default:
break;

View File

@ -18,7 +18,7 @@ import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.util.BlockIterator;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
public class BreakBlocksListener extends AbstractFlagListener {
@ -29,7 +29,7 @@ public class BreakBlocksListener extends AbstractFlagListener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockBreak(final BlockBreakEvent e) {
checkIsland(e, e.getBlock().getLocation(), Flags.BREAK_BLOCKS);
checkIsland(e, e.getBlock().getLocation(), Flag.BREAK_BLOCKS);
}
/**
@ -40,7 +40,7 @@ public class BreakBlocksListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW)
public void onBreakHanging(final HangingBreakByEntityEvent e) {
if (e.getRemover() instanceof Player) {
setUser(User.getInstance(e.getRemover())).checkIsland(e, e.getEntity().getLocation(), Flags.BREAK_BLOCKS);
setUser(User.getInstance(e.getRemover())).checkIsland(e, e.getEntity().getLocation(), Flag.BREAK_BLOCKS);
}
}
@ -63,7 +63,7 @@ public class BreakBlocksListener extends AbstractFlagListener {
while (iter.hasNext()) {
lastBlock = iter.next();
if (lastBlock.getType().equals(Material.SKULL)) {
checkIsland(e, lastBlock.getLocation(), Flags.BREAK_BLOCKS);
checkIsland(e, lastBlock.getLocation(), Flag.BREAK_BLOCKS);
return;
}
}
@ -73,7 +73,7 @@ public class BreakBlocksListener extends AbstractFlagListener {
case CAKE_BLOCK:
case DRAGON_EGG:
case MOB_SPAWNER:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.BREAK_BLOCKS);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.BREAK_BLOCKS);
return;
case BED_BLOCK:
if (e.getPlayer().getWorld().getEnvironment().equals(Environment.NETHER)) {
@ -97,7 +97,7 @@ public class BreakBlocksListener extends AbstractFlagListener {
User user = User.getInstance((Player) e.getAttacker());
// Get the island and if present, check the flag, react if required and return
getIslands().getIslandAt(e.getVehicle().getLocation()).ifPresent(x -> {
if (!x.isAllowed(user, Flags.BREAK_BLOCKS)) {
if (!x.isAllowed(user, Flag.BREAK_BLOCKS)) {
e.setCancelled(true);
user.sendMessage("protection.protected");
}
@ -105,7 +105,7 @@ public class BreakBlocksListener extends AbstractFlagListener {
});
// The player is in the world, but not on an island, so general world settings apply
if (!Flags.BREAK_BLOCKS.isDefaultSetting()) {
if (!Flag.BREAK_BLOCKS.isDefaultSetting()) {
e.setCancelled(true);
user.sendMessage("protection.protected");
}
@ -125,12 +125,12 @@ public class BreakBlocksListener extends AbstractFlagListener {
// Get the attacker
if (e.getDamager() instanceof Player) {
setUser(User.getInstance(e.getDamager())).checkIsland(e, e.getEntity().getLocation(), Flags.BREAK_BLOCKS);
setUser(User.getInstance(e.getDamager())).checkIsland(e, e.getEntity().getLocation(), Flag.BREAK_BLOCKS);
} else if (e.getDamager() instanceof Projectile) {
// Find out who fired the arrow
Projectile p = (Projectile) e.getDamager();
if (p.getShooter() instanceof Player) {
if (!setUser(User.getInstance((Player)p.getShooter())).checkIsland(e, e.getEntity().getLocation(), Flags.BREAK_BLOCKS)) {
if (!setUser(User.getInstance((Player)p.getShooter())).checkIsland(e, e.getEntity().getLocation(), Flag.BREAK_BLOCKS)) {
e.getEntity().setFireTicks(0);
e.getDamager().remove();
}

View File

@ -14,7 +14,7 @@ import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* Handles breeding protection
@ -43,7 +43,7 @@ public class BreedingListener extends AbstractFlagListener {
inHand = e.getPlayer().getInventory().getItemInOffHand();
}
if (inHand != null && BREEDING_ITEMS.contains(inHand.getType())) {
checkIsland(e, e.getRightClicked().getLocation(), Flags.BREEDING);
checkIsland(e, e.getRightClicked().getLocation(), Flag.BREEDING);
}
}
}

View File

@ -10,7 +10,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* Handles interaction with beds
@ -29,7 +29,7 @@ public class BucketListener extends AbstractFlagListener {
if (e.getBlockClicked() != null) {
// This is where the water or lava actually will be dumped
Block dumpBlock = e.getBlockClicked().getRelative(e.getBlockFace());
checkIsland(e, dumpBlock.getLocation(), Flags.BUCKET);
checkIsland(e, dumpBlock.getLocation(), Flag.BUCKET);
}
}
@ -40,17 +40,17 @@ public class BucketListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW)
public void onBucketFill(final PlayerBucketFillEvent e) {
// Check filling of various liquids
if (e.getItemStack().getType().equals(Material.LAVA_BUCKET) && (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA))) {
if (e.getItemStack().getType().equals(Material.LAVA_BUCKET) && (!checkIsland(e, e.getBlockClicked().getLocation(), Flag.COLLECT_LAVA))) {
return;
}
if (e.getItemStack().getType().equals(Material.WATER_BUCKET) && (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_WATER))) {
if (e.getItemStack().getType().equals(Material.WATER_BUCKET) && (!checkIsland(e, e.getBlockClicked().getLocation(), Flag.COLLECT_WATER))) {
return;
}
if (e.getItemStack().getType().equals(Material.MILK_BUCKET) && (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.MILKING))) {
if (e.getItemStack().getType().equals(Material.MILK_BUCKET) && (!checkIsland(e, e.getBlockClicked().getLocation(), Flag.MILKING))) {
return;
}
// Check general bucket use
checkIsland(e, e.getBlockClicked().getLocation(), Flags.BUCKET);
checkIsland(e, e.getBlockClicked().getLocation(), Flag.BUCKET);
}
}

View File

@ -7,7 +7,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerEggThrowEvent;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* Handles throwing regular eggs (not spawn eggs)
@ -22,7 +22,7 @@ public class EggListener extends AbstractFlagListener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEggThrow(PlayerEggThrowEvent e) {
if (!checkIsland(e, e.getEgg().getLocation(), Flags.EGGS)) {
if (!checkIsland(e, e.getEgg().getLocation(), Flag.EGGS)) {
e.setHatching(false);
}
}

View File

@ -12,7 +12,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* Handles interaction with entities like armor stands
@ -25,7 +25,7 @@ public class EntityInteractListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onPlayerInteract(final PlayerInteractAtEntityEvent e) {
if (e.getRightClicked() instanceof ArmorStand) {
checkIsland(e, e.getRightClicked().getLocation(), Flags.ARMOR_STAND);
checkIsland(e, e.getRightClicked().getLocation(), Flag.ARMOR_STAND);
}
}
@ -33,11 +33,11 @@ public class EntityInteractListener extends AbstractFlagListener {
public void onPlayerHitEntity(PlayerInteractEntityEvent e) {
// Animal riding
if (e.getRightClicked() instanceof Vehicle && e.getRightClicked() instanceof Animals) {
checkIsland(e, e.getRightClicked().getLocation(), Flags.RIDING);
checkIsland(e, e.getRightClicked().getLocation(), Flag.RIDING);
}
// Villager trading
if (e.getRightClicked().getType().equals(EntityType.VILLAGER)) {
checkIsland(e, e.getRightClicked().getLocation(), Flags.TRADING);
checkIsland(e, e.getRightClicked().getLocation(), Flag.TRADING);
}
}
}

View File

@ -3,12 +3,13 @@
*/
package us.tastybento.bskyblock.listeners.flags;
import java.util.Optional;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
@ -20,8 +21,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.util.BlockIterator;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.api.flags.FlagType;
import us.tastybento.bskyblock.lists.Flag;
/**
* Handles fire
@ -30,26 +31,36 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class FireListener extends AbstractFlagListener {
/**
* Checks if fire is allowed. If not, cancels the action
* @param e - cancellable event
* @param l - location
* @param flag - flag to check
* @return - true if cancelled, false if not
*/
public boolean checkFire(Cancellable e, Location l, FlagType flag) {
// Check world
if (!inWorld(l)) {
//Bukkit.getLogger().info("DEBUG: not in world");
return false;
}
//Bukkit.getLogger().info("DEBUG: in world");
// Check if the island exists and if fire is allowed
boolean cancel = getIslands().getIslandAt(l).map(i -> {
return !i.isAllowed(flag);
}).orElse(!flag.isDefaultSetting());
e.setCancelled(cancel);
return cancel;
}
/**
* Prevents fire spread
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockBurn(BlockBurnEvent e) {
if (!inWorld(e.getBlock().getLocation())) {
return;
}
// Check if the island exists and if fire is allowed
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
island.ifPresent(x -> {
if (!x.isAllowed(Flags.FIRE_SPREAD)) {
e.setCancelled(true);
}
});
// If not on an island, check the default setting
if (!island.isPresent() && !Flags.FIRE_SPREAD.isDefaultSetting()) {
e.setCancelled(true);
}
public boolean onBlockBurn(BlockBurnEvent e) {
return checkFire(e, e.getBlock().getLocation(), Flag.FIRE);
}
/**
@ -57,23 +68,8 @@ public class FireListener extends AbstractFlagListener {
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockSpread(BlockSpreadEvent e) {
if (e.getSource().getType().equals(Material.FIRE)) {
if (!inWorld(e.getBlock().getLocation())) {
return;
}
// Check if the island exists and if fire is allowed
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
island.ifPresent(x -> {
if (!x.isAllowed(Flags.FIRE_SPREAD)) {
e.setCancelled(true);
}
});
// If not on an island, check the default setting
if (!island.isPresent() && !Flags.FIRE_SPREAD.isDefaultSetting()) {
e.setCancelled(true);
}
}
public boolean onBlockSpread(BlockSpreadEvent e) {
return e.getSource().getType().equals(Material.FIRE) ? checkFire(e, e.getBlock().getLocation(), Flag.FIRE_SPREAD) : false;
}
/**
@ -81,26 +77,9 @@ public class FireListener extends AbstractFlagListener {
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockIgnite(BlockIgniteEvent e) {
if (!inWorld(e.getBlock().getLocation())) {
return;
}
public boolean onBlockIgnite(BlockIgniteEvent e) {
// Check if this is a portal lighting - that is allowed any time
if (e.getBlock().getType().equals(Material.OBSIDIAN)) {
return;
}
// Check if the island exists and if fire is allowed
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
island.ifPresent(x -> {
if (!x.isAllowed(Flags.FIRE)) {
e.setCancelled(true);
}
});
// If not on an island, check the default setting
if (!island.isPresent() && !Flags.FIRE.isDefaultSetting()) {
e.setCancelled(true);
}
return e.getBlock().getType().equals(Material.OBSIDIAN) ? false : checkFire(e, e.getBlock().getLocation(), Flag.FIRE);
}
/**
@ -110,19 +89,19 @@ public class FireListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent e) {
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getMaterial() != null && e.getMaterial().equals(Material.FLINT_AND_STEEL)) {
checkIsland(e, e.getClickedBlock().getLocation(), Flags.FIRE);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.FIRE);
}
// Look along player's sight line to see if any blocks are fire. Players can hit fire out quite a long way away.
try {
BlockIterator iter = new BlockIterator(e.getPlayer(), 10);
Block lastBlock = iter.next();
while (iter.hasNext()) {
Block lastBlock = iter.next();
lastBlock = iter.next();
if (lastBlock.equals(e.getClickedBlock())) {
break;
}
if (lastBlock.getType().equals(Material.FIRE)) {
checkIsland(e, lastBlock.getLocation(), Flags.FIRE_EXTINGUISH);
checkIsland(e, lastBlock.getLocation(), Flag.FIRE_EXTINGUISH);
}
}
} catch (Exception ex) {
@ -134,49 +113,48 @@ public class FireListener extends AbstractFlagListener {
* Protect TNT.
* Note that allowing TNT to explode is governed by the Break Blocks flag.
* @param e - event
* @return true if cancelled
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onTNTPrimed(EntityChangeBlockEvent e) {
public boolean onTNTPrimed(EntityChangeBlockEvent e) {
//Bukkit.getLogger().info("DEBUG: " + e.getBlock().getType());
return e.getBlock().getType().equals(Material.TNT) ? checkFire(e, e.getBlock().getLocation(), Flag.FIRE) : false;
}
/**
* Protect TNT from being set light by a fire arrow
* @param e
* @return true if cancelled
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public boolean onTNTDamage(EntityChangeBlockEvent e) {
// Check world
if (!inWorld(e.getBlock().getLocation())) {
return;
if (!e.getBlock().getType().equals(Material.TNT) || !inWorld(e.getBlock().getLocation())) {
Bukkit.getLogger().info("DEBUG: " + e.getBlock().getType());
return false;
}
// Check for TNT
if (!e.getBlock().getType().equals(Material.TNT)) {
//plugin.getLogger().info("DEBUG: not tnt");
return;
}
// Check if the island exists and if fire is allowed
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
island.ifPresent(x -> {
if (!x.isAllowed(Flags.FIRE)) {
e.setCancelled(true);
}
});
// If not on an island, check the default setting
if (!island.isPresent() && !Flags.FIRE.isDefaultSetting()) {
e.setCancelled(true);
}
// If either of these canceled the event, return
if (e.isCancelled()) {
return;
}
Bukkit.getLogger().info("DEBUG: in world");
// Stop TNT from being damaged if it is being caused by a visitor with a flaming arrow
if (e.getEntity() instanceof Projectile) {
Bukkit.getLogger().info("DEBUG: projectile");
Projectile projectile = (Projectile) e.getEntity();
// Find out who fired it
if (projectile.getShooter() instanceof Player) {
if (projectile.getFireTicks() > 0) {
Player shooter = (Player)projectile.getShooter();
if (setUser(User.getInstance(shooter)).checkIsland(e, e.getBlock().getLocation(), Flags.BREAK_BLOCKS)) {
// Remove the arrow
projectile.remove();
}
if (projectile.getShooter() instanceof Player && projectile.getFireTicks() > 0) {
Bukkit.getLogger().info("DEBUG: player fired a fire arrow");
Player shooter = (Player)projectile.getShooter();
setUser(User.getInstance(shooter));
Bukkit.getLogger().info("DEBUG: block loc = " + e.getBlock().getLocation());
Bukkit.getLogger().info("DEBUG: " + checkIsland(e, e.getBlock().getLocation(), Flag.BREAK_BLOCKS));
if (!setUser(User.getInstance(shooter)).checkIsland(e, e.getBlock().getLocation(), Flag.BREAK_BLOCKS)) {
Bukkit.getLogger().info("DEBUG: remove arrow");
// Remove the arrow
projectile.remove();
e.setCancelled(true);
return true;
}
}
}
return false;
}
}

View File

@ -31,8 +31,8 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.potion.PotionEffect;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.api.flags.FlagType;
import us.tastybento.bskyblock.lists.Flag;
/**
* Handles hurting of monsters and animals directly and indirectly
@ -54,9 +54,9 @@ public class HurtingListener extends AbstractFlagListener {
// Mobs being hurt
if (e.getEntity() instanceof Animals || e.getEntity() instanceof IronGolem || e.getEntity() instanceof Snowman
|| e.getEntity() instanceof Villager) {
respond(e, e.getDamager(), Flags.HURT_MOBS);
respond(e, e.getDamager(), Flag.HURT_MOBS);
} else if (e.getEntity() instanceof Monster || e.getEntity() instanceof Squid || e.getEntity() instanceof Slime) {
respond(e, e.getDamager(), Flags.HURT_MONSTERS);
respond(e, e.getDamager(), Flag.HURT_MONSTERS);
}
}
@ -66,7 +66,7 @@ public class HurtingListener extends AbstractFlagListener {
* @param damager
* @param hurtMobs
*/
private void respond(Event event, Entity damager, Flag hurtMobs) {
private void respond(Event event, Entity damager, FlagType hurtMobs) {
// Get the attacker
if (damager instanceof Player) {
setUser(User.getInstance(damager)).checkIsland(event, damager.getLocation(), hurtMobs);
@ -94,13 +94,13 @@ public class HurtingListener extends AbstractFlagListener {
}
if ((e.getCaught() instanceof Animals || e.getCaught() instanceof IronGolem || e.getCaught() instanceof Snowman
|| e.getCaught() instanceof Villager) && checkIsland(e, e.getCaught().getLocation(), Flags.HURT_MONSTERS)) {
|| e.getCaught() instanceof Villager) && checkIsland(e, e.getCaught().getLocation(), Flag.HURT_MONSTERS)) {
e.getHook().remove();
return;
}
if ((e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime)
&& checkIsland(e, e.getCaught().getLocation(), Flags.HURT_MONSTERS)) {
&& checkIsland(e, e.getCaught().getLocation(), Flag.HURT_MONSTERS)) {
e.getHook().remove();
return;
}
@ -115,7 +115,7 @@ public class HurtingListener extends AbstractFlagListener {
if (e.getRightClicked() instanceof Animals) {
if ((e.getHand().equals(EquipmentSlot.HAND) && e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.COOKIE))
|| (e.getHand().equals(EquipmentSlot.OFF_HAND) && e.getPlayer().getInventory().getItemInOffHand().getType().equals(Material.COOKIE))) {
checkIsland(e, e.getRightClicked().getLocation(), Flags.HURT_MOBS);
checkIsland(e, e.getRightClicked().getLocation(), Flag.HURT_MOBS);
}
}
}
@ -138,7 +138,7 @@ public class HurtingListener extends AbstractFlagListener {
}
// Monsters being hurt
if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) {
if (!setUser(User.getInstance(attacker)).checkIsland(e, entity.getLocation(), Flags.HURT_MONSTERS)) {
if (!setUser(User.getInstance(attacker)).checkIsland(e, entity.getLocation(), Flag.HURT_MONSTERS)) {
for (PotionEffect effect : e.getPotion().getEffects()) {
entity.removePotionEffect(effect.getType());
}
@ -148,7 +148,7 @@ public class HurtingListener extends AbstractFlagListener {
// Mobs being hurt
if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman
|| entity instanceof Villager) {
if (!checkIsland(e, entity.getLocation(), Flags.HURT_MONSTERS)) {
if (!checkIsland(e, entity.getLocation(), Flag.HURT_MONSTERS)) {
for (PotionEffect effect : e.getPotion().getEffects()) {
entity.removePotionEffect(effect.getType());
}
@ -189,12 +189,12 @@ public class HurtingListener extends AbstractFlagListener {
Entity entity = e.getEntity();
// Monsters being hurt
if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) {
checkIsland(e, entity.getLocation(), Flags.HURT_MONSTERS);
checkIsland(e, entity.getLocation(), Flag.HURT_MONSTERS);
}
// Mobs being hurt
if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman
|| entity instanceof Villager) {
checkIsland(e, entity.getLocation(), Flags.HURT_MONSTERS);
checkIsland(e, entity.getLocation(), Flag.HURT_MONSTERS);
}
}
}

View File

@ -17,7 +17,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryClickEvent;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* Handles inventory protection
@ -36,23 +36,23 @@ public class InventoryListener extends AbstractFlagListener {
return;
}
if (e.getInventory().getHolder() instanceof Animals) {
checkIsland(e, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
checkIsland(e, e.getInventory().getLocation(), Flag.MOUNT_INVENTORY);
}
else if (e.getInventory().getHolder() instanceof Chest
|| e.getInventory().getHolder() instanceof Dispenser
|| e.getInventory().getHolder() instanceof Hopper
|| e.getInventory().getHolder() instanceof Dropper
|| e.getInventory().getHolder() instanceof ShulkerBox) {
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flags.CHEST);
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flag.CHEST);
}
else if (e.getInventory().getHolder() instanceof Furnace) {
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flags.FURNACE);
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flag.FURNACE);
}
else if (e.getInventory().getHolder() instanceof BrewingStand) {
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flags.BREWING);
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flag.BREWING);
}
else if (e.getInventory().getHolder() instanceof Beacon) {
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flags.BEACON);
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flag.BEACON);
}
}

View File

@ -10,7 +10,7 @@ import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* @author tastybento
@ -23,7 +23,7 @@ public class ItemDropPickUpListener extends AbstractFlagListener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorDrop(PlayerDropItemEvent e) {
checkIsland(e, e.getItemDrop().getLocation(), Flags.ITEM_DROP);
checkIsland(e, e.getItemDrop().getLocation(), Flag.ITEM_DROP);
}
/*
@ -33,7 +33,7 @@ public class ItemDropPickUpListener extends AbstractFlagListener {
public void onVisitorPickup(EntityPickupItemEvent e) {
if (e.getEntity() instanceof Player) {
// Disallow, but don't tell the player an error
setUser(User.getInstance(e.getEntity())).checkIsland(e, e.getItem().getLocation(), Flags.ITEM_PICKUP, true);
setUser(User.getInstance(e.getEntity())).checkIsland(e, e.getItem().getLocation(), Flag.ITEM_PICKUP, true);
}
}
}

View File

@ -10,7 +10,7 @@ import org.bukkit.event.entity.PlayerLeashEntityEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerUnleashEntityEvent;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* @author tastybento
@ -25,7 +25,7 @@ public class LeashListener extends AbstractFlagListener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onLeashUse(PlayerLeashEntityEvent e) {
checkIsland(e, e.getEntity().getLocation(),Flags.LEASH);
checkIsland(e, e.getEntity().getLocation(),Flag.LEASH);
}
@ -36,7 +36,7 @@ public class LeashListener extends AbstractFlagListener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onLeashUse(PlayerUnleashEntityEvent e) {
checkIsland(e, e.getEntity().getLocation(),Flags.LEASH);
checkIsland(e, e.getEntity().getLocation(),Flag.LEASH);
}
/**
@ -46,7 +46,7 @@ public class LeashListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerLeashHitch(final HangingPlaceEvent e) {
if (e.getEntity() != null && e.getEntity().getType().equals(EntityType.LEASH_HITCH)) {
checkIsland(e, e.getEntity().getLocation(),Flags.LEASH);
checkIsland(e, e.getEntity().getLocation(),Flag.LEASH);
}
}

View File

@ -14,7 +14,7 @@ import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* Handles natural mob spawning.
@ -47,14 +47,14 @@ public class MobSpawnListener extends AbstractFlagListener {
// Cancel the event if these are true
if ((e.getEntity() instanceof Monster || e.getEntity() instanceof Slime)) {
boolean cancel = island.map(i -> {
return !i.isAllowed(Flags.MOB_SPAWN);
}).orElse(!Flags.MOB_SPAWN.isDefaultSetting());
return !i.isAllowed(Flag.MOB_SPAWN);
}).orElse(!Flag.MOB_SPAWN.isDefaultSetting());
e.setCancelled(cancel);
return cancel;
} else if (e.getEntity() instanceof Animals) {
boolean cancel = island.map(i -> {
return !i.isAllowed(Flags.MONSTER_SPAWN);
}).orElse(!Flags.MONSTER_SPAWN.isDefaultSetting());
return !i.isAllowed(Flag.MONSTER_SPAWN);
}).orElse(!Flag.MONSTER_SPAWN.isDefaultSetting());
e.setCancelled(cancel);
return cancel;
}

View File

@ -21,8 +21,8 @@ import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.potion.PotionEffect;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.api.flags.FlagType;
import us.tastybento.bskyblock.lists.Flag;
/**
* TODO: PVP is different to other flags - it's either allowed for everyone or not allowed for everyone. Currently owners can hit visitors.
@ -44,17 +44,17 @@ public class PVPListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageByEntityEvent e) {
if (e.getEntity() instanceof Player) {
Flag flag = Flags.PVP_OVERWORLD;
FlagType flag = Flag.PVP_OVERWORLD;
if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) {
flag = Flags.PVP_NETHER;
flag = Flag.PVP_NETHER;
} else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
flag = Flags.PVP_END;
flag = Flag.PVP_END;
}
respond(e, e.getDamager(), flag);
}
}
private void respond(Event event, Entity damager, Flag flag) {
private void respond(Event event, Entity damager, FlagType flag) {
// Get the attacker
if (damager instanceof Player) {
setUser(User.getInstance(damager)).checkIsland(event, damager.getLocation(), flag);
@ -75,11 +75,11 @@ public class PVPListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onFishing(PlayerFishEvent e) {
if (e.getCaught() != null && e.getCaught() instanceof Player) {
Flag flag = Flags.PVP_OVERWORLD;
FlagType flag = Flag.PVP_OVERWORLD;
if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) {
flag = Flags.PVP_NETHER;
flag = Flag.PVP_NETHER;
} else if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
flag = Flags.PVP_END;
flag = Flag.PVP_END;
}
if (checkIsland(e, e.getCaught().getLocation(), flag)) {
e.getHook().remove();
@ -95,11 +95,11 @@ public class PVPListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onSplashPotionSplash(final PotionSplashEvent e) {
// Deduce the world
Flag flag = Flags.PVP_OVERWORLD;
FlagType flag = Flag.PVP_OVERWORLD;
if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) {
flag = Flags.PVP_NETHER;
flag = Flag.PVP_NETHER;
} else if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
flag = Flags.PVP_END;
flag = Flag.PVP_END;
}
// Try to get the thrower
@ -144,11 +144,11 @@ public class PVPListener extends AbstractFlagListener {
if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) {
// Deduce the world
Flag flag = Flags.PVP_OVERWORLD;
FlagType flag = Flag.PVP_OVERWORLD;
if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) {
flag = Flags.PVP_NETHER;
flag = Flag.PVP_NETHER;
} else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
flag = Flags.PVP_END;
flag = Flag.PVP_END;
}
UUID attacker = thrownPotions.get(e.getDamager().getEntityId());

View File

@ -8,7 +8,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* @author ben
@ -29,14 +29,14 @@ public class PhysicalInteractionListener extends AbstractFlagListener {
switch (e.getClickedBlock().getType()) {
case SOIL:
// Crop trample
checkIsland(e, e.getPlayer().getLocation(), Flags.CROP_TRAMPLE);
checkIsland(e, e.getPlayer().getLocation(), Flag.CROP_TRAMPLE);
break;
case WOOD_PLATE:
case STONE_PLATE:
case GOLD_PLATE:
case IRON_PLATE:
// Pressure plates
checkIsland(e, e.getPlayer().getLocation(), Flags.PRESSURE_PLATE);
checkIsland(e, e.getPlayer().getLocation(), Flag.PRESSURE_PLATE);
break;
default:
break;

View File

@ -10,7 +10,7 @@ import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
public class PlaceBlocksListener extends AbstractFlagListener {
@ -21,7 +21,7 @@ public class PlaceBlocksListener extends AbstractFlagListener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockPlace(final BlockPlaceEvent e) {
checkIsland(e, e.getBlock().getLocation(), Flags.PLACE_BLOCKS);
checkIsland(e, e.getBlock().getLocation(), Flag.PLACE_BLOCKS);
}
/**
@ -31,7 +31,7 @@ public class PlaceBlocksListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerHitEntity(PlayerInteractEntityEvent e) {
if (e.getRightClicked().getType().equals(EntityType.ITEM_FRAME)) {
checkIsland(e, e.getRightClicked().getLocation(), Flags.PLACE_BLOCKS);
checkIsland(e, e.getRightClicked().getLocation(), Flag.PLACE_BLOCKS);
}
}
@ -47,7 +47,7 @@ public class PlaceBlocksListener extends AbstractFlagListener {
}
switch (e.getClickedBlock().getType()) {
case FIREWORK:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.PLACE_BLOCKS);
return;
case RAILS:
case POWERED_RAIL:
@ -55,7 +55,7 @@ public class PlaceBlocksListener extends AbstractFlagListener {
case ACTIVATOR_RAIL:
if (e.getMaterial() != null && (e.getMaterial() == Material.MINECART || e.getMaterial() == Material.STORAGE_MINECART || e.getMaterial() == Material.HOPPER_MINECART
|| e.getMaterial() == Material.EXPLOSIVE_MINECART || e.getMaterial() == Material.POWERED_MINECART)) {
checkIsland(e, e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
checkIsland(e, e.getClickedBlock().getLocation(), Flag.PLACE_BLOCKS);
}
return;
default:
@ -66,7 +66,7 @@ public class PlaceBlocksListener extends AbstractFlagListener {
if (e.getMaterial().equals(Material.END_CRYSTAL) || e.getMaterial() == Material.WOOD_DOOR || e.getMaterial() == Material.CHEST
|| e.getMaterial() == Material.TRAPPED_CHEST || e.getMaterial() == Material.IRON_DOOR
|| (e.getMaterial().name().contains("BOAT") && !e.getClickedBlock().isLiquid())) {
checkIsland(e, e.getPlayer().getLocation(), Flags.PLACE_BLOCKS);
checkIsland(e, e.getPlayer().getLocation(), Flag.PLACE_BLOCKS);
}
}
}
@ -80,7 +80,7 @@ public class PlaceBlocksListener extends AbstractFlagListener {
public void onBlockForm(EntityBlockFormEvent e) {
if (e.getNewState().getType().equals(Material.FROSTED_ICE)) {
// Silently check
checkIsland(e, e.getBlock().getLocation(), Flags.PLACE_BLOCKS, true);
checkIsland(e, e.getBlock().getLocation(), Flag.PLACE_BLOCKS, true);
}
}

View File

@ -8,7 +8,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* Handles portal protection
@ -23,10 +23,10 @@ public class PortalListener extends AbstractFlagListener {
return;
}
if (e.getCause().equals(TeleportCause.NETHER_PORTAL)) {
checkIsland(e, e.getFrom(), Flags.PORTAL);
checkIsland(e, e.getFrom(), Flag.PORTAL);
} else if (e.getCause().equals(TeleportCause.END_PORTAL)) {
// Silent check because it's spammy
checkIsland(e, e.getFrom(), Flags.PORTAL, true);
checkIsland(e, e.getFrom(), Flag.PORTAL, true);
}
}
}

View File

@ -7,7 +7,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerShearEntityEvent;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* Handles shearing
@ -19,7 +19,7 @@ public class ShearingListener extends AbstractFlagListener {
// Protect sheep
@EventHandler(priority = EventPriority.LOW)
public void onShear(final PlayerShearEntityEvent e) {
checkIsland(e, e.getEntity().getLocation(), Flags.SHEARING);
checkIsland(e, e.getEntity().getLocation(), Flag.SHEARING);
}
}

View File

@ -8,7 +8,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* Handles teleporting due to enderpearl or chorus fruit.
@ -27,9 +27,9 @@ public class TeleportationListener extends AbstractFlagListener {
if (e.getCause() != null) {
if (e.getCause().equals(TeleportCause.ENDER_PEARL)) {
checkIsland(e, e.getTo(), Flags.ENDER_PEARL);
checkIsland(e, e.getTo(), Flag.ENDER_PEARL);
} else if (e.getCause().equals(TeleportCause.CHORUS_FRUIT)) {
checkIsland(e, e.getTo(), Flags.CHORUS_FRUIT);
checkIsland(e, e.getTo(), Flag.CHORUS_FRUIT);
}
}
}

View File

@ -0,0 +1,136 @@
package us.tastybento.bskyblock.lists;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import us.tastybento.bskyblock.api.flags.FlagType;
import us.tastybento.bskyblock.api.flags.FlagType.Type;
import us.tastybento.bskyblock.api.flags.FlagBuilder;
import us.tastybento.bskyblock.listeners.flags.BlockInteractionListener;
import us.tastybento.bskyblock.listeners.flags.BreakBlocksListener;
import us.tastybento.bskyblock.listeners.flags.BreedingListener;
import us.tastybento.bskyblock.listeners.flags.BucketListener;
import us.tastybento.bskyblock.listeners.flags.EggListener;
import us.tastybento.bskyblock.listeners.flags.EntityInteractListener;
import us.tastybento.bskyblock.listeners.flags.FireListener;
import us.tastybento.bskyblock.listeners.flags.HurtingListener;
import us.tastybento.bskyblock.listeners.flags.InventoryListener;
import us.tastybento.bskyblock.listeners.flags.ItemDropPickUpListener;
import us.tastybento.bskyblock.listeners.flags.LeashListener;
import us.tastybento.bskyblock.listeners.flags.PVPListener;
import us.tastybento.bskyblock.listeners.flags.PhysicalInteractionListener;
import us.tastybento.bskyblock.listeners.flags.PlaceBlocksListener;
import us.tastybento.bskyblock.listeners.flags.PortalListener;
import us.tastybento.bskyblock.listeners.flags.ShearingListener;
import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
public class Flag {
public static final FlagType BREAK_BLOCKS = new FlagBuilder().id("BREAK_BLOCKS").icon(Material.STONE).listener(new BreakBlocksListener()).build();
public static final FlagType PLACE_BLOCKS = new FlagBuilder().id("PLACE_BLOCKS").icon(Material.DIRT).listener(new PlaceBlocksListener()).build();
// Block interactions - all use BlockInteractionListener()
public static final FlagType ANVIL = new FlagBuilder().id("ANVIL").icon(Material.ANVIL).listener(new BlockInteractionListener()).build();
public static final FlagType BEACON = new FlagBuilder().id("BEACON").icon(Material.BEACON).build();
public static final FlagType BED = new FlagBuilder().id("BED").icon(Material.BED).build();
public static final FlagType BREWING = new FlagBuilder().id("BREWING").icon(Material.BREWING_STAND_ITEM).build();
public static final FlagType CHEST = new FlagBuilder().id("CHEST").icon(Material.CHEST).build();
public static final FlagType DOOR = new FlagBuilder().id("DOOR").allowedByDefault(true).icon(Material.WOODEN_DOOR).build();
public static final FlagType CRAFTING = new FlagBuilder().id("CRAFTING").allowedByDefault(true).icon(Material.WORKBENCH).build();
public static final FlagType ENCHANTING = new FlagBuilder().id("ENCHANTING").allowedByDefault(true).icon(Material.ENCHANTMENT_TABLE).build();
public static final FlagType FURNACE = new FlagBuilder().id("FURNACE").icon(Material.FURNACE).build();
public static final FlagType GATE = new FlagBuilder().id("GATE").allowedByDefault(true).icon(Material.FENCE_GATE).build();
public static final FlagType MUSIC = new FlagBuilder().id("MUSIC").icon(Material.JUKEBOX).build();
public static final FlagType LEVER_BUTTON = new FlagBuilder().id("LEVER_BUTTON").icon(Material.LEVER).build();
public static final FlagType REDSTONE = new FlagBuilder().id("REDSTONE").icon(Material.REDSTONE).build();
public static final FlagType SPAWN_EGGS = new FlagBuilder().id("SPAWN_EGGS").icon(Material.MONSTER_EGG).build();
// Entity interactions
public static final FlagType ARMOR_STAND = new FlagBuilder().id("ARMOR_STAND").icon(Material.ARMOR_STAND).listener(new EntityInteractListener()).build();
public static final FlagType RIDING = new FlagBuilder().id("RIDING").icon(Material.GOLD_BARDING).build();
public static final FlagType TRADING = new FlagBuilder().id("TRADING").allowedByDefault(true).icon(Material.EMERALD).build();
// Breeding
public static final FlagType BREEDING = new FlagBuilder().id("BREEDING").icon(Material.CARROT).listener(new BreedingListener()).build();
// Buckets. All bucket use is covered by one listener
public static final FlagType BUCKET = new FlagBuilder().id("BUCKET").icon(Material.BUCKET).listener(new BucketListener()).build();
public static final FlagType COLLECT_LAVA = new FlagBuilder().id("COLLECT_LAVA").icon(Material.LAVA_BUCKET).build();
public static final FlagType COLLECT_WATER = new FlagBuilder().id("COLLECT_WATER").icon(Material.WATER_BUCKET).build();
public static final FlagType MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build();
// Chorus Fruit and Enderpearls
public static final FlagType CHORUS_FRUIT = new FlagBuilder().id("CHORUS_FRUIT").icon(Material.CHORUS_FRUIT).listener(new TeleportationListener()).build();
public static final FlagType ENDER_PEARL = new FlagBuilder().id("ENDER_PEARL").icon(Material.ENDER_PEARL).build();
// Physical interactions
public static final FlagType CROP_TRAMPLE = new FlagBuilder().id("CROP_TRAMPLE").icon(Material.WHEAT).listener(new PhysicalInteractionListener()).build();
public static final FlagType PRESSURE_PLATE = new FlagBuilder().id("PRESSURE_PLATE").icon(Material.GOLD_PLATE).build();
// Egg throwing
public static final FlagType EGGS = new FlagBuilder().id("EGGS").icon(Material.EGG).listener(new EggListener()).build();
/*
* Fire
* I'll take you to burn.
* Fire
* I'll take you to learn.
* You gonna burn, burn, burn
* Fire
* I'll take you to burn
* - The Crazy World of Arthur Brown
*/
public static final FlagType FIRE = new FlagBuilder().id("FIRE").icon(Material.FLINT_AND_STEEL).listener(new FireListener()).build();
public static final FlagType FIRE_EXTINGUISH = new FlagBuilder().id("FIRE_EXTINGUISH").icon(Material.POTION).build();
public static final FlagType FIRE_SPREAD = new FlagBuilder().id("FIRE_SPREAD").icon(Material.FIREWORK_CHARGE).build();
// Inventories
public static final FlagType MOUNT_INVENTORY = new FlagBuilder().id("MOUNT_INVENTORY").icon(Material.IRON_BARDING).listener(new InventoryListener()).build();
// Hurting things
public static final FlagType HURT_MOBS = new FlagBuilder().id("HURT_MOBS").icon(Material.STONE_SWORD).listener(new HurtingListener()).build();
public static final FlagType HURT_MONSTERS = new FlagBuilder().id("HURT_MONSTERS").icon(Material.WOOD_SWORD).build();
// Leashes
public static final FlagType LEASH = new FlagBuilder().id("LEASH").icon(Material.LEASH).listener(new LeashListener()).build();
// Portal use protection
public static final FlagType PORTAL = new FlagBuilder().id("PORTAL").icon(Material.OBSIDIAN).listener(new PortalListener()).build();
// Shearing
public static final FlagType SHEARING = new FlagBuilder().id("SHEARING").icon(Material.SHEARS).listener(new ShearingListener()).build();
// Item pickup or drop
public static final FlagType ITEM_DROP = new FlagBuilder().id("ITEM_DROP").icon(Material.DIRT).allowedByDefault(true).listener(new ItemDropPickUpListener()).build();
public static final FlagType ITEM_PICKUP = new FlagBuilder().id("ITEM_PICKUP").icon(Material.DIRT).build();
/*
* Settings flags (not protection flags)
*/
// PVP
public static final FlagType PVP_OVERWORLD = new FlagBuilder().id("PVP_OVERWORLD").icon(Material.ARROW).type(Type.SETTING).listener(new PVPListener()).build();
public static final FlagType PVP_NETHER = new FlagBuilder().id("PVP_NETHER").icon(Material.IRON_AXE).type(Type.SETTING).build();
public static final FlagType PVP_END = new FlagBuilder().id("PVP_END").icon(Material.END_CRYSTAL).type(Type.SETTING).build();
// Others
public static final FlagType ENTER_EXIT_MESSAGES = new FlagBuilder().id("ENTER_EXIT_MESSAGES").icon(Material.DIRT).allowedByDefault(true).type(Type.SETTING).build();
public static final FlagType MOB_SPAWN = new FlagBuilder().id("MOB_SPAWN").icon(Material.APPLE).allowedByDefault(true).type(Type.SETTING).build();
public static final FlagType MONSTER_SPAWN = new FlagBuilder().id("MONSTER_SPAWN").icon(Material.MOB_SPAWNER).allowedByDefault(true).type(Type.SETTING).build();
/**
* @return List of all the flags in this class
*/
public static List<FlagType> values() {
return Arrays.asList(Flag.class.getFields()).stream().map(field -> {
try {
return (FlagType)field.get(null);
} catch (IllegalArgumentException | IllegalAccessException e) {
Bukkit.getLogger().severe("Could not get Flag values " + e.getMessage());
}
return null;
}).collect(Collectors.toList());
}
}

View File

@ -1,136 +0,0 @@
package us.tastybento.bskyblock.lists;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.Flag.FlagType;
import us.tastybento.bskyblock.api.flags.FlagBuilder;
import us.tastybento.bskyblock.listeners.flags.BlockInteractionListener;
import us.tastybento.bskyblock.listeners.flags.BreakBlocksListener;
import us.tastybento.bskyblock.listeners.flags.BreedingListener;
import us.tastybento.bskyblock.listeners.flags.BucketListener;
import us.tastybento.bskyblock.listeners.flags.EggListener;
import us.tastybento.bskyblock.listeners.flags.EntityInteractListener;
import us.tastybento.bskyblock.listeners.flags.FireListener;
import us.tastybento.bskyblock.listeners.flags.HurtingListener;
import us.tastybento.bskyblock.listeners.flags.InventoryListener;
import us.tastybento.bskyblock.listeners.flags.ItemDropPickUpListener;
import us.tastybento.bskyblock.listeners.flags.LeashListener;
import us.tastybento.bskyblock.listeners.flags.PVPListener;
import us.tastybento.bskyblock.listeners.flags.PhysicalInteractionListener;
import us.tastybento.bskyblock.listeners.flags.PlaceBlocksListener;
import us.tastybento.bskyblock.listeners.flags.PortalListener;
import us.tastybento.bskyblock.listeners.flags.ShearingListener;
import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
public class Flags {
public static final Flag BREAK_BLOCKS = new FlagBuilder().id("BREAK_BLOCKS").icon(Material.STONE).listener(new BreakBlocksListener()).build();
public static final Flag PLACE_BLOCKS = new FlagBuilder().id("PLACE_BLOCKS").icon(Material.DIRT).listener(new PlaceBlocksListener()).build();
// Block interactions - all use BlockInteractionListener()
public static final Flag ANVIL = new FlagBuilder().id("ANVIL").icon(Material.ANVIL).listener(new BlockInteractionListener()).build();
public static final Flag BEACON = new FlagBuilder().id("BEACON").icon(Material.BEACON).build();
public static final Flag BED = new FlagBuilder().id("BED").icon(Material.BED).build();
public static final Flag BREWING = new FlagBuilder().id("BREWING").icon(Material.BREWING_STAND_ITEM).build();
public static final Flag CHEST = new FlagBuilder().id("CHEST").icon(Material.CHEST).build();
public static final Flag DOOR = new FlagBuilder().id("DOOR").allowedByDefault(true).icon(Material.WOODEN_DOOR).build();
public static final Flag CRAFTING = new FlagBuilder().id("CRAFTING").allowedByDefault(true).icon(Material.WORKBENCH).build();
public static final Flag ENCHANTING = new FlagBuilder().id("ENCHANTING").allowedByDefault(true).icon(Material.ENCHANTMENT_TABLE).build();
public static final Flag FURNACE = new FlagBuilder().id("FURNACE").icon(Material.FURNACE).build();
public static final Flag GATE = new FlagBuilder().id("GATE").allowedByDefault(true).icon(Material.FENCE_GATE).build();
public static final Flag MUSIC = new FlagBuilder().id("MUSIC").icon(Material.JUKEBOX).build();
public static final Flag LEVER_BUTTON = new FlagBuilder().id("LEVER_BUTTON").icon(Material.LEVER).build();
public static final Flag REDSTONE = new FlagBuilder().id("REDSTONE").icon(Material.REDSTONE).build();
public static final Flag SPAWN_EGGS = new FlagBuilder().id("SPAWN_EGGS").icon(Material.MONSTER_EGG).build();
// Entity interactions
public static final Flag ARMOR_STAND = new FlagBuilder().id("ARMOR_STAND").icon(Material.ARMOR_STAND).listener(new EntityInteractListener()).build();
public static final Flag RIDING = new FlagBuilder().id("RIDING").icon(Material.GOLD_BARDING).build();
public static final Flag TRADING = new FlagBuilder().id("TRADING").allowedByDefault(true).icon(Material.EMERALD).build();
// Breeding
public static final Flag BREEDING = new FlagBuilder().id("BREEDING").icon(Material.CARROT).listener(new BreedingListener()).build();
// Buckets. All bucket use is covered by one listener
public static final Flag BUCKET = new FlagBuilder().id("BUCKET").icon(Material.BUCKET).listener(new BucketListener()).build();
public static final Flag COLLECT_LAVA = new FlagBuilder().id("COLLECT_LAVA").icon(Material.LAVA_BUCKET).build();
public static final Flag COLLECT_WATER = new FlagBuilder().id("COLLECT_WATER").icon(Material.WATER_BUCKET).build();
public static final Flag MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build();
// Chorus Fruit and Enderpearls
public static final Flag CHORUS_FRUIT = new FlagBuilder().id("CHORUS_FRUIT").icon(Material.CHORUS_FRUIT).listener(new TeleportationListener()).build();
public static final Flag ENDER_PEARL = new FlagBuilder().id("ENDER_PEARL").icon(Material.ENDER_PEARL).build();
// Physical interactions
public static final Flag CROP_TRAMPLE = new FlagBuilder().id("CROP_TRAMPLE").icon(Material.WHEAT).listener(new PhysicalInteractionListener()).build();
public static final Flag PRESSURE_PLATE = new FlagBuilder().id("PRESSURE_PLATE").icon(Material.GOLD_PLATE).build();
// Egg throwing
public static final Flag EGGS = new FlagBuilder().id("EGGS").icon(Material.EGG).listener(new EggListener()).build();
/*
* Fire
* I'll take you to burn.
* Fire
* I'll take you to learn.
* You gonna burn, burn, burn
* Fire
* I'll take you to burn
* - The Crazy World of Arthur Brown
*/
public static final Flag FIRE = new FlagBuilder().id("FIRE").icon(Material.FLINT_AND_STEEL).listener(new FireListener()).build();
public static final Flag FIRE_EXTINGUISH = new FlagBuilder().id("FIRE_EXTINGUISH").icon(Material.POTION).build();
public static final Flag FIRE_SPREAD = new FlagBuilder().id("FIRE_SPREAD").icon(Material.FIREWORK_CHARGE).build();
// Inventories
public static final Flag MOUNT_INVENTORY = new FlagBuilder().id("MOUNT_INVENTORY").icon(Material.IRON_BARDING).listener(new InventoryListener()).build();
// Hurting things
public static final Flag HURT_MOBS = new FlagBuilder().id("HURT_MOBS").icon(Material.STONE_SWORD).listener(new HurtingListener()).build();
public static final Flag HURT_MONSTERS = new FlagBuilder().id("HURT_MONSTERS").icon(Material.WOOD_SWORD).build();
// Leashes
public static final Flag LEASH = new FlagBuilder().id("LEASH").icon(Material.LEASH).listener(new LeashListener()).build();
// Portal use protection
public static final Flag PORTAL = new FlagBuilder().id("PORTAL").icon(Material.OBSIDIAN).listener(new PortalListener()).build();
// Shearing
public static final Flag SHEARING = new FlagBuilder().id("SHEARING").icon(Material.SHEARS).listener(new ShearingListener()).build();
// Item pickup or drop
public static final Flag ITEM_DROP = new FlagBuilder().id("ITEM_DROP").icon(Material.DIRT).allowedByDefault(true).listener(new ItemDropPickUpListener()).build();
public static final Flag ITEM_PICKUP = new FlagBuilder().id("ITEM_PICKUP").icon(Material.DIRT).build();
/*
* Settings flags (not protection flags)
*/
// PVP
public static final Flag PVP_OVERWORLD = new FlagBuilder().id("PVP_OVERWORLD").icon(Material.ARROW).type(FlagType.SETTING).listener(new PVPListener()).build();
public static final Flag PVP_NETHER = new FlagBuilder().id("PVP_NETHER").icon(Material.IRON_AXE).type(FlagType.SETTING).build();
public static final Flag PVP_END = new FlagBuilder().id("PVP_END").icon(Material.END_CRYSTAL).type(FlagType.SETTING).build();
// Others
public static final Flag ENTER_EXIT_MESSAGES = new FlagBuilder().id("ENTER_EXIT_MESSAGES").icon(Material.DIRT).allowedByDefault(true).type(FlagType.SETTING).build();
public static final Flag MOB_SPAWN = new FlagBuilder().id("MOB_SPAWN").icon(Material.APPLE).allowedByDefault(true).type(FlagType.SETTING).build();
public static final Flag MONSTER_SPAWN = new FlagBuilder().id("MONSTER_SPAWN").icon(Material.MOB_SPAWNER).allowedByDefault(true).type(FlagType.SETTING).build();
/**
* @return List of all the flags in this class
*/
public static List<Flag> values() {
return Arrays.asList(Flags.class.getFields()).stream().map(field -> {
try {
return (Flag)field.get(null);
} catch (IllegalArgumentException | IllegalAccessException e) {
Bukkit.getLogger().severe("Could not get Flag values " + e.getMessage());
}
return null;
}).collect(Collectors.toList());
}
}

View File

@ -7,9 +7,9 @@ import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.FlagType;
import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
/**
* @author Poslovitch
@ -18,7 +18,7 @@ import us.tastybento.bskyblock.lists.Flags;
public class FlagsManager {
private BSkyBlock plugin;
private HashMap<String, Flag> flags = new HashMap<>();
private HashMap<String, FlagType> flags = new HashMap<>();
/**
* Stores the flag listeners that have already been registered into Bukkit's API to avoid duplicates.
@ -29,7 +29,7 @@ public class FlagsManager {
this.plugin = plugin;
// Register default flags
for (Flag flag : Flags.values()) {
for (FlagType flag : Flag.values()) {
registerFlag(flag);
}
}
@ -38,7 +38,7 @@ public class FlagsManager {
* Register a new flag with BSkyBlock
* @param flag
*/
public void registerFlag(Flag flag) {
public void registerFlag(FlagType flag) {
//Bukkit.getLogger().info("DEBUG: registering flag " + flag.getID());
flags.put(flag.getID(), flag);
// If there is a listener which is not already registered, register it into Bukkit.
@ -50,7 +50,7 @@ public class FlagsManager {
});
}
public HashMap<String, Flag> getFlags() {
public HashMap<String, FlagType> getFlags() {
return flags;
}
@ -59,13 +59,13 @@ public class FlagsManager {
* @param id
* @return Flag or null if not known
*/
public Flag getFlagByID(String id) {
public FlagType getFlagByID(String id) {
//Bukkit.getLogger().info("DEBUG: requesting " + id + " flags size = " + flags.size());
return flags.get(id);
}
public Flag getFlagByIcon(PanelItem item) {
for (Flag flag : flags.values()) {
public FlagType getFlagByIcon(PanelItem item) {
for (FlagType flag : flags.values()) {
if (flag.getIcon().equals(item)) {
return flag;
}

View File

@ -15,7 +15,7 @@ import us.tastybento.bskyblock.util.FileLister;
/**
* @author Tastybento, Poslovitch
*/
public final class LocalesManager {
public class LocalesManager {
private BSkyBlock plugin;
private HashMap<Locale, BSBLocale> languages = new HashMap<>();

View File

@ -54,13 +54,13 @@ import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.FlagType;
import us.tastybento.bskyblock.api.flags.FlagBuilder;
import us.tastybento.bskyblock.database.managers.island.IslandsManager;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.listeners.flags.AbstractFlagListener;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
import us.tastybento.bskyblock.managers.FlagsManager;
import us.tastybento.bskyblock.managers.RanksManager;
import us.tastybento.bskyblock.util.Util;
@ -68,7 +68,7 @@ import us.tastybento.bskyblock.util.Util;
@RunWith(PowerMockRunner.class)
//@SuppressStaticInitializationFor("us.tastybento.BSkyBlock")
//@PrepareForTest( { Bukkit.class })
@PrepareForTest( { Flags.class })
@PrepareForTest( { Flag.class })
public class TestBSkyBlock {
private static final UUID MEMBER_UUID = UUID.randomUUID();
private static final UUID OWNER_UUID = UUID.randomUUID();
@ -133,7 +133,7 @@ public class TestBSkyBlock {
Mockito.when(ownerOfIsland.getUniqueId()).thenReturn(OWNER_UUID);
Mockito.when(visitorToIsland.getUniqueId()).thenReturn(VISITOR_UUID);
PowerMockito.mockStatic(Flags.class);
PowerMockito.mockStatic(Flag.class);
plugin = Mockito.mock(BSkyBlock.class);
flagsManager = new FlagsManager(plugin);
@ -430,27 +430,27 @@ public class TestBSkyBlock {
// Check default settings
// Owner should be able to do anything
assertTrue(island.isAllowed(owner, Flags.PLACE_BLOCKS));
assertTrue(island.isAllowed(owner, Flags.BREAK_BLOCKS));
assertTrue(island.isAllowed(owner, Flag.PLACE_BLOCKS));
assertTrue(island.isAllowed(owner, Flag.BREAK_BLOCKS));
// Visitor can do nothing
assertFalse(island.isAllowed(visitor, Flags.PLACE_BLOCKS));
assertFalse(island.isAllowed(visitor, Flags.BREAK_BLOCKS));
assertFalse(island.isAllowed(visitor, Flag.PLACE_BLOCKS));
assertFalse(island.isAllowed(visitor, Flag.BREAK_BLOCKS));
// Set up protection settings - members can break blocks, visitors and place blocks
island.setFlag(Flags.BREAK_BLOCKS, RanksManager.MEMBER_RANK);
assertFalse(island.isAllowed(visitor, Flags.BREAK_BLOCKS));
island.setFlag(Flag.BREAK_BLOCKS, RanksManager.MEMBER_RANK);
assertFalse(island.isAllowed(visitor, Flag.BREAK_BLOCKS));
island.setFlag(Flags.PLACE_BLOCKS, RanksManager.VISITOR_RANK);
assertFalse(island.isAllowed(visitor, Flags.BREAK_BLOCKS));
island.setFlag(Flag.PLACE_BLOCKS, RanksManager.VISITOR_RANK);
assertFalse(island.isAllowed(visitor, Flag.BREAK_BLOCKS));
// Owner should be able to do anything
assertTrue(island.isAllowed(owner, Flags.PLACE_BLOCKS));
assertTrue(island.isAllowed(owner, Flags.BREAK_BLOCKS));
assertTrue(island.isAllowed(owner, Flag.PLACE_BLOCKS));
assertTrue(island.isAllowed(owner, Flag.BREAK_BLOCKS));
// Visitor can only place blocks
assertTrue(island.isAllowed(visitor, Flags.PLACE_BLOCKS));
assertFalse(island.isAllowed(visitor, Flags.BREAK_BLOCKS));
assertTrue(island.isAllowed(visitor, Flag.PLACE_BLOCKS));
assertFalse(island.isAllowed(visitor, Flag.BREAK_BLOCKS));
// Check if the members have capability
User mem1 = User.getInstance(member1); // Visitor
@ -459,16 +459,16 @@ public class TestBSkyBlock {
User mem3 = User.getInstance(member3); // Banned
// Member 1 is a visitor
assertTrue(island.isAllowed(mem1, Flags.PLACE_BLOCKS));
assertFalse(island.isAllowed(mem1, Flags.BREAK_BLOCKS));
assertTrue(island.isAllowed(mem1, Flag.PLACE_BLOCKS));
assertFalse(island.isAllowed(mem1, Flag.BREAK_BLOCKS));
// Member 2 is a team member
assertTrue(island.isAllowed(mem2, Flags.PLACE_BLOCKS));
assertTrue(island.isAllowed(mem2, Flags.BREAK_BLOCKS));
assertTrue(island.isAllowed(mem2, Flag.PLACE_BLOCKS));
assertTrue(island.isAllowed(mem2, Flag.BREAK_BLOCKS));
// Member 3 is no longer a member and is banned
assertFalse(island.isAllowed(mem3, Flags.PLACE_BLOCKS));
assertFalse(island.isAllowed(mem3, Flags.BREAK_BLOCKS));
assertFalse(island.isAllowed(mem3, Flag.PLACE_BLOCKS));
assertFalse(island.isAllowed(mem3, Flag.BREAK_BLOCKS));
}
@Test
@ -482,16 +482,16 @@ public class TestBSkyBlock {
Bukkit.getLogger().info("DEBUG: checking events - vistor");
Event e3 = new BlockBreakEvent(block, visitorToIsland);
Assert.assertFalse(fl.checkIsland(e3, location, Flags.BREAK_BLOCKS, true));
Assert.assertFalse(fl.checkIsland(e3, location, Flag.BREAK_BLOCKS, true));
Bukkit.getLogger().info("DEBUG: checking events - owner");
Event e = new BlockBreakEvent(block, ownerOfIsland);
Assert.assertTrue(fl.checkIsland(e, location, Flags.BREAK_BLOCKS, true));
Assert.assertTrue(fl.checkIsland(e, location, Flag.BREAK_BLOCKS, true));
Bukkit.getLogger().info("DEBUG: checking events - member");
Event e2 = new BlockBreakEvent(block, player);
Assert.assertTrue(fl.checkIsland(e2, location, Flags.BREAK_BLOCKS, true));
Assert.assertTrue(fl.checkIsland(e2, location, Flag.BREAK_BLOCKS, true));
}
@ -499,12 +499,12 @@ public class TestBSkyBlock {
public void TestDefaultFlags() {
// Check all the default flags
FlagsManager fm = new FlagsManager(plugin);
Collection<Flag> defaultFlags = Flags.values();
Collection<Flag> f = fm.getFlags().values();
for (Flag flag : defaultFlags) {
Collection<FlagType> defaultFlags = Flag.values();
Collection<FlagType> f = fm.getFlags().values();
for (FlagType flag : defaultFlags) {
assertTrue(flag.getID(), f.contains(flag));
}
for (Flag flag : f) {
for (FlagType flag : f) {
assertTrue(flag.getID(), defaultFlags.contains(flag));
}
}
@ -513,7 +513,7 @@ public class TestBSkyBlock {
public void TestCustomFlags() {
// Custom
FlagListener fl = new FlagListener(plugin);
Flag customFlag = new FlagBuilder().id("CUSTOM_FLAG").icon(Material.DIAMOND).listener(fl).build();
FlagType customFlag = new FlagBuilder().id("CUSTOM_FLAG").icon(Material.DIAMOND).listener(fl).build();
assertEquals("CUSTOM_FLAG", customFlag.getID());
assertEquals(Material.DIAMOND, customFlag.getIcon().getItem().getType());
assertEquals(fl, customFlag.getListener().get());

View File

@ -16,7 +16,11 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.World;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
@ -38,7 +42,15 @@ public class MySQLDatabaseHandlerTest {
*/
@BeforeClass
public static void setUp() throws Exception {
Server server = mock(Server.class);
World world = mock(World.class);
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
when(server.getWorld("world")).thenReturn(world);
when(server.getVersion()).thenReturn("BSB_Mocking");
Bukkit.setServer(server);
BSkyBlock plugin = mock(BSkyBlock.class);
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
MySQLDatabaseConnecter dbConn = mock(MySQLDatabaseConnecter.class);
Connection connection = mock(Connection.class);
when(dbConn.createConnection()).thenReturn(connection);

View File

@ -6,7 +6,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.World;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.FlagType;
import us.tastybento.bskyblock.database.objects.DataObject;
import us.tastybento.bskyblock.database.objects.adapters.Adapter;
import us.tastybento.bskyblock.database.objects.adapters.FlagSerializer;
@ -59,7 +59,7 @@ public class MySQLDatabaseHandlerTestDataObject implements DataObject {
//// Protection flags ////
@Adapter(FlagSerializer.class)
private HashMap<Flag, Integer> flags = new HashMap<>();
private HashMap<FlagType, Integer> flags = new HashMap<>();
private int levelHandicap;
private Location spawnPoint;
@ -307,14 +307,14 @@ public class MySQLDatabaseHandlerTestDataObject implements DataObject {
/**
* @return the flags
*/
public HashMap<Flag, Integer> getFlags() {
public HashMap<FlagType, Integer> getFlags() {
return flags;
}
/**
* @param flags the flags to set
*/
public void setFlags(HashMap<Flag, Integer> flags) {
public void setFlags(HashMap<FlagType, Integer> flags) {
this.flags = flags;
}

View File

@ -36,11 +36,11 @@ import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.database.managers.island.IslandsManager;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.lists.Flag;
import us.tastybento.bskyblock.managers.FlagsManager;
@RunWith(PowerMockRunner.class)
@PrepareForTest( { Flags.class })
@PrepareForTest( { Flag.class })
public class MobSpawnListenerTest {
private static Location location;
@ -75,7 +75,7 @@ public class MobSpawnListenerTest {
when(location.getBlockX()).thenReturn(0);
when(location.getBlockY()).thenReturn(0);
when(location.getBlockZ()).thenReturn(0);
PowerMockito.mockStatic(Flags.class);
PowerMockito.mockStatic(Flag.class);
plugin = Mockito.mock(BSkyBlock.class);
flagsManager = new FlagsManager(plugin);
@ -220,8 +220,8 @@ public class MobSpawnListenerTest {
when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty());
// Block mobs
Flags.MONSTER_SPAWN.setDefaultSetting(false);
Flags.MOB_SPAWN.setDefaultSetting(false);
Flag.MONSTER_SPAWN.setDefaultSetting(false);
Flag.MOB_SPAWN.setDefaultSetting(false);
// Setup event
CreatureSpawnEvent e = mock(CreatureSpawnEvent.class);
when(e.getLocation()).thenReturn(location);
@ -248,8 +248,8 @@ public class MobSpawnListenerTest {
when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty());
// Block mobs
Flags.MONSTER_SPAWN.setDefaultSetting(true);
Flags.MOB_SPAWN.setDefaultSetting(true);
Flag.MONSTER_SPAWN.setDefaultSetting(true);
Flag.MOB_SPAWN.setDefaultSetting(true);
// Setup event
CreatureSpawnEvent e = mock(CreatureSpawnEvent.class);