mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-05 20:12:54 +00:00
Reformat
This commit is contained in:
parent
ad13062117
commit
dde0b20775
380 changed files with 38917 additions and 46821 deletions
|
@ -1,74 +1,65 @@
|
|||
package com.earth2me.essentials.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"),
|
||||
blacklist_dispenser("protect.blacklist.dispenser");
|
||||
private final String configName;
|
||||
private final String defValueString;
|
||||
private final boolean defValueBoolean;
|
||||
private final boolean isList;
|
||||
private final boolean isString;
|
||||
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"),
|
||||
blacklist_dispenser("protect.blacklist.dispenser");
|
||||
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) {
|
||||
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 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;
|
||||
}
|
||||
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 configName
|
||||
*/
|
||||
public String getConfigName() {
|
||||
return configName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the default value String
|
||||
*/
|
||||
public String getDefaultValueString()
|
||||
{
|
||||
return defValueString;
|
||||
}
|
||||
/**
|
||||
* @return the default value String
|
||||
*/
|
||||
public String getDefaultValueString() {
|
||||
return defValueString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the default value boolean
|
||||
*/
|
||||
public boolean getDefaultValueBoolean()
|
||||
{
|
||||
return defValueBoolean;
|
||||
}
|
||||
/**
|
||||
* @return the default value boolean
|
||||
*/
|
||||
public boolean getDefaultValueBoolean() {
|
||||
return defValueBoolean;
|
||||
}
|
||||
|
||||
public boolean isString()
|
||||
{
|
||||
return isString;
|
||||
}
|
||||
public boolean isString() {
|
||||
return isString;
|
||||
}
|
||||
|
||||
public boolean isList()
|
||||
{
|
||||
return isList;
|
||||
}
|
||||
public boolean isList() {
|
||||
return isList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,63 +1,56 @@
|
|||
package com.earth2me.essentials.antibuild;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild
|
||||
{
|
||||
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;
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
final PluginManager pm = this.getServer().getPluginManager();
|
||||
final Plugin essPlugin = pm.getPlugin("Essentials");
|
||||
if (essPlugin == null || !essPlugin.isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ess = new EssentialsConnect(essPlugin, this);
|
||||
public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild {
|
||||
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;
|
||||
|
||||
final EssentialsAntiBuildListener blockListener = new EssentialsAntiBuildListener(this);
|
||||
pm.registerEvents(blockListener, this);
|
||||
}
|
||||
@Override
|
||||
public void onEnable() {
|
||||
final PluginManager pm = this.getServer().getPluginManager();
|
||||
final Plugin essPlugin = pm.getPlugin("Essentials");
|
||||
if (essPlugin == null || !essPlugin.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
ess = new EssentialsConnect(essPlugin, this);
|
||||
|
||||
@Override
|
||||
public boolean checkProtectionItems(final AntiBuildConfig list, final int id)
|
||||
{
|
||||
final List<Integer> itemList = settingsList.get(list);
|
||||
return itemList != null && !itemList.isEmpty() && itemList.contains(id);
|
||||
}
|
||||
final EssentialsAntiBuildListener blockListener = new EssentialsAntiBuildListener(this);
|
||||
pm.registerEvents(blockListener, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EssentialsConnect getEssentialsConnect()
|
||||
{
|
||||
return ess;
|
||||
}
|
||||
@Override
|
||||
public boolean checkProtectionItems(final AntiBuildConfig list, final int id) {
|
||||
final List<Integer> itemList = settingsList.get(list);
|
||||
return itemList != null && !itemList.isEmpty() && itemList.contains(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<AntiBuildConfig, Boolean> getSettingsBoolean()
|
||||
{
|
||||
return settingsBoolean;
|
||||
}
|
||||
@Override
|
||||
public EssentialsConnect getEssentialsConnect() {
|
||||
return ess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<AntiBuildConfig, List<Integer>> getSettingsList()
|
||||
{
|
||||
return settingsList;
|
||||
}
|
||||
@Override
|
||||
public Map<AntiBuildConfig, Boolean> getSettingsBoolean() {
|
||||
return settingsBoolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSettingBool(final AntiBuildConfig protectConfig)
|
||||
{
|
||||
final Boolean bool = settingsBoolean.get(protectConfig);
|
||||
return bool == null ? protectConfig.getDefaultValueBoolean() : bool;
|
||||
}
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.earth2me.essentials.antibuild;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
@ -21,305 +19,240 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class EssentialsAntiBuildListener implements Listener
|
||||
{
|
||||
final private transient IAntiBuild prot;
|
||||
final private transient IEssentials ess;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public EssentialsAntiBuildListener(final IAntiBuild parent)
|
||||
{
|
||||
this.prot = parent;
|
||||
this.ess = prot.getEssentialsConnect().getEssentials();
|
||||
}
|
||||
|
||||
private boolean metaPermCheck(final User user, final String action, final Block block)
|
||||
{
|
||||
if (block == null)
|
||||
{
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
ess.getLogger().log(Level.INFO, "AntiBuild permission check failed, invalid block.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return metaPermCheck(user, action, block.getTypeId(), block.getData());
|
||||
}
|
||||
public class EssentialsAntiBuildListener implements Listener {
|
||||
final private transient IAntiBuild prot;
|
||||
final private transient IEssentials ess;
|
||||
|
||||
private boolean metaPermCheck(final User user, final String action, final int blockId)
|
||||
{
|
||||
final String blockPerm = "essentials.build." + action + "." + blockId;
|
||||
return user.isAuthorized(blockPerm);
|
||||
}
|
||||
public EssentialsAntiBuildListener(final IAntiBuild parent) {
|
||||
this.prot = parent;
|
||||
this.ess = prot.getEssentialsConnect().getEssentials();
|
||||
}
|
||||
|
||||
private boolean metaPermCheck(final User user, final String action, final int blockId, final short data)
|
||||
{
|
||||
final String blockPerm = "essentials.build." + action + "." + blockId;
|
||||
final String dataPerm = blockPerm + ":" + data;
|
||||
private boolean metaPermCheck(final User user, final String action, final Block block) {
|
||||
if (block == null) {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "AntiBuild permission check failed, invalid block.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return metaPermCheck(user, action, block.getTypeId(), block.getData());
|
||||
}
|
||||
|
||||
if (user.getBase().isPermissionSet(dataPerm))
|
||||
{
|
||||
return user.isAuthorized(dataPerm);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
ess.getLogger().log(Level.INFO, "DataValue perm on " + user.getName() + " is not directly set: " + dataPerm);
|
||||
}
|
||||
}
|
||||
private boolean metaPermCheck(final User user, final String action, final int blockId) {
|
||||
final String blockPerm = "essentials.build." + action + "." + blockId;
|
||||
return user.isAuthorized(blockPerm);
|
||||
}
|
||||
|
||||
return user.isAuthorized(blockPerm);
|
||||
}
|
||||
private boolean metaPermCheck(final User user, final String action, final int blockId, final short data) {
|
||||
final String blockPerm = "essentials.build." + action + "." + blockId;
|
||||
final String dataPerm = blockPerm + ":" + data;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPlace(final BlockPlaceEvent event)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final Block block = event.getBlockPlaced();
|
||||
final int typeId = block.getTypeId();
|
||||
final Material type = block.getType();
|
||||
if (user.getBase().isPermissionSet(dataPerm)) {
|
||||
return user.isAuthorized(dataPerm);
|
||||
} else {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "DataValue perm on " + user.getName() + " is not directly set: " + dataPerm);
|
||||
}
|
||||
}
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")
|
||||
&& !metaPermCheck(user, "place", block))
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(tl("antiBuildPlace", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
return user.isAuthorized(blockPerm);
|
||||
}
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_placement, typeId) && !user.isAuthorized("essentials.protect.exemptplacement"))
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(tl("antiBuildPlace", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final Block block = event.getBlockPlaced();
|
||||
final int typeId = block.getTypeId();
|
||||
final Material type = block.getType();
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_placement, typeId)
|
||||
&& !user.isAuthorized("essentials.protect.alerts.notrigger"))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, type.toString(), tl("alertPlaced"));
|
||||
}
|
||||
}
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") && !metaPermCheck(user, "place", block)) {
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildPlace", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(final BlockBreakEvent event)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final Block block = event.getBlock();
|
||||
final int typeId = block.getTypeId();
|
||||
final Material type = block.getType();
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_placement, typeId) && !user.isAuthorized("essentials.protect.exemptplacement")) {
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildPlace", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")
|
||||
&& !metaPermCheck(user, "break", block))
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(tl("antiBuildBreak", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_placement, typeId) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
|
||||
prot.getEssentialsConnect().alert(user, type.toString(), tl("alertPlaced"));
|
||||
}
|
||||
}
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, typeId)
|
||||
&& !user.isAuthorized("essentials.protect.exemptbreak"))
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(tl("antiBuildBreak", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(final BlockBreakEvent event) {
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final Block block = event.getBlock();
|
||||
final int typeId = block.getTypeId();
|
||||
final Material type = block.getType();
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_break, typeId)
|
||||
&& !user.isAuthorized("essentials.protect.alerts.notrigger"))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, type.toString(), tl("alertBroke"));
|
||||
}
|
||||
}
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") && !metaPermCheck(user, "break", block)) {
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildBreak", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onHangingBreak(final HangingBreakByEntityEvent event)
|
||||
{
|
||||
final Entity entity = event.getRemover();
|
||||
if (entity instanceof Player)
|
||||
{
|
||||
final User user = ess.getUser((Player)entity);
|
||||
final EntityType type = event.getEntity().getType();
|
||||
final boolean warn = ess.getSettings().warnOnBuildDisallow();
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
{
|
||||
if (type == EntityType.PAINTING && !metaPermCheck(user, "break", Material.PAINTING.getId()))
|
||||
{
|
||||
if (warn)
|
||||
{
|
||||
user.sendMessage(tl("antiBuildBreak", Material.PAINTING.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if(type == EntityType.ITEM_FRAME && !metaPermCheck(user, "break", Material.ITEM_FRAME.getId()))
|
||||
{
|
||||
if (warn)
|
||||
{
|
||||
user.sendMessage(tl("antiBuildBreak", Material.ITEM_FRAME.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, typeId) && !user.isAuthorized("essentials.protect.exemptbreak")) {
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildBreak", type.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPistonExtend(final BlockPistonExtendEvent event)
|
||||
{
|
||||
for (Block block : event.getBlocks())
|
||||
{
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_break, typeId) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
|
||||
prot.getEssentialsConnect().alert(user, type.toString(), tl("alertBroke"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPistonRetract(final BlockPistonRetractEvent event)
|
||||
{
|
||||
if (!event.isSticky())
|
||||
{
|
||||
return;
|
||||
}
|
||||
final Block block = event.getRetractLocation().getBlock();
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onHangingBreak(final HangingBreakByEntityEvent event) {
|
||||
final Entity entity = event.getRemover();
|
||||
if (entity instanceof Player) {
|
||||
final User user = ess.getUser((Player) entity);
|
||||
final EntityType type = event.getEntity().getType();
|
||||
final boolean warn = ess.getSettings().warnOnBuildDisallow();
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
|
||||
if (type == EntityType.PAINTING && !metaPermCheck(user, "break", Material.PAINTING.getId())) {
|
||||
if (warn) {
|
||||
user.sendMessage(tl("antiBuildBreak", Material.PAINTING.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
} else if (type == EntityType.ITEM_FRAME && !metaPermCheck(user, "break", Material.ITEM_FRAME.getId())) {
|
||||
if (warn) {
|
||||
user.sendMessage(tl("antiBuildBreak", Material.ITEM_FRAME.toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerInteract(final PlayerInteractEvent event)
|
||||
{
|
||||
// Do not return if cancelled, because the interact event has 2 cancelled states.
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final ItemStack item = event.getItem();
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPistonExtend(final BlockPistonExtendEvent event) {
|
||||
for (Block block : event.getBlocks()) {
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item != null
|
||||
&& prot.checkProtectionItems(AntiBuildConfig.blacklist_usage, item.getTypeId())
|
||||
&& !user.isAuthorized("essentials.protect.exemptusage"))
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(tl("antiBuildUse", item.getType().toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPistonRetract(final BlockPistonRetractEvent event) {
|
||||
if (!event.isSticky()) {
|
||||
return;
|
||||
}
|
||||
final Block block = event.getRetractLocation().getBlock();
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (item != null
|
||||
&& prot.checkProtectionItems(AntiBuildConfig.alert_on_use, item.getTypeId())
|
||||
&& !user.isAuthorized("essentials.protect.alerts.notrigger"))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, item.getType().toString(), tl("alertUsed"));
|
||||
}
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerInteract(final PlayerInteractEvent event) {
|
||||
// Do not return if cancelled, because the interact event has 2 cancelled states.
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final ItemStack item = event.getItem();
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
{
|
||||
if (event.hasItem() && !metaPermCheck(user, "interact", item.getTypeId(), item.getDurability()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(tl("antiBuildUse", item.getType().toString()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.hasBlock() && !metaPermCheck(user, "interact", event.getClickedBlock()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(tl("antiBuildInteract", event.getClickedBlock().getType().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (item != null && prot.checkProtectionItems(AntiBuildConfig.blacklist_usage, item.getTypeId()) && !user.isAuthorized("essentials.protect.exemptusage")) {
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildUse", item.getType().toString()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onCraftItemEvent(final CraftItemEvent event)
|
||||
{
|
||||
HumanEntity entity = event.getWhoClicked();
|
||||
if (item != null && prot.checkProtectionItems(AntiBuildConfig.alert_on_use, item.getTypeId()) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
|
||||
prot.getEssentialsConnect().alert(user, item.getType().toString(), tl("alertUsed"));
|
||||
}
|
||||
|
||||
if (entity instanceof Player)
|
||||
{
|
||||
final User user = ess.getUser((Player)entity);
|
||||
final ItemStack item = event.getRecipe().getResult();
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
|
||||
if (event.hasItem() && !metaPermCheck(user, "interact", item.getTypeId(), item.getDurability())) {
|
||||
event.setCancelled(true);
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildUse", item.getType().toString()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.hasBlock() && !metaPermCheck(user, "interact", event.getClickedBlock())) {
|
||||
event.setCancelled(true);
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildInteract", event.getClickedBlock().getType().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
{
|
||||
if (!metaPermCheck(user, "craft", item.getTypeId(), item.getDurability()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(tl("antiBuildCraft", item.getType().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onCraftItemEvent(final CraftItemEvent event) {
|
||||
HumanEntity entity = event.getWhoClicked();
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event)
|
||||
{
|
||||
if (entity instanceof Player) {
|
||||
final User user = ess.getUser((Player) entity);
|
||||
final ItemStack item = event.getRecipe().getResult();
|
||||
|
||||
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 (!metaPermCheck(user, "craft", item.getTypeId(), item.getDurability())) {
|
||||
event.setCancelled(true);
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildCraft", item.getType().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
{
|
||||
if (!metaPermCheck(user, "pickup", item.getTypeId(), item.getDurability()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
event.getItem().setPickupDelay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerDropItem(final PlayerDropItemEvent event)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final ItemStack item = event.getItem().getItemStack();
|
||||
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final ItemStack item = event.getItemDrop().getItemStack();
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
|
||||
if (!metaPermCheck(user, "pickup", item.getTypeId(), item.getDurability())) {
|
||||
event.setCancelled(true);
|
||||
event.getItem().setPickupDelay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
{
|
||||
if (!metaPermCheck(user, "drop", item.getTypeId(), item.getDurability()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
user.getBase().updateInventory();
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(tl("antiBuildDrop", item.getType().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerDropItem(final PlayerDropItemEvent event) {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockDispense(final BlockDispenseEvent event)
|
||||
{
|
||||
final ItemStack item = event.getItem();
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_dispenser, item.getTypeId()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final ItemStack item = event.getItemDrop().getItemStack();
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
|
||||
if (!metaPermCheck(user, "drop", item.getTypeId(), item.getDurability())) {
|
||||
event.setCancelled(true);
|
||||
user.getBase().updateInventory();
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildDrop", item.getType().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockDispense(final BlockDispenseEvent event) {
|
||||
final ItemStack item = event.getItem();
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_dispenser, item.getTypeId())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,79 +2,65 @@ package com.earth2me.essentials.antibuild;
|
|||
|
||||
import com.earth2me.essentials.IConf;
|
||||
import com.earth2me.essentials.User;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
import net.ess3.api.IEssentials;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class EssentialsConnect
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private final transient IEssentials ess;
|
||||
private final transient IAntiBuild protect;
|
||||
|
||||
public EssentialsConnect(Plugin essPlugin, Plugin essProtect)
|
||||
{
|
||||
if (!essProtect.getDescription().getVersion().equals(essPlugin.getDescription().getVersion()))
|
||||
{
|
||||
LOGGER.log(Level.WARNING, tl("versionMismatchAll"));
|
||||
}
|
||||
ess = (IEssentials)essPlugin;
|
||||
protect = (IAntiBuild)essProtect;
|
||||
AntiBuildReloader pr = new AntiBuildReloader();
|
||||
pr.reloadConfig();
|
||||
ess.addReloadListener(pr);
|
||||
}
|
||||
|
||||
public void onDisable()
|
||||
{
|
||||
}
|
||||
|
||||
public IEssentials getEssentials()
|
||||
{
|
||||
return ess;
|
||||
}
|
||||
|
||||
public void alert(final User user, final String item, final String type)
|
||||
{
|
||||
final Location loc = user.getLocation();
|
||||
final String warnMessage = tl("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"))
|
||||
{
|
||||
alertUser.sendMessage(warnMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
|
||||
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()));
|
||||
}
|
||||
public class EssentialsConnect {
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private final transient IEssentials ess;
|
||||
private final transient IAntiBuild protect;
|
||||
|
||||
}
|
||||
public EssentialsConnect(Plugin essPlugin, Plugin essProtect) {
|
||||
if (!essProtect.getDescription().getVersion().equals(essPlugin.getDescription().getVersion())) {
|
||||
LOGGER.log(Level.WARNING, tl("versionMismatchAll"));
|
||||
}
|
||||
ess = (IEssentials) essPlugin;
|
||||
protect = (IAntiBuild) essProtect;
|
||||
AntiBuildReloader pr = new AntiBuildReloader();
|
||||
pr.reloadConfig();
|
||||
ess.addReloadListener(pr);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
public IEssentials getEssentials() {
|
||||
return ess;
|
||||
}
|
||||
|
||||
public void alert(final User user, final String item, final String type) {
|
||||
final Location loc = user.getLocation();
|
||||
final String warnMessage = tl("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")) {
|
||||
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,19 @@
|
|||
package com.earth2me.essentials.antibuild;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public interface IAntiBuild extends Plugin
|
||||
{
|
||||
boolean checkProtectionItems(final AntiBuildConfig list, final int id);
|
||||
public interface IAntiBuild extends Plugin {
|
||||
boolean checkProtectionItems(final AntiBuildConfig list, final int id);
|
||||
|
||||
boolean getSettingBool(final AntiBuildConfig protectConfig);
|
||||
boolean getSettingBool(final AntiBuildConfig protectConfig);
|
||||
|
||||
EssentialsConnect getEssentialsConnect();
|
||||
EssentialsConnect getEssentialsConnect();
|
||||
|
||||
Map<AntiBuildConfig, Boolean> getSettingsBoolean();
|
||||
Map<AntiBuildConfig, Boolean> getSettingsBoolean();
|
||||
|
||||
Map<AntiBuildConfig, List<Integer>> getSettingsList();
|
||||
Map<AntiBuildConfig, List<Integer>> getSettingsList();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue