diff --git a/adapter/src/main/java/de/erethon/dungeonsxl/adapter/block/BlockAdapter.java b/adapter/src/main/java/de/erethon/dungeonsxl/adapter/block/BlockAdapter.java index 0fa34b33..46e3a96c 100644 --- a/adapter/src/main/java/de/erethon/dungeonsxl/adapter/block/BlockAdapter.java +++ b/adapter/src/main/java/de/erethon/dungeonsxl/adapter/block/BlockAdapter.java @@ -29,6 +29,8 @@ public interface BlockAdapter { void openDoor(Block block); + void closeDoor(Block block); + void setBlockWoolColor(Block block, Color color); BlockFace getFacing(Block block); diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/DungeonsAPI.java b/api/src/main/java/de/erethon/dungeonsxl/api/DungeonsAPI.java index 0d172b0b..bcaf7d70 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/DungeonsAPI.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/DungeonsAPI.java @@ -14,6 +14,7 @@ */ package de.erethon.dungeonsxl.api; +import de.erethon.caliburn.CaliburnAPI; import de.erethon.caliburn.mob.ExMob; import de.erethon.commons.misc.Registry; import de.erethon.dungeonsxl.api.dungeon.Dungeon; @@ -53,6 +54,13 @@ public interface DungeonsAPI extends Plugin { static final File CLASSES = new File(SCRIPTS, "classes"); static final File DUNGEONS = new File(SCRIPTS, "dungeons"); + /** + * Returns the loaded instance of the Caliburn API. + * + * @return the loaded instance of the Caliburn API + */ + CaliburnAPI getCaliburn(); + /** * Returns a cache of player wrapper objects. * diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/sign/AbstractDSign.java b/api/src/main/java/de/erethon/dungeonsxl/api/sign/AbstractDSign.java index b03d0585..22573250 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/sign/AbstractDSign.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/sign/AbstractDSign.java @@ -18,7 +18,9 @@ import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.api.Trigger; +import de.erethon.dungeonsxl.api.world.EditWorld; import de.erethon.dungeonsxl.api.world.GameWorld; +import de.erethon.dungeonsxl.api.world.InstanceWorld; import java.util.HashSet; import java.util.Set; import org.bukkit.ChatColor; @@ -39,16 +41,16 @@ public abstract class AbstractDSign implements DungeonSign { protected DungeonsAPI api; private Sign sign; private String[] lines; - private GameWorld gameWorld; + private InstanceWorld instance; private Set triggers = new HashSet<>(); private boolean initialized; private boolean erroneous; - protected AbstractDSign(DungeonsAPI api, Sign sign, String[] lines, GameWorld gameWorld) { + protected AbstractDSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { this.api = api; this.sign = sign; this.lines = lines; - this.gameWorld = gameWorld; + this.instance = instance; } @Override @@ -61,9 +63,14 @@ public abstract class AbstractDSign implements DungeonSign { return lines; } + @Override + public EditWorld getEditWorld() { + return instance instanceof EditWorld ? (EditWorld) instance : null; + } + @Override public GameWorld getGameWorld() { - return gameWorld; + return instance instanceof GameWorld ? (GameWorld) instance : null; } @Override diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/sign/Button.java b/api/src/main/java/de/erethon/dungeonsxl/api/sign/Button.java index de0ef8ba..27284c12 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/sign/Button.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/sign/Button.java @@ -16,7 +16,7 @@ package de.erethon.dungeonsxl.api.sign; import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.api.Trigger; -import de.erethon.dungeonsxl.api.world.GameWorld; +import de.erethon.dungeonsxl.api.world.InstanceWorld; import org.bukkit.block.Sign; import org.bukkit.entity.Player; @@ -30,8 +30,8 @@ import org.bukkit.entity.Player; */ public abstract class Button extends AbstractDSign { - protected Button(DungeonsAPI api, Sign sign, String[] lines, GameWorld gameWorld) { - super(api, sign, lines, gameWorld); + protected Button(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } /** diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/sign/Deactivatable.java b/api/src/main/java/de/erethon/dungeonsxl/api/sign/Deactivatable.java index 7a8cb479..9c60ab20 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/sign/Deactivatable.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/sign/Deactivatable.java @@ -17,7 +17,7 @@ package de.erethon.dungeonsxl.api.sign; import de.erethon.commons.player.PlayerCollection; import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.api.Trigger; -import de.erethon.dungeonsxl.api.world.GameWorld; +import de.erethon.dungeonsxl.api.world.InstanceWorld; import org.bukkit.block.Sign; import org.bukkit.entity.Player; @@ -29,48 +29,70 @@ import org.bukkit.entity.Player; public abstract class Deactivatable extends AbstractDSign { protected boolean active; - private PlayerCollection playersActivated = new PlayerCollection(); + protected PlayerCollection playersActivated = new PlayerCollection(); - protected Deactivatable(DungeonsAPI api, Sign sign, String[] lines, GameWorld gameWorld) { - super(api, sign, lines, gameWorld); + protected Deactivatable(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } /** * Sets the state to active. *

- * This might not be meaningful if the sign uses {@link #activate(org.bukkit.entity.Player)}. + * Note that the default implementation of {@link #activate(org.bukkit.entity.Player)} assumes that the sign does not need player specific behavior and + * simply calls this method, while the default implementation of this method assumes that the sign should perform + * {@link #activate(org.bukkit.entity.Player)} for each player in the game world. This leaves a button sign with a stackoverflow if not one of both methods + * at least is overriden. Consider using a {@link Passive} sign instead if you need a sign that simply marks places and ignores being triggered. An + * implementation that does not need player specific behavior should set {@link #active} to true. */ public void activate() { - active = true; + getGameWorld().getPlayers().forEach(p -> activate(p.getPlayer())); } /** * Sets the state to active for the given player. + *

+ * Note that the default implementation of this method assumes that the sign does not need player specific behavior and simply calls {@link #activate()}, + * while the default implementation of {@link #activate()} assumes that the sign should perform {@link #activate(org.bukkit.entity.Player)} for each player + * in the game world. This leaves a deactivatable sign with a stackoverflow if not one of both methods at least is overriden. Consider using a + * {@link Passive} sign instead if you need a sign that simply marks places and ignores being triggered. An implementation that needs player specific + * behavior should add the player to the {@link #playersActivated} collection. * * @param player the player * @return if the action was successful */ public boolean activate(Player player) { - return playersActivated.add(player); + activate(); + return true; } /** * Sets the state to inactive. *

- * This might not be meaningful if the sign uses {@link #deactivate(org.bukkit.entity.Player)}. + * Note that the default implementation of {@link #deactivate(org.bukkit.entity.Player)} assumes that the sign does not need player specific behavior and + * simply calls this method, while the default implementation of this method assumes that the sign should perform + * {@link #deactivate(org.bukkit.entity.Player)} for each player in the game world. This leaves a button sign with a stackoverflow if not one of both + * methods at least is overriden. Consider using a {@link Passive} sign instead if you need a sign that simply marks places and ignores being triggered. An + * implementation that does not need player specific behavior should set {@link #active} to false. */ public void deactivate() { - active = false; + getGameWorld().getPlayers().forEach(p -> deactivate(p.getPlayer())); } /** * Sets the state to inactive for the given player. + *

+ * Note that the default implementation of this method assumes that the sign does not need player specific behavior and simply calls + * {@link #deactivate()}, while the default implementation of {@link #deactivate()} assumes that the sign should perform + * {@link #deactivate(org.bukkit.entity.Player)} for each player in the game world. This leaves a deactivatable sign with a stackoverflow if not one of both + * methods at least is overriden. Consider using a {@link Passive} sign instead if you need a sign that simply marks places and ignores being triggered. An + * implementation that needs player specific behavior should remove the player from the {@link #playersActivated} collection. * * @param player the player * @return if the action was successful */ public boolean deactivate(Player player) { - return playersActivated.remove(player); + deactivate(); + return true; } /** @@ -86,12 +108,15 @@ public abstract class Deactivatable extends AbstractDSign { /** * Returns if the sign is activated for the given player. + *

+ * Note that the default implementation of this method assumes that the sign does not need player specific behavior and simply calls {@link #isActive()}. + * An implementation that needs player specific behavior should check if the {@link #playersActivated} collection contains the player. * * @param player the player * @return if the sign is activated for the given player */ public boolean isActive(Player player) { - return playersActivated.contains(player); + return isActive(); } @Override diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/sign/DungeonSign.java b/api/src/main/java/de/erethon/dungeonsxl/api/sign/DungeonSign.java index 35a10d5d..81adbfe7 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/sign/DungeonSign.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/sign/DungeonSign.java @@ -15,6 +15,8 @@ package de.erethon.dungeonsxl.api.sign; import de.erethon.dungeonsxl.api.Trigger; +import de.erethon.dungeonsxl.api.dungeon.Game; +import de.erethon.dungeonsxl.api.world.EditWorld; import de.erethon.dungeonsxl.api.world.GameWorld; import java.util.Set; import org.bukkit.block.Sign; @@ -64,25 +66,57 @@ public interface DungeonSign { /** * Returns the sign that represents event point. + *

+ * Use {@link #getLines()} instead to read the raw data of this dungeon sign. * * @return the sign that represents event point */ Sign getSign(); + /** + * Returns the raw line of this sign at the given index. + *

+ * These lines might not be the physical lines of {@link #getSign()}. + * + * @param index the line index (0-3) + * @return the raw lines of this sign in an array with 4 elements + */ + default String getLine(int index) { + return getLines()[index]; + } + /** * Returns the raw lines of this sign in an array with 4 elements. + *

+ * These lines might not be the physical lines of {@link #getSign()}. * * @return the raw lines of this sign in an array with 4 elements */ String[] getLines(); /** - * Returns the game world this sign is in; null if this is an edit world. + * Returns the edit world this sign is in; null if this is in a game world. * - * @return the game world this sign is in; null if this is an edit world + * @return the edit world this sign is in; null if this is in a game world + */ + EditWorld getEditWorld(); + + /** + * Returns the game world this sign is in; null if this is in an edit world. + * + * @return the game world this sign is in; null if this is in an edit world */ GameWorld getGameWorld(); + /** + * Returns the game played in the world of this sign. + * + * @return the game played in the world of this sign + */ + default Game getGame() { + return getGameWorld().getGame(); + } + /** * Returns a Set of the triggers registered for this sign. * @@ -157,9 +191,7 @@ public interface DungeonSign { * * @return if the sign is valid */ - default boolean validate() { - return true; - } + boolean validate(); /** * Returns if the sign is erroneous. diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/sign/Passive.java b/api/src/main/java/de/erethon/dungeonsxl/api/sign/Passive.java index b407bf6f..89311e16 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/sign/Passive.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/sign/Passive.java @@ -15,7 +15,7 @@ package de.erethon.dungeonsxl.api.sign; import de.erethon.dungeonsxl.api.DungeonsAPI; -import de.erethon.dungeonsxl.api.world.GameWorld; +import de.erethon.dungeonsxl.api.world.InstanceWorld; import org.bukkit.block.Sign; import org.bukkit.entity.Player; @@ -26,8 +26,8 @@ import org.bukkit.entity.Player; */ public abstract class Passive extends AbstractDSign { - protected Passive(DungeonsAPI api, Sign sign, String[] lines, GameWorld gameWorld) { - super(api, sign, lines, gameWorld); + protected Passive(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } /** diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/sign/Rocker.java b/api/src/main/java/de/erethon/dungeonsxl/api/sign/Rocker.java index ca31ec71..d86f9f20 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/sign/Rocker.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/sign/Rocker.java @@ -15,7 +15,7 @@ package de.erethon.dungeonsxl.api.sign; import de.erethon.dungeonsxl.api.DungeonsAPI; -import de.erethon.dungeonsxl.api.world.GameWorld; +import de.erethon.dungeonsxl.api.world.InstanceWorld; import org.bukkit.block.Sign; import org.bukkit.entity.Player; @@ -29,8 +29,8 @@ import org.bukkit.entity.Player; */ public abstract class Rocker extends Deactivatable { - protected Rocker(DungeonsAPI api, Sign sign, String[] lines, GameWorld gameWorld) { - super(api, sign, lines, gameWorld); + protected Rocker(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } /** diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/sign/Windup.java b/api/src/main/java/de/erethon/dungeonsxl/api/sign/Windup.java index 38f77dc4..f5e79f11 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/sign/Windup.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/sign/Windup.java @@ -15,8 +15,11 @@ package de.erethon.dungeonsxl.api.sign; import de.erethon.dungeonsxl.api.DungeonsAPI; -import de.erethon.dungeonsxl.api.world.GameWorld; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import org.bukkit.Bukkit; import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; /** * A sign with an attached task that does actions in a set interval {@link #n} times, like a mob sign that spawns {@link #n} mobs. It is similar to a @@ -26,6 +29,7 @@ import org.bukkit.block.Sign; */ public abstract class Windup extends Deactivatable { + protected double delay = -1; protected double interval = -1; /** * How many times the task is supposed to be executed (unless it is cancelled). @@ -36,26 +40,144 @@ public abstract class Windup extends Deactivatable { */ protected int k; - protected Windup(DungeonsAPI api, Sign sign, String[] lines, GameWorld gameWorld) { - super(api, sign, lines, gameWorld); + private Runnable runnable; + private BukkitTask task; + + protected Windup(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + /** + * Returns the delay before the task runs in seconds. If no delay is specified, this uses the interval. + * + * @return the delay before the task runs in seconds. If no delay is specified, this uses the interval + */ + public double getDelaySeconds() { + return delay != -1 ? delay : interval; + } + + /** + * Returns the delay before the task runs in ticks. If no delay is specified, this uses the interval. + * + * @return the delay before the task runs in ticks. If no delay is specified, this uses the interval + */ + public long getDelayTicks() { + return delay != -1 ? (long) (delay * 20L) : getIntervalTicks(); } /** * Returns the task interval in seconds. * - * @return the task interval + * @return the task interval in seconds */ public double getIntervalSeconds() { return interval; } /** - * Returns the task interval in seconds. + * Returns the task interval in ticks. * - * @return the task interval + * @return the task interval in ticks */ public long getIntervalTicks() { return (long) (interval * 20L); } + /** + * Returns the underlying task if it has started yet or null if not. + * + * @return the underlying task if it has started yet or null if not + */ + public BukkitTask getTask() { + return task; + } + + /** + * Starts the runnable. + */ + public void startTask() { + task = Bukkit.getScheduler().runTaskTimer(api, runnable, getDelayTicks(), getIntervalTicks()); + } + + /** + * Returns the runnable. + * + * @return the runnable + */ + public Runnable getRunnable() { + return runnable; + } + + /** + * Sets the runnable. + * + * @param runnable the runnable + */ + public void setRunnable(Runnable runnable) { + this.runnable = runnable; + } + + /** + * Returns how many times the task is supposed to be executed (like in SIGMA notation). + * + * @return how many times the task is supposed to be executed (like in SIGMA notation) + */ + public int getN() { + return n; + } + + /** + * Sets how many times the task is supposed to be executed (like in SIGMA notation). + * + * @param n the new amount of runs + */ + public void setN(int n) { + this.n = n; + } + + /** + * Returns how many times the task has already been executed (like in SIGMA notation). + * + * @return how many times the task has already been executed (like in SIGMA notation) + */ + public int getK() { + return k; + } + + /** + * Resets k (like in SIGMA notation) to 0. + */ + public void resetK() { + k = 0; + } + + @Override + public void activate() { + active = true; + startTask(); + } + + /** + * Cancels the {@link #getTask() task}. + */ + @Override + public void deactivate() { + active = false; + getTask().cancel(); + } + + /** + * Activates the sign if it is not yet active and deactivates it if it is already active. + * + * @param player the player who triggered the sign or null if no one in particular triggered it + */ + @Override + public void trigger(Player player) { + if (!isActive()) { + activate(player); + } else { + deactivate(); + } + } + } diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/world/GameWorld.java b/api/src/main/java/de/erethon/dungeonsxl/api/world/GameWorld.java index c0842649..2aad5b44 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/world/GameWorld.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/world/GameWorld.java @@ -16,7 +16,6 @@ package de.erethon.dungeonsxl.api.world; import de.erethon.dungeonsxl.api.dungeon.Dungeon; import de.erethon.dungeonsxl.api.dungeon.Game; -import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer; import de.erethon.dungeonsxl.api.mob.DungeonMob; import de.erethon.dungeonsxl.api.player.PlayerGroup; import java.util.Collection; @@ -105,4 +104,18 @@ public interface GameWorld extends InstanceWorld { */ Location getStartLocation(PlayerGroup group); + /** + * Returns if it is required to choose a class in order to start the game. + * + * @return if it is required to choose a class in order to start the game + */ + boolean areClassesEnabled(); + + /** + * Sets if it is required to choose a class in order to start the game. + * + * @param enabled if it is required to choose a class in order to start the game + */ + void setClassesEnabled(boolean enabled); + } diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/world/InstanceWorld.java b/api/src/main/java/de/erethon/dungeonsxl/api/world/InstanceWorld.java index 78f883cd..4d3b7f95 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/world/InstanceWorld.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/world/InstanceWorld.java @@ -21,6 +21,7 @@ import java.util.Collection; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.Sign; /** * Super interface for worlds that are instantiated by DungeonsXL. @@ -77,11 +78,13 @@ public interface InstanceWorld { Collection getDungeonSigns(); /** - * Adds a dungeon sign to this instance. + * Creates a dungeon sign in this instance. * - * @param sign the sign + * @param sign the sign block + * @param lines the lines of the sign + * @return the created sign */ - void addDungeonSign(DungeonSign sign); + DungeonSign createDungeonSign(Sign sign, String[] lines); /** * Removes the given dungeon sign from this instance. diff --git a/bukkit_blockdata/src/main/java/de/erethon/dungeonsxl/adapter/block/BlockAdapterBlockData.java b/bukkit_blockdata/src/main/java/de/erethon/dungeonsxl/adapter/block/BlockAdapterBlockData.java index b07d8dc5..2964a4d3 100644 --- a/bukkit_blockdata/src/main/java/de/erethon/dungeonsxl/adapter/block/BlockAdapterBlockData.java +++ b/bukkit_blockdata/src/main/java/de/erethon/dungeonsxl/adapter/block/BlockAdapterBlockData.java @@ -45,11 +45,21 @@ public class BlockAdapterBlockData implements BlockAdapter { if (!(block.getBlockData() instanceof Openable)) { throw new IllegalArgumentException("Block is not Openable"); } - Openable data = ((Openable) block.getBlockData()); + Openable data = (Openable) block.getBlockData(); data.setOpen(true); block.setBlockData(data); } + @Override + public void closeDoor(Block block) { + if (!(block.getBlockData() instanceof Openable)) { + throw new IllegalArgumentException("Block is not Openable"); + } + Openable data = (Openable) block.getBlockData(); + data.setOpen(false); + block.setBlockData(data); + } + @Override public void setBlockWoolColor(Block block, Color color) { block.setType(color.getWoolMaterial().getMaterial()); diff --git a/bukkit_magicvalues/src/main/java/de/erethon/dungeonsxl/adapter/block/BlockAdapterMagicValues.java b/bukkit_magicvalues/src/main/java/de/erethon/dungeonsxl/adapter/block/BlockAdapterMagicValues.java index d446d8a4..7b26603a 100644 --- a/bukkit_magicvalues/src/main/java/de/erethon/dungeonsxl/adapter/block/BlockAdapterMagicValues.java +++ b/bukkit_magicvalues/src/main/java/de/erethon/dungeonsxl/adapter/block/BlockAdapterMagicValues.java @@ -44,6 +44,11 @@ public class BlockAdapterMagicValues implements BlockAdapter { block.setData((byte) (block.getData() + 4)); } + @Override + public void closeDoor(Block block) { + block.setData((byte) (block.getData() - 4)); + } + @Override public void setBlockWoolColor(Block block, Color color) { block.setTypeIdAndData(Material.WOOL.getId(), color.getDyeColor().getWoolData(), false); diff --git a/core/pom.xml b/core/pom.xml index 4518b058..7f9be455 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -59,12 +59,6 @@ 1.7 provided - - io.github.dre2n - commandsxl - 2.1.2 - provided - net.citizensnpcs citizens diff --git a/core/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java b/core/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java index 3a969fac..58fa0ebd 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java +++ b/core/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java @@ -16,6 +16,9 @@ */ package de.erethon.dungeonsxl; +import de.erethon.dungeonsxl.sign.rocker.TriggerSign; +import de.erethon.dungeonsxl.sign.button.CheckpointSign; +import de.erethon.dungeonsxl.sign.button.SoundMessageSign; import de.erethon.caliburn.CaliburnAPI; import de.erethon.caliburn.loottable.LootTable; import de.erethon.caliburn.mob.ExMob; @@ -70,8 +73,10 @@ import de.erethon.dungeonsxl.player.SecureModeTask; import de.erethon.dungeonsxl.requirement.*; import de.erethon.dungeonsxl.reward.*; import de.erethon.dungeonsxl.sign.DSignListener; -import de.erethon.dungeonsxl.sign.DSignTypeDefault; -import de.erethon.dungeonsxl.sign.SignScriptCache; +import de.erethon.dungeonsxl.sign.button.*; +import de.erethon.dungeonsxl.sign.passive.*; +import de.erethon.dungeonsxl.sign.rocker.*; +import de.erethon.dungeonsxl.sign.windup.*; import de.erethon.dungeonsxl.trigger.TriggerListener; import de.erethon.dungeonsxl.trigger.TriggerTypeCache; import de.erethon.dungeonsxl.util.LWCUtil; @@ -110,6 +115,13 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI { public static final File LOOT_TABLES = new File(SCRIPTS, "loottables"); public static final File MOBS = new File(SCRIPTS, "mobs"); public static final File SIGNS = new File(SCRIPTS, "signs"); + public static final Set LEGACY_SIGNS = new HashSet<>(); + + static { + LEGACY_SIGNS.add("CHEST"); + LEGACY_SIGNS.add("EXTERNALMOB"); + LEGACY_SIGNS.add("FLOOR"); + } private PlayerCache playerCache = new PlayerCache(); private Collection gameCache = new ArrayList<>(); @@ -133,7 +145,7 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI { private TriggerTypeCache triggers; private GlobalProtectionCache protections; private AnnouncerCache announcers; - private SignScriptCache signScripts; + private Registry signScriptRegistry; public DungeonsXL() { settings = DREPluginSettings.builder() @@ -206,7 +218,7 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI { triggers = new TriggerTypeCache(); protections = new GlobalProtectionCache(this); announcers = new AnnouncerCache(this); - signScripts = new SignScriptCache(); + signScriptRegistry = new Registry<>(); dCommands = new DCommandCache(this); } @@ -216,9 +228,45 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI { Bukkit.getPluginManager().registerEvents(new TriggerListener(this), this); // Signs - for (DSignTypeDefault sign : DSignTypeDefault.values()) { - signRegistry.add(sign.getName(), sign.getHandler()); - } + signRegistry.add("ActionBar", ActionBarSign.class); + signRegistry.add("Bed", BedSign.class); + signRegistry.add("Block", BlockSign.class); + signRegistry.add("BossShop", BossShopSign.class); + signRegistry.add("Checkpoint", CheckpointSign.class); + // Deprecated + signRegistry.add("Chest", RewardChestSign.class); + signRegistry.add("Classes", ClassesSign.class); + //signRegistry.add("CMD", CommandSign.class); TODO: REIMPLEMENT + signRegistry.add("Drop", DropSign.class); + signRegistry.add("DungeonChest", DungeonChestSign.class); + signRegistry.add("End", EndSign.class); + // Deprecated + signRegistry.add("ExternalMob", MobSign.class); + signRegistry.add("Flag", FlagSign.class); + // Deprecated + signRegistry.add("Floor", EndSign.class); + signRegistry.add("Hologram", HologramSign.class); + signRegistry.add("Interact", InteractSign.class); + signRegistry.add("Leave", LeaveSign.class); + signRegistry.add("Lives", LivesModifierSign.class); + signRegistry.add("Lobby", LobbySign.class); + signRegistry.add("Mob", MobSign.class); + signRegistry.add("MSG", ChatMessageSign.class); + signRegistry.add("Note", NoteSign.class); + signRegistry.add("Door", OpenDoorSign.class); + signRegistry.add("Place", PlaceSign.class); + signRegistry.add("Protection", ProtectionSign.class); + signRegistry.add("Ready", ReadySign.class); + signRegistry.add("Redstone", RedstoneSign.class); + signRegistry.add("ResourcePack", ResourcePackSign.class); + signRegistry.add("RewardChest", RewardChestSign.class); + signRegistry.add("Script", ScriptSign.class); + signRegistry.add("SoundMSG", SoundMessageSign.class); + signRegistry.add("Start", StartSign.class); + signRegistry.add("Teleport", TeleportSign.class); + signRegistry.add("Title", TitleSign.class); + signRegistry.add("Trigger", TriggerSign.class); + signRegistry.add("Wave", WaveSign.class); Bukkit.getPluginManager().registerEvents(new DSignListener(this), this); // Maps @@ -298,11 +346,15 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI { classRegistry.add(clss.getName(), clss); } Bukkit.getPluginManager().registerEvents(new DMobListener(this), this); - signScripts.init(SIGNS); + + for (File script : FileUtil.getFilesForFolder(SIGNS)) { + SignScript sign = new SignScript(script); + signScriptRegistry.add(sign.getName(), sign); + } + dCommands.register(this); } - // Save and load public void saveData() { protections.saveAll(); instanceCache.getAllIf(i -> i instanceof EditWorld).forEach(i -> ((EditWorld) i).save()); @@ -354,9 +406,7 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI { return instance; } - /** - * @return the loaded instance of CaliburnAPI - */ + @Override public CaliburnAPI getCaliburn() { return caliburn; } @@ -499,10 +549,12 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI { } /** - * @return the loaded instance of SignScriptCache + * Returns a registry of the loaded sign scripts. + * + * @return a registry of the loaded sign scripts */ - public SignScriptCache getSignScriptCache() { - return signScripts; + public Registry getSignScriptRegistry() { + return signScriptRegistry; } @Deprecated diff --git a/core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java b/core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java index 698e53bf..2c359c56 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java +++ b/core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java @@ -28,7 +28,7 @@ import de.erethon.dungeonsxl.api.world.ResourceWorld; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.global.GameSign; import de.erethon.dungeonsxl.player.DGroup; -import de.erethon.dungeonsxl.sign.MobSign; +import de.erethon.dungeonsxl.sign.windup.MobSign; import de.erethon.dungeonsxl.trigger.ProgressTrigger; import de.erethon.dungeonsxl.world.DGameWorld; import java.util.ArrayList; @@ -303,9 +303,8 @@ public class DGame implements Game { MobSign mobSign = (MobSign) dSign; int newAmount = (int) Math.ceil(mobSign.getInitialAmount() * mobCountIncreaseRate); - mobSign.setAmount(newAmount); - mobSign.setInitialAmount(newAmount); - mobSign.initializeTask(); + mobSign.setN(newAmount); + mobSign.startTask(); } } }.runTaskLater(plugin, delay * 20); diff --git a/core/src/main/java/de/erethon/dungeonsxl/event/dsign/DSignEvent.java b/core/src/main/java/de/erethon/dungeonsxl/event/dsign/DSignEvent.java deleted file mode 100644 index 84946221..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/event/dsign/DSignEvent.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.event.dsign; - -import de.erethon.dungeonsxl.sign.DSign; -import org.bukkit.event.Event; - -/** - * @author Daniel Saukel - */ -public abstract class DSignEvent extends Event { - - protected DSign dSign; - - public DSignEvent(DSign dSign) { - this.dSign = dSign; - } - - /** - * @return the dSign - */ - public DSign getDSign() { - return dSign; - } - - /** - * @param dSign the dSign to set - */ - public void setDSign(DSign dSign) { - this.dSign = dSign; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/event/dsign/DSignRegistrationEvent.java b/core/src/main/java/de/erethon/dungeonsxl/event/dsign/DSignRegistrationEvent.java deleted file mode 100644 index 4320c7f6..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/event/dsign/DSignRegistrationEvent.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.event.dsign; - -import de.erethon.dungeonsxl.sign.DSign; -import de.erethon.dungeonsxl.world.DGameWorld; -import org.bukkit.block.Sign; -import org.bukkit.event.Cancellable; -import org.bukkit.event.HandlerList; - -/** - * @author Daniel Saukel - */ -public class DSignRegistrationEvent extends DSignEvent implements Cancellable { - - private static final HandlerList handlers = new HandlerList(); - private boolean cancelled; - - private Sign sign; - private DGameWorld gameWorld; - - public DSignRegistrationEvent(Sign sign, DGameWorld gameWorld, DSign dSign) { - super(dSign); - this.sign = sign; - this.gameWorld = gameWorld; - } - - /** - * @return the sign - */ - public Sign getSign() { - return sign; - } - - /** - * @param sign the sign to set - */ - public void setSign(Sign sign) { - this.sign = sign; - } - - /** - * @return the gameWorld - */ - public DGameWorld getGameWorld() { - return gameWorld; - } - - /** - * @param gameWorld the gameWorld to set - */ - public void setGameWorld(DGameWorld gameWorld) { - this.gameWorld = gameWorld; - } - - @Override - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - - @Override - public boolean isCancelled() { - return cancelled; - } - - @Override - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/reward/ItemReward.java b/core/src/main/java/de/erethon/dungeonsxl/reward/ItemReward.java index c446dcde..049d155b 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/reward/ItemReward.java +++ b/core/src/main/java/de/erethon/dungeonsxl/reward/ItemReward.java @@ -16,7 +16,7 @@ */ package de.erethon.dungeonsxl.reward; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.api.Reward; import java.util.ArrayList; import java.util.Arrays; @@ -29,12 +29,12 @@ import org.bukkit.inventory.ItemStack; */ public class ItemReward implements Reward { - private DungeonsXL plugin; + private DungeonsAPI api; private List items = new ArrayList<>(); - public ItemReward(DungeonsXL plugin) { - this.plugin = plugin; + public ItemReward(DungeonsAPI api) { + this.api = api; } /* Getters and setters */ @@ -69,7 +69,7 @@ public class ItemReward implements Reward { /* Actions */ @Override public void giveTo(Player player) { - plugin.getPlayerCache().get(player).setRewardItems(items); + api.getPlayerCache().get(player).setRewardItems(items); } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/reward/MoneyReward.java b/core/src/main/java/de/erethon/dungeonsxl/reward/MoneyReward.java index 7cb0c3a8..5e0ecc64 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/reward/MoneyReward.java +++ b/core/src/main/java/de/erethon/dungeonsxl/reward/MoneyReward.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.reward; import de.erethon.commons.chat.MessageUtil; -import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.api.Reward; import de.erethon.dungeonsxl.config.DMessage; import net.milkbowl.vault.economy.Economy; @@ -32,8 +31,8 @@ public class MoneyReward implements Reward { private double money; - public MoneyReward(DungeonsXL plugin) { - econ = plugin.getEconomyProvider(); + public MoneyReward(Economy econ) { + this.econ = econ; } /** diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/CheckpointSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/CheckpointSign.java deleted file mode 100644 index b28f40b1..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/CheckpointSign.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.chat.MessageUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.config.DMessage; -import de.erethon.dungeonsxl.player.DGamePlayer; -import de.erethon.dungeonsxl.world.DGameWorld; -import java.util.concurrent.CopyOnWriteArrayList; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; - -/** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel - */ -public class CheckpointSign extends DSign { - - // Variables - private boolean initialized; - private CopyOnWriteArrayList done = new CopyOnWriteArrayList<>(); - - public CheckpointSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - @Override - public boolean check() { - return true; - } - - @Override - public void onInit() { - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - - initialized = true; - } - - @Override - public void onTrigger() { - if (!initialized) { - return; - } - - for (DGamePlayer dplayer : DGamePlayer.getByWorld(getGameWorld().getWorld())) { - dplayer.setCheckpoint(getSign().getLocation()); - MessageUtil.sendMessage(dplayer.getPlayer(), DMessage.PLAYER_CHECKPOINT_REACHED.getMessage()); - } - - remove(); - } - - @Override - public boolean onPlayerTrigger(Player player) { - if (!initialized) { - return true; - } - - DGamePlayer dplayer = DGamePlayer.getByPlayer(player); - if (dplayer != null) { - if (!done.contains(dplayer)) { - done.add(dplayer); - dplayer.setCheckpoint(getSign().getLocation()); - MessageUtil.sendMessage(player, DMessage.PLAYER_CHECKPOINT_REACHED.getMessage()); - } - } - - if (done.size() >= DGamePlayer.getByWorld(getGameWorld().getWorld()).size()) { - remove(); - } - - return true; - } - - @Override - public DSignType getType() { - return DSignTypeDefault.CHECKPOINT; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/CommandSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/CommandSign.java deleted file mode 100644 index 1d33be31..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/CommandSign.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.trigger.InteractTrigger; -import de.erethon.dungeonsxl.world.DGameWorld; -import io.github.dre2n.commandsxl.CommandsXL; -import io.github.dre2n.commandsxl.command.CCommand; -import io.github.dre2n.commandsxl.command.CCommandExecutorTask; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -/** - * @author Daniel Saukel - */ -public class CommandSign extends DSign { - - // Variables - private CCommand cCommand; - private long delay; - - private String command; - private String executor; - private boolean initialized; - - public CommandSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - @Override - public boolean check() { - if (lines[1].isEmpty() || lines[2].isEmpty()) { - return false; - } - - if (lines[1] == null) { - return false; - } - - String[] attributes = lines[2].split(","); - if (attributes.length == 2) { - return true; - - } else { - return false; - } - } - - @Override - public void onInit() { - String[] attributes = lines[2].split(","); - - command = lines[1]; - delay = NumberUtil.parseInt(attributes[0]); - if (attributes.length >= 2) { - executor = attributes[1]; - } - - cCommand = CommandsXL.getPlugin().getCCommands().getCCommand(command); - - if (!getTriggers().isEmpty()) { - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - return; - } - - InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGameWorld()); - if (trigger != null) { - trigger.addListener(this); - getTriggers().add(trigger); - } - - getSign().setLine(0, ChatColor.DARK_BLUE + "############"); - getSign().setLine(1, ChatColor.DARK_GREEN + command); - getSign().setLine(2, ""); - getSign().setLine(3, ChatColor.DARK_BLUE + "############"); - getSign().update(); - - initialized = true; - } - - @Override - public boolean onPlayerTrigger(final Player player) { - if ("Console".equalsIgnoreCase(executor)) { - new CCommandExecutorTask(player, cCommand, Bukkit.getConsoleSender(), true).runTaskLater(plugin, delay * 20); - - } else if ("OP".equalsIgnoreCase(executor)) { - boolean isOp = player.isOp(); - - player.setOp(true); - - new CCommandExecutorTask(player, cCommand, player, true).runTaskLater(plugin, delay * 20); - - if (!isOp) { - new BukkitRunnable() { - @Override - public void run() { - player.setOp(false); - } - }.runTaskLater(plugin, delay * 20 + 1); - } - - } else { - new CCommandExecutorTask(player, cCommand, player, false).runTaskLater(plugin, delay * 20); - } - - return true; - } - - @Override - public void onTrigger() { - if (initialized) { - remove(); - } - } - - @Override - public DSignType getType() { - return DSignTypeDefault.COMMAND; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/DSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/DSign.java deleted file mode 100644 index cd7fb556..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/DSign.java +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.commons.chat.MessageUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.dungeon.DGame; -import de.erethon.dungeonsxl.event.dsign.DSignRegistrationEvent; -import de.erethon.dungeonsxl.trigger.Trigger; -import de.erethon.dungeonsxl.world.DGameWorld; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.HashSet; -import java.util.Set; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; - -/** - * Extend this to create a custom DSign. - * - * @author Frank Baumann, Milan Albrecht, Daniel Saukel - */ -public abstract class DSign { - - protected DungeonsXL plugin; - - public static final String ERROR_0 = ChatColor.DARK_RED + "## ERROR ##"; - public static final String ERROR_1 = ChatColor.WHITE + "Please"; - public static final String ERROR_2 = ChatColor.WHITE + "contact an"; - public static final String ERROR_3 = ChatColor.WHITE + "Admin!"; - - private Sign sign; - protected String[] lines; - private DGameWorld gameWorld; - - // List of Triggers - private Set triggers = new HashSet<>(); - - private boolean erroneous; - - protected DSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - this.plugin = plugin; - - this.sign = sign; - this.lines = lines; - this.gameWorld = gameWorld; - - // Check Trigger - if (gameWorld == null) { - return; - } - - String line3 = lines[3].replaceAll("\\s", ""); - String[] triggerTypes = line3.split(","); - - for (String triggerString : triggerTypes) { - if (triggerString.isEmpty()) { - continue; - } - - String type = triggerString.substring(0, 1); - String value = null; - if (triggerString.length() > 1) { - value = triggerString.substring(1); - } - - Trigger trigger = Trigger.getOrCreate(plugin, type, value, this); - if (trigger != null) { - trigger.addListener(this); - addTrigger(trigger); - } - } - } - - /* Getters and setters */ - /** - * @return the sign - */ - public Sign getSign() { - return sign; - } - - /** - * @param sign the sign to set - */ - public void setSign(Sign sign) { - this.sign = sign; - } - - /** - * @return the sign lines - */ - public String[] getLines() { - return lines; - } - - /** - * @param lines the sign lines to set - */ - public void setLines(String[] lines) { - this.lines = lines; - } - - /** - * @return the gameWorld - */ - public DGameWorld getGameWorld() { - return gameWorld; - } - - /** - * @return the game - */ - public DGame getGame() { - return DGame.getByGameWorld(gameWorld); - } - - /** - * @return the triggers - */ - public Set getTriggers() { - return triggers; - } - - /** - * @param trigger the trigger to add - */ - public void addTrigger(Trigger trigger) { - triggers.add(trigger); - } - - /** - * @param trigger the trigger to remove - */ - public void removeTrigger(Trigger trigger) { - triggers.remove(trigger); - } - - /* Actions */ - public void onInit() { - } - - public void onTrigger() { - } - - public boolean onPlayerTrigger(Player player) { - return false; - } - - public void onDisable() { - } - - public void onUpdate() { - if (erroneous) { - return; - } - - for (Trigger trigger : triggers) { - if (!trigger.isTriggered()) { - onDisable(); - return; - } - - if (trigger.getPlayer() == null) { - continue; - } - - if (onPlayerTrigger(trigger.getPlayer())) { - return; - } - } - - onTrigger(); - } - - public void remove() { - for (Trigger trigger : triggers) { - trigger.removeListener(this); - } - gameWorld.getDSigns().remove(this); - } - - public boolean hasTriggers() { - return !triggers.isEmpty(); - } - - public boolean isErroneous() { - return erroneous; - } - - /** - * Set a placeholder to show that the sign is setup incorrectly. - * - * @param reason the reason why the sign is marked as erroneous - */ - public void markAsErroneous(String reason) { - erroneous = true; - sign.setLine(0, ERROR_0); - sign.setLine(1, ERROR_1); - sign.setLine(2, ERROR_2); - sign.setLine(3, ERROR_3); - sign.update(); - - MessageUtil.log(plugin, "&4A sign at &6" + sign.getX() + ", " + sign.getY() + ", " + sign.getZ() + "&4 is erroneous!"); - MessageUtil.log(plugin, getType().getName() + ": " + reason); - } - - /* Statics */ - public static DSign create(DungeonsXL plugin, Sign sign, DGameWorld gameWorld) { - return create(plugin, sign, sign.getLines(), gameWorld); - } - - public static DSign create(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - DSign dSign = null; - - for (DSignType type : plugin.getDSignCache().getDSigns()) { - if (!lines[0].equalsIgnoreCase("[" + type.getName() + "]")) { - continue; - } - - try { - Constructor constructor = type.getHandler().getConstructor(DungeonsXL.class, Sign.class, String[].class, DGameWorld.class); - dSign = constructor.newInstance(plugin, sign, lines, gameWorld); - - } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { - MessageUtil.log("An error occurred while accessing the handler class of the sign " + type.getName() + ": " + exception.getClass().getSimpleName()); - if (!(type instanceof DSignTypeDefault)) { - MessageUtil.log("Please note that this sign is an unsupported feature added by an addon!"); - } - exception.printStackTrace(); - } - } - - if (gameWorld != null) { - DSignRegistrationEvent event = new DSignRegistrationEvent(sign, gameWorld, dSign); - Bukkit.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return null; - } - } - - if (!(dSign != null && gameWorld != null)) { - return dSign; - } - - if (dSign.getType().isOnDungeonInit()) { - dSign.onInit(); - } - - return dSign; - } - - /* Abstracts */ - public abstract boolean check(); - - public abstract DSignType getType(); - - @Override - public String toString() { - return getClass().getSimpleName() + "{sign=" + sign + "; gameWorld=" + gameWorld + "}"; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/DSignListener.java b/core/src/main/java/de/erethon/dungeonsxl/sign/DSignListener.java index 7681d89a..c5d7c8e3 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/DSignListener.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/DSignListener.java @@ -18,12 +18,15 @@ package de.erethon.dungeonsxl.sign; import de.erethon.commons.chat.MessageUtil; import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.player.GamePlayer; +import de.erethon.dungeonsxl.api.sign.DungeonSign; +import de.erethon.dungeonsxl.api.world.EditWorld; import de.erethon.dungeonsxl.config.DMessage; -import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.trigger.InteractTrigger; -import de.erethon.dungeonsxl.world.DEditWorld; import de.erethon.dungeonsxl.world.DGameWorld; +import java.util.Map.Entry; import org.bukkit.ChatColor; import org.bukkit.block.Block; import org.bukkit.block.BlockState; @@ -40,10 +43,10 @@ import org.bukkit.event.player.PlayerInteractEvent; */ public class DSignListener implements Listener { - private DungeonsXL plugin; + private DungeonsAPI api; - public DSignListener(DungeonsXL plugin) { - this.plugin = plugin; + public DSignListener(DungeonsAPI api) { + this.api = api; } @EventHandler @@ -53,12 +56,12 @@ public class DSignListener implements Listener { if (clickedBlock == null) { return; } - DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); + GamePlayer dPlayer = api.getPlayerCache().getGamePlayer(player); if (dPlayer == null) { return; } - DGameWorld gameWorld = DGameWorld.getByWorld(player.getWorld()); + DGameWorld gameWorld = (DGameWorld) dPlayer.getGameWorld(); if (gameWorld == null) { return; } @@ -69,17 +72,6 @@ public class DSignListener implements Listener { trigger.onTrigger(player); } } - - for (Sign classSign : gameWorld.getClassesSigns()) { - if (classSign != null) { - if (classSign.getLocation().distance(clickedBlock.getLocation()) < 1) { - if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) { - dPlayer.setDClass(ChatColor.stripColor(classSign.getLine(1))); - } - break; - } - } - } } @EventHandler @@ -93,7 +85,7 @@ public class DSignListener implements Listener { } Sign sign = (Sign) state; - DEditWorld editWorld = DEditWorld.getByWorld(sign.getWorld()); + EditWorld editWorld = api.getEditWorld(sign.getWorld()); if (editWorld == null) { return; } @@ -104,34 +96,33 @@ public class DSignListener implements Listener { sign.setLine(2, lines[2]); sign.setLine(3, lines[3]); - for (DSignTypeDefault type : DSignTypeDefault.values()) { - if (!lines[0].equalsIgnoreCase("[" + type.getName() + "]")) { + for (Entry> registryEntry : api.getSignRegistry().entrySet()) { + if (!lines[0].equalsIgnoreCase("[" + registryEntry.getKey() + "]")) { continue; } - if (type.isLegacy()) { + if (DungeonsXL.LEGACY_SIGNS.contains(registryEntry.getKey().toUpperCase())) { MessageUtil.sendMessage(player, ChatColor.RED + "https://erethon.de/resources/dxl-signs/deprecated.gif"); MessageUtil.sendMessage(player, ChatColor.LIGHT_PURPLE + "https://github.com/DRE2N/DungeonsXL/wiki/Legacy-support#updating"); return; } } - DSign dsign = DSign.create(plugin, sign, null); - + DungeonSign dsign = editWorld.createDungeonSign(sign, sign.getLines()); if (dsign == null) { return; } - if (!DPermission.hasPermission(player, dsign.getType().getBuildPermission())) { + if (!DPermission.hasPermission(player, dsign.getBuildPermission())) { MessageUtil.sendMessage(player, DMessage.ERROR_NO_PERMISSIONS.getMessage()); return; } - if (dsign.check()) { + if (dsign.validate()) { editWorld.registerSign(block); - editWorld.getSigns().add(block); MessageUtil.sendMessage(player, DMessage.PLAYER_SIGN_CREATED.getMessage()); } else { + editWorld.removeDungeonSign(block); MessageUtil.sendMessage(player, DMessage.ERROR_SIGN_WRONG_FORMAT.getMessage()); } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/DSignTypeDefault.java b/core/src/main/java/de/erethon/dungeonsxl/sign/DSignTypeDefault.java deleted file mode 100644 index faafab52..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/DSignTypeDefault.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.dungeonsxl.api.sign.DungeonSign; -import de.erethon.dungeonsxl.sign.lobby.ClassesSign; -import de.erethon.dungeonsxl.sign.lobby.LobbySign; -import de.erethon.dungeonsxl.sign.lobby.ReadySign; -import de.erethon.dungeonsxl.sign.lobby.StartSign; -import de.erethon.dungeonsxl.sign.message.ActionBarSign; -import de.erethon.dungeonsxl.sign.message.HologramSign; -import de.erethon.dungeonsxl.sign.message.MessageSign; -import de.erethon.dungeonsxl.sign.message.SoundMessageSign; -import de.erethon.dungeonsxl.sign.message.TitleSign; - -/** - * @author Daniel Saukel - */ -public enum DSignTypeDefault { - - ACTION_BAR("ActionBar", ActionBarSign.class), - BED("Bed", BedSign.class), - BLOCK("Block", BlockSign.class), - BOSS_SHOP("BossShop", BossShopSign.class), - CHECKPOINT("Checkpoint", CheckpointSign.class), - @Deprecated - CHEST("Chest", RewardChestSign.class), - CLASSES("Classes", ClassesSign.class), - COMMAND("CMD", CommandSign.class), - DROP("Drop", DropSign.class), - DUNGEON_CHEST("DungeonChest", DungeonChestSign.class), - END("End", EndSign.class), - @Deprecated - EXTERNAL_MOB("ExternalMob", MobSign.class), - FLAG("Flag", FlagSign.class), - @Deprecated - FLOOR("Floor", EndSign.class), - HOLOGRAM("Hologram", HologramSign.class), - INTERACT("Interact", InteractSign.class), - LEAVE("Leave", LeaveSign.class), - LIVES_MODIFIER("Lives", LivesModifierSign.class), - LOBBY("Lobby", LobbySign.class), - MOB("Mob", MobSign.class), - MESSAGE("MSG", MessageSign.class), - NOTE("Note", NoteSign.class), - OPEN_DOOR("Door", OpenDoorSign.class), - PLACE("Place", PlaceSign.class), - PROTECTION("Protection", ProtectionSign.class), - READY("Ready", ReadySign.class), - REDSTONE("Redstone", RedstoneSign.class), - RESOURCE_PACK("ResourcePack", ResourcePackSign.class), - REWARD_CHEST("RewardChest", RewardChestSign.class), - SCRIPT("Script", ScriptSign.class), - SOUND_MESSAGE("SoundMSG", SoundMessageSign.class), - START("Start", StartSign.class), - TELEPORT("Teleport", TeleportSign.class), - TITLE("Title", TitleSign.class), - TRIGGER("Trigger", TriggerSign.class), - WAVE("Wave", WaveSign.class); - - private String name; - private Class handler; - - DSignTypeDefault(String name, Class handler) { - this.name = name; - this.handler = handler; - } - - public String getName() { - return name; - } - - public Class getHandler() { - return handler; - } - - public boolean isLegacy() { - switch (this) { - case CHEST: - case EXTERNAL_MOB: - case FLOOR: - return true; - default: - return false; - } - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/DelayedPowerTask.java b/core/src/main/java/de/erethon/dungeonsxl/sign/DelayedPowerTask.java deleted file mode 100644 index e404869f..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/DelayedPowerTask.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.dungeonsxl.world.DGameWorld; -import org.bukkit.scheduler.BukkitRunnable; - -/** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel - */ -public class DelayedPowerTask extends BukkitRunnable { - - private RedstoneSign sign; - private boolean enable; - - public DelayedPowerTask(RedstoneSign sign, boolean enable) { - this.sign = sign; - this.enable = enable; - } - - @Override - public void run() { - if (DGameWorld.getByWorld(sign.getBlock().getWorld()) == null) { - sign.getEnableTask().cancel(); - sign.getDisableTask().cancel(); - return; - } - - if (enable) { - sign.power(); - if (sign.getRepeatsToDo() == 1) { - sign.getEnableTask().cancel(); - } - - } else { - sign.unpower(); - if (sign.getRepeatsToDo() == 1) { - sign.getDisableTask().cancel(); - } - sign.setRepeatsToDo(sign.getRepeatsToDo() - 1); - } - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/DropSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/DropSign.java deleted file mode 100644 index ab89f533..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/DropSign.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.caliburn.item.ExItem; -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.world.DGameWorld; -import org.bukkit.Location; -import org.bukkit.block.Sign; -import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; - -/** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel - */ -public class DropSign extends DSign { - - private ItemStack item; - private double interval = -1; - - public DropSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - /* Getters and setters */ - /** - * @return the item - */ - public ItemStack getItem() { - return item; - } - - /** - * @param item the item to set - */ - public void setItem(ItemStack item) { - this.item = item; - } - - /* Actions */ - @Override - public boolean check() { - return plugin.getCaliburn().getExItem(lines[1]) != null; - } - - @Override - public void onInit() { - ExItem item = plugin.getCaliburn().getExItem(lines[1]); - - String[] attributes = lines[2].split(","); - if (attributes.length >= 1) { - this.item = item.toItemStack(NumberUtil.parseInt(attributes[0], 1)); - } - if (attributes.length == 2) { - interval = NumberUtil.parseDouble(attributes[1]); - } - - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - } - - @Override - public void onTrigger() { - final Location spawnLocation = getSign().getLocation().add(0.5, 0, 0.5); - if (interval < 0) { - getSign().getWorld().dropItem(spawnLocation, item); - - } else { - long period = (long) interval * 20; - - new BukkitRunnable() { - @Override - public void run() { - try { - spawnLocation.getWorld().dropItem(spawnLocation, item); - } catch (NullPointerException exception) { - cancel(); - } - } - }.runTaskTimer(plugin, period, period); - } - } - - @Override - public DSignType getType() { - return DSignTypeDefault.DROP; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/FlagSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/FlagSign.java deleted file mode 100644 index e0f62070..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/FlagSign.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.world.DGameWorld; -import de.erethon.dungeonsxl.world.block.TeamFlag; -import org.bukkit.block.Sign; - -/** - * @author Daniel Saukel - */ -public class FlagSign extends DSign { - - private int team; - - public FlagSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - /* Getters and setters */ - @Override - public DSignType getType() { - return DSignTypeDefault.FLAG; - } - - /* Actions */ - @Override - public boolean check() { - return NumberUtil.parseInt(lines[1], -1) != -1; - } - - @Override - public void onInit() { - this.team = NumberUtil.parseInt(lines[1]); - if (getGame().getDGroups().size() > team) { - getGameWorld().addGameBlock(new TeamFlag(plugin, getSign().getBlock(), getGame().getDGroups().get(team))); - } - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/LocationSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/LocationSign.java index c6c2e61c..73354a1a 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/LocationSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/LocationSign.java @@ -18,36 +18,26 @@ package de.erethon.dungeonsxl.sign; import de.erethon.commons.misc.BlockUtil; import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.world.DGameWorld; +import de.erethon.dungeonsxl.api.sign.DungeonSign; import org.bukkit.Location; -import org.bukkit.block.Sign; /** * @author Daniel Saukel */ -public abstract class LocationSign extends DSign { - - protected Location location; - - public LocationSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } +public interface LocationSign extends DungeonSign { @Override - public void onInit() { + default void initialize() { double x = getSign().getX() + 0.5; double y = getSign().getY(); double z = getSign().getZ() + 0.5; float yaw = BlockUtil.blockFaceToYaw(DungeonsXL.BLOCK_ADAPTER.getFacing(getSign().getBlock()).getOppositeFace()); float pitch = 0; - location = new Location(getGameWorld().getWorld(), x, y, z, yaw, pitch); + setLocation(new Location(getGameWorld().getWorld(), x, y, z, yaw, pitch)); } - /** - * @return the location marked by this sign - */ - public Location getLocation() { - return location; - } + Location getLocation(); + + void setLocation(Location location); } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/MobSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/MobSign.java deleted file mode 100644 index ab47c7ac..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/MobSign.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.caliburn.mob.ExMob; -import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.mob.ExternalMobProvider; -import de.erethon.dungeonsxl.mob.ExternalMobProviderCache; -import de.erethon.dungeonsxl.world.DGameWorld; -import java.util.ArrayList; -import java.util.Collection; -import org.bukkit.Location; -import org.bukkit.block.Sign; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitTask; - -/** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel - */ -public class MobSign extends DSign { - - private ExternalMobProviderCache providers; - - private String mob; - private int maxInterval = 1; - private int interval = 0; - private int amount = 1; - private int initialAmount = 1; - private boolean initialized; - private boolean active; - private ExternalMobProvider provider; - private BukkitTask task; - private Collection spawnedMobs = new ArrayList<>(); - - public MobSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - providers = plugin.getExternalMobProviderCache(); - } - - /** - * @return the mob - */ - public String getMob() { - return mob; - } - - /** - * @param mob the mob to set - */ - public void setMob(String mob) { - this.mob = mob; - } - - /** - * @return the the maximum interval between mob spawns - */ - public int getMaxInterval() { - return maxInterval; - } - - /** - * @param maxInterval the maximum interval between mob spawns - */ - public void setMaxInterval(int maxInterval) { - this.maxInterval = maxInterval; - } - - /** - * @return the spawn interval - */ - public int getInterval() { - return interval; - } - - /** - * @param interval the spawn interval - */ - public void setInterval(int interval) { - this.interval = interval; - } - - /** - * @return the amount of mobs - */ - public int getAmount() { - return amount; - } - - /** - * @param amount the amount of mobs to set - */ - public void setAmount(int amount) { - this.amount = amount; - } - - /** - * @return the initial amount of mobs - */ - public int getInitialAmount() { - return initialAmount; - } - - /** - * @param initialAmount the initial amount of mobs to set - */ - public void setInitialAmount(int initialAmount) { - this.initialAmount = initialAmount; - } - - /** - * @return if the sign is initialized - */ - public boolean isInitialized() { - return initialized; - } - - /** - * @param initialized set the sign initialized - */ - public void setInitialized(boolean initialized) { - this.initialized = initialized; - } - - /** - * @return if the sign is active - */ - public boolean isActive() { - return active; - } - - /** - * @param active set the sign active - */ - public void setActive(boolean active) { - this.active = active; - } - - /** - * @return the spawn task - */ - public BukkitTask getTask() { - return task; - } - - /** - * @param task the task to set - */ - public void setTask(BukkitTask task) { - this.task = task; - } - - /** - * Starts a new spawn task. - */ - public void initializeTask() { - task = new MobSpawnTask(this).runTaskTimer(plugin, 0L, 20L); - } - - /** - * Spawns the mob. - * - * @return the spawned mob - */ - public LivingEntity spawn() { - Location spawnLoc = getSign().getLocation().add(0.5, 0, 0.5); - LivingEntity spawned = null; - - if (provider == null) { - ExMob type = plugin.getCaliburn().getExMob(mob); - if (type == null || !type.getSpecies().isAlive()) { - return null; - } - spawned = (LivingEntity) type.toEntity(spawnLoc); - spawned.setRemoveWhenFarAway(false); - - } else { - provider.summon(mob, spawnLoc); - for (Entity entity : spawnLoc.getChunk().getEntities()) { - Location entityLoc = entity.getLocation(); - if (entityLoc.getX() >= spawnLoc.getX() - 1 && entityLoc.getX() <= spawnLoc.getX() + 1 && entityLoc.getY() >= spawnLoc.getY() - 1 - && entityLoc.getY() <= spawnLoc.getY() + 1 && entityLoc.getZ() >= spawnLoc.getZ() - 1 && entityLoc.getZ() <= spawnLoc.getZ() + 1 - && entity instanceof LivingEntity && !spawnedMobs.contains((LivingEntity) entity) && !(entity instanceof Player)) { - spawned = (LivingEntity) entity; - } - } - } - - spawnedMobs.add(spawned); - return spawned; - } - - /** - * @return a Collection of all spawned mobs. - */ - public Collection getSpawnedMobs() { - return spawnedMobs; - } - - @Override - public boolean check() { - if (lines[1].isEmpty() || lines[2].isEmpty()) { - return false; - } - - if (lines[1] == null) { - return false; - } - - String[] attributes = lines[2].split(","); - if (attributes.length == 2 || attributes.length == 3) { - return true; - - } else { - return false; - } - } - - @Override - public void onInit() { - mob = lines[1]; - String[] attributes = lines[2].split(","); - - maxInterval = NumberUtil.parseInt(attributes[0]); - amount = NumberUtil.parseInt(attributes[1]); - initialAmount = amount; - provider = attributes.length == 3 ? providers.getByIdentifier(attributes[2]) : null; - - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - - initialized = true; - } - - @Override - public void onTrigger() { - if (!initialized || active) { - return; - } - - initializeTask(); - - active = true; - } - - @Override - public void onDisable() { - if (!initialized || !active) { - return; - } - - killTask(); - interval = 0; - active = false; - } - - public void killTask() { - if (!initialized || !active) { - return; - } - - if (task != null) { - task.cancel(); - task = null; - } - } - - @Override - public DSignType getType() { - return DSignTypeDefault.MOB; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/PerPlayerSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/PerPlayerSign.java deleted file mode 100644 index 59df5572..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/PerPlayerSign.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.world.DGameWorld; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; - -/** - * @author Daniel Saukel - */ -public abstract class PerPlayerSign extends DSign { - - private Set triggered = new HashSet<>(); - - public PerPlayerSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - @Override - public boolean onPlayerTrigger(Player player) { - return triggered.add(player.getUniqueId()); - } - - /** - * @param player the player to check - * @return true if the player already triggered the sign - */ - public boolean isTriggeredByPlayer(Player player) { - return triggered.contains(player.getUniqueId()); - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/PlaceSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/PlaceSign.java deleted file mode 100644 index a7de673d..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/PlaceSign.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.world.DGameWorld; -import de.erethon.dungeonsxl.world.block.PlaceableBlock; -import org.bukkit.block.Sign; - -/** - * @author Frank Baumann, Daniel Saukel - */ -public class PlaceSign extends DSign { - - public PlaceSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - @Override - public boolean check() { - return true; - } - - @Override - public void onInit() { - getGameWorld().addGameBlock(new PlaceableBlock(plugin, getGameWorld(), getSign().getBlock(), lines[1], lines[2])); - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - } - - @Override - public DSignType getType() { - return DSignTypeDefault.PLACE; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/ProtectionSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/ProtectionSign.java deleted file mode 100644 index 5277b964..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/ProtectionSign.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.misc.BlockUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.world.DGameWorld; -import de.erethon.dungeonsxl.world.block.ProtectedBlock; -import org.bukkit.block.Sign; - -/** - * @author Daniel Saukel - */ -public class ProtectionSign extends DSign { - - public ProtectionSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - /* Getters and setters */ - @Override - public DSignType getType() { - return DSignTypeDefault.PROTECTION; - } - - /* Actions */ - @Override - public boolean check() { - return true; - } - - @Override - public void onInit() { - getGameWorld().addGameBlock(new ProtectedBlock(plugin, BlockUtil.getAttachedBlock(getSign().getBlock()))); - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/RedstoneSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/RedstoneSign.java deleted file mode 100644 index a9028f29..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/RedstoneSign.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.world.DGameWorld; -import org.bukkit.block.Block; -import org.bukkit.block.Sign; -import org.bukkit.scheduler.BukkitTask; - -/** - * @author Frank Baumann, Daniel Saukel - */ -public class RedstoneSign extends DSign { - - // Variables - private boolean initialized; - private boolean active; - private BukkitTask enableTask; - private BukkitTask disableTask; - private Block block; - private long delay = 0; - private long offDelay = 0; - private int repeat = 1; - private int repeatsToDo = 1; - - public RedstoneSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - /** - * @return the initialized - */ - public boolean isInitialized() { - return initialized; - } - - /** - * @param initialized the initialized to set - */ - public void setInitialized(boolean initialized) { - this.initialized = initialized; - } - - /** - * @return the active - */ - public boolean isActive() { - return active; - } - - /** - * @param active the active to set - */ - public void setActive(boolean active) { - this.active = active; - } - - /** - * @return the enableTask - */ - public BukkitTask getEnableTask() { - return enableTask; - } - - /** - * @param enableTask the enableTask to set - */ - public void setEnableTask(BukkitTask enableTask) { - this.enableTask = enableTask; - } - - /** - * @return the disableTask - */ - public BukkitTask getDisableTask() { - return disableTask; - } - - /** - * @param disableTask the disableTask to set - */ - public void setDisableTask(BukkitTask disableTask) { - this.disableTask = disableTask; - } - - /** - * @return the block - */ - public Block getBlock() { - return block; - } - - /** - * @param block the block to set - */ - public void setBlock(Block block) { - this.block = block; - } - - /** - * @return the delay - */ - public long getDelay() { - return delay; - } - - /** - * @param delay the delay to set - */ - public void setDelay(long delay) { - this.delay = delay; - } - - /** - * @return the offDelay - */ - public long getOffDelay() { - return offDelay; - } - - /** - * @param offDelay the offDelay to set - */ - public void setOffDelay(long offDelay) { - this.offDelay = offDelay; - } - - /** - * @return the repeat - */ - public int getRepeat() { - return repeat; - } - - /** - * @param repeat the repeat to set - */ - public void setRepeat(int repeat) { - this.repeat = repeat; - } - - /** - * @return the repeatsToDo - */ - public int getRepeatsToDo() { - return repeatsToDo; - } - - /** - * @param repeatsToDo the repeatsToDo to set - */ - public void setRepeatsToDo(int repeatsToDo) { - this.repeatsToDo = repeatsToDo; - } - - @Override - public boolean check() { - return true; - } - - @Override - public void onInit() { - int line1 = 0; - int line11 = 0; - if (!getSign().getLine(1).isEmpty()) { - String line[] = getSign().getLine(1).split(","); - line1 = NumberUtil.parseInt(line[0]); - if (line.length > 1) { - line11 = NumberUtil.parseInt(line[1]); - } - } - - int line2 = 1; - if (!getSign().getLine(2).isEmpty()) { - line2 = NumberUtil.parseInt(getSign().getLine(2)); - } - - if (line1 > 0) { - delay = (long) line1 * 2; - if (line11 > 0) { - offDelay = (long) line11 * 2; - } else { - offDelay = delay; - } - if (line2 >= 0) { - repeat = line2; - } - } - - block = getSign().getBlock(); - block.setType(VanillaItem.AIR.getMaterial()); - - initialized = true; - } - - @Override - public void onTrigger() { - if (!initialized || active) { - return; - } - - if (delay > 0) { - enableTask = new DelayedPowerTask(this, true).runTaskTimer(plugin, delay, delay + offDelay); - - if (repeat != 1) { - repeatsToDo = repeat; - disableTask = new DelayedPowerTask(this, false).runTaskTimer(plugin, delay + offDelay, delay + offDelay); - } - - } else { - power(); - } - - active = true; - } - - @Override - public void onDisable() { - if (!initialized || !active) { - return; - } - - unpower(); - - if (enableTask != null) { - enableTask.cancel(); - } - if (disableTask != null) { - disableTask.cancel(); - } - - active = false; - } - - public void power() { - block.setType(VanillaItem.REDSTONE_BLOCK.getMaterial()); - } - - public void unpower() { - block.setType(VanillaItem.AIR.getMaterial()); - } - - @Override - public DSignType getType() { - return DSignTypeDefault.REDSTONE; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/ScriptSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/ScriptSign.java deleted file mode 100644 index cc07557d..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/ScriptSign.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.world.DGameWorld; -import org.bukkit.block.Sign; - -/** - * @author Daniel Saukel - */ -public class ScriptSign extends DSign { - - private String name; - - public ScriptSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - name = lines[1]; - } - - /** - * @return the name of the script - */ - public String getName() { - return name; - } - - @Override - public boolean check() { - return plugin.getSignScriptCache().getByName(lines[1]) != null; - } - - @Override - public void onInit() { - SignScript script = plugin.getSignScriptCache().getByName(name); - for (String[] lines : script.getSigns()) { - DSign dSign = DSign.create(plugin, getSign(), lines, getGameWorld()); - if (dSign.isErroneous()) { - continue; - } - getGameWorld().getDSigns().add(dSign); - - dSign.onInit(); - if (!dSign.hasTriggers()) { - dSign.onTrigger(); - } - } - } - - @Override - public DSignType getType() { - return DSignTypeDefault.SCRIPT; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/SignScriptCache.java b/core/src/main/java/de/erethon/dungeonsxl/sign/SignScriptCache.java deleted file mode 100644 index 119e9fcb..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/SignScriptCache.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.commons.misc.FileUtil; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * SignScript instance manager. - * - * @author Daniel Saukel - */ -public class SignScriptCache { - - private List scripts = new ArrayList<>(); - - public void init(File file) { - if (file.isDirectory()) { - for (File script : FileUtil.getFilesForFolder(file)) { - scripts.add(new SignScript(script)); - } - } - } - - /** - * @param name the name to check - * @return the script that has the name - */ - public SignScript getByName(String name) { - for (SignScript script : scripts) { - if (script.getName().equalsIgnoreCase(name)) { - return script; - } - } - - return null; - } - - /** - * @return the scripts - */ - public List getScripts() { - return scripts; - } - - /** - * @param script the SignScript to add - */ - public void addScript(SignScript script) { - scripts.add(script); - } - - /** - * @param script the SignScript to remove - */ - public void removeScript(SignScript script) { - scripts.remove(script); - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/TriggerSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/TriggerSign.java deleted file mode 100644 index 34ab7b17..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/TriggerSign.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.trigger.SignTrigger; -import de.erethon.dungeonsxl.world.DEditWorld; -import de.erethon.dungeonsxl.world.DGameWorld; -import java.util.HashSet; -import java.util.Set; -import org.bukkit.block.Block; -import org.bukkit.block.Sign; - -/** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel - */ -public class TriggerSign extends DSign { - - // Variables - private int triggerId; - private boolean initialized; - - public TriggerSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - @Override - public boolean check() { - Set used = new HashSet<>(); - for (Block block : DEditWorld.getByWorld(getSign().getLocation().getWorld()).getSigns()) { - if (block == null) { - continue; - } - - if (!block.getChunk().isLoaded()) { - block.getChunk().load(); - } - - if (block.getState() instanceof Sign) { - Sign rsign = (Sign) block.getState(); - if (rsign.getLine(0).equalsIgnoreCase("[" + getType().getName() + "]")) { - used.add(NumberUtil.parseInt(rsign.getLine(1))); - } - } - } - - int id = 1; - if (getSign().getLine(1).isEmpty()) { - if (!used.isEmpty()) { - while (used.contains(id)) { - id++; - } - } - - } else { - id = NumberUtil.parseInt(getSign().getLine(1)); - if (used.contains(id)) { - return false; - } else { - return true; - } - } - - getSign().setLine(1, id + ""); - - new SignUpdateTask(getSign()).runTaskLater(plugin, 2L); - - return true; - } - - @Override - public void onInit() { - triggerId = NumberUtil.parseInt(getSign().getLine(1)); - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - - initialized = true; - } - - @Override - public void onTrigger() { - if (!initialized) { - return; - } - - SignTrigger trigger = SignTrigger.getById(triggerId, getGameWorld()); - if (trigger != null) { - trigger.onTrigger(true); - } - } - - @Override - public void onDisable() { - if (!initialized) { - return; - } - - SignTrigger trigger = SignTrigger.getById(triggerId, getGameWorld()); - if (trigger != null) { - trigger.onTrigger(false); - } - } - - @Override - public DSignType getType() { - return DSignTypeDefault.TRIGGER; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/NoteSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/ActionBarSign.java similarity index 54% rename from core/src/main/java/de/erethon/dungeonsxl/sign/NoteSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/button/ActionBarSign.java index 65916d21..38f4fbd2 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/NoteSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/ActionBarSign.java @@ -14,35 +14,38 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.button; -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.world.DGameWorld; +import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; import org.bukkit.block.Sign; +import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class NoteSign extends DSign { +public class ActionBarSign extends MessageSign { - public NoteSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + public ActionBarSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } @Override - public boolean check() { + public String getName() { + return "ActionBar"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".actionbar"; + } + + @Override + public boolean push(Player player) { + MessageUtil.sendActionBarMessage(player, text); return true; } - @Override - public void onInit() { - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - } - - @Override - public DSignType getType() { - return DSignTypeDefault.NOTE; - } - } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/BossShopSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/BossShopSign.java similarity index 68% rename from core/src/main/java/de/erethon/dungeonsxl/sign/BossShopSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/button/BossShopSign.java index 6e6c5046..d82f7f3d 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/BossShopSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/BossShopSign.java @@ -14,12 +14,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.button; -import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Button; +import de.erethon.dungeonsxl.api.world.InstanceWorld; import de.erethon.dungeonsxl.config.DMessage; +import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.world.DGameWorld; import org.black_ixx.bossshop.BossShop; @@ -32,39 +34,56 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class BossShopSign extends DSign { +public class BossShopSign extends Button { private BossShop bossShop; private String shopName; - public BossShopSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + public BossShopSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } - /* Getters and setters*/ - /** - * @return the name of the shop - */ public String getShopName() { return shopName; } - /** - * @param name the name of the shop - */ public void setShopName(String name) { shopName = name; } - /* Actions */ @Override - public boolean check() { + public String getName() { + return "BossShop"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".bossshop"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { return true; } @Override - public void onInit() { + public boolean isSetToAir() { + return false; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { if (Bukkit.getPluginManager().isPluginEnabled("BossShopPro")) { bossShop = (BossShop) Bukkit.getPluginManager().getPlugin("BossShopPro"); } else { @@ -73,42 +92,37 @@ public class BossShopSign extends DSign { if (bossShop == null) { markAsErroneous("BossShop not enabled"); return; - } else if (bossShop.getAPI().getShop(lines[1]) == null) { + } else if (bossShop.getAPI().getShop(getLine(1)) == null) { markAsErroneous("No such BossShop"); return; } - shopName = lines[1]; + shopName = getLine(1); if (!getTriggers().isEmpty()) { - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); + setToAir(); return; } - InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGameWorld()); + InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), (DGameWorld) getGameWorld()); if (trigger != null) { trigger.addListener(this); addTrigger(trigger); } getSign().setLine(0, ChatColor.DARK_BLUE + "############"); - getSign().setLine(1, ChatColor.GREEN + lines[1]); - getSign().setLine(2, ChatColor.GREEN + lines[2]); + getSign().setLine(1, ChatColor.GREEN + getLine(1)); + getSign().setLine(2, ChatColor.GREEN + getLine(2)); getSign().setLine(3, ChatColor.DARK_BLUE + "############"); getSign().update(); } @Override - public boolean onPlayerTrigger(Player player) { + public boolean push(Player player) { openShop(player, shopName); return true; } - @Override - public DSignType getType() { - return DSignTypeDefault.BOSS_SHOP; - } - public void openShop(Player player, String shopName) { BSShop shop = bossShop.getAPI().getShop(shopName); if (shop != null) { diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/button/ChatMessageSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/ChatMessageSign.java new file mode 100644 index 00000000..b47caeda --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/ChatMessageSign.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.button; + +import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import java.util.ArrayList; +import java.util.List; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; + +/** + * @author Frank Baumann, Milan Albrecht, Daniel Saukel + */ +public class ChatMessageSign extends MessageSign { + + private List done = new ArrayList<>(); + + public ChatMessageSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + @Override + public String getName() { + return "MSG"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".msg"; + } + + @Override + public boolean push(Player player) { + if (!done.contains(player)) { + MessageUtil.sendMessage(player, text); + done.add(player); + } + + if (done.size() >= getGameWorld().getWorld().getPlayers().size()) { + getGameWorld().removeDungeonSign(this); + } + + return true; + } + + @Override + public void push() { + for (Player player : getGameWorld().getWorld().getPlayers()) { + MessageUtil.sendMessage(player, text); + } + getGameWorld().removeDungeonSign(this); + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/button/CheckpointSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/CheckpointSign.java new file mode 100644 index 00000000..d2db8bd2 --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/CheckpointSign.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.button; + +import de.erethon.commons.chat.MessageUtil; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.player.GamePlayer; +import de.erethon.dungeonsxl.api.player.InstancePlayer; +import de.erethon.dungeonsxl.api.sign.Button; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.config.DMessage; +import de.erethon.dungeonsxl.player.DPermission; +import java.util.ArrayList; +import java.util.List; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; + +/** + * @author Frank Baumann, Milan Albrecht, Daniel Saukel + */ +public class CheckpointSign extends Button { + + private List done = new ArrayList<>(); + + public CheckpointSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + @Override + public String getName() { + return "Checkpoint"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".checkpoint"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { + } + + @Override + public void push() { + for (InstancePlayer instancePlayer : getGameWorld().getPlayers()) { + GamePlayer gamePlayer = (GamePlayer) instancePlayer; + if (done.contains(gamePlayer)) { + continue; + } + gamePlayer.setLastCheckpoint(getSign().getLocation()); + gamePlayer.sendMessage(DMessage.PLAYER_CHECKPOINT_REACHED.getMessage()); + } + + getGameWorld().removeDungeonSign(this); + } + + @Override + public boolean push(Player player) { + GamePlayer gamePlayer = api.getPlayerCache().getGamePlayer(player); + if (!done.contains(gamePlayer)) { + done.add(gamePlayer); + gamePlayer.setLastCheckpoint(getSign().getLocation()); + MessageUtil.sendMessage(player, DMessage.PLAYER_CHECKPOINT_REACHED.getMessage()); + } + + if (done.size() >= getGameWorld().getPlayers().size()) { + getGameWorld().removeDungeonSign(this); + } + return true; + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/button/ClassesSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/ClassesSign.java new file mode 100644 index 00000000..984a280d --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/ClassesSign.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.button; + +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.player.GamePlayer; +import de.erethon.dungeonsxl.api.player.PlayerClass; +import de.erethon.dungeonsxl.api.sign.Button; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import de.erethon.dungeonsxl.trigger.InteractTrigger; +import de.erethon.dungeonsxl.world.DGameWorld; +import org.bukkit.ChatColor; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; + +/** + * @author Frank Baumann, Daniel Saukel + */ +public class ClassesSign extends Button { + + private PlayerClass playerClass; + + public ClassesSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + playerClass = api.getClassRegistry().get(sign.getLine(1)); + } + + public PlayerClass getPlayerClass() { + return playerClass; + } + + public void setPlayerClass(PlayerClass playerClass) { + this.playerClass = playerClass; + } + + @Override + public String getName() { + return "Classes"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".classes"; + } + + @Override + public boolean isOnDungeonInit() { + return true; + } + + @Override + public boolean isProtected() { + return true; + } + + @Override + public boolean isSetToAir() { + return false; + } + + @Override + public boolean validate() { + return api.getClassRegistry().get(getLine(1)) != null; + } + + @Override + public void initialize() { + if (playerClass != null) { + InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), (DGameWorld) getGameWorld()); + if (trigger != null) { + trigger.addListener(this); + addTrigger(trigger); + } + + getSign().setLine(0, ChatColor.DARK_BLUE + "############"); + getSign().setLine(1, ChatColor.DARK_GREEN + playerClass.getName()); + getSign().setLine(2, ""); + getSign().setLine(3, ChatColor.DARK_BLUE + "############"); + getSign().update(); + + getGameWorld().setClassesEnabled(true); + + } else { + markAsErroneous("No such class"); + } + } + + @Override + public boolean push(Player player) { + GamePlayer gamePlayer = api.getPlayerCache().getGamePlayer(player); + gamePlayer.setPlayerClass(playerClass); + return true; + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/EndSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/EndSign.java similarity index 61% rename from core/src/main/java/de/erethon/dungeonsxl/sign/EndSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/button/EndSign.java index 40d11e4f..12be6135 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/EndSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/EndSign.java @@ -14,13 +14,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.button; import de.erethon.caliburn.item.VanillaItem; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.dungeon.Dungeon; +import de.erethon.dungeonsxl.api.sign.Button; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.api.world.ResourceWorld; import de.erethon.dungeonsxl.config.DMessage; -import de.erethon.dungeonsxl.dungeon.DDungeon; import de.erethon.dungeonsxl.player.DGamePlayer; +import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DResourceWorld; @@ -31,37 +35,56 @@ import org.bukkit.entity.Player; /** * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ -public class EndSign extends DSign { +public class EndSign extends Button { - private DResourceWorld floor; + private ResourceWorld floor; - public EndSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + public EndSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } - /** - * @return the next floor - */ - public DResourceWorld getFloor() { + public ResourceWorld getFloor() { return floor; } - /** - * @param floor the floor to set - */ - public void setFloor(DResourceWorld floor) { + public void setFloor(ResourceWorld floor) { this.floor = floor; } @Override - public boolean check() { + public String getName() { + return "End"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".end"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { return true; } @Override - public void onInit() { - if (!lines[1].isEmpty()) { - floor = plugin.getDWorldCache().getResourceByName(lines[1]); + public boolean isSetToAir() { + return false; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { + if (!getLine(1).isEmpty()) { + floor = api.getMapRegistry().get(getLine(1)); } if (!getTriggers().isEmpty()) { @@ -69,15 +92,15 @@ public class EndSign extends DSign { return; } - InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGameWorld()); + InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), (DGameWorld) getGameWorld()); if (trigger != null) { trigger.addListener(this); addTrigger(trigger); } getSign().setLine(0, ChatColor.DARK_BLUE + "############"); - DDungeon dungeon = getGame().getDungeon(); - if (dungeon.isMultiFloor() && !getGame().getUnplayedFloors().isEmpty() && getGameWorld().getResource() != dungeon.getConfig().getEndFloor()) { + Dungeon dungeon = getGame().getDungeon(); + if (dungeon.isMultiFloor() && !getGame().getUnplayedFloors().isEmpty() && getGameWorld().getResource() != dungeon.getEndFloor()) { getSign().setLine(1, DMessage.SIGN_FLOOR_1.getMessage()); if (floor == null) { getSign().setLine(2, DMessage.SIGN_FLOOR_2.getMessage()); @@ -92,8 +115,8 @@ public class EndSign extends DSign { } @Override - public boolean onPlayerTrigger(Player player) { - DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); + public boolean push(Player player) { + DGamePlayer dPlayer = (DGamePlayer) api.getPlayerCache().getGamePlayer(player); if (dPlayer == null) { return true; } @@ -102,20 +125,8 @@ public class EndSign extends DSign { return true; } - dPlayer.finishFloor(floor); + dPlayer.finishFloor((DResourceWorld) floor); return true; } - @Override - public void onTrigger() { - for (DGamePlayer dPlayer : DGamePlayer.getByWorld(getGameWorld().getWorld())) { - dPlayer.finish(); - } - } - - @Override - public DSignType getType() { - return DSignTypeDefault.END; - } - } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/LeaveSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/LeaveSign.java similarity index 66% rename from core/src/main/java/de/erethon/dungeonsxl/sign/LeaveSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/button/LeaveSign.java index 42a7ce36..e9cbd84c 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/LeaveSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/LeaveSign.java @@ -14,13 +14,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.button; -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Button; +import de.erethon.dungeonsxl.api.world.InstanceWorld; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent; import de.erethon.dungeonsxl.player.DGamePlayer; +import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.Bukkit; @@ -31,25 +33,50 @@ import org.bukkit.entity.Player; /** * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ -public class LeaveSign extends DSign { +public class LeaveSign extends Button { - public LeaveSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + public LeaveSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } @Override - public boolean check() { + public String getName() { + return "Leave"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".leave"; + } + + @Override + public boolean isOnDungeonInit() { return true; } @Override - public void onInit() { + public boolean isProtected() { + return true; + } + + @Override + public boolean isSetToAir() { + return false; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { if (!getTriggers().isEmpty()) { - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); + setToAir(); return; } - InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGameWorld()); + InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), (DGameWorld) getGameWorld()); if (trigger != null) { trigger.addListener(this); addTrigger(trigger); @@ -62,8 +89,8 @@ public class LeaveSign extends DSign { } @Override - public boolean onPlayerTrigger(Player player) { - DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); + public boolean push(Player player) { + DGamePlayer dPlayer = (DGamePlayer) api.getPlayerCache().getGamePlayer(player); if (dPlayer != null) { DGamePlayerEscapeEvent event = new DGamePlayerEscapeEvent(dPlayer); Bukkit.getPluginManager().callEvent(event); @@ -78,23 +105,4 @@ public class LeaveSign extends DSign { return true; } - @Override - public void onTrigger() { - for (DGamePlayer dPlayer : plugin.getDPlayerCache().getDGamePlayers()) { - DGamePlayerEscapeEvent event = new DGamePlayerEscapeEvent(dPlayer); - Bukkit.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return; - } - - dPlayer.leave(); - } - } - - @Override - public DSignType getType() { - return DSignTypeDefault.LEAVE; - } - } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/LivesModifierSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/LivesModifierSign.java similarity index 53% rename from core/src/main/java/de/erethon/dungeonsxl/sign/LivesModifierSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/button/LivesModifierSign.java index bb3b2a30..5c469642 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/LivesModifierSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/LivesModifierSign.java @@ -14,25 +14,25 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.button; -import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.misc.EnumUtil; import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.player.GamePlayer; +import de.erethon.dungeonsxl.api.player.PlayerGroup; +import de.erethon.dungeonsxl.api.sign.Button; +import de.erethon.dungeonsxl.api.world.InstanceWorld; import de.erethon.dungeonsxl.config.DMessage; -import de.erethon.dungeonsxl.dungeon.DGame; -import de.erethon.dungeonsxl.player.DGamePlayer; -import de.erethon.dungeonsxl.player.DGroup; -import de.erethon.dungeonsxl.world.DGameWorld; +import de.erethon.dungeonsxl.player.DPermission; import org.bukkit.block.Sign; import org.bukkit.entity.Player; /** * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ -public class LivesModifierSign extends DSign { +public class LivesModifierSign extends Button { public enum Target { GAME, @@ -43,47 +43,62 @@ public class LivesModifierSign extends DSign { private int lives; private Target target; - public LivesModifierSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + public LivesModifierSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } - /* Getters and setters */ - /** - * @return the lives to add / remove - */ public int getLives() { return lives; } - /** - * @param lives the lives to add / remove - */ public void setLives(int lives) { this.lives = lives; } - /* Actions */ @Override - public boolean check() { - return NumberUtil.parseInt(lines[1]) != 0; + public String getName() { + return "Lives"; } @Override - public void onInit() { - lives = NumberUtil.parseInt(lines[1]); - if (EnumUtil.isValidEnum(Target.class, lines[2].toUpperCase())) { - target = Target.valueOf(lines[2].toUpperCase()); + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".lives"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + return NumberUtil.parseInt(getLine(1)) != 0; + } + + @Override + public void initialize() { + lives = NumberUtil.parseInt(getLine(1)); + if (EnumUtil.isValidEnum(Target.class, getLine(2).toUpperCase())) { + target = Target.valueOf(getLine(2).toUpperCase()); } - - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); } @Override - public boolean onPlayerTrigger(Player player) { + public boolean push(Player player) { switch (target) { case GAME: - for (Player gamePlayer : DGame.getByPlayer(player).getPlayers()) { - DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); + for (Player gamePlayer : getGame().getPlayers()) { + GamePlayer dPlayer = api.getPlayerCache().getGamePlayer(player); if (gamePlayer != null) { modifyLives(dPlayer); } @@ -91,17 +106,17 @@ public class LivesModifierSign extends DSign { break; case GROUP: - modifyLives(DGroup.getByPlayer(player)); + modifyLives(api.getPlayerGroup(player)); break; case PLAYER: - modifyLives(DGamePlayer.getByPlayer(player)); + modifyLives(api.getPlayerCache().getGamePlayer(player)); } return true; } - public void modifyLives(DGamePlayer dPlayer) { + public void modifyLives(GamePlayer dPlayer) { dPlayer.setLives(dPlayer.getLives() + lives); if (lives > 0) { MessageUtil.sendMessage(dPlayer.getPlayer(), DMessage.PLAYER_LIVES_ADDED.getMessage(String.valueOf(lives))); @@ -115,19 +130,14 @@ public class LivesModifierSign extends DSign { } } - public void modifyLives(DGroup dGroup) { - dGroup.setLives(dGroup.getLives() + lives); + public void modifyLives(PlayerGroup group) { + group.setLives(group.getLives() + lives); if (lives > 0) { - dGroup.sendMessage(DMessage.GROUP_LIVES_ADDED.getMessage(String.valueOf(lives))); + group.sendMessage(DMessage.GROUP_LIVES_ADDED.getMessage(String.valueOf(lives))); } else { - dGroup.sendMessage(DMessage.GROUP_LIVES_REMOVED.getMessage(String.valueOf(-1 * lives))); + group.sendMessage(DMessage.GROUP_LIVES_REMOVED.getMessage(String.valueOf(-1 * lives))); } } - @Override - public DSignType getType() { - return DSignTypeDefault.LIVES_MODIFIER; - } - } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/button/MessageSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/MessageSign.java new file mode 100644 index 00000000..a8e13669 --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/MessageSign.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.button; + +import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.dungeon.GameRule; +import de.erethon.dungeonsxl.api.sign.Button; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import org.bukkit.block.Sign; + +/** + * @author Daniel Saukel + */ +public abstract class MessageSign extends Button { + + protected String text; + + public MessageSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + @Override + public boolean isOnDungeonInit() { + return true; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + return !getLine(1).isEmpty(); + } + + @Override + public void initialize() { + String text = getGameWorld().getDungeon().getRules().getState(GameRule.MESSAGES).get(NumberUtil.parseInt(getLine(1))); + if (text != null) { + this.text = text; + } + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/lobby/ReadySign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/ReadySign.java similarity index 52% rename from core/src/main/java/de/erethon/dungeonsxl/sign/lobby/ReadySign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/button/ReadySign.java index ee9b2c11..6cde0d3c 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/lobby/ReadySign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/ReadySign.java @@ -14,19 +14,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign.lobby; +package de.erethon.dungeonsxl.sign.button; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.player.GamePlayer; +import de.erethon.dungeonsxl.api.sign.Button; +import de.erethon.dungeonsxl.api.world.InstanceWorld; import de.erethon.dungeonsxl.config.DMessage; -import de.erethon.dungeonsxl.game.GameType; -import de.erethon.dungeonsxl.game.GameTypeDefault; -import de.erethon.dungeonsxl.player.DGamePlayer; -import de.erethon.dungeonsxl.player.DGroup; -import de.erethon.dungeonsxl.sign.DSign; -import de.erethon.dungeonsxl.sign.DSignType; -import de.erethon.dungeonsxl.sign.DSignTypeDefault; +import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.util.ProgressBar; import de.erethon.dungeonsxl.world.DGameWorld; @@ -37,61 +34,58 @@ import org.bukkit.entity.Player; /** * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ -public class ReadySign extends DSign { +public class ReadySign extends Button { - private GameType gameType; private double autoStart = -1; private boolean triggered = false; private ProgressBar bar; - public ReadySign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + public ReadySign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } - /** - * @return the gameType - */ - public GameType getGameType() { - return gameType; - } - - /** - * @param gameType the gameType to set - */ - public void setGameType(GameType gameType) { - this.gameType = gameType; - } - - /** - * @return the time until the game starts automatically; -1 for no auto start - */ public double getTimeToAutoStart() { return autoStart; } - /** - * @param time the time in seconds until the game starts automatically; -1 for no auto start - */ public void setTimeToAutoStart(double time) { autoStart = time; } @Override - public boolean check() { + public String getName() { + return "Ready"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".ready"; + } + + @Override + public boolean isOnDungeonInit() { return true; } @Override - public void onInit() { - if (plugin.getGameTypeCache().getBySign(this) != null) { - gameType = plugin.getGameTypeCache().getBySign(this); + public boolean isProtected() { + return true; + } - } else { - gameType = GameTypeDefault.CUSTOM; - } + @Override + public boolean isSetToAir() { + return false; + } - if (!lines[2].isEmpty()) { - autoStart = NumberUtil.parseDouble(lines[2], -1); + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { + if (!getLine(2).isEmpty()) { + autoStart = NumberUtil.parseDouble(getLine(2), -1); } if (!getTriggers().isEmpty()) { @@ -99,7 +93,7 @@ public class ReadySign extends DSign { return; } - InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGameWorld()); + InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), (DGameWorld) getGameWorld()); if (trigger != null) { trigger.addListener(this); addTrigger(trigger); @@ -107,34 +101,13 @@ public class ReadySign extends DSign { getSign().setLine(0, ChatColor.DARK_BLUE + "############"); getSign().setLine(1, DMessage.SIGN_READY.getMessage()); - getSign().setLine(2, ChatColor.DARK_RED + gameType.getSignName()); + getSign().setLine(2, ""); getSign().setLine(3, ChatColor.DARK_BLUE + "############"); getSign().update(); } @Override - public boolean onPlayerTrigger(Player player) { - ready(DGamePlayer.getByPlayer(player)); - - if (!triggered && autoStart >= 0) { - triggered = true; - - if (!DGroup.getByPlayer(player).isPlaying()) { - bar = new ProgressBar(getGame().getPlayers(), (int) Math.ceil(autoStart)) { - @Override - public void onFinish() { - onTrigger(); - } - }; - bar.send(plugin); - } - } - - return true; - } - - @Override - public void onTrigger() { + public void push() { if (getGame() == null) { return; } @@ -144,32 +117,48 @@ public class ReadySign extends DSign { } for (Player player : getGame().getPlayers()) { - ready(DGamePlayer.getByPlayer(player)); + ready(api.getPlayerCache().getGamePlayer(player)); } } - private void ready(DGamePlayer dPlayer) { - if (dPlayer == null || dPlayer.isReady()) { + @Override + public boolean push(Player player) { + GamePlayer gamePlayer = api.getPlayerCache().getGamePlayer(player); + ready(gamePlayer); + + if (!triggered && autoStart >= 0) { + triggered = true; + + if (gamePlayer != null && !gamePlayer.getGroup().isPlaying()) { + bar = new ProgressBar(getGame().getPlayers(), (int) Math.ceil(autoStart)) { + @Override + public void onFinish() { + push(); + } + }; + bar.send(api); + } + } + + return true; + } + + private void ready(GamePlayer player) { + if (player == null || player.isReady()) { return; } - if (getGameWorld().getClassesSigns().isEmpty() || dPlayer.getDClass() != null) { - GameType forced = null; - if (getGameWorld().getConfig() != null) { - forced = getGameWorld().getConfig().getForcedGameType(); - } - boolean ready = dPlayer.ready(forced == null ? gameType : forced); - if (ready && bar != null) { + if (!getGameWorld().areClassesEnabled() || player.getPlayerClass() != null) { + if (player.ready() && bar != null) { bar.cancel(); } } - dPlayer.sendMessage((dPlayer.isReady() ? DMessage.PLAYER_READY : DMessage.ERROR_READY).getMessage()); - } - - @Override - public DSignType getType() { - return DSignTypeDefault.READY; + if (player.isReady()) { + player.sendMessage(DMessage.PLAYER_READY.getMessage()); + } else if (getGameWorld().areClassesEnabled()) { + player.sendMessage(DMessage.ERROR_READY.getMessage()); + } } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/ResourcePackSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/ResourcePackSign.java similarity index 61% rename from core/src/main/java/de/erethon/dungeonsxl/sign/ResourcePackSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/button/ResourcePackSign.java index 17b9bae1..4605d9b1 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/ResourcePackSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/ResourcePackSign.java @@ -14,11 +14,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.button; -import de.erethon.caliburn.item.VanillaItem; import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Button; +import de.erethon.dungeonsxl.api.world.InstanceWorld; import de.erethon.dungeonsxl.config.DMessage; +import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.ChatColor; @@ -28,48 +31,60 @@ import org.bukkit.entity.Player; /** * @author Daniel Saukel */ -public class ResourcePackSign extends DSign { +public class ResourcePackSign extends Button { private String resourcePack; - public ResourcePackSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + public ResourcePackSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } - /* Getters and setters */ - @Override - public DSignType getType() { - return DSignTypeDefault.RESOURCE_PACK; - } - - /** - * @return the external mob - */ public String getResourcePack() { return resourcePack; } - /** - * @param resourcePack the resource pack to set - */ public void setExternalMob(String resourcePack) { this.resourcePack = resourcePack; } - /* Actions */ @Override - public boolean check() { - return plugin.getMainConfig().getResourcePacks().get(lines[1]) != null || lines[1].equalsIgnoreCase("reset"); + public String getName() { + return "ResourcePack"; } @Override - public void onInit() { + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".resourcepack"; + } + + @Override + public boolean isOnDungeonInit() { + return true; + } + + @Override + public boolean isProtected() { + return true; + } + + @Override + public boolean isSetToAir() { + return false; + } + + @Override + public boolean validate() { + return ((DungeonsXL) api).getMainConfig().getResourcePacks().get(getLine(1)) != null || getLine(1).equalsIgnoreCase("reset"); + } + + @Override + public void initialize() { Object url = null; - if (lines[1].equalsIgnoreCase("reset")) { + if (getLine(1).equalsIgnoreCase("reset")) { // Placeholder to reset to default url = "http://google.com"; } else { - url = plugin.getMainConfig().getResourcePacks().get(lines[1]); + url = ((DungeonsXL) api).getMainConfig().getResourcePacks().get(getLine(1)); } if (url instanceof String) { @@ -81,26 +96,25 @@ public class ResourcePackSign extends DSign { } if (!getTriggers().isEmpty()) { - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); + setToAir(); return; } - InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGameWorld()); + InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), (DGameWorld) getGameWorld()); if (trigger != null) { trigger.addListener(this); addTrigger(trigger); } - String name = lines[1]; getSign().setLine(0, ChatColor.DARK_BLUE + "############"); getSign().setLine(1, DMessage.SIGN_RESOURCE_PACK.getMessage()); - getSign().setLine(2, ChatColor.DARK_GREEN + name); + getSign().setLine(2, ChatColor.DARK_GREEN + getLine(1)); getSign().setLine(3, ChatColor.DARK_BLUE + "############"); getSign().update(); } @Override - public boolean onPlayerTrigger(Player player) { + public boolean push(Player player) { player.setResourcePack(resourcePack); return true; } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/button/SoundMessageSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/SoundMessageSign.java new file mode 100644 index 00000000..204a918e --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/SoundMessageSign.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.button; + +import de.erethon.commons.compatibility.Internals; +import de.erethon.commons.misc.EnumUtil; +import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Button; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import java.util.ArrayList; +import java.util.List; +import org.bukkit.SoundCategory; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; + +/** + * @author Frank Baumann, Milan Albrecht, Daniel Saukel + */ +public class SoundMessageSign extends Button { + + private String sound; + private SoundCategory category; + private float volume; + private float pitch; + private List done = new ArrayList<>(); + + public SoundMessageSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + @Override + public String getName() { + return "SoundMSG"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".soundmsg"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + if (getLine(1).isEmpty()) { + markAsErroneous("1. Line is empty; expected input: sound name"); + return false; + } + + return true; + } + + @Override + public void initialize() { + sound = getLine(1); + if (getLine(2).isEmpty()) { + return; + } + + String[] args = getLine(2).split(","); + if (args.length >= 1 && args.length != 2 && Internals.isAtLeast(Internals.v1_11_R1)) { + category = EnumUtil.getEnumIgnoreCase(SoundCategory.class, args[0]); + if (category == null) { + category = SoundCategory.MASTER; + } + } + if (args.length == 2) { + volume = (float) NumberUtil.parseDouble(args[0], 5.0); + pitch = (float) NumberUtil.parseDouble(args[1], 1.0); + } else if (args.length == 3) { + volume = (float) NumberUtil.parseDouble(args[1], 5.0); + pitch = (float) NumberUtil.parseDouble(args[2], 1.0); + } + } + + @Override + public void push() { + for (Player player : getGameWorld().getWorld().getPlayers()) { + playSound(player); + } + getGameWorld().removeDungeonSign(this); + } + + @Override + public boolean push(Player player) { + if (!done.contains(player)) { + done.add(player); + playSound(player); + } + + if (done.size() >= getGameWorld().getWorld().getPlayers().size()) { + getGameWorld().removeDungeonSign(this); + } + return true; + } + + private void playSound(Player player) { + if (Internals.isAtLeast(Internals.v1_11_R1)) { + player.playSound(getSign().getLocation(), sound, category, volume, pitch); + } else { + player.playSound(getSign().getLocation(), sound, volume, pitch); + } + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/TeleportSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/TeleportSign.java similarity index 55% rename from core/src/main/java/de/erethon/dungeonsxl/sign/TeleportSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/button/TeleportSign.java index 12ad846c..6c3a1aaa 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/TeleportSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/TeleportSign.java @@ -14,31 +14,71 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.button; -import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.BlockUtil; import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.world.DGameWorld; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Button; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import de.erethon.dungeonsxl.sign.LocationSign; +import org.bukkit.Location; import org.bukkit.block.Sign; import org.bukkit.entity.Player; /** * @author Milan Albrecht, Daniel Saukel */ -public class TeleportSign extends LocationSign { +public class TeleportSign extends Button implements LocationSign { - public TeleportSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + private Location location; + + public TeleportSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } @Override - public boolean check() { + public Location getLocation() { + return location; + } + + @Override + public void setLocation(Location location) { + this.location = location; + } + + @Override + public String getName() { + return "Teleport"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".teleport"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { for (int i = 1; i <= 2; i++) { - if (!lines[i].isEmpty()) { - if (BlockUtil.lettersToYaw(lines[i]) == -1) { - String[] loc = lines[i].split(","); + if (!getLine(i).isEmpty()) { + if (BlockUtil.lettersToYaw(getLine(i)) == -1) { + String[] loc = getLine(i).split(","); if (loc.length != 3) { return false; } @@ -49,17 +89,17 @@ public class TeleportSign extends LocationSign { } @Override - public void onInit() { - super.onInit(); + public void initialize() { + LocationSign.super.initialize(); for (int i = 1; i <= 2; i++) { - if (lines[i].isEmpty()) { + if (getLine(i).isEmpty()) { continue; } - Integer yaw = BlockUtil.lettersToYaw(lines[i]); + Integer yaw = BlockUtil.lettersToYaw(getLine(i)); if (yaw != null) { location.setYaw(yaw); } else { - String[] loc = lines[i].split(","); + String[] loc = getLine(i).split(","); if (loc.length == 3) { double x = NumberUtil.parseDouble(loc[0]); double y = NumberUtil.parseDouble(loc[1]); @@ -75,29 +115,16 @@ public class TeleportSign extends LocationSign { } } } - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); } @Override - public void onTrigger() { - if (location != null) { - for (Player player : getGameWorld().getWorld().getPlayers()) { - player.teleport(location); - } - } - } - - @Override - public boolean onPlayerTrigger(Player player) { + public boolean push(Player player) { if (location != null) { player.teleport(location); + return true; + } else { + return false; } - return true; - } - - @Override - public DSignType getType() { - return DSignTypeDefault.TELEPORT; } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/button/TitleSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/TitleSign.java new file mode 100644 index 00000000..4997628d --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/TitleSign.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.button; + +import de.erethon.commons.chat.MessageUtil; +import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; + +/** + * @author Daniel Saukel + */ +public class TitleSign extends MessageSign { + + private String title, subtitle; + private int fadeIn = 10, stay = 70, fadeOut = 20; + + public TitleSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + @Override + public String getName() { + return "Title"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".title"; + } + + @Override + public void initialize() { + super.initialize(); + + String[] line1 = text.split("/"); + title = line1[0]; + if (line1.length > 1) { + subtitle = line1[1]; + } else { + subtitle = ""; + } + + if (getLine(2).isEmpty()) { + return; + } + String[] line2 = getLine(2).split(","); + if (line2.length != 3) { + return; + } + fadeIn = NumberUtil.parseInt(line2[0], fadeIn); + stay = NumberUtil.parseInt(line2[1], stay); + fadeOut = NumberUtil.parseInt(line2[2], fadeOut); + } + + @Override + public boolean push(Player player) { + MessageUtil.sendTitleMessage(player, title, subtitle, fadeIn, stay, fadeOut); + return true; + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/WaveSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/button/WaveSign.java similarity index 62% rename from core/src/main/java/de/erethon/dungeonsxl/sign/WaveSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/button/WaveSign.java index aad86eca..4e209aed 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/WaveSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/button/WaveSign.java @@ -14,79 +14,94 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.button; -import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Button; +import de.erethon.dungeonsxl.api.world.InstanceWorld; import de.erethon.dungeonsxl.config.DMessage; +import de.erethon.dungeonsxl.dungeon.DGame; +import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.trigger.InteractTrigger; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.ChatColor; import org.bukkit.block.Sign; -import org.bukkit.entity.Player; /** * @author Frank Baumann, Daniel Saukel */ -public class WaveSign extends DSign { +public class WaveSign extends Button { private double mobCountIncreaseRate; private boolean teleport; - public WaveSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + public WaveSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } - /** - * @return the mobCountIncreaseRate - */ public double getMobCountIncreaseRate() { return mobCountIncreaseRate; } - /** - * @param mobCountIncreaseRate the mobCountIncreaseRate to set - */ public void setMobCountIncreaseRate(double mobCountIncreaseRate) { this.mobCountIncreaseRate = mobCountIncreaseRate; } - /** - * @return if the group members will be teleported to the start location - */ public boolean getTeleport() { return teleport; } - /** - * @param teleport Set if the players shall get teleported to the start location - */ public void setTeleport(boolean teleport) { this.teleport = teleport; } @Override - public boolean check() { + public String getName() { + return "Wave"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".wave"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { return true; } @Override - public void onInit() { - if (!lines[1].isEmpty()) { - mobCountIncreaseRate = NumberUtil.parseDouble(lines[1], 2); + public boolean isSetToAir() { + return false; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { + if (!getLine(1).isEmpty()) { + mobCountIncreaseRate = NumberUtil.parseDouble(getLine(1), 2); } - if (!lines[2].isEmpty()) { - teleport = lines[2].equals("+") || lines[2].equals("true"); + if (!getLine(2).isEmpty()) { + teleport = getLine(2).equals("+") || getLine(2).equals("true"); } if (!getTriggers().isEmpty()) { - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); + setToAir(); return; } - InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGameWorld()); + InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), (DGameWorld) getGameWorld()); if (trigger != null) { trigger.addListener(this); addTrigger(trigger); @@ -100,19 +115,8 @@ public class WaveSign extends DSign { } @Override - public boolean onPlayerTrigger(Player player) { - getGame().finishWave(mobCountIncreaseRate, teleport); - return true; - } - - @Override - public void onTrigger() { - getGame().finishWave(mobCountIncreaseRate, teleport); - } - - @Override - public DSignType getType() { - return DSignTypeDefault.WAVE; + public void push() { + ((DGame) getGame()).finishWave(mobCountIncreaseRate, teleport); } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/lobby/ClassesSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/lobby/ClassesSign.java deleted file mode 100644 index 524798de..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/lobby/ClassesSign.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign.lobby; - -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.api.player.PlayerClass; -import de.erethon.dungeonsxl.sign.DSign; -import de.erethon.dungeonsxl.sign.DSignType; -import de.erethon.dungeonsxl.sign.DSignTypeDefault; -import de.erethon.dungeonsxl.world.DGameWorld; -import org.bukkit.ChatColor; -import org.bukkit.block.Sign; - -/** - * @author Frank Baumann, Daniel Saukel - */ -public class ClassesSign extends DSign { - - private PlayerClass dClass; - - public ClassesSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - dClass = plugin.getDClassCache().getByName(sign.getLine(1)); - } - - /* Getters and setters */ - /** - * @return the PlayerClass of the sign - */ - public PlayerClass getDClass() { - return dClass; - } - - /** - * @param dClass the PlayerClass to set - */ - public void setDClass(PlayerClass dClass) { - this.dClass = dClass; - } - - /* Actions */ - @Override - public boolean check() { - return plugin.getDClassCache().getByName(lines[1]) != null; - } - - @Override - public void onInit() { - if (dClass != null) { - getSign().setLine(0, ChatColor.DARK_BLUE + "############"); - getSign().setLine(1, ChatColor.DARK_GREEN + dClass.getName()); - getSign().setLine(2, ""); - getSign().setLine(3, ChatColor.DARK_BLUE + "############"); - getSign().update(); - getGameWorld().getClassesSigns().add(getSign()); - - } else { - markAsErroneous("No such class"); - } - } - - @Override - public DSignType getType() { - return DSignTypeDefault.CLASSES; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/lobby/LobbySign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/lobby/LobbySign.java deleted file mode 100644 index 65e56b95..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/lobby/LobbySign.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign.lobby; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.sign.DSignType; -import de.erethon.dungeonsxl.sign.DSignTypeDefault; -import de.erethon.dungeonsxl.sign.LocationSign; -import de.erethon.dungeonsxl.world.DGameWorld; -import org.bukkit.block.Sign; - -/** - * @author Frank Baumann, Daniel Saukel - */ -public class LobbySign extends LocationSign { - - public LobbySign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - @Override - public boolean check() { - return true; - } - - @Override - public void onInit() { - super.onInit(); - getGameWorld().setLobbyLocation(getLocation()); - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - } - - @Override - public DSignType getType() { - return DSignTypeDefault.LOBBY; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/lobby/StartSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/lobby/StartSign.java deleted file mode 100644 index 6c8b9d5d..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/lobby/StartSign.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign.lobby; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.sign.DSignType; -import de.erethon.dungeonsxl.sign.DSignTypeDefault; -import de.erethon.dungeonsxl.sign.LocationSign; -import de.erethon.dungeonsxl.world.DGameWorld; -import org.bukkit.block.Sign; - -/** - * @author Frank Baumann, Daniel Saukel - */ -public class StartSign extends LocationSign { - - private int id; - - public StartSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - /* Getters and setters */ - /** - * @return the ID - */ - public int getId() { - return id; - } - - /** - * @param id the ID to set - */ - public void setId(int id) { - this.id = id; - } - - /* Actions */ - @Override - public boolean check() { - return true; - } - - @Override - public void onInit() { - super.onInit(); - id = NumberUtil.parseInt(lines[1]); - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - } - - @Override - public DSignType getType() { - return DSignTypeDefault.START; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/message/ActionBarSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/message/ActionBarSign.java deleted file mode 100644 index 96a55e02..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/message/ActionBarSign.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign.message; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.chat.MessageUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.sign.DSignType; -import de.erethon.dungeonsxl.sign.DSignTypeDefault; -import de.erethon.dungeonsxl.sign.PerPlayerSign; -import de.erethon.dungeonsxl.world.DGameWorld; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; - -/** - * @author Daniel Saukel - */ -public class ActionBarSign extends PerPlayerSign { - - private String text; - - public ActionBarSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - /* Getters and setters*/ - /** - * @return the text - */ - public String getText() { - return text; - } - - /** - * @param text the text to set - */ - public void setText(String text) { - this.text = text; - } - - /* Actions */ - @Override - public boolean check() { - return true; - } - - @Override - public void onInit() { - text = lines[1]; - text += lines[2]; - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - } - - @Override - public boolean onPlayerTrigger(Player player) { - if (!super.onPlayerTrigger(player)) { - return false; - } - MessageUtil.sendActionBarMessage(player, text); - return true; - } - - @Override - public DSignType getType() { - return DSignTypeDefault.ACTION_BAR; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/message/MessageSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/message/MessageSign.java deleted file mode 100644 index 42c5b76b..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/message/MessageSign.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign.message; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.sign.DSign; -import de.erethon.dungeonsxl.sign.DSignType; -import de.erethon.dungeonsxl.sign.DSignTypeDefault; -import de.erethon.dungeonsxl.world.DGameWorld; -import java.util.concurrent.CopyOnWriteArrayList; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; - -/** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel - */ -public class MessageSign extends DSign { - - // Variables - private String msg = "UNKNOWN MESSAGE"; - private boolean initialized; - private CopyOnWriteArrayList done = new CopyOnWriteArrayList<>(); - - public MessageSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - @Override - public boolean check() { - if (getSign().getLine(1).isEmpty()) { - return false; - } - - return true; - } - - @Override - public void onInit() { - if (!lines[1].isEmpty()) { - String msg = getGame().getRules().getMessage(NumberUtil.parseInt(lines[1])); - if (msg != null) { - this.msg = msg; - } - } - - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - initialized = true; - } - - @Override - public boolean onPlayerTrigger(Player player) { - if (!initialized) { - return true; - } - - if (!done.contains(player)) { - MessageUtil.sendMessage(player, msg); - done.add(player); - } - - if (done.size() >= getGameWorld().getWorld().getPlayers().size()) { - remove(); - } - - return true; - } - - @Override - public void onTrigger() { - if (initialized) { - for (Player player : getGameWorld().getWorld().getPlayers()) { - MessageUtil.sendMessage(player, msg); - } - remove(); - } - } - - @Override - public DSignType getType() { - return DSignTypeDefault.MESSAGE; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java deleted file mode 100644 index 9cb437ef..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign.message; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.compatibility.Internals; -import de.erethon.commons.misc.EnumUtil; -import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.sign.DSign; -import de.erethon.dungeonsxl.sign.DSignType; -import de.erethon.dungeonsxl.sign.DSignTypeDefault; -import de.erethon.dungeonsxl.world.DGameWorld; -import java.util.concurrent.CopyOnWriteArrayList; -import org.bukkit.SoundCategory; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; - -/** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel - */ -public class SoundMessageSign extends DSign { - - // Variables - private boolean initialized; - private String sound; - private SoundCategory category; - private float volume; - private float pitch; - private CopyOnWriteArrayList done = new CopyOnWriteArrayList<>(); - - public SoundMessageSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - @Override - public boolean check() { - if (getSign().getLine(1).isEmpty()) { - return false; - } - - return true; - } - - @Override - public void onInit() { - if (!lines[1].isEmpty()) { - sound = lines[1]; - if (!lines[2].isEmpty()) { - String[] args = lines[2].split(","); - if (args.length >= 1 && args.length != 2 && Internals.isAtLeast(Internals.v1_11_R1)) { - category = EnumUtil.getEnumIgnoreCase(SoundCategory.class, args[0]); - if (category == null) { - category = SoundCategory.MASTER; - } - } - if (args.length == 2) { - volume = (float) NumberUtil.parseDouble(args[0], 5.0); - pitch = (float) NumberUtil.parseDouble(args[1], 1.0); - } else if (args.length == 3) { - volume = (float) NumberUtil.parseDouble(args[1], 5.0); - pitch = (float) NumberUtil.parseDouble(args[2], 1.0); - } - } - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - initialized = true; - } else { - markAsErroneous("1. Line is empty; expected input: sound name"); - } - } - - @Override - public void onTrigger() { - if (initialized) { - for (Player player : getGameWorld().getWorld().getPlayers()) { - player.playSound(getSign().getLocation(), sound, category, volume, pitch); - } - remove(); - } - } - - @Override - public boolean onPlayerTrigger(Player player) { - if (initialized) { - if (!done.contains(player)) { - done.add(player); - if (Internals.isAtLeast(Internals.v1_11_R1)) { - player.playSound(getSign().getLocation(), sound, category, volume, pitch); - } else { - player.playSound(getSign().getLocation(), sound, volume, pitch); - } - } - - if (done.size() >= getGameWorld().getWorld().getPlayers().size()) { - remove(); - } - } - return true; - } - - @Override - public DSignType getType() { - return DSignTypeDefault.SOUND_MESSAGE; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/message/TitleSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/message/TitleSign.java deleted file mode 100644 index 54361ea3..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/message/TitleSign.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2012-2020 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.sign.message; - -import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.chat.MessageUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.sign.DSignType; -import de.erethon.dungeonsxl.sign.DSignTypeDefault; -import de.erethon.dungeonsxl.sign.PerPlayerSign; -import de.erethon.dungeonsxl.world.DGameWorld; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; - -/** - * @author Daniel Saukel - */ -public class TitleSign extends PerPlayerSign { - - private String title; - private String subtitle; - - public TitleSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - /* Getters and setters*/ - /** - * @return the title - */ - public String getTitle() { - return title; - } - - /** - * @param text the text to set - */ - public void setTitle(String text) { - title = text; - } - - /** - * @return the subtitle - */ - public String getSubtitle() { - return subtitle; - } - - /** - * @param text the text to set - */ - public void setSubtitle(String text) { - subtitle = text; - } - - /* Actions */ - @Override - public boolean check() { - return true; - } - - @Override - public void onInit() { - title = lines[1]; - subtitle = lines[2]; - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - } - - @Override - public boolean onPlayerTrigger(Player player) { - if (!super.onPlayerTrigger(player)) { - return false; - } - MessageUtil.sendTitleMessage(player, title, subtitle); - return true; - } - - @Override - public DSignType getType() { - return DSignTypeDefault.TITLE; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/BedSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/BedSign.java similarity index 52% rename from core/src/main/java/de/erethon/dungeonsxl/sign/BedSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/passive/BedSign.java index af942f7c..b6026d45 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/BedSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/BedSign.java @@ -14,13 +14,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.passive; import de.erethon.caliburn.category.Category; -import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.BlockUtil; import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Passive; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DGroup; +import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.block.TeamBed; import org.bukkit.block.Block; @@ -29,36 +32,53 @@ import org.bukkit.block.Sign; /** * @author Daniel Saukel */ -public class BedSign extends DSign { +public class BedSign extends Passive { private int team; - public BedSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - /* Getters and setters */ - @Override - public DSignType getType() { - return DSignTypeDefault.BED; - } - - /* Actions */ - @Override - public boolean check() { - return NumberUtil.parseInt(lines[1], -1) != -1; + public BedSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } @Override - public void onInit() { - this.team = NumberUtil.parseInt(lines[1]); + public String getName() { + return "Bed"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".bed"; + } + + @Override + public boolean isOnDungeonInit() { + return true; + } + + @Override + public boolean isProtected() { + return true; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + return NumberUtil.parseInt(getLine(1), -1) != -1; + } + + @Override + public void initialize() { + this.team = NumberUtil.parseInt(getLine(1)); Block block = BlockUtil.getAttachedBlock(getSign().getBlock()); if (Category.BEDS.containsBlock(block)) { - if (getGame().getDGroups().size() > team) { - getGameWorld().addGameBlock(new TeamBed(plugin, block, getGame().getDGroups().get(team))); + if (getGame().getGroups().size() > team) { + ((DGameWorld) getGameWorld()).addGameBlock(new TeamBed(api, block, (DGroup) getGame().getGroups().get(team))); } - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); } else { markAsErroneous("No bed attached"); } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/ChestSign.java similarity index 79% rename from core/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/passive/ChestSign.java index 337e68ff..797c24b3 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/ChestSign.java @@ -14,11 +14,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.passive; import de.erethon.caliburn.loottable.LootTable; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.world.DGameWorld; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Passive; +import de.erethon.dungeonsxl.api.world.InstanceWorld; import org.bukkit.block.Block; import org.bukkit.block.Container; import org.bukkit.block.Sign; @@ -27,21 +28,17 @@ import org.bukkit.inventory.ItemStack; /** * @author Frank Baumann, Daniel Saukel */ -public abstract class ChestSign extends DSign { +public abstract class ChestSign extends Passive { protected Block chest; protected ItemStack[] chestContent; protected LootTable lootTable; - protected ChestSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + protected ChestSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } - /* Getters and setters */ - /** - * @return the chest contents - */ public ItemStack[] getChestContents() { if (chestContent == null) { checkChest(); @@ -49,28 +46,38 @@ public abstract class ChestSign extends DSign { return chestContent; } - /** - * @param items the items to set as chest contents - */ public void setChestContents(ItemStack[] items) { chestContent = items; } - /** - * @return the custom loot table - */ public LootTable getLootTable() { return lootTable; } - /** - * @param lootTable the loot table to set - */ public void setLootTable(LootTable lootTable) { this.lootTable = lootTable; } - /* Actions */ + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return false; + } + + @Override + public boolean validate() { + return true; + } + /** * Checks for a chest next to the sign and sets the reward to its contents. */ diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/DungeonChestSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/DungeonChestSign.java similarity index 71% rename from core/src/main/java/de/erethon/dungeonsxl/sign/DungeonChestSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/passive/DungeonChestSign.java index 757f8bf9..781b9b0f 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/DungeonChestSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/DungeonChestSign.java @@ -14,11 +14,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.passive; import de.erethon.caliburn.item.VanillaItem; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.world.DGameWorld; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; import java.util.Arrays; import java.util.List; import org.bukkit.block.Container; @@ -30,35 +31,33 @@ import org.bukkit.inventory.ItemStack; */ public class DungeonChestSign extends ChestSign { - public DungeonChestSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); - } - - /* Getters and setters */ - @Override - public DSignType getType() { - return DSignTypeDefault.DUNGEON_CHEST; - } - - /* Actions */ - @Override - public boolean check() { - return true; + public DungeonChestSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } @Override - public void onInit() { + public String getName() { + return "DungeonChest"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".dungeonchest"; + } + + @Override + public void initialize() { // For consistency with reward chests but also for intuitiveness, both lines should be possible - if (!lines[1].isEmpty()) { - lootTable = plugin.getCaliburn().getLootTable(lines[1]); + if (!getLine(1).isEmpty()) { + lootTable = api.getCaliburn().getLootTable(getLine(1)); } - if (!lines[2].isEmpty()) { - lootTable = plugin.getCaliburn().getLootTable(lines[2]); + if (!getLine(2).isEmpty()) { + lootTable = api.getCaliburn().getLootTable(getLine(2)); } checkChest(); if (chest != null) { - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); + setToAir(); } else { getSign().getBlock().setType(VanillaItem.CHEST.getMaterial()); chest = getSign().getBlock(); diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/passive/FlagSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/FlagSign.java new file mode 100644 index 00000000..f9d51897 --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/FlagSign.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.passive; + +import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Passive; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DGroup; +import de.erethon.dungeonsxl.player.DPermission; +import de.erethon.dungeonsxl.world.DGameWorld; +import de.erethon.dungeonsxl.world.block.TeamFlag; +import org.bukkit.block.Sign; + +/** + * @author Daniel Saukel + */ +public class FlagSign extends Passive { + + private int team; + + public FlagSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + @Override + public String getName() { + return "Flag"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".flag"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + return NumberUtil.parseInt(getLine(1), -1) != -1; + } + + @Override + public void initialize() { + this.team = NumberUtil.parseInt(getLine(1)); + if (getGame().getGroups().size() > team) { + ((DGameWorld) getGameWorld()).addGameBlock(new TeamFlag(api, getSign().getBlock(), (DGroup) getGame().getGroups().get(team))); + } + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/message/HologramSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/HologramSign.java similarity index 63% rename from core/src/main/java/de/erethon/dungeonsxl/sign/message/HologramSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/passive/HologramSign.java index 1191f37b..d765abb3 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/message/HologramSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/HologramSign.java @@ -14,18 +14,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign.message; +package de.erethon.dungeonsxl.sign.passive; import com.gmail.filoghost.holographicdisplays.api.Hologram; import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; import de.erethon.caliburn.item.ExItem; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.sign.DSign; -import de.erethon.dungeonsxl.sign.DSignType; -import de.erethon.dungeonsxl.sign.DSignTypeDefault; -import de.erethon.dungeonsxl.world.DGameWorld; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Passive; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -35,38 +34,63 @@ import org.bukkit.inventory.ItemStack; /** * @author Daniel Saukel */ -public class HologramSign extends DSign { +public class HologramSign extends Passive { private Hologram hologram; - public HologramSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + public HologramSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } @Override - public boolean check() { + public String getName() { + return "Hologram"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".hologram"; + } + + @Override + public boolean isOnDungeonInit() { return true; } @Override - public void onInit() { + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return false; + } + + @Override + public boolean validate() { if (Bukkit.getPluginManager().getPlugin("HolographicDisplays") == null) { markAsErroneous("HolographicDisplays not enabled"); - return; + return false; } + return true; + } + + @Override + public void initialize() { getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); - String[] holoLines = lines[1].split("/"); + String[] holoLines = getLine(1).split("/"); Location location = getSign().getLocation(); - location = location.add(0.5, NumberUtil.parseDouble(lines[2]), 0.5); + location = location.add(0.5, NumberUtil.parseDouble(getLine(2)), 0.5); - hologram = HologramsAPI.createHologram(plugin, location); + hologram = HologramsAPI.createHologram(api, location); for (String line : holoLines) { if (line.startsWith("Item:")) { String id = line.replace("Item:", ""); ItemStack item = null; - ExItem exItem = plugin.getCaliburn().getExItem(id); + ExItem exItem = api.getCaliburn().getExItem(id); if (exItem != null) { item = exItem.toItemStack(); } @@ -79,9 +103,4 @@ public class HologramSign extends DSign { } } - @Override - public DSignType getType() { - return DSignTypeDefault.HOLOGRAM; - } - } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/InteractSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/InteractSign.java similarity index 59% rename from core/src/main/java/de/erethon/dungeonsxl/sign/InteractSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/passive/InteractSign.java index df387fde..8366d386 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/InteractSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/InteractSign.java @@ -14,51 +14,68 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.passive; import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.DungeonSign; +import de.erethon.dungeonsxl.api.sign.Passive; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import de.erethon.dungeonsxl.sign.SignUpdateTask; import de.erethon.dungeonsxl.trigger.InteractTrigger; -import de.erethon.dungeonsxl.world.DEditWorld; import de.erethon.dungeonsxl.world.DGameWorld; import java.util.HashSet; import java.util.Set; import org.bukkit.ChatColor; -import org.bukkit.block.Block; import org.bukkit.block.Sign; -import org.bukkit.entity.Player; /** * @author Milan Albrecht, Daniel Saukel */ -public class InteractSign extends DSign { +public class InteractSign extends Passive { - public InteractSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + private int id = 1; + + public InteractSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } @Override - public boolean check() { + public String getName() { + return "Interact"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".interact"; + } + + @Override + public boolean isOnDungeonInit() { + return true; + } + + @Override + public boolean isProtected() { + return true; + } + + @Override + public boolean isSetToAir() { + return false; + } + + @Override + public boolean validate() { Set used = new HashSet<>(); - for (Block block : DEditWorld.getByWorld(getSign().getLocation().getWorld()).getSigns()) { - if (block == null) { - continue; - } - - if (!block.getChunk().isLoaded()) { - block.getChunk().load(); - } - - if (block.getState() instanceof Sign) { - Sign rsign = (Sign) block.getState(); - if (rsign.getLine(0).equalsIgnoreCase("[" + getType().getName() + "]")) { - used.add(NumberUtil.parseInt(rsign.getLine(1))); - } + for (DungeonSign dSign : getEditWorld().getDungeonSigns()) { + if (dSign instanceof InteractSign) { + used.add(((InteractSign) dSign).id); } } - int id = 1; - if (getSign().getLine(1).isEmpty()) { + if (getLine(1).isEmpty()) { if (!used.isEmpty()) { while (used.contains(id)) { id++; @@ -69,22 +86,21 @@ public class InteractSign extends DSign { id = NumberUtil.parseInt(getSign().getLine(1)); if (id == 0 || used.contains(id)) { return false; - } else { return true; } } - getSign().setLine(1, id + ""); + getSign().setLine(1, String.valueOf(id)); - new SignUpdateTask(getSign()).runTaskLater(plugin, 2L); + new SignUpdateTask(getSign()).runTaskLater(api, 2L); return true; } @Override - public void onInit() { - InteractTrigger trigger = InteractTrigger.getOrCreate(NumberUtil.parseInt(getSign().getLine(1)), getSign().getBlock(), getGameWorld()); + public void initialize() { + InteractTrigger trigger = InteractTrigger.getOrCreate(NumberUtil.parseInt(getSign().getLine(1)), getSign().getBlock(), (DGameWorld) getGameWorld()); if (trigger != null) { trigger.addListener(this); addTrigger(trigger); @@ -97,14 +113,4 @@ public class InteractSign extends DSign { getSign().update(); } - @Override - public boolean onPlayerTrigger(Player player) { - return true; - } - - @Override - public DSignType getType() { - return DSignTypeDefault.INTERACT; - } - } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/passive/LobbySign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/LobbySign.java new file mode 100644 index 00000000..6d36eafd --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/LobbySign.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.passive; + +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Passive; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import de.erethon.dungeonsxl.sign.LocationSign; +import org.bukkit.Location; +import org.bukkit.block.Sign; + +/** + * @author Frank Baumann, Daniel Saukel + */ +public class LobbySign extends Passive implements LocationSign { + + private Location location; + + public LobbySign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + @Override + public Location getLocation() { + return location; + } + + @Override + public void setLocation(Location location) { + this.location = location; + } + + @Override + public String getName() { + return "Lobby"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".lobby"; + } + + @Override + public boolean isOnDungeonInit() { + return true; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { + LocationSign.super.initialize(); + getGameWorld().setLobbyLocation(getLocation()); + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/passive/NoteSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/NoteSign.java new file mode 100644 index 00000000..9a61d049 --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/NoteSign.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.passive; + +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Passive; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import org.bukkit.block.Sign; + +/** + * @author Daniel Saukel + */ +public class NoteSign extends Passive { + + public NoteSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + @Override + public String getName() { + return "Interact"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".note"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/passive/PlaceSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/PlaceSign.java new file mode 100644 index 00000000..ef0b3276 --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/PlaceSign.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.passive; + +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Passive; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import de.erethon.dungeonsxl.world.DGameWorld; +import de.erethon.dungeonsxl.world.block.PlaceableBlock; +import org.bukkit.block.Sign; + +/** + * @author Frank Baumann, Daniel Saukel + */ +public class PlaceSign extends Passive { + + public PlaceSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + @Override + public String getName() { + return "Place"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".place"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { + ((DGameWorld) getGameWorld()).addGameBlock(new PlaceableBlock(api, (DGameWorld) getGameWorld(), getSign().getBlock(), getLine(1), getLine(2))); + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/passive/ProtectionSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/ProtectionSign.java new file mode 100644 index 00000000..8126e647 --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/ProtectionSign.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.passive; + +import de.erethon.commons.misc.BlockUtil; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Passive; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import de.erethon.dungeonsxl.world.DGameWorld; +import de.erethon.dungeonsxl.world.block.ProtectedBlock; +import org.bukkit.block.Sign; + +/** + * @author Daniel Saukel + */ +public class ProtectionSign extends Passive { + + public ProtectionSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + @Override + public String getName() { + return "Protection"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".protection"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { + ((DGameWorld) getGameWorld()).addGameBlock(new ProtectedBlock(api, BlockUtil.getAttachedBlock(getSign().getBlock()))); + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/RewardChestSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/RewardChestSign.java similarity index 71% rename from core/src/main/java/de/erethon/dungeonsxl/sign/RewardChestSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/passive/RewardChestSign.java index fbaff2eb..aef20675 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/RewardChestSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/RewardChestSign.java @@ -14,11 +14,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.passive; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.block.RewardChest; import java.util.Arrays; @@ -34,54 +37,40 @@ public class RewardChestSign extends ChestSign { private double moneyReward; private int levelReward; - public RewardChestSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + public RewardChestSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } - /* Getters and setters */ - /** - * @return the money reward - */ public double getMoneyReward() { return moneyReward; } - /** - * @param amount the amount to set - */ public void setMoneyReward(double amount) { moneyReward = amount; } - /** - * @return the level reward - */ public int getLevelReward() { return levelReward; } - /** - * @param amount the amount to set - */ public void setLevelReward(int amount) { levelReward = amount; } @Override - public DSignType getType() { - return DSignTypeDefault.REWARD_CHEST; - } - - /* Actions */ - @Override - public boolean check() { - return true; + public String getName() { + return "RewardChest"; } @Override - public void onInit() { - if (!lines[1].isEmpty()) { - String[] attributes = lines[1].split(","); + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".rewardchest"; + } + + @Override + public void initialize() { + if (!getLine(1).isEmpty()) { + String[] attributes = getLine(1).split(","); if (attributes.length >= 1) { moneyReward = NumberUtil.parseDouble(attributes[0]); } @@ -90,13 +79,13 @@ public class RewardChestSign extends ChestSign { } } - if (!lines[2].isEmpty()) { - lootTable = plugin.getCaliburn().getLootTable(lines[2]); + if (!getLine(2).isEmpty()) { + lootTable = api.getCaliburn().getLootTable(getLine(2)); } checkChest(); if (chest != null) { - getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); + setToAir(); } else { getSign().getBlock().setType(VanillaItem.CHEST.getMaterial()); chest = getSign().getBlock(); @@ -117,7 +106,7 @@ public class RewardChestSign extends ChestSign { return; } - getGameWorld().addGameBlock(new RewardChest(plugin, chest, moneyReward, levelReward, list.toArray(new ItemStack[list.size()]))); + ((DGameWorld) getGameWorld()).addGameBlock(new RewardChest((DungeonsXL) api, chest, moneyReward, levelReward, list.toArray(new ItemStack[list.size()]))); } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/passive/ScriptSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/ScriptSign.java new file mode 100644 index 00000000..105d6a5c --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/ScriptSign.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.passive; + +import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.DungeonSign; +import de.erethon.dungeonsxl.api.sign.Passive; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import org.bukkit.block.Sign; + +/** + * @author Daniel Saukel + */ +public class ScriptSign extends Passive { + + private String scriptName; + + public ScriptSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + scriptName = lines[1]; + } + + public String getScriptName() { + return scriptName; + } + + public void setScriptName(String name) { + scriptName = name; + } + + @Override + public String getName() { + return "Script"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".script"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return false; + } + + @Override + public boolean validate() { + return ((DungeonsXL) api).getSignScriptRegistry().get(scriptName) != null; + } + + @Override + public void initialize() { + SignScript script = ((DungeonsXL) api).getSignScriptRegistry().get(scriptName); + for (String[] lines : script.getSigns()) { + DungeonSign dSign = getGameWorld().createDungeonSign(getSign(), lines); + if (dSign.isErroneous()) { + getGameWorld().removeDungeonSign(dSign); + continue; + } + + dSign.initialize(); + if (!dSign.hasTriggers()) { + dSign.trigger(null); + } + } + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/SignScript.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/SignScript.java similarity index 98% rename from core/src/main/java/de/erethon/dungeonsxl/sign/SignScript.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/passive/SignScript.java index 38abcf4a..ddfb756f 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/SignScript.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/SignScript.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.passive; import de.erethon.commons.chat.MessageUtil; import java.io.File; diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/passive/StartSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/StartSign.java new file mode 100644 index 00000000..ef668577 --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/StartSign.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.passive; + +import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Passive; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import de.erethon.dungeonsxl.sign.LocationSign; +import org.bukkit.Location; +import org.bukkit.block.Sign; + +/** + * @author Frank Baumann, Daniel Saukel + */ +public class StartSign extends Passive implements LocationSign { + + private Location location; + private int id; + + public StartSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Override + public Location getLocation() { + return location; + } + + @Override + public void setLocation(Location location) { + this.location = location; + } + + @Override + public String getName() { + return "Start"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".start"; + } + + @Override + public boolean isOnDungeonInit() { + return true; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { + LocationSign.super.initialize(); + id = NumberUtil.parseInt(getLine(1)); + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/rocker/BlockSign.java similarity index 56% rename from core/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/rocker/BlockSign.java index 567de02a..68f2e1fc 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/rocker/BlockSign.java @@ -14,48 +14,72 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.rocker; import de.erethon.caliburn.item.ExItem; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Rocker; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.util.MagicValueUtil; -import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.block.Sign; /** * @author Milan Albrecht, Daniel Saukel */ -public class BlockSign extends DSign { +public class BlockSign extends Rocker { - // Variables - private boolean initialized; - private boolean active; private ExItem offBlock = VanillaItem.AIR; private ExItem onBlock = VanillaItem.AIR; private byte offBlockData = 0x0; private byte onBlockData = 0x0; - public BlockSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + public BlockSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } @Override - public boolean check() { + public String getName() { + return "Block"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".block"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { return true; } @Override - public void onInit() { - if (lines[1].isEmpty()) { + public boolean isSetToAir() { + return false; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { + if (getLine(1).isEmpty()) { offBlock = VanillaItem.AIR; } else { - String[] line1 = lines[1].split(","); - offBlock = plugin.getCaliburn().getExItem(line1[0]); + String[] line1 = getLine(1).split(","); + offBlock = api.getCaliburn().getExItem(line1[0]); if (offBlock == null) { - markAsErroneous("Could not recognize offBlock, input: " + lines[1]); + markAsErroneous("Could not recognize offBlock, input: " + getLine(1)); return; } if (line1.length > 1) { @@ -63,14 +87,14 @@ public class BlockSign extends DSign { } } - if (lines[2].isEmpty()) { + if (getLine(2).isEmpty()) { onBlock = VanillaItem.AIR; } else { - String[] line2 = lines[2].split(","); - onBlock = plugin.getCaliburn().getExItem(line2[0]); + String[] line2 = getLine(2).split(","); + onBlock = api.getCaliburn().getExItem(line2[0]); if (onBlock == null) { - markAsErroneous("Could not recognize onBlock, input: " + lines[2]); + markAsErroneous("Could not recognize onBlock, input: " + getLine(2)); return; } if (line2.length > 1) { @@ -83,37 +107,26 @@ public class BlockSign extends DSign { MagicValueUtil.setBlockData(getSign().getBlock(), offBlockData); } catch (IllegalArgumentException exception) { markAsErroneous("offBlock data value " + offBlockData + " cannot be applied to given type " + offBlock.getId()); + } + } + + @Override + public void activate() { + getSign().getBlock().setType(onBlock.getMaterial()); + try { + MagicValueUtil.setBlockData(getSign().getBlock(), onBlockData); + } catch (IllegalArgumentException exception) { + markAsErroneous("onBlock data value " + onBlockData + " cannot be applied to given type " + onBlock.getId()); return; } - initialized = true; + active = true; } @Override - public void onTrigger() { - if (initialized && !active) { - getSign().getBlock().setType(onBlock.getMaterial()); - try { - MagicValueUtil.setBlockData(getSign().getBlock(), onBlockData); - } catch (IllegalArgumentException exception) { - markAsErroneous("onBlock data value " + onBlockData + " cannot be applied to given type " + onBlock.getId()); - return; - } - active = true; - } - } - - @Override - public void onDisable() { - if (initialized && active) { - getSign().getBlock().setType(offBlock.getMaterial()); - MagicValueUtil.setBlockData(getSign().getBlock(), offBlockData); - active = false; - } - } - - @Override - public DSignType getType() { - return DSignTypeDefault.BLOCK; + public void deactivate() { + getSign().getBlock().setType(offBlock.getMaterial()); + MagicValueUtil.setBlockData(getSign().getBlock(), offBlockData); + active = false; } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/OpenDoorSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/rocker/OpenDoorSign.java similarity index 58% rename from core/src/main/java/de/erethon/dungeonsxl/sign/OpenDoorSign.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/rocker/OpenDoorSign.java index 36eedb96..ffb3c2d4 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/OpenDoorSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/rocker/OpenDoorSign.java @@ -14,12 +14,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.rocker; import de.erethon.caliburn.category.Category; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.BlockUtil; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Rocker; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.block.LockedDoor; import org.bukkit.block.Block; @@ -29,65 +32,62 @@ import org.bukkit.block.Sign; /** * @author Daniel Saukel */ -public class OpenDoorSign extends DSign { +public class OpenDoorSign extends Rocker { private LockedDoor door; - private boolean active = true; - public OpenDoorSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) { - super(plugin, sign, lines, gameWorld); + public OpenDoorSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); } - /* Getters and setters */ - /** - * @return the door to open; - */ public LockedDoor getDoor() { return door; } - /** - * @param door the door to open - */ public void setDoor(LockedDoor door) { this.door = door; } - /** - * @return if the sign is active - */ - public boolean isActive() { - return active; - } - - /** - * @param active toggle the sign active - */ - public void setActive(boolean active) { - this.active = active; + @Override + public String getName() { + return "Door"; } @Override - public DSignType getType() { - return DSignTypeDefault.OPEN_DOOR; + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".door"; } - /* Actions */ @Override - public boolean check() { + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { return true; } @Override - public void onInit() { + public boolean validate() { + return true; + } + + @Override + public void initialize() { Block block = BlockUtil.getAttachedBlock(getSign().getBlock()); if (Category.DOORS.containsBlock(block)) { if (block.getRelative(BlockFace.DOWN).getType() == block.getType()) { - door = new LockedDoor(plugin, block.getRelative(BlockFace.DOWN)); + door = new LockedDoor(api, block.getRelative(BlockFace.DOWN)); } else { - door = new LockedDoor(plugin, block); + door = new LockedDoor(api, block); } - getGameWorld().addGameBlock(door); + ((DGameWorld) getGameWorld()).addGameBlock(door); getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); @@ -97,9 +97,17 @@ public class OpenDoorSign extends DSign { } @Override - public void onTrigger() { - if (door != null && active) { + public void activate() { + if (door != null) { door.open(); + active = true; + } + } + + @Override + public void deactivate() { + if (door != null) { + door.close(); active = false; } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/rocker/TriggerSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/rocker/TriggerSign.java new file mode 100644 index 00000000..191dccdd --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/rocker/TriggerSign.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.rocker; + +import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.DungeonSign; +import de.erethon.dungeonsxl.api.sign.Rocker; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import de.erethon.dungeonsxl.sign.SignUpdateTask; +import de.erethon.dungeonsxl.trigger.SignTrigger; +import de.erethon.dungeonsxl.world.DGameWorld; +import java.util.HashSet; +import java.util.Set; +import org.bukkit.block.Sign; + +/** + * @author Frank Baumann, Milan Albrecht, Daniel Saukel + */ +public class TriggerSign extends Rocker { + + private int id = 1; + + public TriggerSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + @Override + public String getName() { + return "Trigger"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".trigger"; + } + + @Override + public boolean isOnDungeonInit() { + return true; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + Set used = new HashSet<>(); + for (DungeonSign dSign : getEditWorld().getDungeonSigns()) { + if (dSign instanceof TriggerSign) { + used.add(((TriggerSign) dSign).id); + } + } + + if (getLine(1).isEmpty()) { + if (!used.isEmpty()) { + while (used.contains(id)) { + id++; + } + } + + } else { + id = NumberUtil.parseInt(getSign().getLine(1)); + if (id == 0 || used.contains(id)) { + return false; + } else { + return true; + } + } + + getSign().setLine(1, String.valueOf(id)); + + new SignUpdateTask(getSign()).runTaskLater(api, 2L); + + return true; + } + + @Override + public void initialize() { + } + + @Override + public void activate() { + SignTrigger trigger = SignTrigger.getById(id, (DGameWorld) getGameWorld()); + if (trigger != null) { + trigger.onTrigger(true); + } + } + + @Override + public void deactivate() { + SignTrigger trigger = SignTrigger.getById(id, (DGameWorld) getGameWorld()); + if (trigger != null) { + trigger.onTrigger(false); + } + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/DropSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/DropSign.java new file mode 100644 index 00000000..5b05147e --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/DropSign.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.windup; + +import de.erethon.caliburn.item.ExItem; +import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Windup; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import org.bukkit.Location; +import org.bukkit.block.Sign; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; + +/** + * @author Frank Baumann, Milan Albrecht, Daniel Saukel + */ +public class DropSign extends Windup { + + private ItemStack item; + private Location spawnLocation; + + public DropSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + public ItemStack getItem() { + return item; + } + + public void setItem(ItemStack item) { + this.item = item; + } + + @Override + public String getName() { + return "Drop"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".drop"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + return api.getCaliburn().getExItem(getLine(1)) != null; + } + + @Override + public void initialize() { + ExItem item = api.getCaliburn().getExItem(getLine(1)); + + String[] attributes = getLine(2).split(","); + if (attributes.length >= 1) { + this.item = item.toItemStack(NumberUtil.parseInt(attributes[0], 1)); + } + if (attributes.length == 2) { + interval = NumberUtil.parseDouble(attributes[1]); + } + + spawnLocation = getSign().getLocation().add(0.5, 0, 0.5); + setRunnable(new BukkitRunnable() { + @Override + public void run() { + try { + spawnLocation.getWorld().dropItem(spawnLocation, getItem()); + } catch (NullPointerException exception) { + cancel(); + } + } + }); + } + + @Override + public void activate() { + if (interval < 0) { + active = true; + getRunnable().run(); + } else { + super.activate(); + } + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSign.java new file mode 100644 index 00000000..22abac1f --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSign.java @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.windup; + +import de.erethon.caliburn.mob.ExMob; +import de.erethon.commons.misc.NumberUtil; +import de.erethon.commons.misc.Registry; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.mob.ExternalMobProvider; +import de.erethon.dungeonsxl.api.sign.Windup; +import de.erethon.dungeonsxl.player.DPermission; +import de.erethon.dungeonsxl.world.DGameWorld; +import java.util.ArrayList; +import java.util.Collection; +import org.bukkit.Location; +import org.bukkit.block.Sign; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + +/** + * @author Frank Baumann, Milan Albrecht, Daniel Saukel + */ +public class MobSign extends Windup { + + private Registry providers; + + private String mob; + private ExternalMobProvider provider; + private Collection spawnedMobs = new ArrayList<>(); + private int initialAmount; + + public MobSign(DungeonsAPI api, Sign sign, String[] lines, DGameWorld gameWorld) { + super(api, sign, lines, gameWorld); + providers = api.getExternalMobProviderRegistry(); + } + + public String getMob() { + return mob; + } + + public void setMob(String mob) { + this.mob = mob; + } + + /** + * Returns the initial amount of mobs to spawn - this value may increase with waves. + * + * @return the initial amount of mobs to spawn - this value may increase with waves + */ + public int getInitialAmount() { + return initialAmount; + } + + public Collection getSpawnedMobs() { + return spawnedMobs; + } + + @Override + public String getName() { + return "Mob"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".mob"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + if (getLine(1).isEmpty() || getLine(2).isEmpty()) { + return false; + } + + String[] attributes = getLine(2).split(","); + if (attributes.length == 2 || attributes.length == 3) { + return true; + + } else { + return false; + } + } + + @Override + public void initialize() { + mob = getLine(1); + String[] attributes = getLine(2).split(","); + + interval = NumberUtil.parseDouble(attributes[0]); + n = NumberUtil.parseInt(attributes[1]); + initialAmount = n; + provider = attributes.length == 3 ? providers.get(attributes[2]) : null; + } + + /** + * Spawns the mob. + * + * @return the spawned mob + */ + public LivingEntity spawn() { + Location spawnLoc = getSign().getLocation().add(0.5, 0, 0.5); + LivingEntity spawned = null; + + if (provider == null) { + ExMob type = api.getCaliburn().getExMob(mob); + if (type == null || !type.getSpecies().isAlive()) { + return null; + } + spawned = (LivingEntity) type.toEntity(spawnLoc); + spawned.setRemoveWhenFarAway(false); + + } else { + provider.summon(mob, spawnLoc); + for (Entity entity : spawnLoc.getChunk().getEntities()) { + Location entityLoc = entity.getLocation(); + if (entityLoc.getX() >= spawnLoc.getX() - 1 && entityLoc.getX() <= spawnLoc.getX() + 1 && entityLoc.getY() >= spawnLoc.getY() - 1 + && entityLoc.getY() <= spawnLoc.getY() + 1 && entityLoc.getZ() >= spawnLoc.getZ() - 1 && entityLoc.getZ() <= spawnLoc.getZ() + 1 + && entity instanceof LivingEntity && !spawnedMobs.contains((LivingEntity) entity) && !(entity instanceof Player)) { + spawned = (LivingEntity) entity; + } + } + } + + spawnedMobs.add(spawned); + return spawned; + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/MobSpawnTask.java b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSpawnTask.java similarity index 52% rename from core/src/main/java/de/erethon/dungeonsxl/sign/MobSpawnTask.java rename to core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSpawnTask.java index 6fb7aa2a..9feb7ae2 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/MobSpawnTask.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSpawnTask.java @@ -14,11 +14,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.erethon.dungeonsxl.sign; +package de.erethon.dungeonsxl.sign.windup; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.world.GameWorld; import de.erethon.dungeonsxl.mob.DMob; -import de.erethon.dungeonsxl.world.DGameWorld; -import org.bukkit.World; import org.bukkit.entity.LivingEntity; import org.bukkit.scheduler.BukkitRunnable; @@ -28,39 +28,32 @@ import org.bukkit.scheduler.BukkitRunnable; public class MobSpawnTask extends BukkitRunnable { private MobSign sign; + private int k, n; + private GameWorld gameWorld; - public MobSpawnTask(MobSign sign) { + public MobSpawnTask(DungeonsAPI api, MobSign sign, int n) { this.sign = sign; + gameWorld = sign.getGameWorld(); + this.n = n; } @Override public void run() { - if (sign.getInterval() <= 0) { - World world = sign.getSign().getWorld(); - DGameWorld gameWorld = DGameWorld.getByWorld(world); - if (gameWorld == null) { - sign.killTask(); - return; - } - - LivingEntity entity = sign.spawn(); - if (entity != null) { - new DMob(entity, sign.getGameWorld(), sign.getMob()); - } - - if (sign.getAmount() != -1) { - if (sign.getAmount() > 1) { - sign.setAmount(sign.getAmount() - 1); - - } else { - sign.killTask(); - } - } - - sign.setInterval(sign.getMaxInterval()); + if (gameWorld == null) { + cancel(); + return; } - sign.setInterval(sign.getInterval() - 1); + LivingEntity entity = sign.spawn(); + if (entity != null) { + new DMob(entity, sign.getGameWorld(), sign.getMob()); + } + + if (k < n) { + k++; + } else { + cancel(); + } } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/RedstoneSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/RedstoneSign.java new file mode 100644 index 00000000..1a8bd488 --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/RedstoneSign.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2012-2020 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.sign.windup; + +import de.erethon.caliburn.item.VanillaItem; +import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.api.DungeonsAPI; +import de.erethon.dungeonsxl.api.sign.Windup; +import de.erethon.dungeonsxl.api.world.InstanceWorld; +import de.erethon.dungeonsxl.player.DPermission; +import org.bukkit.block.Sign; +import org.bukkit.scheduler.BukkitRunnable; + +/** + * @author Frank Baumann, Daniel Saukel + */ +public class RedstoneSign extends Windup { + + public RedstoneSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) { + super(api, sign, lines, instance); + } + + @Override + public String getName() { + return "Redstone"; + } + + @Override + public String getBuildPermission() { + return DPermission.SIGN.getNode() + ".redstone"; + } + + @Override + public boolean isOnDungeonInit() { + return false; + } + + @Override + public boolean isProtected() { + return false; + } + + @Override + public boolean isSetToAir() { + return true; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public void initialize() { + interval = NumberUtil.parseDouble(getLine(1), 0); + n = NumberUtil.parseInt(getLine(2), -1); + setRunnable(new BukkitRunnable() { + @Override + public void run() { + if (getGameWorld() == null) { + cancel(); + return; + } + power(!isPowered()); + if (k < n) { + k++; + } else { + cancel(); + } + } + }); + } + + @Override + public void activate() { + if (active) { + return; + } + + if (delay > 0) { + startTask(); + } else { + power(true); + } + + active = true; + } + + public boolean isPowered() { + return getSign().getBlock().getType() == VanillaItem.REDSTONE_BLOCK.getMaterial(); + } + + public void power(boolean power) { + getSign().getBlock().setType((power ? VanillaItem.REDSTONE_BLOCK : VanillaItem.AIR).getMaterial()); + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/trigger/Trigger.java b/core/src/main/java/de/erethon/dungeonsxl/trigger/Trigger.java index 142a4492..8fb23bde 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/trigger/Trigger.java +++ b/core/src/main/java/de/erethon/dungeonsxl/trigger/Trigger.java @@ -19,8 +19,8 @@ package de.erethon.dungeonsxl.trigger; import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.misc.NumberUtil; import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.sign.DungeonSign; import de.erethon.dungeonsxl.event.trigger.TriggerRegistrationEvent; -import de.erethon.dungeonsxl.sign.DSign; import de.erethon.dungeonsxl.world.DGameWorld; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -39,7 +39,7 @@ public abstract class Trigger implements de.erethon.dungeonsxl.api.Trigger { private boolean triggered; private Player player; // Holds Player for Player specific TriggerTypes - private Set dSigns = new HashSet<>(); + private Set dSigns = new HashSet<>(); /** * @return the triggered @@ -72,41 +72,41 @@ public abstract class Trigger implements de.erethon.dungeonsxl.api.Trigger { /** * @return the dSigns */ - public Set getDSigns() { + public Set getDSigns() { return dSigns; } /** * @param dSign the dSign to add */ - public void addDSign(DSign dSign) { + public void addDSign(DungeonSign dSign) { dSigns.add(dSign); } /** * @param dSign the dSign to remove */ - public void removeDSign(DSign dSign) { + public void removeDSign(DungeonSign dSign) { dSigns.remove(dSign); } - public void addListener(DSign dSign) { + public void addListener(DungeonSign dSign) { if (dSigns.isEmpty()) { - register(dSign.getGameWorld()); + register((DGameWorld) dSign.getGameWorld()); } dSigns.add(dSign); } - public void removeListener(DSign dSign) { + public void removeListener(DungeonSign dSign) { dSigns.remove(dSign); if (dSigns.isEmpty()) { - unregister(dSign.getGameWorld()); + unregister((DGameWorld) dSign.getGameWorld()); } } public void updateDSigns() { - for (DSign dSign : dSigns.toArray(new DSign[dSigns.size()])) { - dSign.onUpdate(); + for (DungeonSign dSign : dSigns.toArray(new DungeonSign[dSigns.size()])) { + dSign.update(); } } @@ -118,13 +118,14 @@ public abstract class Trigger implements de.erethon.dungeonsxl.api.Trigger { gameWorld.removeTrigger(this); } - public static Trigger getOrCreate(DungeonsXL plugin, String identifier, String value, DSign dSign) { + public static Trigger getOrCreate(DungeonsXL plugin, String identifier, String value, DungeonSign dSign) { TriggerType type = plugin.getTriggerCache().getByIdentifier(identifier); + DGameWorld gameWorld = (DGameWorld) dSign.getGameWorld(); Trigger trigger = null; if (type == TriggerTypeDefault.REDSTONE) { - trigger = RedstoneTrigger.getOrCreate(dSign.getSign(), dSign.getGameWorld()); + trigger = RedstoneTrigger.getOrCreate(dSign.getSign(), gameWorld); } else if (type == TriggerTypeDefault.DISTANCE) { @@ -144,19 +145,19 @@ public abstract class Trigger implements de.erethon.dungeonsxl.api.Trigger { } else if (type == TriggerTypeDefault.SIGN) { if (value != null) { - trigger = SignTrigger.getOrCreate(NumberUtil.parseInt(value), dSign.getGameWorld()); + trigger = SignTrigger.getOrCreate(NumberUtil.parseInt(value), gameWorld); } } else if (type == TriggerTypeDefault.INTERACT) { if (value != null) { - trigger = InteractTrigger.getOrCreate(NumberUtil.parseInt(value), dSign.getGameWorld()); + trigger = InteractTrigger.getOrCreate(NumberUtil.parseInt(value), gameWorld); } } else if (type == TriggerTypeDefault.MOB) { if (value != null) { - trigger = MobTrigger.getOrCreate(value, dSign.getGameWorld()); + trigger = MobTrigger.getOrCreate(value, gameWorld); } } else if (type == TriggerTypeDefault.PROGRESS) { @@ -165,23 +166,23 @@ public abstract class Trigger implements de.erethon.dungeonsxl.api.Trigger { if (value.matches("[0-99]/[0-999]")) { int floorCount = NumberUtil.parseInt(value.split("/")[0]); int waveCount = NumberUtil.parseInt(value.split("/")[1]); - trigger = ProgressTrigger.getOrCreate(floorCount, waveCount, dSign.getGameWorld()); + trigger = ProgressTrigger.getOrCreate(floorCount, waveCount, gameWorld); } else { - trigger = ProgressTrigger.getOrCreate(plugin, value, dSign.getGameWorld()); + trigger = ProgressTrigger.getOrCreate(plugin, value, gameWorld); } } } else if (type == TriggerTypeDefault.USE_ITEM) { if (value != null) { - trigger = UseItemTrigger.getOrCreate(plugin, value, dSign.getGameWorld()); + trigger = UseItemTrigger.getOrCreate(plugin, value, gameWorld); } } else if (type == TriggerTypeDefault.WAVE) { if (value != null) { - trigger = WaveTrigger.getOrCreate(NumberUtil.parseDouble(value, 1), dSign.getGameWorld()); + trigger = WaveTrigger.getOrCreate(NumberUtil.parseDouble(value, 1), gameWorld); } } else if (type != null) { diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java b/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java index 362c00c0..6568d762 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java @@ -34,8 +34,8 @@ import de.erethon.dungeonsxl.dungeon.DGame; import de.erethon.dungeonsxl.event.gameworld.GameWorldStartGameEvent; import de.erethon.dungeonsxl.event.gameworld.GameWorldUnloadEvent; import de.erethon.dungeonsxl.sign.LocationSign; -import de.erethon.dungeonsxl.sign.MobSign; -import de.erethon.dungeonsxl.sign.lobby.StartSign; +import de.erethon.dungeonsxl.sign.passive.StartSign; +import de.erethon.dungeonsxl.sign.windup.MobSign; import de.erethon.dungeonsxl.trigger.FortuneTrigger; import de.erethon.dungeonsxl.trigger.ProgressTrigger; import de.erethon.dungeonsxl.trigger.RedstoneTrigger; @@ -61,7 +61,6 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.block.Sign; import org.bukkit.entity.Entity; import org.bukkit.entity.Hanging; import org.bukkit.entity.Player; @@ -79,6 +78,7 @@ public class DGameWorld extends DInstanceWorld implements GameWorld { private Type type = Type.DEFAULT; private boolean isPlaying = false; + private boolean classes = false; private List placedBlocks = new LinkedList<>(); @@ -90,7 +90,6 @@ public class DGameWorld extends DInstanceWorld implements GameWorld { private Set teamFlags = new HashSet<>(); private List secureObjects = new ArrayList<>(); - private List classesSigns = new ArrayList<>(); private List mobs = new ArrayList<>(); private List triggers = new ArrayList<>(); @@ -155,6 +154,16 @@ public class DGameWorld extends DInstanceWorld implements GameWorld { return getWorld().getSpawnLocation(); } + @Override + public boolean areClassesEnabled() { + return classes; + } + + @Override + public void setClassesEnabled(boolean enabled) { + classes = enabled; + } + /** * @return the placeableBlocks */ @@ -249,20 +258,6 @@ public class DGameWorld extends DInstanceWorld implements GameWorld { this.secureObjects = secureObjects; } - /** - * @return the classes signs - */ - public List getClassesSigns() { - return classesSigns; - } - - /** - * @param signs the classes signs to set - */ - public void setClasses(List signs) { - classesSigns = signs; - } - @Override public Collection getMobs() { return mobs; diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/DInstanceWorld.java b/core/src/main/java/de/erethon/dungeonsxl/world/DInstanceWorld.java index 0fd8daae..713cca1a 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/DInstanceWorld.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/DInstanceWorld.java @@ -20,6 +20,7 @@ import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.misc.Registry; import de.erethon.commons.player.PlayerUtil; import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.api.dungeon.GameRule; import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer; import de.erethon.dungeonsxl.api.player.InstancePlayer; @@ -27,6 +28,8 @@ import de.erethon.dungeonsxl.api.player.PlayerCache; import de.erethon.dungeonsxl.api.sign.DungeonSign; import de.erethon.dungeonsxl.api.world.InstanceWorld; import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -34,6 +37,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.Sign; /** * @author Daniel Saukel @@ -103,8 +107,20 @@ public abstract class DInstanceWorld implements InstanceWorld { } @Override - public void addDungeonSign(DungeonSign sign) { - signs.put(sign.getSign().getBlock(), sign); + public DungeonSign createDungeonSign(Sign sign, String[] lines) { + String type = lines[0].substring(1, lines[0].length() - 2); + try { + Class clss = plugin.getSignRegistry().get(type); + Constructor constructor = clss.getConstructor(DungeonsAPI.class, Sign.class, String[].class, InstanceWorld.class); + DungeonSign dSign = (DungeonSign) constructor.newInstance(plugin, sign, lines, this); + signs.put(sign.getBlock(), dSign); + return dSign; + } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException exception) { + MessageUtil.log(plugin, "&4Could not create a dungeon sign of the type \"" + type + + "\". A dungeon sign implementation needs a constructor with the types (DungeonsAPI, org.bukkit.block.Sign, String[], InstanceWorld)."); + return null; + } } @Override diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java b/core/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java index ed7f3004..846fa755 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java @@ -62,8 +62,7 @@ public class DResourceWorld implements ResourceWorld { config = new WorldConfig(plugin, configFile); } - File signDataFile = new File(folder, "DXLData.data"); - signData = new SignData(plugin, signDataFile); + signData = new SignData(new File(folder, "DXLData.data")); } public DResourceWorld(DungeonsXL plugin, File folder) { @@ -76,8 +75,7 @@ public class DResourceWorld implements ResourceWorld { config = new WorldConfig(plugin, configFile); } - File signDataFile = new File(folder, "DXLData.data"); - signData = new SignData(plugin, signDataFile); + signData = new SignData(new File(folder, "DXLData.data")); } /* Getters and setters */ diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/SignData.java b/core/src/main/java/de/erethon/dungeonsxl/world/SignData.java index 7b07cec1..b4602b08 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/SignData.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/SignData.java @@ -16,10 +16,8 @@ */ package de.erethon.dungeonsxl.world; -import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.api.sign.DungeonSign; import de.erethon.dungeonsxl.api.world.InstanceWorld; -import de.erethon.dungeonsxl.sign.DSign; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -37,13 +35,9 @@ import org.bukkit.block.Sign; */ public class SignData { - private DungeonsXL plugin; - private File file; - public SignData(DungeonsXL plugin, File file) { - this.plugin = plugin; - + public SignData(File file) { if (!file.exists()) { try { file.createNewFile(); @@ -55,9 +49,6 @@ public class SignData { this.file = file; } - /** - * @return the file - */ public File getFile() { return file; } @@ -83,9 +74,9 @@ public class SignData { Block block = instance.getWorld().getBlockAt(x, y, z); if (block.getState() instanceof Sign) { - instance.addDungeonSign(DSign.create(plugin, (Sign) block.getState(), instance)); Sign sign = (Sign) block.getState(); String[] lines = sign.getLines(); + instance.createDungeonSign(sign, lines); if (lines[0].equalsIgnoreCase("[lobby]")) { instance.setLobbyLocation(block.getLocation()); diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/block/GameBlock.java b/core/src/main/java/de/erethon/dungeonsxl/world/block/GameBlock.java index 617425a9..ba107ece 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/block/GameBlock.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/block/GameBlock.java @@ -16,7 +16,7 @@ */ package de.erethon.dungeonsxl.world.block; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; import org.bukkit.block.Block; import org.bukkit.event.block.BlockBreakEvent; @@ -27,12 +27,12 @@ import org.bukkit.event.block.BlockBreakEvent; */ public abstract class GameBlock { - protected DungeonsXL plugin; + protected DungeonsAPI api; protected Block block; - public GameBlock(DungeonsXL plugin, Block block) { - this.plugin = plugin; + public GameBlock(DungeonsAPI api, Block block) { + this.api = api; this.block = block; } diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/block/LockedDoor.java b/core/src/main/java/de/erethon/dungeonsxl/world/block/LockedDoor.java index 45cc0fc7..aeee52de 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/block/LockedDoor.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/block/LockedDoor.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.world.block; import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.event.block.BlockBreakEvent; @@ -30,8 +31,8 @@ public class LockedDoor extends GameBlock implements MultiBlock { private Block attachedBlock; - public LockedDoor(DungeonsXL plugin, Block block) { - super(plugin, block); + public LockedDoor(DungeonsAPI api, Block block) { + super(api, block); attachedBlock = getAttachedBlock(); } @@ -59,6 +60,13 @@ public class LockedDoor extends GameBlock implements MultiBlock { DungeonsXL.BLOCK_ADAPTER.openDoor(block); } + /** + * Closes the door. + */ + public void close() { + DungeonsXL.BLOCK_ADAPTER.closeDoor(block); + } + @Override public String toString() { return getClass().getSimpleName() + "{block=" + block + "; attachedBlock=" + attachedBlock + "}"; diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/block/PlaceableBlock.java b/core/src/main/java/de/erethon/dungeonsxl/world/block/PlaceableBlock.java index 14fac7e5..b0675cf4 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/block/PlaceableBlock.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/block/PlaceableBlock.java @@ -19,7 +19,7 @@ package de.erethon.dungeonsxl.world.block; import de.erethon.caliburn.item.ExItem; import de.erethon.commons.misc.BlockUtil; import de.erethon.commons.misc.NumberUtil; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.trigger.SignTrigger; import de.erethon.dungeonsxl.world.DGameWorld; import java.util.HashSet; @@ -39,13 +39,13 @@ public class PlaceableBlock extends GameBlock { private Set faces = new HashSet<>(); private int triggerId = -1; - public PlaceableBlock(DungeonsXL plugin, DGameWorld gameWorld, Block block, String ids, String args) { - super(plugin, block); + public PlaceableBlock(DungeonsAPI api, DGameWorld gameWorld, Block block, String ids, String args) { + super(api, block); this.gameWorld = gameWorld; for (String id : ids.split(",")) { - ExItem item = plugin.getCaliburn().getExItem(id); + ExItem item = api.getCaliburn().getExItem(id); if (item != null) { materials.add(item); } diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/block/ProtectedBlock.java b/core/src/main/java/de/erethon/dungeonsxl/world/block/ProtectedBlock.java index c0539dfc..9ce1d97e 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/block/ProtectedBlock.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/block/ProtectedBlock.java @@ -16,7 +16,7 @@ */ package de.erethon.dungeonsxl.world.block; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; import org.bukkit.block.Block; import org.bukkit.event.block.BlockBreakEvent; @@ -25,8 +25,8 @@ import org.bukkit.event.block.BlockBreakEvent; */ public class ProtectedBlock extends GameBlock { - public ProtectedBlock(DungeonsXL plugin, Block block) { - super(plugin, block); + public ProtectedBlock(DungeonsAPI api, Block block) { + super(api, block); } /* Actions */ diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/block/RewardChest.java b/core/src/main/java/de/erethon/dungeonsxl/world/block/RewardChest.java index f780337a..19af627b 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/block/RewardChest.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/block/RewardChest.java @@ -28,6 +28,7 @@ import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.reward.ItemReward; import de.erethon.dungeonsxl.reward.LevelReward; import de.erethon.dungeonsxl.reward.MoneyReward; +import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.block.Block; @@ -41,6 +42,8 @@ import org.bukkit.inventory.ItemStack; */ public class RewardChest extends GameBlock { + private Economy econ; + private boolean used = false; private Container container; private double moneyReward; @@ -49,6 +52,7 @@ public class RewardChest extends GameBlock { public RewardChest(DungeonsXL plugin, Block container, double moneyReward, int levelReward, ItemStack[] itemReward) { super(plugin, container); + econ = plugin.getEconomyProvider(); if (!(container.getState() instanceof Container)) { return; @@ -132,7 +136,7 @@ public class RewardChest extends GameBlock { } if (container.getLocation().distance(container.getLocation()) < 1) { - addTreasure(plugin.getPlayerGroup(opener)); + addTreasure(api.getPlayerGroup(opener)); used = true; } } @@ -165,7 +169,7 @@ public class RewardChest extends GameBlock { Game game = group.getGame(); if (game == null || game.hasRewards()) { if (!hasMoneyReward) { - MoneyReward reward = new MoneyReward(plugin); + MoneyReward reward = new MoneyReward(econ); reward.addMoney(moneyReward); group.addReward(reward); } @@ -177,14 +181,14 @@ public class RewardChest extends GameBlock { } if (!hasItemReward) { - ItemReward reward = new ItemReward(plugin); + ItemReward reward = new ItemReward(api); reward.addItems(itemReward); group.addReward(reward); } } for (Player player : group.getMembers().getOnlinePlayers()) { - DGamePlayer dPlayer = (DGamePlayer) plugin.getPlayerCache().getGamePlayer(player); + DGamePlayer dPlayer = (DGamePlayer) api.getPlayerCache().getGamePlayer(player); if (dPlayer == null || !dPlayer.canLoot(game.getRules())) { MessageUtil.sendMessage(player, DMessage.ERROR_NO_REWARDS_TIME.getMessage(SimpleDateUtil.ddMMyyyyhhmm(dPlayer.getTimeNextLoot(game.getRules())))); continue; @@ -215,8 +219,8 @@ public class RewardChest extends GameBlock { MessageUtil.sendMessage(player, DMessage.PLAYER_LOOT_ADDED.getMessage(msg)); } - if (moneyReward != 0 && plugin.getEconomyProvider() != null) { - MessageUtil.sendMessage(player, DMessage.PLAYER_LOOT_ADDED.getMessage(plugin.getEconomyProvider().format(moneyReward))); + if (moneyReward != 0 && econ != null) { + MessageUtil.sendMessage(player, DMessage.PLAYER_LOOT_ADDED.getMessage(econ.format(moneyReward))); } if (levelReward != 0) { diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/block/TeamBed.java b/core/src/main/java/de/erethon/dungeonsxl/world/block/TeamBed.java index 05e012e0..68053fb9 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/block/TeamBed.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/block/TeamBed.java @@ -20,6 +20,7 @@ import de.erethon.caliburn.category.Category; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGroup; @@ -35,8 +36,8 @@ public class TeamBed extends TeamBlock implements MultiBlock { private Block attachedBlock; - public TeamBed(DungeonsXL plugin, Block block, DGroup owner) { - super(plugin, block, owner); + public TeamBed(DungeonsAPI api, Block block, DGroup owner) { + super(api, block, owner); attachedBlock = getAttachedBlock(); } @@ -83,7 +84,7 @@ public class TeamBed extends TeamBlock implements MultiBlock { } owner.setLives(0); - owner.getGameWorld().sendMessage(DMessage.GROUP_BED_DESTROYED.getMessage(owner.getName(), plugin.getPlayerCache().getGamePlayer(breaker).getName())); + owner.getGameWorld().sendMessage(DMessage.GROUP_BED_DESTROYED.getMessage(owner.getName(), api.getPlayerCache().getGamePlayer(breaker).getName())); Block block1 = event.getBlock(); if (DungeonsXL.BLOCK_ADAPTER.isBedHead(block)) { Block block2 = getAttachedBlock(block1); diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/block/TeamBlock.java b/core/src/main/java/de/erethon/dungeonsxl/world/block/TeamBlock.java index edabb4e6..2c70fe13 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/block/TeamBlock.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/block/TeamBlock.java @@ -16,7 +16,7 @@ */ package de.erethon.dungeonsxl.world.block; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.player.DGroup; import org.bukkit.block.Block; @@ -27,8 +27,8 @@ public abstract class TeamBlock extends GameBlock { protected DGroup owner; - public TeamBlock(DungeonsXL plugin, Block block, DGroup owner) { - super(plugin, block); + public TeamBlock(DungeonsAPI api, Block block, DGroup owner) { + super(api, block); this.owner = owner; } diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/block/TeamFlag.java b/core/src/main/java/de/erethon/dungeonsxl/world/block/TeamFlag.java index 42be9ca9..52ab22b5 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/block/TeamFlag.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/block/TeamFlag.java @@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.world.block; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.chat.MessageUtil; import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.api.player.GamePlayer; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DGroup; @@ -31,8 +32,8 @@ import org.bukkit.event.block.BlockBreakEvent; */ public class TeamFlag extends TeamBlock { - public TeamFlag(DungeonsXL plugin, Block block, DGroup owner) { - super(plugin, block, owner); + public TeamFlag(DungeonsAPI api, Block block, DGroup owner) { + super(api, block, owner); reset(); } @@ -47,7 +48,7 @@ public class TeamFlag extends TeamBlock { @Override public boolean onBreak(BlockBreakEvent event) { Player breaker = event.getPlayer(); - GamePlayer gamePlayer = plugin.getPlayerCache().getGamePlayer(breaker); + GamePlayer gamePlayer = api.getPlayerCache().getGamePlayer(breaker); if (gamePlayer == null) { return true; }