mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-29 20:09:23 +00:00
@@ -583,42 +583,6 @@ public final class LeavesConfig {
|
||||
}
|
||||
}
|
||||
|
||||
public ForcePeacefulModeSwitchConfig peacefulModeSwitch = new ForcePeacefulModeSwitchConfig();
|
||||
|
||||
@GlobalConfigCategory("force-peaceful-mode-switch")
|
||||
public static class ForcePeacefulModeSwitchConfig {
|
||||
@RemovedConfig(name = "force-peaceful-mode", category = "modify", transform = true)
|
||||
@GlobalConfig(value = "tick", validator = TickValidator.class)
|
||||
public int tick = -1;
|
||||
|
||||
private static class TickValidator extends IntConfigValidator {
|
||||
@Override
|
||||
public void verify(Integer old, Integer value) throws IllegalArgumentException {
|
||||
for (ServerLevel level : MinecraftServer.getServer().getAllLevels()) {
|
||||
level.chunkSource.peacefulModeSwitchTick = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@GlobalConfig(value = "types", validator = TypeValidator.class)
|
||||
public List<ForcePeacefulModeSwitchType> types = List.of(ForcePeacefulModeSwitchType.BLAZE, ForcePeacefulModeSwitchType.WITHER, ForcePeacefulModeSwitchType.SHULKER, ForcePeacefulModeSwitchType.WARDEN);
|
||||
public Set<Class<? extends Entity>> classTypes = new HashSet<>();
|
||||
|
||||
private static class TypeValidator extends ListConfigValidator.ENUM<ForcePeacefulModeSwitchType> {
|
||||
@Override
|
||||
public void verify(List<ForcePeacefulModeSwitchType> old, @NotNull List<ForcePeacefulModeSwitchType> value) throws IllegalArgumentException {
|
||||
Set<Class<? extends Entity>> classes = new HashSet<>();
|
||||
for (ForcePeacefulModeSwitchType type : value) {
|
||||
classes.add(type.getEntityClass());
|
||||
}
|
||||
LeavesConfig.modify.peacefulModeSwitch.classTypes = classes;
|
||||
for (ServerLevel level : MinecraftServer.getServer().getAllLevels()) {
|
||||
level.chunkSource.peacefulModeSwitchEntityTypes = classes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@GlobalConfig("disable-vault-blacklist")
|
||||
public boolean disableVaultBlacklist = false;
|
||||
|
||||
@@ -642,6 +606,10 @@ public final class LeavesConfig {
|
||||
}
|
||||
}
|
||||
|
||||
@RemovedConfig(name = "tick", category = {"modify", "force-peaceful-mode-switch"})
|
||||
@RemovedConfig(name = "types", category = {"modify", "force-peaceful-mode-switch"})
|
||||
@RemovedConfig(name = "force-peaceful-mode-switch", category = "modify")
|
||||
@RemovedConfig(name = "force-peaceful-mode", category = "modify")
|
||||
@RemovedConfig(name = "tick-command", category = "modify")
|
||||
@RemovedConfig(name = "player-can-edit-sign", category = "modify")
|
||||
@RemovedConfig(name = "mending-compatibility-infinity", category = {"modify", "minecraft-old"})
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.minecraft.Util;
|
||||
import org.leavesmc.leaves.command.subcommands.BlockUpdateCommand;
|
||||
import org.leavesmc.leaves.command.subcommands.ConfigCommand;
|
||||
import org.leavesmc.leaves.command.subcommands.CounterCommand;
|
||||
import org.leavesmc.leaves.command.subcommands.PeacefulModeSwitchCommand;
|
||||
import org.leavesmc.leaves.command.subcommands.ReloadCommand;
|
||||
import org.leavesmc.leaves.command.subcommands.ReportCommand;
|
||||
import org.leavesmc.leaves.command.subcommands.UpdateCommand;
|
||||
@@ -23,7 +22,6 @@ public final class LeavesCommand extends LeavesRootCommand {
|
||||
final Map<Set<String>, LeavesSubcommand> commands = new HashMap<>();
|
||||
commands.put(Set.of("config"), new ConfigCommand());
|
||||
commands.put(Set.of("update"), new UpdateCommand());
|
||||
commands.put(Set.of("peaceful"), new PeacefulModeSwitchCommand());
|
||||
commands.put(Set.of("counter"), new CounterCommand());
|
||||
commands.put(Set.of("reload"), new ReloadCommand());
|
||||
commands.put(Set.of("report"), new ReportCommand());
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package org.leavesmc.leaves.command.subcommands;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.NaturalSpawner;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.leavesmc.leaves.command.LeavesCommandUtil;
|
||||
import org.leavesmc.leaves.command.LeavesSubcommand;
|
||||
import org.leavesmc.leaves.command.LeavesSuggestionBuilder;
|
||||
|
||||
public class PeacefulModeSwitchCommand implements LeavesSubcommand {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String subCommand, String[] args) {
|
||||
World world;
|
||||
if (args.length == 0) {
|
||||
if (sender instanceof Player player) {
|
||||
world = player.getWorld();
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Must specify a world! ex: '/leaves peaceful world'", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
final String input = args[0];
|
||||
final World inputWorld = Bukkit.getWorld(input);
|
||||
if (inputWorld == null) {
|
||||
sender.sendMessage(Component.text("'" + input + "' is not a valid world!", NamedTextColor.RED));
|
||||
return;
|
||||
} else {
|
||||
world = inputWorld;
|
||||
}
|
||||
}
|
||||
|
||||
final ServerLevel level = ((CraftWorld) world).getHandle();
|
||||
int chunks = 0;
|
||||
if (level.chunkSource.getLastSpawnState() != null) {
|
||||
chunks = level.chunkSource.getLastSpawnState().getSpawnableChunkCount();
|
||||
}
|
||||
|
||||
sender.sendMessage(Component.join(JoinConfiguration.noSeparators(),
|
||||
Component.text("Peaceful Mode Switch for world: "),
|
||||
Component.text(world.getName(), NamedTextColor.AQUA)
|
||||
));
|
||||
|
||||
sender.sendMessage(Component.join(JoinConfiguration.noSeparators(),
|
||||
Component.text("Refuses per "),
|
||||
Component.text(level.chunkSource.peacefulModeSwitchTick, level.chunkSource.peacefulModeSwitchTick > 0 ? NamedTextColor.AQUA : NamedTextColor.GRAY),
|
||||
Component.text(" tick")
|
||||
));
|
||||
|
||||
int count = level.chunkSource.peacefulModeSwitchCount;
|
||||
int limit = NaturalSpawner.globalLimitForCategory(level, MobCategory.MONSTER, chunks);
|
||||
NamedTextColor color = count >= limit ? NamedTextColor.AQUA : NamedTextColor.GRAY;
|
||||
|
||||
sender.sendMessage(Component.join(JoinConfiguration.noSeparators(),
|
||||
Component.text("Now count "),
|
||||
Component.text(count, color),
|
||||
Component.text("/", color),
|
||||
Component.text(limit, color)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suggest(@NotNull CommandSender sender, @NotNull String alias, @NotNull String @NotNull [] args, @Nullable Location location, LeavesSuggestionBuilder builder) throws IllegalArgumentException {
|
||||
if (args.length > 1) {
|
||||
return;
|
||||
}
|
||||
LeavesCommandUtil.getListMatchingLast(sender, args, Bukkit.getWorlds().stream().map(World::getName).toList()).forEach(builder::suggest);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user