Merge pull request #95 from DRE2N/0.13

0.13
This commit is contained in:
Daniel Saukel 2016-06-22 14:30:53 +02:00 committed by GitHub
commit 3bf602e68d
39 changed files with 913 additions and 430 deletions

13
pom.xml
View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.12.1-SNAPSHOT${buildNo}</version>
<version>0.13${buildNo}</version>
<packaging>jar</packaging>
<name>DungeonsXL</name>
<url>https://dre2n.github.io</url>
@ -47,7 +47,7 @@
<relocations>
<relocation>
<pattern>io.github.dre2n.commons</pattern>
<shadedPattern>io.github.dre2n.util.commons</shadedPattern>
<shadedPattern>io.github.dre2n.dungeonsxl.util.commons</shadedPattern>
</relocation>
<relocation>
<pattern>io.github.dre2n.caliburn</pattern>
@ -87,12 +87,12 @@
<dependency>
<groupId>io.github.dre2n</groupId>
<artifactId>caliburn</artifactId>
<version>0.1.5</version>
<version>0.1.6</version>
</dependency>
<dependency>
<groupId>io.github.dre2n</groupId>
<artifactId>itemsxl</artifactId>
<version>0.1.5</version>
<version>0.1.6</version>
</dependency>
<dependency>
<groupId>io.github.dre2n</groupId>
@ -105,6 +105,11 @@
<version>2.0.18-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gmail.filoghost</groupId>
<artifactId>holographicdisplaysapi</artifactId>
<version>2.1.7</version>
</dependency>
</dependencies>
<repositories>
<repository>

View File

@ -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();
}
}

View File

@ -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();
}

View File

@ -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]");

View File

@ -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();

View File

@ -56,14 +56,13 @@ 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!"),
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!"),
@ -139,16 +138,18 @@ 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!"),
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!"),
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!"),

View File

@ -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);

View File

@ -40,21 +40,14 @@ public class Dungeons {
}
}
/**
* @return the dungeons
*/
public List<Dungeon> 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<Dungeon> getDungeons() {
return dungeons;
}
/**
* @param name
* the name of the Dungeon

View File

@ -48,7 +48,7 @@ public class Game {
private List<DGroup> dGroups = new ArrayList<>();
private boolean started;
private GameType type;
private GameType type = GameTypeDefault.DEFAULT;
private GameWorld world;
private GameRules rules;
private int waveCount;
@ -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)));
}
}

View File

@ -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;
}

View File

@ -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();

View File

@ -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 {

View File

@ -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;
@ -39,6 +38,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;
@ -133,16 +133,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();
}
}
@ -234,7 +225,6 @@ 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()) {
@ -252,14 +242,13 @@ public class PlayerListener implements Listener {
if (name == null) {
name = item.getType().toString();
}
UseItemTrigger trigger = UseItemTrigger.get(name, gameWorld);
UseItemTrigger trigger = UseItemTrigger.getByName(name, gameWorld);
if (trigger != null) {
trigger.onTrigger(player);
}
}
}
}
}
// Check Signs
if (clickedBlock != null) {
@ -288,12 +277,10 @@ 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) {
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());
}
}
@ -301,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;
}
@ -312,6 +297,9 @@ public class PlayerListener implements Listener {
}
}
}
} else if (OpenDoorSign.isProtected(clickedBlock)) {
event.setCancelled(true);
}
}
}
@ -398,15 +386,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.

View File

@ -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();
}

View File

@ -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;
@ -596,11 +610,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 +703,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 +826,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!

View File

@ -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,12 +397,16 @@ public class DGroup {
}
/**
* Will fail if there is no dungeon with this name.
*
* @param dungeonName
* the dungeonName to set
*/
public void setDungeonName(String dungeonName) {
if (plugin.getDungeons().getByName(name) != null) {
this.dungeonName = dungeonName;
}
}
/**
* @return if the group is playing
@ -411,12 +416,16 @@ 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) {
if (Worlds.exists(name)) {
mapName = name;
}
}
/**
* @return the unplayedFloors

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<String> permissions = new ArrayList<>();
/* Getters and setters */
/**
* @return the permission the player must have to play the dungeon
*/
public List<String> getPermissions() {
return permissions;
}
/**
* @param permissions
* the permissions to set
*/
public void setPermissions(List<String> 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) {
}
}

