Explorar o código

* added cmd: /atm balance <player>, minor bugfixes

mastercake10 %!s(int64=7) %!d(string=hai) anos
pai
achega
f5a0ef27e6

+ 12 - 1
TimeIsMoney2/src/de/Linus122/TimeIsMoney/Main.java

@@ -23,6 +23,7 @@ import java.util.UUID;
 
 import org.bukkit.Bukkit;
 import org.bukkit.Location;
+import org.bukkit.Server;
 import org.bukkit.command.Command;
 import org.bukkit.command.ConsoleCommandSender;
 import org.bukkit.command.PluginCommand;
@@ -329,7 +330,7 @@ public class Main extends JavaPlugin{
 			sendActionbar(p, message.replace("%money%", economy.format(payout.payout_amount)));
 		}
 		for(String cmd : payout.commands){
-			this.getServer().dispatchCommand(this.getServer().getConsoleSender(), cmd.replace("/", "").replaceAll("%player%", p.getName()));
+			dispatchCommandSync(cmd.replace("/", "").replaceAll("%player%", p.getName()));
 		}
 		
 		//ADD PAYED MONEY
@@ -342,6 +343,16 @@ public class Main extends JavaPlugin{
 		lastLocation.put(p.getUniqueId(), p.getLocation());
 	
 	}
+	public void dispatchCommandSync(final String cmd){
+		final Server server = this.getServer();
+		
+		this.getServer().getScheduler().runTask(this, new Runnable(){
+			
+			public void run(){
+				server.dispatchCommand(server.getConsoleSender(), cmd);
+			}
+		});
+	}
 	@SuppressWarnings("deprecation")
 	public void log(String msg){
 		if(!this.getConfig().getBoolean("debug-log")){

+ 30 - 10
TimeIsMoney2/src/modules/atm/ATM.java

@@ -73,6 +73,12 @@ public class ATM implements Listener, CommandExecutor {
 		}
 		
 	}
+	//Doesn't support groups 
+	public static double getBankBalance(OfflinePlayer p){
+		String bankString =  p.getName() + "_TimBANK";
+		if(!cfg.contains(bankString)) cfg.set(bankString, 0.0);
+		return cfg.getDouble(bankString);
+	}
 	public static double getBankBalance(Player p){
 		String bankString = getBankString(p);
 		if(!cfg.contains(bankString)) cfg.set(bankString, 0.0);
@@ -341,18 +347,32 @@ public class ATM implements Listener, CommandExecutor {
 		}
 		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!");
+				switch(args[0]){
+					case "balance":
+						if(args.length > 1){		
+							cs.sendMessage("§2ATM-Balance of§c " + args[1] + "§2: §c" + this.getBankBalance(Bukkit.getOfflinePlayer(args[1])));
+						}else{
+							cs.sendMessage("/atm balance <player>");
+						}
+						break;
+					default:
+						@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!");
+						}
+						break;
+						
 				}
+			
 			}else{
-				cs.sendMessage("/atm <player>");
+				cs.sendMessage("§c/atm <player> §a- opens atm for player");
+				cs.sendMessage("§c/atm balance <player> §a- gets balance of player");
 				return true;
 			}
 		}

+ 18 - 0
TimeIsMoney2/src/v1_12_R1/NBTUtils.java

@@ -0,0 +1,18 @@
+package v1_12_R1;
+
+import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+
+import de.Linus122.TimeIsMoney.Utils;
+import net.minecraft.server.v1_12_R1.ChatMessageType;
+import net.minecraft.server.v1_12_R1.IChatBaseComponent;
+import net.minecraft.server.v1_12_R1.PacketPlayOutChat;
+
+public class NBTUtils implements Utils{
+  public void sendActionBarMessage(Player p, String message)
+  {
+	    IChatBaseComponent icbc = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + message.replace('&', '§') + "\"}");
+	    PacketPlayOutChat bar = new PacketPlayOutChat(icbc, ChatMessageType.GAME_INFO);
+	    ((CraftPlayer)p).getHandle().playerConnection.sendPacket(bar);
+  }
+}