Skip to content

Commit

Permalink
1.26.1 - Prevent error from invalid config options
Browse files Browse the repository at this point in the history
  • Loading branch information
moom0o committed Jun 13, 2022
1 parent 98873c3 commit 04b969f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 18 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,16 @@ SpecificEnchantments: # If RevertSpecificEnchantments is enabled, only these spe
- "DIG_SPEED" # The name of the enchantment in the spigot api
ItemsSkipped: # Items that won't be reverted from illegal enchants or unbreakablity.
- "GOLDEN_APPLE" # Make sure to keep this line here or else enchanted golden apples will be reverted to normal ones.
DataValues:
RevertSpecificDataValues: true # Required for rest of config options
RevertIllegalGoldenApple: true #Revert golden apples that aren't 0 or 1.
SpecificDataValues: # If you want to ban any other data values
- "SuperIllegalItem(0)" # (1) is the data value. For example GOLDEN_APPLE uses (0) for unenchanted and (1) for enchanted.
RevertUnbreakables:
Enabled: true # Revert unbreakable items, items with less than 0 durability will be automatically removed or set to 0 durability, which will break on the next use. Items with higher than max durability will be set to legal maximum durability.
EnableWhitelist: false # If enabled, only items in the whitelist will be reverted.
Whitelist:
- "DIAMOND_CHESTPLATE" # The name of the item in the spigot api
SkipZeroDurability: true # Make sure to keep enabled, otherwise netherite tools will mistakenly be set to maximum durability, due to some bug in spigot.
# Only removes player heads, not mob heads
RemoveIllegalHeads: true
Expand Down Expand Up @@ -397,7 +405,10 @@ BANNED_BLOCKS: # SPIGOT ITEM NAMES!!! YOU WILL RECEIVE AN ERROR IF YOU DO NOT FO
- COMMAND
- STRUCTURE_BLOCK
- ENDER_PORTAL_FRAME # the issue where the plugin thinks a player has placed a end portal frame when activating the portal has been fixed.
DisableBannedBlocksWarnings: false # Disable warnings for some reason

BANNED_NAMES: # Remove items that were custom named to a specific string. Suggested by STORMIN.
- "Super Insane Mega Sussy Item" # case sensitive
OnlyRevertStacksForCertainItems: false
RevertStackedItemsList:
- TOTEM
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.moomoo</groupId>
<artifactId>anarchyexploitfixes</artifactId>
<version>1.26.0</version>
<version>1.26.1</version>
<packaging>jar</packaging>

<name>AnarchyExploitFixes</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/moomoo/anarchyexploitfixes/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.inventory.meta.SpawnEggMeta;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

