From 9bdab01b10c14c7f12cb94be16d94334d57bc1d6 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 30 Jul 2015 16:47:02 +0200 Subject: [PATCH 01/10] Added support for money rewards - untested! --- src/com/dre/dungeonsxl/DPlayer.java | 3 ++- src/com/dre/dungeonsxl/P.java | 15 +++++++++++++++ src/com/dre/dungeonsxl/game/GameChest.java | 6 +++++- src/com/dre/dungeonsxl/signs/SIGNChest.java | 19 ++++++++++++++----- .../dre/dungeonsxl/signs/SIGNMythicMobs.java | 1 - 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/com/dre/dungeonsxl/DPlayer.java b/src/com/dre/dungeonsxl/DPlayer.java index b59d8f56..8bbab195 100644 --- a/src/com/dre/dungeonsxl/DPlayer.java +++ b/src/com/dre/dungeonsxl/DPlayer.java @@ -54,6 +54,7 @@ public class DPlayer { public String[] linesCopy; public Inventory treasureInv = P.p.getServer().createInventory(player, 45, "Belohnungen"); + public double treasureMoney = 0; public int initialLives = -1; @@ -131,6 +132,7 @@ public class DPlayer { if (!this.isinTestMode) {// Nur wenn man nicht am Testen ist if (isFinished) { this.addTreasure(); + p.economy.depositPlayer(this.player, treasureMoney); // Set Time File file = new File(p.getDataFolder() + "/dungeons/" + gworld.dungeonname, "players.yml"); @@ -157,7 +159,6 @@ public class DPlayer { if (gworld.isTutorial) { p.permission.playerAddGroup(this.player, p.mainConfig.tutorialEndGroup); p.permission.playerRemoveGroup(this.player, p.mainConfig.tutorialStartGroup); - p.getServer().dispatchCommand(p.getServer().getConsoleSender(), "pex user "+player.getName()+" group set "+p.mainConfig.tutorialEndGroup);//TODO: Use Vault for this! } } } diff --git a/src/com/dre/dungeonsxl/P.java b/src/com/dre/dungeonsxl/P.java index 1dbebbd4..7d7d8b25 100644 --- a/src/com/dre/dungeonsxl/P.java +++ b/src/com/dre/dungeonsxl/P.java @@ -11,6 +11,7 @@ import java.util.HashMap; import java.util.UUID; import java.util.concurrent.CopyOnWriteArrayList; +import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.permission.Permission; import org.apache.commons.lang.math.NumberUtils; @@ -88,6 +89,9 @@ public class P extends JavaPlugin { // Setup Permissions this.setupPermissions(); + + // Setup Economy + this.setupEconomy(); // Listener entityListener = new EntityListener(); @@ -219,6 +223,17 @@ public class P extends JavaPlugin { return false; } + // Economy + public Economy economy = null; + + private Boolean setupEconomy() { + RegisteredServiceProvider economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); + if (economyProvider != null) { + economy = economyProvider.getProvider(); + } + return (economy != null); + } + // Save and Load public void saveData() { File file = new File(this.getDataFolder(), "data.yml"); diff --git a/src/com/dre/dungeonsxl/game/GameChest.java b/src/com/dre/dungeonsxl/game/GameChest.java index 4a0b9502..f63a290f 100644 --- a/src/com/dre/dungeonsxl/game/GameChest.java +++ b/src/com/dre/dungeonsxl/game/GameChest.java @@ -20,12 +20,15 @@ public class GameChest { public boolean isUsed = false; public Chest chest; public GameWorld gworld; + public double moneyReward; - public GameChest(Block chest, GameWorld gworld) { + public GameChest(Block chest, GameWorld gworld, double moneyReward) { if (chest.getState() instanceof Chest) { this.chest = (Chest) chest.getState(); this.gworld = gworld; + + this.moneyReward = moneyReward; gworld.gchests.add(this); } @@ -36,6 +39,7 @@ public class GameChest { for (Player player : dgroup.getPlayers()) { DPlayer dplayer = DPlayer.get(player); if (dplayer != null) { + dplayer.treasureMoney = dplayer.treasureMoney + moneyReward; String msg = ""; for (ItemStack istack : this.chest.getInventory().getContents()) { if (istack != null) { diff --git a/src/com/dre/dungeonsxl/signs/SIGNChest.java b/src/com/dre/dungeonsxl/signs/SIGNChest.java index aca5a07f..4ac196d0 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNChest.java +++ b/src/com/dre/dungeonsxl/signs/SIGNChest.java @@ -12,28 +12,37 @@ public class SIGNChest extends DSign { public String buildPermissions = "dxl.sign.chest"; public boolean onDungeonInit = false; + // Variables + private double moneyReward; + public SIGNChest(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override public boolean check() { - // TODO Auto-generated method stub - + String lines[] = sign.getLines(); + if (lines[1].equals("")) { + return false; + } return true; } @Override public void onInit() { + String lines[] = sign.getLines(); + if (!lines[1].equals("")) { + moneyReward = Double.parseDouble(lines[1]); + } for (int i = -1; i <= 1; i++) { if (sign.getBlock().getRelative(i, 0, 0).getType() == Material.CHEST) { - new GameChest(sign.getBlock().getRelative(i, 0, 0), gworld); + new GameChest(sign.getBlock().getRelative(i, 0, 0), gworld, moneyReward); } if (sign.getBlock().getRelative(0, 0, i).getType() == Material.CHEST) { - new GameChest(sign.getBlock().getRelative(0, 0, i), gworld); + new GameChest(sign.getBlock().getRelative(0, 0, i), gworld, moneyReward); } if (sign.getBlock().getRelative(0, i, 0).getType() == Material.CHEST) { - new GameChest(sign.getBlock().getRelative(0, i, 0), gworld); + new GameChest(sign.getBlock().getRelative(0, i, 0), gworld, moneyReward); } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNMythicMobs.java b/src/com/dre/dungeonsxl/signs/SIGNMythicMobs.java index 36b4ae35..6cbba69b 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNMythicMobs.java +++ b/src/com/dre/dungeonsxl/signs/SIGNMythicMobs.java @@ -6,7 +6,6 @@ import org.bukkit.World; import org.bukkit.block.Sign; import org.bukkit.Location; -import com.dre.dungeonsxl.P; import com.dre.dungeonsxl.game.GameWorld; public class SIGNMythicMobs extends DSign { From 2b7cf84e8964ebdcfecb30bcac2da4f6ca2eb41c Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 3 Aug 2015 17:18:41 +0200 Subject: [PATCH 02/10] Added /dxl play command --- src/com/dre/dungeonsxl/LanguageReader.java | 4 +- src/com/dre/dungeonsxl/commands/CMDPlay.java | 59 +++++++++++++++++++ .../dre/dungeonsxl/commands/DCommandRoot.java | 6 +- 3 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 src/com/dre/dungeonsxl/commands/CMDPlay.java diff --git a/src/com/dre/dungeonsxl/LanguageReader.java b/src/com/dre/dungeonsxl/LanguageReader.java index effccac8..29a00caf 100644 --- a/src/com/dre/dungeonsxl/LanguageReader.java +++ b/src/com/dre/dungeonsxl/LanguageReader.java @@ -122,10 +122,10 @@ public class LanguageReader { defaults.put("Help_Cmd_DeletePortal", "/dxl deleteportal - Deletes the portal you are looking at"); defaults.put("Help_Cmd_Reload", "/dxl reload - Reloads the plugin"); defaults.put("Help_Cmd_Save", "/dxl save - Saves the current dungeon"); + defaults.put("Help_Cmd_Play", "/dxl play [dungeon]"); defaults.put("Help_Cmd_Test", "/dxl test [dungeon] - Tests a dungeon"); + defaults.put("Help_Cmd_Lives", "/dxl lives - Shows the lives a player has left"); defaults.put("Help_Cmd_Uninvite", "/dxl uninvite - Uninvite a player to edit a dungeon"); - defaults.put("Help_Cmd_Lives", "/dxl lives - show the lives a player has left"); - } private void check() { diff --git a/src/com/dre/dungeonsxl/commands/CMDPlay.java b/src/com/dre/dungeonsxl/commands/CMDPlay.java new file mode 100644 index 00000000..3ac3a0ab --- /dev/null +++ b/src/com/dre/dungeonsxl/commands/CMDPlay.java @@ -0,0 +1,59 @@ +package com.dre.dungeonsxl.commands; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.dre.dungeonsxl.DGroup; +import com.dre.dungeonsxl.DPlayer; +import com.dre.dungeonsxl.EditWorld; +import com.dre.dungeonsxl.game.GameWorld; + +public class CMDPlay extends DCommand { + + public CMDPlay() { + this.command = "play"; + this.args = -1; + this.help = p.language.get("Help_Cmd_Play"); + this.permissions = "dxl.play"; + this.isPlayerCommand = true; + } + + @Override + public void onExecute(String[] args, CommandSender sender) { + Player player = (Player) sender; + DPlayer dplayer = DPlayer.get(player); + String dungeonname; + + if (dplayer == null) { + if (args.length > 1) { + dungeonname = args[1]; + + if (EditWorld.exist(dungeonname)) { + if (DGroup.get(player) == null) { + DGroup dgroup = new DGroup(player, dungeonname); + if (dgroup != null) { + if (dgroup.getGworld() == null) { + dgroup.setGworld(GameWorld.load(DGroup.get(player).getDungeonname())); + } + if (dgroup.getGworld().locLobby == null) { + new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().world.getSpawnLocation(), false); + } else { + new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().locLobby, false); + } + } + } else { + p.msg(player, p.language.get("Error_LeaveGroup")); + } + } else { + p.msg(player, p.language.get("Error_DungeonNotExist", dungeonname)); + } + } else { + this.displayHelp(player); + } + } else { + p.msg(player, p.language.get("Error_LeaveDungeon")); + } + + } + +} diff --git a/src/com/dre/dungeonsxl/commands/DCommandRoot.java b/src/com/dre/dungeonsxl/commands/DCommandRoot.java index 928b0170..2b0e61f7 100644 --- a/src/com/dre/dungeonsxl/commands/DCommandRoot.java +++ b/src/com/dre/dungeonsxl/commands/DCommandRoot.java @@ -18,14 +18,15 @@ public class DCommandRoot { public CMDDeletePortal cmdDeletePortal = new CMDDeletePortal(); public CMDChat cmdChat = new CMDChat(); public CMDChatSpy cmdChatSpy = new CMDChatSpy(); + public CMDLives cmdLives = new CMDLives(); public CMDList cmdList = new CMDList(); public CMDUninvite cmdUninvite = new CMDUninvite(); public CMDInvite cmdInvite = new CMDInvite(); public CMDMsg cmdMsg = new CMDMsg(); + public CMDPlay cmdPlay = new CMDPlay(); public CMDTest cmdTest = new CMDTest(); public CMDHelp cmdHelp = new CMDHelp(); public CMDReload cmdReload = new CMDReload(); - public CMDLives cmdLives = new CMDLives(); // Methods public DCommandRoot() { @@ -41,13 +42,14 @@ public class DCommandRoot { this.commands.add(cmdDeletePortal); this.commands.add(cmdChat); this.commands.add(cmdChatSpy); + this.commands.add(cmdLives); this.commands.add(cmdList); this.commands.add(cmdUninvite); this.commands.add(cmdInvite); this.commands.add(cmdMsg); + this.commands.add(cmdPlay); this.commands.add(cmdTest); this.commands.add(cmdHelp); this.commands.add(cmdReload); - this.commands.add(cmdLives); } } From 5be72ab94132d19ab9706d8a305cfcd4d8f5a69a Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 11 Aug 2015 19:33:31 +0200 Subject: [PATCH 03/10] Improve economy support -Fees -Configurability --- src/com/dre/dungeonsxl/DConfig.java | 12 ++++++++++++ src/com/dre/dungeonsxl/DGroup.java | 11 +++++++++++ src/com/dre/dungeonsxl/P.java | 14 +++++++++----- src/com/dre/dungeonsxl/game/GameWorld.java | 7 +++++++ src/com/dre/dungeonsxl/util/OfflinePlayerUtil.java | 5 ++++- 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/com/dre/dungeonsxl/DConfig.java b/src/com/dre/dungeonsxl/DConfig.java index d3101277..327fa825 100644 --- a/src/com/dre/dungeonsxl/DConfig.java +++ b/src/com/dre/dungeonsxl/DConfig.java @@ -38,6 +38,8 @@ public class DConfig { private int timeUntilKickOfflinePlayer = -1; + private double fee = 0; + private List finishedOne; private List finishedAll; private int timeLastPlayed = 0; @@ -188,6 +190,12 @@ public class DConfig { } /* Dungeon Requirements */ + if (configFile.contains("fee")) { + fee = configFile.getDouble("fee"); + } else { + fee = mainConfig.fee; + } + if (configFile.contains("mustFinishOne")) { finishedOne = configFile.getStringList("mustFinishOne"); } else { @@ -332,6 +340,10 @@ public class DConfig { return timeLastPlayed; } + public double getFee() { + return fee; + } + public List getFinishedAll() { return finishedAll; } diff --git a/src/com/dre/dungeonsxl/DGroup.java b/src/com/dre/dungeonsxl/DGroup.java index 0ddcbae2..e5c622a3 100644 --- a/src/com/dre/dungeonsxl/DGroup.java +++ b/src/com/dre/dungeonsxl/DGroup.java @@ -1,8 +1,10 @@ package com.dre.dungeonsxl; +import java.io.File; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.entity.Player; + import com.dre.dungeonsxl.game.GameWorld; public class DGroup { @@ -61,6 +63,15 @@ public class DGroup { for (Player player : getPlayers()) { DPlayer dplayer = DPlayer.get(player); dplayer.respawn(); + if (P.p.mainConfig.enableEconomy) { + File file = new File(P.p.getDataFolder() + "/dungeons/" + dungeonname + "/config.yml"); + if (file != null) { + DConfig confReader = new DConfig(file); + if (confReader != null) { + P.economy.withdrawPlayer(player, confReader.getFee()); + } + } + } } DGSign.updatePerGroup(this); diff --git a/src/com/dre/dungeonsxl/P.java b/src/com/dre/dungeonsxl/P.java index 7d7d8b25..d6560734 100644 --- a/src/com/dre/dungeonsxl/P.java +++ b/src/com/dre/dungeonsxl/P.java @@ -224,14 +224,18 @@ public class P extends JavaPlugin { } // Economy - public Economy economy = null; + public static Economy economy = null; private Boolean setupEconomy() { - RegisteredServiceProvider economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); - if (economyProvider != null) { - economy = economyProvider.getProvider(); + if (mainConfig.enableEconomy) { + RegisteredServiceProvider economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); + if (economyProvider != null) { + economy = economyProvider.getProvider(); + } + return (economy != null); + } else { + return false; } - return (economy != null); } // Save and Load diff --git a/src/com/dre/dungeonsxl/game/GameWorld.java b/src/com/dre/dungeonsxl/game/GameWorld.java index 7f949bf3..06030ae1 100644 --- a/src/com/dre/dungeonsxl/game/GameWorld.java +++ b/src/com/dre/dungeonsxl/game/GameWorld.java @@ -161,6 +161,13 @@ public class GameWorld { } DConfig config = new DConfig(new File(p.getDataFolder() + "/dungeons/" + dungeon, "config.yml")); + + if (p.mainConfig.enableEconomy) { + if (!(P.economy.getBalance(player) >= config.getFee())) { + return false; + } + } + if (config.getFinished() != null && config.getFinishedAll() != null) { if (!config.getFinished().isEmpty()) { diff --git a/src/com/dre/dungeonsxl/util/OfflinePlayerUtil.java b/src/com/dre/dungeonsxl/util/OfflinePlayerUtil.java index ad9358eb..095ab5d4 100644 --- a/src/com/dre/dungeonsxl/util/OfflinePlayerUtil.java +++ b/src/com/dre/dungeonsxl/util/OfflinePlayerUtil.java @@ -4,12 +4,15 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.bukkit.Server; public class OfflinePlayerUtil { + static Server server = Bukkit.getServer(); + @SuppressWarnings("deprecation") public static UUID getUniqueIdFromName(String name) { - OfflinePlayer player = Bukkit.getServer().getOfflinePlayer(name); + OfflinePlayer player = server.getOfflinePlayer(name); UUID uuid = player.getUniqueId(); return uuid; } From 77baa789e62af4d4da9f825e4e40f90e78b25f19 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 11 Aug 2015 19:34:27 +0200 Subject: [PATCH 04/10] Improve play command Added requirements --- src/com/dre/dungeonsxl/commands/CMDPlay.java | 38 ++++++++++++++------ 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/com/dre/dungeonsxl/commands/CMDPlay.java b/src/com/dre/dungeonsxl/commands/CMDPlay.java index 3ac3a0ab..26be2422 100644 --- a/src/com/dre/dungeonsxl/commands/CMDPlay.java +++ b/src/com/dre/dungeonsxl/commands/CMDPlay.java @@ -1,11 +1,15 @@ package com.dre.dungeonsxl.commands; +import java.io.File; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import com.dre.dungeonsxl.DConfig; import com.dre.dungeonsxl.DGroup; import com.dre.dungeonsxl.DPlayer; import com.dre.dungeonsxl.EditWorld; +import com.dre.dungeonsxl.P; import com.dre.dungeonsxl.game.GameWorld; public class CMDPlay extends DCommand { @@ -29,20 +33,34 @@ public class CMDPlay extends DCommand { dungeonname = args[1]; if (EditWorld.exist(dungeonname)) { - if (DGroup.get(player) == null) { - DGroup dgroup = new DGroup(player, dungeonname); - if (dgroup != null) { - if (dgroup.getGworld() == null) { - dgroup.setGworld(GameWorld.load(DGroup.get(player).getDungeonname())); - } - if (dgroup.getGworld().locLobby == null) { - new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().world.getSpawnLocation(), false); + if (GameWorld.canPlayDungeon(dungeonname, player)) { + if (GameWorld.checkRequirements(dungeonname, player)) { + if (DGroup.get(player) == null) { + DGroup dgroup = new DGroup(player, dungeonname); + if (dgroup != null) { + if (dgroup.getGworld() == null) { + dgroup.setGworld(GameWorld.load(DGroup.get(player).getDungeonname())); + } + if (dgroup.getGworld().locLobby == null) { + new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().world.getSpawnLocation(), false); + } else { + new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().locLobby, false); + } + } } else { - new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().locLobby, false); + p.msg(player, p.language.get("Error_LeaveGroup")); } + } else { + P.p.msg(player, P.p.language.get("Error_Requirements")); } } else { - p.msg(player, p.language.get("Error_LeaveGroup")); + File file = new File(p.getDataFolder() + "/dungeons/" + dungeonname + "/config.yml"); + if (file != null) { + DConfig confReader = new DConfig(file); + if (confReader != null) { + P.p.msg(player, P.p.language.get("Error_Cooldown", "" + confReader.getTimeToNextPlay())); + } + } } } else { p.msg(player, p.language.get("Error_DungeonNotExist", dungeonname)); From c562999f11f3d3dca73edc43880cb11536b96fa0 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 12 Aug 2015 15:02:06 +0200 Subject: [PATCH 05/10] Remove static modifier of economy --- src/com/dre/dungeonsxl/DGroup.java | 2 +- src/com/dre/dungeonsxl/P.java | 2 +- src/com/dre/dungeonsxl/game/GameWorld.java | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/com/dre/dungeonsxl/DGroup.java b/src/com/dre/dungeonsxl/DGroup.java index e5c622a3..64626947 100644 --- a/src/com/dre/dungeonsxl/DGroup.java +++ b/src/com/dre/dungeonsxl/DGroup.java @@ -68,7 +68,7 @@ public class DGroup { if (file != null) { DConfig confReader = new DConfig(file); if (confReader != null) { - P.economy.withdrawPlayer(player, confReader.getFee()); + P.p.economy.withdrawPlayer(player, confReader.getFee()); } } } diff --git a/src/com/dre/dungeonsxl/P.java b/src/com/dre/dungeonsxl/P.java index d6560734..923331d9 100644 --- a/src/com/dre/dungeonsxl/P.java +++ b/src/com/dre/dungeonsxl/P.java @@ -224,7 +224,7 @@ public class P extends JavaPlugin { } // Economy - public static Economy economy = null; + public Economy economy = null; private Boolean setupEconomy() { if (mainConfig.enableEconomy) { diff --git a/src/com/dre/dungeonsxl/game/GameWorld.java b/src/com/dre/dungeonsxl/game/GameWorld.java index 06030ae1..7bb7079d 100644 --- a/src/com/dre/dungeonsxl/game/GameWorld.java +++ b/src/com/dre/dungeonsxl/game/GameWorld.java @@ -161,13 +161,13 @@ public class GameWorld { } DConfig config = new DConfig(new File(p.getDataFolder() + "/dungeons/" + dungeon, "config.yml")); - + if (p.mainConfig.enableEconomy) { - if (!(P.economy.getBalance(player) >= config.getFee())) { + if (!(P.p.economy.getBalance(player) >= config.getFee())) { return false; } } - + if (config.getFinished() != null && config.getFinishedAll() != null) { if (!config.getFinished().isEmpty()) { From c8a9b510d4023b8b9b121fcc8f6d2f2f106f08eb Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 12 Aug 2015 17:05:53 +0200 Subject: [PATCH 06/10] Split keepInventory (WIP) --- src/com/dre/dungeonsxl/DConfig.java | 52 ++++++++++++++++-- src/com/dre/dungeonsxl/DPlayer.java | 4 +- src/com/dre/dungeonsxl/P.java | 8 +-- .../dungeonsxl/listener/DeathListener.java | 31 ----------- .../dungeonsxl/listener/PlayerListener.java | 14 ----- .../listener/player/PlayerDeathListener.java | 54 +++++++++++++++++++ 6 files changed, 109 insertions(+), 54 deletions(-) delete mode 100644 src/com/dre/dungeonsxl/listener/DeathListener.java create mode 100644 src/com/dre/dungeonsxl/listener/player/PlayerDeathListener.java diff --git a/src/com/dre/dungeonsxl/DConfig.java b/src/com/dre/dungeonsxl/DConfig.java index 327fa825..e5ecfe27 100644 --- a/src/com/dre/dungeonsxl/DConfig.java +++ b/src/com/dre/dungeonsxl/DConfig.java @@ -23,6 +23,10 @@ public class DConfig { private File file; private boolean keepInventory = false; + private boolean keepInventoryOnEnter = false; + private boolean keepInventoryOnEscape = false; + private boolean keepInventoryOnFinish = false; + private boolean keepInventoryOnDeath = true; private CopyOnWriteArrayList dClasses = new CopyOnWriteArrayList(); private Map msgs = new HashMap(); @@ -149,14 +153,40 @@ public class DConfig { } } - /* keep Inventory */ + /* Keep Inventory */ if (configFile.contains("keepInventory")) { - keepInventory = configFile.getBoolean("keepInventory"); + keepInventoryOnEnter = configFile.getBoolean("keepInventory"); + keepInventoryOnEscape = configFile.getBoolean("keepInventory"); + keepInventoryOnFinish = configFile.getBoolean("keepInventory"); } else { keepInventory = mainConfig.keepInventory; } - /* keep Inventory */ + if (configFile.contains("keepInventoryOnEnter")) { + keepInventoryOnEnter = configFile.getBoolean("keepInventoryOnEnter"); + } else { + keepInventoryOnEnter = mainConfig.keepInventoryOnEnter; + } + + if (configFile.contains("keepInventoryOnEscape")) { + keepInventoryOnEscape = configFile.getBoolean("keepInventoryOnEscape"); + } else { + keepInventoryOnEscape = mainConfig.keepInventoryOnEscape; + } + + if (configFile.contains("keepInventoryOnFinish")) { + keepInventoryOnFinish = configFile.getBoolean("keepInventoryOnFinish"); + } else { + keepInventoryOnFinish = mainConfig.keepInventoryOnFinish; + } + + if (configFile.contains("keepInventoryOnDeath")) { + keepInventoryOnDeath = configFile.getBoolean("keepInventoryOnDeath"); + } else { + keepInventoryOnDeath = mainConfig.keepInventoryOnDeath; + } + + /* Lives */ if (configFile.contains("initialLives")) { initialLives = configFile.getInt("initialLives"); } else { @@ -316,6 +346,22 @@ public class DConfig { return keepInventory; } + public boolean getKeepInventoryOnEnter() { + return keepInventoryOnEnter; + } + + public boolean getKeepInventoryOnEscape() { + return keepInventoryOnEscape; + } + + public boolean getKeepInventoryOnFinish() { + return keepInventoryOnFinish; + } + + public boolean getKeepInventoryOnDeath() { + return keepInventoryOnDeath; + } + public int getInitialLives() { return initialLives; } diff --git a/src/com/dre/dungeonsxl/DPlayer.java b/src/com/dre/dungeonsxl/DPlayer.java index 8bbab195..65362b90 100644 --- a/src/com/dre/dungeonsxl/DPlayer.java +++ b/src/com/dre/dungeonsxl/DPlayer.java @@ -76,7 +76,7 @@ public class DPlayer { this.clearPlayerData(); } else { this.player.setGameMode(GameMode.SURVIVAL); - if (!(GameWorld.get(world).config.getKeepInventory())) { + if (!(GameWorld.get(world).config.getKeepInventoryOnEnter())) { this.clearPlayerData(); } if (GameWorld.get(world).config.isLobbyDisabled()) { @@ -218,7 +218,7 @@ public class DPlayer { } // Respawn Items - if (!(GameWorld.get(world).config.getKeepInventory())) { + if (!(GameWorld.get(world).config.getKeepInventoryOnDeath())) { if (this.respawnInventory != null || this.respawnArmor != null) { this.player.getInventory().setContents(this.respawnInventory); this.player.getInventory().setArmorContents(this.respawnArmor); diff --git a/src/com/dre/dungeonsxl/P.java b/src/com/dre/dungeonsxl/P.java index 923331d9..889acf17 100644 --- a/src/com/dre/dungeonsxl/P.java +++ b/src/com/dre/dungeonsxl/P.java @@ -32,11 +32,11 @@ import com.dre.dungeonsxl.commands.DCommandRoot; import com.dre.dungeonsxl.game.GameWorld; import com.dre.dungeonsxl.listener.BlockListener; import com.dre.dungeonsxl.listener.CommandListener; -import com.dre.dungeonsxl.listener.DeathListener; import com.dre.dungeonsxl.listener.EntityListener; import com.dre.dungeonsxl.listener.HangingListener; import com.dre.dungeonsxl.listener.PlayerListener; import com.dre.dungeonsxl.listener.WorldListener; +import com.dre.dungeonsxl.listener.player.PlayerDeathListener; import com.dre.dungeonsxl.multiversionhandler.MultiVersionHandler; public class P extends JavaPlugin { @@ -51,7 +51,7 @@ public class P extends JavaPlugin { private static Listener blockListener; private static Listener worldListener; private static Listener hangingListener; - private static Listener deathListener; + private static Listener playerDeathListener; // Main Config Reader public MainConfig mainConfig; @@ -99,14 +99,14 @@ public class P extends JavaPlugin { blockListener = new BlockListener(); worldListener = new WorldListener(); hangingListener = new HangingListener(); - deathListener = new DeathListener(); + playerDeathListener = new PlayerDeathListener(); Bukkit.getServer().getPluginManager().registerEvents(entityListener, this); Bukkit.getServer().getPluginManager().registerEvents(playerListener, this); Bukkit.getServer().getPluginManager().registerEvents(blockListener, this); Bukkit.getServer().getPluginManager().registerEvents(worldListener, this); Bukkit.getServer().getPluginManager().registerEvents(hangingListener, this); - Bukkit.getServer().getPluginManager().registerEvents(deathListener, this); + Bukkit.getServer().getPluginManager().registerEvents(playerDeathListener, this); // Load All this.loadAll(); diff --git a/src/com/dre/dungeonsxl/listener/DeathListener.java b/src/com/dre/dungeonsxl/listener/DeathListener.java deleted file mode 100644 index 58288d76..00000000 --- a/src/com/dre/dungeonsxl/listener/DeathListener.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.dre.dungeonsxl.listener; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; - -import com.dre.dungeonsxl.P; - -public class DeathListener implements Listener { - - P p = P.p; - int lives = -1; - - @EventHandler - public void onDeath(PlayerDeathEvent event) { - Player player = event.getEntity(); - if (P.lives.containsKey(player)) { - lives = P.lives.get(player) - 1; - P.lives.put(player, lives); - } - if (lives == 0) { - Bukkit.broadcastMessage(p.language.get("Player_DeathKick").replaceAll("v1", player.getName()).replaceAll("&", "\u00a76")); - player.performCommand("dxl leave"); - } else if (!(lives == -1)) { - p.msg(player, p.language.get("Player_Death").replaceAll("v1", String.valueOf(lives))); - } - } - -} diff --git a/src/com/dre/dungeonsxl/listener/PlayerListener.java b/src/com/dre/dungeonsxl/listener/PlayerListener.java index e941e73b..fdf3ec52 100644 --- a/src/com/dre/dungeonsxl/listener/PlayerListener.java +++ b/src/com/dre/dungeonsxl/listener/PlayerListener.java @@ -10,7 +10,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; -import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; @@ -378,19 +377,6 @@ public class PlayerListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGH) - public void onPlayerDeath(PlayerDeathEvent event) { - DPlayer dplayer = DPlayer.get(event.getEntity()); - if (dplayer != null) { - dplayer.respawnInventory = event.getEntity().getInventory().getContents(); - dplayer.respawnArmor = event.getEntity().getInventory().getArmorContents(); - // Delete all drops - for (ItemStack istack : event.getDrops()) { - istack.setType(Material.AIR); - } - } - } - // Deny Player Cmds @EventHandler(priority = EventPriority.HIGH) public void onPlayerCommand(PlayerCommandPreprocessEvent event) { diff --git a/src/com/dre/dungeonsxl/listener/player/PlayerDeathListener.java b/src/com/dre/dungeonsxl/listener/player/PlayerDeathListener.java new file mode 100644 index 00000000..49e41965 --- /dev/null +++ b/src/com/dre/dungeonsxl/listener/player/PlayerDeathListener.java @@ -0,0 +1,54 @@ +package com.dre.dungeonsxl.listener.player; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.inventory.ItemStack; + +import com.dre.dungeonsxl.DConfig; +import com.dre.dungeonsxl.DPlayer; +import com.dre.dungeonsxl.P; +import com.dre.dungeonsxl.game.GameWorld; + +public class PlayerDeathListener implements Listener { + + P p = P.p; + int lives = -1; + + @EventHandler(priority = EventPriority.HIGH) + public void onDeath(PlayerDeathEvent event) { + Player player = event.getEntity(); + DPlayer dplayer = DPlayer.get(player); + + DConfig dConfig = GameWorld.get(player.getLocation().getWorld()).config; + + if (dConfig.getKeepInventoryOnDeath()) { + if (dplayer != null) { + dplayer.respawnInventory = event.getEntity().getInventory().getContents(); + dplayer.respawnArmor = event.getEntity().getInventory().getArmorContents(); + // Delete all drops + for (ItemStack istack : event.getDrops()) { + istack.setType(Material.AIR); + } + } + } + + if (P.lives.containsKey(player)) { + lives = P.lives.get(player) - 1; + P.lives.put(player, lives); + } + + if (lives == 0) { + Bukkit.broadcastMessage(p.language.get("Player_DeathKick").replaceAll("v1", player.getName()).replaceAll("&", "\u00a76")); + player.performCommand("dxl leave"); + } else if (!(lives == -1)) { + p.msg(player, p.language.get("Player_Death").replaceAll("v1", String.valueOf(lives))); + } + + } + +} From 0dc20b271b9f987c792245f73ade0f469935c0ab Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 12 Aug 2015 20:16:08 +0200 Subject: [PATCH 07/10] Small fixes / improvements concerning lives --- src/com/dre/dungeonsxl/DPlayer.java | 4 ++-- src/com/dre/dungeonsxl/P.java | 2 +- src/com/dre/dungeonsxl/commands/CMDLives.java | 4 ++-- .../listener/player/PlayerDeathListener.java | 18 +++++++++--------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/com/dre/dungeonsxl/DPlayer.java b/src/com/dre/dungeonsxl/DPlayer.java index 65362b90..e54b83e0 100644 --- a/src/com/dre/dungeonsxl/DPlayer.java +++ b/src/com/dre/dungeonsxl/DPlayer.java @@ -86,7 +86,7 @@ public class DPlayer { } // Lives - P.lives.put(this.player, initialLives); + p.lives.put(this.player, initialLives); DUtility.secureTeleport(this.player, teleport); } @@ -112,7 +112,7 @@ public class DPlayer { remove(this); // Lives - P.lives.remove(player); + p.lives.remove(player); this.savePlayer.reset(); diff --git a/src/com/dre/dungeonsxl/P.java b/src/com/dre/dungeonsxl/P.java index 889acf17..054b5956 100644 --- a/src/com/dre/dungeonsxl/P.java +++ b/src/com/dre/dungeonsxl/P.java @@ -43,7 +43,7 @@ public class P extends JavaPlugin { public static P p; // Lives - public static HashMap lives; + public HashMap lives; // Listener private static Listener entityListener; diff --git a/src/com/dre/dungeonsxl/commands/CMDLives.java b/src/com/dre/dungeonsxl/commands/CMDLives.java index ce56c8c8..a69d576e 100644 --- a/src/com/dre/dungeonsxl/commands/CMDLives.java +++ b/src/com/dre/dungeonsxl/commands/CMDLives.java @@ -18,8 +18,8 @@ public class CMDLives extends DCommand { public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; String lives = ""; - if (P.lives.containsKey(player)) { - lives = String.valueOf(P.lives.get(player)); + if (P.p.lives.containsKey(player)) { + lives = String.valueOf(P.p.lives.get(player)); p.msg(player, p.language.get("Cmd_Lives").replaceAll("v1", player.getName()).replaceAll("v2", lives)); } else { p.msg(player, p.language.get("Error_NotInDungeon")); diff --git a/src/com/dre/dungeonsxl/listener/player/PlayerDeathListener.java b/src/com/dre/dungeonsxl/listener/player/PlayerDeathListener.java index 49e41965..d024936d 100644 --- a/src/com/dre/dungeonsxl/listener/player/PlayerDeathListener.java +++ b/src/com/dre/dungeonsxl/listener/player/PlayerDeathListener.java @@ -22,14 +22,14 @@ public class PlayerDeathListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onDeath(PlayerDeathEvent event) { Player player = event.getEntity(); - DPlayer dplayer = DPlayer.get(player); + DPlayer dPlayer = DPlayer.get(player); DConfig dConfig = GameWorld.get(player.getLocation().getWorld()).config; if (dConfig.getKeepInventoryOnDeath()) { - if (dplayer != null) { - dplayer.respawnInventory = event.getEntity().getInventory().getContents(); - dplayer.respawnArmor = event.getEntity().getInventory().getArmorContents(); + if (dPlayer != null) { + dPlayer.respawnInventory = event.getEntity().getInventory().getContents(); + dPlayer.respawnArmor = event.getEntity().getInventory().getArmorContents(); // Delete all drops for (ItemStack istack : event.getDrops()) { istack.setType(Material.AIR); @@ -37,13 +37,13 @@ public class PlayerDeathListener implements Listener { } } - if (P.lives.containsKey(player)) { - lives = P.lives.get(player) - 1; - P.lives.put(player, lives); + if (p.lives.containsKey(player)) { + lives = p.lives.get(player) - 1; + p.lives.put(player, lives); } - if (lives == 0) { - Bukkit.broadcastMessage(p.language.get("Player_DeathKick").replaceAll("v1", player.getName()).replaceAll("&", "\u00a76")); + if (lives == 0 && dPlayer.isReady) { + Bukkit.broadcastMessage(p.language.get("Player_DeathKick").replaceAll("v1", player.getName()).replaceAll("&", "\u00a7")); player.performCommand("dxl leave"); } else if (!(lives == -1)) { p.msg(player, p.language.get("Player_Death").replaceAll("v1", String.valueOf(lives))); From b4599e74f3bb59c09b2ec43ba4087f7097d72bb9 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 26 Aug 2015 21:35:15 +0200 Subject: [PATCH 08/10] keepInventory split --- src/com/dre/dungeonsxl/DConfig.java | 22 +++++++++++------- src/com/dre/dungeonsxl/DPlayer.java | 17 ++++++++++---- src/com/dre/dungeonsxl/DSavePlayer.java | 31 +++++++++++++------------ 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/com/dre/dungeonsxl/DConfig.java b/src/com/dre/dungeonsxl/DConfig.java index e5ecfe27..a9244ca5 100644 --- a/src/com/dre/dungeonsxl/DConfig.java +++ b/src/com/dre/dungeonsxl/DConfig.java @@ -155,11 +155,21 @@ public class DConfig { /* Keep Inventory */ if (configFile.contains("keepInventory")) { - keepInventoryOnEnter = configFile.getBoolean("keepInventory"); - keepInventoryOnEscape = configFile.getBoolean("keepInventory"); - keepInventoryOnFinish = configFile.getBoolean("keepInventory"); + if (!configFile.contains("keepInventoryOnEnter")) { + keepInventoryOnEnter = configFile.getBoolean("keepInventory"); + } + if (!configFile.contains("keepInventoryOnEscape")) { + keepInventoryOnEscape = configFile.getBoolean("keepInventory"); + } + if (!configFile.contains("keepInventoryOnFinish")) { + keepInventoryOnFinish = configFile.getBoolean("keepInventory"); + } } else { - keepInventory = mainConfig.keepInventory; + if (mainConfig.keepInventory) { + keepInventoryOnEnter = mainConfig.keepInventory; + keepInventoryOnEscape = mainConfig.keepInventory; + keepInventoryOnFinish = mainConfig.keepInventory; + } } if (configFile.contains("keepInventoryOnEnter")) { @@ -342,10 +352,6 @@ public class DConfig { return tmpSecureObjects; } - public boolean getKeepInventory() { - return keepInventory; - } - public boolean getKeepInventoryOnEnter() { return keepInventoryOnEnter; } diff --git a/src/com/dre/dungeonsxl/DPlayer.java b/src/com/dre/dungeonsxl/DPlayer.java index e54b83e0..4df29995 100644 --- a/src/com/dre/dungeonsxl/DPlayer.java +++ b/src/com/dre/dungeonsxl/DPlayer.java @@ -76,10 +76,11 @@ public class DPlayer { this.clearPlayerData(); } else { this.player.setGameMode(GameMode.SURVIVAL); - if (!(GameWorld.get(world).config.getKeepInventoryOnEnter())) { + DConfig dConfig = GameWorld.get(world).config; + if (!(dConfig.getKeepInventoryOnEnter())) { this.clearPlayerData(); } - if (GameWorld.get(world).config.isLobbyDisabled()) { + if (dConfig.isLobbyDisabled()) { this.ready(); } initialLives = GameWorld.get(world).config.getInitialLives(); @@ -105,7 +106,7 @@ public class DPlayer { public void escape() { remove(this); - this.savePlayer.reset(); + this.savePlayer.reset(false); } public void leave() { @@ -114,7 +115,13 @@ public class DPlayer { // Lives p.lives.remove(player); - this.savePlayer.reset(); + DConfig dConfig = GameWorld.get(world).config; + if (this.isFinished) { + this.savePlayer.reset(dConfig.getKeepInventoryOnFinish()); + } + else { + this.savePlayer.reset(dConfig.getKeepInventoryOnEscape()); + } if (this.isEditing) { EditWorld eworld = EditWorld.get(this.world); @@ -218,7 +225,7 @@ public class DPlayer { } // Respawn Items - if (!(GameWorld.get(world).config.getKeepInventoryOnDeath())) { + if (GameWorld.get(world).config.getKeepInventoryOnDeath()) { if (this.respawnInventory != null || this.respawnArmor != null) { this.player.getInventory().setContents(this.respawnInventory); this.player.getInventory().setArmorContents(this.respawnArmor); diff --git a/src/com/dre/dungeonsxl/DSavePlayer.java b/src/com/dre/dungeonsxl/DSavePlayer.java index 47c72297..d59e70c2 100644 --- a/src/com/dre/dungeonsxl/DSavePlayer.java +++ b/src/com/dre/dungeonsxl/DSavePlayer.java @@ -59,30 +59,31 @@ public class DSavePlayer { save(); } - public void reset() { + public void reset(boolean keepInventory) { Player onlinePlayer = p.getServer().getPlayer(this.playerName); try{ if (onlinePlayer != null) { /* Player is online */ - onlinePlayer.getInventory().setContents(this.oldInventory); - onlinePlayer.getInventory().setArmorContents(this.oldArmor); - onlinePlayer.setTotalExperience(this.oldExp); - onlinePlayer.setLevel(this.oldLvl); - onlinePlayer.setHealth(this.oldHealth); - onlinePlayer.setFoodLevel(this.oldFoodLevel); - onlinePlayer.setGameMode(this.oldGamemode); - onlinePlayer.setFireTicks(this.oldFireTicks); - for (PotionEffect effect : onlinePlayer.getActivePotionEffects()) { - onlinePlayer.removePotionEffect(effect.getType()); + if (!keepInventory) { + onlinePlayer.getInventory().setContents(this.oldInventory); + onlinePlayer.getInventory().setArmorContents(this.oldArmor); + onlinePlayer.setTotalExperience(this.oldExp); + onlinePlayer.setLevel(this.oldLvl); + onlinePlayer.setHealth(this.oldHealth); + onlinePlayer.setFoodLevel(this.oldFoodLevel); + onlinePlayer.setGameMode(this.oldGamemode); + onlinePlayer.setFireTicks(this.oldFireTicks); + for (PotionEffect effect : onlinePlayer.getActivePotionEffects()) { + onlinePlayer.removePotionEffect(effect.getType()); + } + onlinePlayer.addPotionEffects(this.oldPotionEffects); } - onlinePlayer.addPotionEffects(this.oldPotionEffects); - DUtility.secureTeleport(onlinePlayer, this.oldLocation); } else { /* Player is offline */ Player offlinePlayer = p.getOfflinePlayer(this.playerName, UUID.fromString(uuid), this.oldLocation); - if (offlinePlayer != null) { + if (offlinePlayer != null && !keepInventory) { offlinePlayer.getInventory().setContents(this.oldInventory); offlinePlayer.getInventory().setArmorContents(this.oldArmor); offlinePlayer.setTotalExperience(this.oldExp); @@ -174,7 +175,7 @@ public class DSavePlayer { // Create Player DSavePlayer savePlayer = new DSavePlayer(playerName, uuid, oldLocation, oldInventory, oldArmor, oldLvl, oldExp, oldHealth, oldFoodLevel, oldFireTicks, oldGamemode, oldPotionEffects); - savePlayer.reset(); + savePlayer.reset(false); } } From cabbb35775b490345674323ef20ee6a43e7b5d9b Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Fri, 28 Aug 2015 21:56:29 +0200 Subject: [PATCH 09/10] Added MythicMobs compatibility to mob trigger --- src/com/dre/dungeonsxl/DPlayer.java | 4 ++- src/com/dre/dungeonsxl/game/DMob.java | 20 ++++++++++++ .../dre/dungeonsxl/signs/SIGNMythicMobs.java | 32 +++++++++++++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/com/dre/dungeonsxl/DPlayer.java b/src/com/dre/dungeonsxl/DPlayer.java index 4df29995..cbb8f68e 100644 --- a/src/com/dre/dungeonsxl/DPlayer.java +++ b/src/com/dre/dungeonsxl/DPlayer.java @@ -113,7 +113,9 @@ public class DPlayer { remove(this); // Lives - p.lives.remove(player); + if (p.lives.containsKey(player)) { + p.lives.remove(player); + } DConfig dConfig = GameWorld.get(world).config; if (this.isFinished) { diff --git a/src/com/dre/dungeonsxl/game/DMob.java b/src/com/dre/dungeonsxl/game/DMob.java index 40eef78b..d07ea539 100644 --- a/src/com/dre/dungeonsxl/game/DMob.java +++ b/src/com/dre/dungeonsxl/game/DMob.java @@ -2,6 +2,7 @@ package com.dre.dungeonsxl.game; import java.util.Random; +import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; @@ -15,6 +16,8 @@ public class DMob { public LivingEntity entity; public DMobType type; + public String trigger; + public DMob(LivingEntity entity, GameWorld gworld, DMobType type) { gworld.dmobs.add(this); @@ -29,6 +32,21 @@ public class DMob { this.entity.getEquipment().setItemInHandDropChance(0); } + public DMob(LivingEntity entity, GameWorld gworld, DMobType type, String trigger) { + gworld.dmobs.add(this); + + this.entity = entity; + this.type = type; + this.trigger = trigger; + + /* Remove DropChance of equipment */ + this.entity.getEquipment().setHelmetDropChance(0); + this.entity.getEquipment().setChestplateDropChance(0); + this.entity.getEquipment().setLeggingsDropChance(0); + this.entity.getEquipment().setBootsDropChance(0); + this.entity.getEquipment().setItemInHandDropChance(0); + } + // Statics public static void onDeath(EntityDeathEvent event) { if (event.getEntity() instanceof LivingEntity) { @@ -49,6 +67,8 @@ public class DMob { } } name = dmob.type.getName(); + } else if (dmob.type == null && dmob.trigger != null) {// <=MythicMobs mob + name = dmob.trigger; } else { name = victim.getType().getName(); } diff --git a/src/com/dre/dungeonsxl/signs/SIGNMythicMobs.java b/src/com/dre/dungeonsxl/signs/SIGNMythicMobs.java index 6cbba69b..9881e654 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNMythicMobs.java +++ b/src/com/dre/dungeonsxl/signs/SIGNMythicMobs.java @@ -1,11 +1,16 @@ package com.dre.dungeonsxl.signs; +import java.util.ArrayList; + +import org.bukkit.entity.Entity; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Sign; +import org.bukkit.entity.LivingEntity; import org.bukkit.Location; +import com.dre.dungeonsxl.game.DMob; import com.dre.dungeonsxl.game.GameWorld; public class SIGNMythicMobs extends DSign { @@ -22,6 +27,9 @@ public class SIGNMythicMobs extends DSign { private boolean initialized; private boolean active; private int taskId = -1; + private Location spawnLoc; + private LivingEntity mythicMob; + private ArrayList mythicMobs = new ArrayList(); public SIGNMythicMobs(Sign sign, GameWorld gworld) { super(sign, gworld); @@ -104,15 +112,19 @@ public class SIGNMythicMobs extends DSign { GameWorld gworld = GameWorld.get(world); if (gworld != null) { - Location spawnLoc = sign.sign.getLocation().add(0.5, 0, 0.5); + spawnLoc = sign.sign.getLocation().add(0.5, 0, 0.5); double x = spawnLoc.getX(); double y = spawnLoc.getY(); double z = spawnLoc.getZ(); String command = "mm mobs spawn " + mob + " " + amount + " DXL_Game_" + gworld.id + ","+ x + "," + y + "," + z; - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command); + setMythicMobs(); + if (mythicMob != null) { + new DMob(mythicMob, sign.gworld, null, mob); + } + // Set the amount if (amount != -1) { if (amount > 1) { @@ -141,4 +153,20 @@ public class SIGNMythicMobs extends DSign { public boolean isOnDungeonInit() { return onDungeonInit; } + + private void setMythicMobs() { + for (Entity entity : spawnLoc.getChunk().getEntities()) { + if (entity.getLocation().getX() >= spawnLoc.getX()-1 + && entity.getLocation().getX() <= spawnLoc.getX()+1 + && entity.getLocation().getY() >= spawnLoc.getY()-1 + && entity.getLocation().getY() <= spawnLoc.getY()+1 + && entity.getLocation().getZ() >= spawnLoc.getZ()-1 + && entity.getLocation().getZ() <= spawnLoc.getZ()+1 + && !mythicMobs.contains(entity)) { + mythicMob = (LivingEntity) entity; + mythicMobs.add(entity); + return; + } + } + } } From 2fe1c9d28a2e5a82d6cf23299081bb89cbb456bc Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sat, 29 Aug 2015 15:44:13 +0200 Subject: [PATCH 10/10] Fixed NPE in /dxl leave --- src/com/dre/dungeonsxl/DPlayer.java | 16 ++++++++++------ src/com/dre/dungeonsxl/game/DMob.java | 1 - src/com/dre/dungeonsxl/game/GameChest.java | 5 ++++- src/plugin.yml | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/com/dre/dungeonsxl/DPlayer.java b/src/com/dre/dungeonsxl/DPlayer.java index cbb8f68e..f15e5800 100644 --- a/src/com/dre/dungeonsxl/DPlayer.java +++ b/src/com/dre/dungeonsxl/DPlayer.java @@ -117,12 +117,16 @@ public class DPlayer { p.lives.remove(player); } - DConfig dConfig = GameWorld.get(world).config; - if (this.isFinished) { - this.savePlayer.reset(dConfig.getKeepInventoryOnFinish()); - } - else { - this.savePlayer.reset(dConfig.getKeepInventoryOnEscape()); + if (!this.isEditing) { + DConfig dConfig = GameWorld.get(world).config; + if (this.isFinished) { + this.savePlayer.reset(dConfig.getKeepInventoryOnFinish()); + } + else { + this.savePlayer.reset(dConfig.getKeepInventoryOnEscape()); + } + } else { + this.savePlayer.reset(false); } if (this.isEditing) { diff --git a/src/com/dre/dungeonsxl/game/DMob.java b/src/com/dre/dungeonsxl/game/DMob.java index d07ea539..e1592d0e 100644 --- a/src/com/dre/dungeonsxl/game/DMob.java +++ b/src/com/dre/dungeonsxl/game/DMob.java @@ -2,7 +2,6 @@ package com.dre.dungeonsxl.game; import java.util.Random; -import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; diff --git a/src/com/dre/dungeonsxl/game/GameChest.java b/src/com/dre/dungeonsxl/game/GameChest.java index f63a290f..a586a928 100644 --- a/src/com/dre/dungeonsxl/game/GameChest.java +++ b/src/com/dre/dungeonsxl/game/GameChest.java @@ -61,6 +61,9 @@ public class GameChest { msg = msg.substring(0, msg.length() - 1); P.p.msg(player, P.p.language.get("Player_LootAdded", msg)); + if (moneyReward != 0) { + P.p.msg(player, P.p.language.get("Player_LootAdded", String.valueOf(moneyReward))); + } } } } @@ -85,7 +88,7 @@ public class GameChest { event.setCancelled(true); } } else { - P.p.msg(P.p.getServer().getPlayer(event.getPlayer().getName()), ChatColor.RED + "Diese Kiste wurde schon geöffnet!"); + P.p.msg(P.p.getServer().getPlayer(event.getPlayer().getUniqueId()), ChatColor.RED + "Diese Kiste wurde schon geöffnet!"); event.setCancelled(true); } } diff --git a/src/plugin.yml b/src/plugin.yml index 6bd103b0..b0a2bcae 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: DungeonsXL main: com.dre.dungeonsxl.P -version: 0.9.6-SNAPSHOT +version: 0.9.6 author: Frank Baumann authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel] website: http://www.dre2n.ml