Skip to content

Commit

Permalink
Implement whitelist-world-regex and blacklist-world-regex config options
Browse files Browse the repository at this point in the history
  • Loading branch information
Moulberry committed Nov 7, 2023
1 parent a76aaba commit eb1a1cd
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 19 deletions.
17 changes: 17 additions & 0 deletions src/main/java/com/moulberry/axiom/AxiomPaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.moulberry.axiom.buffer.CompressedBlockEntity;
import com.moulberry.axiom.event.AxiomCreateWorldPropertiesEvent;
import com.moulberry.axiom.event.AxiomModifyWorldEvent;
import com.moulberry.axiom.packet.*;
import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry;
import com.moulberry.axiom.world_properties.server.ServerWorldProperty;
Expand Down Expand Up @@ -175,6 +176,22 @@ public boolean canUseAxiom(Player player) {
}
}

public boolean canModifyWorld(Player player, World world) {
String whitelist = this.configuration.getString("whitelist-world-regex");
if (whitelist != null && !world.getName().matches(whitelist)) {
return false;
}

String blacklist = this.configuration.getString("blacklist-world-regex");
if (blacklist != null && world.getName().matches(blacklist)) {
return false;
}

AxiomModifyWorldEvent modifyWorldEvent = new AxiomModifyWorldEvent(player, world);
Bukkit.getPluginManager().callEvent(modifyWorldEvent);
return !modifyWorldEvent.isCancelled();
}

@EventHandler
public void onFailMove(PlayerFailMoveEvent event) {
if (event.getPlayer().hasPermission("axiom.*")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.moulberry.axiom.event;

import com.moulberry.axiom.AxiomPaper;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
return;
}

// Call AxiomModifyWorldEvent event
AxiomModifyWorldEvent modifyWorldEvent = new AxiomModifyWorldEvent(bukkitPlayer, bukkitPlayer.getWorld());
Bukkit.getPluginManager().callEvent(modifyWorldEvent);
if (modifyWorldEvent.isCancelled()) {
if (!this.plugin.canModifyWorld(bukkitPlayer, bukkitPlayer.getWorld())) {
sendEmptyResponse(player, id);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ private void applyBlockBuffer(ServerPlayer player, MinecraftServer server, Block
return;
}

// Call AxiomModifyWorldEvent event
AxiomModifyWorldEvent modifyWorldEvent = new AxiomModifyWorldEvent(player.getBukkitEntity(), world.getWorld());
Bukkit.getPluginManager().callEvent(modifyWorldEvent);
if (modifyWorldEvent.isCancelled()) return;
if (!this.plugin.canModifyWorld(player.getBukkitEntity(), world.getWorld())) {
return;
}

// Allowed, apply buffer
BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
Expand Down Expand Up @@ -257,10 +256,9 @@ private void applyBiomeBuffer(ServerPlayer player, MinecraftServer server, Biome
return;
}

// Call AxiomModifyWorldEvent event
AxiomModifyWorldEvent modifyWorldEvent = new AxiomModifyWorldEvent(player.getBukkitEntity(), world.getWorld());
Bukkit.getPluginManager().callEvent(modifyWorldEvent);
if (modifyWorldEvent.isCancelled()) return;
if (!this.plugin.canModifyWorld(player.getBukkitEntity(), world.getWorld())) {
return;
}

Set<LevelChunk> changedChunks = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
return;
}

// Check if player is allowed to modify this world
AxiomModifyWorldEvent modifyWorldEvent = new AxiomModifyWorldEvent(bukkitPlayer, bukkitPlayer.getWorld());
Bukkit.getPluginManager().callEvent(modifyWorldEvent);
if (modifyWorldEvent.isCancelled()) return;
if (!this.plugin.canModifyWorld(bukkitPlayer, bukkitPlayer.getWorld())) {
return;
}

// Read packet
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player pla
if (!level.dimension().equals(key)) return;

// Call modify world
AxiomModifyWorldEvent modifyWorldEvent = new AxiomModifyWorldEvent(player, player.getWorld());
Bukkit.getPluginManager().callEvent(modifyWorldEvent);
if (modifyWorldEvent.isCancelled()) return;
if (!this.plugin.canModifyWorld(player, player.getWorld())) {
return;
}

// Call time change event
AxiomTimeChangeEvent timeChangeEvent = new AxiomTimeChangeEvent(player, time, freezeTime);
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ unsupported-axiom-version: "kick"
# Maximum packet size. Must not be less than 32767
max-block-buffer-packet-size: 0x100000

# Regex for whitelisting worlds
# The world can only be modified if the regex matches the world's name
whitelist-world-regex: null

# Regex for blacklisting worlds
# If the regex matches the world's name, the world can't be modified
blacklist-world-regex: null

# Toggles for individual packet handlers. May break certain features
packet-handlers:
hello: true
Expand Down

0 comments on commit eb1a1cd

Please sign in to comment.