Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions src/main/java/dev/twme/debugstickpro/DebugStickPro.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
package dev.twme.debugstickpro;

import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;

import com.github.retrooper.packetevents.PacketEvents;

import dev.twme.debugstickpro.blockdatautil.BlockDataSeparater;
import dev.twme.debugstickpro.commands.MainCommand;
import dev.twme.debugstickpro.commands.MainCommandTabComplete;
Expand All @@ -9,7 +19,22 @@
import dev.twme.debugstickpro.display.ActionBarDisplayTask;
import dev.twme.debugstickpro.hook.CoreProtectUtil;
import dev.twme.debugstickpro.hook.PlaceholderAPIUtil;
import dev.twme.debugstickpro.listeners.*;
import dev.twme.debugstickpro.listeners.BlockBreakEventListener;
import dev.twme.debugstickpro.listeners.BlockPlaceEventListenerCanBuildChecker;
import dev.twme.debugstickpro.listeners.ChunkLoadEventListener;
import dev.twme.debugstickpro.listeners.ChunkUnloadEventListener;
import dev.twme.debugstickpro.listeners.FreezeBlockIsolationListener;
import dev.twme.debugstickpro.listeners.LeftClickListener;
import dev.twme.debugstickpro.listeners.PlayerChangeDebugStickModeEventListener;
import dev.twme.debugstickpro.listeners.PlayerChangedWorldEventListener;
import dev.twme.debugstickpro.listeners.PlayerDropItemListener;
import dev.twme.debugstickpro.listeners.PlayerItemHeldListener;
import dev.twme.debugstickpro.listeners.PlayerJoinListener;
import dev.twme.debugstickpro.listeners.PlayerLocaleChangeEventListener;
import dev.twme.debugstickpro.listeners.PlayerQuitListener;
import dev.twme.debugstickpro.listeners.PlayerSwapHandItemsEventListener;
import dev.twme.debugstickpro.listeners.RightClickListener;
import dev.twme.debugstickpro.listeners.WorldUnloadEventListener;
import dev.twme.debugstickpro.localization.LangFileManager;
import dev.twme.debugstickpro.localization.PlayerLanguageManager;
import dev.twme.debugstickpro.mode.freeze.FreezeBlockManager;
Expand All @@ -22,14 +47,6 @@
import me.tofaa.entitylib.APIConfig;
import me.tofaa.entitylib.EntityLib;
import me.tofaa.entitylib.spigot.SpigotEntityLibPlatform;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;

import java.util.UUID;

