mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-05 12:02:53 +00:00
Initial removal of item IDs.
We do not rely on Bukkit's item ids anymore, though we still support them in commands via a mapping built off of the items.csv.
This commit is contained in:
parent
dcbc106e62
commit
1a820ad9b7
24 changed files with 225 additions and 141 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.earth2me.essentials.antibuild;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
@ -10,8 +11,8 @@ 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 final transient Map<AntiBuildConfig, Boolean> settingsBoolean = new EnumMap<>(AntiBuildConfig.class);
|
||||
private final transient Map<AntiBuildConfig, List<Material>> settingsList = new EnumMap<>(AntiBuildConfig.class);
|
||||
private transient EssentialsConnect ess = null;
|
||||
|
||||
@Override
|
||||
|
@ -28,9 +29,9 @@ public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild {
|
|||
}
|
||||
|
||||
@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);
|
||||
public boolean checkProtectionItems(final AntiBuildConfig list, final Material mat) {
|
||||
final List<Material> itemList = settingsList.get(list);
|
||||
return itemList != null && !itemList.isEmpty() && itemList.contains(mat);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,7 +45,7 @@ public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<AntiBuildConfig, List<Integer>> getSettingsList() {
|
||||
public Map<AntiBuildConfig, List<Material>> getSettingsList() {
|
||||
return settingsList;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,16 +40,16 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
return metaPermCheck(user, action, block.getTypeId(), block.getData());
|
||||
return metaPermCheck(user, action, block.getType(), block.getData());
|
||||
}
|
||||
|
||||
private boolean metaPermCheck(final User user, final String action, final int blockId) {
|
||||
final String blockPerm = "essentials.build." + action + "." + blockId;
|
||||
private boolean metaPermCheck(final User user, final String action, final Material material) {
|
||||
final String blockPerm = "essentials.build." + action + "." + material;
|
||||
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;
|
||||
private boolean metaPermCheck(final User user, final String action, final Material material, final short data) {
|
||||
final String blockPerm = "essentials.build." + action + "." + material;
|
||||
final String dataPerm = blockPerm + ":" + data;
|
||||
|
||||
if (user.getBase().isPermissionSet(dataPerm)) {
|
||||
|
@ -78,7 +78,7 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_placement, typeId) && !user.isAuthorized("essentials.protect.exemptplacement")) {
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_placement, type) && !user.isAuthorized("essentials.protect.exemptplacement")) {
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildPlace", type.toString()));
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_placement, typeId) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_placement, type) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
|
||||
prot.getEssentialsConnect().alert(user, type.toString(), tl("alertPlaced"));
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, typeId) && !user.isAuthorized("essentials.protect.exemptbreak")) {
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, type) && !user.isAuthorized("essentials.protect.exemptbreak")) {
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildBreak", type.toString()));
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_break, typeId) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_break, type) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
|
||||
prot.getEssentialsConnect().alert(user, type.toString(), tl("alertBroke"));
|
||||
}
|
||||
}
|
||||
|
@ -127,12 +127,12 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
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 (type == EntityType.PAINTING && !metaPermCheck(user, "break", Material.PAINTING)) {
|
||||
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())) {
|
||||
} else if (type == EntityType.ITEM_FRAME && !metaPermCheck(user, "break", Material.ITEM_FRAME)) {
|
||||
if (warn) {
|
||||
user.sendMessage(tl("antiBuildBreak", Material.ITEM_FRAME.toString()));
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
@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())) {
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getType())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
return;
|
||||
}
|
||||
final Block block = event.getBlock();
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId())) {
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
final User user = ess.getUser(event.getPlayer());
|
||||
final ItemStack item = event.getItem();
|
||||
|
||||
if (item != null && prot.checkProtectionItems(AntiBuildConfig.blacklist_usage, item.getTypeId()) && !user.isAuthorized("essentials.protect.exemptusage")) {
|
||||
if (item != null && prot.checkProtectionItems(AntiBuildConfig.blacklist_usage, item.getType()) && !user.isAuthorized("essentials.protect.exemptusage")) {
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildUse", item.getType().toString()));
|
||||
}
|
||||
|
@ -177,12 +177,12 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (item != null && prot.checkProtectionItems(AntiBuildConfig.alert_on_use, item.getTypeId()) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
|
||||
if (item != null && prot.checkProtectionItems(AntiBuildConfig.alert_on_use, item.getType()) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
|
||||
prot.getEssentialsConnect().alert(user, item.getType().toString(), tl("alertUsed"));
|
||||
}
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
|
||||
if (event.hasItem() && !metaPermCheck(user, "interact", item.getTypeId(), item.getDurability())) {
|
||||
if (event.hasItem() && !metaPermCheck(user, "interact", item.getType(), item.getDurability())) {
|
||||
event.setCancelled(true);
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildUse", item.getType().toString()));
|
||||
|
@ -207,7 +207,7 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
final ItemStack item = event.getRecipe().getResult();
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
|
||||
if (!metaPermCheck(user, "craft", item.getTypeId(), item.getDurability())) {
|
||||
if (!metaPermCheck(user, "craft", item.getType(), item.getDurability())) {
|
||||
event.setCancelled(true);
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
user.sendMessage(tl("antiBuildCraft", item.getType().toString()));
|
||||
|
@ -224,7 +224,7 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
final ItemStack item = event.getItem().getItemStack();
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
|
||||
if (!metaPermCheck(user, "pickup", item.getTypeId(), item.getDurability())) {
|
||||
if (!metaPermCheck(user, "pickup", item.getType(), item.getDurability())) {
|
||||
event.setCancelled(true);
|
||||
event.getItem().setPickupDelay(50);
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
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())) {
|
||||
if (!metaPermCheck(user, "drop", item.getType(), item.getDurability())) {
|
||||
event.setCancelled(true);
|
||||
user.getBase().updateInventory();
|
||||
if (ess.getSettings().warnOnBuildDisallow()) {
|
||||
|
@ -251,7 +251,7 @@ public class EssentialsAntiBuildListener implements Listener {
|
|||
@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())) {
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_dispenser, item.getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.earth2me.essentials.antibuild;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -7,7 +8,7 @@ import java.util.Map;
|
|||
|
||||
|
||||
public interface IAntiBuild extends Plugin {
|
||||
boolean checkProtectionItems(final AntiBuildConfig list, final int id);
|
||||
boolean checkProtectionItems(final AntiBuildConfig list, final Material mat);
|
||||
|
||||
boolean getSettingBool(final AntiBuildConfig protectConfig);
|
||||
|
||||
|
@ -15,5 +16,5 @@ public interface IAntiBuild extends Plugin {
|
|||
|
||||
Map<AntiBuildConfig, Boolean> getSettingsBoolean();
|
||||
|
||||
Map<AntiBuildConfig, List<Integer>> getSettingsList();
|
||||
Map<AntiBuildConfig, List<Material>> getSettingsList();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue