fixed npe with new flag containers

This commit is contained in:
Redecouverte 2011-02-28 17:47:51 +01:00
parent 4d8cd430b7
commit 0ff24627ca
8 changed files with 115 additions and 52 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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,15 +52,7 @@ 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) {
@ -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 "-";
}
}

View File

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

View File

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

View File

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