From 6c1e0da6b670b36b814410ba70dca0a0f1a2c383 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 28 Nov 2024 18:43:37 +0100 Subject: [PATCH] yes --- .forgejo/workflows/build.yml | 4 +- .../java/eu/m724/tweaks/TweaksConfig.java | 13 ++++- .../java/eu/m724/tweaks/TweaksPlugin.java | 7 ++- .../eu/m724/tweaks/auth/AuthListener.java | 26 --------- .../java/eu/m724/tweaks/auth/AuthManager.java | 17 ------ .../java/eu/m724/tweaks/chat/ChatManager.java | 4 +- .../m724/tweaks/compass/CompassListener.java | 8 ++- .../m724/tweaks/hardcore/HardcoreManager.java | 35 ++++++++++++ .../{MotdListener.java => MotdManager.java} | 4 +- .../eu/m724/tweaks/player/MusicPlayer.java | 4 +- .../eu/m724/tweaks/updater/UpdateChecker.java | 9 +++- .../m724/tweaks/updater/UpdaterManager.java | 13 +++-- .../worldborder/WorldBorderInfoPayload.java | 28 ---------- src/main/resources/config.yml | 16 +++++- src/main/resources/motd sets/2006.txt | 53 +++++++++++++++++++ 15 files changed, 144 insertions(+), 97 deletions(-) delete mode 100644 src/main/java/eu/m724/tweaks/auth/AuthListener.java delete mode 100644 src/main/java/eu/m724/tweaks/auth/AuthManager.java create mode 100644 src/main/java/eu/m724/tweaks/hardcore/HardcoreManager.java rename src/main/java/eu/m724/tweaks/motd/{MotdListener.java => MotdManager.java} (98%) delete mode 100644 src/main/java/eu/m724/tweaks/worldborder/WorldBorderInfoPayload.java create mode 100644 src/main/resources/motd sets/2006.txt diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index 9136ecb..c10e77e 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -9,10 +9,10 @@ jobs: - name: Install JDK run: apt install --no-install-recommends -y openjdk-21-jdk-headless maven git nodejs - name: Clone repository - run: git clone https://git.m724.eu/Minecon724/mutils.git . + run: git clone https://git.m724.eu/Minecon724/tweaks724.git . - name: Build run: mvn clean package - name: Upload artifacts uses: https://github.com/actions/upload-artifact@v3 with: - path: target/mutils-*.jar \ No newline at end of file + path: target/tweaks-*.jar \ No newline at end of file diff --git a/src/main/java/eu/m724/tweaks/TweaksConfig.java b/src/main/java/eu/m724/tweaks/TweaksConfig.java index b8647f3..f624840 100644 --- a/src/main/java/eu/m724/tweaks/TweaksConfig.java +++ b/src/main/java/eu/m724/tweaks/TweaksConfig.java @@ -37,7 +37,10 @@ public record TweaksConfig( boolean pomodoroEnabled, boolean pomodoroForce, - boolean updaterEnabled + boolean updaterEnabled, + + boolean hardcoreEnabled, + float hardcoreChance ) { public static final int CONFIG_VERSION = 1; private static TweaksConfig config; @@ -87,6 +90,11 @@ public record TweaksConfig( boolean pomodoroEnabled = config.getBoolean("pomodoro.enabled"); boolean pomodoroForce = config.getBoolean("pomodoro.force"); + boolean updaterEnabled = config.getBoolean("updater.enabled"); + + boolean hardcoreEnabled = config.getBoolean("hardcore.enabled"); + float hardcoreChance = (float) config.getDouble("hardcore.chance"); + TweaksConfig.config = new TweaksConfig( isProtocolLib, hideWorldBorder, @@ -96,7 +104,8 @@ public record TweaksConfig( chatEnabled, chatLocalEvents, chatDefaultName, compassEnabled, compassWidth, compassPrecision, pomodoroEnabled, pomodoroForce, - true // TODO + updaterEnabled, + hardcoreEnabled, hardcoreChance ); return TweaksConfig.config; diff --git a/src/main/java/eu/m724/tweaks/TweaksPlugin.java b/src/main/java/eu/m724/tweaks/TweaksPlugin.java index 8470cd1..0868361 100644 --- a/src/main/java/eu/m724/tweaks/TweaksPlugin.java +++ b/src/main/java/eu/m724/tweaks/TweaksPlugin.java @@ -9,7 +9,8 @@ package eu.m724.tweaks; import eu.m724.tweaks.chat.ChatCommands; import eu.m724.tweaks.chat.ChatManager; import eu.m724.tweaks.door.DoorManager; -import eu.m724.tweaks.motd.MotdListener; +import eu.m724.tweaks.hardcore.HardcoreManager; +import eu.m724.tweaks.motd.MotdManager; import eu.m724.tweaks.ping.F3NameListener; import eu.m724.tweaks.ping.PingChecker; import eu.m724.tweaks.ping.PingCommands; @@ -56,7 +57,7 @@ public class TweaksPlugin extends JavaPlugin { if (config.motdEnabled()) { try { - new MotdListener(this).init(); + new MotdManager(this).init(); } catch (IOException e) { getLogger().severe("Failed to initialize MOTD extension"); throw new RuntimeException(e); @@ -79,5 +80,7 @@ public class TweaksPlugin extends JavaPlugin { throw new RuntimeException(e); } } + + new HardcoreManager().init(this); } } diff --git a/src/main/java/eu/m724/tweaks/auth/AuthListener.java b/src/main/java/eu/m724/tweaks/auth/AuthListener.java deleted file mode 100644 index 954b8c8..0000000 --- a/src/main/java/eu/m724/tweaks/auth/AuthListener.java +++ /dev/null @@ -1,26 +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.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerLoginEvent; - -public class AuthListener implements Listener { - private final AuthManager authManager; - - public AuthListener(AuthManager authManager) { - this.authManager = authManager; - } - - @EventHandler - public void onPlayerLogin(PlayerLoginEvent event) { - Player player = event.getPlayer(); - String hostname = event.getHostname(); - } -} diff --git a/src/main/java/eu/m724/tweaks/auth/AuthManager.java b/src/main/java/eu/m724/tweaks/auth/AuthManager.java deleted file mode 100644 index 909c3d7..0000000 --- a/src/main/java/eu/m724/tweaks/auth/AuthManager.java +++ /dev/null @@ -1,17 +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.plugin.Plugin; - -public class AuthManager { - private final Plugin plugin; - - public AuthManager(Plugin plugin) { - this.plugin = plugin; - } -} diff --git a/src/main/java/eu/m724/tweaks/chat/ChatManager.java b/src/main/java/eu/m724/tweaks/chat/ChatManager.java index ab7a8c3..5a30e1a 100644 --- a/src/main/java/eu/m724/tweaks/chat/ChatManager.java +++ b/src/main/java/eu/m724/tweaks/chat/ChatManager.java @@ -174,9 +174,7 @@ public class ChatManager { public void deleteChatRoom(ChatRoom chatRoom) { roomIdMap.remove(chatRoom.id); ChatRoomLoader.getFile(plugin, chatRoom.id).delete(); - chatRoom.players.forEach(player -> { - setPlayerChatRoom(getById(defaultRoom), player); - }); + chatRoom.players.forEach(player -> setPlayerChatRoom(getById(defaultRoom), player)); } /** diff --git a/src/main/java/eu/m724/tweaks/compass/CompassListener.java b/src/main/java/eu/m724/tweaks/compass/CompassListener.java index 4835f6f..3f1c188 100644 --- a/src/main/java/eu/m724/tweaks/compass/CompassListener.java +++ b/src/main/java/eu/m724/tweaks/compass/CompassListener.java @@ -102,7 +102,7 @@ public class CompassListener implements Listener { // for (Map.Entry entry : currentPoints.entrySet()) { - double distance = -wrapModRange(yaw - entry.getKey(), -180, 180); + double distance = -wrapYawRange(yaw - entry.getKey()); int index = (int) (distance / precision + width / 2.0); if (index >= 0 && index < width) { @@ -122,10 +122,8 @@ public class CompassListener implements Listener { } } - private double wrapModRange(double value, double start, double stop) { - double range = stop - start; - double result = start + (value - start - Math.floor((value - start) / range) * range); - return result == stop ? start : result; + private double wrapYawRange(double value) { + return wrapMod(value, 360) - 180; } private double wrapMod(double value, double stop) { diff --git a/src/main/java/eu/m724/tweaks/hardcore/HardcoreManager.java b/src/main/java/eu/m724/tweaks/hardcore/HardcoreManager.java new file mode 100644 index 0000000..0dc632b --- /dev/null +++ b/src/main/java/eu/m724/tweaks/hardcore/HardcoreManager.java @@ -0,0 +1,35 @@ +/* + * 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.hardcore; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.*; +import eu.m724.tweaks.TweaksConfig; +import org.bukkit.plugin.Plugin; + +public class HardcoreManager { + private final float chance = TweaksConfig.getConfig().hardcoreChance(); + + public void init(Plugin plugin) { + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter( + plugin, + ListenerPriority.NORMAL, + PacketType.Play.Server.LOGIN + ) { + @Override + public void onPacketSending(PacketEvent event) { + PacketContainer packet = event.getPacket(); + int entityId = packet.getIntegers().read(0); + + if (chance > ((48271 * entityId) % 65537) / 65537f) // gotta be fast + // the "is hardcore" boolean https://wiki.vg/Protocol#Login_.28play.29 + packet.getBooleans().write(0, true); + } + }); + } +} diff --git a/src/main/java/eu/m724/tweaks/motd/MotdListener.java b/src/main/java/eu/m724/tweaks/motd/MotdManager.java similarity index 98% rename from src/main/java/eu/m724/tweaks/motd/MotdListener.java rename to src/main/java/eu/m724/tweaks/motd/MotdManager.java index d5623db..a3357a7 100644 --- a/src/main/java/eu/m724/tweaks/motd/MotdListener.java +++ b/src/main/java/eu/m724/tweaks/motd/MotdManager.java @@ -27,12 +27,12 @@ import java.util.Arrays; import java.util.Optional; import java.util.concurrent.ThreadLocalRandom; -public class MotdListener { +public class MotdManager { private final Plugin plugin; private Component[] motds; - public MotdListener(Plugin plugin) { + public MotdManager(Plugin plugin) { this.plugin = plugin; } diff --git a/src/main/java/eu/m724/tweaks/player/MusicPlayer.java b/src/main/java/eu/m724/tweaks/player/MusicPlayer.java index 684efe1..a1b475e 100644 --- a/src/main/java/eu/m724/tweaks/player/MusicPlayer.java +++ b/src/main/java/eu/m724/tweaks/player/MusicPlayer.java @@ -63,9 +63,7 @@ public class MusicPlayer { for (int i=0; i installedVersions; try (FileInputStream inputStream = new FileInputStream(cacheFile)) { installedVersions = VersionCheckCache.loadAll(inputStream); + } catch (FileNotFoundException e) { + installedVersions = new HashSet<>(); } - Set versionedResources = installedVersions.stream() - .map(rv -> new VersionedResource( - resources.stream().filter(r -> r.resourceId() == rv.resourceId()).findFirst().get(), - rv, - null + final Set ivf = installedVersions; + Set versionedResources = resources.stream() + .map(res -> new VersionedResource( + res, ivf.stream().filter(iv -> iv.resourceId() == res.resourceId()).findFirst().orElse(null), null )).collect(Collectors.toSet()); diff --git a/src/main/java/eu/m724/tweaks/worldborder/WorldBorderInfoPayload.java b/src/main/java/eu/m724/tweaks/worldborder/WorldBorderInfoPayload.java deleted file mode 100644 index ed0055d..0000000 --- a/src/main/java/eu/m724/tweaks/worldborder/WorldBorderInfoPayload.java +++ /dev/null @@ -1,28 +0,0 @@ -package eu.m724.tweaks.worldborder; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; - -// TODO I could do this with API but yeah I'm more comfortable with this - -public record WorldBorderInfoPayload(int extensionRadius) implements CustomPacketPayload { - private static final Type TYPE = - new Type<>(ResourceLocation.tryBuild("tweaks724", "worldborder")); - - public static final StreamCodec STREAM_CODEC = - CustomPacketPayload.codec(WorldBorderInfoPayload::write, WorldBorderInfoPayload::new); - - public Type type() { - return TYPE; - } - - private WorldBorderInfoPayload(FriendlyByteBuf byteBuf) { - this(byteBuf.readVarInt()); - } - - private void write(FriendlyByteBuf byteBuf) { - byteBuf.writeVarInt(extensionRadius); - } -} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 457a2f8..294ac09 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -49,7 +49,21 @@ pomodoro: # Players will be unable to join the server during break and will be kicked a short time after pomodoro ends force: true +# Updates your plugins +# The plugin must be from SpigotMC and its versioning should match that on SpigotMC +# Allow "api.spigotmc.org" on your firewall if you have one +# Watch the console for setup instructions +updater: + enabled: true + +# Hardcore hearts. It just makes hearts with the eyes like on hardcore, nothing more. +# WARNING: "Respawn" label will be "spectate world". The button still respawns though +hardcore: + enabled: true + # 0.0 - 1.0 decimal. This is if you want to make it like an Easter egg + chance: 1.0 + # Finally, thank you for downloading Tweaks724, I hope you enjoy! # Don't modify unless told to -magic number dont modify this: 1 \ No newline at end of file +magic number don't modify this: 1 \ No newline at end of file diff --git a/src/main/resources/motd sets/2006.txt b/src/main/resources/motd sets/2006.txt new file mode 100644 index 0000000..ead9745 --- /dev/null +++ b/src/main/resources/motd sets/2006.txt @@ -0,0 +1,53 @@ +Zlikwidować całkowicie dla młodzieży alkohol, papierosy i narkotyki + +Usprawnić w naszym Białymstoku komunikację miejską. +Miejską i dalekobieżną. + +Tak, bo nasza komunikacja jest bardzo, bardzo słaba, bardzo zła + +Otworzyć zakłady, miejsca pracy dla młodzieży i dla ludzi. Tak. I chcę bardzo, bardzo to zrobić. + +Usprawnić w naszym mieście… w całym… na całym Podlasiu. + +Żeby nie było bandyctwa, żeby nie było złodziejstwa, żeby nie było niczego. + +Żeby starsi ludzie mogli przejść. +Bo nawet teraz dochodzi do mnie skargi, postulaty. + +Apelują starszy ludzie w podeszłym wieku, że młodzież zaczepia. + +A ja się nie dziwię się, że młodzież starszych ludzi zaczepia, napada… napadają i tak dalej. + +Bo młodzież nie ma pracy, nie ma pracy. +Zakłady nasze w Białymstoku są rozwalane. + +Zamiast budowane, zamiast usprawnić Białystok, żeby miejsca pracy. + +Tak jak mleczarnie tu w Białymstoku, tak jak Spomasz w Starosielcach, tak jak… i inne zakłady są rozwalane. + +Żeby policja pilnowała całego naszego porządku. +Bo od tego jest policja i straż miejska. + +Od tego oni są. Od tego są oni. Od tego są! + +A w urzędzie u mnie miejskim będzie ład i porządek. +Nie będzie biurokractwa, nie będzie łachmaństwa. + +W zimową porą będą szykować architekci plany budowy dróg. Plany budowy dróg. + +Podkreślam jeszcze raz – plany budowy dróg. + +A na wiosnę wyjdziemy z budową ulic i… ulic. +Bo jakie mamy drogi? Jakie mamy? + +Co się stało się pod Jeżewem? +Co się stało się? + +A kierowcy też będą przez policję surowo karani za alkohol, za papierosy, za wszystko! + +I jeszcze też usprawnię granicę w Kuźnicy i w Bobrownikach. + +Że granica między Białorusią a nami będzie naprawdę. +Naprawdę będzie granica. + +Że nie będzie przemytu ani papierosów, ani narkotyków, ani alkoholu. \ No newline at end of file