mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-18 12:31:26 +02:00
Updating antibuild to use 3.0 configs and perms.
AntiBuild listener still has some conversions to do
This commit is contained in:
36
Essentials/src/net/ess3/settings/antibuild/Alert.java
Normal file
36
Essentials/src/net/ess3/settings/antibuild/Alert.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package net.ess3.settings.antibuild;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.ess3.storage.Comment;
|
||||
import net.ess3.storage.ListType;
|
||||
import net.ess3.storage.StorageObject;
|
||||
import org.bukkit.Material;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Alert implements StorageObject
|
||||
{
|
||||
@Comment("For which block types would you like to be alerted?")
|
||||
@ListType(Material.class)
|
||||
private Set<Material> alertOnPlacement = new HashSet<Material>();
|
||||
@ListType(Material.class)
|
||||
private Set<Material> alertOnUse = new HashSet<Material>();
|
||||
@ListType(Material.class)
|
||||
private Set<Material> alertOnBreak = new HashSet<Material>();
|
||||
|
||||
public Alert()
|
||||
{
|
||||
//todo full default list
|
||||
alertOnPlacement.add(Material.GLASS);
|
||||
alertOnUse.add(Material.LAVA);
|
||||
alertOnBreak.add(Material.OBSIDIAN);
|
||||
}
|
||||
}
|
43
Essentials/src/net/ess3/settings/antibuild/AntiBuild.java
Normal file
43
Essentials/src/net/ess3/settings/antibuild/AntiBuild.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package net.ess3.settings.antibuild;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.ess3.storage.*;
|
||||
import org.bukkit.Material;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AntiBuild implements StorageObject
|
||||
{
|
||||
@Comment(
|
||||
{
|
||||
"Should people with build: false in permissions be allowed to build",
|
||||
"Set true to disable building for those people",
|
||||
"Setting to false means EssentialsAntiBuild will never prevent you from building"
|
||||
})
|
||||
private boolean build = true;
|
||||
@Comment(
|
||||
{
|
||||
"Should people with build: false in permissions be allowed to use items",
|
||||
"Set true to disable using for those people",
|
||||
"Setting to false means EssentialsAntiBuild will never prevent you from using"
|
||||
})
|
||||
private boolean use = true;
|
||||
|
||||
@Comment({"Should we tell people they are not allowed to build"})
|
||||
private boolean warnOnBuildDisallow = true;
|
||||
|
||||
|
||||
Alert alert = new Alert();
|
||||
|
||||
BlackList blacklist = new BlackList();
|
||||
|
||||
|
||||
}
|
42
Essentials/src/net/ess3/settings/antibuild/BlackList.java
Normal file
42
Essentials/src/net/ess3/settings/antibuild/BlackList.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package net.ess3.settings.antibuild;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.ess3.storage.Comment;
|
||||
import net.ess3.storage.ListType;
|
||||
import net.ess3.storage.StorageObject;
|
||||
import org.bukkit.Material;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class BlackList implements StorageObject
|
||||
{
|
||||
@Comment({"Which blocks should people be prevented from placing"})
|
||||
@ListType(Material.class)
|
||||
private Set<Material> placement = new HashSet<Material>();
|
||||
|
||||
@Comment({"Which items should people be prevented from using"})
|
||||
@ListType(Material.class)
|
||||
private Set<Material> usage = new HashSet<Material>();
|
||||
|
||||
@Comment({"Which blocks should people be prevented from breaking"})
|
||||
@ListType(Material.class)
|
||||
private Set<Material> breaking = new HashSet<Material>();
|
||||
|
||||
@Comment({"Which blocks should not be pushed by pistons"})
|
||||
@ListType(Material.class)
|
||||
private Set<Material> piston = new HashSet<Material>();
|
||||
|
||||
|
||||
public BlackList()
|
||||
{
|
||||
//todo defaults
|
||||
}
|
||||
}
|
@@ -18,8 +18,7 @@ public class Protect implements StorageObject
|
||||
"Set prevent.creeper-explosion to true, if you want to disable creeper explosions."
|
||||
})
|
||||
private int creeperMaxHeight = -1;
|
||||
@Comment("Should we tell people they are not allowed to build")
|
||||
private boolean warnOnBuildDisallow = true;
|
||||
|
||||
@Comment("Disable weather options")
|
||||
private boolean disableStorm = false;
|
||||
private boolean disableThunder = false;
|
||||
|
@@ -1,26 +0,0 @@
|
||||
package net.ess3.settings.protect;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.ess3.storage.Comment;
|
||||
import net.ess3.storage.StorageObject;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SignsAndRails implements StorageObject
|
||||
{
|
||||
@Comment("Protect all signs")
|
||||
private boolean protectSigns = true;
|
||||
@Comment("Prevent users from destroying rails")
|
||||
private boolean protectRails = true;
|
||||
@Comment(
|
||||
{
|
||||
"Blocks below rails/signs are also protected if the respective rail/sign is protected.",
|
||||
"This makes it more difficult to circumvent protection, and should be enabled.",
|
||||
"This only has an effect if rails or signs is also enabled."
|
||||
})
|
||||
private boolean blockBelow = true;
|
||||
@Comment("Prevent placing blocks above protected rails, this is to stop a potential griefing")
|
||||
private boolean preventBlockAboveRails = false;
|
||||
}
|
@@ -18,7 +18,6 @@ import net.ess3.economy.register.Method;
|
||||
import net.ess3.permissions.Permissions;
|
||||
import net.ess3.utils.DateUtil;
|
||||
import net.ess3.utils.FormatUtil;
|
||||
import net.ess3.utils.Util;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@@ -1,73 +0,0 @@
|
||||
package net.ess3.antibuild;
|
||||
|
||||
|
||||
public enum AntiBuildConfig
|
||||
{
|
||||
disable_build("protect.disable.build", true),
|
||||
disable_use("protect.disable.use", true),
|
||||
alert_on_placement("protect.alert.on-placement"),
|
||||
alert_on_use("protect.alert.on-use"),
|
||||
alert_on_break("protect.alert.on-break"),
|
||||
blacklist_placement("protect.blacklist.placement"),
|
||||
blacklist_usage("protect.blacklist.usage"),
|
||||
blacklist_break("protect.blacklist.break"),
|
||||
blacklist_piston("protect.blacklist.piston");
|
||||
private final String configName;
|
||||
private final String defValueString;
|
||||
private final boolean defValueBoolean;
|
||||
private final boolean isList;
|
||||
private final boolean isString;
|
||||
|
||||
private AntiBuildConfig(final String configName)
|
||||
{
|
||||
this(configName, null, false, true, false);
|
||||
}
|
||||
|
||||
private AntiBuildConfig(final String configName, final boolean defValueBoolean)
|
||||
{
|
||||
this(configName, null, defValueBoolean, false, false);
|
||||
}
|
||||
|
||||
private AntiBuildConfig(final String configName, final String defValueString, final boolean defValueBoolean, final boolean isList, final boolean isString)
|
||||
{
|
||||
this.configName = configName;
|
||||
this.defValueString = defValueString;
|
||||
this.defValueBoolean = defValueBoolean;
|
||||
this.isList = isList;
|
||||
this.isString = isString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the configName
|
||||
*/
|
||||
public String getConfigName()
|
||||
{
|
||||
return configName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the default value String
|
||||
*/
|
||||
public String getDefaultValueString()
|
||||
{
|
||||
return defValueString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the default value boolean
|
||||
*/
|
||||
public boolean getDefaultValueBoolean()
|
||||
{
|
||||
return defValueBoolean;
|
||||
}
|
||||
|
||||
public boolean isString()
|
||||
{
|
||||
return isString;
|
||||
}
|
||||
|
||||
public boolean isList()
|
||||
{
|
||||
return isList;
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package net.ess3.antibuild;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.settings.antibuild.AntiBuild;
|
||||
import net.ess3.storage.AsyncStorageObjectHolder;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author devhome
|
||||
*/
|
||||
public class AntiBuildHolder extends AsyncStorageObjectHolder<AntiBuild>
|
||||
{
|
||||
public AntiBuildHolder(final IEssentials ess)
|
||||
{
|
||||
super(ess, AntiBuild.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getStorageFile() throws IOException
|
||||
{
|
||||
return new File(ess.getPlugin().getDataFolder(), "protect.yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishRead()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishWrite()
|
||||
{
|
||||
}
|
||||
}
|
@@ -12,9 +12,8 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private final transient Map<AntiBuildConfig, Boolean> settingsBoolean = new EnumMap<AntiBuildConfig, Boolean>(AntiBuildConfig.class);
|
||||
private final transient Map<AntiBuildConfig, List<Integer>> settingsList = new EnumMap<AntiBuildConfig, List<Integer>>(AntiBuildConfig.class);
|
||||
private transient EssentialsConnect ess = null;
|
||||
private transient AntiBuildHolder settings = null;
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
@@ -32,7 +31,7 @@ public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkProtectionItems(final AntiBuildConfig list, final int id)
|
||||
public boolean checkProtectionItems(final int id)
|
||||
{
|
||||
final List<Integer> itemList = settingsList.get(list);
|
||||
return itemList != null && !itemList.isEmpty() && itemList.contains(id);
|
||||
@@ -42,24 +41,17 @@ public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild
|
||||
public EssentialsConnect getEssentialsConnect()
|
||||
{
|
||||
return ess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AntiBuildHolder getSettings()
|
||||
{
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<AntiBuildConfig, Boolean> getSettingsBoolean()
|
||||
public void setSettings(final AntiBuildHolder settings)
|
||||
{
|
||||
return settingsBoolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<AntiBuildConfig, List<Integer>> getSettingsList()
|
||||
{
|
||||
return settingsList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSettingBool(final AntiBuildConfig protectConfig)
|
||||
{
|
||||
final Boolean bool = settingsBoolean.get(protectConfig);
|
||||
return bool == null ? protectConfig.getDefaultValueBoolean() : bool;
|
||||
this.settings = settings;
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package net.ess3.antibuild;
|
||||
import java.util.logging.Level;
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.user.User;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -23,13 +24,13 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EssentialsAntiBuildListener implements Listener
|
||||
{
|
||||
final private transient IAntiBuild prot;
|
||||
final private transient IAntiBuild antib;
|
||||
final private transient IEssentials ess;
|
||||
|
||||
public EssentialsAntiBuildListener(final IAntiBuild parent)
|
||||
{
|
||||
this.prot = parent;
|
||||
this.ess = prot.getEssentialsConnect().getEssentials();
|
||||
this.antib = parent;
|
||||
this.ess = antib.getEssentialsConnect().getEssentials();
|
||||
}
|
||||
|
||||
private boolean metaPermCheck(final User user, final String action, final Block block)
|
||||
@@ -70,73 +71,95 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPlace(final BlockPlaceEvent event)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final AntiBuildHolder ab = antib.getSettings();
|
||||
ab.acquireReadLock();
|
||||
final IUser user = ess.getUserMap().getUser(event.getPlayer());
|
||||
final Block block = event.getBlockPlaced();
|
||||
final int typeId = block.getTypeId();
|
||||
final Material type = block.getType();
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")
|
||||
&& !metaPermCheck(user, "place", block))
|
||||
try
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(_("antiBuildPlace", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_placement, typeId) && !user.isAuthorized("essentials.protect.exemptplacement"))
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
if (ab.getData().isBuild()
|
||||
&& !user.canBuild() && !user.hasPermission("essentials.build")
|
||||
&& !Permissions.getPlacePermission(type).isAuthorized(user))
|
||||
//metaPermCheck(user, "place", block)) todo - double check metadata
|
||||
{
|
||||
user.sendMessage(_("antiBuildPlace", type.toString()));
|
||||
if (ab.getData().isWarnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(_("antiBuildPlace", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_placement, typeId)
|
||||
&& !user.isAuthorized("essentials.protect.alerts.notrigger"))
|
||||
if (ab.getData().getBlacklist().getPlacement().contains(type) && !Permissions.BLACKLIST_ALLOWPLACEMENT.isAuthorized(user))
|
||||
//antib.checkProtectionItems(AntiBuildConfig.blacklist_placement, typeId) && !user.isAuthorized("essentials.protect.exemptplacement"))
|
||||
{
|
||||
if (ab.getData().isWarnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(_("antiBuildPlace", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ab.getData().getAlert().getAlertOnPlacement().contains(type)
|
||||
&& !Permissions.ALERTS_NOTRIGGER.isAuthorized(user))
|
||||
{
|
||||
antib.getEssentialsConnect().alert(user, type.toString(), _("alertPlaced"));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, type.toString(), _("alertPlaced"));
|
||||
ab.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(final BlockBreakEvent event)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final AntiBuildHolder ab = antib.getSettings();
|
||||
ab.acquireReadLock();
|
||||
final IUser user = ess.getUserMap().getUser(event.getPlayer());
|
||||
final Block block = event.getBlock();
|
||||
final int typeId = block.getTypeId();
|
||||
final Material type = block.getType();
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")
|
||||
&& !metaPermCheck(user, "break", block))
|
||||
try
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
if (ab.getData().isBuild() && !user.canBuild() && !user.isAuthorized("essentials.build")
|
||||
&& !Permissions.getBreakPermission(type).isAuthorized(user))
|
||||
//!metaPermCheck(user, "break", block))
|
||||
{
|
||||
user.sendMessage(_("antiBuildBreak", type.toString()));
|
||||
if (ab.getData().isWarnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(_("antiBuildBreak", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, typeId)
|
||||
&& !user.isAuthorized("essentials.protect.exemptbreak"))
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
if (ab.getData().getBlacklist().getBreaking().contains(type) && !Permissions.BLACKLIST_ALLOWBREAK.isAuthorized(user))
|
||||
{
|
||||
user.sendMessage(_("antiBuildBreak", type.toString()));
|
||||
if (ab.getData().isWarnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(_("antiBuildBreak", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_break, typeId)
|
||||
&& !user.isAuthorized("essentials.protect.alerts.notrigger"))
|
||||
if (antib.checkProtectionItems(AntiBuildConfig.alert_on_break, typeId)
|
||||
&& !user.isAuthorized("essentials.protect.alerts.notrigger"))
|
||||
{
|
||||
antib.getEssentialsConnect().alert(user, type.toString(), _("alertBroke"));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, type.toString(), _("alertBroke"));
|
||||
ab.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +170,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
if (entity instanceof Player)
|
||||
{
|
||||
final User user = ess.getUser(entity);
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")
|
||||
if (antib.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")
|
||||
&& !metaPermCheck(user, "break", Material.PAINTING.getId()))
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
@@ -164,7 +187,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
{
|
||||
for (Block block : event.getBlocks())
|
||||
{
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId()))
|
||||
if (antib.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@@ -180,7 +203,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
return;
|
||||
}
|
||||
final Block block = event.getRetractLocation().getBlock();
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId()))
|
||||
if (antib.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@@ -195,7 +218,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
final ItemStack item = event.getItem();
|
||||
|
||||
if (item != null
|
||||
&& prot.checkProtectionItems(AntiBuildConfig.blacklist_usage, item.getTypeId())
|
||||
&& antib.checkProtectionItems(AntiBuildConfig.blacklist_usage, item.getTypeId())
|
||||
&& !user.isAuthorized("essentials.protect.exemptusage"))
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
@@ -207,13 +230,13 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
}
|
||||
|
||||
if (item != null
|
||||
&& prot.checkProtectionItems(AntiBuildConfig.alert_on_use, item.getTypeId())
|
||||
&& antib.checkProtectionItems(AntiBuildConfig.alert_on_use, item.getTypeId())
|
||||
&& !user.isAuthorized("essentials.protect.alerts.notrigger"))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed"));
|
||||
antib.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed"));
|
||||
}
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
if (antib.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
{
|
||||
if (event.hasItem() && !metaPermCheck(user, "interact", item.getTypeId(), item.getData().getData()))
|
||||
{
|
||||
@@ -245,7 +268,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
final User user = ess.getUser(entity);
|
||||
final ItemStack item = event.getRecipe().getResult();
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
if (antib.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
{
|
||||
if (!metaPermCheck(user, "craft", item.getTypeId(), item.getData().getData()))
|
||||
{
|
||||
@@ -266,7 +289,7 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final ItemStack item = event.getItem().getItemStack();
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
if (antib.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
{
|
||||
if (!metaPermCheck(user, "pickup", item.getTypeId(), item.getData().getData()))
|
||||
{
|
||||
@@ -280,15 +303,15 @@ public class EssentialsAntiBuildListener implements Listener
|
||||
public void onPlayerDropItem(final PlayerDropItemEvent event)
|
||||
{
|
||||
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final IUser user = ess.getUserMap().getUser(event.getPlayer());
|
||||
final ItemStack item = event.getItemDrop().getItemStack();
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
if (antib.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
{
|
||||
if (!metaPermCheck(user, "drop", item.getTypeId(), item.getData().getData()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
user.updateInventory();
|
||||
user.getPlayer().updateInventory();
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(_("antiBuildDrop", item.getType().toString()));
|
||||
|
@@ -1,11 +1,10 @@
|
||||
package net.ess3.antibuild;
|
||||
|
||||
import net.ess3.api.IConf;
|
||||
import net.ess3.api.IEssentials;
|
||||
import static net.ess3.I18n._;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.ess3.user.User;
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IUser;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@@ -15,7 +14,7 @@ public class EssentialsConnect
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private final transient IEssentials ess;
|
||||
private final transient IAntiBuild protect;
|
||||
private final transient IAntiBuild antib;
|
||||
|
||||
public EssentialsConnect(Plugin essPlugin, Plugin essProtect)
|
||||
{
|
||||
@@ -24,10 +23,8 @@ public class EssentialsConnect
|
||||
LOGGER.log(Level.WARNING, _("versionMismatchAll"));
|
||||
}
|
||||
ess = (IEssentials)essPlugin;
|
||||
protect = (IAntiBuild)essProtect;
|
||||
AntiBuildReloader pr = new AntiBuildReloader();
|
||||
pr.reloadConfig();
|
||||
ess.addReloadListener(pr);
|
||||
antib = (IAntiBuild)essProtect;
|
||||
antib.setSettings(new AntiBuildHolder(ess));
|
||||
}
|
||||
|
||||
public void onDisable()
|
||||
@@ -39,42 +36,20 @@ public class EssentialsConnect
|
||||
return ess;
|
||||
}
|
||||
|
||||
public void alert(final User user, final String item, final String type)
|
||||
public void alert(final IUser user, final String item, final String type)
|
||||
{
|
||||
final Location loc = user.getLocation();
|
||||
final Location loc = user.getPlayer().getLocation();
|
||||
final String warnMessage = _("alertFormat", user.getName(), type, item,
|
||||
loc.getWorld().getName() + "," + loc.getBlockX() + ","
|
||||
+ loc.getBlockY() + "," + loc.getBlockZ());
|
||||
LOGGER.log(Level.WARNING, warnMessage);
|
||||
for (Player p : ess.getServer().getOnlinePlayers())
|
||||
{
|
||||
final User alertUser = ess.getUser(p);
|
||||
if (alertUser.isAuthorized("essentials.protect.alerts"))
|
||||
final IUser alertUser = ess.getUserMap().getUser(p);
|
||||
if (Permissions.ALERTS.isAuthorized(alertUser))
|
||||
{
|
||||
alertUser.sendMessage(warnMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class AntiBuildReloader implements IConf
|
||||
{
|
||||
@Override
|
||||
public void reloadConfig()
|
||||
{
|
||||
for (AntiBuildConfig protectConfig : AntiBuildConfig.values())
|
||||
{
|
||||
if (protectConfig.isList())
|
||||
{
|
||||
protect.getSettingsList().put(protectConfig, ess.getSettings().getProtectList(protectConfig.getConfigName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
protect.getSettingsBoolean().put(protectConfig, ess.getSettings().getProtectBoolean(protectConfig.getConfigName(), protectConfig.getDefaultValueBoolean()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,19 +1,15 @@
|
||||
package net.ess3.antibuild;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public interface IAntiBuild extends Plugin
|
||||
{
|
||||
boolean checkProtectionItems(final AntiBuildConfig list, final int id);
|
||||
|
||||
boolean getSettingBool(final AntiBuildConfig protectConfig);
|
||||
boolean checkProtectionItems(final int id);
|
||||
|
||||
EssentialsConnect getEssentialsConnect();
|
||||
|
||||
AntiBuildHolder getSettings();
|
||||
|
||||
Map<AntiBuildConfig, Boolean> getSettingsBoolean();
|
||||
|
||||
Map<AntiBuildConfig, List<Integer>> getSettingsList();
|
||||
void setSettings(AntiBuildHolder settings);
|
||||
}
|
||||
|
177
EssentialsAntiBuild/src/net/ess3/antibuild/Permissions.java
Normal file
177
EssentialsAntiBuild/src/net/ess3/antibuild/Permissions.java
Normal file
@@ -0,0 +1,177 @@
|
||||
package net.ess3.antibuild;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Locale;
|
||||
import net.ess3.api.IPermission;
|
||||
import net.ess3.bukkit.PermissionFactory;
|
||||
import net.ess3.permissions.BasePermission;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
|
||||
public enum Permissions implements IPermission
|
||||
{
|
||||
|
||||
BLACKLIST_ALLOWPLACEMENT,
|
||||
BLACKLIST_ALLOWUSAGE,
|
||||
BLACKLIST_ALLOWBREAK,
|
||||
ALERTS,
|
||||
ALERTS_NOTRIGGER;
|
||||
private static final String base = "essentials.build.";
|
||||
private final String permission;
|
||||
private final PermissionDefault defaultPerm;
|
||||
private transient Permission bukkitPerm = null;
|
||||
|
||||
private Permissions()
|
||||
{
|
||||
this(PermissionDefault.OP);
|
||||
}
|
||||
|
||||
private Permissions(final PermissionDefault defaultPerm)
|
||||
{
|
||||
permission = base + toString().toLowerCase(Locale.ENGLISH).replace('_', '.');
|
||||
this.defaultPerm = defaultPerm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionName()
|
||||
{
|
||||
return permission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Permission getPermission()
|
||||
{
|
||||
if (bukkitPerm != null)
|
||||
{
|
||||
return bukkitPerm;
|
||||
}
|
||||
else
|
||||
{
|
||||
return PermissionFactory.registerPermission(getPermissionName(), getPermissionDefault());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionDefault getPermissionDefault()
|
||||
{
|
||||
return this.defaultPerm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAuthorized(final CommandSender sender)
|
||||
{
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
private static EnumMap<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class);
|
||||
|
||||
public static IPermission getPlacePermission(final Material mat)
|
||||
{
|
||||
IPermission perm = permissions.get(mat);
|
||||
if (perm == null)
|
||||
{
|
||||
perm = new BasePermission("essentials.place.", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", ""))
|
||||
{
|
||||
@Override
|
||||
public PermissionDefault getPermissionDefault()
|
||||
{
|
||||
return PermissionDefault.TRUE;
|
||||
}
|
||||
};
|
||||
permissions.put(mat, perm);
|
||||
}
|
||||
return perm;
|
||||
}
|
||||
|
||||
public static IPermission getBreakPermission(final Material mat)
|
||||
{
|
||||
IPermission perm = permissions.get(mat);
|
||||
if (perm == null)
|
||||
{
|
||||
perm = new BasePermission("essentials.break.", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", ""))
|
||||
{
|
||||
@Override
|
||||
public PermissionDefault getPermissionDefault()
|
||||
{
|
||||
return PermissionDefault.TRUE;
|
||||
}
|
||||
};
|
||||
permissions.put(mat, perm);
|
||||
}
|
||||
return perm;
|
||||
}
|
||||
|
||||
public static IPermission getInteractPermission(final Material mat)
|
||||
{
|
||||
IPermission perm = permissions.get(mat);
|
||||
if (perm == null)
|
||||
{
|
||||
perm = new BasePermission("essentials.interact.", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", ""))
|
||||
{
|
||||
@Override
|
||||
public PermissionDefault getPermissionDefault()
|
||||
{
|
||||
return PermissionDefault.TRUE;
|
||||
}
|
||||
};
|
||||
permissions.put(mat, perm);
|
||||
}
|
||||
return perm;
|
||||
}
|
||||
public static IPermission getCraftPermission(final Material mat)
|
||||
{
|
||||
IPermission perm = permissions.get(mat);
|
||||
if (perm == null)
|
||||
{
|
||||
perm = new BasePermission("essentials.craft.", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", ""))
|
||||
{
|
||||
@Override
|
||||
public PermissionDefault getPermissionDefault()
|
||||
{
|
||||
return PermissionDefault.TRUE;
|
||||
}
|
||||
};
|
||||
permissions.put(mat, perm);
|
||||
}
|
||||
return perm;
|
||||
}
|
||||
|
||||
public static IPermission getPickupPermission(final Material mat)
|
||||
{
|
||||
IPermission perm = permissions.get(mat);
|
||||
if (perm == null)
|
||||
{
|
||||
perm = new BasePermission("essentials.pickup.", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", ""))
|
||||
{
|
||||
@Override
|
||||
public PermissionDefault getPermissionDefault()
|
||||
{
|
||||
return PermissionDefault.TRUE;
|
||||
}
|
||||
};
|
||||
permissions.put(mat, perm);
|
||||
}
|
||||
return perm;
|
||||
}
|
||||
|
||||
public static IPermission getDropPermission(final Material mat)
|
||||
{
|
||||
IPermission perm = permissions.get(mat);
|
||||
if (perm == null)
|
||||
{
|
||||
perm = new BasePermission("essentials.drop.", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", ""))
|
||||
{
|
||||
@Override
|
||||
public PermissionDefault getPermissionDefault()
|
||||
{
|
||||
return PermissionDefault.TRUE;
|
||||
}
|
||||
};
|
||||
permissions.put(mat, perm);
|
||||
}
|
||||
return perm;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user