Skip to content

Commit

Permalink
11.0.0.0: Add option for specific block interaction list in Cheat Pre…
Browse files Browse the repository at this point in the history
…vention.

Closes SirBlobman#306
  • Loading branch information
SirBlobman committed Nov 11, 2021
1 parent 3ebaee9 commit 413f5a0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,38 @@ public void onInteract(PlayerInteractEvent e) {
if(action != Action.RIGHT_CLICK_BLOCK && action != Action.LEFT_CLICK_BLOCK) {
return;
}

Block block = e.getClickedBlock();
if(block == null) {
return;
}

Player player = e.getPlayer();
if(isInCombat(player) && shouldPreventInteraction()) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.blocks.prevent-interaction", null);
if(!isInCombat(player)) {
return;
}

Material material = block.getType();
if(canInteract(material)) {
return;
}

e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.blocks.prevent-interaction", null);
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBreak(BlockBreakEvent e) {
Player player = e.getPlayer();
if(!isInCombat(player)) return;
if(!isInCombat(player)) {
return;
}

Block block = e.getBlock();
Material material = block.getType();
if(canBreak(material)) return;
if(canBreak(material)) {
return;
}

e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.blocks.prevent-breaking", null);
Expand All @@ -52,11 +68,15 @@ public void onBreak(BlockBreakEvent e) {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlace(BlockPlaceEvent e) {
Player player = e.getPlayer();
if(!isInCombat(player)) return;
if(!isInCombat(player)) {
return;
}

Block block = e.getBlock();
Material material = block.getType();
if(canPlace(material)) return;
if(canPlace(material)) {
return;
}

e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.blocks.prevent-placing", null);
Expand All @@ -69,7 +89,9 @@ private YamlConfiguration getConfiguration() {

private boolean canBreak(Material material) {
YamlConfiguration configuration = getConfiguration();
if(!configuration.getBoolean("prevent-breaking")) return true;
if(!configuration.getBoolean("prevent-breaking")) {
return true;
}

String materialName = material.name();
List<String> noBreakList = configuration.getStringList("prevent-breaking-list");
Expand All @@ -78,15 +100,23 @@ private boolean canBreak(Material material) {

private boolean canPlace(Material material) {
YamlConfiguration configuration = getConfiguration();
if(!configuration.getBoolean("prevent-placing")) return true;
if(!configuration.getBoolean("prevent-placing")) {
return true;
}

String materialName = material.name();
List<String> noBreakList = configuration.getStringList("prevent-placing-list");
return (!noBreakList.contains("*") && !noBreakList.contains(materialName));
}

private boolean shouldPreventInteraction() {
private boolean canInteract(Material material) {
YamlConfiguration configuration = getConfiguration();
return configuration.getBoolean("prevent-interaction", false);
if(!configuration.getBoolean("prevent-interaction")) {
return true;
}

String materialName = material.name();
List<String> noInteractList = configuration.getStringList("prevent-interaction-list");
return (!noInteractList.contains("*") && !noInteractList.contains(materialName));
}
}
14 changes: 10 additions & 4 deletions expansion/cheat-prevention/expansion/src/main/resources/blocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@
# Default: false
prevent-interaction: false

# This is a list of blocks that players should not interact with during combat.
# Spigot Material List: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
# This defaults to prevent all block interactions.
prevent-interaction-list:
- "*"

# Should players be prevented from breaking blocks during combat?
# Default: true
prevent-breaking: true

# Should players be prevented from placing blocks during combat?
# Default: true
prevent-placing: true

# This is a list of blocks that should be prevented from breaking
# Spigot Material List: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
# This defaults to prevent all block breaking
prevent-breaking-list:
- "*"

# Should players be prevented from placing blocks during combat?
# Default: true
prevent-placing: true

# This is a list of blocks that should be prevented from placing
# Spigot Material List: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
# This defaults to prevent all block placing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ prefix: "Cheat Prevention"
description: "${project.description}"

main: "combatlogx.expansion.cheat.prevention.CheatPreventionExpansion"
version: "16.5"
version: "16.6"
author: "SirBlobman"

0 comments on commit 413f5a0

Please sign in to comment.