Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disable-general-commands to Bukkit config #2042

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions worldguard-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ configurations {

dependencies {
"api"(project(":worldguard-core"))
"compileOnly"("io.papermc.paper:paper-api:1.20-R0.1-SNAPSHOT")
"runtimeOnly"("org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT") {
"compileOnly"("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
"runtimeOnly"("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT") {
exclude("junit", "junit")
}
"api"("com.sk89q.worldedit:worldedit-bukkit:${Versions.WORLDEDIT}") { isTransitive = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public class BukkitConfigurationManager extends YamlConfigurationManager {

@Unreported private WorldGuardPlugin plugin;
@Unreported private ConcurrentMap<String, BukkitWorldConfiguration> worlds = new ConcurrentHashMap<>();

private boolean isFreshInstall;
private boolean hasCommandBookGodMode;
boolean disableGeneralCommands;
boolean extraStats;

/**
Expand All @@ -56,6 +57,8 @@ public Collection<BukkitWorldConfiguration> getWorldConfigs() {
public void load() {
super.load();
this.extraStats = getConfig().getBoolean("custom-metrics-charts", true);
// Disable legacy commands for fresh installs
this.disableGeneralCommands = getConfig().getBoolean("disable-general-commands", isFreshInstall);
}

@Override
Expand All @@ -66,7 +69,7 @@ public File getDataFolder() {
@Override
public void copyDefaults() {
// Create the default configuration file
plugin.createDefaultConfiguration(new File(plugin.getDataFolder(), "config.yml"), "config.yml");
isFreshInstall = plugin.createDefaultConfiguration(new File(plugin.getDataFolder(), "config.yml"), "config.yml");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void onEnable() {
reg.register(ToggleCommands.class);
reg.register(ProtectionCommands.class);

if (!platform.getGlobalStateManager().hasCommandBookGodMode()) {
if (!platform.getGlobalStateManager().disableGeneralCommands && !platform.getGlobalStateManager().hasCommandBookGodMode()) {
reg.register(GeneralCommands.class);
}

Expand Down Expand Up @@ -488,7 +488,7 @@ private void configureLogger() {
* @param actual The destination file
* @param defaultName The name of the file inside the jar's defaults folder
*/
public void createDefaultConfiguration(File actual, String defaultName) {
public boolean createDefaultConfiguration(File actual, String defaultName) {

// Make parent directories
File parent = actual.getParentFile();
Expand All @@ -497,7 +497,7 @@ public void createDefaultConfiguration(File actual, String defaultName) {
}

if (actual.exists()) {
return;
return false;
}

try (InputStream stream = getResource("defaults/" + defaultName)){
Expand All @@ -506,7 +506,7 @@ public void createDefaultConfiguration(File actual, String defaultName) {
} catch (IOException e) {
getLogger().severe("Unable to read default configuration: " + defaultName);
}

return true;
}

private void copyDefaultConfig(InputStream input, File actual, String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.sk89q.worldguard.config.WorldConfiguration;
import com.sk89q.worldguard.protection.flags.Flags;
import io.papermc.lib.PaperLib;
import io.papermc.paper.event.player.PlayerOpenSignEvent;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.GameMode;
Expand Down Expand Up @@ -1266,5 +1267,13 @@ private class PaperListener implements Listener {
public void onEntityTransform(EntityZapEvent event) {
Events.fireToCancel(event, new DamageEntityEvent(event, create(event.getBolt()), event.getEntity()));
}

@EventHandler(ignoreCancelled = true)
public void onSignOpen(PlayerOpenSignEvent event) {
if (event.getCause() == PlayerOpenSignEvent.Cause.INTERACT) {
// other cases are handled by other events
Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), event.getSign().getBlock()));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void registerEvents() {
}
}

@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerRespawn(PlayerRespawnEvent event) {
LocalPlayer player = getPlugin().wrapPlayer(event.getPlayer());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,8 @@ public static boolean isConsideredBuildingIfUsed(Material type) {
|| type == Material.DRAGON_EGG
|| Tag.FLOWER_POTS.isTagged(type)
|| Tag.CANDLES.isTagged(type)
|| Tag.CANDLE_CAKES.isTagged(type);
|| Tag.CANDLE_CAKES.isTagged(type)
|| Tag.ALL_SIGNS.isTagged(type);
}

/**
Expand Down