View File

@ -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<? extends Requirement> handler;

View File

@ -29,16 +29,20 @@ 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),
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),
@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),

View File

@ -0,0 +1,95 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
/**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
*/
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);
}
/* 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]);
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() {
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
public DSignType getType() {
return type;
}
}

View File

@ -0,0 +1,95 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.world.GameWorld;
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().getBlock().setType(Material.AIR);
String[] holoLines = lines[1].split("/");
Location location = getSign().getLocation();
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 = null;
if (Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) {
UniversalItem universalItem = plugin.getCaliburnAPI().getItems().getById(id);
if (universalItem != null) {
item = universalItem.toItemStack(1);
}
}
if (item == null) {
if (EnumUtil.isValidEnum(Material.class, id)) {
item = new ItemStack(Material.valueOf(id));
} else {
item = new ItemStack(NumberUtil.parseInt(id, 1));
}
}
hologram.appendItemLine(item);
} else {
hologram.appendTextLine(ChatColor.translateAlternateColorCodes('&', line));
}
}
}
@Override
public DSignType getType() {
return type;
}
}

View File

@ -0,0 +1,127 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
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 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)));
}
if (dPlayer.getLives() <= 0) {
dPlayer.kill();
}
}
@Override
public DSignType getType() {
return type;
}
}

View File

@ -0,0 +1,112 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
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.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.material.Door;
/**
* @author Daniel Saukel
*/
public class OpenDoorSign extends DSign {
private DSignType type = DSignTypeDefault.OPEN_DOOR;
private Block block;
public OpenDoorSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
/* Getters and setters */
/**
* @return the door to open;
*/
public Block getBlock() {
return block;
}
/**
* @param block
* the door to open
*/
public void setBlock(Block 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.getState().getData() instanceof Door) {
if (block.getRelative(BlockFace.DOWN).getType() == block.getType()) {
this.block = block.getRelative(BlockFace.DOWN);
} else {
this.block = block;
}
}
getSign().getBlock().setType(Material.AIR);
}
@Override
public void onTrigger() {
if (block != null) {
((Door) block.getState().getData()).setOpen(true);
block.getState().update(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) {
GameWorld gameWorld = GameWorld.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;
}
}

View File

@ -16,19 +16,21 @@
*/
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;
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 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,8 @@ public class ReadySign extends DSign {
private DSignType type = DSignTypeDefault.READY;
private GameType gameType;
private double autoStart = -1;
private boolean triggered = false;
public ReadySign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
@ -58,6 +62,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 +91,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 +116,33 @@ public class ReadySign extends DSign {
@Override
public boolean onPlayerTrigger(Player player) {
ready(DGamePlayer.getByPlayer(player));
if (!triggered && autoStart >= 0) {
triggered = true;
new BukkitRunnable() {
@Override
public void run() {
onTrigger();
}
}.runTaskLater(plugin, (long) (autoStart * 20));
if (!DGroup.getByPlayer(player).isPlaying()) {
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));
if (getGame() == null) {
return;
}
for (Player player : getGame().getPlayers()) {
ready(DGamePlayer.getByPlayer(player));
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}
}
}

View File

@ -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<GameWorld, ArrayList<DistanceTrigger>> 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<DistanceTrigger> 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<DistanceTrigger> getTriggers(GameWorld gameWorld) {
return triggers.get(gameWorld);
}
public static DistanceTrigger[] getTriggersArray(GameWorld gameWorld) {
return getTriggers(gameWorld).toArray(new DistanceTrigger[getTriggers(gameWorld).size()]);
}
}

View File

@ -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<GameWorld, ArrayList<InteractTrigger>> 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<InteractTrigger> 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)) {
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)) {
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);
}
}

View File

@ -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<GameWorld, ArrayList<MobTrigger>> 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<MobTrigger> 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)) {
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);
}
}

View File

@ -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<GameWorld, ArrayList<ProgressTrigger>> 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<ProgressTrigger> 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<ProgressTrigger> getByGameWorld(GameWorld gameWorld) {
Set<ProgressTrigger> 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);
}
}

View File

