diff --git a/config.yml b/config.yml index 9f51a1c0..de040869 100644 --- a/config.yml +++ b/config.yml @@ -83,6 +83,12 @@ regions: mobdamage: on waterflow: on +iconomy: + enable: on + buy-on-claim: on + # Price per Block for buying on claim + buy-on-claim-price: 2 + blacklist: logging: console: diff --git a/plugin.yml b/plugin.yml index 79d3f64a..74893bf8 100644 --- a/plugin.yml +++ b/plugin.yml @@ -35,4 +35,7 @@ commands: description: Ports you to the region usage: / ... aliases: tpr + buyregion: + description: Buy a buyable region + usage: / [info] \ No newline at end of file diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index 368b41b1..3d6695f2 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -27,6 +27,7 @@ import java.util.logging.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.bukkit.plugin.Plugin; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -74,10 +75,11 @@ public class WorldGuardPlugin extends JavaPlugin { Blacklist blacklist; - public Set invinciblePlayers = new HashSet(); public Set amphibiousPlayers = new HashSet(); public boolean fireSpreadDisableToggle; + + public boolean isiConomyEnabled = false; // Configuration follows public boolean suppressTickSyncWarnings; @@ -112,6 +114,9 @@ public class WorldGuardPlugin extends JavaPlugin { public boolean disableSuffocationDamage; public boolean teleportOnSuffocation; public boolean useRegions; + public boolean useiConomy; + public boolean buyOnClaim; + public int buyOnClaimPrice; public int regionWand = 287; public String blockCreatureSpawn = ""; /** @@ -146,6 +151,7 @@ public void onEnable() { loadConfiguration(); postReload(); registerEvents(); + checkiConomy(); if (suppressTickSyncWarnings) { Logger.getLogger("Minecraft").setFilter(new TickSyncDelayLoggerFilter()); @@ -198,6 +204,21 @@ private void registerEvents() { this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new TimedFlagsTimer(this), 25*5, 25*5); } + + /** + * Check if iConomy is enabled on this server + */ + public boolean checkiConomy() { + Plugin test = this.getServer().getPluginManager().getPlugin("iConomy"); + + if (test != null) { + this.isiConomyEnabled = true; + } else { + this.isiConomyEnabled = false; + } + + return isiConomyEnabled; + } /** * Register an event. @@ -306,6 +327,10 @@ public void loadConfiguration() { blockCreatureSpawn += creature.toLowerCase() + " "; } + useiConomy = config.getBoolean("iconomy.enable", false); + buyOnClaim = config.getBoolean("iconomy.buy-on-claim", false); + buyOnClaimPrice = config.getInt("iconomy.buy-on-claim-price", 1); + GlobalFlags globalFlags = new GlobalFlags(); globalFlags.canBuild = config.getBoolean("regions.default.build", true); globalFlags.canAccessChests = config.getBoolean("regions.default.chest-access", false); diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java b/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java index 58447792..4a72db7f 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java +++ b/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java @@ -58,6 +58,7 @@ public CommandHandler(WorldGuardPlugin wg) this.commandMap.put("stack", new CommandStack()); this.commandMap.put("stopfire", new CommandStopFire()); this.commandMap.put("tpregrion", new CommandTpRegion()); + this.commandMap.put("buyregion", new CommandBuyRegion()); } diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionClaim.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionClaim.java index 59e9880f..fefe4919 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionClaim.java +++ b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionClaim.java @@ -32,6 +32,7 @@ import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import com.nijikokun.bukkit.iConomy.iConomy; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; @@ -104,6 +105,27 @@ public boolean handle(CommandSender sender, String senderName, String command, S region.getOwners().addPlayer(player.getName()); + if (wg.useiConomy && wg.buyOnClaim) { + if (iConomy.db.has_balance(player.getName())) { + int balance = iConomy.db.get_balance(player.getName()); + int regionCosts = region.countBlocks() * wg.buyOnClaimPrice; + if (balance >= regionCosts) { + iConomy.db.set_balance(player.getName(), balance - regionCosts); + player.sendMessage(ChatColor.YELLOW + "You have bought that region for " + + iConomy.Misc.formatCurrency(regionCosts, iConomy.currency)); + } else { + player.sendMessage(ChatColor.RED + "You have not enough money."); + player.sendMessage(ChatColor.RED + "The region you want to claim costs " + + iConomy.Misc.formatCurrency(regionCosts, iConomy.currency)); + player.sendMessage(ChatColor.RED + "You have " + iConomy.Misc.formatCurrency(balance, iConomy.currency)); + return true; + } + } else { + player.sendMessage(ChatColor.YELLOW + "You have not enough money."); + return true; + } + } + mgr.addRegion(region); mgr.save(); player.sendMessage(ChatColor.YELLOW + "Region saved as " + id + "."); diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java index 5172d1b7..e63f71c4 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java +++ b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java @@ -121,8 +121,7 @@ public boolean handle(CommandSender sender, String senderName, String command, S }else{ player.sendMessage(ChatColor.RED + "Usage: /region flag teleport "); } - } - else + } else { player.sendMessage(ChatColor.RED + "Unknown flag specified."); } diff --git a/src/com/sk89q/worldguard/bukkit/commands/FlagInfo.java b/src/com/sk89q/worldguard/bukkit/commands/FlagInfo.java index 0a0aa420..f187b3af 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/FlagInfo.java +++ b/src/com/sk89q/worldguard/bukkit/commands/FlagInfo.java @@ -56,6 +56,8 @@ public static enum FlagValueType { STRING, BOOLEAN, INT, FLOAT, DOUBLE, STATE }; flagList.add(new FlagInfo("lavafirespread", null, FlagValueType.STATE, "states", "lavafirespread")); flagList.add(new FlagInfo("chest", null, FlagValueType.STATE, "states", "chest")); flagList.add(new FlagInfo("waterflow", null, FlagValueType.STATE, "states", "waterflow")); + flagList.add(new FlagInfo("iconomy", "buyable", FlagValueType.BOOLEAN, "iconomy", "buyable")); + flagList.add(new FlagInfo("iconomy", "price", FlagValueType.INT, "iconomy", "price")); } public static FlagInfo getFlagInfo(String name, String subName) { diff --git a/src/com/sk89q/worldguard/protection/regions/ProtectedCuboidRegion.java b/src/com/sk89q/worldguard/protection/regions/ProtectedCuboidRegion.java index 7638f06a..8bb94a9b 100644 --- a/src/com/sk89q/worldguard/protection/regions/ProtectedCuboidRegion.java +++ b/src/com/sk89q/worldguard/protection/regions/ProtectedCuboidRegion.java @@ -107,4 +107,13 @@ public boolean contains(Vector pt) { public String getTypeName() { return "cuboid"; } + + /** + * Get the number of Blocks in this region + * + * @return + */ + public int countBlocks() { + return 1; + } } diff --git a/src/com/sk89q/worldguard/protection/regions/ProtectedPolygonalRegion.java b/src/com/sk89q/worldguard/protection/regions/ProtectedPolygonalRegion.java index de2a257e..036d3d11 100644 --- a/src/com/sk89q/worldguard/protection/regions/ProtectedPolygonalRegion.java +++ b/src/com/sk89q/worldguard/protection/regions/ProtectedPolygonalRegion.java @@ -133,4 +133,12 @@ public String getTypeName() { return "polygon"; } + /** + * Get the number of Blocks in this region + * + * @return + */ + public int countBlocks() { + return 1; + } } diff --git a/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java b/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java index 9de3d3e6..bd8c936a 100644 --- a/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java +++ b/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java @@ -246,6 +246,13 @@ public boolean isMember(LocalPlayer player) { public AreaFlags getFlags() { return flags; } + + /** + * Get the number of Blocks in this region + * + * @return + */ + public abstract int countBlocks(); /** * Check to see if a point is inside this region.