-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/dupepreventions/CarpetDupe.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,72 @@ | ||
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.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.ArrayList; | ||
import java.util.List; | ||
|
||
public class CarpetDupe extends AEFModule implements Listener { | ||
|
||
private final boolean deleteCarpet; | ||
|
||
public CarpetDupe() { | ||
super("dupe-preventions.carpet-dupe", false, | ||
"Will prevent Pistons that are pusing carpets from working."); | ||
this.deleteCarpet = config.getBoolean(configPath + ".delete-carpet", true); | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
HandlerList.unregisterAll(this); | ||
} | ||
|
||
@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; | ||
|
||
List<Block> carpets = new ArrayList<>(8); | ||
|
||
for (Block block : affectedBlocks) { | ||
if (MaterialUtil.CARPETS.contains(block.getType())) { | ||
carpets.add(block); | ||
} | ||
} | ||
|
||
if (carpets.isEmpty()) { | ||
return; | ||
} | ||
|
||
event.setCancelled(true); | ||
|
||
if (deleteCarpet) { | ||
for (Block block : carpets) { | ||
plugin.getServer().getGlobalRegionScheduler() | ||
.execute(plugin, () -> block.setType(XMaterial.AIR.get(), false)); | ||
} | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...chyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/dupepreventions/CarpetDupe.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,73 @@ | ||
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.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.ArrayList; | ||
import java.util.List; | ||
|
||
public class CarpetDupe extends AEFModule implements Listener { | ||
|
||
private final boolean deleteCarpet; | ||
|
||
public CarpetDupe() { | ||
super("dupe-preventions.carpet-dupe", false, | ||
"Will prevent Pistons that are pusing carpets from working."); | ||
this.deleteCarpet = config.getBoolean(configPath + ".delete-carpet", true); | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
HandlerList.unregisterAll(this); | ||
} | ||
|
||
@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; | ||
|
||
List<Block> carpets = new ArrayList<>(8); | ||
|
||
for (Block block : affectedBlocks) { | ||
if (MaterialUtil.CARPETS.contains(block.getType())) { | ||
carpets.add(block); | ||
} | ||
} | ||
|
||
if (carpets.isEmpty()) { | ||
return; | ||
} | ||
|
||
event.setCancelled(true); | ||
|
||
if (deleteCarpet) { | ||
plugin.getServer().getScheduler().runTaskLater(plugin, () -> { | ||
for (Block block : carpets) { | ||
block.setType(XMaterial.AIR.get(), false); | ||
} | ||
}, 1L); | ||
} | ||
} | ||
} |
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