Explorar o código

improve the atm per world feature

linus %!s(int64=8) %!d(string=hai) anos
pai
achega
7074a95c2f

+ 19 - 0
TimeIsMoney2/src/config.yml

@@ -44,3 +44,22 @@ atm_title: "&cATM"
 atm_withdraw: "&cWithdraw"
 atm_deposit: "&cDeposit"
 atm_balance: "&cBank balance:"
+# You can seperate the ATM balances for different worlds by group them. Just set group-atms to true and write atm_groups as described below.
+# Note: Existing bank accounts will be removed when enabling this feature. 
+group-atms: false
+# Example groups for seperating all worlds:
+#atm_groups:
+#  group1:
+#  - world
+#  group2:
+#  - world_nether
+#  group3:
+#   - world_the_end
+# Example groups for seperating skyblock worlds and survival worlds:
+#atm_groups:
+#  group1:
+#  - ASkyblock_world
+#  - Askyblock_spawn
+#  group2:
+#  - survival_world
+#  - farm_world

+ 67 - 0
TimeIsMoney2/src/config.yml~

@@ -1,3 +1,69 @@
+<<<<<<< HEAD
+configuration-version: 12
+
+auto-update: true
+debug-log: false
+
+afk_payout: false
+display-messages-in-chat: true
+display-messages-in-actionbar: true
+display-messages-in-actionbar-time: 10
+give_money_every_second: 600
+store-money-in-bank: false
+# Payouts will be delivered by "chance" instead "permission".
+choose-payout-by-chance: false
+
+# You can add as many payouts you want. You only can choose between "permission"
+# and "change", not both.
+payouts:
+  1:
+    payout_amount: 50
+    max_payout_per_day: 1000
+    # chance: 10
+    permission:
+  2:
+    payout_amount: 100
+    max_payout_per_day: 10000
+    commands:
+      - /give %player% diamond 1
+    # chance: 90
+    # You can use any permission name you want. e.g. myserver.donor
+    permission: tim.vip
+
+# Translations
+message: "&aYou earned &c%money% &afor 10 minutes online time!"
+message_payoutlimit_reached: "&cYou have reached the payout limit today. You earned 0$"
+message_afk: "&cYou havn't earned money because you were afk!"
+message_actionbar: "&aYou earned &c%money% &afor 10 minutes online time!"
+message_payoutlimit_reached_actionbar: "&cYou have reached the payout limit today. You got 0$"
+message_afk_actionbar: "&cYou havn't earned money because you were afk!"
+message_atm_noperms: "&cYou don't have the permission to use ATM's!"
+message_atm_nomoneyinbank: "&cYou don't have enough money in bank!"
+message_atm_nomoney: "&cYou don't have enough money!"
+# ATM -> Place down a sign with [atm] on the first line to use it!
+atm_title: "&cATM"
+atm_withdraw: "&cWithdraw"
+atm_deposit: "&cDeposit"
+atm_balance: "&cBank balance:"
+# You can seperate the ATM balances for different worlds by group them.
+group-atms: false
+# Example groups for seperating all worlds:
+#atm_groups:
+#  group1:
+#  - world
+#  group2:
+#  - world_nether
+#  group3:
+#   - world_the_end
+# Example groups for seperating skyblock worlds and survival worlds:
+#atm_groups:
+#  group1:
+#  - ASkyblock_world
+#  - Askyblock_spawn
+#  group2:
+#  - survival_world
+#  - farm_world
+=======
 configuration-version: 12
 
 auto-update: true
@@ -44,3 +110,4 @@ atm_title: "&cATM"
 atm_withdraw: "&cWithdraw"
 atm_deposit: "&cDeposit"
 atm_balance: "&cBank balance:"
+>>>>>>> refs/remotes/origin/master

+ 2 - 2
TimeIsMoney2/src/de/Linus122/TimeIsMoney/Main.java

