// /town deposit <amount> public static void deposit(Player player, String amountString) { PlayerData playerData = Players.get(player.getName()); double amount; Holdings holdings = iConomy.getAccount(player.getName()).getHoldings(); PlayerTown playerTown = PlayerTowns.get(playerData.townName); // Make sure the player is a resident of a town if (playerData.townName.equals("")) { Util.message(player, "Only town residents can use the deposit command."); return; } // Ensure that the typed amount is a valid number try { amount = Double.parseDouble(amountString); } catch (Exception ex) { Util.message(player, "Invalid amount."); return; } // Ensure that the amount is greater than 0 (no sneaky withdrawls!) if (amount <= 0) { Util.message(player, "Invalid amount."); return; } // Make sure the player has enough money to make the deposit if (!holdings.hasEnough(amount)) { Util.message(player, "You only have " + iConomy.format(holdings.balance()) + "."); return; } // Subtract the amount from the player's balance holdings.subtract(amount); // Update the database RageMod.database.townDeposit(playerTown.id_PlayerTown, playerData.id_Player, amount); // Update the town data playerTown.treasuryBalance += amount; PlayerTowns.put(playerTown); // Update the player data playerData.treasuryBalance += amount; Players.update(playerData); Util.message(player, "Deposited " + iConomy.format(amount) + " into town treasury."); }
/** On player move, detect they are inside a portal then teleport them appropriately. */ @Override public void onPlayerMove(PlayerMoveEvent event) { if (event.isCancelled()) { return; } /** Grab the Player and our Players Session */ final Player pl = event.getPlayer(); final Location loc = pl.getLocation(); MVPlayerSession ps = this.plugin.getPlayerSession(pl); if (ps == null || ps.getLocation().getBlockX() == loc.getBlockX() && ps.getLocation().getBlockY() == loc.getBlockY() && ps.getLocation().getBlockZ() == loc.getBlockZ()) { return; } else { ps.setLocation(loc); // Update the Players Session to the new Location. } /** Start the Price off at 0, this will change according to the Portal/World Settings. */ Integer price = 0; /** Start of our Location as NULL, this allows us to check it later on. */ Location d = null; /** * First we do a check against all the Portals we have created, if the area the user is within * is a Portal then we will act upon it; if not then we move onto our next check. */ String ptest = utils.isPortal(pl.getLocation()); if (ptest != null) { MVPortal p = this.plugin.MVPortals.get(ptest); price = (int) Math.round(p.getPrice()); d = playerTeleporter.portalDestination(pl, ptest, p); } /** End of First Portal Check. */ /** * If the first Portal Check failed then we will check for Any Signs around the player. This * check is only performed if the user is standing inside a Portal Block. */ if (this.plugin.configMV.getBoolean("checksigns", true) && d == null) { d = playerTeleporter.portalSignMethod(pl); } /** End of Sign Based Portal Check. */ /** * Standard Nether Portal Check, this will be for a Single Player like feel, customizeable... * Can be on or off. */ if (this.plugin.configMV.getBoolean("splike", false) && d == null) { d = playerTeleporter.portalSPNether(pl); } /** End of Single Player Nether Check. */ // TODO: Permissions to add here... /** If we have a Location set and it is NOT NULL then we can perform a teleport. */ if (d != null) { if (!ps.getTeleportable()) { return; } if (!playerTeleporter.canTravelFromWorld(pl, d.getWorld())) { ps.sendMessage( "Sorry but you cannot travel to '" + d.getWorld().getName() + "' from this World!"); return; } if (!playerTeleporter.canEnterWorld(pl, d.getWorld())) { ps.sendMessage("Sorry but you cannot enter the '" + d.getWorld().getName() + "' world."); return; } if (MultiVerse.useiConomy && !MultiVerse.Permissions.has(pl, "multiverse.portal.exempt") && price > 0) { Holdings balance = iConomy.getAccount(pl.getName()).getHoldings(); if (balance.hasEnough(price)) { balance.subtract(price); pl.sendMessage( ChatColor.RED + this.plugin.logPrefix + " You have been charged " + iConomy.format(price)); } else { if (ps.getAlertable()) { pl.sendMessage("Sorry but you do not have the required funds for this portal"); ps.setAlertCooldown(); } return; } } final Location destination = d; plugin .getServer() .getScheduler() .scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { pl.teleport(destination); } }); ps.setTPCooldown(); return; } return; }
// /town create <town_name> public static void create(Player player, String townName) { PlayerData playerData = Players.get(player.getName()); HashMap<String, Integer> nearbyTowns = PlayerTowns.checkForNearbyTowns(player.getLocation()); Holdings holdings = iConomy.getAccount(player.getName()).getHoldings(); int cost = RageConfig.townLevels.get(1).initialCost; // Ensure that the player is not currently a resident of a town if (!playerData.townName.equals("")) { Util.message( player, "You are already a resident of '" + playerData.townName + "'; you must use '/town leave' before you can create a new town."); return; } // Ensure that the town name is not taken if (PlayerTowns.get(townName) != null) { Util.message(player, "A town named " + townName + " already exists!"); return; } // Ensure that the current zone is allowed to create towns if (!RageZones.checkPermission(player.getLocation(), Action.TOWN_CREATE)) { Util.message(player, "You cannot create a town in this zone."); return; } // Check for any towns that are too close to the current point - list all if (nearbyTowns.size() > 0) { String message = "You are too close to the following towns: "; for (String nearbyTownName : nearbyTowns.keySet()) { message += nearbyTownName + " (" + nearbyTowns.get(nearbyTownName) + "m) "; } Util.message(player, message); Util.message( player, "Towns must be a minimum distance of " + RageConfig.Town_MIN_DISTANCE_BETWEEN + "m apart."); return; } // Check to see if the player has enough money to join the specified faction if (!holdings.hasEnough(cost)) { Util.message( player, "You need at least " + iConomy.format(cost) + " to create a " + RageConfig.townLevels.get(1).name + "."); return; } // Subtract from player balance holdings.subtract(cost); // TODO: Check against NPC town names // Create the town if name selected, otherwise return message if (!townName.equals("")) { // Add the new town to the database int townID = RageMod.database.townCreate(player, townName); // Update PlayerTowns PlayerTown playerTown = new PlayerTown(); playerTown.id_PlayerTown = townID; playerTown.townName = townName; playerTown.centerPoint = new Location2D((int) player.getLocation().getX(), (int) player.getLocation().getZ()); playerTown.id_Faction = playerData.id_Faction; playerTown.bankruptDate = null; playerTown.townLevel = RageConfig.townLevels.get(1); playerTown.treasuryBalance = RageConfig.townLevels.get(1).minimumBalance; playerTown.minimumBalance = RageConfig.townLevels.get(1).minimumBalance; playerTown.mayor = playerData.name; playerTown.world = player.getWorld(); playerTown.buildRegion(); playerTown.createBorder(); PlayerTowns.put(playerTown); // Update the playerData playerData.townName = townName; playerData.isMayor = true; playerData.currentTown = playerTown; playerData.treasuryBalance = cost; Players.update(playerData); Util.message(player, "Congratulations, you are the new mayor of " + townName + "!"); } else { Util.message( player, "This location is valid for a new town - to create one, type '/town create <town_name>'"); } }