New world border tools
All checks were successful
/ deploy (push) Successful in 2m3s

Expand or hide or ideally both
This commit is contained in:
Minecon724 2024-12-01 10:49:42 +01:00
parent b23f773198
commit 6f0dae932b
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
6 changed files with 123 additions and 66 deletions

View file

@ -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,

View file

@ -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());

View file

@ -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);
}
}

View file

@ -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);
}
});
}
}

View file

@ -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);
// 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);
}
// because the plugin loads "post world"
plugin.getServer().getWorlds().forEach(w -> {
wbrl.onWorldLoad(new WorldLoadEvent(w));
});
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);
}
});
}
}

View file

@ -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)