@@ -45,7 +45,7 @@ public class Main extends JavaPlugin{
 	ConsoleCommandSender clogger = this.getServer().getConsoleSender();
 	
 	public static int cfg_version = 12;
-	public static int pl_version = 1928;
+	public static int pl_version = 1930;
 
 	int currentDay = 0;
 	
@@ -304,7 +304,7 @@ public class Main extends JavaPlugin{
 		
 		//DEPOSIT
 		if(finalconfig.getBoolean("store-money-in-bank")){
-			String bank = p.getName() + "_TimBANK";
+			String bank = ATM.getBank(p);
 			if(!Main.economy.hasAccount(bank)){
 				Main.economy.createPlayerAccount(bank);
 			}

+ 46 - 5
TimeIsMoney2/src/modules/atm/ATM.java

@@ -5,8 +5,12 @@ import java.util.List;
 
 import org.bukkit.Bukkit;
 import org.bukkit.Material;
+import org.bukkit.OfflinePlayer;
 import org.bukkit.block.Block;
 import org.bukkit.block.Sign;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
 import org.bukkit.entity.Player;
 import org.bukkit.event.Event.Result;
 import org.bukkit.event.EventHandler;
@@ -26,15 +30,28 @@ import org.bukkit.plugin.Plugin;
 import de.Linus122.TimeIsMoney.Main;
 import net.milkbowl.vault.economy.EconomyResponse;
 
-public class ATM implements Listener {
+public class ATM implements Listener, CommandExecutor {
 	Plugin pl;
 	
-	public ATM(Plugin pl){
+	public ATM(Main pl){
 		this.pl = pl;
 		pl.getServer().getPluginManager().registerEvents(this, pl);
-		
+		pl.getCommand("atm").setExecutor(this);
 	}
 	
+	public static String getBank(Player p){
+		if(!Main.finalconfig.getBoolean("group-atms")){
+			return p.getName() + "_TimBANK";
+		}else{
+			for(String key : Main.finalconfig.getConfigurationSection("atm_groups").getKeys(false)){
+				List<String> list = Main.finalconfig.getStringList("atm_groups." + key);
+				if(list.contains(p.getWorld().getName())){
+					return p.getName() + "_TimBANK_" + key;
+				}
+			}
+		}
+		return p.getName() + "_TimBANK";
+	}
 	@EventHandler(priority = EventPriority.HIGHEST)
 	public void onInteract(PlayerInteractEvent e){
 		if(e.getClickedBlock() != null){
@@ -68,7 +85,7 @@ public class ATM implements Listener {
 			if(e.getInventory().getTitle().equals(Main.finalconfig.getString("atm_title").replace('&', '§'))){
 				e.setResult(Result.DENY);
 				//e.setCancelled(true);
-				String bank = e.getWhoClicked().getName() + "_TimBANK";
+				String bank = getBank((Player)e.getWhoClicked());
 				if(e.getCurrentItem() != null){
 					if(e.getCurrentItem().getItemMeta().getDisplayName().split(" ")[0].equals(Main.finalconfig.getString("atm_withdraw").replace('&', '§'))){
 	
@@ -116,12 +133,14 @@ public class ATM implements Listener {
 			return Main.economy.getBalance(name);
 	}
 	private void openGUI(Player player) {
+		String bank = getBank(player);
+		
 		Inventory atm_gui = Bukkit.createInventory(null, 9, "§cATM");
 		
 		//
 		ItemStack is = new ItemStack(Material.GOLD_NUGGET, 1);
 		ItemMeta im = is.getItemMeta();
-		im.setDisplayName(Main.finalconfig.getString("atm_balance").replace('&', '§') + " " + Main.economy.format(getBankbalance(player.getName() + "_TimBANK")));
+		im.setDisplayName(Main.finalconfig.getString("atm_balance").replace('&', '§') + " " + Main.economy.format(getBankbalance(bank)));
 		is.setItemMeta(im);
 		atm_gui.setItem(4, is);
 		
@@ -253,4 +272,26 @@ public class ATM implements Listener {
 			}, 10L);
 		}
 	}
+
+	@Override
+	public boolean onCommand(CommandSender cs, Command arg1, String arg2, String[] args) {
+		if(cs.hasPermission("tim.admin")){
+			if(args.length > 0){
+				@SuppressWarnings("deprecation")
+				OfflinePlayer op = Bukkit.getOfflinePlayer(args[0]);
+				if(op == null){
+					cs.sendMessage("Player is offline");
+					return true;
+				}
+				if(op.isOnline()){
+					openGUI(op.getPlayer());
+					cs.sendMessage("opened!");
+				}
+			}else{
+				cs.sendMessage("/atm <player>");
+				return true;
+			}
+		}
+		return true;
+	}
 }

+ 4 - 0
TimeIsMoney2/src/plugin.yml

@@ -11,3 +11,7 @@ commands:
       aliases: tim
       usage: /<command>
       permission: tim.reload
+   atm:
+      description: Opens the atm for other player
+      usage: /<command>
+      permission: tim.admin