Skip to content

Commit

Permalink
prevent block breaking option (#523)
Browse files Browse the repository at this point in the history
* prevent block breaking option

* prevent block breaking option
  • Loading branch information
minecrafter197 authored Aug 14, 2024
1 parent 5679c73 commit 2fdbe0d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
Expand Down Expand Up @@ -70,6 +71,18 @@ public final void onBlockPlace(final BlockPlaceEvent event) {
}
}

@EventHandler(ignoreCancelled = true)
public final void onBlockBreak(final BlockBreakEvent event) {
if (!Settings.isBlockBreakBlocks() && !Settings.isBlockBreakBlocksNewbie())
return;

final PvPlayer combatPlayer = ph.get(event.getPlayer());
if (Settings.isBlockBreakBlocks() && combatPlayer.isInCombat() || Settings.isBlockBreakBlocksNewbie() && combatPlayer.isNewbie()) {
event.setCancelled(true);
combatPlayer.sendActionBar(Messages.getBlockBreakBlockedInCombat(), 1000);
}
}

@EventHandler(ignoreCancelled = true)
public final void onToggleFlight(final PlayerToggleFlightEvent event) {
if (Settings.isDisableFly() && event.isFlying() && ph.get(event.getPlayer()).isInCombat()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class Messages {
private static String pvpForceEnabledWG;
private static String teleportBlockedInCombat;
private static String blockPlaceBlockedInCombat;
private static String blockBreakBlockedInCombat;
private static String eatBlockedInCombat;
private static String interactBlockedInCombat;
private static String newbiePickupItemBlocked;
Expand Down Expand Up @@ -189,6 +190,7 @@ private static void getMessages() {
newbiePickupItemBlocked = getString("Newbie_Pickup_Items_Blocked");
newbieForceRemovedWG = getString("Newbie_Force_Removed_WorldGuard");
blockPlaceBlockedInCombat = getString("Block_Place_Blocked_InCombat");
blockBreakBlockedInCombat = getString("Block_Break_Blocked_InCombat");
eatBlockedInCombat = getString("Eating_Blocked_InCombat");
enderpearlBlockedIncombat = getString("EnderPearl_Blocked_InCombat");
chorusBlockedInCombat = getString("ChorusFruit_Blocked_InCombat");
Expand Down Expand Up @@ -528,6 +530,10 @@ public static String getBlockPlaceBlockedInCombat() {
return blockPlaceBlockedInCombat;
}

public static String getBlockBreakBlockedInCombat() {
return blockBreakBlockedInCombat;
}

public static String getEatBlockedInCombat() {
return eatBlockedInCombat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public enum DropMode {
private static boolean blockPickNewbies;
private static boolean blockPlaceBlocksNewbie;
private static boolean blockPlaceBlocks;
private static boolean blockBreakBlocksNewbie;
private static boolean blockBreakBlocks;
private static boolean blockGlideInCombat;
private static boolean blockEat;
private static boolean blockTotemUndying;
Expand Down Expand Up @@ -205,6 +207,7 @@ public static void initizalizeVariables(final YamlConfiguration c) {
blockChorusFruit = TAGGEDCOMBAT.getBoolean("Block.ChorusFruits", true);
blockTeleport = TAGGEDCOMBAT.getBoolean("Block.Teleport", true);
blockPlaceBlocks = TAGGEDCOMBAT.getBoolean("Block.Place Blocks", false);
blockBreakBlocks = TAGGEDCOMBAT.getBoolean("Block.Break Blocks", false);
blockInteractInCombat = TAGGEDCOMBAT.getBoolean("Block.Interact.Enabled", false);
blockInteractItemList = TAGGEDCOMBAT.getStringList("Block.Interact.List");
blockGlideInCombat = TAGGEDCOMBAT.getBoolean("Block.Elytra", false);
Expand All @@ -230,6 +233,7 @@ public static void initizalizeVariables(final YamlConfiguration c) {
newbieAllowDisable = NEWBIEPROTECTION.getBoolean("Allow Player Disable", true);
blockPickNewbies = NEWBIEPROTECTION.getBoolean("Block Pick Items", false);
blockPlaceBlocksNewbie = NEWBIEPROTECTION.getBoolean("Block Place Blocks", false);
blockBreakBlocksNewbie = NEWBIEPROTECTION.getBoolean("Block Break Blocks", false);
newbieGodMode = NEWBIEPROTECTION.getBoolean("Protect From Everything", false);
newbieBlacklist = getList(NEWBIEPROTECTION.getStringList("Command Blacklist"));

Expand Down Expand Up @@ -447,10 +451,18 @@ public static boolean isBlockPlaceBlocksNewbie() {
return blockPlaceBlocksNewbie;
}

public static boolean isBlockBreakBlocksNewbie() {
return blockBreakBlocksNewbie;
}

public static boolean isBlockPlaceBlocks() {
return blockPlaceBlocks;
}

public static boolean isBlockBreakBlocks() {
return blockBreakBlocks;
}

public static boolean isBlockGlide() {
return blockGlideInCombat;
}
Expand Down
2 changes: 2 additions & 0 deletions pvpmanager/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Tagged In Combat:
ChorusFruits: false
Teleport: true
Place Blocks: false
Break Blocks: false
Interact:
Enabled: false
# List of materials to block interaction, adding DOOR means all materials that end with DOOR like IRON_DOOR and so on
Expand Down Expand Up @@ -161,6 +162,7 @@ Newbie Protection:
# Block players from picking up items or place blocks while they have protection
Block Pick Items: false
Block Place Blocks: false
Block Break Blocks: false
# Protect newbies from all types of damage including PvE
Protect From Everything: false
Command Blacklist:
Expand Down
1 change: 1 addition & 0 deletions pvpmanager/src/main/resources/locale/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Out_Of_Combat = &6[&8PvPManager&6] &aYou are no longer in combat.
Out_Of_Combat_ActionBar = &aYou are no longer in combat
Command_Denied_InCombat = &6[&8PvPManager&6] &cCommand denied! You are still in combat!
Block_Place_Blocked_InCombat = &6[&8PvPManager&6] &4You can't place blocks while in combat!
Block_Break_Blocked_InCombat = &6[&8PvPManager&6] &4You can't break blocks while in combat!
Eating_Blocked_InCombat = &6[&8PvPManager&6] &4Eating is blocked while in combat!
EnderPearl_Blocked_InCombat = &6[&8PvPManager&6] &4You can't use enderpearls while in combat!
ChorusFruit_Blocked_InCombat = "&6[&8PvPManager&6] &4You can't eat chorus fruits while in combat!
Expand Down

0 comments on commit 2fdbe0d

Please sign in to comment.