Skip to content

Commit

Permalink
Added welcome message for new players
Browse files Browse the repository at this point in the history
  • Loading branch information
preprocessor committed Apr 12, 2024
1 parent 5c7d394 commit 6c19cc3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/lusiiplugin/mixin/PlayerManagerMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package lusiiplugin.mixin;

import net.minecraft.server.MinecraftServer;
import net.minecraft.server.entity.player.EntityPlayerMP;
import net.minecraft.server.player.PlayerManager;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.io.File;

@Mixin(value = PlayerManager.class, remap = false)
public abstract class PlayerManagerMixin {

@Shadow
@Final
private MinecraftServer server;

@Inject(method = "addPlayer", at = @At("HEAD"))
private void welcomeMessage(EntityPlayerMP player, CallbackInfo ci) {
File playerData = new File("world/players/" + player.username + ".dat");

if (!playerData.exists()) {
server.serverCommandHandler.sendMessageToAllPlayers("§4Welcome §3" + player.username + "§4 to the server!" );
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/lusiiplugin.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"EntityTNTMixin",
"NetServerHandlerMixin",
"NicknameCommandMixin",
"PlayerManagerMixin",
"SpawnCommandMixin",
"TreecapitatorMixin"
],
Expand Down

0 comments on commit 6c19cc3

Please sign in to comment.