Changes handling WorldGuard flags, it now actually adds friends

Reworked applying flag settings configured in AreaShop to the WorldGuard
region. Now supports adding the friends to the regions, adding groups to
a region (g:groupname, would allow someone 'unlocking' functionality of
a region for a whole group of players) and adding group restrictions to
other flags (for example: 'entry: deny g:non_owners').
This commit is contained in:
Thijs Wiefferink 2014-12-01 21:00:27 +01:00
parent 59627e1b97
commit cf3139f373
8 changed files with 159 additions and 142 deletions

View File

@ -1,10 +1,7 @@
############################################## # ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
# config.yml of the AreaShop plugin # # ║ config.yml file of the AreaShop plugin created by NLThijs48, Github can be found at https://github.com/NLthijs48/AreaShop ║
# This plugin has been created by NLThijs48 # # ║ This file contains options to change the working of the plugin, the profiles defined here can be used in default.yml ║
# Check the server minecraft.go-craft.com # # ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
# and then the Survival server for a demo #
##############################################
# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ # ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
# │ GENERAL: Options that influence the global state of the plugin │ # │ GENERAL: Options that influence the global state of the plugin │
# └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ # └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
@ -38,7 +35,7 @@ useColorsInConsole: false
## Post error messages in the console when a command run from the config fails (from the 'runCommands' section for example) ## Post error messages in the console when a command run from the config fails (from the 'runCommands' section for example)
postCommandErrors: true postCommandErrors: true
## Enables / disables debug messages in the console, could be useful to figure out where errors come from ## Enables / disables debug messages in the console, could be useful to figure out where errors come from
debug: false debug: true
## Version of the config, do not change! ## Version of the config, do not change!
version: 2.1.0 version: 2.1.0
@ -81,11 +78,13 @@ limitGroups:
# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ # ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
# │ PROFILES: Assigned in general (default.yml), for a group (groups.yml) or individually (<region>.yml) │ # │ PROFILES: Assigned in general (default.yml), for a group (groups.yml) or individually (<region>.yml) │
# └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ # └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
## Below is a list of default tags that can be used with all the profiles below. ## Below is a list of tags that can be used with all the profiles below.
## If a tag has no value (for example when you use %player% when the region is not rented/bought) then the tag will not get replaced ## If a tag has no value (for example when you use %player% when the region is not rented/bought) then the tag will not get replaced
## %region% The region name (with correct capitalization) ## %region% The region name (with correct capitalization)
## %player% The name of the player that rents/buys the region (with correct capitalization), will not get replaced if no renter/buyer ## %player% The name of the player that rents/buys the region (with correct capitalization), will not get replaced if no renter/buyer
## %uuid% The uuid of the player that rents/buys the region, will not get replaced if no renter/buyer ## %uuid% The uuid of the player that rents/buys the region, will not get replaced if no renter/buyer
## %friends% The names of friends added to this region separated by ', '
## %friendsuuid% The UUID's of friends added to this region separated by ', '
## %price% The price of the region formatted with the configured characters before and after the number ## %price% The price of the region formatted with the configured characters before and after the number
## %duration% The duration of a rent region, for example '1 d', '4 minutes' or '2 years' ## %duration% The duration of a rent region, for example '1 d', '4 minutes' or '2 years'
## %world% The name of the world that the region is in ## %world% The name of the world that the region is in
@ -220,23 +219,23 @@ schematicProfiles:
restore: '' restore: ''
## Flag profiles to specify what flags should be set on the WorldGuard regions ## Flag profiles to specify what flags should be set on the WorldGuard regions
## All normal region flags as present in WorldGuard can be used, and also members, owners, priority and parent ## All normal region flags as present in WorldGuard can be used, and also members, owners, priority and parent
## Use 'clear' for members or owners to remove all players. Use '' for a normal flag to reset it. ## Use '' for members or owners to clear it. Use '' for a flag to reset it.
flagProfiles: flagProfiles:
default: default:
forrent: forrent:
members: clear members: ''
greeting: '%lang:prefix%%lang:greeting-forrent%' greeting: '%lang:prefix%%lang:greeting-forrent%'
rented: rented:
members: clear, +%player% members: '%player%, %friends%'
greeting: '%lang:prefix%%lang:greeting-rented%' greeting: '%lang:prefix%%lang:greeting-rented%'
forsale: forsale:
members: clear members: ''
greeting: '%lang:prefix%%lang:greeting-forsale%' greeting: '%lang:prefix%%lang:greeting-forsale%'
sold: sold:
members: clear, +%player% members: '%player%, %friends%'
greeting: '%lang:prefix%%lang:greeting-bought%' greeting: '%lang:prefix%%lang:greeting-bought%'
resale: resale:
members: clear, +%player% members: '%player%, %friends%'
greetin: '%lang:prefix%%lang:greeting-resale%' greetin: '%lang:prefix%%lang:greeting-resale%'
## Profiles that specify when players should get messages about rent that almost run out ## Profiles that specify when players should get messages about rent that almost run out
## The numbers that start sections in the profile specify how time before it actually runs out it should be executed ## The numbers that start sections in the profile specify how time before it actually runs out it should be executed

