diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java
index a717c3e2..9c170c57 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java
@@ -22,7 +22,9 @@ import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.instance.edit.DEditPlayerEscapeEvent;
+import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent;
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
+import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
@@ -67,12 +69,17 @@ public class LeaveCommand extends BRCommand {
return;
}
- DEditPlayerEscapeEvent dPlayerEscapeEvent = new DEditPlayerEscapeEvent((DEditPlayer) dPlayer);
- plugin.getServer().getPluginManager().callEvent(dPlayerEscapeEvent);
+ if (dPlayer instanceof DGamePlayer) {
+ DGamePlayerEscapeEvent dPlayerEscapeEvent = new DGamePlayerEscapeEvent((DGamePlayer) dPlayer);
+ plugin.getServer().getPluginManager().callEvent(dPlayerEscapeEvent);
+ if (dPlayerEscapeEvent.isCancelled()) {
+ return;
+ }
+ }
+
DPlayerLeaveDGroupEvent dPlayerLeaveDGroupEvent = new DPlayerLeaveDGroupEvent(dPlayer, dGroup);
plugin.getServer().getPluginManager().callEvent(dPlayerLeaveDGroupEvent);
-
- if (dPlayerEscapeEvent.isCancelled() || dPlayerLeaveDGroupEvent.isCancelled()) {
+ if (dPlayerLeaveDGroupEvent.isCancelled()) {
return;
}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java
index da5c433e..61b84d0e 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java
@@ -86,6 +86,7 @@ public enum DMessages implements Messages {
ERROR_NOT_IN_GROUP("Error_NotInGroup", "&4The player &6&v1&4 is not member of the group &6&v2&v4."),
ERROR_NOT_INVITED("Error_NotInvited", "&4You are not invited to the group &6&v1&4."),
ERROR_NOT_SAVED("Error_NotSaved", "&4The map &6&v1&4 has not been saved to the &6DungeonsXL/maps/ &4folder yet!"),
+ ERROR_BLOCK_OWN_TEAM("Error_BlockOwnTeam", "&4This block belongs to your own group."),
ERROR_READY("Error_Ready", "&4Choose your class first!"),
ERROR_REQUIREMENTS("Error_Requirements", "&4You don't fulfill the requirements for this dungeon!"),
ERROR_SIGN_WRONG_FORMAT("Error_SignWrongFormat", "&4The sign is not written correctly!"),
@@ -126,8 +127,11 @@ public enum DMessages implements Messages {
HELP_CMD_SETTINGS("Help_Cmd_Settings", "/dxl settings ([edit|global|player])- Opens the settings menu"),
HELP_CMD_TEST("Help_Cmd_Test", "/dxl test - Starts the game in test mode"),
HELP_CMD_UNINVITE("Help_Cmd_Uninvite", "/dxl uninvite [player] [dungeon] - Uninvite a player to edit a dungeon"),
+ GROUP_BED_DESTROYED("Group_BedDestroyed", "&6The bed of the group &4&v1 &6has been destroyed by &4&v2&6!"),
GROUP_CREATED("Group_Created", "&4&v1&6 created the group &4&v2&6!"),
GROUP_DISBANDED("Group_Disbanded", "&4&v1&6 disbanded the group &4&v2&6."),
+ GROUP_FLAG_CAPTURED("Group_FlagCaptured", "&4&v1&6 has captured the flag of the group &4&v2&6!"),
+ GROUP_FLAG_STEALING("Group_FlagStealing", "&4&v1&6 is stealing the flag of the group &4&v2&6!"),
GROUP_INVITED_PLAYER("Group_InvitedPlayer", "&4&v1&6 invited the player &4&v2&6 to the group &4&v3&6."),
GROUP_JOINED_GAME("Group_JoinedGame", "&6Your group successfully joined the game."),
GROUP_UNINVITED_PLAYER("Group_UninvitedPlayer", "&4&v1&6 took back the invitation for &4&v2&6 to the group &4&v3&6."),
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java
index b55c7fca..cc06ca6c 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java
@@ -91,7 +91,7 @@ public class BlockListener implements Listener {
// Deny DGameWorld block breaking
DGameWorld gameWorld = DGameWorld.getByWorld(block.getWorld());
if (gameWorld != null) {
- if (gameWorld.onBreak(player, block)) {
+ if (gameWorld.onBreak(event)) {
event.setCancelled(true);
}
}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java
index 0a542f71..62a00305 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java
@@ -36,13 +36,13 @@ import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
import io.github.dre2n.dungeonsxl.player.DPermissions;
import io.github.dre2n.dungeonsxl.player.DPlayers;
import io.github.dre2n.dungeonsxl.reward.DLootInventory;
-import io.github.dre2n.dungeonsxl.world.block.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;
import io.github.dre2n.dungeonsxl.world.DEditWorld;
import io.github.dre2n.dungeonsxl.world.DGameWorld;
+import io.github.dre2n.dungeonsxl.world.block.LockedDoor;
+import io.github.dre2n.dungeonsxl.world.block.RewardChest;
import java.util.ArrayList;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@@ -117,9 +117,8 @@ public class PlayerListener implements Listener {
return;
}
- dPlayer.setLives(dPlayer.getLives() - dPlayerDeathEvent.getLostLives());
-
if (dPlayer.getLives() != -1) {
+ dPlayer.setLives(dPlayer.getLives() - dPlayerDeathEvent.getLostLives());
MessageUtil.sendMessage(player, DMessages.PLAYER_DEATH.getMessage(String.valueOf(dPlayer.getLives())));
if (game.getRules().getKeepInventoryOnDeath()) {
@@ -142,6 +141,7 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer();
DGlobalPlayer dGlobalPlayer = dPlayers.getByPlayer(player);
Block clickedBlock = event.getClickedBlock();
+ DGameWorld dGameWorld = DGameWorld.getByWorld(player.getWorld());
if (dGlobalPlayer.isInBreakMode()) {
return;
@@ -149,7 +149,7 @@ public class PlayerListener implements Listener {
if (clickedBlock != null) {
// Block Enderchests
- if (DGameWorld.getByWorld(player.getWorld()) != null || DEditWorld.getByWorld(player.getWorld()) != null) {
+ if (dGameWorld != null || DEditWorld.getByWorld(player.getWorld()) != null) {
if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
if (clickedBlock.getType() == Material.ENDER_CHEST) {
if (!DPermissions.hasPermission(player, DPermissions.BYPASS)) {
@@ -167,7 +167,7 @@ public class PlayerListener implements Listener {
}
// Block Dispensers
- if (DGameWorld.getByWorld(player.getWorld()) != null) {
+ if (dGameWorld != null) {
if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
if (clickedBlock.getType() == Material.DISPENSER) {
if (!DPermissions.hasPermission(player, DPermissions.BYPASS)) {
@@ -177,6 +177,13 @@ public class PlayerListener implements Listener {
}
}
}
+
+ for (LockedDoor door : dGameWorld.getLockedDoors()) {
+ if (clickedBlock.equals(door.getBlock()) || clickedBlock.equals(door.getAttachedBlock())) {
+ event.setCancelled(true);
+ return;
+ }
+ }
}
// Check Portals
@@ -298,9 +305,6 @@ public class PlayerListener implements Listener {
}
}
}
-
- } else if (OpenDoorSign.isProtected(clickedBlock)) {
- event.setCancelled(true);
}
}
}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java
index ff7d990a..2b989c40 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java
@@ -74,6 +74,8 @@ public class DGamePlayer extends DInstancePlayer {
private int initialLives = -1;
private int lives;
+ private DGroup stealing;
+
public DGamePlayer(Player player, DGameWorld world) {
super(player, world.getWorld());
@@ -365,6 +367,28 @@ public class DGamePlayer extends DInstancePlayer {
this.lives = lives;
}
+ /**
+ * @return if the player is stealing a flag
+ */
+ public boolean isStealing() {
+ return stealing != null;
+ }
+
+ /**
+ * @return the group whose flag is stolen
+ */
+ public DGroup getRobbedGroup() {
+ return stealing;
+ }
+
+ /**
+ * @param dGroup
+ * the group whose flag is stolen
+ */
+ public void setRobbedGroup(DGroup dGroup) {
+ stealing = dGroup;
+ }
+
/* Actions */
@Override
public void leave() {
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BedSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BedSign.java
new file mode 100644
index 00000000..89f6cd74
--- /dev/null
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/BedSign.java
@@ -0,0 +1,65 @@
+/*
+ * 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.commons.util.NumberUtil;
+import io.github.dre2n.dungeonsxl.world.DGameWorld;
+import io.github.dre2n.dungeonsxl.world.block.TeamBed;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.Sign;
+
+/**
+ * @author Daniel Saukel
+ */
+public class BedSign extends DSign {
+
+ private DSignType type = DSignTypeDefault.BED;
+
+ private int team;
+
+ public BedSign(Sign sign, String[] lines, DGameWorld gameWorld) {
+ super(sign, lines, gameWorld);
+ }
+
+ /* Getters and setters */
+ @Override
+ public DSignType getType() {
+ return type;
+ }
+
+ /* Actions */
+ @Override
+ public boolean check() {
+ return NumberUtil.parseInt(lines[1], -1) != -1;
+ }
+
+ @Override
+ public void onInit() {
+ this.team = NumberUtil.parseInt(lines[1]);
+ Block block = BlockUtil.getAttachedBlock(getSign().getBlock());
+
+ if (block.getType() == Material.BED_BLOCK) {
+ getGameWorld().addGameBlock(new TeamBed(block, getGame().getDGroups().get(team)));
+ getSign().getBlock().setType(Material.AIR);
+ } else {
+ markAsErroneous();
+ }
+ }
+
+}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ChestSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ChestSign.java
index 6816623d..ac804d9b 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ChestSign.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ChestSign.java
@@ -18,8 +18,8 @@ package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.loottable.DLootTable;
-import io.github.dre2n.dungeonsxl.reward.RewardChest;
import io.github.dre2n.dungeonsxl.world.DGameWorld;
+import io.github.dre2n.dungeonsxl.world.block.RewardChest;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
@@ -181,7 +181,7 @@ public class ChestSign extends DSign {
itemReward = list.toArray(new ItemStack[list.size()]);
}
- new RewardChest(chest, getGameWorld(), moneyReward, levelReward, itemReward);
+ getGameWorld().addGameBlock(new RewardChest(chest, moneyReward, levelReward, itemReward));
getSign().getBlock().setType(Material.AIR);
} else {
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignType.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignType.java
index fce73d99..fb5e19de 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignType.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignType.java
@@ -32,10 +32,15 @@ public interface DSignType {
public String getBuildPermission();
/**
- * @return the onDungeonInit
+ * @return if the sign gets initialized when the dungeon is loaded instead of when the game starts
*/
public boolean isOnDungeonInit();
+ /**
+ * @return if the sign block should be destroyable after the initialization
+ */
+ public boolean isProtected();
+
/**
* @return the handler
*/
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java
index b5f2b33d..f1c5f0ba 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java
@@ -23,45 +23,50 @@ import io.github.dre2n.dungeonsxl.player.DPermissions;
*/
public enum DSignTypeDefault implements DSignType {
- BLOCK("Block", "block", false, BlockSign.class),
- CHECKPOINT("Checkpoint", "checkpoint", false, CheckpointSign.class),
- CHEST("Chest", "chest", false, ChestSign.class),
- 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),
- 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),
- LOBBY("Lobby", "lobby", true, LobbySign.class),
- MOB("Mob", "mob", false, DMobSign.class),
- MESSAGE("MSG", "msg", false, MessageSign.class),
+ BED("Bed", "bed", false, false, BedSign.class),
+ BLOCK("Block", "block", false, true, BlockSign.class),
+ CHECKPOINT("Checkpoint", "checkpoint", false, false, CheckpointSign.class),
+ CHEST("Chest", "chest", false, false, ChestSign.class),
+ CHUNK_UPDATER("ChunkUpdater", "chunkupdater", true, false, ChunkUpdaterSign.class),
+ CLASSES("Classes", "classes", true, true, ClassesSign.class),
+ COMMAND("CMD", "cmd", false, false, CommandSign.class),
+ DROP("Drop", "drop", false, false, DropSign.class),
+ END("End", "end", false, true, EndSign.class),
+ EXTERNAL_MOB("ExternalMob", "mob", false, false, ExternalMobSign.class),
+ FLAG("Flag", "flag", false, false, FlagSign.class),
+ FLOOR("Floor", "floor", false, true, FloorSign.class),
+ HOLOGRAM("Hologram", "hologram", true, false, HologramSign.class),
+ INTERACT("Interact", "interact", true, true, InteractSign.class),
+ LEAVE("Leave", "leave", true, true, LeaveSign.class),
+ LIVES_MODIFIER("Lives", "lives", false, false, LivesModifierSign.class),
+ LOBBY("Lobby", "lobby", true, false, LobbySign.class),
+ MOB("Mob", "mob", false, false, DMobSign.class),
+ MESSAGE("MSG", "msg", false, 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),
- SCRIPT("Script", "script", false, ScriptSign.class),
- SOUND_MESSAGE("SoundMSG", "soundmsg", false, SoundMessageSign.class),
- START("Start", "start", true, StartSign.class),
- TELEPORT("Teleport", "teleport", false, TeleportSign.class),
- TRIGGER("Trigger", "trigger", true, TriggerSign.class),
- WAVE("Wave", "wave", false, WaveSign.class);
+ MYTHIC_MOBS("MythicMobs", "mob", false, false, ExternalMobSign.class),
+ OPEN_DOOR("Door", "door", false, false, OpenDoorSign.class),
+ PLACE("Place", "place", false, false, PlaceSign.class),
+ PROTECTION("Protection", "protection", false, false, ProtectionSign.class),
+ READY("Ready", "ready", true, true, ReadySign.class),
+ REDSTONE("Redstone", "redstone", false, false, RedstoneSign.class),
+ SCRIPT("Script", "script", false, false, ScriptSign.class),
+ SOUND_MESSAGE("SoundMSG", "soundmsg", false, false, SoundMessageSign.class),
+ START("Start", "start", true, false, StartSign.class),
+ TELEPORT("Teleport", "teleport", false, false, TeleportSign.class),
+ TRIGGER("Trigger", "trigger", true, false, TriggerSign.class),
+ WAVE("Wave", "wave", false, false, WaveSign.class);
private String name;
private String buildPermission;
private boolean onDungeonInit;
+ private boolean isProtected;
private Class extends DSign> handler;
- DSignTypeDefault(String name, String buildPermission, boolean onDungeonInit, Class extends DSign> handler) {
+ DSignTypeDefault(String name, String buildPermission, boolean onDungeonInit, boolean isProtected, Class extends DSign> handler) {
this.name = name;
this.buildPermission = buildPermission;
this.onDungeonInit = onDungeonInit;
+ this.isProtected = isProtected;
this.handler = handler;
}
@@ -80,6 +85,11 @@ public enum DSignTypeDefault implements DSignType {
return onDungeonInit;
}
+ @Override
+ public boolean isProtected() {
+ return isProtected;
+ }
+
@Override
public Class extends DSign> getHandler() {
return handler;
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java
new file mode 100644
index 00000000..28220cee
--- /dev/null
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/FlagSign.java
@@ -0,0 +1,55 @@
+/*
+ * 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.NumberUtil;
+import io.github.dre2n.dungeonsxl.world.DGameWorld;
+import io.github.dre2n.dungeonsxl.world.block.TeamFlag;
+import org.bukkit.block.Sign;
+
+/**
+ * @author Daniel Saukel
+ */
+public class FlagSign extends DSign {
+
+ private DSignType type = DSignTypeDefault.FLAG;
+
+ private int team;
+
+ public FlagSign(Sign sign, String[] lines, DGameWorld gameWorld) {
+ super(sign, lines, gameWorld);
+ }
+
+ /* Getters and setters */
+ @Override
+ public DSignType getType() {
+ return type;
+ }
+
+ /* Actions */
+ @Override
+ public boolean check() {
+ return NumberUtil.parseInt(lines[1], -1) != -1;
+ }
+
+ @Override
+ public void onInit() {
+ this.team = NumberUtil.parseInt(lines[1]);
+ getGameWorld().addGameBlock(new TeamFlag(getSign().getBlock(), team, getGame().getDGroups().get(team)));
+ }
+
+}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java
index 942b1272..ddd1033b 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/OpenDoorSign.java
@@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.commons.util.BlockUtil;
import io.github.dre2n.dungeonsxl.world.DGameWorld;
+import io.github.dre2n.dungeonsxl.world.block.LockedDoor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -31,7 +32,7 @@ public class OpenDoorSign extends DSign {
private DSignType type = DSignTypeDefault.OPEN_DOOR;
- private Block block;
+ private LockedDoor door;
public OpenDoorSign(Sign sign, String[] lines, DGameWorld gameWorld) {
super(sign, lines, gameWorld);
@@ -41,16 +42,16 @@ public class OpenDoorSign extends DSign {
/**
* @return the door to open;
*/
- public Block getBlock() {
- return block;
+ public LockedDoor getDoor() {
+ return door;
}
/**
- * @param block
+ * @param door
* the door to open
*/
- public void setBlock(Block block) {
- this.block = block;
+ public void setDoor(LockedDoor door) {
+ this.door = door;
}
@Override
@@ -69,44 +70,24 @@ public class OpenDoorSign extends DSign {
Block block = BlockUtil.getAttachedBlock(getSign().getBlock());
if (block.getState().getData() instanceof Door) {
if (block.getRelative(BlockFace.DOWN).getType() == block.getType()) {
- this.block = block.getRelative(BlockFace.DOWN);
+ door = new LockedDoor(block.getRelative(BlockFace.DOWN));
} else {
- this.block = block;
-
+ door = new LockedDoor(block);
}
- }
+ getGameWorld().addGameBlock(door);
- getSign().getBlock().setType(Material.AIR);
+ getSign().getBlock().setType(Material.AIR);
+
+ } else {
+ markAsErroneous();
+ }
}
@Override
public void onTrigger() {
- if (block != null) {
- ((Door) block.getState().getData()).setOpen(true);
- block.getState().update(true);
+ if (door != null) {
+ door.open();
}
}
- /* Statics */
- /**
- * @param block
- * the block to check
- * @return
- * true if the block is openable only with a sign
- */
- public static boolean isProtected(Block block) {
- DGameWorld gameWorld = DGameWorld.getByWorld(block.getWorld());
- if (gameWorld != null) {
- for (DSign dSign : gameWorld.getDSigns(DSignTypeDefault.OPEN_DOOR)) {
- Block signBlock1 = ((OpenDoorSign) dSign).getBlock();
- Block signBlock2 = signBlock1.getRelative(BlockFace.UP);
- if (block.equals(signBlock1) || block.equals(signBlock2)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java
index d7f830d9..0fb51287 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/PlaceSign.java
@@ -39,7 +39,7 @@ public class PlaceSign extends DSign {
@Override
public void onInit() {
- getGameWorld().getPlaceableBlocks().add(new PlaceableBlock(getSign().getBlock(), lines[1], lines[2]));
+ getGameWorld().addGameBlock(new PlaceableBlock(getSign().getBlock(), lines[1], lines[2]));
getSign().getBlock().setType(Material.AIR);
}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ProtectionSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ProtectionSign.java
new file mode 100644
index 00000000..2af4d9a4
--- /dev/null
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ProtectionSign.java
@@ -0,0 +1,54 @@
+/*
+ * 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.DGameWorld;
+import io.github.dre2n.dungeonsxl.world.block.ProtectedBlock;
+import org.bukkit.Material;
+import org.bukkit.block.Sign;
+
+/**
+ * @author Daniel Saukel
+ */
+public class ProtectionSign extends DSign {
+
+ private DSignType type = DSignTypeDefault.PROTECTION;
+
+ public ProtectionSign(Sign sign, String[] lines, DGameWorld gameWorld) {
+ super(sign, lines, gameWorld);
+ }
+
+ /* Getters and setters */
+ @Override
+ public DSignType getType() {
+ return type;
+ }
+
+ /* Actions */
+ @Override
+ public boolean check() {
+ return true;
+ }
+
+ @Override
+ public void onInit() {
+ getGameWorld().addGameBlock(new ProtectedBlock(BlockUtil.getAttachedBlock(getSign().getBlock())));
+ getSign().getBlock().setType(Material.AIR);
+ }
+
+}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java
index cc441f7b..98e1ed3d 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java
@@ -24,7 +24,6 @@ import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameRules;
import io.github.dre2n.dungeonsxl.mob.DMob;
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;
@@ -36,6 +35,13 @@ 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 io.github.dre2n.dungeonsxl.world.block.GameBlock;
+import io.github.dre2n.dungeonsxl.world.block.LockedDoor;
+import io.github.dre2n.dungeonsxl.world.block.MultiBlock;
+import io.github.dre2n.dungeonsxl.world.block.PlaceableBlock;
+import io.github.dre2n.dungeonsxl.world.block.RewardChest;
+import io.github.dre2n.dungeonsxl.world.block.TeamBed;
+import io.github.dre2n.dungeonsxl.world.block.TeamFlag;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
@@ -55,6 +61,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Spider;
+import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
@@ -69,12 +76,18 @@ public class DGameWorld extends DInstanceWorld {
// TO DO: Which lists actually need to be CopyOnWriteArrayLists?
private List placedBlocks = new LinkedList<>();
- private CopyOnWriteArrayList placeableBlocks = new CopyOnWriteArrayList<>();
+
+ private Set gameBlocks = new HashSet<>();
+ private Set lockedDoors = new HashSet<>();
+ private Set placeableBlocks = new HashSet<>();
+ private Set rewardChests = new HashSet<>();
+ private Set teamBeds = new HashSet<>();
+ private Set teamFlags = new HashSet<>();
+
private List secureObjects = new CopyOnWriteArrayList<>();
private CopyOnWriteArrayList loadedChunks = new CopyOnWriteArrayList<>();
private CopyOnWriteArrayList classesSigns = new CopyOnWriteArrayList<>();
private CopyOnWriteArrayList dMobs = new CopyOnWriteArrayList<>();
- private CopyOnWriteArrayList rewardChests = new CopyOnWriteArrayList<>();
private CopyOnWriteArrayList dSigns = new CopyOnWriteArrayList<>();
private CopyOnWriteArrayList triggers = new CopyOnWriteArrayList<>();
@@ -163,16 +176,83 @@ public class DGameWorld extends DInstanceWorld {
/**
* @return the placeableBlocks
*/
- public CopyOnWriteArrayList getPlaceableBlocks() {
+ public Set getGameBlocks() {
+ return gameBlocks;
+ }
+
+ /**
+ * @param gameBlock
+ * the gameBlock to add
+ */
+ public void addGameBlock(GameBlock gameBlock) {
+ gameBlocks.add(gameBlock);
+
+ if (gameBlock instanceof LockedDoor) {
+ lockedDoors.add((LockedDoor) gameBlock);
+ } else if (gameBlock instanceof PlaceableBlock) {
+ placeableBlocks.add((PlaceableBlock) gameBlock);
+ } else if (gameBlock instanceof RewardChest) {
+ rewardChests.add((RewardChest) gameBlock);
+ } else if (gameBlock instanceof TeamBed) {
+ teamBeds.add((TeamBed) gameBlock);
+ } else if (gameBlock instanceof TeamFlag) {
+ teamFlags.add((TeamFlag) gameBlock);
+ }
+ }
+
+ /**
+ * @param gameBlock
+ * the gameBlock to remove
+ */
+ public void removeGameBlock(GameBlock gameBlock) {
+ gameBlocks.remove(gameBlock);
+
+ if (gameBlock instanceof LockedDoor) {
+ lockedDoors.remove((LockedDoor) gameBlock);
+ } else if (gameBlock instanceof PlaceableBlock) {
+ placeableBlocks.remove((PlaceableBlock) gameBlock);
+ } else if (gameBlock instanceof RewardChest) {
+ rewardChests.remove((RewardChest) gameBlock);
+ } else if (gameBlock instanceof TeamBed) {
+ teamBeds.remove((TeamBed) gameBlock);
+ } else if (gameBlock instanceof TeamFlag) {
+ teamFlags.remove((TeamFlag) gameBlock);
+ }
+ }
+
+ /**
+ * @return the rewardChests
+ */
+ public Set getRewardChests() {
+ return rewardChests;
+ }
+
+ /**
+ * @return the locked doors
+ */
+ public Set getLockedDoors() {
+ return lockedDoors;
+ }
+
+ /**
+ * @return the placeable blocks
+ */
+ public Set getPlaceableBlocks() {
return placeableBlocks;
}
/**
- * @param placeableBlocks
- * the placeableBlocks to set
+ * @return the team beds
*/
- public void setPlaceableBlocks(CopyOnWriteArrayList placeableBlocks) {
- this.placeableBlocks = placeableBlocks;
+ public Set getTeamBeds() {
+ return teamBeds;
+ }
+
+ /**
+ * @return the team flags
+ */
+ public Set getTeamFlags() {
+ return teamFlags;
}
/**
@@ -243,21 +323,6 @@ public class DGameWorld extends DInstanceWorld {
dMobs.remove(dMob);
}
- /**
- * @return the rewardChests
- */
- public CopyOnWriteArrayList getRewardChests() {
- return rewardChests;
- }
-
- /**
- * @param rewardChests
- * the rewardChests to set
- */
- public void setRewardChests(CopyOnWriteArrayList rewardChests) {
- this.rewardChests = rewardChests;
- }
-
/**
* @return the dSigns
*/
@@ -460,16 +525,34 @@ public class DGameWorld extends DInstanceWorld {
}
}
- public boolean onBreak(Player player, Block block) {
+ /**
+ * Handles what happens when a player breaks a block.
+ *
+ * @param event
+ * the passed Bukkit event
+ * @return if the event is cancelled
+ */
+ public boolean onBreak(BlockBreakEvent event) {
+ Player player = event.getPlayer();
+ Block block = event.getBlock();
for (DSign dSign : dSigns) {
- if (dSign.getSign().getBlock().equals(block)) {
+ if (block.equals(dSign.getSign().getBlock()) && dSign.getType().isProtected()) {
return true;
}
}
- for (RewardChest rChest : rewardChests) {
- if (rChest.getChest().getBlock().equals(block)) {
- return true;
+ for (GameBlock gameBlock : gameBlocks) {
+ if (block.equals(gameBlock.getBlock())) {
+ if (gameBlock.onBreak(event)) {
+ return true;
+ }
+
+ } else if (gameBlock instanceof MultiBlock) {
+ if (block.equals(((MultiBlock) gameBlock).getAttachedBlock())) {
+ if (gameBlock.onBreak(event)) {
+ return true;
+ }
+ }
}
}
@@ -505,6 +588,16 @@ public class DGameWorld extends DInstanceWorld {
return true;
}
+ /**
+ * Handles what happens when a player places a block.
+ *
+ * @param player
+ * @param block
+ * @param against
+ * @param hand
+ * the event parameters.
+ * @return if the event is cancelled
+ */
public boolean onPlace(Player player, Block block, Block against, ItemStack hand) {
// Workaround for a bug that would allow 3-Block-high jumping
Location loc = player.getLocation();
@@ -525,7 +618,7 @@ public class DGameWorld extends DInstanceWorld {
}
GameRules rules = game.getRules();
- if (!rules.canPlaceBlocks() && !GamePlaceableBlock.canBuildHere(block, block.getFace(against), hand.getType(), this)) {
+ if (!rules.canPlaceBlocks() && !PlaceableBlock.canBuildHere(block, block.getFace(against), hand.getType(), this)) {
return true;
}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/GameBlock.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/GameBlock.java
new file mode 100644
index 00000000..307d7244
--- /dev/null
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/GameBlock.java
@@ -0,0 +1,59 @@
+/*
+ * 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.block;
+
+import org.bukkit.block.Block;
+import org.bukkit.event.block.BlockBreakEvent;
+
+/**
+ * @author Daniel Saukel
+ */
+public abstract class GameBlock {
+
+ protected Block block;
+
+ public GameBlock(Block block) {
+ this.block = block;
+ }
+
+ /* Getters and setters */
+ /**
+ * @return the block
+ */
+ public Block getBlock() {
+ return block;
+ }
+
+ /**
+ * @param block
+ * the block to set
+ */
+ public void setBlock(Block block) {
+ this.block = block;
+ }
+
+ /* Abstracts */
+ /**
+ * Handles what happens when a player breaks the block.
+ *
+ * @param event
+ * the passed Bukkit event
+ * @return if the event is cancelled
+ */
+ public abstract boolean onBreak(BlockBreakEvent event);
+
+}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java
new file mode 100644
index 00000000..1db52238
--- /dev/null
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/LockedDoor.java
@@ -0,0 +1,61 @@
+/*
+ * 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.block;
+
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.event.block.BlockBreakEvent;
+import org.bukkit.material.Door;
+
+/**
+ * @author Daniel Saukel
+ */
+public class LockedDoor extends GameBlock implements MultiBlock {
+
+ private Block attachedBlock;
+
+ public LockedDoor(Block block) {
+ super(block);
+ attachedBlock = getAttachedBlock();
+ }
+
+ /* Getters and setters */
+ @Override
+ public Block getAttachedBlock() {
+ if (attachedBlock != null) {
+ return attachedBlock;
+
+ } else {
+ return block.getRelative(BlockFace.UP);
+ }
+ }
+
+ /* Actions */
+ @Override
+ public boolean onBreak(BlockBreakEvent event) {
+ return true;
+ }
+
+ /**
+ * Opens the door.
+ */
+ public void open() {
+ ((Door) block.getState().getData()).setOpen(true);
+ block.getState().update(true);
+ }
+
+}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/MultiBlock.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/MultiBlock.java
new file mode 100644
index 00000000..cc69dafb
--- /dev/null
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/MultiBlock.java
@@ -0,0 +1,31 @@
+/*
+ * 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.block;
+
+import org.bukkit.block.Block;
+
+/**
+ * In some cases, a "game block" might actually be a structure with multiple blocks,
+ * like a bed or a door with two halfs. These GameBlocks implement MultiBlock.
+ *
+ * @author Daniel Saukel
+ */
+public interface MultiBlock {
+
+ public Block getAttachedBlock();
+
+}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/GamePlaceableBlock.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/PlaceableBlock.java
similarity index 94%
rename from core/src/main/java/io/github/dre2n/dungeonsxl/world/GamePlaceableBlock.java
rename to core/src/main/java/io/github/dre2n/dungeonsxl/world/block/PlaceableBlock.java
index 5f1f324d..c0bbeb16 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/GamePlaceableBlock.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/PlaceableBlock.java
@@ -14,22 +14,23 @@
* 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;
+package io.github.dre2n.dungeonsxl.world.block;
import io.github.dre2n.commons.util.NumberUtil;
+import io.github.dre2n.dungeonsxl.world.DGameWorld;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.event.block.BlockBreakEvent;
/**
* @author Frank Baumann, Daniel Saukel
*/
-public class GamePlaceableBlock {
+public class PlaceableBlock extends GameBlock {
// Variables
- private Block block;
private Set materials = new HashSet<>();
private boolean onTop = false;
@@ -39,8 +40,8 @@ public class GamePlaceableBlock {
private boolean onEast = false;
private boolean onWest = false;
- public GamePlaceableBlock(Block block, String ids, String directions) {
- this.block = block;
+ public PlaceableBlock(Block block, String ids, String directions) {
+ super(block);
// Split ids
if (!ids.isEmpty()) {
@@ -252,9 +253,15 @@ public class GamePlaceableBlock {
}
}
+ /* Actions */
+ @Override
+ public boolean onBreak(BlockBreakEvent event) {
+ return false;
+ }
+
// Can build
public static boolean canBuildHere(Block block, BlockFace blockFace, Material mat, DGameWorld gameWorld) {
- for (GamePlaceableBlock gamePlacableBlock : gameWorld.getPlaceableBlocks()) {
+ for (PlaceableBlock gamePlacableBlock : gameWorld.getPlaceableBlocks()) {
if (gamePlacableBlock.block.getFace(block) != BlockFace.SELF) {
continue;
}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/ProtectedBlock.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/ProtectedBlock.java
new file mode 100644
index 00000000..4509a9b7
--- /dev/null
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/ProtectedBlock.java
@@ -0,0 +1,37 @@
+/*
+ * 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.block;
+
+import org.bukkit.block.Block;
+import org.bukkit.event.block.BlockBreakEvent;
+
+/**
+ * @author Daniel Saukel
+ */
+public class ProtectedBlock extends GameBlock {
+
+ public ProtectedBlock(Block block) {
+ super(block);
+ }
+
+ /* Actions */
+ @Override
+ public boolean onBreak(BlockBreakEvent event) {
+ return true;
+ }
+
+}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardChest.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/RewardChest.java
similarity index 87%
rename from core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardChest.java
rename to core/src/main/java/io/github/dre2n/dungeonsxl/world/block/RewardChest.java
index c4c8850a..711a43cd 100644
--- a/core/src/main/java/io/github/dre2n/dungeonsxl/reward/RewardChest.java
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/RewardChest.java
@@ -14,14 +14,18 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package io.github.dre2n.dungeonsxl.reward;
+package io.github.dre2n.dungeonsxl.world.block;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
-import io.github.dre2n.dungeonsxl.world.DGameWorld;
+import io.github.dre2n.dungeonsxl.reward.ItemReward;
+import io.github.dre2n.dungeonsxl.reward.LevelReward;
+import io.github.dre2n.dungeonsxl.reward.MoneyReward;
+import io.github.dre2n.dungeonsxl.reward.Reward;
+import io.github.dre2n.dungeonsxl.reward.RewardTypeDefault;
import net.milkbowl.vault.item.ItemInfo;
import net.milkbowl.vault.item.Items;
import org.bukkit.Bukkit;
@@ -29,35 +33,34 @@ import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
+import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
/**
* @author Frank Baumann, Daniel Saukel
*/
-public class RewardChest {
-
+public class RewardChest extends GameBlock {
+
static DungeonsXL plugin = DungeonsXL.getInstance();
// Variables
private boolean used = false;
private Chest chest;
- private DGameWorld gameWorld;
private double moneyReward;
private int levelReward;
private ItemStack[] itemReward;
-
- public RewardChest(Block chest, DGameWorld gameWorld, double moneyReward, int levelReward, ItemStack[] itemReward) {
+
+ public RewardChest(Block chest, double moneyReward, int levelReward, ItemStack[] itemReward) {
+ super(chest);
+
if (!(chest.getState() instanceof Chest)) {
return;
}
-
+
this.chest = (Chest) chest.getState();
- this.gameWorld = gameWorld;
this.moneyReward = moneyReward;
this.levelReward = levelReward;
this.itemReward = itemReward;
-
- gameWorld.getRewardChests().add(this);
}
/**
@@ -90,21 +93,6 @@ public class RewardChest {
this.chest = chest;
}
- /**
- * @return the gameWorld
- */
- public DGameWorld getGameWorld() {
- return gameWorld;
- }
-
- /**
- * @param gameWorld
- * the gameWorld to set
- */
- public void setGameWorld(DGameWorld gameWorld) {
- this.gameWorld = gameWorld;
- }
-
/**
* @return the moneyReward
*/
@@ -136,6 +124,11 @@ public class RewardChest {
}
/* Actions */
+ @Override
+ public boolean onBreak(BlockBreakEvent event) {
+ return true;
+ }
+
/**
* @param opener
* the player who opens the chest
@@ -145,77 +138,77 @@ public class RewardChest {
MessageUtil.sendMessage(plugin.getServer().getPlayer(opener.getUniqueId()), DMessages.ERROR_CHEST_IS_OPENED.getMessage());
return;
}
-
+
if (chest.getLocation().distance(chest.getLocation()) < 1) {
addTreasure(DGroup.getByPlayer(opener));
used = true;
}
}
-
+
public void addTreasure(DGroup dGroup) {
if (dGroup == null) {
return;
}
-
+
boolean hasMoneyReward = false;
boolean hasLevelReward = false;
boolean hasItemReward = false;
-
+
for (Reward reward : dGroup.getRewards()) {
if (reward.getType() == RewardTypeDefault.MONEY) {
hasMoneyReward = true;
((MoneyReward) reward).addMoney(moneyReward);
-
+
} else if (reward.getType() == RewardTypeDefault.LEVEL) {
hasLevelReward = true;
((LevelReward) reward).addLevels(levelReward);
-
+
} else if (reward.getType() == RewardTypeDefault.ITEM) {
hasItemReward = true;
((ItemReward) reward).addItems(itemReward);
}
}
-
+
if (!hasMoneyReward) {
Reward reward = Reward.create(RewardTypeDefault.MONEY);
((MoneyReward) reward).addMoney(moneyReward);
dGroup.addReward(reward);
}
-
+
if (!hasLevelReward) {
Reward reward = Reward.create(RewardTypeDefault.LEVEL);
((LevelReward) reward).addLevels(levelReward);
dGroup.addReward(reward);
}
-
+
if (!hasItemReward) {
Reward reward = Reward.create(RewardTypeDefault.ITEM);
((ItemReward) reward).addItems(itemReward);
dGroup.addReward(reward);
}
-
+
for (Player player : dGroup.getPlayers()) {
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
if (dPlayer == null) {
continue;
}
-
+
if (itemReward != null) {
String msg = "";
for (ItemStack itemStack : itemReward) {
-
+
if (itemStack == null) {
continue;
}
-
+
String name = null;
-
+
if (itemStack.hasItemMeta()) {
if (itemStack.getItemMeta().hasDisplayName()) {
name = itemStack.getItemMeta().getDisplayName();
}
}
-
+
if (name == null) {
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
ItemInfo itemInfo = Items.itemByStack(itemStack);
@@ -224,30 +217,30 @@ public class RewardChest {
} else {
name = itemStack.getType().name();
}
-
+
} else {
name = itemStack.getType().toString();
}
}
-
+
msg += ChatColor.RED + " " + itemStack.getAmount() + " " + name + ChatColor.GOLD + ",";
}
-
+
if (msg.length() >= 1) {
msg = msg.substring(0, msg.length() - 1);
}
-
+
MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(msg));
}
-
+
if (moneyReward != 0 && plugin.getEconomyProvider() != null) {
MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(plugin.getEconomyProvider().format(moneyReward)));
}
-
+
if (levelReward != 0) {
MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(levelReward + " levels"));
}
}
}
-
+
}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBed.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBed.java
new file mode 100644
index 00000000..d8d2866a
--- /dev/null
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBed.java
@@ -0,0 +1,96 @@
+/*
+ * 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.block;
+
+import io.github.dre2n.commons.util.messageutil.MessageUtil;
+import io.github.dre2n.dungeonsxl.config.DMessages;
+import io.github.dre2n.dungeonsxl.player.DGamePlayer;
+import io.github.dre2n.dungeonsxl.player.DGroup;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.entity.Player;
+import org.bukkit.event.block.BlockBreakEvent;
+import org.bukkit.material.Bed;
+
+/**
+ * @author Daniel Saukel
+ */
+public class TeamBed extends TeamBlock implements MultiBlock {
+
+ private Block attachedBlock;
+
+ public TeamBed(Block block, DGroup owner) {
+ super(block, owner);
+ attachedBlock = getAttachedBlock();
+ }
+
+ /* Getters and setters */
+ public Block getAttachedBlock(Block block) {
+ if (block.getRelative(BlockFace.EAST).getType() == Material.BED_BLOCK) {
+ return block.getRelative(BlockFace.EAST);
+
+ } else if (block.getRelative(BlockFace.NORTH).getType() == Material.BED_BLOCK) {
+ return block.getRelative(BlockFace.NORTH);
+
+ } else if (block.getRelative(BlockFace.WEST).getType() == Material.BED_BLOCK) {
+ return block.getRelative(BlockFace.WEST);
+
+ } else if (block.getRelative(BlockFace.SOUTH).getType() == Material.BED_BLOCK) {
+ return block.getRelative(BlockFace.SOUTH);
+
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Block getAttachedBlock() {
+ if (attachedBlock != null) {
+ return attachedBlock;
+
+ } else {
+ return getAttachedBlock(block);
+ }
+ }
+
+ /* Actions */
+ @Override
+ public boolean onBreak(BlockBreakEvent event) {
+ Player breaker = event.getPlayer();
+ if (owner.getPlayers().contains(breaker)) {
+ MessageUtil.sendMessage(breaker, DMessages.ERROR_BLOCK_OWN_TEAM.getMessage());
+ return true;
+ }
+
+ for (DGamePlayer player : owner.getDGamePlayers()) {
+ player.setLives(1);
+ }
+
+ owner.getGameWorld().sendMessage(DMessages.GROUP_BED_DESTROYED.getMessage(owner.getName(), breaker.getName()));
+ Block block1 = event.getBlock();
+ if (((Bed) block1.getState().getData()).isHeadOfBed()) {
+ Block block2 = getAttachedBlock(block1);
+ if (block2 != null) {
+ block2.setType(Material.AIR);
+ }
+ }
+ block1.setType(Material.AIR);
+ return true;
+ }
+
+}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBlock.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBlock.java
new file mode 100644
index 00000000..6f2ab638
--- /dev/null
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamBlock.java
@@ -0,0 +1,50 @@
+/*
+ * 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.block;
+
+import io.github.dre2n.dungeonsxl.player.DGroup;
+import org.bukkit.block.Block;
+
+/**
+ * @author Daniel Saukel
+ */
+public abstract class TeamBlock extends GameBlock {
+
+ protected DGroup owner;
+
+ public TeamBlock(Block block, DGroup owner) {
+ super(block);
+ this.owner = owner;
+ }
+
+ /* Getters and setters */
+ /**
+ * @return the group that owns the flag
+ */
+ public DGroup getOwner() {
+ return owner;
+ }
+
+ /**
+ * @param owner
+ * the owner group to set
+ */
+ public void setOwner(DGroup owner) {
+ this.owner = owner;
+ }
+
+}
diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java
new file mode 100644
index 00000000..37ebb4ad
--- /dev/null
+++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/TeamFlag.java
@@ -0,0 +1,73 @@
+/*
+ * 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.block;
+
+import io.github.dre2n.commons.util.messageutil.MessageUtil;
+import io.github.dre2n.dungeonsxl.DungeonsXL;
+import io.github.dre2n.dungeonsxl.config.DMessages;
+import io.github.dre2n.dungeonsxl.player.DGamePlayer;
+import io.github.dre2n.dungeonsxl.player.DGroup;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.entity.Player;
+import org.bukkit.event.block.BlockBreakEvent;
+
+/**
+ * @author Daniel Saukel
+ */
+public class TeamFlag extends TeamBlock {
+
+ DungeonsXL plugin = DungeonsXL.getInstance();
+
+ public static final int WOOL = 35;
+
+ private byte teamId;
+
+ public TeamFlag(Block block, int teamId, DGroup owner) {
+ super(block, owner);
+ this.teamId = plugin.getMainConfig().getGroupColorPriority().get(teamId).byteValue();
+ reset();
+ }
+
+ /* Actions */
+ /**
+ * Reset a team flag when the capturer dies.
+ */
+ public void reset() {
+ block.setTypeIdAndData(WOOL, teamId, false);
+ }
+
+ @Override
+ public boolean onBreak(BlockBreakEvent event) {
+ Player breaker = event.getPlayer();
+ DGamePlayer gamePlayer = DGamePlayer.getByPlayer(breaker);
+ if (gamePlayer == null) {
+ return true;
+ }
+
+ if (owner.getPlayers().contains(breaker)) {
+ MessageUtil.sendMessage(breaker, DMessages.ERROR_BLOCK_OWN_TEAM.getMessage());
+ return true;
+ }
+
+ owner.getGameWorld().sendMessage(DMessages.GROUP_FLAG_STEALING.getMessage(breaker.getName(), owner.getName()));
+ gamePlayer.setRobbedGroup(owner);
+ event.getBlock().setType(Material.AIR);
+ return true;
+ }
+
+}
diff --git a/core/src/test/java/io/github/dre2n/dungeonsxl/sign/DSignTypeCustom.java b/core/src/test/java/io/github/dre2n/dungeonsxl/sign/DSignTypeCustom.java
index 537fede3..2f45104f 100644
--- a/core/src/test/java/io/github/dre2n/dungeonsxl/sign/DSignTypeCustom.java
+++ b/core/src/test/java/io/github/dre2n/dungeonsxl/sign/DSignTypeCustom.java
@@ -23,17 +23,19 @@ import io.github.dre2n.dungeonsxl.player.DPermissions;
*/
public enum DSignTypeCustom implements DSignType {
- CUSTOM("Custom", "custom", false, CustomSign.class);
+ CUSTOM("Custom", "custom", false, false, CustomSign.class);
private String name;
private String buildPermission;
private boolean onDungeonInit;
+ private boolean isProtected;
private Class extends DSign> handler;
- DSignTypeCustom(String name, String buildPermission, boolean onDungeonInit, Class extends DSign> handler) {
+ DSignTypeCustom(String name, String buildPermission, boolean onDungeonInit, boolean isProtected, Class extends DSign> handler) {
this.name = name;
this.buildPermission = buildPermission;
this.onDungeonInit = onDungeonInit;
+ this.isProtected = isProtected;
this.handler = handler;
}
@@ -52,6 +54,11 @@ public enum DSignTypeCustom implements DSignType {
return onDungeonInit;
}
+ @Override
+ public boolean isProtected() {
+ return isProtected;
+ }
+
@Override
public Class extends DSign> getHandler() {
return handler;