@ -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<GameWorld, ArrayList<RedstoneTrigger>> 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<RedstoneTrigger> 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,36 +85,21 @@ public class RedstoneTrigger extends Trigger {
}
if (rtBlock != null) {
if (hasTriggers(gameWorld)) {
for (RedstoneTrigger trigger : getTriggers(gameWorld)) {
for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.REDSTONE)) {
RedstoneTrigger trigger = (RedstoneTrigger) uncasted;
if (trigger.rtBlock.equals(rtBlock)) {
return trigger;
}
}
}
return new RedstoneTrigger(rtBlock);
}
return null;
}
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<RedstoneTrigger> getTriggers(GameWorld gameWorld) {
return triggers.get(gameWorld);
}
public static RedstoneTrigger[] getTriggersArray(GameWorld gameWorld) {
return getTriggers(gameWorld).toArray(new RedstoneTrigger[getTriggers(gameWorld).size()]);
}
}

View File

@ -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<GameWorld, ArrayList<SignTrigger>> 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<SignTrigger> 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)) {
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);
}
}

View File

@ -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();
}

View File

@ -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<GameWorld, ArrayList<UseItemTrigger>> triggers = new HashMap<>();
private TriggerType type = TriggerTypeDefault.USE_ITEM;
private String name;
@ -57,40 +52,23 @@ public class UseItemTrigger extends Trigger {
updateDSigns();
}
@Override
public void register(GameWorld gameWorld) {
if (!hasTriggers(gameWorld)) {
ArrayList<UseItemTrigger> 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)) {
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) {
@ -99,12 +77,7 @@ public class UseItemTrigger extends Trigger {
}
}
}
}
return null;
}
public static boolean hasTriggers(GameWorld gameWorld) {
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
}
}

View File

@ -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<GameWorld, ArrayList<WaveTrigger>> 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<WaveTrigger> 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<WaveTrigger> getByGameWorld(GameWorld gameWorld) {
Set<WaveTrigger> 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);
}
}

View File

@ -29,13 +29,17 @@ 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.DSignType;
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;
import io.github.dre2n.dungeonsxl.trigger.TriggerType;
import io.github.dre2n.dungeonsxl.trigger.TriggerTypeDefault;
import java.io.File;
import java.io.FileInputStream;
@ -72,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<ItemStack> secureObjects = new ArrayList<>();
@ -83,6 +86,7 @@ public class GameWorld {
// TODO: Killed mobs
private CopyOnWriteArrayList<RewardChest> rewardChests = new CopyOnWriteArrayList<>();
private CopyOnWriteArrayList<DSign> dSigns = new CopyOnWriteArrayList<>();
private CopyOnWriteArrayList<Trigger> triggers = new CopyOnWriteArrayList<>();
private WorldConfig worldConfig;
public GameWorld() {
@ -203,16 +207,31 @@ public class GameWorld {
/**
* @return the start location
*/
public Location getStartLocation() {
return locStart;
public Location getStartLocation(DGroup dGroup) {
int index = getGame().getDGroups().indexOf(dGroup);
// Try the matching location
for (DSign dSign : dSigns) {
if (dSign.getType() == DSignTypeDefault.START) {
if (((StartSign) dSign).getId() == index) {
return dSign.getSign().getLocation();
}
}
}
/**
* @param location
* the location to start to set
*/
public void setStartLocation(Location location) {
this.locStart = location;
// 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();
}
/**
@ -335,6 +354,19 @@ public class GameWorld {
return dSigns;
}
/**
* @return the triggers with the type
*/
public List<DSign> getDSigns(DSignType type) {
List<DSign> dSignsOfType = new ArrayList<>();
for (DSign dSign : dSigns) {
if (dSign.getType() == type) {
dSignsOfType.add(dSign);
}
}
return dSignsOfType;
}
/**
* @param dSigns
* the dSigns to set
@ -343,6 +375,42 @@ public class GameWorld {
this.dSigns = dSigns;
}
/**
* @return the triggers
*/
public CopyOnWriteArrayList<Trigger> getTriggers() {
return triggers;
}
/**
* @return the triggers with the type
*/
public List<Trigger> getTriggers(TriggerType type) {
List<Trigger> 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
*/
@ -426,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()) {

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.world;
import java.io.File;
import java.util.Set;
/**
* @author Daniel Saukel
*/
public class Worlds {
/*private Set<ResourceWorld> 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;
}
}

View File

@ -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.