View File

@ -1,6 +1,7 @@
### All settings below are default settings and can be overridden # ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
### by group settings or region settings (copy a section to a region or group and change them there) # ║ default.yml file of the AreaShop plugin created by NLThijs48, Github can be found at https://github.com/NLthijs48/AreaShop ║
# ║ All settings below are default settings and can be overridden by group settings or individual region settings ║
# ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ # ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
# │ GENERAL: Options for all regions │ # │ GENERAL: Options for all regions │
# └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ # └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
@ -30,6 +31,7 @@ general:
## Restricts the /as buy and /as rent commands to the region itself (player needs to be inside) ## Restricts the /as buy and /as rent commands to the region itself (player needs to be inside)
restrictedToRegion: false restrictedToRegion: false
# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ # ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
# │ RENT: Options for rent regions │ # │ RENT: Options for rent regions │
# └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ # └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
@ -54,6 +56,7 @@ rent:
## The profile for the expiration warnings as specified in the config ## The profile for the expiration warnings as specified in the config
expirationWarningProfile: 'default' expirationWarningProfile: 'default'
# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ # ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
# │ BUY: Options for buy regions │ # │ BUY: Options for buy regions │
# └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ # └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

View File

@ -72,6 +72,8 @@ public final class AreaShop extends JavaPlugin {
public static final String tagTimeLeft = "%timeleft%"; public static final String tagTimeLeft = "%timeleft%";
public static final String tagClicker = "%clicker%"; public static final String tagClicker = "%clicker%";
public static final String tagResellPrice = "%resellprice%"; public static final String tagResellPrice = "%resellprice%";
public static final String tagFriends = "%friends%";
public static final String tagFriendsUUID = "%friendsuuid%";
public static AreaShop getInstance() { public static AreaShop getInstance() {
return AreaShop.instance; return AreaShop.instance;

View File

@ -80,7 +80,7 @@ public class AddfriendCommand extends CommandAreaShop {
return; return;
} }
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]); OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
if(region.getFriendList().contains(friend.getUniqueId())) { if(region.getFriends().contains(friend.getUniqueId())) {
plugin.message(sender, "addfriend-alreadyAdded", friend.getName()); plugin.message(sender, "addfriend-alreadyAdded", friend.getName());
return; return;
} }
@ -97,7 +97,7 @@ public class AddfriendCommand extends CommandAreaShop {
if(sender.hasPermission("areashop.addfriend") && sender instanceof Player) { if(sender.hasPermission("areashop.addfriend") && sender instanceof Player) {
if(region.isOwner((Player)sender)) { if(region.isOwner((Player)sender)) {
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]); OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
if(region.getFriendList().contains(friend.getUniqueId())) { if(region.getFriends().contains(friend.getUniqueId())) {
plugin.message(sender, "addfriend-alreadyAdded", friend.getName()); plugin.message(sender, "addfriend-alreadyAdded", friend.getName());
return; return;
} }

View File

@ -78,7 +78,7 @@ public class DelfriendCommand extends CommandAreaShop {
return; return;
} }
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]); OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
if(!region.getFriendList().contains(friend.getUniqueId())) { if(!region.getFriends().contains(friend.getUniqueId())) {
plugin.message(sender, "delfriend-notAdded", friend.getName()); plugin.message(sender, "delfriend-notAdded", friend.getName());
return; return;
} }
@ -91,7 +91,7 @@ public class DelfriendCommand extends CommandAreaShop {
if(sender.hasPermission("areashop.delfriend") && sender instanceof Player) { if(sender.hasPermission("areashop.delfriend") && sender instanceof Player) {
if(region.isOwner((Player)sender)) { if(region.isOwner((Player)sender)) {
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]); OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
if(!region.getFriendList().contains(friend.getUniqueId())) { if(!region.getFriends().contains(friend.getUniqueId())) {
plugin.message(sender, "delfriend-notAdded", friend.getName()); plugin.message(sender, "delfriend-notAdded", friend.getName());
return; return;
} }

View File

@ -268,6 +268,8 @@ public class BuyRegion extends GeneralRegion {
plugin.message(player, "buy-payError"); plugin.message(player, "buy-payError");
return false; return false;
} }
AreaShop.debug(player.getName() + " has bought region " + getName() + " for " + getFormattedPrice());
// Run commands // Run commands
this.runEventCommands(RegionEvent.BOUGHT, true); this.runEventCommands(RegionEvent.BOUGHT, true);
// Set the owner // Set the owner
@ -280,8 +282,6 @@ public class BuyRegion extends GeneralRegion {
// Send message to the player // Send message to the player
plugin.message(player, "buy-succes", getName()); plugin.message(player, "buy-succes", getName());
AreaShop.debug(player.getName() + " has bought region " + getName() + " for " + getFormattedPrice());
this.saveRequired(); this.saveRequired();
// Run commands // Run commands
this.runEventCommands(RegionEvent.BOUGHT, false); this.runEventCommands(RegionEvent.BOUGHT, false);

View File

@ -40,17 +40,10 @@ import com.sk89q.worldedit.data.DataException;
import com.sk89q.worldedit.schematic.SchematicFormat; import com.sk89q.worldedit.schematic.SchematicFormat;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain; import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.BooleanFlag;
import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.DoubleFlag;
import com.sk89q.worldguard.protection.flags.EnumFlag;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.IntegerFlag;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat; import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.flags.SetFlag; import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.flags.StringFlag;
import com.sk89q.worldguard.protection.managers.storage.StorageException; import com.sk89q.worldguard.protection.managers.storage.StorageException;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException; import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
@ -368,6 +361,8 @@ public abstract class GeneralRegion {
result.put(AreaShop.tagWidth, getWidth()); result.put(AreaShop.tagWidth, getWidth());
result.put(AreaShop.tagDepth, getDepth()); result.put(AreaShop.tagDepth, getDepth());
result.put(AreaShop.tagHeight, getHeight()); result.put(AreaShop.tagHeight, getHeight());
result.put(AreaShop.tagFriends, Utils.createCommaSeparatedList(getFriendNames()));
result.put(AreaShop.tagFriendsUUID, Utils.createCommaSeparatedList(getFriends()));
// TODO: add more? coordinates? // TODO: add more? coordinates?
@ -465,7 +460,7 @@ public abstract class GeneralRegion {
* Get the list of friends added to this region * Get the list of friends added to this region
* @return Friends added to this region * @return Friends added to this region
*/ */
public Set<UUID> getFriendList() { public Set<UUID> getFriends() {
HashSet<UUID> result = new HashSet<UUID>(); HashSet<UUID> result = new HashSet<UUID>();
for(String friend : config.getStringList("general.friends")) { for(String friend : config.getStringList("general.friends")) {
try { try {
@ -480,6 +475,25 @@ public abstract class GeneralRegion {
return result; return result;
} }
/**
* Get the list of friends added to this region
* @return Friends added to this region
*/
public Set<String> getFriendNames() {
HashSet<String> result = new HashSet<String>();
for(String friend : config.getStringList("general.friends")) {
try {
UUID id = UUID.fromString(friend);
if(id != null) {
result.add(Bukkit.getOfflinePlayer(id).getName());
}
} catch(IllegalArgumentException e) {
// Don't add it
}
}
return result;
}
/** /**
* Remove all friends that are added to this region * Remove all friends that are added to this region
*/ */
@ -808,9 +822,6 @@ public abstract class GeneralRegion {
// } // }
// } // }
editSession.enableQueue(); editSession.enableQueue();
try { try {
SchematicFormat.MCEDIT.load(restoreFile).place(editSession, origin, false); SchematicFormat.MCEDIT.load(restoreFile).place(editSession, origin, false);
@ -840,6 +851,11 @@ public abstract class GeneralRegion {
} }
} }
protected static <V> void setFlag(ProtectedRegion region, Flag<V> flag, CommandSender sender, String value) throws InvalidFlagFormat {
region.setFlag(flag, flag.parseInput(WorldGuardPlugin.inst(), sender, value));
}
/** /**
* Set the region flags/options to the values of a ConfigurationSection * Set the region flags/options to the values of a ConfigurationSection
* @param player The player that does it * @param player The player that does it
@ -847,69 +863,74 @@ public abstract class GeneralRegion {
* @param flags * @param flags
* @return * @return
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected boolean setRegionFlags(ConfigurationSection flags) { protected boolean setRegionFlags(ConfigurationSection flags) {
// TODO A lot of testing + delete lines below
// https://github.com/sk89q/WorldGuard/blob/master/src/main/java/com/sk89q/worldguard/bukkit/commands/region/RegionCommands.java#L461
// https://github.com/sk89q/WorldGuard/blob/master/src/main/java/com/sk89q/worldguard/bukkit/commands/region/RegionCommandsBase.java#L393
boolean result = true; boolean result = true;
if(flags == null) { if(flags == null) {
AreaShop.debug("Flags section is null"); AreaShop.debug("Flags section is null");
return false; return false;
} }
Set<String> flagNames = flags.getKeys(false); Set<String> flagNames = flags.getKeys(false);
WorldGuardPlugin worldGuard = plugin.getWorldGuard(); WorldGuardPlugin worldGuard = plugin.getWorldGuard();
Flag<?> flagType = null;
Object flagValue = null;
/* Get the region */ // Get the region
ProtectedRegion region = getRegion(); ProtectedRegion region = getRegion();
if(region == null) { if(region == null) {
AreaShop.debug("Region '" + getName() + "' does not exist, setting flags failed"); AreaShop.debug("Region '" + getName() + "' does not exist, setting flags failed");
return false; return false;
} }
Iterator<String> it = flagNames.iterator(); Iterator<String> it = flagNames.iterator();
// Loop through all flags that are set in the config
while(it.hasNext()) { while(it.hasNext()) {
String flagName = it.next(); String flagName = it.next();
String value = flags.getString(flagName); String value = flags.getString(flagName);
// Apply replacements
if(value != null) {
value = applyAllReplacements(value); value = applyAllReplacements(value);
} value = translateBukkitToWorldGuardColors(value);
/* Check for a couple of options or use as flag */
if(flagName.equalsIgnoreCase("members")) { if(flagName.equalsIgnoreCase("members")) {
/* Split the string and parse all values */ // Split the string and parse all values
String[] names = value.split("\\s*,\\s*"); String[] names = value.split(", ");
DefaultDomain members = region.getMembers(); DefaultDomain members = region.getMembers();
for(int i=0; i<names.length; i++) { members.clear();
if(names[i].equals("clear")) { for(String name : names) {
members.removeAll(); if(name != null && !name.isEmpty()) {
} else if(names[i].charAt(0) == '+') { // Check for groups
members.addPlayer(names[i].substring(1));; if(name.startsWith("g:")) {
} else if(names[i].charAt(0) == '-') { if(name.length() > 2) {
members.removePlayer(names[i].substring(1));; members.addGroup(name.substring(2));
}
} else {
members.addPlayer(name);
}
} }
} }
region.setMembers(members); region.setMembers(members);
AreaShop.debug(" Flag " + flagName + " set: " + members.toUserFriendlyString());
} else if(flagName.equalsIgnoreCase("owners")) { } else if(flagName.equalsIgnoreCase("owners")) {
/* Split the string and parse all values */ // Split the string and parse all values
String[] names = value.split("\\s*,\\s*"); String[] names = value.split(" ");
DefaultDomain owners = region.getOwners(); DefaultDomain owners = region.getOwners();
for(int i=0; i<names.length; i++) { owners.clear();
if(names[i].equals("clear")) { for(String name : names) {
owners.removeAll(); if(name != null && !name.isEmpty()) {
} else if(names[i].charAt(0) == '+') { // Check for groups
owners.addPlayer(names[i].substring(1));; if(name.startsWith("g:")) {
} else if(names[i].charAt(0) == '-') { if(name.length() > 2) {
owners.removePlayer(names[i].substring(1));; owners.addGroup(name.substring(2));
}
} else {
owners.addPlayer(name);
}
} }
} }
region.setOwners(owners); region.setOwners(owners);
AreaShop.debug(" Flag " + flagName + " set: " + owners.toUserFriendlyString());
} else if(flagName.equalsIgnoreCase("priority")) { } else if(flagName.equalsIgnoreCase("priority")) {
try { try {
int priority = Integer.parseInt(value); int priority = Integer.parseInt(value);
region.setPriority(priority); region.setPriority(priority);
AreaShop.debug("Flag set: " + flagName + " --> " + value); AreaShop.debug(" Flag " + flagName + " set: " + value);
} catch(NumberFormatException e) { } catch(NumberFormatException e) {
plugin.getLogger().info("The value of flag " + flagName + " is not a number"); plugin.getLogger().info("The value of flag " + flagName + " is not a number");
result = false; result = false;
@ -919,6 +940,7 @@ public abstract class GeneralRegion {
if(parentRegion != null) { if(parentRegion != null) {
try { try {
region.setParent(parentRegion); region.setParent(parentRegion);
AreaShop.debug(" Flag " + flagName + " set: " + value);
} catch (CircularInheritanceException e) { } catch (CircularInheritanceException e) {
plugin.getLogger().info("The parent set in the config is not correct (circular inheritance)"); plugin.getLogger().info("The parent set in the config is not correct (circular inheritance)");
} }
@ -926,75 +948,67 @@ public abstract class GeneralRegion {
plugin.getLogger().info("The parent set in the config is not correct (region does not exist)"); plugin.getLogger().info("The parent set in the config is not correct (region does not exist)");
} }
} else { } else {
flagType = null; // Parse all other normal flags (groups are also handled)
flagValue = null; String flagSetting = null;
com.sk89q.worldguard.protection.flags.RegionGroup groupValue = null;
try { Flag<?> foundFlag = DefaultFlag.fuzzyMatchFlag(flagName);
flagType = DefaultFlag.fuzzyMatchFlag(flagName); if(foundFlag == null) {
if(flagType != null && !(value.equals("") || value.equals("none"))) { plugin.getLogger().info("Found wrong flag in flagProfiles section: " + flagName + ", check if that is the correct WorldGuard flag");
flagValue = flagType.parseInput(worldGuard, null, value); continue;
} }
RegionGroupFlag groupFlag = foundFlag.getRegionGroupFlag();
if(value == null || value.isEmpty()) {
region.setFlag(foundFlag, null);
if (groupFlag != null) {
region.setFlag(groupFlag, null);
}
AreaShop.debug(" Flag " + flagName + " reset (+ possible group of flag)");
continue;
} else {
if(groupFlag == null) {
flagSetting = value;
} else {
for(String part : value.split(" ")) {
if(part.startsWith("g:")) {
if(part.length() > 2) {
try {
groupValue = groupFlag.parseInput(worldGuard, null, part.substring(2));
} catch(InvalidFlagFormat e) {
plugin.getLogger().info("Found wrong group value for flag " + flagName);
}
}
} else {
if(flagSetting == null) {
flagSetting = part;
} else {
flagSetting += " " + part;
}
}
}
}
if (flagSetting != null) {
try {
setFlag(region, foundFlag, null, flagSetting);
AreaShop.debug(" Flag " + flagName + " set: " + flagSetting);
} catch (InvalidFlagFormat e) { } catch (InvalidFlagFormat e) {
plugin.getLogger().info("The value of flag " + flagName + " is wrong"); plugin.getLogger().info("Found wrong value for flag " + flagName);
result = false;
} }
if(flagType != null) { }
if(flagType instanceof StateFlag) { if(groupValue != null) {
if(value.equals("")) { if(groupValue == groupFlag.getDefault()) {
region.setFlag((StateFlag)flagType, null); region.setFlag(groupFlag, null);
AreaShop.debug(" Group of flag " + flagName + " set to default: " + groupValue);
} else { } else {
region.setFlag((StateFlag)flagType, (State)flagValue); region.setFlag(groupFlag, groupValue);
} AreaShop.debug(" Group of flag " + flagName + " set: " + groupValue);
} else if(flagType instanceof BooleanFlag) { }
if(value.equals("")) { }
region.setFlag((BooleanFlag)flagType, null);
} else {
region.setFlag((BooleanFlag)flagType, (Boolean)flagValue);
}
} else if(flagType instanceof IntegerFlag) {
if(value.equals("")) {
region.setFlag((IntegerFlag)flagType, null);
} else {
region.setFlag((IntegerFlag)flagType, (Integer)flagValue);
}
} else if(flagType instanceof DoubleFlag) {
if(value.equals("")) {
region.setFlag((DoubleFlag)flagType, null);
} else {
region.setFlag((DoubleFlag)flagType, (Double)flagValue);
}
} else if(flagType instanceof StringFlag) {
if(value.equals("")) {
region.setFlag((StringFlag)flagType, null);
} else {
String coloredValue = translateBukkitToWorldGuardColors((String)flagValue);
region.setFlag((StringFlag)flagType, coloredValue);
}
} else if(flagType instanceof SetFlag<?>) {
if(value.equals("")) {
region.setFlag((SetFlag)flagType, null);
} else {
region.setFlag((SetFlag)flagType, (Set<String>)flagValue);
}
} /* else if(flagType instanceof LocationFlag) {
region.setFlag((LocationFlag)flagType, (Location)flagValue);
} */ else if(flagType instanceof EnumFlag) {
if(value.equals("")) {
region.setFlag((EnumFlag)flagType, null);
} else {
region.setFlag((EnumFlag)flagType, (Enum)flagValue);
}
} else {
result = false;
}
AreaShop.debug("Region " + region.getId() + ", flag " + flagName + " --> " + value);
} else {
result = false;
} }
} }
} }
try { try {
// TODO include into periodic saving program
worldGuard.getRegionManager(getWorld()).save(); worldGuard.getRegionManager(getWorld()).save();
} catch (StorageException e) { } catch (StorageException e) {
plugin.getLogger().info("Error: regions could not be saved"); plugin.getLogger().info("Error: regions could not be saved");

View File

@ -467,8 +467,8 @@ public class RentRegion extends GeneralRegion {
calendar.setTimeInMillis(getRentedUntil()); calendar.setTimeInMillis(getRentedUntil());
} }
calendar.setTimeInMillis(calendar.getTimeInMillis() + getDuration()); calendar.setTimeInMillis(calendar.getTimeInMillis() + getDuration());
SimpleDateFormat dateFull = new SimpleDateFormat(plugin.getConfig().getString("timeFormatChat")); SimpleDateFormat dateFull = new SimpleDateFormat(plugin.getConfig().getString("timeFormatChat"));
AreaShop.debug(player.getName() + " has rented region " + getName() + " for " + getFormattedPrice() + " until " + dateFull.format(calendar.getTime()));
/* Add values to the rent and send it to FileManager */ /* Add values to the rent and send it to FileManager */
setRentedUntil(calendar.getTimeInMillis()); setRentedUntil(calendar.getTimeInMillis());
@ -493,7 +493,6 @@ public class RentRegion extends GeneralRegion {
plugin.message(player, "rent-rented", getName(), dateFull.format(calendar.getTime())); plugin.message(player, "rent-rented", getName(), dateFull.format(calendar.getTime()));
plugin.message(player, "rent-extend"); plugin.message(player, "rent-extend");
} }
AreaShop.debug(player.getName() + " has rented region " + getName() + " for " + getFormattedPrice() + " until " + dateFull.format(calendar.getTime()));
this.saveRequired(); this.saveRequired();
if(!extend) { if(!extend) {