diff --git a/src/main/java/eu/m724/tweaks/TweaksConfig.java b/src/main/java/eu/m724/tweaks/TweaksConfig.java index 1bd5752..0a6bde7 100644 --- a/src/main/java/eu/m724/tweaks/TweaksConfig.java +++ b/src/main/java/eu/m724/tweaks/TweaksConfig.java @@ -10,6 +10,7 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.Plugin; public record TweaksConfig( + boolean worldborderExpand, boolean worldborderHide, boolean brandEnabled, @@ -64,7 +65,8 @@ public record TweaksConfig( throw new RuntimeException("Did you downgrade the plugin? Remove config.yml and let the plugin re-create it", exception); } - boolean hideWorldBorder = config.getBoolean("worldborder.hide"); + boolean worldborderExpand = config.getBoolean("worldborder.expand"); + boolean worldborderHide = config.getBoolean("worldborder.hide"); boolean brandEnabled = config.getBoolean("brand.enabled"); String brandText = config.getString("brand.text"); @@ -98,7 +100,7 @@ public record TweaksConfig( boolean sleepInstant = config.getBoolean("sleep.instant"); TweaksConfig.config = new TweaksConfig( - hideWorldBorder, + worldborderExpand, worldborderHide, brandEnabled, brandText, brandShowPing, brandShowMspt, doorEnabled, doorDoubleOpen, doorKnocking, motdEnabled, motdSet, diff --git a/src/main/java/eu/m724/tweaks/TweaksPlugin.java b/src/main/java/eu/m724/tweaks/TweaksPlugin.java index 4f92389..a611ee2 100644 --- a/src/main/java/eu/m724/tweaks/TweaksPlugin.java +++ b/src/main/java/eu/m724/tweaks/TweaksPlugin.java @@ -33,6 +33,9 @@ public class TweaksPlugin extends JavaPlugin { TweaksConfig config = TweaksConfig.load(this); new Language(Locale.US); // TODO + // whether enabled is handled inside + new WorldBorderManager().init(this); + if (config.chatEnabled()) { ChatManager chatManager = new ChatManager(this); chatManager.init(); @@ -68,10 +71,6 @@ public class TweaksPlugin extends JavaPlugin { } } - if (config.worldborderHide()) { - new WorldBorderManager().init(this); - } - if (config.pomodoroEnabled()) { new PomodoroManager(this).init(); getCommand("pomodoro").setExecutor(new PomodoroCommands()); diff --git a/src/main/java/eu/m724/tweaks/worldborder/WorldBorderExpanderListener.java b/src/main/java/eu/m724/tweaks/worldborder/WorldBorderExpanderListener.java new file mode 100644 index 0000000..3c4bc45 --- /dev/null +++ b/src/main/java/eu/m724/tweaks/worldborder/WorldBorderExpanderListener.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2024 Minecon724 + * Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file + * in the project root for the full license text. + */ + +package eu.m724.tweaks.worldborder; + +import net.minecraft.server.level.ServerLevel; +import org.bukkit.craftbukkit.v1_21_R1.CraftWorld; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.world.WorldLoadEvent; + +public class WorldBorderExpanderListener implements Listener { + @EventHandler + public void onWorldLoad(WorldLoadEvent event) { + ServerLevel level = ((CraftWorld) event.getWorld()).getHandle(); + + level.getWorldBorder().setAbsoluteMaxSize(30000000); + } +} diff --git a/src/main/java/eu/m724/tweaks/worldborder/WorldBorderHider.java b/src/main/java/eu/m724/tweaks/worldborder/WorldBorderHider.java new file mode 100644 index 0000000..06b3491 --- /dev/null +++ b/src/main/java/eu/m724/tweaks/worldborder/WorldBorderHider.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2024 Minecon724 + * Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file + * in the project root for the full license text. + */ + +package eu.m724.tweaks.worldborder; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.ListenerPriority; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import org.bukkit.plugin.Plugin; + +import java.nio.ByteBuffer; + +public class WorldBorderHider { + private static final int EXTENSION_RADIUS = 512; + + public void init(Plugin plugin) { + plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "tweaks724:worldborder"); + byte[] infoArray = ByteBuffer.allocate(4).putInt(EXTENSION_RADIUS).array(); + + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter( + plugin, + ListenerPriority.NORMAL, + PacketType.Play.Server.INITIALIZE_BORDER + ) { + @Override + public void onPacketSending(PacketEvent event) { + PacketContainer packet = event.getPacket(); + // old diameter + packet.getDoubles().write(2, packet.getDoubles().read(2) + EXTENSION_RADIUS * 2); + // new diameter + packet.getDoubles().write(3, packet.getDoubles().read(3) + EXTENSION_RADIUS * 2); + + // border radius + packet.getIntegers().write(0, packet.getIntegers().read(0) + EXTENSION_RADIUS); + // warning distance + packet.getIntegers().write(1, packet.getIntegers().read(1) + EXTENSION_RADIUS); + + event.getPlayer().sendPluginMessage(plugin, "tweaks724:worldborder", infoArray); + } + }); + + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter( + plugin, + ListenerPriority.NORMAL, + PacketType.Play.Server.SET_BORDER_SIZE + ) { + @Override + public void onPacketSending(PacketEvent event) { + PacketContainer packet = event.getPacket(); + // diameter + packet.getDoubles().write(0, packet.getDoubles().read(0) + EXTENSION_RADIUS * 2); + } + }); + + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter( + plugin, + ListenerPriority.NORMAL, + PacketType.Play.Server.SET_BORDER_WARNING_DISTANCE + ) { + @Override + public void onPacketSending(PacketEvent event) { + PacketContainer packet = event.getPacket(); + // warning distance + packet.getIntegers().write(0, packet.getIntegers().read(0) + EXTENSION_RADIUS); + } + }); + } +} diff --git a/src/main/java/eu/m724/tweaks/worldborder/WorldBorderManager.java b/src/main/java/eu/m724/tweaks/worldborder/WorldBorderManager.java index 5501bfa..2354a83 100644 --- a/src/main/java/eu/m724/tweaks/worldborder/WorldBorderManager.java +++ b/src/main/java/eu/m724/tweaks/worldborder/WorldBorderManager.java @@ -6,69 +6,24 @@ package eu.m724.tweaks.worldborder; -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.ListenerPriority; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; +import eu.m724.tweaks.TweaksConfig; +import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.plugin.Plugin; -import java.nio.ByteBuffer; - public class WorldBorderManager { - private static final int EXTENSION_RADIUS = 512; - public void init(Plugin plugin) { - plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "tweaks724:worldborder"); - byte[] infoArray = ByteBuffer.allocate(4).putInt(EXTENSION_RADIUS).array(); + if (TweaksConfig.getConfig().worldborderExpand()) { + WorldBorderExpanderListener wbrl = new WorldBorderExpanderListener(); + plugin.getServer().getPluginManager().registerEvents(wbrl, plugin); - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter( - plugin, - ListenerPriority.NORMAL, - PacketType.Play.Server.INITIALIZE_BORDER - ) { - @Override - public void onPacketSending(PacketEvent event) { - PacketContainer packet = event.getPacket(); - // old diameter - packet.getDoubles().write(2, packet.getDoubles().read(2) + EXTENSION_RADIUS * 2); - // new diameter - packet.getDoubles().write(3, packet.getDoubles().read(3) + EXTENSION_RADIUS * 2); + // because the plugin loads "post world" + plugin.getServer().getWorlds().forEach(w -> { + wbrl.onWorldLoad(new WorldLoadEvent(w)); + }); + } - // border radius - // packet.getIntegers().write(0, packet.getIntegers().read(0) + EXTENSION_RADIUS); - // warning distance - packet.getIntegers().write(1, packet.getIntegers().read(1) + EXTENSION_RADIUS); - - event.getPlayer().sendPluginMessage(plugin, "tweaks724:worldborder", infoArray); - } - }); - - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter( - plugin, - ListenerPriority.NORMAL, - PacketType.Play.Server.SET_BORDER_SIZE - ) { - @Override - public void onPacketSending(PacketEvent event) { - PacketContainer packet = event.getPacket(); - // diameter - packet.getDoubles().write(0, packet.getDoubles().read(0) + EXTENSION_RADIUS * 2); - } - }); - - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter( - plugin, - ListenerPriority.NORMAL, - PacketType.Play.Server.SET_BORDER_WARNING_DISTANCE - ) { - @Override - public void onPacketSending(PacketEvent event) { - PacketContainer packet = event.getPacket(); - // warning distance - packet.getIntegers().write(0, packet.getIntegers().read(0) + EXTENSION_RADIUS); - } - }); + if (TweaksConfig.getConfig().worldborderHide()) { + new WorldBorderHider().init(plugin); + } } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 94c1766..29b092a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -5,10 +5,15 @@ # - https://discord.gg/86X4Z5JUeq # - https://www.spigotmc.org/threads/tweaks724.670906/ +# Warning: Don't use /worldborder while this is on worldborder: - # Hides the world border at 30 mil + # Expands the worldborder to 30,000,000 + # It's not possible to go beyond that without client and server mods. (Though I have a prototype) + # Enjoy 307,199,918,080 more usable blocks + expand: true + # Hides the world border # Client side so it won't make the world bigger or anything - # Warning: Don't use /worldborder while this is on + # Also enable expand if you don't want to glitch at 29,999,984. (this is because you can only go beyond with a pearl) hide: true # "Server brand" (second line of F3)