Expand Down Expand Up @@ -292,6 +291,7 @@ public void revert(ItemStack item) {
if (getConfig().getStringList("BANNED_NAMES").contains(item.getI18NDisplayName()))
item.subtract(item.getAmount());
if (getConfig().getBoolean("DataValues.RevertSpecificDataValues")) {
getLogger().info(item.getType().name() + item.getType().getMaxDurability());
if (getConfig().getStringList("DataValues.SpecificDataValues").contains(item.getData().toString())) {
item.subtract(item.getAmount());
}
Expand Down
56 changes: 40 additions & 16 deletions src/main/java/me/moomoo/anarchyexploitfixes/patches/Illegals.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.bukkit.block.Container;
import org.bukkit.block.Skull;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
Expand All @@ -33,7 +35,13 @@ private void onPlayerInteractEvent(PlayerInteractEvent evt) {
if (evt.getClickedBlock().getState() instanceof Container) {
((Container) evt.getClickedBlock().getState()).getInventory().forEach(plugin::revert);

config.getStringList("BANNED_BLOCKS").forEach(b -> ((Container) evt.getClickedBlock().getState()).getInventory().remove(Material.getMaterial(b)));
config.getStringList("BANNED_BLOCKS").forEach(b -> {
if (Material.getMaterial(b) != null) {
((Container) evt.getClickedBlock().getState()).getInventory().remove(Material.getMaterial(b));
} else if (!plugin.getConfig().getBoolean("DisableBannedBlocksWarnings")) {
plugin.getLogger().warning("BANNED_BLOCKS '" + b + "' not recognized. Please change to correct value from https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html");
}
});
}
}
}
Expand All @@ -44,9 +52,7 @@ private void onPlayerJoinEvent(PlayerJoinEvent evt) {
FileConfiguration config = plugin.getConfig();

if (config.getBoolean("RemoveIllegalBlocksOnJoin")) {
config.getStringList("BANNED_BLOCKS").forEach(b -> evt.getPlayer().getInventory().remove(Material.getMaterial(b)));

evt.getPlayer().getInventory().forEach(plugin::revert);
getBannedBlocks(config, evt.getPlayer(), evt);
}
}

Expand All @@ -55,13 +61,23 @@ private void onInventoryOpenEvent(InventoryOpenEvent evt) {
FileConfiguration config = plugin.getConfig();

if (config.getBoolean("RemoveIllegalBlocksOnInventoryOpen")) {
config.getStringList("BANNED_BLOCKS").forEach(b -> evt.getPlayer().getInventory().remove(Material.getMaterial(b)));

evt.getPlayer().getInventory().forEach(plugin::revert);
getBannedBlocks(config, evt.getPlayer(), evt);
evt.getPlayer().getEnderChest().forEach(plugin::revert);
}
}

private void getBannedBlocks(FileConfiguration config, HumanEntity player, Event evt) {
config.getStringList("BANNED_BLOCKS").forEach(b -> {
if (Material.getMaterial(b) != null) {
player.getInventory().remove(Material.getMaterial(b));
} else if (!plugin.getConfig().getBoolean("DisableBannedBlocksWarnings")) {
plugin.getLogger().warning("BANNED_BLOCKS '" + b + "' not recognized. Please change to correct value from https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html");
}
});

player.getInventory().forEach(plugin::revert);
}

@EventHandler
private void onBlockDropItemEvent(PlayerDropItemEvent evt) {
FileConfiguration config = plugin.getConfig();
Expand Down Expand Up @@ -126,9 +142,13 @@ private void onInventoryInteractEvent(InventoryInteractEvent evt) {

if (config.getBoolean("RemoveIllegalBlocksOnInteract")) {
config.getStringList("BANNED_BLOCKS").forEach(b -> {
if (evt.getInventory().contains(Material.getMaterial(b))) {
evt.getInventory().remove(Material.getMaterial(b));
evt.setCancelled(true);
if (Material.getMaterial(b) != null) {
if (evt.getInventory().contains(Material.getMaterial(b))) {
evt.getInventory().remove(Material.getMaterial(b));
evt.setCancelled(true);
}
} else if (!plugin.getConfig().getBoolean("DisableBannedBlocksWarnings")) {
plugin.getLogger().warning("BANNED_BLOCKS '" + b + "' not recognized. Please change to correct value from https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html");
}
});

Expand Down Expand Up @@ -183,13 +203,17 @@ private void onBlockPlace(BlockPlaceEvent evt) {
if (config.getStringList("BANNED_BLOCKS").contains(block)) {
if (config.getBoolean("RemoveIllegalBlockOnPlace")) {
config.getStringList("BANNED_BLOCKS").forEach(b -> {
if (evt.getPlayer().getInventory().contains(Material.getMaterial(b))) {
if (Material.getMaterial(b).equals(Material.ENDER_PORTAL_FRAME) && evt.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.EYE_OF_ENDER)) {
evt.getPlayer().getInventory().remove(Material.getMaterial(b));
} else {
evt.getPlayer().getInventory().remove(Material.getMaterial(b));
evt.setCancelled(true);
if (Material.getMaterial(b) != null) {
if (evt.getPlayer().getInventory().contains(Material.getMaterial(b))) {
if (Material.getMaterial(b).equals(Material.ENDER_PORTAL_FRAME) && evt.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.EYE_OF_ENDER)) {
evt.getPlayer().getInventory().remove(Material.getMaterial(b));
} else {
evt.getPlayer().getInventory().remove(Material.getMaterial(b));
evt.setCancelled(true);
}
}
} else if (!plugin.getConfig().getBoolean("DisableBannedBlocksWarnings")) {
plugin.getLogger().warning("BANNED_BLOCKS '" + b + "' not recognized. Please change to correct value from https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html");
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ BANNED_BLOCKS: # SPIGOT ITEM NAMES!!! YOU WILL RECEIVE AN ERROR IF YOU DO NOT FO
- COMMAND
- STRUCTURE_BLOCK
- ENDER_PORTAL_FRAME # the issue where the plugin thinks a player has placed a end portal frame when activating the portal has been fixed.
DisableBannedBlocksWarnings: false # Disable warnings for some reason

BANNED_NAMES: # Remove items that were custom named to a specific string. Suggested by STORMIN.
- "Super Insane Mega Sussy Item" # case sensitive
Expand Down

0 comments on commit 04b969f

Please sign in to comment.