mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Add global gamerules
This commit is contained in:
parent
580f87f28b
commit
d0b89d995c
@ -9,6 +9,7 @@ import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -44,8 +45,17 @@ public class DebugCMD extends PlexCommand
|
||||
{
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
PlexUtils.commitGameRules(world);
|
||||
PlexLog.debug("Set gamerules for world: " + world.getName());
|
||||
PlexUtils.commitGlobalGameRules(world);
|
||||
PlexLog.log("Set global gamerules for world: " + world.getName());
|
||||
}
|
||||
for (String world : plugin.config.getConfigurationSection("worlds").getKeys(false))
|
||||
{
|
||||
World bukkitWorld = Bukkit.getWorld(world);
|
||||
if (bukkitWorld != null)
|
||||
{
|
||||
PlexUtils.commitSpecificGameRules(bukkitWorld);
|
||||
PlexLog.log("Set specific gamerules for world: " + world.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
return mmString("<aqua>Re-applied game all the game rules!");
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package dev.plex.services.impl;
|
||||
import dev.plex.services.AbstractService;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
@ -18,8 +19,17 @@ public class GameRuleService extends AbstractService
|
||||
{
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
PlexUtils.commitGameRules(world);
|
||||
PlexLog.debug("Set gamerules for world: " + world.getName());
|
||||
PlexUtils.commitGlobalGameRules(world);
|
||||
PlexLog.log("Set global gamerules for world: " + world.getName());
|
||||
}
|
||||
for (String world : plugin.config.getConfigurationSection("worlds").getKeys(false))
|
||||
{
|
||||
World bukkitWorld = Bukkit.getWorld(world);
|
||||
if (bukkitWorld != null)
|
||||
{
|
||||
PlexUtils.commitSpecificGameRules(bukkitWorld);
|
||||
PlexLog.log("Set specific gamerules for world: " + world.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,9 +239,23 @@ public class PlexUtils extends PlexBase
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void commitGameRules(World world)
|
||||
public static <T> void commitGlobalGameRules(World world)
|
||||
{
|
||||
for (String s : Plex.get().config.getStringList("global_gamerules"))
|
||||
{
|
||||
readGameRules(world, s);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void commitSpecificGameRules(World world)
|
||||
{
|
||||
for (String s : Plex.get().config.getStringList("worlds." + world.getName().toLowerCase(Locale.ROOT) + ".gameRules"))
|
||||
{
|
||||
readGameRules(world, s);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void readGameRules(World world, String s)
|
||||
{
|
||||
String gameRule = s.split(";")[0];
|
||||
T value = (T)s.split(";")[1];
|
||||
@ -256,11 +270,9 @@ public class PlexUtils extends PlexBase
|
||||
PlexLog.error(String.format("Failed to set game rule %s for world %s with value %s!", gameRule, world.getName().toLowerCase(Locale.ROOT), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Object check(T value)
|
||||
{
|
||||
|
||||
if (value.toString().equalsIgnoreCase("true") || value.toString().equalsIgnoreCase("false"))
|
||||
{
|
||||
return Boolean.parseBoolean(value.toString());
|
||||
|
@ -47,14 +47,10 @@ data:
|
||||
password: ""
|
||||
|
||||
# See https://plex.us.org/docs/customization/config#worlds for documentation
|
||||
worlds:
|
||||
flatlands:
|
||||
name: "Flatlands"
|
||||
permission: "plex.world.flatlands"
|
||||
noEdit: "&cYou can't edit this world!"
|
||||
gameRules:
|
||||
- "doWeatherCycle;false"
|
||||
- "doDaylightCycle;false"
|
||||
# These gamerules apply to all worlds on the server
|
||||
global_gamerules:
|
||||
- "doWeatherCycle;true"
|
||||
- "doDaylightCycle;true"
|
||||
- "doMobSpawning;false"
|
||||
- "keepInventory;true"
|
||||
- "doFireTick;false"
|
||||
@ -66,6 +62,16 @@ worlds:
|
||||
- "announceAdvancements;false"
|
||||
- "showDeathMessages;false"
|
||||
- "sendCommandFeedback;false"
|
||||
|
||||
worlds:
|
||||
flatlands:
|
||||
name: "Flatlands"
|
||||
permission: "plex.world.flatlands"
|
||||
noEdit: "&cYou can't edit this world!"
|
||||
gameRules:
|
||||
# The gamerules here override the global gamerules
|
||||
- "doWeatherCycle;false"
|
||||
- "doDaylightCycle;false"
|
||||
parameters:
|
||||
grass_block: 1
|
||||
dirt: 32
|
||||
@ -80,17 +86,6 @@ worlds:
|
||||
gameRules:
|
||||
- "doWeatherCycle;false"
|
||||
- "doDaylightCycle;false"
|
||||
- "doMobSpawning;false"
|
||||
- "keepInventory;true"
|
||||
- "doFireTick;false"
|
||||
- "doMobLoot;false"
|
||||
- "mobGriefing;false"
|
||||
- "doTileDrops;false"
|
||||
- "commandBlockOutput;false"
|
||||
- "naturalRegeneration;true"
|
||||
- "announceAdvancements;false"
|
||||
- "showDeathMessages;false"
|
||||
- "sendCommandFeedback;false"
|
||||
parameters:
|
||||
grass_block: 1
|
||||
dirt: 32
|
||||
@ -105,17 +100,6 @@ worlds:
|
||||
gameRules:
|
||||
- "doWeatherCycle;false"
|
||||
- "doDaylightCycle;false"
|
||||
- "doMobSpawning;false"
|
||||
- "keepInventory;true"
|
||||
- "doFireTick;false"
|
||||
- "doMobLoot;false"
|
||||
- "mobGriefing;false"
|
||||
- "doTileDrops;false"
|
||||
- "commandBlockOutput;false"
|
||||
- "naturalRegeneration;true"
|
||||
- "announceAdvancements;false"
|
||||
- "showDeathMessages;false"
|
||||
- "sendCommandFeedback;false"
|
||||
parameters:
|
||||
grass_block: 1
|
||||
dirt: 32
|
||||
|
Loading…
Reference in New Issue
Block a user