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:
@@ -22,53 +22,62 @@ public class Alert implements StorageObject
|
||||
@ListType(Material.class)
|
||||
@Getter(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?")
|
||||
@ListType(Material.class)
|
||||
@Getter(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?")
|
||||
@ListType(Material.class)
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private Set<Material> alertOnBreak = null;
|
||||
private Set<Material> alertOnBreak = new HashSet<Material>();
|
||||
|
||||
;
|
||||
public Alert()
|
||||
{
|
||||
if (alertOnPlacement == null)
|
||||
if (alertOnPlacement.isEmpty())
|
||||
{
|
||||
Material[] mat =
|
||||
{
|
||||
Material.LAVA, Material.STATIONARY_LAVA, Material.TNT, Material.LAVA_BUCKET
|
||||
};
|
||||
alertOnPlacement = new HashSet<Material>();
|
||||
alertOnPlacement.addAll(Arrays.asList(mat));
|
||||
}
|
||||
|
||||
if (alertOnUse == null)
|
||||
if (alertOnUse.isEmpty())
|
||||
{
|
||||
alertOnUse = new HashSet<Material>();
|
||||
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)
|
||||
{
|
||||
alertOnBreak = new HashSet<Material>();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Set<Material> getAlertOnPlacement()
|
||||
{
|
||||
return alertOnPlacement;
|
||||
}
|
||||
|
||||
public Set<Material> getAlertOnUse()
|
||||
{
|
||||
return alertOnUse;
|
||||
}
|
||||
|
||||
public Set<Material> getAlertOnBreak()
|
||||
{
|
||||
return alertOnBreak;
|
||||
return alertOnBreak.contains(mat);
|
||||
}
|
||||
}
|
@@ -25,7 +25,7 @@ public class BlackList implements StorageObject
|
||||
@ListType(Material.class)
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private Set<Material> placement;
|
||||
private Set<Material> placement = new HashSet<Material>();
|
||||
@Comment(
|
||||
{
|
||||
"Which items should people be prevented from using"
|
||||
@@ -33,7 +33,7 @@ public class BlackList implements StorageObject
|
||||
@ListType(Material.class)
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private Set<Material> usage;
|
||||
private Set<Material> usage = new HashSet<Material>();
|
||||
@Comment(
|
||||
{
|
||||
"Which blocks should people be prevented from breaking"
|
||||
@@ -41,7 +41,7 @@ public class BlackList implements StorageObject
|
||||
@ListType(Material.class)
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private Set<Material> breaking;
|
||||
private Set<Material> breaking = new HashSet<Material>();
|
||||
@Comment(
|
||||
{
|
||||
"Which blocks should not be pushed by pistons"
|
||||
@@ -49,56 +49,60 @@ public class BlackList implements StorageObject
|
||||
@ListType(Material.class)
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private Set<Material> piston;
|
||||
private Set<Material> piston = new HashSet<Material>();
|
||||
|
||||
public BlackList()
|
||||
{
|
||||
if (placement == null)
|
||||
if(placement.isEmpty())
|
||||
{
|
||||
Material[] mat =
|
||||
{
|
||||
Material.LAVA, Material.STATIONARY_LAVA, Material.TNT, Material.LAVA_BUCKET
|
||||
};
|
||||
placement = new HashSet<Material>();
|
||||
|
||||
placement.addAll(Arrays.asList(mat));
|
||||
}
|
||||
|
||||
if (usage == null)
|
||||
|
||||
if (usage.isEmpty())
|
||||
{
|
||||
usage = new HashSet<Material>();
|
||||
usage.add(Material.LAVA_BUCKET);
|
||||
}
|
||||
|
||||
if (breaking == null)
|
||||
{
|
||||
breaking = new HashSet<Material>();
|
||||
}
|
||||
|
||||
if (piston == null)
|
||||
public boolean getPlacement(Material mat)
|
||||
{
|
||||
piston = new HashSet<Material>();
|
||||
if(placement == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return placement.contains(mat);
|
||||
}
|
||||
|
||||
|
||||
public boolean getUsage(Material mat)
|
||||
{
|
||||
if(usage == null)
|
||||
{
|
||||
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 breaking;
|
||||
}
|
||||
|
||||
public Set<Material> getPiston()
|
||||
{
|
||||
return piston;
|
||||
return piston.contains(mat);
|
||||
}
|
||||
}
|
||||
|
@@ -51,7 +51,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
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())
|
||||
{
|
||||
@@ -61,7 +61,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
return;
|
||||
}
|
||||
|
||||
if (antib.getSettings().getData().getAlert().getAlertOnPlacement().contains(type)
|
||||
if (antib.getSettings().getData().getAlert().getAlertOnPlacement(type)
|
||||
&& !Permissions.ALERTS_NOTRIGGER.isAuthorized(user))
|
||||
{
|
||||
antib.getEssentialsConnect().alert(user, type.toString(), _("alertPlaced"));
|
||||
@@ -88,7 +88,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
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())
|
||||
{
|
||||
@@ -98,7 +98,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
return;
|
||||
}
|
||||
|
||||
if (antib.getSettings().getData().getAlert().getAlertOnBreak().contains(type)
|
||||
if (antib.getSettings().getData().getAlert().getAlertOnBreak(type)
|
||||
&& !Permissions.ALERTS_NOTRIGGER.isAuthorized(user))
|
||||
{
|
||||
antib.getEssentialsConnect().alert(user, type.toString(), _("alertBroke"));
|
||||
@@ -130,7 +130,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
{
|
||||
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);
|
||||
return;
|
||||
@@ -146,7 +146,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
@@ -160,7 +160,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
final ItemStack item = event.getItem();
|
||||
|
||||
if (item != null
|
||||
&& antib.getSettings().getData().getBlacklist().getUsage().contains(item.getType())
|
||||
&& antib.getSettings().getData().getBlacklist().getUsage(item.getType())
|
||||
&& !Permissions.BLACKLIST_ALLOWUSAGE.isAuthorized(user))
|
||||
{
|
||||
if (antib.getSettings().getData().isWarnOnBuildDisallow())
|
||||
@@ -172,7 +172,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
}
|
||||
|
||||
if (item != null
|
||||
&& antib.getSettings().getData().getAlert().getAlertOnUse().contains(item.getType())
|
||||
&& antib.getSettings().getData().getAlert().getAlertOnUse(item.getType())
|
||||
&& !Permissions.ALERTS_NOTRIGGER.isAuthorized(user))
|
||||
{
|
||||
antib.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed"));
|
||||
|
Reference in New Issue
Block a user