1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-07 15:16:41 +02:00

Null handling in AntiBuild

This commit is contained in:
ementalo
2012-10-24 14:48:12 +01:00
parent bb838c3369
commit 96d76f46fc
3 changed files with 79 additions and 66 deletions

View File

@@ -22,53 +22,62 @@ public class Alert implements StorageObject
@ListType(Material.class) @ListType(Material.class)
@Getter(AccessLevel.NONE) @Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
private Set<Material> alertOnPlacement = null; private Set<Material> alertOnPlacement = new HashSet<Material>();
@Comment("For which block types would you like to be alerted when used?") ;
@Comment("For which block types would you like to be alerted when used?")
@ListType(Material.class) @ListType(Material.class)
@Getter(AccessLevel.NONE) @Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
private Set<Material> alertOnUse = null; private Set<Material> alertOnUse = new HashSet<Material>();
;
@Comment("For which block types would you like to be alerted when broken?") @Comment("For which block types would you like to be alerted when broken?")
@ListType(Material.class) @ListType(Material.class)
@Getter(AccessLevel.NONE) @Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
private Set<Material> alertOnBreak = null; private Set<Material> alertOnBreak = new HashSet<Material>();
;
public Alert() public Alert()
{ {
if (alertOnPlacement == null) if (alertOnPlacement.isEmpty())
{ {
Material[] mat = Material[] mat =
{ {
Material.LAVA, Material.STATIONARY_LAVA, Material.TNT, Material.LAVA_BUCKET Material.LAVA, Material.STATIONARY_LAVA, Material.TNT, Material.LAVA_BUCKET
}; };
alertOnPlacement = new HashSet<Material>();
alertOnPlacement.addAll(Arrays.asList(mat)); alertOnPlacement.addAll(Arrays.asList(mat));
} }
if (alertOnUse == null) if (alertOnUse.isEmpty())
{ {
alertOnUse = new HashSet<Material>();
alertOnUse.add(Material.LAVA_BUCKET); alertOnUse.add(Material.LAVA_BUCKET);
} }
}
public boolean getAlertOnPlacement(Material mat)
{
if (alertOnPlacement == null)
{
return false;
}
return alertOnPlacement.contains(mat);
}
public boolean getAlertOnUse(Material mat)
{
if (alertOnUse == null)
{
return false;
}
return alertOnUse.contains(mat);
}
public boolean getAlertOnBreak(Material mat)
{
if (alertOnBreak == null) if (alertOnBreak == null)
{ {
alertOnBreak = new HashSet<Material>(); return false;
} }
} return alertOnBreak.contains(mat);
public Set<Material> getAlertOnPlacement()
{
return alertOnPlacement;
}
public Set<Material> getAlertOnUse()
{
return alertOnUse;
}
public Set<Material> getAlertOnBreak()
{
return alertOnBreak;
} }
} }

View File

