Skip to content

Commit

Permalink
1.0.3:
Browse files Browse the repository at this point in the history
- Properly set the server's default gamemode
- Various codestyle fixes
  • Loading branch information
onebeastchris committed Dec 28, 2023
1 parent 55ef1d3 commit 0c86dba
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20+build.1
loader_version=0.14.21

# Mod Properties
mod_version=1.0.2
mod_version=1.0.3
maven_group=net.onebeastofchris
archives_base_name=visitors

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/onebeastchris/command/discordCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package onebeastchris.command;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.tree.LiteralCommandNode;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.MutableText;
Expand All @@ -14,12 +13,11 @@
import static net.minecraft.server.command.CommandManager.literal;

public class discordCommand {
public static LiteralCommandNode register(CommandDispatcher<ServerCommandSource> dispatcher) {
return dispatcher.register(
literal("discord").executes(context -> discordCommand(context.getSource())));
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("discord").executes(context -> run(context.getSource())));
}

public static int discordCommand(ServerCommandSource source) {
public static int run(ServerCommandSource source) {
Supplier<Text> discordInviteMessage = () -> Text.of(visitors.config.getDiscordInviteMessage());
Supplier<Text> discordLink = () -> {
Text link = Text.of("[" + visitors.config.getInviteLink() + "]");
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/onebeastchris/event/ServerJoinEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
public class ServerJoinEvent {

public static final HashMap<ServerPlayerEntity, PlayerInfoStorage> tempStorage = new HashMap<>();

public static void register() {
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
ServerPlayerEntity player = handler.getPlayer().networkHandler.player;
GameProfile profile = player.getGameProfile();

if (PlayerDataUtil.isVisitor(profile)) {
visitors.LOGGER.info(profile.getName() + " joined the server as a visitor.");

// update visitor map with player value
PlayerDataUtil.addVisitor(profile, player);

tempStorage.put(player, new PlayerInfoStorage(
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/onebeastchris/event/ServerLeaveEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.world.GameMode;
import onebeastchris.util.PlayerDataUtil;
import onebeastchris.util.PlayerInfoStorage;
import onebeastchris.util.Register;
import onebeastchris.visitors;


Expand All @@ -17,7 +17,7 @@ public static void register() {
GameProfile profile = player.getGameProfile();

if (PlayerDataUtil.isVisitor(profile)) {
onLeave(player, profile);
onLeave(player, profile);
}
});
}
Expand All @@ -31,7 +31,7 @@ public static void onLeave(ServerPlayerEntity player, GameProfile profile){
double z = storage.position().getZ();

player.teleport(storage.world(), x, y, z, 0, 0);
player.changeGameMode(GameMode.DEFAULT);
player.changeGameMode(Register.server.getDefaultGameMode());
player.sendMessage(Text.of(visitors.config.getWelcomeMemberMessage()), true);
player.setCustomName(storage.name());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public abstract class ServerConfigListMixin {
private void add(ServerConfigEntry<?> entry, CallbackInfo ci) {
if (entry instanceof WhitelistEntry whitelistEntry) {
try {
//noinspection unchecked
GameProfile profile = ((ServerConfigEntryMixin.ServerConfigEntryInvoker<GameProfile>) whitelistEntry).callGetKey();
visitors.LOGGER.debug("WhitelistEntry: " + profile.getName());
PlayerDataUtil.changeStatus(profile);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/onebeastchris/util/PlayerDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class PlayerDataUtil {

public static HashMap<GameProfile, ServerPlayerEntity> visitorMap = new HashMap<>();
public static final HashMap<GameProfile, ServerPlayerEntity> visitorMap = new HashMap<>();

public static void addFutureVisitor(GameProfile gameProfile){
visitorMap.put(gameProfile, null);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/onebeastchris/util/Register.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package onebeastchris.util;

import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.minecraft.server.MinecraftServer;
import onebeastchris.command.discordCommand;
import onebeastchris.event.ServerJoinEvent;
import onebeastchris.event.ServerLeaveEvent;
Expand All @@ -9,6 +11,8 @@

public class Register {

public static MinecraftServer server;

public static void registerCommand() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> discordCommand.register(dispatcher));
}
Expand All @@ -20,5 +24,7 @@ public static void registerAll() {
if (visitors.config.getDiscordCommand() && !visitors.config.getInviteLink().equals("https://discord.gg/INVITE_LINK")) {
registerCommand();
}

ServerLifecycleEvents.SERVER_STARTED.register((minecraftServer) -> server = minecraftServer);
}
}
2 changes: 1 addition & 1 deletion src/main/java/onebeastchris/visitors.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class visitors implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("visitors");

public static ConfigUtil config = new ConfigUtil();
public static final ConfigUtil config = new ConfigUtil();

@Override
public void onInitialize() {
Expand Down

0 comments on commit 0c86dba

Please sign in to comment.