public final class DebugStickPro extends JavaPlugin {
/**
Expand All @@ -46,7 +63,7 @@ public final class DebugStickPro extends JavaPlugin {
/**
* This is the version of the plugin
*/
public static final int CONFIG_VERSION = 6;
public static final int CONFIG_VERSION = 7;

/**
* This is the version of the language file
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/dev/twme/debugstickpro/config/ConfigFile.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package dev.twme.debugstickpro.config;

import net.kyori.adventure.text.Component;
import org.bukkit.Material;

import java.util.ArrayList;
import java.util.HashSet;

import org.bukkit.Material;

import net.kyori.adventure.text.Component;

public class ConfigFile {

public static int ConfigVersion;
Expand Down Expand Up @@ -49,6 +50,18 @@ public static class AutoRegionProtection {
public static boolean Enabled;
}

public static class BlockFilter {
public static class Whitelist {
public static boolean Enabled;
public static HashSet<String> Blocks;
}

public static class Blacklist {
public static boolean Enabled;
public static HashSet<String> Blocks;
}
}

public static class BlockDataFilter {
public static class Whitelist {
public static boolean Enabled;
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/dev/twme/debugstickpro/config/ConfigLoader.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package dev.twme.debugstickpro.config;

import dev.twme.debugstickpro.DebugStickPro;
import dev.twme.debugstickpro.utils.Log;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;

import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;

import dev.twme.debugstickpro.DebugStickPro;
import dev.twme.debugstickpro.utils.Log;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;

public class ConfigLoader {
private final static ConfigLoader instance = new ConfigLoader();
private File file;
Expand Down Expand Up @@ -96,6 +97,11 @@ private void loadValues() {

ConfigFile.AutoRegionProtection.Enabled = config.getBoolean("AutoRegionProtection.Enabled");

ConfigFile.BlockFilter.Whitelist.Enabled = config.getBoolean("BlockFilter.Whitelist.Enabled");
ConfigFile.BlockFilter.Whitelist.Blocks = new HashSet<>(config.getStringList("BlockFilter.Whitelist.Blocks"));
ConfigFile.BlockFilter.Blacklist.Enabled = config.getBoolean("BlockFilter.Blacklist.Enabled");
ConfigFile.BlockFilter.Blacklist.Blocks = new HashSet<>(config.getStringList("BlockFilter.Blacklist.Blocks"));

ConfigFile.BlockDataFilter.Whitelist.Enabled = config.getBoolean("BlockDataFilter.Whitelist.Enabled");
ConfigFile.BlockDataFilter.Whitelist.Whitelist = new HashSet<>(config.getStringList("BlockDataFilter.Whitelist.Whitelist"));
ConfigFile.BlockDataFilter.Blacklist.Enabled = config.getBoolean("BlockDataFilter.Blacklist.Enabled");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package dev.twme.debugstickpro.mode.classic;

import dev.twme.debugstickpro.blockdatautil.BlockDataSeparater;
import dev.twme.debugstickpro.blockdatautil.SubBlockData;
import dev.twme.debugstickpro.playerdata.PlayerData;
import java.util.ArrayList;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.UUID;
import dev.twme.debugstickpro.blockdatautil.BlockDataSeparater;
import dev.twme.debugstickpro.blockdatautil.SubBlockData;
import dev.twme.debugstickpro.playerdata.PlayerData;
import dev.twme.debugstickpro.utils.BlockFilterUtil;

public class ClassicLeftClick {

Expand All @@ -24,6 +26,10 @@ public static void changeSelectedSubBlockType(UUID playerUUID, PlayerData player
return;
}

if (!BlockFilterUtil.isAllowed(player, block)) {
return;
}

ArrayList<SubBlockData> subBlockDataList = BlockDataSeparater.separate(block, playerUUID);

if (subBlockDataList.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package dev.twme.debugstickpro.mode.copy;

import dev.twme.debugstickpro.blockdatautil.BlockDataSeparater;
import dev.twme.debugstickpro.blockdatautil.SubBlockData;
import dev.twme.debugstickpro.events.CopyModeCopyBlockDataEvent;
import dev.twme.debugstickpro.playerdata.PlayerData;
import dev.twme.debugstickpro.playerdata.PlayerDataManager;
import dev.twme.debugstickpro.utils.AutoCheckCanChangeUtil;
import java.util.ArrayList;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Skull;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.UUID;
import dev.twme.debugstickpro.blockdatautil.BlockDataSeparater;
import dev.twme.debugstickpro.blockdatautil.SubBlockData;
import dev.twme.debugstickpro.events.CopyModeCopyBlockDataEvent;
import dev.twme.debugstickpro.playerdata.PlayerData;
import dev.twme.debugstickpro.playerdata.PlayerDataManager;
import dev.twme.debugstickpro.utils.AutoCheckCanChangeUtil;

public class CopyLeftClick {
public static void onLeftClick(UUID playerUUID, PlayerData playerData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dev.twme.debugstickpro.utils;

import dev.twme.debugstickpro.config.ConfigFile;
import dev.twme.debugstickpro.listeners.BlockPlaceEventListenerCanBuildChecker;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

import java.util.UUID;
import dev.twme.debugstickpro.config.ConfigFile;
import dev.twme.debugstickpro.listeners.BlockPlaceEventListenerCanBuildChecker;

public final class AutoCheckCanChangeUtil {
/**
Expand All @@ -19,12 +20,12 @@ public final class AutoCheckCanChangeUtil {
*/
public static boolean canChange(UUID playerUUID, Block block) {
Player player = Bukkit.getPlayer(playerUUID);
World world = block.getWorld();

if (player.hasPermission("debugstickpro.bypassregion")) {
return true;
if (player == null) {
return false;
}

World world = block.getWorld();

boolean canChange = true;

if (ConfigFile.WhitelistWorlds.Enabled) {
Expand All @@ -43,14 +44,16 @@ public static boolean canChange(UUID playerUUID, Block block) {
}
}

if (ConfigFile.AutoRegionProtection.Enabled) {
if (canChange) {
if (!BlockPlaceEventListenerCanBuildChecker.canBuild(block, playerUUID)) {
canChange = false;
}
if (ConfigFile.AutoRegionProtection.Enabled && canChange && !player.hasPermission("debugstickpro.bypassregion")) {
if (!BlockPlaceEventListenerCanBuildChecker.canBuild(block, playerUUID)) {
canChange = false;
}
}

if (canChange && !BlockFilterUtil.isAllowed(player, block)) {
canChange = false;
}

return canChange;
}
}
54 changes: 54 additions & 0 deletions src/main/java/dev/twme/debugstickpro/utils/BlockFilterUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dev.twme.debugstickpro.utils;

import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

import dev.twme.debugstickpro.config.ConfigFile;

public final class BlockFilterUtil {

/**
* Check if the block is allowed by the BlockFilter settings.
*
* @param player the player to check
* @param block the block to check
* @return true if the block is allowed, false if it is filtered out
*/
public static boolean isAllowed(Player player, Block block) {
if (player == null) {
return false;
}

// Bypass permission applies to both whitelist and blacklist.
if (player.hasPermission("debugstickpro.bypassblockfilter")) {
return true;
}

String materialName = block.getType().name();

// Whitelist check
if (ConfigFile.BlockFilter.Whitelist.Enabled) {
boolean inWhitelist = ConfigFile.BlockFilter.Whitelist.Blocks.contains("*")
|| ConfigFile.BlockFilter.Whitelist.Blocks.contains(materialName);
if (!inWhitelist) {
return false;
}
}

// Blacklist check (takes precedence)
if (ConfigFile.BlockFilter.Blacklist.Enabled) {
if (ConfigFile.BlockFilter.Blacklist.Blocks.contains(materialName)) {
return false;
}
}

return true;
}

public static boolean isAllowed(UUID playerUUID, Block block) {
return isAllowed(Bukkit.getPlayer(playerUUID), block);
}
}
19 changes: 18 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Don't touch this value
ConfigVersion: 6
ConfigVersion: 7

Language:
# Language files are located in the "lang" folder.
Expand Down Expand Up @@ -86,6 +86,23 @@ BlockDataFilter:
- "AgeableData"
- "WaterloggedData"

BlockFilter:
# Permission bypass for both whitelist and blacklist: debugstickpro.bypassblockfilter
Whitelist:
# If enabled, the debug stick will only work on the specified blocks.
Enabled: false
# Options to fill: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
Blocks:
- "*"
Blacklist:
# If enabled, the debug stick will not work on the specified blocks.
# This option takes precedence over the whitelist.
Enabled: false
Comment thread
TWME-TW marked this conversation as resolved.
# Options to fill: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
Blocks:
- "BEDROCK"
- "BARRIER"

ModeSetting:
ClassicMode:
# If enabled, when switching modes, the selected BlockData type will be cleared.
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ permissions:
default: op
# Per-type bypass pattern:
# debugstickpro.bypassblacklist.<subblockdatatype-lowercase>
debugstickpro.bypassblockfilter:
description: Allows bypassing the BlockFilter whitelist and blacklist
default: op
debugstickpro.basic:
description: Allows basic usage of the DebugStickPro
default: op
Expand All @@ -77,3 +80,4 @@ permissions:
- debugstickpro.reload
- debugstickpro.bypassregion
- debugstickpro.bypassblacklist
- debugstickpro.bypassblockfilter
Loading