-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expand carpet-dupe to blockentitydupe and make configurable
- Loading branch information
Showing
5 changed files
with
214 additions
and
145 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
...xploitFixesFolia/src/main/java/me/xginko/aef/modules/dupepreventions/BlockEntityDupe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package me.xginko.aef.modules.dupepreventions; | ||
|
||
import com.cryptomorin.xseries.XMaterial; | ||
import me.xginko.aef.modules.AEFModule; | ||
import me.xginko.aef.utils.MaterialUtil; | ||
import org.bukkit.Material; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.block.BlockPistonEvent; | ||
import org.bukkit.event.block.BlockPistonExtendEvent; | ||
import org.bukkit.event.block.BlockPistonRetractEvent; | ||
|
||
import java.util.Collections; | ||
import java.util.EnumMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class BlockEntityDupe extends AEFModule implements Listener { | ||
|
||
private final Map<Material, Boolean> materials = new EnumMap<>(Material.class); | ||
|
||
private Set<Block> removalList; | ||
|
||
public BlockEntityDupe() { | ||
super("dupe-preventions.block-entity-dupe", false, """ | ||
Will prevent Pistons that are pusing carpets/rails/tnt from working. | ||
This isn't recommended to be used for turning everything off. | ||
Use papers settings for that. | ||
This is intended for admins that want to allow specific dupes only."""); | ||
|
||
if (config.getBoolean(configPath + ".carpets.prevent", true)) { | ||
boolean remove = config.getBoolean(configPath + ".carpets.delete", true); | ||
for (Material material : MaterialUtil.CARPETS) { | ||
materials.put(material, remove); | ||
} | ||
} | ||
|
||
if (config.getBoolean(configPath + ".rails.prevent", true)) { | ||
boolean remove = config.getBoolean(configPath + ".rails.delete", true); | ||
for (Material material : MaterialUtil.RAILS) { | ||
materials.put(material, remove); | ||
} | ||
} | ||
|
||
if (config.getBoolean(configPath + ".tnt.prevent", false)) { | ||
materials.put(XMaterial.TNT.get(), config.getBoolean(configPath + ".tnt.delete", true)); | ||
} | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
removalList = Collections.newSetFromMap(new ConcurrentHashMap<>()); | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
HandlerList.unregisterAll(this); | ||
if (removalList != null) { | ||
setBlocksToAir(); | ||
removalList.clear(); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onPistonExtend(BlockPistonExtendEvent event) { | ||
onPistonEvent(event, event.getBlocks()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onPistonRetract(BlockPistonRetractEvent event) { | ||
onPistonEvent(event, event.getBlocks()); | ||
} | ||
|
||
private void onPistonEvent(BlockPistonEvent event, List<Block> affectedBlocks) { | ||
if (affectedBlocks.isEmpty()) return; | ||
|
||
for (Block block : affectedBlocks) { | ||
if (materials.containsKey(block.getType())) { | ||
event.setCancelled(true); | ||
if (materials.get(block.getType())) { | ||
removalList.add(block); | ||
} | ||
} | ||
} | ||
|
||
setBlocksToAir(); | ||
} | ||
|
||
private void setBlocksToAir() { | ||
if (removalList.isEmpty()) return; | ||
|
||
for (Block block : removalList) { | ||
plugin.getServer().getRegionScheduler() | ||
.execute(plugin, block.getLocation(), () -> block.setType(XMaterial.AIR.get(), false)); | ||
removalList.remove(block); | ||
} | ||
} | ||
} |
72 changes: 0 additions & 72 deletions
72
AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/dupepreventions/CarpetDupe.java
This file was deleted.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
...ploitFixesLegacy/src/main/java/me/xginko/aef/modules/dupepreventions/BlockEntityDupe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package me.xginko.aef.modules.dupepreventions; | ||
|
||
import com.cryptomorin.xseries.XMaterial; | ||
import me.xginko.aef.modules.AEFModule; | ||
import me.xginko.aef.utils.MaterialUtil; | ||
import org.bukkit.Material; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.block.BlockPistonEvent; | ||
import org.bukkit.event.block.BlockPistonExtendEvent; | ||
import org.bukkit.event.block.BlockPistonRetractEvent; | ||
|
||
import java.util.Collections; | ||
import java.util.EnumMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class BlockEntityDupe extends AEFModule implements Listener { | ||
|
||
private final Map<Material, Boolean> materials = new EnumMap<>(Material.class); | ||
|
||
private Set<Block> removalList; | ||
|
||
public BlockEntityDupe() { | ||
super("dupe-preventions.block-entity-dupe", false, | ||
"Will prevent Pistons that are pusing carpets/rails/tnt from working.\n" + | ||
"This isn't recommended to be used for turning everything off.\n" + | ||
"Use papers settings for that.\n" + | ||
"This is intended for admins that want to allow specific dupes only."); | ||
|
||
if (config.getBoolean(configPath + ".carpets.prevent", true)) { | ||
boolean remove = config.getBoolean(configPath + ".carpets.delete", true); | ||
for (Material material : MaterialUtil.CARPETS) { | ||
materials.put(material, remove); | ||
} | ||
} | ||
|
||
if (config.getBoolean(configPath + ".rails.prevent", true)) { | ||
boolean remove = config.getBoolean(configPath + ".rails.delete", true); | ||
for (Material material : MaterialUtil.RAILS) { | ||
materials.put(material, remove); | ||
} | ||
} | ||
|
||
if (config.getBoolean(configPath + ".tnt.prevent", false)) { | ||
materials.put(XMaterial.TNT.get(), config.getBoolean(configPath + ".tnt.delete", true)); | ||
} | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
removalList = Collections.newSetFromMap(new ConcurrentHashMap<>()); | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
HandlerList.unregisterAll(this); | ||
if (removalList != null) { | ||
setBlocksToAir(); | ||
removalList.clear(); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onPistonExtend(BlockPistonExtendEvent event) { | ||
onPistonEvent(event, event.getBlocks()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onPistonRetract(BlockPistonRetractEvent event) { | ||
onPistonEvent(event, event.getBlocks()); | ||
} | ||
|
||
private void onPistonEvent(BlockPistonEvent event, List<Block> affectedBlocks) { | ||
if (affectedBlocks.isEmpty()) return; | ||
|
||
for (Block block : affectedBlocks) { | ||
if (materials.containsKey(block.getType())) { | ||
event.setCancelled(true); | ||
if (materials.get(block.getType())) { | ||
removalList.add(block); | ||
} | ||
} | ||
} | ||
|
||
setBlocksToAir(); | ||
} | ||
|
||
private void setBlocksToAir() { | ||
if (removalList.isEmpty()) return; | ||
|
||
plugin.getServer().getScheduler().runTaskLater(plugin, () -> { | ||
for (Block block : removalList) { | ||
block.setType(XMaterial.AIR.get(), false); | ||
removalList.remove(block); | ||
} | ||
}, 1L); | ||
} | ||
} |
73 changes: 0 additions & 73 deletions
73
...chyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/dupepreventions/CarpetDupe.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters