Skip to content

Commit

Permalink
improve banned-blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Feb 8, 2024
1 parent a124e16 commit 42a7590
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@ public class PreventPlacingBannedBlocks implements AnarchyExploitFixesModule, Li

public PreventPlacingBannedBlocks() {
shouldEnable();
this.bannedMaterial = AnarchyExploitFixes.getConfiguration().getList("illegals.ban-specific-blocks.banned-blocks", List.of(
"CHAIN_COMMAND_BLOCK", "COMMAND_BLOCK", "COMMAND_BLOCK_MINECART", "REPEATING_COMMAND_BLOCK",
"BEDROCK", "BARRIER", "STRUCTURE_BLOCK", "STRUCTURE_VOID", "END_PORTAL_FRAME", "END_PORTAL", "NETHER_PORTAL", "LIGHT"
)).stream()
this.bannedMaterial = AnarchyExploitFixes.getConfiguration()
.getList("illegals.ban-specific-blocks.banned-blocks", List.of(
"CHAIN_COMMAND_BLOCK",
"COMMAND_BLOCK",
"COMMAND_BLOCK_MINECART",
"REPEATING_COMMAND_BLOCK",
"BEDROCK",
"BARRIER",
"STRUCTURE_BLOCK",
"STRUCTURE_VOID",
"END_PORTAL_FRAME",
"END_PORTAL",
"NETHER_PORTAL",
"LIGHT"))
.stream()
.map(confMaterial -> {
try {
return Material.valueOf(confMaterial);
Expand Down Expand Up @@ -67,14 +78,8 @@ public void disable() {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onInteract(PlayerInteractEvent event) {
if (!bannedMaterial.contains(event.getMaterial())) return;

// This is a workaround because BlockPlaceEvent reports that players were placing end_portal_frames
// when they were actually just putting eyes into them.
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.END_PORTAL_FRAME) {
if (event.getItem() != null && event.getItem().getType() == Material.ENDER_EYE) return;
if (bannedMaterial.contains(event.getMaterial())) {
event.setCancelled(true);
}

event.setCancelled(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,33 @@
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class PreventPlacingBannedBlocks implements AnarchyExploitFixesModule, Listener {

private final Set<Material> bannedMaterial;
private final Material ENDER_EYE, END_PORTAL_FRAME;

public PreventPlacingBannedBlocks() {
shouldEnable();

// default list entries based on version
List<String> defaults;
if (AnarchyExploitFixes.getMCVersion() > 12) {
defaults = Arrays.asList(
"PLAYER_HEAD", "CHAIN_COMMAND_BLOCK", "COMMAND_BLOCK", "COMMAND_BLOCK_MINECART", "REPEATING_COMMAND_BLOCK",
"BEDROCK", "BARRIER", "STRUCTURE_BLOCK", "STRUCTURE_VOID", "END_PORTAL_FRAME", "END_PORTAL", "NETHER_PORTAL", "LIGHT"
);
} else {
defaults = Arrays.asList("BEDROCK", "BARRIER", "COMMAND", "STRUCTURE_BLOCK", "ENDER_PORTAL_FRAME");
}
List<String> defaults = Stream.of(
XMaterial.CHAIN_COMMAND_BLOCK,
XMaterial.COMMAND_BLOCK,
XMaterial.COMMAND_BLOCK_MINECART,
XMaterial.REPEATING_COMMAND_BLOCK,
XMaterial.BEDROCK,
XMaterial.BARRIER,
XMaterial.STRUCTURE_BLOCK,
XMaterial.STRUCTURE_VOID,
XMaterial.END_PORTAL_FRAME,
XMaterial.END_PORTAL,
XMaterial.NETHER_PORTAL,
XMaterial.LIGHT,
XMaterial.REINFORCED_DEEPSLATE)
.filter(XMaterial::isSupported)
.map(XMaterial::parseMaterial)
.map(Enum::name)
.collect(Collectors.toList());

this.bannedMaterial = AnarchyExploitFixes.getConfiguration().getList("illegals.ban-specific-blocks.banned-blocks", defaults)
.stream()
Expand All @@ -45,9 +53,6 @@ public PreventPlacingBannedBlocks() {
})
.filter(Objects::nonNull)
.collect(Collectors.toCollection(HashSet::new));

this.ENDER_EYE = XMaterial.ENDER_EYE.parseMaterial();
this.END_PORTAL_FRAME = XMaterial.END_PORTAL_FRAME.parseMaterial();
}

@Override
Expand All @@ -73,14 +78,8 @@ public boolean shouldEnable() {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onInteract(PlayerInteractEvent event) {
if (!bannedMaterial.contains(event.getMaterial())) return;

// This is a workaround because BlockPlaceEvent reports that players were placing end_portal_frames
// when they were actually just putting eyes into them.
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == END_PORTAL_FRAME) {
if (event.getItem() != null && event.getItem().getType() == ENDER_EYE) return;
if (bannedMaterial.contains(event.getMaterial())) {
event.setCancelled(true);
}

event.setCancelled(true);
}
}

0 comments on commit 42a7590

Please sign in to comment.