Before it's too late
This commit is contained in:
parent
e59b95e2ef
commit
648535fd22
34 changed files with 549 additions and 560 deletions
4
pom.xml
4
pom.xml
|
@ -17,8 +17,8 @@
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
||||||
<project.nms.version>v1_21_R1</project.nms.version>
|
<project.nms.version>v1_21_R2</project.nms.version>
|
||||||
<project.minecraft.version>1.21.1</project.minecraft.version>
|
<project.minecraft.version>1.21.3</project.minecraft.version>
|
||||||
<project.spigot.version>${project.minecraft.version}-R0.1-SNAPSHOT</project.spigot.version>
|
<project.spigot.version>${project.minecraft.version}-R0.1-SNAPSHOT</project.spigot.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
|
@ -12,36 +12,50 @@ import java.util.logging.Logger;
|
||||||
public class DebugLogger {
|
public class DebugLogger {
|
||||||
static Logger logger;
|
static Logger logger;
|
||||||
|
|
||||||
public static void info(String message) {
|
public static void info(String message, Object... format) {
|
||||||
log(Level.INFO, message);
|
log(Level.INFO, message, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warning(String message) {
|
public static void warning(String message, Object... format) {
|
||||||
log(Level.WARNING, message);
|
log(Level.WARNING, message, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void severe(String message) {
|
public static void severe(String message, Object... format) {
|
||||||
log(Level.SEVERE, message);
|
log(Level.SEVERE, message, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fine(String message) {
|
public static void fine(String message, Object... format) {
|
||||||
log(Level.FINE, message);
|
log(Level.FINE, message, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void log(Level level, String message) {
|
public static void finer(String message, Object... format) {
|
||||||
|
log(Level.FINER, message, format);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void log(Level level, String message, Object... format) {
|
||||||
if (logger.getLevel().intValue() > level.intValue()) return;
|
if (logger.getLevel().intValue() > level.intValue()) return;
|
||||||
|
|
||||||
var caller = Thread.currentThread().getStackTrace()[3].getClassName();
|
var caller = Thread.currentThread().getStackTrace()[3].getClassName();
|
||||||
|
|
||||||
|
if (caller.equals(TweaksModule.class.getName())) {
|
||||||
|
var pcaller = Thread.currentThread().getStackTrace()[4].getClassName();
|
||||||
|
if (pcaller.endsWith("Module"))
|
||||||
|
caller = pcaller;
|
||||||
|
}
|
||||||
|
|
||||||
if (caller.startsWith("eu.m724.tweaks."))
|
if (caller.startsWith("eu.m724.tweaks."))
|
||||||
caller = caller.substring(15);
|
caller = caller.substring(15);
|
||||||
|
|
||||||
message = "[" + caller + "] " + message;
|
message = "[" + caller + "] " + message.formatted(format);
|
||||||
|
|
||||||
if (level.intValue() < Level.INFO.intValue()) { // levels below info are never logged even if set for some reason
|
if (level.intValue() < Level.INFO.intValue()) { // levels below info are never logged even if set for some reason
|
||||||
level = Level.INFO;
|
|
||||||
// colors text gray (cyan is close to gray)
|
// colors text gray (cyan is close to gray)
|
||||||
message = "\033[36m" + message + "\033[39m";
|
if (level == Level.FINE) {
|
||||||
|
message = "\033[38;5;250m" + message + "\033[39m";
|
||||||
|
} else {
|
||||||
|
message = "\033[38;5;245m" + message + "\033[39m";
|
||||||
|
}
|
||||||
|
level = Level.INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.log(level, message);
|
logger.log(level, message);
|
||||||
|
|
87
src/main/java/eu/m724/tweaks/TweaksModule.java
Normal file
87
src/main/java/eu/m724/tweaks/TweaksModule.java
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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;
|
||||||
|
|
||||||
|
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.PacketEvent;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public abstract class TweaksModule {
|
||||||
|
protected abstract void onInit();
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
var name = getClass().getSimpleName();
|
||||||
|
DebugLogger.finer("Initializing " + name);
|
||||||
|
long start = System.nanoTime();
|
||||||
|
|
||||||
|
this.onInit();
|
||||||
|
|
||||||
|
long end = System.nanoTime();
|
||||||
|
DebugLogger.fine("Initialized %s in %d µs", name, (end - start) / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO not static maybe?
|
||||||
|
protected TweaksPlugin getPlugin() {
|
||||||
|
return TweaksPlugin.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TweaksConfig getConfig() {
|
||||||
|
return TweaksConfig.getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void registerEvents(Listener listener) {
|
||||||
|
DebugLogger.finer("Registered listener: " + listener.getClass().getName());
|
||||||
|
getPlugin().getServer().getPluginManager().registerEvents(listener, getPlugin());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onPacketSend(PacketType packetType, Consumer<PacketEvent> consumer) {
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(getPlugin(), ListenerPriority.NORMAL, packetType) {
|
||||||
|
@Override
|
||||||
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
consumer.accept(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
DebugLogger.finer("Registered packet send: " + packetType.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onPacketReceive(PacketType packetType, Consumer<PacketEvent> consumer) {
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(getPlugin(), ListenerPriority.NORMAL, packetType) {
|
||||||
|
@Override
|
||||||
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
|
consumer.accept(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
DebugLogger.finer("Registered packet receive: " + packetType.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void registerCommand(String command, CommandExecutor executor) {
|
||||||
|
getPlugin().getCommand(command).setExecutor(executor);
|
||||||
|
DebugLogger.finer("Registered command: " + command);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends TweaksModule> T init(Class<T> clazz) {
|
||||||
|
T module;
|
||||||
|
try {
|
||||||
|
module = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
} catch (InstantiationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.init();
|
||||||
|
|
||||||
|
return module;
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,33 +7,36 @@
|
||||||
package eu.m724.tweaks;
|
package eu.m724.tweaks;
|
||||||
|
|
||||||
import eu.m724.mstats.MStatsPlugin;
|
import eu.m724.mstats.MStatsPlugin;
|
||||||
import eu.m724.tweaks.alert.AlertManager;
|
import eu.m724.tweaks.alert.AlertModule;
|
||||||
import eu.m724.tweaks.auth.AuthManager;
|
import eu.m724.tweaks.auth.AuthModule;
|
||||||
import eu.m724.tweaks.chat.ChatManager;
|
import eu.m724.tweaks.chat.ChatModule;
|
||||||
import eu.m724.tweaks.door.DoorKnockListener;
|
import eu.m724.tweaks.door.DoorKnockModule;
|
||||||
import eu.m724.tweaks.door.DoorOpenListener;
|
import eu.m724.tweaks.door.DoorOpenModule;
|
||||||
import eu.m724.tweaks.full.FullListener;
|
import eu.m724.tweaks.full.FullModule;
|
||||||
import eu.m724.tweaks.hardcore.HardcoreManager;
|
import eu.m724.tweaks.hardcore.HardcoreModule;
|
||||||
import eu.m724.tweaks.killswitch.KillswitchManager;
|
import eu.m724.tweaks.killswitch.KillswitchModule;
|
||||||
import eu.m724.tweaks.knockback.KnockbackListener;
|
import eu.m724.tweaks.knockback.KnockbackModule;
|
||||||
import eu.m724.tweaks.motd.MotdManager;
|
import eu.m724.tweaks.motd.MotdModule;
|
||||||
import eu.m724.tweaks.ping.F3NameListener;
|
import eu.m724.tweaks.ping.F3NameListener;
|
||||||
import eu.m724.tweaks.ping.PingChecker;
|
import eu.m724.tweaks.ping.PingChecker;
|
||||||
import eu.m724.tweaks.pomodoro.PomodoroManager;
|
import eu.m724.tweaks.pomodoro.PomodoroModule;
|
||||||
import eu.m724.tweaks.redstone.RedstoneManager;
|
import eu.m724.tweaks.redstone.RedstoneModule;
|
||||||
import eu.m724.tweaks.sleep.SleepManager;
|
import eu.m724.tweaks.sleep.SleepModule;
|
||||||
import eu.m724.tweaks.swing.SwingManager;
|
import eu.m724.tweaks.swing.SwingModule;
|
||||||
import eu.m724.tweaks.updater.UpdaterManager;
|
import eu.m724.tweaks.updater.UpdaterModule;
|
||||||
import eu.m724.tweaks.worldborder.WorldBorderExpander;
|
import eu.m724.tweaks.worldborder.WorldBorderExpandModule;
|
||||||
import eu.m724.tweaks.worldborder.WorldBorderHider;
|
import eu.m724.tweaks.worldborder.WorldBorderHideModule;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class TweaksPlugin extends MStatsPlugin {
|
public class TweaksPlugin extends MStatsPlugin {
|
||||||
|
private static TweaksPlugin INSTANCE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
|
INSTANCE = this;
|
||||||
|
|
||||||
if (getServer().getPluginManager().getPlugin("ProtocolLib") == null) {
|
if (getServer().getPluginManager().getPlugin("ProtocolLib") == null) {
|
||||||
getLogger().severe("ProtocolLib is required for this plugin.");
|
getLogger().severe("ProtocolLib is required for this plugin.");
|
||||||
|
@ -46,37 +49,36 @@ public class TweaksPlugin extends MStatsPlugin {
|
||||||
|
|
||||||
getLogger().setLevel(config.debug() ? Level.FINEST : Level.INFO);
|
getLogger().setLevel(config.debug() ? Level.FINEST : Level.INFO);
|
||||||
DebugLogger.logger = getLogger();
|
DebugLogger.logger = getLogger();
|
||||||
DebugLogger.fine("Debug enabled. There may be performance issues.");
|
|
||||||
|
|
||||||
DebugLogger.fine("Enabling Language");
|
if (config.debug()) {
|
||||||
|
DebugLogger.warning("Debug harms performance");
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugLogger.fine("Language");
|
||||||
new Language(Locale.of(config.locale())); // TODO
|
new Language(Locale.of(config.locale())); // TODO
|
||||||
DebugLogger.fine(Language.getString("languageNotice", Language.getString("language"), Language.getString("languageEnglish")));
|
DebugLogger.fine(Language.getString("languageNotice", Language.getString("language"), Language.getString("languageEnglish")));
|
||||||
|
|
||||||
/* start modules */
|
/* start modules */
|
||||||
|
|
||||||
if (config.worldborderHide()) {
|
if (config.worldborderHide()) {
|
||||||
DebugLogger.fine("Enabling Worldborder hide");
|
TweaksModule.init(WorldBorderHideModule.class);
|
||||||
new WorldBorderHider().init(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.worldborderExpand()) {
|
if (config.worldborderExpand()) {
|
||||||
DebugLogger.fine("Enabling Worldborder expand");
|
TweaksModule.init(WorldBorderExpandModule.class);
|
||||||
new WorldBorderExpander().init(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.chatEnabled()) {
|
if (config.chatEnabled()) {
|
||||||
DebugLogger.fine("Enabling Chat");
|
TweaksModule.init(ChatModule.class);
|
||||||
new ChatManager(this).init(getCommand("chat"), getCommand("chatmanage"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.doorKnocking()) {
|
if (config.doorKnocking()) {
|
||||||
DebugLogger.fine("Enabling Door knock");
|
TweaksModule.init(DoorKnockModule.class);
|
||||||
getServer().getPluginManager().registerEvents(new DoorKnockListener(), this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.doorDoubleOpen()) {
|
if (config.doorDoubleOpen()) {
|
||||||
DebugLogger.fine("Enabling Door double open");
|
TweaksModule.init(DoorOpenModule.class);
|
||||||
getServer().getPluginManager().registerEvents(new DoorOpenListener(), this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.brandEnabled()) {
|
if (config.brandEnabled()) {
|
||||||
|
@ -88,57 +90,45 @@ public class TweaksPlugin extends MStatsPlugin {
|
||||||
new PingChecker(this).init(getCommand("ping"));
|
new PingChecker(this).init(getCommand("ping"));
|
||||||
|
|
||||||
if (config.motdEnabled()) {
|
if (config.motdEnabled()) {
|
||||||
DebugLogger.fine("Enabling MOTD");
|
TweaksModule.init(MotdModule.class);
|
||||||
new MotdManager(this).init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.pomodoroEnabled()) {
|
if (config.pomodoroEnabled()) {
|
||||||
DebugLogger.fine("Enabling Pomodoro");
|
TweaksModule.init(PomodoroModule.class);
|
||||||
new PomodoroManager(this).init(getCommand("pomodoro"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.updaterEnabled()) {
|
if (config.updaterEnabled()) {
|
||||||
DebugLogger.fine("Enabling Updater");
|
TweaksModule.init(UpdaterModule.class);
|
||||||
new UpdaterManager(this).init(getCommand("updates"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.hardcoreEnabled()) {
|
if (config.hardcoreEnabled()) {
|
||||||
DebugLogger.fine("Enabling Hardcore");
|
TweaksModule.init(HardcoreModule.class);
|
||||||
new HardcoreManager().init(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.sleepEnabled()) {
|
if (config.sleepEnabled()) {
|
||||||
DebugLogger.fine("Enabling Sleep");
|
TweaksModule.init(SleepModule.class);
|
||||||
new SleepManager().init(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.authEnabled()) {
|
if (config.authEnabled()) {
|
||||||
DebugLogger.fine("Enabling Auth");
|
TweaksModule.init(AuthModule.class);
|
||||||
new AuthManager(this).init(getCommand("tauth"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugLogger.fine("Enabling Alert");
|
TweaksModule.init(AlertModule.class);
|
||||||
new AlertManager(this).init(getCommand("emergencyalert"));
|
|
||||||
|
|
||||||
DebugLogger.fine("Enabling Full");
|
TweaksModule.init(FullModule.class);
|
||||||
getServer().getPluginManager().registerEvents(new FullListener(), this);
|
|
||||||
|
|
||||||
if (config.redstoneEnabled()) {
|
if (config.redstoneEnabled()) {
|
||||||
DebugLogger.fine("Enabling Redstone");
|
TweaksModule.init(RedstoneModule.class);
|
||||||
new RedstoneManager(this).init(getCommand("retstone"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugLogger.fine("Enabling Knockback");
|
TweaksModule.init(KnockbackModule.class);
|
||||||
new KnockbackListener(this);
|
|
||||||
|
|
||||||
if (config.killswitchEnabled()) {
|
if (config.killswitchEnabled()) {
|
||||||
DebugLogger.fine("Enabling Killswitch");
|
TweaksModule.init(KillswitchModule.class);
|
||||||
new KillswitchManager(this).init(getCommand("servkill"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.swingEnabled()) {
|
if (config.swingEnabled()) {
|
||||||
DebugLogger.fine("Enabling Swing");
|
TweaksModule.init(SwingModule.class);
|
||||||
new SwingManager(this).init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* end modules */
|
/* end modules */
|
||||||
|
@ -154,4 +144,8 @@ public class TweaksPlugin extends MStatsPlugin {
|
||||||
public boolean hasResource(String resource) {
|
public boolean hasResource(String resource) {
|
||||||
return this.getClassLoader().getResource(resource) != null;
|
return this.getClassLoader().getResource(resource) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TweaksPlugin getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2024 Minecon724
|
* Copyright (C) 2025 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
@ -20,9 +20,9 @@ public class AlertCommand implements CommandExecutor {
|
||||||
private List<String> pending;
|
private List<String> pending;
|
||||||
private long when;
|
private long when;
|
||||||
|
|
||||||
private final AlertManager manager;
|
private final AlertModule manager;
|
||||||
|
|
||||||
public AlertCommand(AlertManager manager) {
|
public AlertCommand(AlertModule manager) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class AlertCommand implements CommandExecutor {
|
||||||
} else if (args[0].equalsIgnoreCase("confirm")) {
|
} else if (args[0].equalsIgnoreCase("confirm")) {
|
||||||
sender.sendMessage("CONFIRM must be in all caps");
|
sender.sendMessage("CONFIRM must be in all caps");
|
||||||
} else if (args[0].equalsIgnoreCase("cancel")) {
|
} else if (args[0].equalsIgnoreCase("cancel")) {
|
||||||
if (AlertManager.current != null) {
|
if (AlertModule.current != null) {
|
||||||
manager.stop();
|
manager.stop();
|
||||||
sender.sendMessage("Cancelled alert");
|
sender.sendMessage("Cancelled alert");
|
||||||
} else if (pending != null) {
|
} else if (pending != null) {
|
||||||
|
@ -86,7 +86,7 @@ public class AlertCommand implements CommandExecutor {
|
||||||
|
|
||||||
if (pending != null) {
|
if (pending != null) {
|
||||||
when = System.currentTimeMillis();
|
when = System.currentTimeMillis();
|
||||||
if (AlertManager.current != null) {
|
if (AlertModule.current != null) {
|
||||||
sender.sendMessage("Broadcasting a new alert will cancel the currently active one");
|
sender.sendMessage("Broadcasting a new alert will cancel the currently active one");
|
||||||
}
|
}
|
||||||
sender.sendMessage("Please confirm broadcast with /emergencyalert CONFIRM within 15 seconds");
|
sender.sendMessage("Please confirm broadcast with /emergencyalert CONFIRM within 15 seconds");
|
||||||
|
|
|
@ -1,90 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.alert;
|
|
||||||
|
|
||||||
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.TweaksPlugin;
|
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class AlertManager {
|
|
||||||
private final TweaksPlugin plugin;
|
|
||||||
|
|
||||||
private BukkitTask notifyTask;
|
|
||||||
static Alert current;
|
|
||||||
static Map<Player, Integer> pages = new HashMap<>();
|
|
||||||
|
|
||||||
public AlertManager(TweaksPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(PluginCommand command) {
|
|
||||||
command.setExecutor(new AlertCommand(this));
|
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(
|
|
||||||
plugin,
|
|
||||||
ListenerPriority.NORMAL,
|
|
||||||
PacketType.Play.Client.ENCHANT_ITEM
|
|
||||||
) {
|
|
||||||
@Override
|
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
|
||||||
if (current == null) return;
|
|
||||||
if (!current.isOpen(event.getPlayer())) return;
|
|
||||||
|
|
||||||
PacketContainer packet = event.getPacket();
|
|
||||||
|
|
||||||
int windowId, buttonId;
|
|
||||||
windowId = packet.getIntegers().read(0);
|
|
||||||
buttonId = packet.getIntegers().read(1);
|
|
||||||
|
|
||||||
var page = pages.getOrDefault(event.getPlayer(),1);
|
|
||||||
|
|
||||||
if (buttonId == 1) { // prev page
|
|
||||||
page--;
|
|
||||||
} else if (buttonId == 2) { // nextc page
|
|
||||||
page++;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pages.put(event.getPlayer(), page);
|
|
||||||
var npacket = new PacketContainer(PacketType.Play.Server.WINDOW_DATA);
|
|
||||||
npacket.getIntegers().write(0, windowId);
|
|
||||||
npacket.getIntegers().write(1, 0);
|
|
||||||
npacket.getIntegers().write(2, page);
|
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), npacket);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public Alert start(String... content) {
|
|
||||||
stop();
|
|
||||||
current = new Alert(content);
|
|
||||||
notifyTask = new AlertRunnable(current, v -> this.stop()).runTaskTimer(plugin, 0, 10);
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
if (current == null) return;
|
|
||||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
|
||||||
if (current.isOpen(player))
|
|
||||||
player.closeInventory();
|
|
||||||
}
|
|
||||||
pages.clear();
|
|
||||||
notifyTask.cancel();
|
|
||||||
current = null;
|
|
||||||
}
|
|
||||||
}
|
|
74
src/main/java/eu/m724/tweaks/alert/AlertModule.java
Normal file
74
src/main/java/eu/m724/tweaks/alert/AlertModule.java
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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.alert;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import eu.m724.tweaks.TweaksModule;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class AlertModule extends TweaksModule {
|
||||||
|
private BukkitTask notifyTask;
|
||||||
|
static Alert current;
|
||||||
|
static Map<Player, Integer> pages = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onInit() {
|
||||||
|
registerCommand("emergencyalert", new AlertCommand(this));
|
||||||
|
|
||||||
|
onPacketReceive(PacketType.Play.Client.ENCHANT_ITEM, (event) -> {
|
||||||
|
if (current == null) return;
|
||||||
|
if (!current.isOpen(event.getPlayer())) return;
|
||||||
|
|
||||||
|
PacketContainer packet = event.getPacket();
|
||||||
|
|
||||||
|
int windowId, buttonId;
|
||||||
|
windowId = packet.getIntegers().read(0);
|
||||||
|
buttonId = packet.getIntegers().read(1);
|
||||||
|
|
||||||
|
var page = pages.getOrDefault(event.getPlayer(),1);
|
||||||
|
|
||||||
|
if (buttonId == 1) { // prev page
|
||||||
|
page--;
|
||||||
|
} else if (buttonId == 2) { // nextc page
|
||||||
|
page++;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pages.put(event.getPlayer(), page);
|
||||||
|
var npacket = new PacketContainer(PacketType.Play.Server.WINDOW_DATA);
|
||||||
|
npacket.getIntegers().write(0, windowId);
|
||||||
|
npacket.getIntegers().write(1, 0);
|
||||||
|
npacket.getIntegers().write(2, page);
|
||||||
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), npacket);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public Alert start(String... content) {
|
||||||
|
stop();
|
||||||
|
current = new Alert(content);
|
||||||
|
notifyTask = new AlertRunnable(current, v -> this.stop()).runTaskTimer(getPlugin(), 0, 10);
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
if (current == null) return;
|
||||||
|
for (Player player : getPlugin().getServer().getOnlinePlayers()) {
|
||||||
|
if (current.isOpen(player))
|
||||||
|
player.closeInventory();
|
||||||
|
}
|
||||||
|
pages.clear();
|
||||||
|
notifyTask.cancel();
|
||||||
|
current = null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.auth;
|
|
||||||
|
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class AuthManager {
|
|
||||||
private final AuthStorage authStorage;
|
|
||||||
private final Plugin plugin;
|
|
||||||
|
|
||||||
public AuthManager(Plugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.authStorage = new AuthStorage(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(PluginCommand command) {
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new AuthListener(authStorage), plugin);
|
|
||||||
command.setExecutor(new AuthCommands(authStorage));
|
|
||||||
}
|
|
||||||
}
|
|
19
src/main/java/eu/m724/tweaks/auth/AuthModule.java
Normal file
19
src/main/java/eu/m724/tweaks/auth/AuthModule.java
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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.auth;
|
||||||
|
|
||||||
|
import eu.m724.tweaks.TweaksModule;
|
||||||
|
|
||||||
|
public class AuthModule extends TweaksModule {
|
||||||
|
@Override
|
||||||
|
protected void onInit() {
|
||||||
|
var authStorage = new AuthStorage(getPlugin());
|
||||||
|
|
||||||
|
registerEvents(new AuthListener(authStorage));
|
||||||
|
registerCommand("tauth", new AuthCommands(authStorage));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2024 Minecon724
|
* Copyright (C) 2025 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
@ -21,9 +21,9 @@ import java.util.Arrays;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ChatCommands implements CommandExecutor {
|
public class ChatCommands implements CommandExecutor {
|
||||||
private final ChatManager manager;
|
private final ChatModule manager;
|
||||||
|
|
||||||
public ChatCommands(ChatManager manager) {
|
public ChatCommands(ChatModule manager) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +94,9 @@ public class ChatCommands implements CommandExecutor {
|
||||||
ChatRoom newRoom = manager.createChatRoom(argument, null, player);
|
ChatRoom newRoom = manager.createChatRoom(argument, null, player);
|
||||||
sender.sendMessage("Created a chat room. Join it: /c " + newRoom.id);
|
sender.sendMessage("Created a chat room. Join it: /c " + newRoom.id);
|
||||||
sender.sendMessage("You might also want to protect it with a password: /cm setpassword");
|
sender.sendMessage("You might also want to protect it with a password: /cm setpassword");
|
||||||
} catch (ChatManager.InvalidIdException e) {
|
} catch (ChatModule.InvalidIdException e) {
|
||||||
sender.sendMessage("ID is invalid: " + e.getMessage());
|
sender.sendMessage("ID is invalid: " + e.getMessage());
|
||||||
} catch (ChatManager.ChatRoomExistsException e) {
|
} catch (ChatModule.ChatRoomExistsException e) {
|
||||||
sender.sendMessage("Room %s already exists".formatted(argument));
|
sender.sendMessage("Room %s already exists".formatted(argument));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
sender.sendMessage("Failed to create room");
|
sender.sendMessage("Failed to create room");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2024 Minecon724
|
* Copyright (C) 2025 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
@ -25,13 +25,14 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
public class ChatListener implements Listener {
|
public class ChatListener implements Listener {
|
||||||
private final ChatManager chatManager;
|
private final ChatModule chatModule;
|
||||||
private final String defaultRoom = TweaksConfig.getConfig().chatDefaultName();
|
private final String defaultRoom = TweaksConfig.getConfig().chatDefaultName();
|
||||||
private final boolean localEvents = TweaksConfig.getConfig().chatLocalEvents();
|
private final boolean localEvents = TweaksConfig.getConfig().chatLocalEvents();
|
||||||
private final int radius;
|
private final int radius;
|
||||||
|
|
||||||
public ChatListener(ChatManager chatManager) {
|
public ChatListener(ChatModule chatModule) {
|
||||||
this.chatManager = chatManager;
|
this.chatModule = chatModule;
|
||||||
|
|
||||||
if (TweaksConfig.getConfig().chatRadius() < 0) {
|
if (TweaksConfig.getConfig().chatRadius() < 0) {
|
||||||
radius = 0;
|
radius = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -52,7 +53,7 @@ public class ChatListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
ChatRoom chatRoom = chatManager.getPlayerChatRoom(player);
|
ChatRoom chatRoom = chatModule.getPlayerChatRoom(player);
|
||||||
|
|
||||||
if (localEvents) {
|
if (localEvents) {
|
||||||
var cb = new ComponentBuilder()
|
var cb = new ComponentBuilder()
|
||||||
|
@ -77,7 +78,7 @@ public class ChatListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
ChatRoom chatRoom = chatManager.removePlayer(player);
|
ChatRoom chatRoom = chatModule.removePlayer(player);
|
||||||
|
|
||||||
if (localEvents) {
|
if (localEvents) {
|
||||||
var cb = new ComponentBuilder()
|
var cb = new ComponentBuilder()
|
||||||
|
@ -103,7 +104,7 @@ public class ChatListener implements Listener {
|
||||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||||
if (localEvents) {
|
if (localEvents) {
|
||||||
Player player = event.getEntity();
|
Player player = event.getEntity();
|
||||||
ChatRoom chatRoom = chatManager.getPlayerChatRoom(player);
|
ChatRoom chatRoom = chatModule.getPlayerChatRoom(player);
|
||||||
|
|
||||||
// would be easier on Paper but this is not Paper
|
// would be easier on Paper but this is not Paper
|
||||||
BaseComponent deathMessage = ComponentSerializer.deserialize(Component.Serializer.toJson(((CraftPlayer)player).getHandle().getCombatTracker().getDeathMessage(), CraftRegistry.getMinecraftRegistry()));
|
BaseComponent deathMessage = ComponentSerializer.deserialize(Component.Serializer.toJson(((CraftPlayer)player).getHandle().getCombatTracker().getDeathMessage(), CraftRegistry.getMinecraftRegistry()));
|
||||||
|
@ -124,7 +125,7 @@ public class ChatListener implements Listener {
|
||||||
|
|
||||||
// broadcast to killer if available
|
// broadcast to killer if available
|
||||||
if (player.getLastDamageCause().getDamageSource().getCausingEntity() instanceof Player killer) {
|
if (player.getLastDamageCause().getDamageSource().getCausingEntity() instanceof Player killer) {
|
||||||
ChatRoom chatRoom2 = chatManager.getPlayerChatRoom(killer);
|
ChatRoom chatRoom2 = chatModule.getPlayerChatRoom(killer);
|
||||||
if (chatRoom != chatRoom2) {
|
if (chatRoom != chatRoom2) {
|
||||||
if (proximityFor(chatRoom)) {
|
if (proximityFor(chatRoom)) {
|
||||||
chatRoom2.broadcastNear(killer.getLocation(), radius, component);
|
chatRoom2.broadcastNear(killer.getLocation(), radius, component);
|
||||||
|
@ -142,7 +143,7 @@ public class ChatListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
ChatRoom chatRoom = chatManager.getPlayerChatRoom(player);
|
ChatRoom chatRoom = chatModule.getPlayerChatRoom(player);
|
||||||
String message = event.getMessage();
|
String message = event.getMessage();
|
||||||
|
|
||||||
var component = new ComponentBuilder()
|
var component = new ComponentBuilder()
|
||||||
|
|
|
@ -1,50 +1,43 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2024 Minecon724
|
* Copyright (C) 2025 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package eu.m724.tweaks.chat;
|
package eu.m724.tweaks.chat;
|
||||||
|
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
import eu.m724.tweaks.TweaksModule;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ChatManager {
|
public class ChatModule extends TweaksModule {
|
||||||
private final Plugin plugin;
|
private final NamespacedKey chatRoomKey = new NamespacedKey(getPlugin(), "chatRoom");
|
||||||
private final NamespacedKey chatRoomKey;
|
private final String defaultRoom = getConfig().chatDefaultName();
|
||||||
private final String defaultRoom;
|
|
||||||
|
|
||||||
private final Map<Player, ChatRoom> playerMap = new HashMap<>();
|
private final Map<Player, ChatRoom> playerMap = new HashMap<>();
|
||||||
private final Map<String, ChatRoom> roomIdMap = new HashMap<>();
|
private final Map<String, ChatRoom> roomIdMap = new HashMap<>();
|
||||||
|
|
||||||
public ChatManager(Plugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.chatRoomKey = new NamespacedKey(plugin, "chatRoom");
|
|
||||||
this.defaultRoom = TweaksConfig.getConfig().chatDefaultName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(PluginCommand chatCommand, PluginCommand chatManageCommand) {
|
@Override
|
||||||
if (plugin.getServer().isEnforcingSecureProfiles()) {
|
protected void onInit() {
|
||||||
|
if (getPlugin().getServer().isEnforcingSecureProfiles()) {
|
||||||
throw new RuntimeException("Please disable enforce-secure-profile in server.properties to use chatrooms");
|
throw new RuntimeException("Please disable enforce-secure-profile in server.properties to use chatrooms");
|
||||||
}
|
}
|
||||||
|
|
||||||
getById(defaultRoom);
|
getById(defaultRoom);
|
||||||
plugin.getServer().getPluginManager().registerEvents(new ChatListener(this), plugin);
|
registerEvents(new ChatListener(this));
|
||||||
|
|
||||||
var chatCommands = new ChatCommands(this);
|
var chatCommands = new ChatCommands(this);
|
||||||
chatCommand.setExecutor(chatCommands);
|
registerCommand("chat", chatCommands);
|
||||||
chatManageCommand.setExecutor(chatCommands);
|
registerCommand("chatmanage", chatCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -1,21 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.compass;
|
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class CompassManager {
|
|
||||||
private final Plugin plugin;
|
|
||||||
|
|
||||||
public CompassManager(Plugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init() {
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new CompassListener(), plugin);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2024 Minecon724
|
* Copyright (C) 2025 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package eu.m724.tweaks.compass;
|
package eu.m724.tweaks.compass;
|
||||||
|
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
import eu.m724.tweaks.TweaksModule;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
@ -25,9 +25,9 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
// TODO dimension check
|
// TODO dimension check
|
||||||
public class CompassListener implements Listener {
|
public class CompassModule extends TweaksModule implements Listener {
|
||||||
private final int precision = TweaksConfig.getConfig().compassPrecision(); // degrees every point
|
private final int precision = getConfig().compassPrecision(); // degrees every point
|
||||||
private final int width = TweaksConfig.getConfig().compassWidth(); // points left to right
|
private final int width = getConfig().compassWidth(); // points left to right
|
||||||
|
|
||||||
private final Map<Integer, String> points = Map.of(
|
private final Map<Integer, String> points = Map.of(
|
||||||
0, ChatColor.DARK_GRAY + "S",
|
0, ChatColor.DARK_GRAY + "S",
|
||||||
|
@ -36,6 +36,11 @@ public class CompassListener implements Listener {
|
||||||
270, ChatColor.DARK_GRAY + "E"
|
270, ChatColor.DARK_GRAY + "E"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onInit() {
|
||||||
|
registerEvents(this);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||||
if (event.getMainHandItem().getType() == Material.COMPASS || event.getOffHandItem().getType() == Material.COMPASS) {
|
if (event.getMainHandItem().getType() == Material.COMPASS || event.getOffHandItem().getType() == Material.COMPASS) {
|
|
@ -1,11 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2024 Minecon724
|
* Copyright (C) 2025 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package eu.m724.tweaks.door;
|
package eu.m724.tweaks.door;
|
||||||
|
|
||||||
|
import eu.m724.tweaks.TweaksModule;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
@ -22,7 +23,12 @@ import org.bukkit.util.RayTraceResult;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class DoorKnockListener implements Listener {
|
public class DoorKnockModule extends TweaksModule implements Listener {
|
||||||
|
@Override
|
||||||
|
protected void onInit() {
|
||||||
|
registerEvents(this);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockDamageAbort(BlockDamageAbortEvent event) {
|
public void onBlockDamageAbort(BlockDamageAbortEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
|
@ -1,11 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2024 Minecon724
|
* Copyright (C) 2025 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package eu.m724.tweaks.door;
|
package eu.m724.tweaks.door;
|
||||||
|
|
||||||
|
import eu.m724.tweaks.TweaksModule;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
@ -15,7 +16,11 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
public class DoorOpenListener implements Listener {
|
public class DoorOpenModule extends TweaksModule implements Listener {
|
||||||
|
@Override
|
||||||
|
protected void onInit() {
|
||||||
|
registerEvents(this);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
@ -71,5 +76,4 @@ public class DoorOpenListener implements Listener {
|
||||||
location.getBlock().setBlockData(nextDoor);
|
location.getBlock().setBlockData(nextDoor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,16 +1,22 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2024 Minecon724
|
* Copyright (C) 2025 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package eu.m724.tweaks.full;
|
package eu.m724.tweaks.full;
|
||||||
|
|
||||||
|
import eu.m724.tweaks.TweaksModule;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
|
||||||
public class FullListener implements Listener {
|
public class FullModule extends TweaksModule implements Listener {
|
||||||
|
@Override
|
||||||
|
protected void onInit() {
|
||||||
|
registerEvents(this);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||||
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL && event.getPlayer().hasPermission("tweaks724.bypass-full")) {
|
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL && event.getPlayer().hasPermission("tweaks724.bypass-full")) {
|
|
@ -1,60 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2025 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.hardcore;
|
|
||||||
|
|
||||||
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.DebugLogger;
|
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
|
||||||
import net.minecraft.world.level.levelgen.RandomSupport;
|
|
||||||
import net.minecraft.world.level.levelgen.Xoroshiro128PlusPlus;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
|
|
||||||
// how we do it is much faster than any Random
|
|
||||||
public class HardcoreManager {
|
|
||||||
private final double chance = TweaksConfig.getConfig().hardcoreChance();
|
|
||||||
|
|
||||||
private final long chanceLong = BigInteger.valueOf(Long.MIN_VALUE)
|
|
||||||
.add(
|
|
||||||
new BigDecimal(
|
|
||||||
BigInteger.valueOf(Long.MAX_VALUE).subtract(BigInteger.valueOf(Long.MIN_VALUE))
|
|
||||||
).multiply(
|
|
||||||
BigDecimal.valueOf(chance)
|
|
||||||
).toBigInteger()
|
|
||||||
).longValue();
|
|
||||||
|
|
||||||
private final Xoroshiro128PlusPlus rng = new Xoroshiro128PlusPlus(
|
|
||||||
RandomSupport.generateUniqueSeed(),
|
|
||||||
RandomSupport.generateUniqueSeed()
|
|
||||||
);
|
|
||||||
|
|
||||||
public void init(Plugin plugin) {
|
|
||||||
DebugLogger.fine("Chance long: " + chanceLong);
|
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(
|
|
||||||
plugin,
|
|
||||||
ListenerPriority.NORMAL,
|
|
||||||
PacketType.Play.Server.LOGIN
|
|
||||||
) {
|
|
||||||
@Override
|
|
||||||
public void onPacketSending(PacketEvent event) {
|
|
||||||
PacketContainer packet = event.getPacket();
|
|
||||||
|
|
||||||
if (rng.nextLong() < chanceLong)
|
|
||||||
// the "is hardcore" boolean https://wiki.vg/Protocol#Login_.28play.29
|
|
||||||
packet.getBooleans().write(0, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
52
src/main/java/eu/m724/tweaks/hardcore/HardcoreModule.java
Normal file
52
src/main/java/eu/m724/tweaks/hardcore/HardcoreModule.java
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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.hardcore;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import eu.m724.tweaks.DebugLogger;
|
||||||
|
import eu.m724.tweaks.TweaksModule;
|
||||||
|
import net.minecraft.world.level.levelgen.RandomSupport;
|
||||||
|
import net.minecraft.world.level.levelgen.Xoroshiro128PlusPlus;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
|
// how we do it is much faster than any Random
|
||||||
|
public class HardcoreModule extends TweaksModule {
|
||||||
|
private final Xoroshiro128PlusPlus rng;
|
||||||
|
private final long chanceLong;
|
||||||
|
|
||||||
|
public HardcoreModule() {
|
||||||
|
this.rng = new Xoroshiro128PlusPlus(
|
||||||
|
RandomSupport.generateUniqueSeed(),
|
||||||
|
RandomSupport.generateUniqueSeed()
|
||||||
|
);
|
||||||
|
|
||||||
|
this.chanceLong = BigInteger.valueOf(Long.MIN_VALUE)
|
||||||
|
.add(
|
||||||
|
new BigDecimal(
|
||||||
|
BigInteger.valueOf(Long.MAX_VALUE).subtract(BigInteger.valueOf(Long.MIN_VALUE))
|
||||||
|
).multiply(
|
||||||
|
BigDecimal.valueOf(getConfig().hardcoreChance())
|
||||||
|
).toBigInteger()
|
||||||
|
).longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onInit() {
|
||||||
|
DebugLogger.fine("Chance long: " + chanceLong);
|
||||||
|
|
||||||
|
onPacketSend(PacketType.Play.Server.LOGIN, (event) -> {
|
||||||
|
PacketContainer packet = event.getPacket();
|
||||||
|
|
||||||
|
if (rng.nextLong() < chanceLong)
|
||||||
|
// the "is hardcore" boolean https://wiki.vg/Protocol#Login_.28play.29
|
||||||
|
packet.getBooleans().write(0, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,13 +10,10 @@ import com.sun.net.httpserver.HttpExchange;
|
||||||
import com.sun.net.httpserver.HttpHandler;
|
import com.sun.net.httpserver.HttpHandler;
|
||||||
import com.sun.net.httpserver.HttpServer;
|
import com.sun.net.httpserver.HttpServer;
|
||||||
import eu.m724.tweaks.DebugLogger;
|
import eu.m724.tweaks.DebugLogger;
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
import eu.m724.tweaks.TweaksModule;
|
||||||
import eu.m724.tweaks.TweaksPlugin;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -27,17 +24,12 @@ import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
||||||
public class KillswitchManager implements CommandExecutor, HttpHandler {
|
public class KillswitchModule extends TweaksModule implements CommandExecutor, HttpHandler {
|
||||||
private final Plugin plugin;
|
|
||||||
private final Ratelimit ratelimit = new Ratelimit();
|
private final Ratelimit ratelimit = new Ratelimit();
|
||||||
|
|
||||||
private byte[] secret;
|
private byte[] secret;
|
||||||
private String secretEncoded;
|
private String secretEncoded;
|
||||||
|
|
||||||
public KillswitchManager(Plugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadKey(File file) {
|
private void loadKey(File file) {
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
try {
|
try {
|
||||||
|
@ -63,15 +55,16 @@ public class KillswitchManager implements CommandExecutor, HttpHandler {
|
||||||
this.secretEncoded = Base64.getEncoder().encodeToString(secret);
|
this.secretEncoded = Base64.getEncoder().encodeToString(secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(PluginCommand serverKillCommand) {
|
@Override
|
||||||
serverKillCommand.setExecutor(this);
|
protected void onInit() {
|
||||||
|
registerCommand("servkill", this);
|
||||||
|
|
||||||
if (TweaksConfig.getConfig().killswitchListen() != null) {
|
if (getConfig().killswitchListen() != null) {
|
||||||
loadKey(new File(plugin.getDataFolder(), "storage/killswitch key"));
|
loadKey(new File(getPlugin().getDataFolder(), "storage/killswitch key"));
|
||||||
|
|
||||||
ratelimit.runTaskTimerAsynchronously(plugin, 0, 20 * 300);
|
ratelimit.runTaskTimerAsynchronously(getPlugin(), 0, 20 * 300);
|
||||||
|
|
||||||
var listenAddress = TweaksConfig.getConfig().killswitchListen().split(":");
|
var listenAddress = getConfig().killswitchListen().split(":");
|
||||||
InetSocketAddress bindAddress;
|
InetSocketAddress bindAddress;
|
||||||
if (listenAddress.length == 1) {
|
if (listenAddress.length == 1) {
|
||||||
bindAddress = new InetSocketAddress(Integer.parseInt(listenAddress[0]));
|
bindAddress = new InetSocketAddress(Integer.parseInt(listenAddress[0]));
|
|
@ -7,22 +7,22 @@
|
||||||
package eu.m724.tweaks.knockback;
|
package eu.m724.tweaks.knockback;
|
||||||
|
|
||||||
import eu.m724.tweaks.DebugLogger;
|
import eu.m724.tweaks.DebugLogger;
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
import eu.m724.tweaks.TweaksModule;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityKnockbackByEntityEvent;
|
import org.bukkit.event.entity.EntityKnockbackByEntityEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class KnockbackListener implements Listener {
|
public class KnockbackModule extends TweaksModule implements Listener {
|
||||||
private final Map<EntityType, Vector> modifiers = new HashMap<>();
|
private final Map<EntityType, Vector> modifiers = new HashMap<>();
|
||||||
|
|
||||||
public KnockbackListener(Plugin plugin) {
|
@Override
|
||||||
TweaksConfig.getConfig().knockbackModifiers().forEach((k, v) -> {
|
protected void onInit() {
|
||||||
|
getConfig().knockbackModifiers().forEach((k, v) -> {
|
||||||
EntityType type;
|
EntityType type;
|
||||||
double mod;
|
double mod;
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public class KnockbackListener implements Listener {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!modifiers.isEmpty())
|
if (!modifiers.isEmpty())
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
registerEvents(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
|
@ -7,7 +7,6 @@
|
||||||
package eu.m724.tweaks.motd;
|
package eu.m724.tweaks.motd;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.events.*;
|
import com.comphenix.protocol.events.*;
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
import com.comphenix.protocol.reflect.StructureModifier;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
@ -15,14 +14,13 @@ import com.google.gson.JsonParseException;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import eu.m724.tweaks.DebugLogger;
|
import eu.m724.tweaks.DebugLogger;
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
import eu.m724.tweaks.TweaksConfig;
|
||||||
import eu.m724.tweaks.TweaksPlugin;
|
import eu.m724.tweaks.TweaksModule;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
import net.minecraft.SharedConstants;
|
import net.minecraft.SharedConstants;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.protocol.status.ServerStatus;
|
import net.minecraft.network.protocol.status.ServerStatus;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -31,34 +29,29 @@ import java.util.Arrays;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class MotdManager {
|
public class MotdModule extends TweaksModule {
|
||||||
private final TweaksPlugin plugin;
|
|
||||||
|
|
||||||
private Component[] motds;
|
private Component[] motds;
|
||||||
|
|
||||||
public MotdManager(TweaksPlugin plugin) {
|
@Override
|
||||||
this.plugin = plugin;
|
protected void onInit() {
|
||||||
}
|
|
||||||
|
|
||||||
public void init() {
|
|
||||||
// TODO adding more MOTD features would require checking whether to enable set
|
// TODO adding more MOTD features would require checking whether to enable set
|
||||||
|
|
||||||
String motdSetName = TweaksConfig.getConfig().motdSet();
|
String motdSetName = TweaksConfig.getConfig().motdSet();
|
||||||
String motdSetPath = "motd sets/" + motdSetName + ".txt";
|
String motdSetPath = "motd sets/" + motdSetName + ".txt";
|
||||||
File motdSetsFile = new File(plugin.getDataFolder(), motdSetPath);
|
File motdSetsFile = new File(getPlugin().getDataFolder(), motdSetPath);
|
||||||
|
|
||||||
// create "motd sets" directory
|
// create "motd sets" directory
|
||||||
motdSetsFile.getParentFile().mkdirs();
|
motdSetsFile.getParentFile().mkdirs();
|
||||||
|
|
||||||
// if this is a builtin set
|
// if this is a builtin set
|
||||||
if (!motdSetsFile.exists() && plugin.hasResource(motdSetPath))
|
if (!motdSetsFile.exists() && getPlugin().hasResource(motdSetPath))
|
||||||
plugin.saveResource(motdSetPath, false);
|
getPlugin().saveResource(motdSetPath, false);
|
||||||
|
|
||||||
if (!motdSetsFile.exists()) {
|
if (!motdSetsFile.exists()) {
|
||||||
throw new RuntimeException("MOTD set \"%s\" doesn't exist".formatted(motdSetName));
|
throw new RuntimeException("MOTD set \"%s\" doesn't exist".formatted(motdSetName));
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileContent = null;
|
String fileContent;
|
||||||
try {
|
try {
|
||||||
fileContent = Files.readString(motdSetsFile.toPath());
|
fileContent = Files.readString(motdSetsFile.toPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -73,9 +66,9 @@ public class MotdManager {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json = JsonParser.parseString(entry);
|
json = JsonParser.parseString(entry);
|
||||||
DebugLogger.fine("JSON line: " + entry);
|
DebugLogger.finer("JSON line: %s...", entry.substring(0, Math.min(entry.length(), 10)));
|
||||||
} catch (JsonParseException e) {
|
} catch (JsonParseException e) {
|
||||||
DebugLogger.fine("Not a JSON line: " + entry);
|
DebugLogger.finer("JSON line: %s...", entry.substring(0, Math.min(entry.length(), 10)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json == null) {
|
if (json == null) {
|
||||||
|
@ -86,17 +79,7 @@ public class MotdManager {
|
||||||
})
|
})
|
||||||
.toArray(Component[]::new);
|
.toArray(Component[]::new);
|
||||||
|
|
||||||
registerListener(plugin);
|
onPacketSend(PacketType.Status.Server.SERVER_INFO, (event) -> {
|
||||||
}
|
|
||||||
|
|
||||||
private void registerListener(Plugin plugin) {
|
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(
|
|
||||||
plugin,
|
|
||||||
ListenerPriority.NORMAL,
|
|
||||||
PacketType.Status.Server.SERVER_INFO
|
|
||||||
) {
|
|
||||||
@Override
|
|
||||||
public void onPacketSending(PacketEvent event) {
|
|
||||||
PacketContainer packet = event.getPacket();
|
PacketContainer packet = event.getPacket();
|
||||||
|
|
||||||
Component motd = motds[ThreadLocalRandom.current().nextInt(motds.length)];
|
Component motd = motds[ThreadLocalRandom.current().nextInt(motds.length)];
|
||||||
|
@ -119,7 +102,6 @@ public class MotdManager {
|
||||||
);
|
);
|
||||||
|
|
||||||
packet.getStructures().write(0, new InternalStructure(newStatus, new StructureModifier<>(ServerStatus.class)));
|
packet.getStructures().write(0, new InternalStructure(newStatus, new StructureModifier<>(ServerStatus.class)));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2024 Minecon724
|
* Copyright (C) 2025 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
@ -9,8 +9,6 @@ package eu.m724.tweaks.ping;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class PingChecker {
|
public class PingChecker {
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.pomodoro;
|
|
||||||
|
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class PomodoroManager {
|
|
||||||
private final Plugin plugin;
|
|
||||||
|
|
||||||
public PomodoroManager(Plugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(PluginCommand pomodoroCommand) {
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new PomodoroListener(), plugin);
|
|
||||||
new PomodoroRunnable(plugin).runTaskTimerAsynchronously(plugin, 0, 20L);
|
|
||||||
|
|
||||||
pomodoroCommand.setExecutor(new PomodoroCommands());
|
|
||||||
}
|
|
||||||
}
|
|
19
src/main/java/eu/m724/tweaks/pomodoro/PomodoroModule.java
Normal file
19
src/main/java/eu/m724/tweaks/pomodoro/PomodoroModule.java
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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.pomodoro;
|
||||||
|
|
||||||
|
import eu.m724.tweaks.TweaksModule;
|
||||||
|
|
||||||
|
public class PomodoroModule extends TweaksModule {
|
||||||
|
@Override
|
||||||
|
protected void onInit() {
|
||||||
|
registerEvents(new PomodoroListener());
|
||||||
|
new PomodoroRunnable(getPlugin()).runTaskTimerAsynchronously(getPlugin(), 0, 20L);
|
||||||
|
|
||||||
|
registerCommand("pomodoro", new PomodoroCommands());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2024 Minecon724
|
* Copyright (C) 2025 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
@ -8,36 +8,29 @@ package eu.m724.tweaks.redstone;
|
||||||
|
|
||||||
import eu.m724.tweaks.DebugLogger;
|
import eu.m724.tweaks.DebugLogger;
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
import eu.m724.tweaks.TweaksConfig;
|
||||||
import org.bukkit.command.PluginCommand;
|
import eu.m724.tweaks.TweaksModule;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class RedstoneManager {
|
public class RedstoneModule extends TweaksModule {
|
||||||
private final Plugin plugin;
|
private final RedstoneGateways redstoneGateways = new RedstoneGateways(getPlugin());
|
||||||
private final RedstoneGateways redstoneGateways;
|
|
||||||
|
|
||||||
private DatagramSocket socket;
|
private DatagramSocket socket;
|
||||||
private RedstoneStateUpdateRunnable runnable;
|
private RedstoneStateUpdateRunnable runnable;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onInit() {
|
||||||
|
RedstoneStore.init(getPlugin());
|
||||||
|
var gatewayItem = new GatewayItem(getPlugin());
|
||||||
|
|
||||||
public RedstoneManager(Plugin plugin) {
|
registerEvents(new RedstoneListener(redstoneGateways, gatewayItem));
|
||||||
this.plugin = plugin;
|
registerCommand("retstone", new RedstoneCommands(gatewayItem));
|
||||||
this.redstoneGateways = new RedstoneGateways(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(PluginCommand command) {
|
|
||||||
RedstoneStore.init(plugin);
|
|
||||||
var gatewayItem = new GatewayItem(plugin);
|
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new RedstoneListener(redstoneGateways, gatewayItem), plugin);
|
|
||||||
command.setExecutor(new RedstoneCommands(gatewayItem));
|
|
||||||
|
|
||||||
this.runnable = new RedstoneStateUpdateRunnable(redstoneGateways);
|
this.runnable = new RedstoneStateUpdateRunnable(redstoneGateways);
|
||||||
this.runnable.runTaskTimer(plugin, 0, 20); // TODO configurable
|
this.runnable.runTaskTimer(getPlugin(), 0, 20); // TODO configurable
|
||||||
|
|
||||||
var listenAddress = TweaksConfig.getConfig().redstoneListen().split(":");
|
var listenAddress = TweaksConfig.getConfig().redstoneListen().split(":");
|
||||||
InetSocketAddress bindAddress;
|
InetSocketAddress bindAddress;
|
||||||
|
@ -52,7 +45,6 @@ public class RedstoneManager {
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
throw new RuntimeException("Starting socket", e);
|
throw new RuntimeException("Starting socket", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSocket(SocketAddress bindAddress) throws SocketException {
|
private void initSocket(SocketAddress bindAddress) throws SocketException {
|
||||||
|
@ -96,12 +88,12 @@ public class RedstoneManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enqueueUpdate(int gatewayId, byte power) {
|
private void enqueueUpdate(int gatewayId, byte power) {
|
||||||
DebugLogger.fine("Update enqueued " + gatewayId + " " + power);
|
DebugLogger.finer("Update enqueued " + gatewayId + " " + power);
|
||||||
runnable.enqueueUpdate(gatewayId, power);
|
runnable.enqueueUpdate(gatewayId, power);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enqueueRetrieve(int gatewayId, Consumer<Byte> consumer) {
|
private void enqueueRetrieve(int gatewayId, Consumer<Byte> consumer) {
|
||||||
DebugLogger.fine("Retrieve enqueued " + gatewayId);
|
DebugLogger.finer("Retrieve enqueued " + gatewayId);
|
||||||
runnable.enqueueRetrieve(gatewayId, consumer);
|
runnable.enqueueRetrieve(gatewayId, consumer);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,18 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.sleep;
|
|
||||||
|
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class SleepManager {
|
|
||||||
public void init(Plugin plugin) {
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new SleepListener(), plugin);
|
|
||||||
if (!TweaksConfig.getConfig().sleepInstant())
|
|
||||||
new TimeForwardRunnable(plugin).runTaskTimer(plugin, 0, 1); // TODO maybe not
|
|
||||||
}
|
|
||||||
}
|
|
19
src/main/java/eu/m724/tweaks/sleep/SleepModule.java
Normal file
19
src/main/java/eu/m724/tweaks/sleep/SleepModule.java
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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.sleep;
|
||||||
|
|
||||||
|
import eu.m724.tweaks.TweaksModule;
|
||||||
|
|
||||||
|
public class SleepModule extends TweaksModule {
|
||||||
|
@Override
|
||||||
|
protected void onInit() {
|
||||||
|
registerEvents(new SleepListener());
|
||||||
|
|
||||||
|
if (!getConfig().sleepInstant())
|
||||||
|
new TimeForwardRunnable(getPlugin()).runTaskTimer(getPlugin(), 0, 1); // TODO maybe not
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@
|
||||||
package eu.m724.tweaks.swing;
|
package eu.m724.tweaks.swing;
|
||||||
|
|
||||||
import eu.m724.tweaks.DebugLogger;
|
import eu.m724.tweaks.DebugLogger;
|
||||||
|
import eu.m724.tweaks.TweaksModule;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
@ -14,29 +15,23 @@ import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class SwingManager implements Listener {
|
public class SwingModule extends TweaksModule implements Listener {
|
||||||
private final Plugin plugin;
|
|
||||||
|
|
||||||
private final Set<Material> tools = new HashSet<>();
|
private final Set<Material> tools = new HashSet<>();
|
||||||
|
|
||||||
public SwingManager(Plugin plugin) {
|
@Override
|
||||||
this.plugin = plugin;
|
protected void onInit() {
|
||||||
|
|
||||||
Arrays.stream(Material.values())
|
Arrays.stream(Material.values())
|
||||||
.filter(m -> m.name().contains("SWORD"))
|
.filter(m -> m.name().contains("SWORD"))
|
||||||
.forEach(tools::add);
|
.forEach(tools::add);
|
||||||
|
|
||||||
DebugLogger.fine("Tools: " + tools.size());
|
DebugLogger.finer("Tools: " + tools.size());
|
||||||
}
|
|
||||||
|
|
||||||
public void init() {
|
registerEvents(this);
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
|
@ -11,6 +11,7 @@ import eu.m724.tweaks.Language;
|
||||||
import eu.m724.tweaks.updater.cache.VersionedResource;
|
import eu.m724.tweaks.updater.cache.VersionedResource;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
|
@ -24,13 +25,15 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class UpdateChecker extends BukkitRunnable {
|
public class UpdateChecker extends BukkitRunnable {
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
private final File cacheFile;
|
||||||
private final Set<VersionedResource> resources;
|
private final Set<VersionedResource> resources;
|
||||||
|
|
||||||
static final Set<VersionedResource> availableUpdates = new HashSet<>();
|
static final Set<VersionedResource> availableUpdates = new HashSet<>();
|
||||||
static LocalTime lastChecked = null;
|
static LocalTime lastChecked = null;
|
||||||
|
|
||||||
UpdateChecker(Logger logger, Set<VersionedResource> resources) {
|
UpdateChecker(Logger logger, File cacheFile, Set<VersionedResource> resources) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.cacheFile = cacheFile;
|
||||||
this.resources = resources; // TODO make a copy?
|
this.resources = resources; // TODO make a copy?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +82,9 @@ public class UpdateChecker extends BukkitRunnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
checkAll();
|
checkAll();
|
||||||
|
|
||||||
try (FileOutputStream outputStream = new FileOutputStream(UpdaterManager.cacheFile)) {
|
DebugLogger.finer("Done checking, now saving");
|
||||||
|
cacheFile.getParentFile().mkdirs();
|
||||||
|
try (FileOutputStream outputStream = new FileOutputStream(cacheFile)) {
|
||||||
VersionCheckCache.writeAll(outputStream, resources.stream().map(VersionedResource::running).filter(Objects::nonNull).collect(Collectors.toSet()));
|
VersionCheckCache.writeAll(outputStream, resources.stream().map(VersionedResource::running).filter(Objects::nonNull).collect(Collectors.toSet()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -7,11 +7,10 @@
|
||||||
package eu.m724.tweaks.updater;
|
package eu.m724.tweaks.updater;
|
||||||
|
|
||||||
import eu.m724.tweaks.DebugLogger;
|
import eu.m724.tweaks.DebugLogger;
|
||||||
|
import eu.m724.tweaks.TweaksModule;
|
||||||
import eu.m724.tweaks.updater.cache.ResourceVersion;
|
import eu.m724.tweaks.updater.cache.ResourceVersion;
|
||||||
import eu.m724.tweaks.updater.cache.SpigotResource;
|
import eu.m724.tweaks.updater.cache.SpigotResource;
|
||||||
import eu.m724.tweaks.updater.cache.VersionedResource;
|
import eu.m724.tweaks.updater.cache.VersionedResource;
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -21,28 +20,21 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class UpdaterManager {
|
public class UpdaterModule extends TweaksModule {
|
||||||
static File cacheFile;
|
@Override
|
||||||
|
protected void onInit() {
|
||||||
private final Plugin plugin;
|
|
||||||
|
|
||||||
public UpdaterManager(Plugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
cacheFile = new File(plugin.getDataFolder(), "storage/cache/updater");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(PluginCommand updatesCommand){
|
|
||||||
// scan installed plugins
|
// scan installed plugins
|
||||||
Set<SpigotResource> resources = null;
|
Set<SpigotResource> resources;
|
||||||
try {
|
try {
|
||||||
resources = new PluginScanner(plugin).load();
|
resources = new PluginScanner(getPlugin()).load();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Loading plugins", e);
|
throw new RuntimeException("Loading plugins", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheFile.getParentFile().mkdirs(); // TODO move this somewhere else
|
|
||||||
|
|
||||||
// load installed versions from cache
|
// load installed versions from cache
|
||||||
|
var cacheFile = new File(getPlugin().getDataFolder(), "storage/cache/updater");
|
||||||
|
|
||||||
Set<ResourceVersion> installedVersions;
|
Set<ResourceVersion> installedVersions;
|
||||||
try (FileInputStream inputStream = new FileInputStream(cacheFile)) {
|
try (FileInputStream inputStream = new FileInputStream(cacheFile)) {
|
||||||
installedVersions = VersionCheckCache.loadAll(inputStream);
|
installedVersions = VersionCheckCache.loadAll(inputStream);
|
||||||
|
@ -60,9 +52,9 @@ public class UpdaterManager {
|
||||||
)).collect(Collectors.toSet());
|
)).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
|
||||||
new UpdateChecker(plugin.getLogger(), versionedResources)
|
new UpdateChecker(getPlugin().getLogger(), cacheFile, versionedResources)
|
||||||
.runTaskTimerAsynchronously(plugin, 600, 12 * 3600 * 20);
|
.runTaskTimerAsynchronously(getPlugin(), 600, 12 * 3600 * 20); // 12 hours
|
||||||
|
|
||||||
updatesCommand.setExecutor(new UpdaterCommands());
|
registerCommand("updates", new UpdaterCommands());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,24 +1,25 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2024 Minecon724
|
* Copyright (C) 2025 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package eu.m724.tweaks.worldborder;
|
package eu.m724.tweaks.worldborder;
|
||||||
|
|
||||||
|
import eu.m724.tweaks.TweaksModule;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import org.bukkit.craftbukkit.v1_21_R1.CraftWorld;
|
import org.bukkit.craftbukkit.v1_21_R1.CraftWorld;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.world.WorldLoadEvent;
|
import org.bukkit.event.world.WorldLoadEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class WorldBorderExpander implements Listener {
|
public class WorldBorderExpandModule extends TweaksModule implements Listener {
|
||||||
public void init(Plugin plugin) {
|
@Override
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
protected void onInit() {
|
||||||
|
registerEvents(this);
|
||||||
|
|
||||||
// because the plugin loads "post world"
|
// because the plugin loads "post world"
|
||||||
plugin.getServer().getWorlds().forEach(w -> {
|
getPlugin().getServer().getWorlds().forEach(w -> {
|
||||||
onWorldLoad(new WorldLoadEvent(w));
|
onWorldLoad(new WorldLoadEvent(w));
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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.events.PacketContainer;
|
||||||
|
import eu.m724.tweaks.TweaksModule;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
public class WorldBorderHideModule extends TweaksModule {
|
||||||
|
private static final int EXTENSION_RADIUS = 512;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onInit() {
|
||||||
|
getPlugin().getServer().getMessenger().registerOutgoingPluginChannel(getPlugin(), "tweaks724:worldborder");
|
||||||
|
|
||||||
|
byte[] infoArray = ByteBuffer.allocate(4).putInt(EXTENSION_RADIUS).array();
|
||||||
|
|
||||||
|
onPacketSend(PacketType.Play.Server.INITIALIZE_BORDER, (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(getPlugin(), "tweaks724:worldborder", infoArray);
|
||||||
|
});
|
||||||
|
|
||||||
|
onPacketSend(PacketType.Play.Server.SET_BORDER_SIZE, (event) -> {
|
||||||
|
PacketContainer packet = event.getPacket();
|
||||||
|
// diameter
|
||||||
|
packet.getDoubles().write(0, packet.getDoubles().read(0) + EXTENSION_RADIUS * 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
onPacketSend(PacketType.Play.Server.SET_BORDER_WARNING_DISTANCE, (event) -> {
|
||||||
|
PacketContainer packet = event.getPacket();
|
||||||
|
// warning distance
|
||||||
|
packet.getIntegers().write(0, packet.getIntegers().read(0) + EXTENSION_RADIUS);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,74 +0,0 @@
|
||||||
/*
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue