Skip to content

Commit

Permalink
Drop util config and move more to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Jan 13, 2025
1 parent a990a70 commit 510b462
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 46 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# GlobalLinkServer Plugin

### `server.properties`
```properties
allow-nether=false
generate-structures=false
generator-settings={"biome"\:"minecraft\:the_void","layers"\:[{"block"\:"minecraft\:air","height"\:1}]}
level-type=minecraft\:flat
motd=§aGeyserMC §bLinking §fServer
spawn-protection=200
```

### `bukkit.yml`
```yaml
settings:
allow-end: false
```
57 changes: 36 additions & 21 deletions src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -108,6 +111,22 @@ public void onEnable() {
);
});

// Set game rules
World world = getServer().getWorld("world");
world.setGameRule(GameRule.ANNOUNCE_ADVANCEMENTS, false);
world.setGameRule(GameRule.DO_MOB_SPAWNING, false);
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
world.setGameRule(GameRule.FALL_DAMAGE, false);
world.setGameRule(GameRule.DO_IMMEDIATE_RESPAWN, true);
world.setGameRule(GameRule.RANDOM_TICK_SPEED, 0);
world.setGameRule(GameRule.SHOW_DEATH_MESSAGES, false);

// Make nighttime
world.setTime(18000);

getServer().setDefaultGameMode(GameMode.ADVENTURE);

LOGGER.info("Started Global Linking Server plugin!");
}

Expand Down Expand Up @@ -135,30 +154,29 @@ public void onCommands(PlayerCommandSendEvent event) {

@EventHandler
public void onPlayerLoad(PlayerJoinEvent event) {
if (config.util().hideJoinLeaveMessages()) event.joinMessage(null);
Utils.processJoin(event.getPlayer());
event.joinMessage(null);

if (config.util().hidePlayers()) {
Bukkit.getOnlinePlayers().forEach(player -> {
event.getPlayer().hidePlayer(this, player);
player.hidePlayer(this, event.getPlayer());
});
}
event.getPlayer().setPersistent(false);
event.getPlayer().setAllowFlight(true);

// Hide all players from each other
Bukkit.getOnlinePlayers().forEach(player -> {
event.getPlayer().hidePlayer(this, player);
player.hidePlayer(this, event.getPlayer());
});

if (config.util().respawnOnJoin()) Utils.fakeRespawn(event.getPlayer());
Utils.processJoin(event.getPlayer());
}

@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
if (config.util().hideJoinLeaveMessages()) event.quitMessage(null);
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) {
if (event.getCause() == EntityDamageEvent.DamageCause.VOID && event.getEntity() instanceof Player player) {
event.setCancelled(true);

Utils.fakeRespawn(player);
Expand All @@ -167,33 +185,30 @@ public void onEntityDamage(EntityDamageEvent event) {

@EventHandler
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (config.util().preventHunger()) {
if (event.getFoodLevel() < event.getEntity().getFoodLevel()) {
event.setCancelled(true);
}
if (event.getFoodLevel() < event.getEntity().getFoodLevel()) {
event.setCancelled(true);
}
}

@EventHandler
public void onDeath(PlayerDeathEvent event) {
if (config.util().hideDeathMessages()) event.deathMessage(null);
event.deathMessage(null);
}

@EventHandler
public void onPlayerChat(AsyncChatEvent event) {
if (config.util().disableChat()) event.setCancelled(true);
event.setCancelled(true);
}

@EventHandler
public void onServerListPing(PaperServerListPingEvent event) {
if (!config.util().hidePlayerCount()) return;
event.getListedPlayers().clear();
event.setNumPlayers(0);
event.setMaxPlayers(1);
}

@EventHandler
public void onPlayerRecipeDiscover(PlayerRecipeDiscoverEvent event) {
if (config.util().disableRecipeDiscover()) event.setCancelled(true);
event.setCancelled(true);
}
}
15 changes: 1 addition & 14 deletions src/main/java/org/geysermc/globallinkserver/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,12 @@
package org.geysermc.globallinkserver.config;

public record Config(
Database database,
Util util
Database database
) {
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,
boolean hidePlayerCount,
boolean disableRecipeDiscover
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,12 @@ public static Config readConfig(JavaPlugin plugin) {
plugin.saveConfig();

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"),
util.getBoolean("hide-player-count"),
util.getBoolean("disable-recipe-discover")
));
}
}

0 comments on commit 510b462

Please sign in to comment.