From 5ff968d3946657e29edcc306e046ae71555c3c8d Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 19 Jun 2016 14:15:27 +0200 Subject: [PATCH 01/21] Added sign to modify lives --- pom.xml | 2 +- .../dre2n/dungeonsxl/config/DMessages.java | 2 + .../dungeonsxl/sign/DSignTypeDefault.java | 1 + .../dungeonsxl/sign/LivesModifierSign.java | 123 ++++++++++++++++++ 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java diff --git a/pom.xml b/pom.xml index afe1e87b..63de8ed6 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.github.dre2n dungeonsxl - 0.12.1-SNAPSHOT${buildNo} + 0.13-SNAPSHOT${buildNo} jar DungeonsXL https://dre2n.github.io diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 3fedf028..abfb9cfe 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -146,6 +146,8 @@ public enum DMessages implements Messages { PLAYER_KICKED("Player_Kicked", "&4You have been kicked out of the group &6&v1&4."), PLAYER_LEAVE_GROUP("Player_LeaveGroup", "&6You have successfully left your group!"), PLAYER_LEFT_GROUP("Player_LeftGroup", "&6Player &4&v1&6 has left the Group!"), + PLAYER_LIVES_ADDED("Player_LivesAdded", "&6Received a bonus of &4&v1&6 lives."), + PLAYER_LIVES_REMOVED("Player_LivesRemoved", "&6You lost &4&v1&6 lives!"), PLAYER_LOOT_ADDED("Player_LootAdded", "&4&v1&6 have been added to your reward inventory!"), PLAYER_NEW_CAPTAIN("Player_NewCaptain", "&6You are now the new captain of your group."), PLAYER_OFFLINE("Player_Offline", "&Player &4&v1&6 went offline. In &4&v2&6 seconds he will autmatically be kicked from the Dungeon!"), diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index 74969732..f9b60226 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -34,6 +34,7 @@ public enum DSignTypeDefault implements DSignType { FLOOR("Floor", "floor", false, FloorSign.class), INTERACT("Interact", "interact", true, InteractSign.class), LEAVE("Leave", "leave", true, LeaveSign.class), + LIVES_MODIFIER("Lives", "lives", false, LivesModifierSign.class), LOBBY("Lobby", "lobby", true, LobbySign.class), MOB("Mob", "mob", false, DMobSign.class), MESSAGE("MSG", "msg", false, MessageSign.class), diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java new file mode 100644 index 00000000..ec5a8867 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2012-2016 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 io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.dungeonsxl.config.DMessages; +import io.github.dre2n.dungeonsxl.game.Game; +import io.github.dre2n.dungeonsxl.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.player.DGroup; +import io.github.dre2n.dungeonsxl.world.GameWorld; +import io.github.dre2n.itemsxl.util.commons.util.EnumUtil; +import io.github.dre2n.itemsxl.util.commons.util.NumberUtil; +import io.github.dre2n.itemsxl.util.commons.util.messageutil.MessageUtil; +import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; + +/** + * @author Frank Baumann, Milan Albrecht, Daniel Saukel + */ +public class LivesModifierSign extends DSign { + + public enum Target { + GAME, + GROUP, + PLAYER, + } + + private DSignType type = DSignTypeDefault.LIVES_MODIFIER; + + private int lives; + private Target target; + + public LivesModifierSign(Sign sign, String[] lines, GameWorld gameWorld) { + super(sign, lines, gameWorld); + } + + /* 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; + } + + @Override + public void onInit() { + lives = NumberUtil.parseInt(lines[1]); + if (EnumUtil.isValidEnum(Target.class, lines[2].toUpperCase())) { + target = Target.valueOf(lines[2].toUpperCase()); + } + + getSign().getBlock().setType(Material.AIR); + } + + @Override + public boolean onPlayerTrigger(Player player) { + switch (target) { + case GAME: + for (Player gamePlayer : Game.getByPlayer(player).getPlayers()) { + DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); + if (gamePlayer != null) { + modifyLives(dPlayer); + } + } + break; + + case GROUP: + for (DGamePlayer dPlayer : DGroup.getByPlayer(player).getDGamePlayers()) { + modifyLives(dPlayer); + } + break; + + case PLAYER: + modifyLives(DGamePlayer.getByPlayer(player)); + } + + return true; + } + + public void modifyLives(DGamePlayer dPlayer) { + dPlayer.setLives(dPlayer.getLives() + lives); + if (lives > 0) { + MessageUtil.sendMessage(dPlayer.getPlayer(), DMessages.PLAYER_LIVES_ADDED.getMessage(String.valueOf(lives))); + + } else { + MessageUtil.sendMessage(dPlayer.getPlayer(), DMessages.PLAYER_LIVES_REMOVED.getMessage(String.valueOf(-1 * lives))); + } + } + + @Override + public DSignType getType() { + return type; + } + +} From 4a6c450097a61f11a4c68cd4165e9d7d1bf857ba Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 19 Jun 2016 20:09:34 +0200 Subject: [PATCH 02/21] Added drop sign; resolves #14 --- .../dungeonsxl/sign/DSignTypeDefault.java | 1 + .../dre2n/dungeonsxl/sign/DropSign.java | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/sign/DropSign.java diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index f9b60226..f5e3e011 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -29,6 +29,7 @@ public enum DSignTypeDefault implements DSignType { CHUNK_UPDATER("ChunkUpdater", "chunkupdater", true, ChunkUpdaterSign.class), CLASSES("Classes", "classes", true, ClassesSign.class), COMMAND("CMD", "cmd", false, CommandSign.class), + DROP("Drop", "drop", false, DropSign.class), END("End", "end", false, EndSign.class), EXTERNAL_MOB("ExternalMob", "mob", false, ExternalMobSign.class), FLOOR("Floor", "floor", false, FloorSign.class), diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/DropSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/DropSign.java new file mode 100644 index 00000000..d530ad54 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/DropSign.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2012-2016 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 io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.caliburn.item.UniversalItem; +import io.github.dre2n.commons.util.NumberUtil; +import io.github.dre2n.dungeonsxl.world.GameWorld; +import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.inventory.ItemStack; + +/** + * @author Frank Baumann, Milan Albrecht, Daniel Saukel + */ +public class DropSign extends DSign { + + private DSignType type = DSignTypeDefault.DROP; + + private ItemStack item; + + public DropSign(Sign sign, String[] lines, GameWorld gameWorld) { + super(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.getCaliburnAPI().getItems().getById(lines[1]) != null; + } + + @Override + public void onInit() { + UniversalItem item = plugin.getCaliburnAPI().getItems().getById(lines[1]); + this.item = item.toItemStack(NumberUtil.parseInt(lines[2], 1)); + getSign().getBlock().setType(Material.AIR); + } + + @Override + public void onTrigger() { + getSign().getWorld().dropItem(getSign().getLocation(), item); + } + + @Override + public DSignType getType() { + return type; + } + +} From 973297b2cc6e11c59836d75671e45efac4b806a0 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 19 Jun 2016 21:36:41 +0200 Subject: [PATCH 03/21] Added warp / destination signs --- .../dungeonsxl/sign/DSignTypeDefault.java | 4 +- .../dungeonsxl/sign/DestinationSign.java | 69 +++++++++++ .../dre2n/dungeonsxl/sign/WarpSign.java | 114 ++++++++++++++++++ 3 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/sign/DestinationSign.java create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/sign/WarpSign.java diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index f5e3e011..34e75364 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -29,6 +29,7 @@ public enum DSignTypeDefault implements DSignType { CHUNK_UPDATER("ChunkUpdater", "chunkupdater", true, ChunkUpdaterSign.class), CLASSES("Classes", "classes", true, ClassesSign.class), COMMAND("CMD", "cmd", false, CommandSign.class), + DESTINATION("Destination", "warp", false, DestinationSign.class), DROP("Drop", "drop", false, DropSign.class), END("End", "end", false, EndSign.class), EXTERNAL_MOB("ExternalMob", "mob", false, ExternalMobSign.class), @@ -49,7 +50,8 @@ public enum DSignTypeDefault implements DSignType { START("Start", "start", true, StartSign.class), TELEPORT("Teleport", "teleport", false, TeleportSign.class), TRIGGER("Trigger", "trigger", true, TriggerSign.class), - WAVE("Wave", "wave", false, WaveSign.class); + WAVE("Wave", "wave", false, WaveSign.class), + WARP("Warp", "warp", false, WarpSign.class); private String name; private String buildPermission; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/DestinationSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/DestinationSign.java new file mode 100644 index 00000000..d4c2e85c --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/DestinationSign.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2012-2016 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 io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.dungeonsxl.world.GameWorld; +import org.bukkit.Material; +import org.bukkit.block.Sign; + +/** + * @author Frank Baumann, Milan Albrecht, Daniel Saukel + */ +public class DestinationSign extends DSign { + + private DSignType type = DSignTypeDefault.DESTINATION; + + private String id; + + public DestinationSign(Sign sign, String[] lines, GameWorld gameWorld) { + super(sign, lines, gameWorld); + } + + /* Getters and setters */ + /** + * @return the ID + */ + public String getId() { + return id; + } + + /** + * @param id + * the ID of the destination sign + */ + public void setId(String id) { + this.id = id; + } + + /* Actions */ + @Override + public boolean check() { + return true; + } + + @Override + public void onInit() { + id = lines[1]; + getSign().getBlock().setType(Material.AIR); + } + + @Override + public DSignType getType() { + return type; + } + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/WarpSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/WarpSign.java new file mode 100644 index 00000000..41df166c --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/WarpSign.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2012-2016 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 io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; +import io.github.dre2n.dungeonsxl.world.GameWorld; +import io.github.dre2n.itemsxl.util.commons.util.playerutil.PlayerUtil; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; + +/** + * @author Frank Baumann, Milan Albrecht, Daniel Saukel + */ +public class WarpSign extends DSign { + + private DSignType type = DSignTypeDefault.WARP; + + private String destination; + + public WarpSign(Sign sign, String[] lines, GameWorld gameWorld) { + super(sign, lines, gameWorld); + } + + /** + * @return the destination sign + */ + public DestinationSign getDestinationSign() { + for (DSign dSign : getGameWorld().getDSigns()) { + if (dSign.getType() == DSignTypeDefault.DESTINATION) { + if (((DestinationSign) dSign).getId().equals(destination)) { + return (DestinationSign) dSign; + } + } + } + + return null; + } + + /** + * @return the destination + */ + public Location getDestination() { + if (getDestinationSign() != null) { + return getDestinationSign().getSign().getLocation(); + + } else { + return null; + } + } + + /** + * @param id + * the ID of the destination sign + */ + public void setDestination(String id) { + destination = id; + } + + @Override + public boolean check() { + return true; + } + + @Override + public void onInit() { + destination = lines[1]; + + 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 + "Warp"); + getSign().setLine(2, ""); + getSign().setLine(3, ChatColor.DARK_BLUE + "############"); + getSign().update(); + } + + @Override + public boolean onPlayerTrigger(Player player) { + PlayerUtil.secureTeleport(player, getDestination()); + return true; + } + + @Override + public DSignType getType() { + return type; + } + +} From cea08e440dcf1c649167405da3227b573fe77129 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 19 Jun 2016 23:26:24 +0200 Subject: [PATCH 04/21] Multiple start locations; resolves #16 --- .../io/github/dre2n/dungeonsxl/game/Game.java | 2 +- .../dungeonsxl/listener/PlayerListener.java | 10 +---- .../dre2n/dungeonsxl/player/DGamePlayer.java | 18 ++------- .../dre2n/dungeonsxl/sign/StartSign.java | 22 ++++++++++- .../dre2n/dungeonsxl/world/GameWorld.java | 37 ++++++++++++++----- 5 files changed, 53 insertions(+), 36 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index 912b40ab..f92abacb 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -381,7 +381,7 @@ public class Game { public void run() { if (teleport) { for (Player player : getPlayers()) { - PlayerUtil.secureTeleport(player, world.getStartLocation()); + PlayerUtil.secureTeleport(player, world.getStartLocation(DGroup.getByPlayer(player))); } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index f3e2685d..dd443e1b 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -398,15 +398,7 @@ public class PlayerListener implements Listener { Location respawn = gamePlayer.getCheckpoint(); if (respawn == null) { - respawn = dGroup.getGameWorld().getStartLocation(); - } - - if (respawn == null) { - respawn = dGroup.getGameWorld().getLobbyLocation(); - } - - if (respawn == null) { - respawn = dGroup.getGameWorld().getWorld().getSpawnLocation(); + respawn = dGroup.getGameWorld().getStartLocation(dGroup); } // Because some plugins set another respawn point, DXL teleports a few ticks later. diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 65b18931..30d8a84e 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -596,11 +596,7 @@ public class DGamePlayer extends DInstancePlayer { Location respawn = checkpoint; if (respawn == null) { - respawn = dGroup.getGameWorld().getStartLocation(); - } - - if (respawn == null) { - respawn = dGroup.getGameWorld().getLobbyLocation(); + respawn = dGroup.getGameWorld().getStartLocation(dGroup); } if (respawn == null) { @@ -693,7 +689,7 @@ public class DGamePlayer extends DInstancePlayer { for (Player player : dGroup.getPlayers()) { DGamePlayer dPlayer = getByPlayer(player); dPlayer.setWorld(gameWorld.getWorld()); - dPlayer.setCheckpoint(dGroup.getGameWorld().getStartLocation()); + dPlayer.setCheckpoint(dGroup.getGameWorld().getStartLocation(dGroup)); if (dPlayer.getWolf() != null) { dPlayer.getWolf().teleport(dPlayer.getCheckpoint()); } @@ -816,15 +812,7 @@ public class DGamePlayer extends DInstancePlayer { teleportLocation = getCheckpoint(); if (teleportLocation == null) { - teleportLocation = dGroup.getGameWorld().getStartLocation(); - } - - if (teleportLocation == null) { - teleportLocation = dGroup.getGameWorld().getLobbyLocation(); - } - - if (teleportLocation == null) { - teleportLocation = getWorld().getSpawnLocation(); + teleportLocation = dGroup.getGameWorld().getStartLocation(dGroup); } // Don't forget Doge! diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/StartSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/StartSign.java index 8d3935ea..1f435b10 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/StartSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/StartSign.java @@ -16,6 +16,7 @@ */ package io.github.dre2n.dungeonsxl.sign; +import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.dungeonsxl.world.GameWorld; import org.bukkit.Material; import org.bukkit.block.Sign; @@ -27,10 +28,29 @@ public class StartSign extends DSign { private DSignType type = DSignTypeDefault.START; + private int id; + public StartSign(Sign sign, String[] lines, GameWorld gameWorld) { super(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; @@ -38,7 +58,7 @@ public class StartSign extends DSign { @Override public void onInit() { - getGameWorld().setStartLocation(getSign().getLocation()); + id = NumberUtil.parseInt(lines[1]); getSign().getBlock().setType(Material.AIR); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java index 2d3bf546..c54cb92d 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java @@ -29,10 +29,12 @@ import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.game.GamePlaceableBlock; import io.github.dre2n.dungeonsxl.mob.DMob; import io.github.dre2n.dungeonsxl.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.reward.RewardChest; import io.github.dre2n.dungeonsxl.sign.DSign; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; import io.github.dre2n.dungeonsxl.sign.MobSign; -import io.github.dre2n.dungeonsxl.trigger.MobTrigger; +import io.github.dre2n.dungeonsxl.sign.StartSign; import io.github.dre2n.dungeonsxl.trigger.ProgressTrigger; import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger; import io.github.dre2n.dungeonsxl.trigger.Trigger; @@ -203,16 +205,31 @@ public class GameWorld { /** * @return the start location */ - public Location getStartLocation() { - return locStart; - } + public Location getStartLocation(DGroup dGroup) { + int index = getGame().getDGroups().indexOf(dGroup); - /** - * @param location - * the location to start to set - */ - public void setStartLocation(Location location) { - this.locStart = location; + // Try the matching location + for (DSign dSign : dSigns) { + if (dSign.getType() == DSignTypeDefault.START) { + if (((StartSign) dSign).getId() == index) { + return dSign.getSign().getLocation(); + } + } + } + + // Try any location + for (DSign dSign : dSigns) { + if (dSign.getType() == DSignTypeDefault.START) { + return dSign.getSign().getLocation(); + } + } + + // Lobby location as fallback + if (locLobby != null) { + return locLobby; + } + + return world.getSpawnLocation(); } /** From 00df06e45e39d068748b67663822f730ac428da5 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 19 Jun 2016 23:41:24 +0200 Subject: [PATCH 05/21] Added permission requirement --- .../dre2n/dungeonsxl/config/WorldConfig.java | 11 ++- .../requirement/PermissionRequirement.java | 70 +++++++++++++++++++ .../requirement/RequirementTypeDefault.java | 3 +- 3 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/requirement/PermissionRequirement.java diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java b/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java index aa19fe9c..fe94d6eb 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java @@ -26,7 +26,9 @@ import io.github.dre2n.dungeonsxl.game.GameType; import io.github.dre2n.dungeonsxl.requirement.FeeLevelRequirement; import io.github.dre2n.dungeonsxl.requirement.FeeMoneyRequirement; import io.github.dre2n.dungeonsxl.requirement.GroupSizeRequirement; +import io.github.dre2n.dungeonsxl.requirement.PermissionRequirement; import io.github.dre2n.dungeonsxl.requirement.Requirement; +import io.github.dre2n.dungeonsxl.requirement.RequirementTypeDefault; import io.github.dre2n.dungeonsxl.util.DeserialisazionUtil; import java.io.File; import java.io.IOException; @@ -190,15 +192,18 @@ public class WorldConfig extends GameRules { Requirement requirement = Requirement.create(plugin.getRequirementTypes().getByIdentifier(identifier)); // Check for built-in requirements - if (requirement instanceof FeeMoneyRequirement) { + if (requirement.getType() == RequirementTypeDefault.FEE_MONEY) { ((FeeMoneyRequirement) requirement).setFee(configFile.getDouble("requirements.feeMoney")); - } else if (requirement instanceof FeeLevelRequirement) { + } else if (requirement.getType() == RequirementTypeDefault.FEE_LEVEL) { ((FeeLevelRequirement) requirement).setFee(configFile.getInt("requirements.feeLevel")); - } else if (requirement instanceof GroupSizeRequirement) { + } else if (requirement.getType() == RequirementTypeDefault.GROUP_SIZE) { ((GroupSizeRequirement) requirement).setMinimum(configFile.getInt("requirements.groupSize.minimum")); ((GroupSizeRequirement) requirement).setMaximum(configFile.getInt("requirements.groupSize.maximum")); + + } else if (requirement.getType() == RequirementTypeDefault.PERMISSION) { + ((PermissionRequirement) requirement).setPermissions(configFile.getStringList("requirements.permission")); } requirements.add(requirement); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/requirement/PermissionRequirement.java b/src/main/java/io/github/dre2n/dungeonsxl/requirement/PermissionRequirement.java new file mode 100644 index 00000000..5523cd73 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/requirement/PermissionRequirement.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2012-2016 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 io.github.dre2n.dungeonsxl.requirement; + +import io.github.dre2n.dungeonsxl.player.DPermissions; +import java.util.ArrayList; +import java.util.List; +import org.bukkit.entity.Player; + +/** + * @author Daniel Saukel + */ +public class PermissionRequirement extends Requirement { + + private RequirementType type = RequirementTypeDefault.PERMISSION; + + private List permissions = new ArrayList<>(); + + /* Getters and setters */ + /** + * @return the permission the player must have to play the dungeon + */ + public List getPermissions() { + return permissions; + } + + /** + * @param permissions + * the permissions to set + */ + public void setPermissions(List permissions) { + this.permissions = permissions; + } + + @Override + public RequirementType getType() { + return type; + } + + /* Actions */ + @Override + public boolean check(Player player) { + for (String permission : permissions) { + if (!DPermissions.hasPermission(player, permission)) { + return false; + } + } + + return true; + } + + @Override + public void demand(Player player) { + } + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypeDefault.java b/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypeDefault.java index a22aa2d8..c4a3a4e0 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypeDefault.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypeDefault.java @@ -23,7 +23,8 @@ public enum RequirementTypeDefault implements RequirementType { FEE_LEVEL("feeLevel", FeeLevelRequirement.class), FEE_MONEY("feeMoney", FeeMoneyRequirement.class), - GROUP_SIZE("groupSize", GroupSizeRequirement.class); + GROUP_SIZE("groupSize", GroupSizeRequirement.class), + PERMISSION("permission", PermissionRequirement.class); private String identifier; private Class handler; From d8b128f013216f4781cd65ff09f5d413c55ec2f8 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 20 Jun 2016 13:56:40 +0200 Subject: [PATCH 06/21] Revert "Added warp / destination signs" This reverts commit 9cfe5ebf4ed9ce371b0ec6b154c0a716e8b0694a. --- .../dungeonsxl/sign/DSignTypeDefault.java | 4 +- .../dungeonsxl/sign/DestinationSign.java | 69 ----------- .../dre2n/dungeonsxl/sign/WarpSign.java | 114 ------------------ 3 files changed, 1 insertion(+), 186 deletions(-) delete mode 100644 src/main/java/io/github/dre2n/dungeonsxl/sign/DestinationSign.java delete mode 100644 src/main/java/io/github/dre2n/dungeonsxl/sign/WarpSign.java diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index 34e75364..f5e3e011 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -29,7 +29,6 @@ public enum DSignTypeDefault implements DSignType { CHUNK_UPDATER("ChunkUpdater", "chunkupdater", true, ChunkUpdaterSign.class), CLASSES("Classes", "classes", true, ClassesSign.class), COMMAND("CMD", "cmd", false, CommandSign.class), - DESTINATION("Destination", "warp", false, DestinationSign.class), DROP("Drop", "drop", false, DropSign.class), END("End", "end", false, EndSign.class), EXTERNAL_MOB("ExternalMob", "mob", false, ExternalMobSign.class), @@ -50,8 +49,7 @@ public enum DSignTypeDefault implements DSignType { START("Start", "start", true, StartSign.class), TELEPORT("Teleport", "teleport", false, TeleportSign.class), TRIGGER("Trigger", "trigger", true, TriggerSign.class), - WAVE("Wave", "wave", false, WaveSign.class), - WARP("Warp", "warp", false, WarpSign.class); + WAVE("Wave", "wave", false, WaveSign.class); private String name; private String buildPermission; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/DestinationSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/DestinationSign.java deleted file mode 100644 index d4c2e85c..00000000 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/DestinationSign.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2012-2016 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 io.github.dre2n.dungeonsxl.sign; - -import io.github.dre2n.dungeonsxl.world.GameWorld; -import org.bukkit.Material; -import org.bukkit.block.Sign; - -/** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel - */ -public class DestinationSign extends DSign { - - private DSignType type = DSignTypeDefault.DESTINATION; - - private String id; - - public DestinationSign(Sign sign, String[] lines, GameWorld gameWorld) { - super(sign, lines, gameWorld); - } - - /* Getters and setters */ - /** - * @return the ID - */ - public String getId() { - return id; - } - - /** - * @param id - * the ID of the destination sign - */ - public void setId(String id) { - this.id = id; - } - - /* Actions */ - @Override - public boolean check() { - return true; - } - - @Override - public void onInit() { - id = lines[1]; - getSign().getBlock().setType(Material.AIR); - } - - @Override - public DSignType getType() { - return type; - } - -} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/WarpSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/WarpSign.java deleted file mode 100644 index 41df166c..00000000 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/WarpSign.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2012-2016 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 io.github.dre2n.dungeonsxl.sign; - -import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; -import io.github.dre2n.dungeonsxl.world.GameWorld; -import io.github.dre2n.itemsxl.util.commons.util.playerutil.PlayerUtil; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; - -/** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel - */ -public class WarpSign extends DSign { - - private DSignType type = DSignTypeDefault.WARP; - - private String destination; - - public WarpSign(Sign sign, String[] lines, GameWorld gameWorld) { - super(sign, lines, gameWorld); - } - - /** - * @return the destination sign - */ - public DestinationSign getDestinationSign() { - for (DSign dSign : getGameWorld().getDSigns()) { - if (dSign.getType() == DSignTypeDefault.DESTINATION) { - if (((DestinationSign) dSign).getId().equals(destination)) { - return (DestinationSign) dSign; - } - } - } - - return null; - } - - /** - * @return the destination - */ - public Location getDestination() { - if (getDestinationSign() != null) { - return getDestinationSign().getSign().getLocation(); - - } else { - return null; - } - } - - /** - * @param id - * the ID of the destination sign - */ - public void setDestination(String id) { - destination = id; - } - - @Override - public boolean check() { - return true; - } - - @Override - public void onInit() { - destination = lines[1]; - - 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 + "Warp"); - getSign().setLine(2, ""); - getSign().setLine(3, ChatColor.DARK_BLUE + "############"); - getSign().update(); - } - - @Override - public boolean onPlayerTrigger(Player player) { - PlayerUtil.secureTeleport(player, getDestination()); - return true; - } - - @Override - public DSignType getType() { - return type; - } - -} From 1ddf0df88a3ec4388cc4cc2745ec3d23ffa855a5 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 20 Jun 2016 14:34:02 +0200 Subject: [PATCH 07/21] Added timer to ready signs --- .../dre2n/dungeonsxl/sign/ReadySign.java | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java index 6eb0eef3..6f85a6b3 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java @@ -22,13 +22,15 @@ 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.player.DGamePlayer; -import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; +import io.github.dre2n.dungeonsxl.util.ProgressBar; import io.github.dre2n.dungeonsxl.world.GameWorld; +import io.github.dre2n.itemsxl.util.commons.util.NumberUtil; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Sign; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; /** * @author Frank Baumann, Milan Albrecht, Daniel Saukel @@ -38,6 +40,7 @@ public class ReadySign extends DSign { private DSignType type = DSignTypeDefault.READY; private GameType gameType; + private double autoStart = -1; public ReadySign(Sign sign, String[] lines, GameWorld gameWorld) { super(sign, lines, gameWorld); @@ -58,6 +61,21 @@ public class ReadySign extends DSign { 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() { return true; @@ -72,6 +90,10 @@ public class ReadySign extends DSign { gameType = GameTypeDefault.DEFAULT; } + if (!lines[2].isEmpty()) { + autoStart = NumberUtil.parseDouble(lines[2], -1); + } + if (!getTriggers().isEmpty()) { getSign().getBlock().setType(Material.AIR); return; @@ -93,15 +115,25 @@ public class ReadySign extends DSign { @Override public boolean onPlayerTrigger(Player player) { ready(DGamePlayer.getByPlayer(player)); + + if (autoStart >= 0) { + new BukkitRunnable() { + @Override + public void run() { + onTrigger(); + } + }.runTaskLater(plugin, (long) (autoStart * 20)); + + ProgressBar.sendProgressBar(getGame().getPlayers(), (int) Math.ceil(autoStart)); + } + return true; } @Override public void onTrigger() { - for (DGroup dGroup : Game.getByGameWorld(getGameWorld()).getDGroups()) { - for (Player player : dGroup.getPlayers()) { - ready(DGamePlayer.getByPlayer(player)); - } + for (Player player : Game.getByGameWorld(getGameWorld()).getPlayers()) { + ready(DGamePlayer.getByPlayer(player)); } } From c7695f815e0ae5c02be62751465541b155ef88ec Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 20 Jun 2016 15:34:46 +0200 Subject: [PATCH 08/21] Added open door sign --- .../dungeonsxl/listener/PlayerListener.java | 4 + .../dungeonsxl/sign/DSignTypeDefault.java | 1 + .../dre2n/dungeonsxl/sign/OpenDoorSign.java | 107 ++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index dd443e1b..d52434bd 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -39,6 +39,7 @@ import io.github.dre2n.dungeonsxl.player.DPlayers; import io.github.dre2n.dungeonsxl.player.DSavePlayer; import io.github.dre2n.dungeonsxl.reward.DLootInventory; import io.github.dre2n.dungeonsxl.reward.RewardChest; +import io.github.dre2n.dungeonsxl.sign.OpenDoorSign; import io.github.dre2n.dungeonsxl.task.RespawnTask; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; import io.github.dre2n.dungeonsxl.trigger.UseItemTrigger; @@ -312,6 +313,9 @@ public class PlayerListener implements Listener { } } } + + } else if (OpenDoorSign.isProtected(clickedBlock)) { + event.setCancelled(true); } } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index f5e3e011..be1cbbea 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -41,6 +41,7 @@ public enum DSignTypeDefault implements DSignType { MESSAGE("MSG", "msg", false, MessageSign.class), @Deprecated MYTHIC_MOBS("MythicMobs", "mob", false, ExternalMobSign.class), + OPEN_DOOR("Door", "door", false, OpenDoorSign.class), PLACE("Place", "place", false, PlaceSign.class), READY("Ready", "ready", true, ReadySign.class), REDSTONE("Redstone", "redstone", false, RedstoneSign.class), diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java new file mode 100644 index 00000000..8c003f49 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2012-2016 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 io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.commons.util.BlockUtil; +import io.github.dre2n.dungeonsxl.world.GameWorld; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; +import org.bukkit.material.Openable; + +/** + * @author Daniel Saukel + */ +public class OpenDoorSign extends DSign { + + private DSignType type = DSignTypeDefault.OPEN_DOOR; + + private Openable block; + + public OpenDoorSign(Sign sign, String[] lines, GameWorld gameWorld) { + super(sign, lines, gameWorld); + } + + /* Getters and setters */ + /** + * @return the door / fence gate / ... to open; + */ + public Openable getBlock() { + return block; + } + + /** + * @param block + * the door / fence gate / ... to open + */ + public void setBlock(Openable block) { + this.block = block; + } + + @Override + public DSignType getType() { + return type; + } + + /* Actions */ + @Override + public boolean check() { + return true; + } + + @Override + public void onInit() { + Block block = BlockUtil.getAttachedBlock(getSign().getBlock()); + if (block instanceof Openable) { + this.block = (Openable) block; + } + + getSign().setType(Material.AIR); + } + + @Override + public void onTrigger() { + block.setOpen(true); + } + + /* Statics */ + /** + * @param block + * the block to check + * @return + * true if the block is openable only with a sign + */ + public static boolean isProtected(Block block) { + if (!(block instanceof Openable)) { + return false; + } + + GameWorld gameWorld = GameWorld.getByWorld(block.getWorld()); + if (gameWorld != null) { + for (DSign dSign : gameWorld.getDSigns()) { + if (dSign.getType() == DSignTypeDefault.OPEN_DOOR) { + if (((OpenDoorSign) dSign).getBlock().equals(block)) { + return true; + } + } + } + } + + return false; + } + +} From df843c95efad5a701bbea2d912f6eec8ffd3111a Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 20 Jun 2016 16:03:16 +0200 Subject: [PATCH 09/21] Holographic Displays integration; resolves #4 --- pom.xml | 5 ++ .../dungeonsxl/sign/DSignTypeDefault.java | 1 + .../dre2n/dungeonsxl/sign/HologramSign.java | 88 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java diff --git a/pom.xml b/pom.xml index 63de8ed6..87a0c76f 100644 --- a/pom.xml +++ b/pom.xml @@ -105,6 +105,11 @@ 2.0.18-SNAPSHOT provided + + com.gmail.filoghost + holographicdisplaysapi + 2.1.7 + diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index be1cbbea..b5f2b33d 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -33,6 +33,7 @@ public enum DSignTypeDefault implements DSignType { END("End", "end", false, EndSign.class), EXTERNAL_MOB("ExternalMob", "mob", false, ExternalMobSign.class), FLOOR("Floor", "floor", false, FloorSign.class), + HOLOGRAM("Hologram", "hologram", true, HologramSign.class), INTERACT("Interact", "interact", true, InteractSign.class), LEAVE("Leave", "leave", true, LeaveSign.class), LIVES_MODIFIER("Lives", "lives", false, LivesModifierSign.class), diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java new file mode 100644 index 00000000..f5b431a2 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2012-2016 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 io.github.dre2n.dungeonsxl.sign; + +import com.gmail.filoghost.holographicdisplays.api.Hologram; +import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; +import io.github.dre2n.commons.compatibility.CompatibilityHandler; +import io.github.dre2n.commons.compatibility.Version; +import io.github.dre2n.commons.util.EnumUtil; +import io.github.dre2n.dungeonsxl.world.GameWorld; +import io.github.dre2n.itemsxl.util.commons.util.NumberUtil; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.inventory.ItemStack; + +/** + * @author Daniel Saukel + */ +public class HologramSign extends DSign { + + private DSignType type = DSignTypeDefault.HOLOGRAM; + + private Hologram hologram; + + public HologramSign(Sign sign, String[] lines, GameWorld gameWorld) { + super(sign, lines, gameWorld); + } + + @Override + public boolean check() { + return true; + } + + @Override + @SuppressWarnings("deprecation") + public void onInit() { + getSign().setType(Material.AIR); + + String[] holoLines = lines[1].split("/"); + Location location = getSign().getLocation(); + location = location.add(0, NumberUtil.parseDouble(lines[2]), 0); + + hologram = HologramsAPI.createHologram(plugin, location); + for (String line : holoLines) { + if (line.startsWith("Item:")) { + String id = line.replace("Item:", ""); + ItemStack item; + + if (Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) { + item = plugin.getCaliburnAPI().getItems().getById(id).toItemStack(1); + + } else if (EnumUtil.isValidEnum(Material.class, id)) { + item = new ItemStack(Material.valueOf(id)); + + } else { + item = new ItemStack(NumberUtil.parseInt(id)); + } + + hologram.appendItemLine(item); + + } else { + hologram.appendTextLine(ChatColor.translateAlternateColorCodes('&', line)); + } + } + } + + @Override + public DSignType getType() { + return type; + } + +} From 84ba83b143710a40216cef70951e8f0cc44752be Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 20 Jun 2016 17:31:08 +0200 Subject: [PATCH 10/21] Use GameWorld object to store triggers instead of a Map --- .../dungeonsxl/listener/PlayerListener.java | 36 ++++++----- .../io/github/dre2n/dungeonsxl/mob/DMob.java | 2 +- .../dre2n/dungeonsxl/sign/OpenDoorSign.java | 8 +-- .../dre2n/dungeonsxl/sign/TriggerSign.java | 4 +- .../dungeonsxl/trigger/DistanceTrigger.java | 44 +------------ .../dungeonsxl/trigger/InteractTrigger.java | 57 +++++------------ .../dre2n/dungeonsxl/trigger/MobTrigger.java | 42 +++---------- .../dungeonsxl/trigger/ProgressTrigger.java | 33 +--------- .../dungeonsxl/trigger/RedstoneTrigger.java | 52 +++------------- .../dre2n/dungeonsxl/trigger/SignTrigger.java | 42 +++---------- .../dre2n/dungeonsxl/trigger/Trigger.java | 12 ++-- .../dungeonsxl/trigger/UseItemTrigger.java | 45 +++----------- .../dre2n/dungeonsxl/trigger/WaveTrigger.java | 34 +---------- .../dre2n/dungeonsxl/world/GameWorld.java | 61 +++++++++++++++++-- 14 files changed, 139 insertions(+), 333 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index d52434bd..6956816a 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -235,28 +235,26 @@ public class PlayerListener implements Listener { GameWorld gameWorld = GameWorld.getByWorld(player.getWorld()); if (gameWorld != null) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) { - if (UseItemTrigger.hasTriggers(gameWorld)) { - String name = null; - if (item.hasItemMeta()) { - if (item.getItemMeta().hasDisplayName()) { - name = item.getItemMeta().getDisplayName(); + String name = null; + if (item.hasItemMeta()) { + if (item.getItemMeta().hasDisplayName()) { + name = item.getItemMeta().getDisplayName(); - } else if (item.getType() == Material.WRITTEN_BOOK || item.getType() == Material.BOOK_AND_QUILL) { - if (item.getItemMeta() instanceof BookMeta) { - BookMeta meta = (BookMeta) item.getItemMeta(); - if (meta.hasTitle()) { - name = meta.getTitle(); - } + } else if (item.getType() == Material.WRITTEN_BOOK || item.getType() == Material.BOOK_AND_QUILL) { + if (item.getItemMeta() instanceof BookMeta) { + BookMeta meta = (BookMeta) item.getItemMeta(); + if (meta.hasTitle()) { + name = meta.getTitle(); } } } - if (name == null) { - name = item.getType().toString(); - } - UseItemTrigger trigger = UseItemTrigger.get(name, gameWorld); - if (trigger != null) { - trigger.onTrigger(player); - } + } + if (name == null) { + name = item.getType().toString(); + } + UseItemTrigger trigger = UseItemTrigger.getByName(name, gameWorld); + if (trigger != null) { + trigger.onTrigger(player); } } } @@ -289,7 +287,7 @@ public class PlayerListener implements Listener { if (gameWorld != null) { // Trigger InteractTrigger - InteractTrigger trigger = InteractTrigger.get(clickedBlock, gameWorld); + InteractTrigger trigger = InteractTrigger.getByBlock(clickedBlock, gameWorld); if (trigger != null) { if (event.getAction() == Action.LEFT_CLICK_BLOCK) { trigger.onTrigger(player); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/mob/DMob.java b/src/main/java/io/github/dre2n/dungeonsxl/mob/DMob.java index 48588b53..5eb41673 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/mob/DMob.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/mob/DMob.java @@ -136,7 +136,7 @@ public class DMob { name = victim.getType().getName(); } - MobTrigger mobTrigger = MobTrigger.get(name, gameWorld); + MobTrigger mobTrigger = MobTrigger.getByName(name, gameWorld); if (mobTrigger != null) { mobTrigger.onTrigger(); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java index 8c003f49..7e5b8c3d 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java @@ -92,11 +92,9 @@ public class OpenDoorSign extends DSign { GameWorld gameWorld = GameWorld.getByWorld(block.getWorld()); if (gameWorld != null) { - for (DSign dSign : gameWorld.getDSigns()) { - if (dSign.getType() == DSignTypeDefault.OPEN_DOOR) { - if (((OpenDoorSign) dSign).getBlock().equals(block)) { - return true; - } + for (DSign dSign : gameWorld.getDSigns(DSignTypeDefault.OPEN_DOOR)) { + if (((OpenDoorSign) dSign).getBlock().equals(block)) { + return true; } } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/TriggerSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/TriggerSign.java index a088bcc7..52c919d1 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/TriggerSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/TriggerSign.java @@ -100,7 +100,7 @@ public class TriggerSign extends DSign { return; } - SignTrigger trigger = SignTrigger.get(triggerId, getGameWorld()); + SignTrigger trigger = SignTrigger.getById(triggerId, getGameWorld()); if (trigger != null) { trigger.onTrigger(true); } @@ -112,7 +112,7 @@ public class TriggerSign extends DSign { return; } - SignTrigger trigger = SignTrigger.get(triggerId, getGameWorld()); + SignTrigger trigger = SignTrigger.getById(triggerId, getGameWorld()); if (trigger != null) { trigger.onTrigger(false); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/DistanceTrigger.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/DistanceTrigger.java index ebe32df3..f7b6e903 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/trigger/DistanceTrigger.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/DistanceTrigger.java @@ -18,9 +18,6 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import io.github.dre2n.dungeonsxl.world.GameWorld; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -29,8 +26,6 @@ import org.bukkit.entity.Player; */ public class DistanceTrigger extends Trigger { - private static Map> triggers = new HashMap<>(); - private TriggerType type = TriggerTypeDefault.DISTANCE; private int distance = 5; @@ -60,56 +55,23 @@ public class DistanceTrigger extends Trigger { 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; } + /* Statics */ public static void triggerAllInDistance(Player player, GameWorld gameWorld) { - if (!hasTriggers(gameWorld)) { - return; - } - if (!player.getLocation().getWorld().equals(gameWorld.getWorld())) { return; } - for (DistanceTrigger trigger : getTriggersArray(gameWorld)) { + for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.DISTANCE)) { + DistanceTrigger trigger = (DistanceTrigger) uncasted; if (player.getLocation().distance(trigger.loc) < trigger.distance) { trigger.onTrigger(player); } } } - public static boolean hasTriggers(GameWorld gameWorld) { - return !triggers.isEmpty() && triggers.containsKey(gameWorld); - } - - public static ArrayList getTriggers(GameWorld gameWorld) { - return triggers.get(gameWorld); - } - - public static DistanceTrigger[] getTriggersArray(GameWorld gameWorld) { - return getTriggers(gameWorld).toArray(new DistanceTrigger[getTriggers(gameWorld).size()]); - } - } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/InteractTrigger.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/InteractTrigger.java index 852d3126..4d99444d 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/trigger/InteractTrigger.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/InteractTrigger.java @@ -18,9 +18,6 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import io.github.dre2n.dungeonsxl.world.GameWorld; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -29,8 +26,6 @@ import org.bukkit.entity.Player; */ public class InteractTrigger extends Trigger { - private static Map> triggers = new HashMap<>(); - private TriggerType type = TriggerTypeDefault.INTERACT; private int interactId; @@ -54,35 +49,17 @@ public class InteractTrigger extends Trigger { 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; } + /* Statics */ public static InteractTrigger getOrCreate(int id, GameWorld gameWorld) { if (id == 0) { return null; } - InteractTrigger trigger = get(id, gameWorld); + InteractTrigger trigger = getById(id, gameWorld); if (trigger != null) { return trigger; } @@ -90,7 +67,7 @@ public class InteractTrigger extends Trigger { } public static InteractTrigger getOrCreate(int id, Block block, GameWorld gameWorld) { - InteractTrigger trigger = get(id, gameWorld); + InteractTrigger trigger = getById(id, gameWorld); if (trigger != null) { trigger.interactBlock = block; return trigger; @@ -98,34 +75,28 @@ public class InteractTrigger extends Trigger { return new InteractTrigger(id, block); } - public static InteractTrigger get(Block block, GameWorld gameWorld) { - if (hasTriggers(gameWorld)) { - for (InteractTrigger trigger : triggers.get(gameWorld)) { - if (trigger.interactBlock != null) { - if (trigger.interactBlock.equals(block)) { - return trigger; - } + public static InteractTrigger getByBlock(Block block, GameWorld gameWorld) { + for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.INTERACT)) { + InteractTrigger trigger = (InteractTrigger) uncasted; + if (trigger.interactBlock != null) { + if (trigger.interactBlock.equals(block)) { + return trigger; } } } return null; } - public static InteractTrigger get(int id, GameWorld gameWorld) { + public static InteractTrigger getById(int id, GameWorld gameWorld) { if (id != 0) { - if (hasTriggers(gameWorld)) { - for (InteractTrigger trigger : triggers.get(gameWorld)) { - if (trigger.interactId == id) { - return trigger; - } + for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.INTERACT)) { + InteractTrigger trigger = (InteractTrigger) uncasted; + if (trigger.interactId == id) { + return trigger; } } } return null; } - public static boolean hasTriggers(GameWorld gameWorld) { - return !triggers.isEmpty() && triggers.containsKey(gameWorld); - } - } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/MobTrigger.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/MobTrigger.java index dc879dc0..374bbc6c 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/trigger/MobTrigger.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/MobTrigger.java @@ -18,17 +18,12 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import io.github.dre2n.dungeonsxl.world.GameWorld; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; /** * @author Frank Baumann, Daniel Saukel */ public class MobTrigger extends Trigger { - private static Map> triggers = new HashMap<>(); - private TriggerType type = TriggerTypeDefault.MOB; private String name; @@ -49,51 +44,28 @@ public class MobTrigger extends Trigger { 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; } + /* Statics */ public static MobTrigger getOrCreate(String name, GameWorld gameWorld) { - MobTrigger trigger = get(name, gameWorld); + MobTrigger trigger = getByName(name, gameWorld); if (trigger != null) { return trigger; } return new MobTrigger(name); } - public static MobTrigger get(String name, GameWorld gameWorld) { - if (hasTriggers(gameWorld)) { - for (MobTrigger trigger : triggers.get(gameWorld)) { - if (trigger.name.equalsIgnoreCase(name)) { - return trigger; - } + public static MobTrigger getByName(String name, GameWorld gameWorld) { + for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.MOB)) { + MobTrigger trigger = (MobTrigger) uncasted; + if (trigger.name.equalsIgnoreCase(name)) { + return trigger; } } return null; } - public static boolean hasTriggers(GameWorld gameWorld) { - return !triggers.isEmpty() && triggers.containsKey(gameWorld); - } - } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/ProgressTrigger.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/ProgressTrigger.java index 0c149de6..41f552a3 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/trigger/ProgressTrigger.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/ProgressTrigger.java @@ -18,10 +18,7 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import io.github.dre2n.dungeonsxl.world.GameWorld; -import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; -import java.util.Map; import java.util.Set; /** @@ -29,8 +26,6 @@ import java.util.Set; */ public class ProgressTrigger extends Trigger { - private static Map> triggers = new HashMap<>(); - private TriggerType type = TriggerTypeDefault.PROGRESS; private String floor; @@ -105,30 +100,12 @@ public class ProgressTrigger extends Trigger { 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; } + /* Statics */ public static ProgressTrigger getOrCreate(int floorCount, int waveCount, GameWorld gameWorld) { if (floorCount == 0 & waveCount == 0 || floorCount < 0 || waveCount < 0) { return null; @@ -142,14 +119,10 @@ public class ProgressTrigger extends Trigger { public static Set getByGameWorld(GameWorld gameWorld) { Set toReturn = new HashSet<>(); - for (ProgressTrigger trigger : triggers.get(gameWorld)) { - toReturn.add(trigger); + for (Trigger trigger : gameWorld.getTriggers(TriggerTypeDefault.PROGRESS)) { + toReturn.add((ProgressTrigger) trigger); } return toReturn; } - public static boolean hasTriggers(GameWorld gameWorld) { - return !triggers.isEmpty() && triggers.containsKey(gameWorld); - } - } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/RedstoneTrigger.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/RedstoneTrigger.java index e02de200..bfdf38e3 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/trigger/RedstoneTrigger.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/RedstoneTrigger.java @@ -18,9 +18,6 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import io.github.dre2n.dungeonsxl.world.GameWorld; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -31,8 +28,6 @@ import org.bukkit.block.Sign; */ public class RedstoneTrigger extends Trigger { - private static Map> triggers = new HashMap<>(); - private TriggerType type = TriggerTypeDefault.REDSTONE; private Block rtBlock; @@ -61,30 +56,12 @@ public class RedstoneTrigger extends Trigger { } } - @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; } + /* Statics */ public static RedstoneTrigger getOrCreate(Sign sign, GameWorld gameWorld) { Block rtBlock = null; if (sign.getBlock().getType() == Material.WALL_SIGN) { @@ -108,11 +85,10 @@ public class RedstoneTrigger extends Trigger { } if (rtBlock != null) { - if (hasTriggers(gameWorld)) { - for (RedstoneTrigger trigger : getTriggers(gameWorld)) { - if (trigger.rtBlock.equals(rtBlock)) { - return trigger; - } + for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.REDSTONE)) { + RedstoneTrigger trigger = (RedstoneTrigger) uncasted; + if (trigger.rtBlock.equals(rtBlock)) { + return trigger; } } return new RedstoneTrigger(rtBlock); @@ -121,23 +97,9 @@ public class RedstoneTrigger extends Trigger { } public static void updateAll(GameWorld gameWorld) { - if (hasTriggers(gameWorld)) { - for (RedstoneTrigger trigger : getTriggersArray(gameWorld)) { - trigger.onTrigger(); - } + for (Trigger trigger : gameWorld.getTriggers(TriggerTypeDefault.REDSTONE)) { + ((RedstoneTrigger) trigger).onTrigger(); } } - public static boolean hasTriggers(GameWorld gameWorld) { - return !triggers.isEmpty() && triggers.containsKey(gameWorld); - } - - public static ArrayList getTriggers(GameWorld gameWorld) { - return triggers.get(gameWorld); - } - - public static RedstoneTrigger[] getTriggersArray(GameWorld gameWorld) { - return getTriggers(gameWorld).toArray(new RedstoneTrigger[getTriggers(gameWorld).size()]); - } - } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/SignTrigger.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/SignTrigger.java index f44eabf2..15e52dbf 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/trigger/SignTrigger.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/SignTrigger.java @@ -18,17 +18,12 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import io.github.dre2n.dungeonsxl.world.GameWorld; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; /** * @author Frank Baumann, Daniel Saukel */ public class SignTrigger extends Trigger { - private static Map> triggers = new HashMap<>(); - private TriggerType type = TriggerTypeDefault.SIGN; private int stId; @@ -51,51 +46,28 @@ public class SignTrigger extends Trigger { } } - @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; } + /* Statics */ public static SignTrigger getOrCreate(int id, GameWorld gameWorld) { - SignTrigger trigger = get(id, gameWorld); + SignTrigger trigger = getById(id, gameWorld); if (trigger != null) { return trigger; } return new SignTrigger(id); } - public static SignTrigger get(int id, GameWorld gameWorld) { - if (hasTriggers(gameWorld)) { - for (SignTrigger trigger : triggers.get(gameWorld)) { - if (trigger.stId == id) { - return trigger; - } + public static SignTrigger getById(int id, GameWorld gameWorld) { + for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.SIGN)) { + SignTrigger trigger = (SignTrigger) uncasted; + if (trigger.stId == id) { + return trigger; } } return null; } - public static boolean hasTriggers(GameWorld gameWorld) { - return !triggers.isEmpty() && triggers.containsKey(gameWorld); - } - } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/Trigger.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/Trigger.java index 7d1ac506..66ada342 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/trigger/Trigger.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/Trigger.java @@ -113,6 +113,14 @@ public abstract class Trigger { } } + public void register(GameWorld gameWorld) { + gameWorld.addTrigger(this); + } + + public void unregister(GameWorld gameWorld) { + gameWorld.removeTrigger(this); + } + public static Trigger getOrCreate(String identifier, String value, DSign dSign) { TriggerType type = plugin.getTriggers().getByIdentifier(identifier); Trigger trigger = null; @@ -199,10 +207,6 @@ public abstract class Trigger { } /* Abstracts */ - public abstract void register(GameWorld gameWorld); - - public abstract void unregister(GameWorld gameWorld); - public abstract TriggerType getType(); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/UseItemTrigger.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/UseItemTrigger.java index 9fb8e056..05c5b63d 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/trigger/UseItemTrigger.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/UseItemTrigger.java @@ -18,9 +18,6 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import io.github.dre2n.dungeonsxl.world.GameWorld; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -29,8 +26,6 @@ import org.bukkit.entity.Player; */ public class UseItemTrigger extends Trigger { - private static Map> triggers = new HashMap<>(); - private TriggerType type = TriggerTypeDefault.USE_ITEM; private String name; @@ -57,54 +52,32 @@ public class UseItemTrigger extends Trigger { 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; } + /* Statics */ public static UseItemTrigger getOrCreate(String name, GameWorld gameWorld) { - UseItemTrigger trigger = get(name, gameWorld); + UseItemTrigger trigger = getByName(name, gameWorld); if (trigger != null) { return trigger; } return new UseItemTrigger(name); } - public static UseItemTrigger get(String name, GameWorld gameWorld) { - if (hasTriggers(gameWorld)) { - for (UseItemTrigger trigger : triggers.get(gameWorld)) { - if (trigger.name.equalsIgnoreCase(name)) { + public static UseItemTrigger getByName(String name, GameWorld gameWorld) { + for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.USE_ITEM)) { + UseItemTrigger trigger = (UseItemTrigger) uncasted; + if (trigger.name.equalsIgnoreCase(name)) { + return trigger; + } else if (trigger.matchedName != null) { + if (trigger.matchedName.equalsIgnoreCase(name)) { return trigger; - } else if (trigger.matchedName != null) { - if (trigger.matchedName.equalsIgnoreCase(name)) { - return trigger; - } } } } return null; } - public static boolean hasTriggers(GameWorld gameWorld) { - return !triggers.isEmpty() && triggers.containsKey(gameWorld); - } - } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/WaveTrigger.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/WaveTrigger.java index 22b401e0..1fc21c70 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/trigger/WaveTrigger.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/WaveTrigger.java @@ -18,10 +18,7 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import io.github.dre2n.dungeonsxl.world.GameWorld; -import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; -import java.util.Map; import java.util.Set; /** @@ -29,8 +26,6 @@ import java.util.Set; */ public class WaveTrigger extends Trigger { - private static Map> triggers = new HashMap<>(); - private TriggerType type = TriggerTypeDefault.WAVE; private double mustKillRate = 1; @@ -67,25 +62,6 @@ public class WaveTrigger extends Trigger { setTriggered(false); } - @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; @@ -101,17 +77,11 @@ public class WaveTrigger extends Trigger { */ public static Set getByGameWorld(GameWorld gameWorld) { Set toReturn = new HashSet<>(); - if (triggers.get(gameWorld) != null) { - for (WaveTrigger trigger : triggers.get(gameWorld)) { - toReturn.add(trigger); - } + for (Trigger trigger : gameWorld.getTriggers()) { + toReturn.add((WaveTrigger) trigger); } return toReturn; } - public static boolean hasTriggers(GameWorld gameWorld) { - return !triggers.isEmpty() && triggers.containsKey(gameWorld); - } - } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java index c54cb92d..9592f82f 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java @@ -32,12 +32,14 @@ import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.reward.RewardChest; import io.github.dre2n.dungeonsxl.sign.DSign; +import io.github.dre2n.dungeonsxl.sign.DSignType; import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; import io.github.dre2n.dungeonsxl.sign.MobSign; import io.github.dre2n.dungeonsxl.sign.StartSign; import io.github.dre2n.dungeonsxl.trigger.ProgressTrigger; import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger; import io.github.dre2n.dungeonsxl.trigger.Trigger; +import io.github.dre2n.dungeonsxl.trigger.TriggerType; import io.github.dre2n.dungeonsxl.trigger.TriggerTypeDefault; import java.io.File; import java.io.FileInputStream; @@ -74,7 +76,6 @@ public class GameWorld { private World world; private String mapName; private Location locLobby; - private Location locStart; private boolean isPlaying = false; private int id; private List secureObjects = new ArrayList<>(); @@ -85,6 +86,7 @@ public class GameWorld { // TODO: Killed mobs private CopyOnWriteArrayList rewardChests = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList dSigns = new CopyOnWriteArrayList<>(); + private CopyOnWriteArrayList triggers = new CopyOnWriteArrayList<>(); private WorldConfig worldConfig; public GameWorld() { @@ -352,6 +354,19 @@ public class GameWorld { return dSigns; } + /** + * @return the triggers with the type + */ + public List getDSigns(DSignType type) { + List dSignsOfType = new ArrayList<>(); + for (DSign dSign : dSigns) { + if (dSign.getType() == type) { + dSignsOfType.add(dSign); + } + } + return dSignsOfType; + } + /** * @param dSigns * the dSigns to set @@ -360,6 +375,42 @@ public class GameWorld { this.dSigns = dSigns; } + /** + * @return the triggers + */ + public CopyOnWriteArrayList getTriggers() { + return triggers; + } + + /** + * @return the triggers with the type + */ + public List getTriggers(TriggerType type) { + List triggersOfType = new ArrayList<>(); + for (Trigger trigger : triggers) { + if (trigger.getType() == type) { + triggersOfType.add(trigger); + } + } + return triggersOfType; + } + + /** + * @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); + } + /** * @return the potential amount of mobs in the world */ @@ -443,11 +494,11 @@ public class GameWorld { } } } - if (RedstoneTrigger.hasTriggers(this)) { - for (RedstoneTrigger trigger : RedstoneTrigger.getTriggersArray(this)) { - trigger.onTrigger(); - } + + for (Trigger trigger : getTriggers(TriggerTypeDefault.REDSTONE)) { + ((RedstoneTrigger) trigger).onTrigger(); } + for (DSign dSign : dSigns) { if (dSign != null) { if (!dSign.hasTriggers()) { From f317c687ecc4aae152558a7c2dcf3471b720a5d0 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 20 Jun 2016 17:55:50 +0200 Subject: [PATCH 11/21] Fixed BRCommons package relocation --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 87a0c76f..16a48276 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.github.dre2n dungeonsxl - 0.13-SNAPSHOT${buildNo} + 0.13${buildNo} jar DungeonsXL https://dre2n.github.io @@ -47,7 +47,7 @@ io.github.dre2n.commons - io.github.dre2n.util.commons + io.github.dre2n.dungeonsxl.util.commons io.github.dre2n.caliburn From a4d583532f11c3ef7946634af8ab41316496c78f Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 20 Jun 2016 18:05:03 +0200 Subject: [PATCH 12/21] Fix imports --- .../java/io/github/dre2n/dungeonsxl/sign/HologramSign.java | 2 +- .../io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java | 6 +++--- .../java/io/github/dre2n/dungeonsxl/sign/ReadySign.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java index f5b431a2..febbd191 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java @@ -21,8 +21,8 @@ import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; import io.github.dre2n.commons.compatibility.CompatibilityHandler; import io.github.dre2n.commons.compatibility.Version; import io.github.dre2n.commons.util.EnumUtil; +import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.dungeonsxl.world.GameWorld; -import io.github.dre2n.itemsxl.util.commons.util.NumberUtil; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java index ec5a8867..da4e58ea 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java @@ -16,14 +16,14 @@ */ package io.github.dre2n.dungeonsxl.sign; +import io.github.dre2n.commons.util.EnumUtil; +import io.github.dre2n.commons.util.NumberUtil; +import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.world.GameWorld; -import io.github.dre2n.itemsxl.util.commons.util.EnumUtil; -import io.github.dre2n.itemsxl.util.commons.util.NumberUtil; -import io.github.dre2n.itemsxl.util.commons.util.messageutil.MessageUtil; import org.bukkit.Material; import org.bukkit.block.Sign; import org.bukkit.entity.Player; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java index 6f85a6b3..8286ffb2 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java @@ -16,6 +16,7 @@ */ package io.github.dre2n.dungeonsxl.sign; +import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.game.Game; @@ -25,7 +26,6 @@ import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; import io.github.dre2n.dungeonsxl.util.ProgressBar; import io.github.dre2n.dungeonsxl.world.GameWorld; -import io.github.dre2n.itemsxl.util.commons.util.NumberUtil; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Sign; From c0736be0ae073cc00cc82a551c3766b4866983af Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 20 Jun 2016 18:20:50 +0200 Subject: [PATCH 13/21] Ready sign: Don't show multiple and unnecessary progress bars --- .../io/github/dre2n/dungeonsxl/sign/ReadySign.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java index 8286ffb2..9df76d4e 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java @@ -23,6 +23,7 @@ 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.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; import io.github.dre2n.dungeonsxl.util.ProgressBar; import io.github.dre2n.dungeonsxl.world.GameWorld; @@ -41,6 +42,7 @@ public class ReadySign extends DSign { private GameType gameType; private double autoStart = -1; + private boolean triggered = false; public ReadySign(Sign sign, String[] lines, GameWorld gameWorld) { super(sign, lines, gameWorld); @@ -116,7 +118,9 @@ public class ReadySign extends DSign { public boolean onPlayerTrigger(Player player) { ready(DGamePlayer.getByPlayer(player)); - if (autoStart >= 0) { + if (!triggered && autoStart >= 0) { + triggered = true; + new BukkitRunnable() { @Override public void run() { @@ -124,7 +128,9 @@ public class ReadySign extends DSign { } }.runTaskLater(plugin, (long) (autoStart * 20)); - ProgressBar.sendProgressBar(getGame().getPlayers(), (int) Math.ceil(autoStart)); + if (!DGroup.getByPlayer(player).isPlaying()) { + ProgressBar.sendProgressBar(getGame().getPlayers(), (int) Math.ceil(autoStart)); + } } return true; From 511725f091bcf780e02eb646e03d9980e1e14f98 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 20 Jun 2016 18:57:53 +0200 Subject: [PATCH 14/21] Update to Caliburn 0.1.6 --- pom.xml | 4 ++-- src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 16a48276..6a803a99 100644 --- a/pom.xml +++ b/pom.xml @@ -87,12 +87,12 @@ io.github.dre2n caliburn - 0.1.5 + 0.1.6 io.github.dre2n itemsxl - 0.1.5 + 0.1.6 io.github.dre2n diff --git a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index 72e6f556..7f74c90a 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -17,10 +17,6 @@ package io.github.dre2n.dungeonsxl; import io.github.dre2n.caliburn.CaliburnAPI; -import io.github.dre2n.caliburn.item.ItemCategories; -import io.github.dre2n.caliburn.item.Items; -import io.github.dre2n.caliburn.mob.MobCategories; -import io.github.dre2n.caliburn.mob.Mobs; import io.github.dre2n.commons.command.BRCommands; import io.github.dre2n.commons.compatibility.Internals; import io.github.dre2n.commons.compatibility.Version; @@ -63,8 +59,6 @@ import io.github.dre2n.itemsxl.ItemsXL; import java.io.File; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.HandlerList; import org.bukkit.scheduler.BukkitTask; @@ -334,8 +328,7 @@ public class DungeonsXL extends BRPlugin { caliburn = ItemsXL.getInstance().getAPI(); } else { caliburn = new CaliburnAPI(this); - ConfigurationSection placeholder = new YamlConfiguration(); - caliburn.setup(new Items(caliburn), new Mobs(caliburn), new ItemCategories(caliburn, placeholder), new MobCategories(caliburn, placeholder)); + caliburn.setupClean(); } } From 882393a0276e67195b7a874332949bb26911d1ac Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 21 Jun 2016 12:45:58 +0200 Subject: [PATCH 15/21] Fixed hologram sign --- .../dre2n/dungeonsxl/sign/HologramSign.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java index febbd191..1ff47521 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java @@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.sign; import com.gmail.filoghost.holographicdisplays.api.Hologram; import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; +import io.github.dre2n.caliburn.item.UniversalItem; import io.github.dre2n.commons.compatibility.CompatibilityHandler; import io.github.dre2n.commons.compatibility.Version; import io.github.dre2n.commons.util.EnumUtil; @@ -50,26 +51,32 @@ public class HologramSign extends DSign { @Override @SuppressWarnings("deprecation") public void onInit() { - getSign().setType(Material.AIR); + getSign().getBlock().setType(Material.AIR); String[] holoLines = lines[1].split("/"); Location location = getSign().getLocation(); - location = location.add(0, NumberUtil.parseDouble(lines[2]), 0); + location = location.add(0.5, NumberUtil.parseDouble(lines[2]), 0.5); hologram = HologramsAPI.createHologram(plugin, location); for (String line : holoLines) { if (line.startsWith("Item:")) { String id = line.replace("Item:", ""); - ItemStack item; + ItemStack item = null; if (Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) { - item = plugin.getCaliburnAPI().getItems().getById(id).toItemStack(1); + UniversalItem universalItem = plugin.getCaliburnAPI().getItems().getById(id); + if (universalItem != null) { + item = universalItem.toItemStack(1); + } + } - } else if (EnumUtil.isValidEnum(Material.class, id)) { - item = new ItemStack(Material.valueOf(id)); + if (item == null) { + if (EnumUtil.isValidEnum(Material.class, id)) { + item = new ItemStack(Material.valueOf(id)); - } else { - item = new ItemStack(NumberUtil.parseInt(id)); + } else { + item = new ItemStack(NumberUtil.parseInt(id, 1)); + } } hologram.appendItemLine(item); From 101c821af6cddc0f9092cdbef24ba8657f51d836 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 21 Jun 2016 13:55:53 +0200 Subject: [PATCH 16/21] Lives modifier sign: Added dying if no lives are left --- .../dre2n/dungeonsxl/listener/PlayerListener.java | 11 +---------- .../dre2n/dungeonsxl/player/DGamePlayer.java | 14 ++++++++++++++ .../dre2n/dungeonsxl/sign/LivesModifierSign.java | 4 ++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 6956816a..37b8e619 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -134,16 +134,7 @@ public class PlayerListener implements Listener { } if (dPlayer.getLives() == 0 && dPlayer.isReady()) { - DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(dPlayer, DPlayerKickEvent.Cause.DEATH); - plugin.getServer().getPluginManager().callEvent(dPlayerKickEvent); - - if (!dPlayerKickEvent.isCancelled()) { - MessageUtil.broadcastMessage(DMessages.PLAYER_DEATH_KICK.getMessage(player.getName())); - dPlayer.leave(); - if (game.getRules().getKeepInventoryOnEscape()) { - dPlayer.applyRespawnInventory(); - } - } + dPlayer.kill(); } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 30d8a84e..46e12d60 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -456,6 +456,20 @@ public class DGamePlayer extends DInstancePlayer { } } + public void kill() { + DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(this, DPlayerKickEvent.Cause.DEATH); + plugin.getServer().getPluginManager().callEvent(dPlayerKickEvent); + + if (!dPlayerKickEvent.isCancelled()) { + MessageUtil.broadcastMessage(DMessages.PLAYER_DEATH_KICK.getMessage(player.getName())); + GameRules rules = Game.getByPlayer(player).getRules(); + leave(); + if (rules.getKeepInventoryOnEscape() && rules.getKeepInventoryOnDeath()) { + applyRespawnInventory(); + } + } + } + public boolean checkRequirements(Game game) { if (DPermissions.hasPermission(player, DPermissions.IGNORE_REQUIREMENTS)) { return true; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java index da4e58ea..5c2e73c9 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/LivesModifierSign.java @@ -113,6 +113,10 @@ public class LivesModifierSign extends DSign { } else { MessageUtil.sendMessage(dPlayer.getPlayer(), DMessages.PLAYER_LIVES_REMOVED.getMessage(String.valueOf(-1 * lives))); } + + if (dPlayer.getLives() <= 0) { + dPlayer.kill(); + } } @Override From fccaed5bb987f5fb4ea3d485181fdc81b80c24e6 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 21 Jun 2016 13:56:09 +0200 Subject: [PATCH 17/21] Fixed NPE --- .../java/io/github/dre2n/dungeonsxl/sign/ReadySign.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java index 9df76d4e..fc146470 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java @@ -19,7 +19,6 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.config.DMessages; -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.player.DGamePlayer; @@ -138,7 +137,11 @@ public class ReadySign extends DSign { @Override public void onTrigger() { - for (Player player : Game.getByGameWorld(getGameWorld()).getPlayers()) { + if (getGame() == null) { + return; + } + + for (Player player : getGame().getPlayers()) { ready(DGamePlayer.getByPlayer(player)); } } From d7dce66347c0086aa3bacd136d2def73b38a6395 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 21 Jun 2016 14:17:11 +0200 Subject: [PATCH 18/21] Add interval and stack size to drop sign --- .../dre2n/dungeonsxl/sign/DropSign.java | 21 +++++++- .../dre2n/dungeonsxl/task/DropItemTask.java | 48 +++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/task/DropItemTask.java diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/DropSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/DropSign.java index d530ad54..25e32dec 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/DropSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/DropSign.java @@ -18,7 +18,9 @@ package io.github.dre2n.dungeonsxl.sign; import io.github.dre2n.caliburn.item.UniversalItem; import io.github.dre2n.commons.util.NumberUtil; +import io.github.dre2n.dungeonsxl.task.DropItemTask; import io.github.dre2n.dungeonsxl.world.GameWorld; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Sign; import org.bukkit.inventory.ItemStack; @@ -31,6 +33,7 @@ public class DropSign extends DSign { private DSignType type = DSignTypeDefault.DROP; private ItemStack item; + private double interval = -1; public DropSign(Sign sign, String[] lines, GameWorld gameWorld) { super(sign, lines, gameWorld); @@ -61,13 +64,27 @@ public class DropSign extends DSign { @Override public void onInit() { UniversalItem item = plugin.getCaliburnAPI().getItems().getById(lines[1]); - this.item = item.toItemStack(NumberUtil.parseInt(lines[2], 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(Material.AIR); } @Override public void onTrigger() { - getSign().getWorld().dropItem(getSign().getLocation(), item); + Location spawnLocation = getSign().getLocation().add(0.5, 0, 0.5); + if (interval < 0) { + getSign().getWorld().dropItem(spawnLocation, item); + + } else { + new DropItemTask(item, spawnLocation).runTaskTimer(plugin, 0, (long) interval * 20); + } } @Override diff --git a/src/main/java/io/github/dre2n/dungeonsxl/task/DropItemTask.java b/src/main/java/io/github/dre2n/dungeonsxl/task/DropItemTask.java new file mode 100644 index 00000000..24b3ceaf --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/task/DropItemTask.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2012-2016 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 io.github.dre2n.dungeonsxl.task; + +import io.github.dre2n.dungeonsxl.DungeonsXL; +import org.bukkit.Location; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; + +/** + * @author Frank Baumann, Daniel Saukel + */ +public class DropItemTask extends BukkitRunnable { + + DungeonsXL plugin = DungeonsXL.getInstance(); + + private ItemStack item; + private Location location; + + public DropItemTask(ItemStack item, Location location) { + this.item = item; + this.location = location; + } + + @Override + public void run() { + try { + location.getWorld().dropItem(location, item); + } catch (NullPointerException exception) { + cancel(); + } + } + +} From b23efdb3a175a5c1f951dcabe23ca5b0aa982ae2 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 21 Jun 2016 17:57:24 +0200 Subject: [PATCH 19/21] Fix door sign (WIP) --- .../io/github/dre2n/dungeonsxl/game/Game.java | 2 +- .../dre2n/dungeonsxl/sign/OpenDoorSign.java | 37 +++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index f92abacb..07d1fef4 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -48,7 +48,7 @@ public class Game { private List dGroups = new ArrayList<>(); private boolean started; - private GameType type; + private GameType type = GameTypeDefault.DEFAULT; private GameWorld world; private GameRules rules; private int waveCount; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java index 7e5b8c3d..6ecf4111 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java @@ -20,8 +20,9 @@ import io.github.dre2n.commons.util.BlockUtil; import io.github.dre2n.dungeonsxl.world.GameWorld; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; -import org.bukkit.material.Openable; +import org.bukkit.material.Door; /** * @author Daniel Saukel @@ -30,7 +31,7 @@ public class OpenDoorSign extends DSign { private DSignType type = DSignTypeDefault.OPEN_DOOR; - private Openable block; + private Block block; public OpenDoorSign(Sign sign, String[] lines, GameWorld gameWorld) { super(sign, lines, gameWorld); @@ -38,17 +39,17 @@ public class OpenDoorSign extends DSign { /* Getters and setters */ /** - * @return the door / fence gate / ... to open; + * @return the door to open; */ - public Openable getBlock() { + public Block getBlock() { return block; } /** * @param block - * the door / fence gate / ... to open + * the door to open */ - public void setBlock(Openable block) { + public void setBlock(Block block) { this.block = block; } @@ -66,16 +67,24 @@ public class OpenDoorSign extends DSign { @Override public void onInit() { Block block = BlockUtil.getAttachedBlock(getSign().getBlock()); - if (block instanceof Openable) { - this.block = (Openable) block; + if (block.getState().getData() instanceof Door) { + if (block.getRelative(BlockFace.DOWN).getType() == block.getType()) { + this.block = block.getRelative(BlockFace.DOWN); + } else { + this.block = block; + + } } - getSign().setType(Material.AIR); + getSign().getBlock().setType(Material.AIR); } @Override public void onTrigger() { - block.setOpen(true); + if (block != null) { + ((Door) block.getState().getData()).setOpen(true); + block.getState().update(true); + } } /* Statics */ @@ -86,14 +95,12 @@ public class OpenDoorSign extends DSign { * true if the block is openable only with a sign */ public static boolean isProtected(Block block) { - if (!(block instanceof Openable)) { - return false; - } - GameWorld gameWorld = GameWorld.getByWorld(block.getWorld()); if (gameWorld != null) { for (DSign dSign : gameWorld.getDSigns(DSignTypeDefault.OPEN_DOOR)) { - if (((OpenDoorSign) dSign).getBlock().equals(block)) { + Block signBlock1 = ((OpenDoorSign) dSign).getBlock(); + Block signBlock2 = signBlock1.getRelative(BlockFace.UP); + if (block.equals(signBlock1) || block.equals(signBlock2)) { return true; } } From 3e118f688ee1ecc5395355e8ac0f3782fc5ca65c Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 22 Jun 2016 13:56:41 +0200 Subject: [PATCH 20/21] Fix game sign / portal exception --- .../dre2n/dungeonsxl/announcer/Announcer.java | 4 +- .../dre2n/dungeonsxl/command/ListCommand.java | 2 +- .../dre2n/dungeonsxl/command/PlayCommand.java | 4 +- .../dre2n/dungeonsxl/config/DMessages.java | 6 +-- .../dre2n/dungeonsxl/dungeon/Dungeons.java | 18 ++++---- .../dre2n/dungeonsxl/global/DPortal.java | 4 +- .../dre2n/dungeonsxl/global/GameSign.java | 4 +- .../dre2n/dungeonsxl/global/GroupSign.java | 2 +- .../dungeonsxl/listener/PlayerListener.java | 1 - .../dre2n/dungeonsxl/player/DGroup.java | 17 +++++-- .../github/dre2n/dungeonsxl/world/Worlds.java | 46 +++++++++++++++++++ 11 files changed, 82 insertions(+), 26 deletions(-) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/world/Worlds.java diff --git a/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java index 6c60cdd5..8b14126d 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java @@ -94,7 +94,7 @@ public class Announcer { if (multiFloor) { dungeonName = identifier; - Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + Dungeon dungeon = plugin.getDungeons().getByName(identifier); if (dungeon != null) { mapName = dungeon.getConfig().getStartFloor(); } @@ -135,7 +135,7 @@ public class Announcer { if (multiFloor) { dungeonName = identifier; - Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + Dungeon dungeon = plugin.getDungeons().getByName(identifier); if (dungeon != null) { mapName = dungeon.getConfig().getStartFloor(); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/ListCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/ListCommand.java index a336d604..81e7d338 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/command/ListCommand.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/ListCommand.java @@ -75,7 +75,7 @@ public class ListCommand extends BRCommand { if (args.length >= 2) { if (args[1].equalsIgnoreCase("dungeons") || args[1].equalsIgnoreCase("d")) { if (args.length >= 3) { - Dungeon dungeon = plugin.getDungeons().getDungeon(args[2]); + Dungeon dungeon = plugin.getDungeons().getByName(args[2]); if (dungeon != null) { MessageUtil.sendPluginTag(sender, plugin); MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + dungeon.getName() + " &4&l]"); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java index 553b2493..37978851 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java @@ -70,7 +70,7 @@ public class PlayCommand extends BRCommand { identifier = args[2]; mapName = identifier; if (args[1].equalsIgnoreCase("dungeon") || args[1].equalsIgnoreCase("d")) { - Dungeon dungeon = plugin.getDungeons().getDungeon(args[2]); + Dungeon dungeon = plugin.getDungeons().getByName(args[2]); if (dungeon != null) { multiFloor = true; mapName = dungeon.getConfig().getStartFloor(); @@ -102,7 +102,7 @@ public class PlayCommand extends BRCommand { } else { dGroup.setDungeonName(identifier); - Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + Dungeon dungeon = plugin.getDungeons().getByName(identifier); if (dungeon != null) { DungeonConfig config = dungeon.getConfig(); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index abfb9cfe..db8006dc 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -56,7 +56,7 @@ public enum DMessages implements Messages { ERROR_COOLDOWN("Error_Cooldown", "&4You can only enter this dungeon every &6&v1&4 hours!"), ERROR_DISPENSER("Error_Dispenser", "&4You cannot access this dispenser!"), ERROR_DROP("Error_Drop", "&4You cannot drop safe items"), - ERROR_DUNGEON_NOT_EXIST("Error_DungeonNotExist", "&4Dungeon &6&v1&4 does not exist!"), + ERROR_DUNGEON_NOT_EXIST("Error_DungeonNotExist", "&4This dungeon does not exist."), ERROR_ENDERCHEST("Error_Enderchest", "&4You cannot use an enderchest while in a dungeon!"), ERROR_IN_GROUP("Error_InGroup", "&4The player &6&v1&4 is already member of a group."), ERROR_JOIN_GROUP("Error_JoinGroup", "&4You have to join a group first!"), @@ -139,7 +139,7 @@ public enum DMessages implements Messages { PLAYER_CHECKPOINT_REACHED("Player_CheckpointReached", "&6Checkpoint reached!"), PLAYER_DEATH("Player_Death", "&6You died, lives left: &2&v1"), PLAYER_DEATH_KICK("Player_DeathKick", "&2&v1&6 died and lost his last life."), - PLAYER_FINISHED_DUNGEON("Player_FinishedDungeon", "&6You successfully finished the Dungeon!"), + PLAYER_FINISHED_DUNGEON("Player_FinishedDungeon", "&6You successfully finished the dungeon!"), PLAYER_INVITED("Player_Invited", "&4&v1&6 invited you to the group &4&v2&6."), PLAYER_UNINVITED("Player_Uninvited", "&4&v1&6 took back your invitation to the group &4&v2&6."), PLAYER_JOIN_GROUP("Player_JoinGroup", "&6You successfully joined the group!"), @@ -150,7 +150,7 @@ public enum DMessages implements Messages { PLAYER_LIVES_REMOVED("Player_LivesRemoved", "&6You lost &4&v1&6 lives!"), PLAYER_LOOT_ADDED("Player_LootAdded", "&4&v1&6 have been added to your reward inventory!"), PLAYER_NEW_CAPTAIN("Player_NewCaptain", "&6You are now the new captain of your group."), - PLAYER_OFFLINE("Player_Offline", "&Player &4&v1&6 went offline. In &4&v2&6 seconds he will autmatically be kicked from the Dungeon!"), + PLAYER_OFFLINE("Player_Offline", "&Player &4&v1&6 went offline. In &4&v2&6 seconds he will autmatically be kicked from the dungeon!"), PLAYER_OFFLINE_NEVER("Player_OfflineNever", "&6The player &4&v1&6 went offline. He will &4not&6 be kicked from the dungeon automatically!"), PLAYER_PORTAL_ABORT("Player_PortalAbort", "&6Portal creation cancelled!"), PLAYER_PORTAL_INTRODUCTION("Player_PortalIntroduction", "&6Click the two edges of the portal with the wooden sword!"), diff --git a/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java b/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java index 4112d33b..35b5fa10 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeons.java @@ -40,21 +40,14 @@ public class Dungeons { } } - /** - * @return the dungeons - */ - public List getDungeons() { - return dungeons; - } - /** * @param name * the name of the Dungeon * @return the Dungeon that has the name */ - public Dungeon getDungeon(String name) { + public Dungeon getByName(String name) { for (Dungeon dungeon : dungeons) { - if (dungeon.getName().equals(name)) { + if (dungeon.getName().equalsIgnoreCase(name)) { return dungeon; } } @@ -62,6 +55,13 @@ public class Dungeons { return null; } + /** + * @return the dungeons + */ + public List getDungeons() { + return dungeons; + } + /** * @param name * the name of the Dungeon diff --git a/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java b/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java index 0d4b9c16..27e428fd 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java @@ -185,13 +185,13 @@ public class DPortal extends GlobalProtection { } } - if (target == null) { + if (target == null && dGroup.getMapName() != null) { target = new GameWorld(dGroup.getMapName()); dGroup.setGameWorld(target); } if (target == null) { - MessageUtil.sendMessage(player, DMessages.ERROR_DUNGEON_NOT_EXIST.getMessage(DGroup.getByPlayer(player).getMapName())); + MessageUtil.sendMessage(player, DMessages.ERROR_DUNGEON_NOT_EXIST.getMessage()); return; } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java b/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java index 27a3466c..1d4cea42 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java @@ -63,7 +63,7 @@ public class GameSign extends GlobalProtection { this.setMultiFloor(multiFloor); if (multiFloor) { dungeonName = identifier; - Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + Dungeon dungeon = plugin.getDungeons().getByName(identifier); if (dungeon != null) { mapName = dungeon.getConfig().getStartFloor(); } else { @@ -511,6 +511,8 @@ public class GameSign extends GlobalProtection { if (topSign.getLine(0).equals(NEW_GAME)) { Game game = new Game(dGroup); + dGroup.setDungeonName(gameSign.dungeonName); + dGroup.setMapName(gameSign.mapName); gameSign.games[column] = game; gameSign.update(); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/global/GroupSign.java b/src/main/java/io/github/dre2n/dungeonsxl/global/GroupSign.java index d3cf672c..fb82873a 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/global/GroupSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/global/GroupSign.java @@ -62,7 +62,7 @@ public class GroupSign extends GlobalProtection { this.setMultiFloor(multiFloor); if (multiFloor) { dungeonName = identifier; - Dungeon dungeon = plugin.getDungeons().getDungeon(identifier); + Dungeon dungeon = plugin.getDungeons().getByName(identifier); if (dungeon != null) { mapName = dungeon.getConfig().getStartFloor(); } else { diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 37b8e619..79b554b8 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -22,7 +22,6 @@ import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.MainConfig; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerDeathEvent; -import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GameSign; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index f39fe6a7..94c17a3a 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -34,6 +34,7 @@ import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.reward.Reward; import io.github.dre2n.dungeonsxl.task.TimeIsRunningTask; import io.github.dre2n.dungeonsxl.world.GameWorld; +import io.github.dre2n.dungeonsxl.world.Worlds; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -107,7 +108,7 @@ public class DGroup { } } - dungeon = plugin.getDungeons().getDungeon(identifier); + dungeon = plugin.getDungeons().getByName(identifier); if (multiFloor && dungeon != null) { dungeonName = dungeon.getName(); mapName = dungeon.getConfig().getStartFloor(); @@ -376,7 +377,7 @@ public class DGroup { * the name of the dungeon */ public void setDungeon(String name) { - dungeon = plugin.getDungeons().getDungeon(name); + dungeon = plugin.getDungeons().getByName(name); if (dungeon != null) { dungeonName = dungeon.getName(); mapName = dungeon.getConfig().getStartFloor(); @@ -396,11 +397,15 @@ public class DGroup { } /** + * Will fail if there is no dungeon with this name. + * * @param dungeonName * the dungeonName to set */ public void setDungeonName(String dungeonName) { - this.dungeonName = dungeonName; + if (plugin.getDungeons().getByName(name) != null) { + this.dungeonName = dungeonName; + } } /** @@ -411,11 +416,15 @@ public class DGroup { } /** + * Will fail if there is no resource world with this name. + * * @param name * the name to set */ public void setMapName(String name) { - mapName = name; + if (Worlds.exists(name)) { + mapName = name; + } } /** diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/Worlds.java b/src/main/java/io/github/dre2n/dungeonsxl/world/Worlds.java new file mode 100644 index 00000000..e9d822f0 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/Worlds.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2012-2016 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 io.github.dre2n.dungeonsxl.world; + +import java.io.File; +import java.util.Set; + +/** + * @author Daniel Saukel + */ +public class Worlds { + + /*private Set resourceWorlds; + + public Worlds(File folder) { + for (File file : folder.listFiles()) { + resourceWorlds.add(new ResourceWorld()); + } + }*/ + + @Deprecated + public static boolean exists(String name) { + for (File world : io.github.dre2n.dungeonsxl.DungeonsXL.MAPS.listFiles()) { + if (world.isDirectory() && world.getName().equalsIgnoreCase(name)) { + return true; + } + } + + return false; + } + +} From 863e7742664058fae9bf8439d7b8a9e3ff492322 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 22 Jun 2016 14:29:41 +0200 Subject: [PATCH 21/21] Accept right clicks on signs --- .../java/io/github/dre2n/dungeonsxl/config/DMessages.java | 1 - .../github/dre2n/dungeonsxl/listener/PlayerListener.java | 8 ++------ src/main/resources/plugin.yml | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index db8006dc..3d3ddf4c 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -63,7 +63,6 @@ public enum DMessages implements Messages { ERROR_LEAVE_DUNGEON("Error_LeaveDungeon", "&4You have to leave your current dungeon first!"), ERROR_LEAVE_GAME("Error_LeaveGame", "&4You have to leave your current game first!"), ERROR_LEAVE_GROUP("Error_LeaveGroup", "&4You have to leave your group first!"), - ERROR_LEFT_CLICK("Error_Leftklick", "&4You have to use Left-Click on this sign!"), ERROR_MSG_ID_NOT_EXIST("Error_MsgIdNotExist", "&4Messages with Id &6&v1&4 does not exist!"), ERROR_MSG_FORMAT("Error_MsgFormat", "&4The Messages has to be between \"!"), ERROR_MSG_NO_INT("Error_MsgNoInt", "&4The argument [id] has to include a number!"), diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 79b554b8..4ad92df4 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -279,10 +279,8 @@ public class PlayerListener implements Listener { // Trigger InteractTrigger InteractTrigger trigger = InteractTrigger.getByBlock(clickedBlock, gameWorld); if (trigger != null) { - if (event.getAction() == Action.LEFT_CLICK_BLOCK) { + if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) { trigger.onTrigger(player); - } else { - MessageUtil.sendMessage(player, DMessages.ERROR_LEFT_CLICK.getMessage()); } } @@ -290,10 +288,8 @@ public class PlayerListener implements Listener { for (Sign classSign : gameWorld.getSignClass()) { if (classSign != null) { if (classSign.getLocation().distance(clickedBlock.getLocation()) < 1) { - if (event.getAction() == Action.LEFT_CLICK_BLOCK) { + if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) { dPlayer.setDClass(ChatColor.stripColor(classSign.getLine(1))); - } else { - MessageUtil.sendMessage(player, DMessages.ERROR_LEFT_CLICK.getMessage()); } return; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 83bb3d74..36c167d2 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ version: ${project.version} authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel] description: ${project.description} website: ${project.url} -softdepend: [BlueRoseCommons, CommandsXL, ItemsXL, Vault, CustomMobs, InsaneMobs, MythicMobs] +softdepend: [BlueRoseCommons, CommandsXL, ItemsXL, Vault, CustomMobs, InsaneMobs, MythicMobs, HolographicDisplays] commands: dungeonsxl: description: Reference command for DungeonsXL.