From 9bdab01b10c14c7f12cb94be16d94334d57bc1d6 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 30 Jul 2015 16:47:02 +0200 Subject: [PATCH] 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 {