Fix bug with changed time settings not loading old values

This commit is contained in:
Thijs Wiefferink 2015-05-22 19:01:30 +02:00
parent 5231f6e86e
commit 0b9bffe68f
5 changed files with 73 additions and 72 deletions

View File

@ -691,7 +691,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
* @return The duration in milliseconds translated from the durationstring, or if it is invalid then 0
*/
public long durationStringToLong(String duration) {
if(duration == null) {
if(duration == null || duration.indexOf(' ') == -1) {
return 0;
} else if(duration.equalsIgnoreCase("disabled") || duration.equalsIgnoreCase("unlimited")) {
return -1;
@ -735,7 +735,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
* @return milliseconds that the setting indicates
*/
public long getDurationFromSecondsOrString(String path) {
if(getConfig().isLong(path)) {
if(getConfig().isLong(path) || getConfig().isInt(path)) {
return getConfig().getLong(path)*1000;
} else {
return durationStringToLong(getConfig().getString(path));
@ -748,7 +748,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
* @return milliseconds that the setting indicates
*/
public long getDurationFromMinutesOrString(String path) {
if(getConfig().isLong(path)) {
if(getConfig().isLong(path) || getConfig().isInt(path)) {
return getConfig().getLong(path)*60*1000;
} else {
return durationStringToLong(getConfig().getString(path));

View File

@ -63,7 +63,8 @@ public class Utils {
|| !config.isString("world")
|| !config.isDouble("x")
|| !config.isDouble("y")
|| !config.isDouble("z")) {
|| !config.isDouble("z")
|| Bukkit.getWorld(config.getString("world")) == null) {
return null;
}
Location result = new Location(

View File

@ -754,77 +754,77 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
// TODO: Remove the sign if the location is wrong?
AreaShop.debug(" location null");
result = false;
continue;
}
// Get the profile set in the config
String profile = config.getString("general.signs." + sign + ".profile");
if(profile == null || profile.length() == 0) {
profile = getStringSetting("general.signProfile");
}
// Get the prefix
String prefix = "signProfiles." + profile + "." + getState().getValue().toLowerCase() + ".";
// Get the lines
String[] signLines = new String[4];
signLines[0] = plugin.getConfig().getString(prefix + "line1");
signLines[1] = plugin.getConfig().getString(prefix + "line2");
signLines[2] = plugin.getConfig().getString(prefix + "line3");
signLines[3] = plugin.getConfig().getString(prefix + "line4");
// Check if the sign should be present
Block block = location.getBlock();
if(!plugin.getConfig().isSet(prefix)
|| ( (signLines[0] == null || signLines[0].length() == 0)
&& (signLines[1] == null || signLines[1].length() == 0)
&& (signLines[2] == null || signLines[2].length() == 0)
&& (signLines[3] == null || signLines[3].length() == 0) )) {
block.setType(Material.AIR);
} else {
Sign signState = null;
if(block.getType() != Material.WALL_SIGN && block.getType() != Material.SIGN_POST) {
Material signType = null;
try {
signType = Material.valueOf(config.getString("general.signs." + sign + ".signType"));
} catch(NullPointerException | IllegalArgumentException e) {
signType = null;
} else {
// Get the profile set in the config
String profile = config.getString("general.signs." + sign + ".profile");
if(profile == null || profile.length() == 0) {
profile = getStringSetting("general.signProfile");
}
// Get the prefix
String prefix = "signProfiles." + profile + "." + getState().getValue().toLowerCase() + ".";
// Get the lines
String[] signLines = new String[4];
signLines[0] = plugin.getConfig().getString(prefix + "line1");
signLines[1] = plugin.getConfig().getString(prefix + "line2");
signLines[2] = plugin.getConfig().getString(prefix + "line3");
signLines[3] = plugin.getConfig().getString(prefix + "line4");
// Check if the sign should be present
Block block = location.getBlock();
if(!plugin.getConfig().isSet(prefix)
|| ( (signLines[0] == null || signLines[0].length() == 0)
&& (signLines[1] == null || signLines[1].length() == 0)
&& (signLines[2] == null || signLines[2].length() == 0)
&& (signLines[3] == null || signLines[3].length() == 0) )) {
block.setType(Material.AIR);
} else {
Sign signState = null;
if(block.getType() != Material.WALL_SIGN && block.getType() != Material.SIGN_POST) {
Material signType = null;
try {
signType = Material.valueOf(config.getString("general.signs." + sign + ".signType"));
} catch(NullPointerException | IllegalArgumentException e) {
signType = null;
}
if(signType != Material.WALL_SIGN && signType != Material.SIGN_POST) {
AreaShop.debug(" setting sign failed");
continue;
}
block.setType(signType);
signState = (Sign)block.getState();
org.bukkit.material.Sign signData = (org.bukkit.material.Sign)signState.getData();
BlockFace signFace;
try {
signFace = BlockFace.valueOf(config.getString("general.signs." + sign + ".facing"));
} catch(NullPointerException | IllegalArgumentException e) {
signFace = null;
}
if(signFace != null) {
signData.setFacingDirection(signFace);
signState.setData(signData);
}
}
if(signType != Material.WALL_SIGN && signType != Material.SIGN_POST) {
AreaShop.debug(" setting sign failed");
continue;
if(signState == null) {
signState = (Sign)block.getState();
}
block.setType(signType);
signState = (Sign)block.getState();
org.bukkit.material.Sign signData = (org.bukkit.material.Sign)signState.getData();
BlockFace signFace;
try {
signFace = BlockFace.valueOf(config.getString("general.signs." + sign + ".facing"));
} catch(NullPointerException | IllegalArgumentException e) {
signFace = null;
if(!config.isString("general.signs." + sign + ".signType")) {
setSetting("general.signs." + sign + ".signType", signState.getType().toString());
}
if(signFace != null) {
signData.setFacingDirection(signFace);
signState.setData(signData);
if(!config.isString("general.signs." + sign + ".facing")) {
setSetting("general.signs." + sign + ".facing", signData.getFacing().toString());
}
// Apply replacements and color and then set it on the sign
for(int i=0; i<signLines.length; i++) {
if(signLines[i] == null) {
signState.setLine(i, "");
continue;
}
signLines[i] = applyAllReplacements(signLines[i]);
signLines[i] = plugin.fixColors(signLines[i]);
signState.setLine(i, signLines[i]);
}
signState.update();
}
if(signState == null) {
signState = (Sign)block.getState();
}
org.bukkit.material.Sign signData = (org.bukkit.material.Sign)signState.getData();
if(!config.isString("general.signs." + sign + ".signType")) {
setSetting("general.signs." + sign + ".signType", signState.getType().toString());
}
if(!config.isString("general.signs." + sign + ".facing")) {
setSetting("general.signs." + sign + ".facing", signData.getFacing().toString());
}
// Apply replacements and color and then set it on the sign
for(int i=0; i<signLines.length; i++) {
if(signLines[i] == null) {
signState.setLine(i, "");
continue;
}
signLines[i] = applyAllReplacements(signLines[i]);
signLines[i] = plugin.fixColors(signLines[i]);
signState.setLine(i, signLines[i]);
}
signState.update();
}
}
return result;

View File

@ -294,7 +294,7 @@ expirationWarningProfiles:
# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
# │ LIMITS AND TIMINGS: Options for limits and the frequencies for certain functions (be very carefull with these!) │
# │ LIMITS AND TIMINGS: Options for limits and the frequencies for certain functions (be very careful with these!)
# └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
## Maximum number of blocks to save to or restore from a .schemetic
maximumBlocks: 1000000

View File

@ -7,8 +7,8 @@ author: NLThijs48
website: http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/
commands:
AreaShop:
description: For all commands use /as help
usage: AreaShop has not started correctly, check the console and correct any errors
description: 'For all commands use /as help'
usage: 'AreaShop has not started correctly, check the log file (or console) and correct any errors'
aliases: [as]
permissions:
areashop.*: