diff --git a/src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java b/src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java index 073ccaf..94d7d08 100644 --- a/src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java +++ b/src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java @@ -12,6 +12,7 @@ import io.papermc.paper.command.brigadier.Commands; import io.papermc.paper.command.brigadier.argument.ArgumentTypes; +import io.papermc.paper.event.player.AsyncChatEvent; import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager; import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; import net.kyori.adventure.text.Component; @@ -20,6 +21,9 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerCommandSendEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -36,6 +40,7 @@ public class GlobalLinkServer extends JavaPlugin implements Listener { public static Logger LOGGER; public static LinkManager linkManager; + public static Config config; public final static Component LINK_INSTRUCTIONS = Component.text("Run the ").color(NamedTextColor.AQUA) .append(Component.text("`/link`", NamedTextColor.GREEN)) @@ -49,7 +54,7 @@ public class GlobalLinkServer extends JavaPlugin implements Listener { public void onEnable() { LOGGER = getLogger(); - Config config = ConfigReader.readConfig(this); + config = ConfigReader.readConfig(this); linkManager = new LinkManager(config); CommandUtils commandUtils = new CommandUtils(linkManager); @@ -128,11 +133,52 @@ public void onCommands(PlayerCommandSendEvent event) { @EventHandler public void onPlayerLoad(PlayerJoinEvent event) { + if (config.util().hideJoinLeaveMessages()) event.joinMessage(null); Utils.processJoin(event.getPlayer()); + + if (config.util().hidePlayers()) { + Bukkit.getOnlinePlayers().forEach(player -> { + event.getPlayer().hidePlayer(this, player); + player.hidePlayer(this, event.getPlayer()); + }); + } + + if (config.util().respawnOnJoin()) Utils.fakeRespawn(event.getPlayer()); } @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { + if (config.util().hideJoinLeaveMessages()) event.quitMessage(null); Utils.processLeave(event.getPlayer()); } + + @EventHandler + public void onEntityDamage(EntityDamageEvent event) { + if (config.util().voidTeleport() + && event.getEntity() instanceof Player player + && event.getCause() == EntityDamageEvent.DamageCause.VOID) { + event.setCancelled(true); + + Utils.fakeRespawn(player); + } + } + + @EventHandler + public void onFoodLevelChange(FoodLevelChangeEvent event) { + if (config.util().preventHunger()) { + if (event.getFoodLevel() < event.getEntity().getFoodLevel()) { + event.setCancelled(true); + } + } + } + + @EventHandler + public void onDeath(PlayerDeathEvent event) { + if (config.util().hideDeathMessages()) event.deathMessage(null); + } + + @EventHandler + public void onPlayerChat(AsyncChatEvent event) { + if (config.util().disableChat()) event.setCancelled(true); + } } diff --git a/src/main/java/org/geysermc/globallinkserver/config/Config.java b/src/main/java/org/geysermc/globallinkserver/config/Config.java index 46b1d60..f8c9575 100644 --- a/src/main/java/org/geysermc/globallinkserver/config/Config.java +++ b/src/main/java/org/geysermc/globallinkserver/config/Config.java @@ -6,8 +6,23 @@ package org.geysermc.globallinkserver.config; public record Config( - String hostname, - String username, - String password, - String database -) {} + Database database, + Util util +) { + public record Database( + String hostname, + String username, + String password, + String database + ) {} + + public record Util( + boolean hideJoinLeaveMessages, + boolean hideDeathMessages, + boolean hidePlayers, + boolean disableChat, + boolean voidTeleport, + boolean preventHunger, + boolean respawnOnJoin + ) {} +} diff --git a/src/main/java/org/geysermc/globallinkserver/config/ConfigReader.java b/src/main/java/org/geysermc/globallinkserver/config/ConfigReader.java index 8ccf7a3..7e2fe56 100644 --- a/src/main/java/org/geysermc/globallinkserver/config/ConfigReader.java +++ b/src/main/java/org/geysermc/globallinkserver/config/ConfigReader.java @@ -14,9 +14,22 @@ public static Config readConfig(JavaPlugin plugin) { var config = plugin.getConfig(); plugin.saveConfig(); - return new Config(config.getString("hostname"), - config.getString("username"), - config.getString("password"), - config.getString("database")); + var database = config.getConfigurationSection("database"); + var util = config.getConfigurationSection("util"); + + return new Config(new Config.Database( + database.getString("hostname"), + database.getString("username"), + database.getString("password"), + database.getString("database") + ), new Config.Util( + util.getBoolean("hide-join-leave-messages"), + util.getBoolean("hide-death-messages"), + util.getBoolean("hide-players"), + util.getBoolean("disable-chat"), + util.getBoolean("void-teleport"), + util.getBoolean("prevent-hunger"), + util.getBoolean("respawn-on-join") + )); } } diff --git a/src/main/java/org/geysermc/globallinkserver/link/LinkManager.java b/src/main/java/org/geysermc/globallinkserver/link/LinkManager.java index 0474bd1..b8314e2 100644 --- a/src/main/java/org/geysermc/globallinkserver/link/LinkManager.java +++ b/src/main/java/org/geysermc/globallinkserver/link/LinkManager.java @@ -41,8 +41,8 @@ public class LinkManager { public LinkManager(Config config) { try { Class.forName("org.mariadb.jdbc.Driver"); - dataSource = new MariaDbPoolDataSource("jdbc:mariadb://" + config.hostname() + "/" + config.database() - + "?user=" + config.username() + "&password=" + config.password() + "&minPoolSize=1&maxPoolSize=3"); + dataSource = new MariaDbPoolDataSource("jdbc:mariadb://" + config.database().hostname() + "/" + config.database().database() + + "?user=" + config.database().username() + "&password=" + config.database().password() + "&minPoolSize=1&maxPoolSize=3"); } catch (ClassNotFoundException exception) { throw new RuntimeException("Cannot find required class to load the MariaDB database"); } diff --git a/src/main/java/org/geysermc/globallinkserver/util/Utils.java b/src/main/java/org/geysermc/globallinkserver/util/Utils.java index 63d0a15..8432f19 100644 --- a/src/main/java/org/geysermc/globallinkserver/util/Utils.java +++ b/src/main/java/org/geysermc/globallinkserver/util/Utils.java @@ -10,7 +10,9 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerTeleportEvent; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.floodgate.api.FloodgateApi; import org.geysermc.floodgate.api.player.FloodgatePlayer; @@ -88,4 +90,10 @@ public static void sendCurrentLinkInfo(Player player) { ); } } + + public static void fakeRespawn(Player player) { + player.teleport(player.getWorld().getSpawnLocation(), PlayerTeleportEvent.TeleportCause.COMMAND); + player.setFallDistance(0); + player.setHealth(player.getAttribute(Attribute.MAX_HEALTH).getValue()); + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 262fbd7..e94ccd0 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,4 +1,14 @@ -hostname: 127.0.0.1 -username: global_link -password: some_pass -database: global_link_dev \ No newline at end of file +database: + hostname: 127.0.0.1 + username: global_link + password: some_pass + database: global_link_dev + +util: + hide-join-leave-messages: true + hide-death-messages: true + hide-players: true + disable-chat: true + void-teleport: true + prevent-hunger: true + respawn-on-join: true