From 0ff24627ca5ea4cb5b65ef94de4e22acc42f7119 Mon Sep 17 00:00:00 2001 From: Redecouverte Date: Mon, 28 Feb 2011 17:47:51 +0100 Subject: [PATCH] fixed npe with new flag containers --- .../protection/ApplicableRegionSet.java | 14 +++---- .../regions/flags/BooleanRegionFlag.java | 23 +++++++---- .../regions/flags/DoubleRegionFlag.java | 22 +++++++---- .../regions/flags/IntegerRegionFlag.java | 21 +++++++--- .../regions/flags/LocationRegionFlag.java | 39 ++++++++++++------- .../regions/flags/RegionGroupRegionFlag.java | 16 +++++++- .../regions/flags/StateRegionFlag.java | 21 +++++++--- .../regions/flags/StringRegionFlag.java | 11 +++++- 8 files changed, 115 insertions(+), 52 deletions(-) diff --git a/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java b/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java index c3007979..beb7de1d 100644 --- a/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java +++ b/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java @@ -120,7 +120,7 @@ public BooleanRegionFlag getBooleanFlag(FlagType type, boolean inherit) { if (flag instanceof BooleanRegionFlag) { return (BooleanRegionFlag) flag; } else { - return null; + return new BooleanRegionFlag(); } } @@ -131,7 +131,7 @@ public StateRegionFlag getStateFlag(FlagType type, boolean inherit) { if (flag instanceof StateRegionFlag) { return (StateRegionFlag) flag; } else { - return null; + return new StateRegionFlag(); } } @@ -142,7 +142,7 @@ public IntegerRegionFlag getIntegerFlag(FlagType type, boolean inherit) { if (flag instanceof IntegerRegionFlag) { return (IntegerRegionFlag) flag; } else { - return null; + return new IntegerRegionFlag(); } } @@ -153,7 +153,7 @@ public DoubleRegionFlag getDoubleFlag(FlagType type, boolean inherit) { if (flag instanceof DoubleRegionFlag) { return (DoubleRegionFlag) flag; } else { - return null; + return new DoubleRegionFlag(); } } @@ -164,7 +164,7 @@ public StringRegionFlag getStringFlag(FlagType type, boolean inherit) { if (flag instanceof StringRegionFlag) { return (StringRegionFlag) flag; } else { - return null; + return new StringRegionFlag(); } } @@ -175,7 +175,7 @@ public RegionGroupRegionFlag getRegionGroupFlag(FlagType type, boolean inherit) if (flag instanceof RegionGroupRegionFlag) { return (RegionGroupRegionFlag) flag; } else { - return null; + return new RegionGroupRegionFlag(); } } @@ -186,7 +186,7 @@ public LocationRegionFlag getLocationFlag(FlagType type, boolean inherit) { if (flag instanceof LocationRegionFlag) { return (LocationRegionFlag) flag; } else { - return null; + return new LocationRegionFlag(); } } diff --git a/src/com/sk89q/worldguard/protection/regions/flags/BooleanRegionFlag.java b/src/com/sk89q/worldguard/protection/regions/flags/BooleanRegionFlag.java index 34c3ac20..b693bfd5 100644 --- a/src/com/sk89q/worldguard/protection/regions/flags/BooleanRegionFlag.java +++ b/src/com/sk89q/worldguard/protection/regions/flags/BooleanRegionFlag.java @@ -32,9 +32,13 @@ public BooleanRegionFlag(RegionFlagContainer container, RegionFlagInfo info, Str this.setValue(value); } + public BooleanRegionFlag() { + super(null, null); + } + public void setValue(Boolean newValue) { this.value = newValue; - this.container.internalSetValue(info.name, newValue != null ? newValue.toString() : null); + this.updataContainer(); } public Boolean getValue() { @@ -50,16 +54,22 @@ public boolean setValue(String newValue) { this.value = null; } else { newValue = newValue.toLowerCase(); - if(newValue.equals("on") || newValue.equals("allow") || newValue.equals("1")) - { + if (newValue.equals("on") || newValue.equals("allow") || newValue.equals("1")) { newValue = "true"; } this.value = Boolean.valueOf(newValue); } + this.updataContainer(); return true; } + private void updataContainer() { + if (this.container != null) { + this.container.internalSetValue(info.name, this.value != null ? this.value.toString() : null); + } + } + @Override public boolean hasValue() { return this.value != null; @@ -67,12 +77,9 @@ public boolean hasValue() { @Override public String toString() { - if(this.value != null) - { + if (this.value != null) { return this.value.toString(); - } - else - { + } else { return "-"; } } diff --git a/src/com/sk89q/worldguard/protection/regions/flags/DoubleRegionFlag.java b/src/com/sk89q/worldguard/protection/regions/flags/DoubleRegionFlag.java index 92c07a02..d8f8e6c4 100644 --- a/src/com/sk89q/worldguard/protection/regions/flags/DoubleRegionFlag.java +++ b/src/com/sk89q/worldguard/protection/regions/flags/DoubleRegionFlag.java @@ -31,9 +31,13 @@ public DoubleRegionFlag(RegionFlagContainer container, RegionFlagInfo info, Stri this.setValue(value); } + public DoubleRegionFlag() { + super(null, null); + } + public void setValue(Double newValue) { this.value = newValue; - this.container.internalSetValue(info.name, newValue != null ? newValue.toString() : null); + this.updataContainer(); } public Double getValue() { @@ -52,13 +56,20 @@ public boolean setValue(String newValue) { this.value = Double.valueOf(newValue); } catch (Exception e) { this.value = null; + this.updataContainer(); return false; } } - + this.updataContainer(); return true; } + private void updataContainer() { + if (this.container != null) { + this.container.internalSetValue(info.name, this.value != null ? this.value.toString() : null); + } + } + @Override public boolean hasValue() { return this.value != null; @@ -66,12 +77,9 @@ public boolean hasValue() { @Override public String toString() { - if(this.value != null) - { + if (this.value != null) { return this.value.toString(); - } - else - { + } else { return "-"; } } diff --git a/src/com/sk89q/worldguard/protection/regions/flags/IntegerRegionFlag.java b/src/com/sk89q/worldguard/protection/regions/flags/IntegerRegionFlag.java index 34c8dae1..d3ac55df 100644 --- a/src/com/sk89q/worldguard/protection/regions/flags/IntegerRegionFlag.java +++ b/src/com/sk89q/worldguard/protection/regions/flags/IntegerRegionFlag.java @@ -31,9 +31,13 @@ public IntegerRegionFlag(RegionFlagContainer container, RegionFlagInfo info, Str this.setValue(value); } + public IntegerRegionFlag() { + super(null, null); + } + public void setValue(Integer newValue) { this.value = newValue; - this.container.internalSetValue(info.name, newValue != null ? newValue.toString() : null); + this.updataContainer(); } public Integer getValue() { @@ -52,13 +56,21 @@ public boolean setValue(String newValue) { this.value = Integer.valueOf(newValue); } catch (Exception e) { this.value = null; + this.updataContainer(); return false; } } + this.updataContainer(); return true; } + private void updataContainer() { + if (this.container != null) { + this.container.internalSetValue(info.name, this.value != null ? this.value.toString() : null); + } + } + @Override public boolean hasValue() { return this.value != null; @@ -66,12 +78,9 @@ public boolean hasValue() { @Override public String toString() { - if(this.value != null) - { + if (this.value != null) { return this.value.toString(); - } - else - { + } else { return "-"; } } diff --git a/src/com/sk89q/worldguard/protection/regions/flags/LocationRegionFlag.java b/src/com/sk89q/worldguard/protection/regions/flags/LocationRegionFlag.java index 5d6b7a39..7a50d571 100644 --- a/src/com/sk89q/worldguard/protection/regions/flags/LocationRegionFlag.java +++ b/src/com/sk89q/worldguard/protection/regions/flags/LocationRegionFlag.java @@ -36,6 +36,10 @@ public LocationRegionFlag(RegionFlagContainer container, RegionFlagInfo info, St this.setValue(value); } + public LocationRegionFlag() { + super(null, null); + } + public void setValue(Location newValue) { if (newValue == null) { this.worldName = null; @@ -48,19 +52,11 @@ public void setValue(Location newValue) { this.pitch = newValue.getPitch(); } - String stringVal; - if (newValue == null) { - stringVal = null; - } else { - stringVal = newValue.getWorld().getName() + ";" + newValue.getBlockX() + ";" - + newValue.getBlockY() + ";" + newValue.getBlockZ() + ";" + newValue.getYaw() - + ";" + newValue.getPitch(); - } - this.container.internalSetValue(info.name, stringVal); + this.updataContainer(); } public Location getValue(Server server) { - + if (this.worldName == null) { return null; } else { @@ -97,25 +93,38 @@ public boolean setValue(String newValue) { } catch (Exception e) { this.worldName = null; + this.updataContainer(); return false; } } + this.updataContainer(); return true; } + private void updataContainer() { + if (this.container != null) { + String stringVal; + if (this.worldName == null) { + stringVal = null; + } else { + stringVal = this.worldName + ";" + this.x + ";" + this.y + ";" + this.z + + ";" + this.yaw + ";" + this.pitch; + } + this.container.internalSetValue(info.name, stringVal); + } + } + @Override public boolean hasValue() { return this.worldName != null; } + @Override public String toString() { - if(this.worldName != null) - { + if (this.worldName != null) { return this.worldName + "(" + Math.round(this.x) + "," + Math.round(this.y) + "," + Math.round(this.z) + ")"; - } - else - { + } else { return "-"; } } diff --git a/src/com/sk89q/worldguard/protection/regions/flags/RegionGroupRegionFlag.java b/src/com/sk89q/worldguard/protection/regions/flags/RegionGroupRegionFlag.java index a48eec70..22b68e7a 100644 --- a/src/com/sk89q/worldguard/protection/regions/flags/RegionGroupRegionFlag.java +++ b/src/com/sk89q/worldguard/protection/regions/flags/RegionGroupRegionFlag.java @@ -31,9 +31,13 @@ public RegionGroupRegionFlag(RegionFlagContainer container, RegionFlagInfo info, this.setValue(value); } + public RegionGroupRegionFlag() { + super(null, null); + } + public void setValue(RegionGroup newValue) { this.value = newValue; - this.container.internalSetValue(info.name, newValue != null ? newValue.toString() : null); + this.updataContainer(); } public RegionGroup getValue() { @@ -52,13 +56,21 @@ public boolean setValue(String newValue) { this.value = RegionGroup.valueOf(newValue); } catch (Exception e) { this.value = null; + this.updataContainer(); return false; } } + this.updataContainer(); return true; } - + + private void updataContainer() { + if (this.container != null) { + this.container.internalSetValue(info.name, this.value != null ? this.value.toString() : null); + } + } + @Override public boolean hasValue() { return this.value != null; diff --git a/src/com/sk89q/worldguard/protection/regions/flags/StateRegionFlag.java b/src/com/sk89q/worldguard/protection/regions/flags/StateRegionFlag.java index 5d91e735..a812e902 100644 --- a/src/com/sk89q/worldguard/protection/regions/flags/StateRegionFlag.java +++ b/src/com/sk89q/worldguard/protection/regions/flags/StateRegionFlag.java @@ -31,9 +31,13 @@ public StateRegionFlag(RegionFlagContainer container, RegionFlagInfo info, Strin this.setValue(value); } + public StateRegionFlag() { + super(null, null); + } + public void setValue(State newValue) { this.value = newValue; - this.container.internalSetValue(info.name, newValue != null ? newValue.toString() : null); + this.updataContainer(); } public State getValue() { @@ -53,13 +57,21 @@ public boolean setValue(String newValue) { this.value = State.valueOf(newValue); } catch (Exception e) { this.value = null; + this.updataContainer(); return false; } } + this.updataContainer(); return true; } + private void updataContainer() { + if (this.container != null) { + this.container.internalSetValue(info.name, this.value != null ? this.value.toString() : null); + } + } + @Override public boolean hasValue() { return this.value != null; @@ -67,12 +79,9 @@ public boolean hasValue() { @Override public String toString() { - if(this.value != null) - { + if (this.value != null) { return this.value.toString(); - } - else - { + } else { return "-"; } } diff --git a/src/com/sk89q/worldguard/protection/regions/flags/StringRegionFlag.java b/src/com/sk89q/worldguard/protection/regions/flags/StringRegionFlag.java index 78d589d5..fc77a2b9 100644 --- a/src/com/sk89q/worldguard/protection/regions/flags/StringRegionFlag.java +++ b/src/com/sk89q/worldguard/protection/regions/flags/StringRegionFlag.java @@ -32,9 +32,13 @@ public StringRegionFlag(RegionFlagContainer container, RegionFlagInfo info, Stri this.value = value; } + public StringRegionFlag() { + super(null, null); + } + public boolean setValue(String newValue) { this.value = newValue; - this.container.internalSetValue(info.name, newValue); + this.updataContainer(); return true; } @@ -46,6 +50,11 @@ public String getValue(String def) { return this.value != null ? this.value : def; } + private void updataContainer() { + if (this.container != null) { + this.container.internalSetValue(info.name, this.value); + } + } @Override public boolean hasValue() {