@@ -25,7 +25,7 @@ public class BlackList implements StorageObject
@ListType(Material.class) @ListType(Material.class)
@Getter(AccessLevel.NONE) @Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
private Set<Material> placement; private Set<Material> placement = new HashSet<Material>();
@Comment( @Comment(
{ {
"Which items should people be prevented from using" "Which items should people be prevented from using"
@@ -33,7 +33,7 @@ public class BlackList implements StorageObject
@ListType(Material.class) @ListType(Material.class)
@Getter(AccessLevel.NONE) @Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
private Set<Material> usage; private Set<Material> usage = new HashSet<Material>();
@Comment( @Comment(
{ {
"Which blocks should people be prevented from breaking" "Which blocks should people be prevented from breaking"
@@ -41,7 +41,7 @@ public class BlackList implements StorageObject
@ListType(Material.class) @ListType(Material.class)
@Getter(AccessLevel.NONE) @Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
private Set<Material> breaking; private Set<Material> breaking = new HashSet<Material>();
@Comment( @Comment(
{ {
"Which blocks should not be pushed by pistons" "Which blocks should not be pushed by pistons"
@@ -49,56 +49,60 @@ public class BlackList implements StorageObject
@ListType(Material.class) @ListType(Material.class)
@Getter(AccessLevel.NONE) @Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
private Set<Material> piston; private Set<Material> piston = new HashSet<Material>();
public BlackList() public BlackList()
{ {
if (placement == null) if(placement.isEmpty())
{ {
Material[] mat = Material[] mat =
{ {
Material.LAVA, Material.STATIONARY_LAVA, Material.TNT, Material.LAVA_BUCKET Material.LAVA, Material.STATIONARY_LAVA, Material.TNT, Material.LAVA_BUCKET
}; };
placement = new HashSet<Material>();
placement.addAll(Arrays.asList(mat)); placement.addAll(Arrays.asList(mat));
} }
if (usage == null)
if (usage.isEmpty())
{ {
usage = new HashSet<Material>();
usage.add(Material.LAVA_BUCKET); usage.add(Material.LAVA_BUCKET);
} }
}
if (breaking == null)
public boolean getPlacement(Material mat)
{
if(placement == null)
{ {
breaking = new HashSet<Material>(); return false;
} }
return placement.contains(mat);
if (piston == null) }
public boolean getUsage(Material mat)
{
if(usage == null)
{ {
piston = new HashSet<Material>(); return false;
} }
return usage.contains(mat);
} }
public Set<Material> getPlacement() public boolean getBreaking(Material mat)
{ {
return placement; if(breaking == null)
{
return false;
}
return breaking.contains(mat);
} }
public Set<Material> getUsage() public boolean getPiston(Material mat)
{ {
return usage; if(piston == null)
} {
return false;
public Set<Material> getBreaking() }
{ return piston.contains(mat);
return breaking;
}
public Set<Material> getPiston()
{
return piston;
} }
} }

View File

@@ -51,7 +51,7 @@ public class EssentialsAntiBuildListener implements Listener
return; return;
} }
if (antib.getSettings().getData().getBlacklist().getPlacement().contains(type) && !Permissions.BLACKLIST_ALLOWPLACEMENT.isAuthorized(user)) if (antib.getSettings().getData().getBlacklist().getPlacement(type) && !Permissions.BLACKLIST_ALLOWPLACEMENT.isAuthorized(user))
{ {
if (antib.getSettings().getData().isWarnOnBuildDisallow()) if (antib.getSettings().getData().isWarnOnBuildDisallow())
{ {
@@ -61,7 +61,7 @@ public class EssentialsAntiBuildListener implements Listener
return; return;
} }
if (antib.getSettings().getData().getAlert().getAlertOnPlacement().contains(type) if (antib.getSettings().getData().getAlert().getAlertOnPlacement(type)
&& !Permissions.ALERTS_NOTRIGGER.isAuthorized(user)) && !Permissions.ALERTS_NOTRIGGER.isAuthorized(user))
{ {
antib.getEssentialsConnect().alert(user, type.toString(), _("alertPlaced")); antib.getEssentialsConnect().alert(user, type.toString(), _("alertPlaced"));
@@ -88,7 +88,7 @@ public class EssentialsAntiBuildListener implements Listener
return; return;
} }
if (antib.getSettings().getData().getBlacklist().getBreaking().contains(type) && !Permissions.BLACKLIST_ALLOWBREAK.isAuthorized(user)) if (antib.getSettings().getData().getBlacklist().getBreaking(type) && !Permissions.BLACKLIST_ALLOWBREAK.isAuthorized(user))
{ {
if (antib.getSettings().getData().isWarnOnBuildDisallow()) if (antib.getSettings().getData().isWarnOnBuildDisallow())
{ {
@@ -98,7 +98,7 @@ public class EssentialsAntiBuildListener implements Listener
return; return;
} }
if (antib.getSettings().getData().getAlert().getAlertOnBreak().contains(type) if (antib.getSettings().getData().getAlert().getAlertOnBreak(type)
&& !Permissions.ALERTS_NOTRIGGER.isAuthorized(user)) && !Permissions.ALERTS_NOTRIGGER.isAuthorized(user))
{ {
antib.getEssentialsConnect().alert(user, type.toString(), _("alertBroke")); antib.getEssentialsConnect().alert(user, type.toString(), _("alertBroke"));
@@ -130,7 +130,7 @@ public class EssentialsAntiBuildListener implements Listener
{ {
for (Block block : event.getBlocks()) for (Block block : event.getBlocks())
{ {
if (antib.getSettings().getData().getBlacklist().getPiston().contains(block.getType())) if (antib.getSettings().getData().getBlacklist().getPiston(block.getType()))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
@@ -146,7 +146,7 @@ public class EssentialsAntiBuildListener implements Listener
return; return;
} }
final Block block = event.getRetractLocation().getBlock(); final Block block = event.getRetractLocation().getBlock();
if (antib.getSettings().getData().getBlacklist().getPiston().contains(block.getType())) if (antib.getSettings().getData().getBlacklist().getPiston(block.getType()))
{ {
event.setCancelled(true); event.setCancelled(true);
} }
@@ -160,7 +160,7 @@ public class EssentialsAntiBuildListener implements Listener
final ItemStack item = event.getItem(); final ItemStack item = event.getItem();
if (item != null if (item != null
&& antib.getSettings().getData().getBlacklist().getUsage().contains(item.getType()) && antib.getSettings().getData().getBlacklist().getUsage(item.getType())
&& !Permissions.BLACKLIST_ALLOWUSAGE.isAuthorized(user)) && !Permissions.BLACKLIST_ALLOWUSAGE.isAuthorized(user))
{ {
if (antib.getSettings().getData().isWarnOnBuildDisallow()) if (antib.getSettings().getData().isWarnOnBuildDisallow())
@@ -172,7 +172,7 @@ public class EssentialsAntiBuildListener implements Listener
} }
if (item != null if (item != null
&& antib.getSettings().getData().getAlert().getAlertOnUse().contains(item.getType()) && antib.getSettings().getData().getAlert().getAlertOnUse(item.getType())
&& !Permissions.ALERTS_NOTRIGGER.isAuthorized(user)) && !Permissions.ALERTS_NOTRIGGER.isAuthorized(user))
{ {
antib.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed")); antib.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed"));