Commits

Mike Bayer committed 74e6433

- event model is working
- skip zero balances

  • Participants
  • Parent commits 308d185

Comments (0)

Files changed (2)

src/main/java/com/zzzcomputing/bukkit/atmcraft/AtmCraft.java

     			
     		) {
 
+    		// run the inventory changed on the next event tick.
+    		// much easier.
             Bukkit.getScheduler().runTask(this, new Runnable() {
             	
                 @Override

src/main/java/com/zzzcomputing/bukkit/atmcraft/AtmSession.java

 		}
 		for (int i=0; i<names.length(); i++) {
 			String name = names.getString(i);
-			int balance = new Double(result.getDouble(name)).intValue();;
+			int balance = new Double(result.getDouble(name)).intValue();
+			if (balance == 0) {
+				continue;
+			}
 			Material material;
 			try {
 				material = Material.valueOf(name);
 	}
 	
 	private void deposit(Material material, int amount) {
-		Logger.info("Deposit " + String.valueOf(amount) + " of " + material.toString());
-		Util.sendPlayerMessage(player, "Deposit " + String.valueOf(amount) + " of " + material.toString());
+		withdraw_or_deposit(material, amount, false);
 	}
 	
 	private void withdraw(Material material, int amount) {
-		Logger.info("Withdraw " + String.valueOf(amount) + " of " + material.toString());
-		Util.sendPlayerMessage(player, "Withdraw " + String.valueOf(amount) + " of " + material.toString());
+		withdraw_or_deposit(material, amount, true);
 	}
 	
+	private void withdraw_or_deposit(Material material, int amount, boolean withdraw) {
+		String verb;
+		if (withdraw) {
+			verb = "Withdraw";
+		}
+		else {
+			verb = "Deposit";
+		}
+		Logger.info(verb + " " + String.valueOf(amount) + " of " + material.toString());
+
+		String urlParameters = "auth_token=" + authToken;
+		urlParameters += "&type=" + String.valueOf(material);
+		urlParameters += "&amount=" + String.valueOf(amount);
+		String url = getServiceURL() + (withdraw ? "/withdraw" : "/deposit");
+		try {
+			Util.postToJson(url, urlParameters);
+			Util.sendPlayerMessage(player, verb + " " + String.valueOf(amount) + " of " + material.toString());
+		}
+		catch (Exception e) {
+			Util.sendPlayerMessage(player, verb + " failed: " + e);
+			e.printStackTrace();
+		}
+		
+		
+	}
 	private String getServiceURL() {
 		return this.parent.config.getString("serverurl");
 	}