mirror of
https://github.com/CompeyDev/stinky-mod.git
synced 2024-12-12 12:50:39 +00:00
feat: join & leave messages + ;ec command
This commit is contained in:
parent
c35b30dfcc
commit
d996d21ced
1 changed files with 50 additions and 3 deletions
|
@ -1,9 +1,21 @@
|
|||
package xyz.devcomp;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import xyz.devcomp.config.ConfigHandler;
|
||||
import xyz.devcomp.config.ConfigModel;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
|
||||
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -20,6 +32,41 @@ public class Stinky implements ModInitializer {
|
|||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
|
||||
LOGGER.info("Hello Fabric world!");
|
||||
LOGGER.info("Hello from Stinky!");
|
||||
|
||||
// TODO: Cleanup logic with a shared function for both join & leave events
|
||||
// FIXME: Load & Unload events are fired on death and respawn too, not just join and leave
|
||||
|
||||
ServerEntityEvents.ENTITY_LOAD.register((Entity entity, ServerLevel world) -> {
|
||||
ArrayList<String> joinMsgStrings = Stinky.Config.getJoinMessageStrings();
|
||||
String formattedUsername = entity.getName().toString().replaceAll("literal", "").replaceAll("\\{", "")
|
||||
.replaceAll("\\}", "");
|
||||
|
||||
// Get a random join message and display it as a green system message
|
||||
entity.sendSystemMessage(Component.literal(String.format(
|
||||
joinMsgStrings.get((int) (Math.random() * joinMsgStrings.size())), formattedUsername))
|
||||
.setStyle(Style.EMPTY.withColor(43520)));
|
||||
});
|
||||
|
||||
ServerEntityEvents.ENTITY_UNLOAD.register((Entity entity, ServerLevel world) -> {
|
||||
ArrayList<String> leaveMsgStrings = Stinky.Config.getLeaveMessageStrings();
|
||||
String formattedUsername = entity.getName().toString().replaceAll("literal", "").replaceAll("\\{", "")
|
||||
.replaceAll("\\}", "");
|
||||
|
||||
// Get a random leave message and display it as a red system message
|
||||
entity.sendSystemMessage(Component.literal(String.format(
|
||||
leaveMsgStrings.get((int) (Math.random() * leaveMsgStrings.size())), formattedUsername))
|
||||
.setStyle(Style.EMPTY.withColor(11141120)));
|
||||
});
|
||||
|
||||
ServerMessageEvents.CHAT_MESSAGE.register((PlayerChatMessage msg, ServerPlayer plr, ChatType.Bound bound) -> {
|
||||
String msgString = msg.signedContent();
|
||||
|
||||
LOGGER.info("msgString: ", msgString);
|
||||
|
||||
if (msgString == ";ec") {
|
||||
plr.setHealth(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue