mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-12 01:25:26 +02:00
Split Ess protect into EssProtect and EssAntiBuild
New permissions: essentials.build - same as build: true essentials.build.interact.<id> - whitelist single interact block essentials.build.place.<id> - whitelist single place block essentials.build.break.<id> - whitelist single break block essentials.build.use.<id> - whitelist single use item
This commit is contained in:
@@ -2,7 +2,6 @@ package com.earth2me.essentials.protect;
|
||||
|
||||
import com.earth2me.essentials.IConf;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.protect.data.ProtectedBlockMemory;
|
||||
import com.earth2me.essentials.protect.data.ProtectedBlockMySQL;
|
||||
import com.earth2me.essentials.protect.data.ProtectedBlockSQLite;
|
||||
@@ -10,8 +9,6 @@ import java.beans.PropertyVetoException;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
@@ -43,23 +40,6 @@ public class EssentialsConnect
|
||||
return ess;
|
||||
}
|
||||
|
||||
public void alert(final User user, final String item, final String type)
|
||||
{
|
||||
final Location loc = user.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"))
|
||||
{
|
||||
alertUser.sendMessage(warnMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class ProtectReloader implements IConf
|
||||
{
|
||||
|
@@ -73,13 +73,6 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
|
||||
LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essenials Protect is in emergency mode now.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkProtectionItems(final ProtectConfig list, final int id)
|
||||
{
|
||||
final List<Integer> itemList = settingsList.get(list);
|
||||
return itemList != null && !itemList.isEmpty() && itemList.contains(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProtectedBlock getStorage()
|
||||
{
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.earth2me.essentials.protect;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.protect.data.IProtectedBlock;
|
||||
@@ -36,26 +35,9 @@ public class EssentialsProtectBlockListener implements Listener
|
||||
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
|
||||
if (prot.getSettingBool(ProtectConfig.disable_build) && !user.canBuild())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final Block blockPlaced = event.getBlockPlaced();
|
||||
final int id = blockPlaced.getTypeId();
|
||||
|
||||
if (prot.checkProtectionItems(ProtectConfig.blacklist_placement, id) && !user.isAuthorized("essentials.protect.exemptplacement"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.hasPermission("essentials.protect.alerts.notrigger")
|
||||
&& prot.checkProtectionItems(ProtectConfig.alert_on_placement, id))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, blockPlaced.getType().toString(), _("alertPlaced"));
|
||||
}
|
||||
|
||||
final Block below = blockPlaced.getRelative(BlockFace.DOWN);
|
||||
if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL)
|
||||
@@ -234,27 +216,11 @@ public class EssentialsProtectBlockListener implements Listener
|
||||
}
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
|
||||
if (prot.getSettingBool(ProtectConfig.disable_build) && !user.canBuild())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final Block block = event.getBlock();
|
||||
final int typeId = block.getTypeId();
|
||||
|
||||
if (prot.checkProtectionItems(ProtectConfig.blacklist_break, typeId)
|
||||
&& !user.isAuthorized("essentials.protect.exemptbreak"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final Material type = block.getType();
|
||||
|
||||
if (!user.hasPermission("essentials.protect.alerts.notrigger")
|
||||
&& prot.checkProtectionItems(ProtectConfig.alert_on_break, typeId))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, type.toString(), _("alertBroke"));
|
||||
}
|
||||
final IProtectedBlock storage = prot.getStorage();
|
||||
|
||||
if (user.isAuthorized("essentials.protect.admin"))
|
||||
@@ -333,11 +299,6 @@ public class EssentialsProtectBlockListener implements Listener
|
||||
}
|
||||
for (Block block : event.getBlocks())
|
||||
{
|
||||
if (prot.checkProtectionItems(ProtectConfig.blacklist_piston, block.getTypeId()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS
|
||||
|| block.getType() == Material.RAILS
|
||||
|| block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL
|
||||
@@ -385,11 +346,6 @@ public class EssentialsProtectBlockListener implements Listener
|
||||
return;
|
||||
}
|
||||
final Block block = event.getRetractLocation().getBlock();
|
||||
if (prot.checkProtectionItems(ProtectConfig.blacklist_piston, block.getTypeId()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS
|
||||
|| block.getType() == Material.RAILS
|
||||
|| block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL
|
||||
|
@@ -3,14 +3,12 @@ package com.earth2me.essentials.protect;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class EssentialsProtectPlayerListener implements Listener
|
||||
@@ -30,38 +28,6 @@ public class EssentialsProtectPlayerListener implements Listener
|
||||
// Do not return if cancelled, because the interact event has 2 cancelled states.
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
|
||||
if (event.hasItem()
|
||||
&& (event.getItem().getType() == Material.WATER_BUCKET
|
||||
|| event.getItem().getType() == Material.LAVA_BUCKET)
|
||||
&& prot.getSettingBool(ProtectConfig.disable_build) && !user.canBuild())
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(_("buildAlert"));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (prot.getSettingBool(ProtectConfig.disable_use) && !user.canBuild())
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(_("buildAlert"));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack item = event.getItem();
|
||||
if (item != null
|
||||
&& prot.checkProtectionItems(ProtectConfig.blacklist_usage, item.getTypeId())
|
||||
&& !user.isAuthorized("essentials.protect.exemptusage"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.isAuthorized("essentials.protect.ownerinfo") && event.getAction() == Action.RIGHT_CLICK_BLOCK)
|
||||
{
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
@@ -82,11 +48,5 @@ public class EssentialsProtectPlayerListener implements Listener
|
||||
user.sendMessage(_("protectionOwner", ownerNames));
|
||||
}
|
||||
}
|
||||
if (item != null
|
||||
&& !user.hasPermission("essentials.protect.alerts.notrigger")
|
||||
&& prot.checkProtectionItems(ProtectConfig.alert_on_use, item.getTypeId()))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,8 +8,6 @@ import org.bukkit.plugin.Plugin;
|
||||
|
||||
public interface IProtect extends Plugin
|
||||
{
|
||||
boolean checkProtectionItems(final ProtectConfig list, final int id);
|
||||
|
||||
boolean getSettingBool(final ProtectConfig protectConfig);
|
||||
|
||||
String getSettingString(final ProtectConfig protectConfig);
|
||||
|
@@ -10,8 +10,6 @@ public enum ProtectConfig
|
||||
memstore("protect.memstore", false),
|
||||
disable_contactdmg("protect.disable.contactdmg", false),
|
||||
disable_lavadmg("protect.disable.lavadmg", false),
|
||||
disable_build("protect.disable.build", true),
|
||||
disable_use("protect.disable.use", true),
|
||||
disable_pvp("protect.disable.pvp", false),
|
||||
disable_projectiles("protect.disable.projectiles", false),
|
||||
disable_fall("protect.disable.fall", false),
|
||||
@@ -47,14 +45,7 @@ public enum ProtectConfig
|
||||
protect_below_rails("protect.protect.block-below", true),
|
||||
protect_signs("protect.protect.signs", true),
|
||||
protect_against_signs("protect.protect.block-below", true),
|
||||
enderdragon_fakeexplosions("protect.enderdragon-fakeexplosions", false),
|
||||
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");
|
||||
enderdragon_fakeexplosions("protect.enderdragon-fakeexplosions", false);
|
||||
private final String configName;
|
||||
private final String defValueString;
|
||||
private final boolean defValueBoolean;
|
||||
|
Reference in New Issue
Block a user