Added iConomy support:

- Ability to pay for claiming a region (price per block)
- Ability to create buyable regions with custom price

NOTE: inserted only placeholders for countBlocks(); so buy on claim will not work correctly

INFO: I had not enough time to test it
This commit is contained in:
DarkLiKally 2011-02-25 01:36:47 +01:00
parent 5f12d99e73
commit b9fe5d2afc
10 changed files with 85 additions and 3 deletions

View File

@ -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:

View File

@ -35,4 +35,7 @@ commands:
description: Ports you to the region
usage: /<command> <region id> ...
aliases: tpr
buyregion:
description: Buy a buyable region
usage: /<command> <region id> [info]

View File

@ -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,11 +75,12 @@ public class WorldGuardPlugin extends JavaPlugin {
Blacklist blacklist;
public Set<String> invinciblePlayers = new HashSet<String>();
public Set<String> amphibiousPlayers = new HashSet<String>();
public boolean fireSpreadDisableToggle;
public boolean isiConomyEnabled = false;
// Configuration follows
public boolean suppressTickSyncWarnings;
public boolean enforceOneSession;
@ -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());
@ -199,6 +205,21 @@ private void registerEvents() {
}
/**
* 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);

View File

@ -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());
}

View File

@ -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 + ".");

View File

@ -121,8 +121,7 @@ public boolean handle(CommandSender sender, String senderName, String command, S
}else{
player.sendMessage(ChatColor.RED + "Usage: /region flag <regionid> teleport <set|delete>");
}
}
else
} else
{
player.sendMessage(ChatColor.RED + "Unknown flag specified.");
}

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -133,4 +133,12 @@ public String getTypeName() {
return "polygon";
}
/**
* Get the number of Blocks in this region
*
* @return
*/
public int countBlocks() {
return 1;
}
}

View File

@ -247,6 +247,13 @@ 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.
*