forked from kaboomserver/extras
Replace existing gamerule checks with WorldGameRuleChangeEvent
This commit is contained in:
parent
389c55c42b
commit
9e32dc5c25
4 changed files with 22 additions and 21 deletions
|
@ -40,6 +40,7 @@ import pw.kaboom.extras.modules.player.PlayerInteract;
|
|||
import pw.kaboom.extras.modules.player.PlayerRecipe;
|
||||
import pw.kaboom.extras.modules.player.PlayerTeleport;
|
||||
import pw.kaboom.extras.modules.server.ServerCommand;
|
||||
import pw.kaboom.extras.modules.server.ServerGameRule;
|
||||
import pw.kaboom.extras.modules.server.ServerTabComplete;
|
||||
import pw.kaboom.extras.modules.server.ServerTick;
|
||||
|
||||
|
@ -109,6 +110,7 @@ public final class Main extends JavaPlugin {
|
|||
|
||||
/* Server-related modules */
|
||||
this.getServer().getPluginManager().registerEvents(new ServerCommand(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new ServerGameRule(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new ServerTabComplete(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new ServerTick(), this);
|
||||
|
||||
|
|
|
@ -128,15 +128,6 @@ public final class ServerCommand implements Listener {
|
|||
return "cancel";
|
||||
}
|
||||
break;
|
||||
case "/minecraft:gamerule":
|
||||
case "/gamerule":
|
||||
if (arr.length >= 3) {
|
||||
if ("randomTickSpeed".equalsIgnoreCase(arr[1])
|
||||
&& Double.parseDouble(arr[2]) > 6) {
|
||||
return command.replaceFirst(arr[2], "6");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "/minecraft:give":
|
||||
case "/give":
|
||||
if (Double.parseDouble(arr[arr.length - 1]) > 64) {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package pw.kaboom.extras.modules.server;
|
||||
|
||||
import io.papermc.paper.event.world.WorldGameRuleChangeEvent;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public final class ServerGameRule implements Listener {
|
||||
@EventHandler
|
||||
void onGameRuleChange(final WorldGameRuleChangeEvent event) {
|
||||
final GameRule<?> gameRule = event.getGameRule();
|
||||
|
||||
if ((gameRule == GameRule.RANDOM_TICK_SPEED
|
||||
&& Integer.parseInt(event.getValue()) > 6)
|
||||
|| (event.getGameRule() == GameRule.SPAWN_RADIUS
|
||||
&& Integer.parseInt(event.getValue()) > 100)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package pw.kaboom.extras.modules.server;
|
||||
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
@ -10,17 +9,6 @@ public final class ServerTick implements Listener {
|
|||
@EventHandler
|
||||
void onPlayerStatisticIncrement(final PlayerStatisticIncrementEvent event) {
|
||||
final World world = event.getPlayer().getWorld();
|
||||
final Integer randomTickSpeed = world.getGameRuleValue(GameRule.RANDOM_TICK_SPEED);
|
||||
|
||||
if (randomTickSpeed > 6) {
|
||||
world.setGameRule(GameRule.RANDOM_TICK_SPEED, 6);
|
||||
}
|
||||
|
||||
final Integer spawnRadius = world.getGameRuleValue(GameRule.SPAWN_RADIUS);
|
||||
|
||||
if (spawnRadius > 100) {
|
||||
world.setGameRule(GameRule.SPAWN_RADIUS, 100);
|
||||
}
|
||||
|
||||
if (!world.isAutoSave()) {
|
||||
world.setAutoSave(true);
|
||||
|
|
Loading…
Reference in a new issue