diff --git a/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java b/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java index e9a26562..9e928cd2 100644 --- a/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java +++ b/src/io/github/dre2n/dungeonsxl/config/MessageConfig.java @@ -17,6 +17,7 @@ public class MessageConfig { GROUP_UNINVITED_PLAYER("Group_UninvitedPlayer", "&4&v1&6 took back the invitation for &4&v2&6 to the group &4&v3&6."), GROUP_KICKED_PLAYER("Group_KickedPlayer", "&4&v1&6 kicked the player &4&v2&6 from the group &4&v3&6."), GROUP_PLAYER_JOINED("Group_PlayerJoined", "&6Player &4&v1&6 has joined the group!"), + GROUP_WAVE_FINISHED("Group_WaveFinished", "&6Your group finished wave no. &4&v1&6. The next one is going to start in &4&v2&6 seconds."), LOG_ERROR_MOB_ENCHANTMENT("Log_Error_MobEnchantment", "&4Error at loading mob.yml: Enchantment &6&v1&4 doesn't exist!"), LOG_ERROR_MOBTYPE("Log_Error_MobType", "&4Error at loading mob.yml: Mob &6&v1&4 doesn't exist!"), diff --git a/src/io/github/dre2n/dungeonsxl/game/GameChest.java b/src/io/github/dre2n/dungeonsxl/game/GameChest.java index 6ef0ae4e..dc077748 100644 --- a/src/io/github/dre2n/dungeonsxl/game/GameChest.java +++ b/src/io/github/dre2n/dungeonsxl/game/GameChest.java @@ -169,6 +169,10 @@ public class GameChest { } // Statics + /** + * @param event + * event.getPlayer() has to be a Player + */ public static void onOpenInventory(InventoryOpenEvent event) { InventoryView inventory = event.getView(); @@ -196,7 +200,7 @@ public class GameChest { } if (gameChest.chest.getLocation().distance(chest.getLocation()) < 1) { - gameChest.addTreasure(DGroup.getByGameWorld(gameWorld)); + gameChest.addTreasure(DGroup.getByPlayer((Player) event.getPlayer())); gameChest.used = true; event.setCancelled(true); } diff --git a/src/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java b/src/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java index cf47c07c..e4bbfc01 100644 --- a/src/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java +++ b/src/io/github/dre2n/dungeonsxl/game/GameTypeDefault.java @@ -18,28 +18,23 @@ public enum GameTypeDefault implements GameType { QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", false, false, false, true, true, false, GameMode.SURVIVAL), TEST("Test", "Test", false, false, false, false, true, true, GameMode.SURVIVAL), TUTORIAL("Tutorial", "Tutorial", false, false, false, true, false, false, GameMode.SURVIVAL), - DEFAULT("Default", "Default"); + DEFAULT("Default", "Default", false, false, false, true, false, false, GameMode.SURVIVAL); private String displayName; private String signName; - private boolean playerVersusPlayer; - private boolean friendlyFire; - private boolean mobWaves; - private boolean rewards; - private boolean showTime; - private boolean build; - private GameMode gameMode; - - GameTypeDefault(String displayName, String signName) { - this.displayName = displayName; - this.signName = signName; - } + private boolean playerVersusPlayer;// TODO: Testing + private boolean friendlyFire;// TODO: Testing + private boolean mobWaves;// TODO: Implementing + private boolean rewards;// TODO: Testing + private boolean showTime;// TODO: Implementing + private boolean build;// TODO: Testing + private GameMode gameMode;// TODO: Testing GameTypeDefault(String displayName, String signName, boolean playerVersusPlayer, boolean friendlyFire, boolean mobWaves, boolean rewards, boolean showTime, boolean build, GameMode gameMode) { this.displayName = displayName; this.signName = signName; this.playerVersusPlayer = playerVersusPlayer; - this.setFriendlyFire(friendlyFire); + this.friendlyFire = friendlyFire; this.mobWaves = mobWaves; this.rewards = rewards; this.showTime = showTime; diff --git a/src/io/github/dre2n/dungeonsxl/game/GameWorld.java b/src/io/github/dre2n/dungeonsxl/game/GameWorld.java index df7fe1ea..8d0875e1 100644 --- a/src/io/github/dre2n/dungeonsxl/game/GameWorld.java +++ b/src/io/github/dre2n/dungeonsxl/game/GameWorld.java @@ -60,6 +60,7 @@ public class GameWorld { private CopyOnWriteArrayList signClass = new CopyOnWriteArrayList(); private CopyOnWriteArrayList dMobs = new CopyOnWriteArrayList(); + //TODO: Killed mobs private CopyOnWriteArrayList gameChests = new CopyOnWriteArrayList(); private CopyOnWriteArrayList dSigns = new CopyOnWriteArrayList(); private WorldConfig worldConfig; @@ -273,11 +274,19 @@ public class GameWorld { } /** - * @param dMobs - * the dMobs to set + * @param dMob + * the dMob to add */ - public void setDMobs(CopyOnWriteArrayList dMobs) { - this.dMobs = dMobs; + public void addDMob(DMob dMob) { + dMobs.add(dMob); + } + + /** + * @param dMob + * the dMob to remove + */ + public void removeDMob(DMob dMob) { + dMobs.remove(dMob); } /** diff --git a/src/io/github/dre2n/dungeonsxl/listener/BlockListener.java b/src/io/github/dre2n/dungeonsxl/listener/BlockListener.java index a3eab2ee..02b5f925 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/BlockListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/BlockListener.java @@ -4,6 +4,8 @@ import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.game.GamePlaceableBlock; +import io.github.dre2n.dungeonsxl.game.GameType; +import io.github.dre2n.dungeonsxl.game.GameTypeDefault; import io.github.dre2n.dungeonsxl.game.GameWorld; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GroupSign; @@ -119,8 +121,17 @@ public class BlockListener implements Listener { // Deny GameWorld Blocks GameWorld gameWorld = GameWorld.getByWorld(block.getWorld()); if (gameWorld != null) { - if (gameWorld.getDSigns().contains(block) || !gameWorld.getConfig().canBuild()) { + if (gameWorld.getDSigns().contains(block)) { event.setCancelled(true); + + } else if (gameWorld.getGame() != null) { + GameType gameType = gameWorld.getGame().getType(); + if (gameType == GameTypeDefault.DEFAULT && gameWorld.getConfig() != null) { + event.setCancelled( !gameWorld.getConfig().canBuild()); + + } else if ( !gameType.canBuild()) { + event.setCancelled(true); + } } } } diff --git a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 1c9a711e..3d154dae 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -92,16 +92,19 @@ public class PlayerListener implements Listener { }.runTaskLater(plugin, 1L); } - } else if ( !(dPlayer.getLives() == -1)) { + } + + if (dPlayer.getLives() != -1) { MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_DEATH, String.valueOf(dPlayer.getLives()))); - } else if (dConfig != null) { - if (dConfig.getKeepInventoryOnDeath()) { - dPlayer.setRespawnInventory(event.getEntity().getInventory().getContents()); - dPlayer.setRespawnArmor(event.getEntity().getInventory().getArmorContents()); - // Delete all drops - for (ItemStack istack : event.getDrops()) { - istack.setType(Material.AIR); + if (dConfig != null) { + if (dConfig.getKeepInventoryOnDeath()) { + dPlayer.setRespawnInventory(event.getEntity().getInventory().getContents()); + dPlayer.setRespawnArmor(event.getEntity().getInventory().getArmorContents()); + // Delete all drops + for (ItemStack istack : event.getDrops()) { + istack.setType(Material.AIR); + } } } } @@ -555,7 +558,9 @@ public class PlayerListener implements Listener { // Inventory Events @EventHandler(priority = EventPriority.HIGH) public void onInventoryOpen(InventoryOpenEvent event) { - GameChest.onOpenInventory(event); + if (event.getPlayer() instanceof Player) { + GameChest.onOpenInventory(event); + } } @EventHandler diff --git a/src/io/github/dre2n/dungeonsxl/mob/DMob.java b/src/io/github/dre2n/dungeonsxl/mob/DMob.java index fdf3da8c..f508c58f 100644 --- a/src/io/github/dre2n/dungeonsxl/mob/DMob.java +++ b/src/io/github/dre2n/dungeonsxl/mob/DMob.java @@ -19,7 +19,7 @@ public class DMob { private String trigger; public DMob(LivingEntity entity, GameWorld gameWorld, DMobType type) { - gameWorld.getDMobs().add(this); + gameWorld.addDMob(this); this.entity = entity; this.type = type; @@ -33,7 +33,7 @@ public class DMob { } public DMob(LivingEntity entity, GameWorld gameWorld, DMobType type, String trigger) { - gameWorld.getDMobs().add(this); + gameWorld.addDMob(this); this.entity = entity; this.type = type; @@ -63,40 +63,41 @@ public class DMob { } for (DMob dMob : gameWorld.getDMobs()) { - if (dMob.entity == victim) { - - DMobDeathEvent dMobDeathEvent = new DMobDeathEvent(dMob, event); - - if (dMobDeathEvent.isCancelled()) { - return; - } - - if (dMob.type != null) { - for (ItemStack itemStack : dMob.type.getDrops().keySet()) { - Random randomGenerator = new Random(); - int random = randomGenerator.nextInt(100); - - if (dMob.type.getDrops().get(itemStack) > random) { - event.getDrops().add(itemStack); - } - } - name = dMob.type.getName(); - - } else if (dMob.type == null && dMob.trigger != null) {// <=MythicMobs mob - name = dMob.trigger; - - } else { - name = victim.getType().getName(); - } - - MobTrigger trigger = MobTrigger.get(name, gameWorld); - if (trigger != null) { - trigger.onTrigger(); - } - - gameWorld.getDMobs().remove(dMob); + if (dMob.entity != victim) { + continue; + } + + DMobDeathEvent dMobDeathEvent = new DMobDeathEvent(dMob, event); + + if (dMobDeathEvent.isCancelled()) { return; } + + if (dMob.type != null) { + for (ItemStack itemStack : dMob.type.getDrops().keySet()) { + Random randomGenerator = new Random(); + int random = randomGenerator.nextInt(100); + + if (dMob.type.getDrops().get(itemStack) > random) { + event.getDrops().add(itemStack); + } + } + name = dMob.type.getName(); + + } else if (dMob.type == null && dMob.trigger != null) {// <=MythicMobs mob + name = dMob.trigger; + + } else { + name = victim.getType().getName(); + } + + MobTrigger trigger = MobTrigger.get(name, gameWorld); + if (trigger != null) { + trigger.onTrigger(); + } + + gameWorld.removeDMob(dMob); + return; } } diff --git a/src/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/io/github/dre2n/dungeonsxl/player/DGroup.java index 4d4ccc36..80f99ea7 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -1,17 +1,22 @@ package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.MessageConfig; import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages; +import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupStartFloorEvent; import io.github.dre2n.dungeonsxl.event.requirement.RequirementDemandEvent; import io.github.dre2n.dungeonsxl.event.reward.RewardAdditionEvent; import io.github.dre2n.dungeonsxl.game.Game; +import io.github.dre2n.dungeonsxl.game.GameType; +import io.github.dre2n.dungeonsxl.game.GameTypeDefault; import io.github.dre2n.dungeonsxl.game.GameWorld; import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.reward.Reward; import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.util.playerutil.PlayerUtil; import java.util.ArrayList; import java.util.List; @@ -23,6 +28,7 @@ import org.bukkit.entity.Player; public class DGroup { static DungeonsXL plugin = DungeonsXL.getPlugin(); + static MessageConfig messageConfig = plugin.getMessageConfig(); private String name; private Player captain; @@ -34,6 +40,7 @@ public class DGroup { private GameWorld gameWorld; private boolean playing; private int floorCount; + private int waveCount; private List rewards = new ArrayList(); public DGroup(String name, Player player) { @@ -375,6 +382,21 @@ public class DGroup { this.floorCount = floorCount; } + /** + * @return the waveCount + */ + public int getWaveCount() { + return waveCount; + } + + /** + * @param waveCount + * the waveCount to set + */ + public void setWaveCount(int waveCount) { + this.waveCount = waveCount; + } + /** * @return the rewards */ @@ -460,21 +482,41 @@ public class DGroup { MessageUtil.sendScreenMessage(player, "&4&l" + mapName.replaceAll("_", " ")); } - for (Requirement requirement : gameWorld.getConfig().getRequirements()) { - RequirementDemandEvent requirementDemandEvent = new RequirementDemandEvent(requirement, player); - - if (requirementDemandEvent.isCancelled()) { - continue; + WorldConfig config = gameWorld.getConfig(); + if (config != null) { + for (Requirement requirement : config.getRequirements()) { + RequirementDemandEvent requirementDemandEvent = new RequirementDemandEvent(requirement, player); + + if (requirementDemandEvent.isCancelled()) { + continue; + } + + requirement.demand(player); } - requirement.demand(player); + GameType gameType = game.getType(); + if (gameType == GameTypeDefault.DEFAULT) { + player.setGameMode(config.getGameMode()); + + } else { + player.setGameMode(gameType.getGameMode()); + } } - } GroupSign.updatePerGroup(this); } + public void finishWave(double mobCountIncreaseRate) { + for (DGroup dGroup : DGroup.getByGameWorld(gameWorld)) { + dGroup.sendMessage(messageConfig.getMessage(Messages.GROUP_WAVE_FINISHED, String.valueOf(dGroup.getWaveCount()) + "TIME"));// TODO + + for (Player player : dGroup.getPlayers()) { + PlayerUtil.secureTeleport(player, gameWorld.getLocStart()); + } + } + } + /** * Send a message to all players in the group */ @@ -522,16 +564,6 @@ public class DGroup { return null; } - public static DGroup getByGameWorld(GameWorld gameWorld) { - for (DGroup dGroup : plugin.getDGroups()) { - if (dGroup.getGameWorld() == gameWorld) { - return dGroup; - } - } - - return null; - } - public static void leaveGroup(Player player) { for (DGroup dGroup : plugin.getDGroups()) { if (dGroup.getPlayers().contains(player)) { @@ -540,4 +572,20 @@ public class DGroup { } } + /** + * @param gameWorld + * the GameWorld to check + * @return a List of DGroups in this GameWorld + */ + public static List getByGameWorld(GameWorld gameWorld) { + List dGroups = new ArrayList(); + for (DGroup dGroup : plugin.getDGroups()) { + if (dGroup.getGameWorld().equals(gameWorld)) { + dGroups.add(dGroup); + } + } + + return dGroups; + } + } diff --git a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java index 9bf39568..be9588ff 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java +++ b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java @@ -93,7 +93,7 @@ public class DPlayer { } else { WorldConfig worldConfig = GameWorld.getByWorld(world).getConfig(); - this.getPlayer().setGameMode(worldConfig.getGameMode()); + this.getPlayer().setGameMode(GameMode.SURVIVAL); if ( !worldConfig.getKeepInventoryOnEnter()) { clearPlayerData(); } @@ -523,8 +523,12 @@ public class DPlayer { // Belohnung if ( !isInTestMode()) {// Nur wenn man nicht am Testen ist if (finished) { - for (Reward reward : gameWorld.getConfig().getRewards()) { - reward.giveTo(player); + if (gameWorld.getGame() != null) { + if (gameWorld.getGame().getType().hasRewards()) { + for (Reward reward : gameWorld.getConfig().getRewards()) { + reward.giveTo(player); + } + } } addTreasure(); diff --git a/src/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/src/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index f5491561..01d27b2f 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/src/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -21,7 +21,8 @@ public enum DSignTypeDefault implements DSignType { REDSTONE("Redstone", "dxl.sign.redstone", false, RedstoneSign.class), SOUND_MESSAGE("SoundMSG", "dxl.sign.soundmsg", false, SoundMessageSign.class), START("Start", "dxl.sign.start", true, StartSign.class), - TRIGGER("Trigger", "dxl.sign.trigger", true, TriggerSign.class); + TRIGGER("Trigger", "dxl.sign.trigger", true, TriggerSign.class), + WAVE("Wave", "dxl.sign.wave", false, WaveSign.class); private String name; private String buildPermission; diff --git a/src/io/github/dre2n/dungeonsxl/sign/EndSign.java b/src/io/github/dre2n/dungeonsxl/sign/EndSign.java index d334af36..a9ff01a0 100644 --- a/src/io/github/dre2n/dungeonsxl/sign/EndSign.java +++ b/src/io/github/dre2n/dungeonsxl/sign/EndSign.java @@ -45,11 +45,15 @@ public class EndSign extends DSign { @Override public boolean onPlayerTrigger(Player player) { DPlayer dPlayer = DPlayer.getByPlayer(player); - if (dPlayer != null) { - if ( !dPlayer.isFinished()) { - dPlayer.finish(); - } + if (dPlayer == null) { + return true; } + + if (dPlayer.isFinished()) { + return true; + } + + dPlayer.finish(); return true; } diff --git a/src/io/github/dre2n/dungeonsxl/sign/WaveSign.java b/src/io/github/dre2n/dungeonsxl/sign/WaveSign.java new file mode 100644 index 00000000..11157af1 --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/sign/WaveSign.java @@ -0,0 +1,95 @@ +package io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.dungeonsxl.game.GameWorld; +import io.github.dre2n.dungeonsxl.player.DGroup; +import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; +import io.github.dre2n.dungeonsxl.util.NumberUtil; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; + +public class WaveSign extends DSign { + + private DSignType type = DSignTypeDefault.WAVE; + + private double mobCountIncreaseRate; + + public WaveSign(Sign sign, GameWorld gameWorld) { + super(sign, gameWorld); + } + + /** + * @return the mobCountIncreaseRate + */ + public double getMobCountIncreaseRate() { + return mobCountIncreaseRate; + } + + /** + * @param mobCountIncreaseRate + * the mobCountIncreaseRate to set + */ + public void setMobCountIncreaseRate(double mobCountIncreaseRate) { + this.mobCountIncreaseRate = mobCountIncreaseRate; + } + + @Override + public boolean check() { + return true; + } + + @Override + public void onInit() { + String[] lines = getSign().getLines(); + if ( !lines[1].equals("")) { + mobCountIncreaseRate = NumberUtil.parseDouble(lines[1], 2); + } + + if ( !getTriggers().isEmpty()) { + getSign().getBlock().setType(Material.AIR); + return; + } + + InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGameWorld()); + if (trigger != null) { + trigger.addListener(this); + addTrigger(trigger); + } + + getSign().setLine(0, ChatColor.DARK_BLUE + "############"); + getSign().setLine(1, ChatColor.DARK_GREEN + "START"); + getSign().setLine(2, ChatColor.DARK_GREEN + "NEXT WAVE"); + getSign().setLine(3, ChatColor.DARK_BLUE + "############"); + getSign().update(); + } + + @Override + public boolean onPlayerTrigger(Player player) { + DGroup dGroup = DGroup.getByPlayer(player); + if (dGroup == null) { + return true; + } + + if (getGameWorld() == null) { + return true; + } + + dGroup.finishWave(mobCountIncreaseRate); + return true; + } + + @Override + public void onTrigger() { + for (DGroup dGroup : plugin.getDGroups()) { + dGroup.finishWave(mobCountIncreaseRate); + } + } + + @Override + public DSignType getType() { + return type; + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/trigger/Trigger.java b/src/io/github/dre2n/dungeonsxl/trigger/Trigger.java index 222c2e41..746e3e0f 100644 --- a/src/io/github/dre2n/dungeonsxl/trigger/Trigger.java +++ b/src/io/github/dre2n/dungeonsxl/trigger/Trigger.java @@ -135,6 +135,12 @@ public abstract class Trigger { return UseItemTrigger.getOrCreate(value, dSign.getGameWorld()); } + } else if (type == TriggerTypeDefault.WAVE) { + + if (value != null) { + return WaveTrigger.getOrCreate(NumberUtil.parseInt(value, 1), dSign.getGameWorld()); + } + } else if (type != null) { Trigger trigger = null; diff --git a/src/io/github/dre2n/dungeonsxl/trigger/TriggerTypeDefault.java b/src/io/github/dre2n/dungeonsxl/trigger/TriggerTypeDefault.java index 8c4661ed..e6232653 100644 --- a/src/io/github/dre2n/dungeonsxl/trigger/TriggerTypeDefault.java +++ b/src/io/github/dre2n/dungeonsxl/trigger/TriggerTypeDefault.java @@ -7,7 +7,8 @@ public enum TriggerTypeDefault implements TriggerType { MOB("M", MobTrigger.class), REDSTONE("R", RedstoneTrigger.class), SIGN("T", SignTrigger.class), - USE_ITEM("U", UseItemTrigger.class); + USE_ITEM("U", UseItemTrigger.class), + WAVE("W", WaveTrigger.class); private String identifier; private Class handler; diff --git a/src/io/github/dre2n/dungeonsxl/trigger/WaveTrigger.java b/src/io/github/dre2n/dungeonsxl/trigger/WaveTrigger.java new file mode 100644 index 00000000..9f5c8449 --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/trigger/WaveTrigger.java @@ -0,0 +1,93 @@ +package io.github.dre2n.dungeonsxl.trigger; + +import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; +import io.github.dre2n.dungeonsxl.game.GameWorld; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class WaveTrigger extends Trigger { + + private static Map> triggers = new HashMap>(); + + private TriggerType type = TriggerTypeDefault.WAVE; + + private int mustKillAmount; + + public WaveTrigger(int mustKillAmount) { + this.mustKillAmount = mustKillAmount; + } + + public void onTrigger() { + TriggerActionEvent event = new TriggerActionEvent(this); + + if (event.isCancelled()) { + return; + } + + setTriggered(true); + updateDSigns(); + } + + @Override + public void register(GameWorld gameWorld) { + if ( !hasTriggers(gameWorld)) { + ArrayList list = new ArrayList(); + list.add(this); + triggers.put(gameWorld, list); + + } else { + triggers.get(gameWorld).add(this); + } + } + + @Override + public void unregister(GameWorld gameWorld) { + if (hasTriggers(gameWorld)) { + triggers.get(gameWorld).remove(this); + } + } + + @Override + public TriggerType getType() { + return type; + } + + public static WaveTrigger getOrCreate(int mustKillAmount, GameWorld gameWorld) { + WaveTrigger trigger = get(gameWorld); + if (trigger != null) { + return trigger; + } + return new WaveTrigger(mustKillAmount); + } + + public static WaveTrigger get(GameWorld gameWorld) { + if (hasTriggers(gameWorld)) { + for (WaveTrigger trigger : triggers.get(gameWorld)) { + return trigger; + } + } + return null; + } + + public static boolean hasTriggers(GameWorld gameWorld) { + return !triggers.isEmpty() && triggers.containsKey(gameWorld); + } + + /** + * @return the mustKillAmount + */ + public int getMustKillAmount() { + return mustKillAmount; + } + + /** + * @param mustKillAmount + * the mustKillAmount to set + */ + public void setMustKillAmount(int mustKillAmount) { + this.mustKillAmount = mustKillAmount; + } + +} diff --git a/src/plugin.yml b/src/plugin.yml index aae5283e..20a4f149 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -22,6 +22,8 @@ permissions: default: op dxl.escape: default: true + dxl.game: + default: true dxl.group: default: op dxl.group.admin: