/** * Creates a new market for the specified word. Places a single sell offer at the price of 0.0, * since it just goes to the highest bidder when the station is free. * * @param w */ private void addNewWordToWordMarket(Word w) { DoubleAuction<Word, WordStationAgent, WordOrderManager> new_market = new DoubleAuction<Word, WordStationAgent, WordOrderManager>(); // add the new word at a free price... only give it to the highest paying wordstation when it's // free Economy economy = SimulationWorldMarketTaskAllocation.getSimulationWorld().economy; float revenue_for_word = economy.getRevenueForCompletingWord(w); new_market.addBid(this, w, revenue_for_word); setProfit(getProfit() + revenue_for_word); wordMarket.put(w, new_market); }
public boolean execute() { if (this.player == null) { return false; } if ((Economy.getEconomy() != null) && (this.cmdBlock.getEconomyPrice() > 0)) { if (!this.player.hasPermission("commandsign.costs.bypass")) { if (Economy.getEconomy().has(this.player, this.cmdBlock.getEconomyPrice())) { Economy.getEconomy().withdrawPlayer(this.player, this.cmdBlock.getEconomyPrice()); String msg = Messages.get("usage.you_paied"); msg = msg.replace("{PRICE}", Economy.getEconomy().format(this.cmdBlock.getEconomyPrice())); this.player.sendMessage(msg); } else { String err = Messages.get("usage.not_enough_money"); err = err.replace("{PRICE}", Economy.getEconomy().format(this.cmdBlock.getEconomyPrice())); this.player.sendMessage(err); return false; } } } if (this.cmdBlock.getTimeBetweenPlayerUsage() > 0) { if (this.cmdBlock.hasPlayerRecentlyUsed(this.player)) { if (!player.hasPermission("commandsign.timer.bypass")) { this.player.sendMessage(Messages.get("usage.player_cooldown")); return false; } } this.cmdBlock.addUsage(this.player); } PermissionAttachment perms = Container.getContainer().getPlayerPermissions(this.player); for (String perm : this.cmdBlock.getPermissions()) { if (!this.player.hasPermission(perm)) { perms.setPermission(perm, true); } } for (String command : this.cmdBlock.getCommands()) { handleCommand(command); } for (String perm : this.cmdBlock.getPermissions()) { if (perms.getPermissions().containsKey(perm)) { perms.unsetPermission(perm); } } return true; }
public void checkRequirements() throws CommandSignsException { if (this.player == null) { throw new CommandSignsException(Messages.get("usage.invalid_player")); } for (String needed : this.cmdBlock.getNeededPermissions()) { if (!this.player.hasPermission(needed)) { String err = Messages.get("usage.miss_needed_permission"); err = err.replace("{NEEDED_PERM}", needed); throw new CommandSignsException(err); } } if (this.cmdBlock.getTimeBetweenUsage() > 0) { long now = System.currentTimeMillis(); long toWait = this.cmdBlock.getLastTimeUsed() + (this.cmdBlock.getTimeBetweenUsage() * 1000) - now; if (toWait > 0) { if (!this.player.hasPermission("commandsign.timer.bypass")) { String msg = Messages.get("usage.general_cooldown"); msg = msg.replace( "{TIME}", df.format(this.cmdBlock.getTimeBetweenUsage() - (toWait / 1000.0))); msg = msg.replace("{REMAINING}", df.format(toWait / 1000.0)); throw new CommandSignsException(msg); } } } if (this.cmdBlock.getTimeBetweenPlayerUsage() > 0) { if (this.cmdBlock.hasPlayerRecentlyUsed(this.player)) { if (!player.hasPermission("commandsign.timer.bypass")) { throw new CommandSignsException(Messages.get("usage.player_cooldown")); } } } if ((Economy.getEconomy() != null) && (this.cmdBlock.getEconomyPrice() > 0)) { if (!Economy.getEconomy().has(this.player, this.cmdBlock.getEconomyPrice()) && !this.player.hasPermission("commandsign.costs.bypass")) { String err = Messages.get("usage.not_enough_money"); err = err.replace("{PRICE}", Economy.getEconomy().format(this.cmdBlock.getEconomyPrice())); throw new CommandSignsException(err); } } if (!this.player.hasPermission("commandsign.timer.bypass")) { this.cmdBlock.refreshLastTime(); } }
public void regionPrice(Player player, String[] args) { Selection sel = worldEdit.getSelection(player); if (sel == null) { player.sendMessage(ChatColor.RED + "Select a region with a wooden axe first."); return; } ProtectedRegion region = null; String id = "icp__tempregion"; if (sel instanceof Polygonal2DSelection) { Polygonal2DSelection polySel = (Polygonal2DSelection) sel; int minY = polySel.getNativeMinimumPoint().getBlockY(); int maxY = polySel.getNativeMaximumPoint().getBlockY(); region = new ProtectedPolygonalRegion(id, polySel.getNativePoints(), minY, maxY); } else if (sel instanceof CuboidSelection) { BlockVector min = sel.getNativeMinimumPoint().toBlockVector(); BlockVector max = sel.getNativeMaximumPoint().toBlockVector(); region = new ProtectedCuboidRegion(id, min, max); } else { player.sendMessage( ChatColor.RED + "(shouldn't happen) Something went wrong. The type of region selected is unsupported!"); return; } double cost = (int) Math.ceil(econ.getCost(region.volume())); player.sendMessage(ChatColor.AQUA + "That region will cost you $" + cost + "."); }
public void checkRegion(Player sender, String[] args) { if (!sender.hasPermission("iceprotect.buy")) { sender.sendMessage(ChatColor.RED + "You don't have permission!"); return; } if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Wrong usage. /pr help"); return; } String id = "icp__tempregion"; Location loc = sender.getLocation(); BlockVector min = new BlockVector(loc.getX() - 1, loc.getY() - 1, loc.getZ() - 1); BlockVector max = new BlockVector(loc.getX() + 1, loc.getY() + 1, loc.getZ() + 1); ProtectedRegion region = new ProtectedCuboidRegion(id, min, max); RegionManager mgr = plugin.getGlobalRegionManager().get(sender.getWorld()); ApplicableRegionSet regions = mgr.getApplicableRegions(region); ProtectedRegion appReg = null; for (ProtectedRegion r : regions) { if (econ.isRegionForSale(r.getId())) { appReg = r; break; } } if (appReg == null) { sender.sendMessage(ChatColor.RED + "No nearby regions for sale!"); return; } else { double cost = regionsForSale.getDouble("regions." + appReg.getId() + ".price", 0D); if (cost == 0) { sender.sendMessage( ChatColor.RED + "(this shouldn't happen) You can't buy this region. Notify an admin!"); return; } sender.sendMessage( ChatColor.YELLOW + "This region " + appReg.getId() + " is for sale by " + regionsForSale.getString("regions." + appReg.getId() + ".seller")); sender.sendMessage(ChatColor.YELLOW + "And costs $" + cost + "."); } }
public void buyRegion(Player sender, String[] args) { if (!sender.hasPermission("iceprotect.buy")) { sender.sendMessage(ChatColor.RED + "You don't have permission!"); return; } if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Wrong usage. /pr help"); return; } String id = "icp__tempregion"; Location loc = sender.getLocation(); BlockVector min = new BlockVector(loc.getX() - 1, loc.getY() - 1, loc.getZ() - 1); BlockVector max = new BlockVector(loc.getX() + 1, loc.getY() + 1, loc.getZ() + 1); ProtectedRegion region = new ProtectedCuboidRegion(id, min, max); RegionManager mgr = plugin.getGlobalRegionManager().get(sender.getWorld()); ApplicableRegionSet regions = mgr.getApplicableRegions(region); ProtectedRegion appReg = null; for (ProtectedRegion r : regions) { if (econ.isRegionForSale(r.getId())) { appReg = r; break; } } if (appReg == null) { sender.sendMessage(ChatColor.RED + "No nearby regions for sale!"); return; } econ.buyRegion(appReg, sender, mgr); }
public void setRegion(Player sender, String[] args) { if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Wrong usage. /pr help"); return; } LocalPlayer wgPlayer = plugin.wrapPlayer(sender); String id = "icp_" + sender.getName() + "_" + args[1]; if (!ProtectedRegion.isValidId(id)) { sender.sendMessage(ChatColor.RED + "Invalid region name specified!"); return; } Selection sel = worldEdit.getSelection(sender); if (sel == null) { sender.sendMessage(ChatColor.RED + "Select a region with a wooden axe first."); return; } RegionManager mgr = plugin.getGlobalRegionManager().get(sel.getWorld()); if (mgr.hasRegion(id)) { sender.sendMessage( ChatColor.RED + "That region name is already taken. Please choose a new name."); return; } int regionCount = mgr.getRegionCountOfPlayer(wgPlayer); if (regionCount > Economy.maxDonatorAllowedRegions && !sender.isOp() && sender.hasPermission("iceprotect.freeprotect")) { sender.sendMessage( ChatColor.RED + "You have reached the maximum allowed regions per user (" + Economy.maxDonatorAllowedRegions + ")."); sender.sendMessage(ChatColor.RED + "Please contact an admin."); return; } ProtectedRegion region = null; if (sel instanceof Polygonal2DSelection) { Polygonal2DSelection polySel = (Polygonal2DSelection) sel; int minY = polySel.getNativeMinimumPoint().getBlockY(); int maxY = polySel.getNativeMaximumPoint().getBlockY(); region = new ProtectedPolygonalRegion(id, polySel.getNativePoints(), minY, maxY); } else if (sel instanceof CuboidSelection) { BlockVector min = sel.getNativeMinimumPoint().toBlockVector(); BlockVector max = sel.getNativeMaximumPoint().toBlockVector(); region = new ProtectedCuboidRegion(id, min, max); } else { sender.sendMessage( ChatColor.RED + "(shouldn't happen) Something went wrong. The type of region selected is unsupported!"); return; } String[] names = new String[1]; names[0] = sender.getName(); region.setOwners(RegionUtil.parseDomainString(names, 0)); ApplicableRegionSet regions = mgr.getApplicableRegions(region); if (!regions.isOwnerOfAll(wgPlayer)) { sender.sendMessage(ChatColor.RED + "That region overlaps with another one not owned by you!"); return; } double cost = (int) Math.ceil(econ.getCost(region.volume())); if (cost > Economy.maxDonatorAllowedCost && sender.hasPermission("iceprotect.freeprotect")) { sender.sendMessage( ChatColor.RED + "You have exceeded the maximum allowed price for this region!"); sender.sendMessage( ChatColor.RED + "Cost: " + ChatColor.GRAY + "$" + cost + ChatColor.RED + ", " + ChatColor.GRAY + "$" + Economy.maxDonatorAllowedCost + " allowed."); return; } if (!sender.hasPermission("iceprotect.freeprotect") && !econ.chargePlayer(sender, cost)) { sender.sendMessage(ChatColor.RED + "You don't have enough money! $" + cost + " needed."); return; } mgr.addRegion(region); try { mgr.save(); sender.sendMessage( ChatColor.YELLOW + "Region saved as " + args[1] + ". " + (sender.hasPermission("iceprotect.freeprotect") ? "" : "Cost: $" + cost + ".")); } catch (IOException e) { sender.sendMessage( ChatColor.RED + "(shouldn't happen) Failed to write regions file: " + e.getMessage()); e.printStackTrace(); return; } }