Add prefix, nickname, chat colors
This commit is contained in:
parent
c5e8f1cc54
commit
707b99f58d
12 changed files with 544 additions and 16 deletions
|
@ -3,23 +3,15 @@ package dev.zontreck.otemod;
|
|||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import com.mojang.serialization.Codec;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.world.BiomeModifier;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
|
@ -30,7 +22,6 @@ import net.minecraftforge.fml.config.ModConfig;
|
|||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
|
||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
|
@ -39,17 +30,23 @@ import net.minecraftforge.registries.ForgeRegistries;
|
|||
import org.slf4j.Logger;
|
||||
|
||||
import dev.zontreck.otemod.blocks.ModBlocks;
|
||||
import dev.zontreck.otemod.chat.ChatServerOverride;
|
||||
import dev.zontreck.otemod.commands.DelHomeCommand;
|
||||
import dev.zontreck.otemod.commands.FlyCommand;
|
||||
import dev.zontreck.otemod.commands.HomeCommand;
|
||||
import dev.zontreck.otemod.commands.HomesCommand;
|
||||
import dev.zontreck.otemod.commands.SetHomeCommand;
|
||||
import dev.zontreck.otemod.commands.profilecmds.ChatColorCommand;
|
||||
import dev.zontreck.otemod.commands.profilecmds.NameColorCommand;
|
||||
import dev.zontreck.otemod.commands.profilecmds.NickCommand;
|
||||
import dev.zontreck.otemod.commands.profilecmds.PrefixColorCommand;
|
||||
import dev.zontreck.otemod.commands.profilecmds.PrefixCommand;
|
||||
import dev.zontreck.otemod.configs.OTEServerConfig;
|
||||
import dev.zontreck.otemod.configs.Profile;
|
||||
import dev.zontreck.otemod.database.Database;
|
||||
import dev.zontreck.otemod.database.Database.DatabaseConnectionException;
|
||||
import dev.zontreck.otemod.events.EventHandler;
|
||||
import dev.zontreck.otemod.items.ModItems;
|
||||
import dev.zontreck.otemod.ore.Modifier;
|
||||
import dev.zontreck.otemod.ore.Modifier.ModifierOfBiomes;
|
||||
|
||||
// The value here should match an entry in the META-INF/mods.toml file
|
||||
|
@ -63,6 +60,8 @@ public class OTEMod
|
|||
public static final String MODIFY_BIOMES = "modify_biomes";
|
||||
public static final ResourceLocation MODIFY_BIOMES_RL = new ResourceLocation(OTEMod.MOD_ID, MODIFY_BIOMES);
|
||||
public static Database DB=null;
|
||||
public static Map<String,Profile> PROFILES = new HashMap<String,Profile>();
|
||||
|
||||
|
||||
public OTEMod()
|
||||
{
|
||||
|
@ -83,6 +82,7 @@ public class OTEMod
|
|||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new ChatServerOverride());
|
||||
|
||||
ModBlocks.register(bus);
|
||||
ModItems.register(bus);
|
||||
|
@ -92,7 +92,11 @@ public class OTEMod
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @DISABLED DUE TO PlayerEvent.PlayerLoggedInEvent
|
||||
* with that event, we just handle this there. This code is kept as a reference until the new player gear functions have been added.
|
||||
* Prereq for new player gear: OTEMod Vault API
|
||||
*
|
||||
@SubscribeEvent
|
||||
public void onSpawn(EntityJoinLevelEvent ev){
|
||||
Level w = ev.getLevel();
|
||||
|
@ -114,10 +118,12 @@ public class OTEMod
|
|||
Inventory i = p.getInventory();
|
||||
|
||||
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*
|
||||
*/
|
||||
|
||||
public boolean firstJoin(Player p){
|
||||
|
||||
|
@ -149,6 +155,14 @@ public class OTEMod
|
|||
DelHomeCommand.register(ev.getDispatcher());
|
||||
|
||||
FlyCommand.register(ev.getDispatcher());
|
||||
|
||||
ChatColorCommand.register(ev.getDispatcher());
|
||||
NameColorCommand.register(ev.getDispatcher());
|
||||
PrefixColorCommand.register(ev.getDispatcher());
|
||||
PrefixCommand.register(ev.getDispatcher());
|
||||
NickCommand.register(ev.getDispatcher());
|
||||
|
||||
|
||||
}
|
||||
|
||||
// You can use SubscribeEvent and let the Event Bus discover methods to call
|
||||
|
|
|
@ -1,6 +1,30 @@
|
|||
package dev.zontreck.otemod.chat;
|
||||
|
||||
public class ChatColor {
|
||||
public enum ColorOptions{
|
||||
Black,
|
||||
Dark_Blue,
|
||||
Dark_Green,
|
||||
Dark_Aqua,
|
||||
Dark_Red,
|
||||
Dark_Purple,
|
||||
Gold,
|
||||
Gray,
|
||||
Dark_Gray,
|
||||
Blue,
|
||||
Green,
|
||||
Aqua,
|
||||
Red,
|
||||
Light_Purple,
|
||||
Yellow,
|
||||
White,
|
||||
MinecoinGold,
|
||||
Underline,
|
||||
Bold,
|
||||
Italic,
|
||||
Strikethrough,
|
||||
Crazy
|
||||
}
|
||||
public static char CODE = '§';
|
||||
public static String BLACK = build("0");
|
||||
public static String DARK_BLUE = build("1");
|
||||
|
@ -37,4 +61,21 @@ public class ChatColor {
|
|||
{
|
||||
return RESET+WHITE;
|
||||
}
|
||||
|
||||
public static String from(String nick){
|
||||
switch(nick.toLowerCase()){
|
||||
case "black":
|
||||
{
|
||||
return BLACK;
|
||||
}
|
||||
case "crazy":
|
||||
{
|
||||
return CRAZY;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return RESET+CRAZY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
144
src/main/java/dev/zontreck/otemod/chat/ChatServerOverride.java
Normal file
144
src/main/java/dev/zontreck/otemod/chat/ChatServerOverride.java
Normal file
|
@ -0,0 +1,144 @@
|
|||
package dev.zontreck.otemod.chat;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.configs.PlayerFlyCache;
|
||||
import dev.zontreck.otemod.configs.Profile;
|
||||
import dev.zontreck.otemod.database.Database;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
|
||||
@EventBusSubscriber(modid=OTEMod.MOD_ID, bus=Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public class ChatServerOverride {
|
||||
|
||||
@OnlyIn(Dist.DEDICATED_SERVER)
|
||||
@SubscribeEvent
|
||||
public void onJoin(final PlayerEvent.PlayerLoggedInEvent ev)
|
||||
{
|
||||
//Player joined, send custom alert
|
||||
|
||||
// Download user data from database
|
||||
try{
|
||||
Connection c = OTEMod.DB.getConnection();
|
||||
String SQL = "SELECT * FROM `profiles` WHERE `uuid`=?;";
|
||||
PreparedStatement pst = c.prepareStatement(SQL);
|
||||
pst.setString(1,ev.getEntity().getStringUUID());
|
||||
|
||||
ResultSet rs = pst.executeQuery();
|
||||
boolean has_profile=false;
|
||||
while(rs.next())
|
||||
{
|
||||
has_profile=true;
|
||||
|
||||
|
||||
OTEMod.PROFILES.put(ev.getEntity().getStringUUID(), new Profile(rs.getString("username"), rs.getString("prefix"), rs.getString("nickname"), rs.getString("name_color"), ev.getEntity().getStringUUID(), rs.getString("prefix_color"), rs.getString("chat_color")));
|
||||
}
|
||||
|
||||
if(!has_profile)
|
||||
{
|
||||
// Create profile!
|
||||
ServerPlayer play = (ServerPlayer)ev.getEntity();
|
||||
Profile p = Profile.factory(play);
|
||||
OTEMod.PROFILES.put(play.getStringUUID(), p);
|
||||
p.commit(); // Commits the profile to the server
|
||||
|
||||
ev.getEntity().displayClientMessage(Component.literal(ChatColor.BOLD+ ChatColor.DARK_GRAY + "["+ChatColor.DARK_GREEN + "OTEMOD" + ChatColor.DARK_GRAY + "] "+ChatColor.DARK_GREEN + "First join! Your server profile has been created"), false);
|
||||
}
|
||||
}catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
Profile prof = Profile.get_profile_of(ev.getEntity().getStringUUID());
|
||||
if(prof == null){
|
||||
OTEMod.LOGGER.error("FATAL: Profile was null for "+ev.getEntity().getName().getString());
|
||||
return;
|
||||
}
|
||||
|
||||
ChatServerOverride.broadcast(Component.literal(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_GREEN + "+" + ChatColor.DARK_GRAY + "] "+ ChatColor.BOLD + ChatColor.DARK_AQUA + prof.nickname), ev.getEntity().getServer());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.DEDICATED_SERVER)
|
||||
@SubscribeEvent
|
||||
public void onLeave(final PlayerEvent.PlayerLoggedOutEvent ev)
|
||||
{
|
||||
// Get player profile, send disconnect alert, then commit profile and remove it from memory
|
||||
Profile px = Profile.get_profile_of(ev.getEntity().getStringUUID());
|
||||
|
||||
if(px==null)return;
|
||||
|
||||
// Send the alert
|
||||
ChatServerOverride.broadcast(Component.literal(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_RED + "-" + ChatColor.DARK_GRAY + "] "+ChatColor.BOLD + ChatColor.DARK_AQUA + px.nickname), ev.getEntity().getServer());
|
||||
|
||||
px.commit();
|
||||
OTEMod.PROFILES.remove(ev.getEntity().getStringUUID());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.DEDICATED_SERVER)
|
||||
@SubscribeEvent
|
||||
public void onClone(final PlayerEvent.Clone ev)
|
||||
{
|
||||
// Fix for fly ability not copying to new instance on death or other circumstances
|
||||
Player old = ev.getOriginal();
|
||||
Player n = ev.getEntity();
|
||||
|
||||
PlayerFlyCache c = PlayerFlyCache.cachePlayer((ServerPlayer)old);
|
||||
c.Assert((ServerPlayer)n);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.DEDICATED_SERVER)
|
||||
@SubscribeEvent
|
||||
public void onChat(final ServerChatEvent ev){
|
||||
// Player has chatted, apply override
|
||||
ServerPlayer sp = ev.getPlayer();
|
||||
// Get profile
|
||||
Profile XD = Profile.get_profile_of(sp.getStringUUID());
|
||||
|
||||
// Override the chat!
|
||||
String prefixStr = "";
|
||||
if(XD.prefix != ""){
|
||||
prefixStr = ChatColor.DARK_GRAY + "[" + ChatColor.BOLD + XD.prefix_color + XD.prefix + ChatColor.resetChat() + ChatColor.DARK_GRAY + "] ";
|
||||
}
|
||||
String nameStr = ChatColor.resetChat() + "< "+ XD.name_color + XD.nickname + ChatColor.resetChat() + " >";
|
||||
String message = ": "+XD.chat_color + ev.getMessage().getString();
|
||||
Style hover = Style.EMPTY;
|
||||
hover=hover.withFont(Style.DEFAULT_FONT).withHoverEvent(HoverTip.get(ChatColor.MINECOIN_GOLD+"User Name: "+XD.username));
|
||||
ev.setCanceled(true);
|
||||
|
||||
ChatServerOverride.broadcast(Component.literal(prefixStr+nameStr+message).setStyle(hover), ev.getPlayer().server);
|
||||
}
|
||||
|
||||
|
||||
public static void broadcastAboveToolBar(Component message, MinecraftServer s)
|
||||
{
|
||||
// This will broadcast to all players
|
||||
for(ServerPlayer play : s.getPlayerList().getPlayers())
|
||||
{
|
||||
play.displayClientMessage(message, true); // Send the message!
|
||||
}
|
||||
}
|
||||
public static void broadcast(Component message, MinecraftServer s)
|
||||
{
|
||||
// This will broadcast to all players
|
||||
for(ServerPlayer play : s.getPlayerList().getPlayers())
|
||||
{
|
||||
play.displayClientMessage(message, false); // Send the message!
|
||||
}
|
||||
}
|
||||
}
|
|
@ -127,7 +127,7 @@ public class HomeCommand {
|
|||
|
||||
MobEffectInstance inst = new MobEffectInstance(MobEffects.DARKNESS, 200, 1, true, true);
|
||||
MobEffectInstance regen = new MobEffectInstance(MobEffects.REGENERATION, 200, 1, true, true);
|
||||
MobEffectInstance invul = new MobEffectInstance(MobEffects.LEVITATION, 200, 1, true, true);
|
||||
MobEffectInstance invul = new MobEffectInstance(MobEffects.LEVITATION, 75, 1, true, true);
|
||||
|
||||
|
||||
p.addEffect(inst);
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package dev.zontreck.otemod.commands;
|
||||
|
||||
public class TPACommand {
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package dev.zontreck.otemod.commands.profilecmds;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.chat.ChatColor;
|
||||
import dev.zontreck.otemod.chat.ChatColor.ColorOptions;
|
||||
import dev.zontreck.otemod.configs.Profile;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
|
||||
public class ChatColorCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("ccolor")
|
||||
.executes(c->setchatcolor(c.getSource(), ColorOptions.White))
|
||||
.then(Commands.argument("color", EnumArgument.enumArgument(ChatColor.ColorOptions.class))//StringArgumentType.string())
|
||||
.executes(c -> setchatcolor(c.getSource(), c.getArgument("color", ChatColor.ColorOptions.class)))// EnumArgument.getS(c, "color")))
|
||||
)
|
||||
);
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
public static int setchatcolor(CommandSourceStack source, ColorOptions string) {
|
||||
|
||||
// Chat Color has a registry of colors that we can use to map back to our desired color
|
||||
String actual_color = string.toString();
|
||||
// To code
|
||||
String colorcoded = ChatColor.from(actual_color);
|
||||
|
||||
// Get profile
|
||||
if(source.getPlayer()==null){
|
||||
source.sendFailure(Component.literal(ChatColor.DARK_RED+"Only a player can use this command"));
|
||||
return 1;
|
||||
}
|
||||
Profile p = Profile.get_profile_of(source.getPlayer().getStringUUID());
|
||||
p.chat_color = colorcoded;
|
||||
p.commit();
|
||||
OTEMod.PROFILES.put(source.getPlayer().getStringUUID(), p);
|
||||
|
||||
source.sendSuccess(Component.literal(ChatColor.DARK_GRAY+ "["+ChatColor.DARK_GREEN+ "OTEMOD" + ChatColor.DARK_GRAY + "] "+ChatColor.DARK_PURPLE + "Your chat color has been updated"), false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package dev.zontreck.otemod.commands.profilecmds;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.chat.ChatColor;
|
||||
import dev.zontreck.otemod.chat.ChatColor.ColorOptions;
|
||||
import dev.zontreck.otemod.configs.Profile;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
|
||||
public class NameColorCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("ncolor")
|
||||
.executes(c->setchatcolor(c.getSource(), ColorOptions.White))
|
||||
.then(Commands.argument("color", EnumArgument.enumArgument(ChatColor.ColorOptions.class))//StringArgumentType.string())
|
||||
.executes(c -> setchatcolor(c.getSource(), c.getArgument("color", ChatColor.ColorOptions.class)))// EnumArgument.getS(c, "color")))
|
||||
)
|
||||
);
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
public static int setchatcolor(CommandSourceStack source, ColorOptions string) {
|
||||
|
||||
// Chat Color has a registry of colors that we can use to map back to our desired color
|
||||
String actual_color = string.toString();
|
||||
// To code
|
||||
String colorcoded = ChatColor.from(actual_color);
|
||||
|
||||
// Get profile
|
||||
if(source.getPlayer()==null){
|
||||
source.sendFailure(Component.literal(ChatColor.DARK_RED+"Only a player can use this command"));
|
||||
return 1;
|
||||
}
|
||||
Profile p = Profile.get_profile_of(source.getPlayer().getStringUUID());
|
||||
p.name_color = colorcoded;
|
||||
p.commit();
|
||||
OTEMod.PROFILES.put(source.getPlayer().getStringUUID(), p);
|
||||
|
||||
source.sendSuccess(Component.literal(ChatColor.DARK_GRAY+ "["+ChatColor.DARK_GREEN+ "OTEMOD" + ChatColor.DARK_GRAY + "] "+ChatColor.DARK_PURPLE + "Your name color has been updated"), false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package dev.zontreck.otemod.commands.profilecmds;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.chat.ChatColor;
|
||||
import dev.zontreck.otemod.chat.ChatColor.ColorOptions;
|
||||
import dev.zontreck.otemod.configs.Profile;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
|
||||
public class NickCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("nick")
|
||||
.executes(c->setchatcolor(c.getSource(), c.getSource().getPlayer().getName().getString()))
|
||||
.then(Commands.argument("new_name", StringArgumentType.string())//StringArgumentType.string())
|
||||
.executes(c -> setchatcolor(c.getSource(), StringArgumentType.getString(c, "new_name")))// EnumArgument.getS(c, "color")))
|
||||
)
|
||||
);
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
public static int setchatcolor(CommandSourceStack source, String string) {
|
||||
|
||||
// Get profile
|
||||
if(source.getPlayer()==null){
|
||||
source.sendFailure(Component.literal(ChatColor.DARK_RED+"Only a player can use this command"));
|
||||
return 1;
|
||||
}
|
||||
Profile p = Profile.get_profile_of(source.getPlayer().getStringUUID());
|
||||
p.nickname = string;
|
||||
p.commit();
|
||||
OTEMod.PROFILES.put(source.getPlayer().getStringUUID(), p);
|
||||
|
||||
source.sendSuccess(Component.literal(ChatColor.DARK_GRAY+ "["+ChatColor.DARK_GREEN+ "OTEMOD" + ChatColor.DARK_GRAY + "] "+ChatColor.DARK_PURPLE + "Your nickname has been updated"), false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package dev.zontreck.otemod.commands.profilecmds;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.chat.ChatColor;
|
||||
import dev.zontreck.otemod.chat.ChatColor.ColorOptions;
|
||||
import dev.zontreck.otemod.configs.Profile;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
|
||||
public class PrefixColorCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("pcolor")
|
||||
.executes(c->setchatcolor(c.getSource(), ColorOptions.White))
|
||||
.then(Commands.argument("color", EnumArgument.enumArgument(ChatColor.ColorOptions.class))//StringArgumentType.string())
|
||||
.executes(c -> setchatcolor(c.getSource(), c.getArgument("color", ChatColor.ColorOptions.class)))// EnumArgument.getS(c, "color")))
|
||||
)
|
||||
);
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
public static int setchatcolor(CommandSourceStack source, ColorOptions string) {
|
||||
|
||||
// Chat Color has a registry of colors that we can use to map back to our desired color
|
||||
String actual_color = string.toString();
|
||||
// To code
|
||||
String colorcoded = ChatColor.from(actual_color);
|
||||
|
||||
// Get profile
|
||||
if(source.getPlayer()==null){
|
||||
source.sendFailure(Component.literal(ChatColor.DARK_RED+"Only a player can use this command"));
|
||||
return 1;
|
||||
}
|
||||
Profile p = Profile.get_profile_of(source.getPlayer().getStringUUID());
|
||||
p.name_color = colorcoded;
|
||||
p.commit();
|
||||
OTEMod.PROFILES.put(source.getPlayer().getStringUUID(), p);
|
||||
|
||||
source.sendSuccess(Component.literal(ChatColor.DARK_GRAY+ "["+ChatColor.DARK_GREEN+ "OTEMOD" + ChatColor.DARK_GRAY + "] "+ChatColor.DARK_PURPLE + "Your prefix color has been updated"), false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package dev.zontreck.otemod.commands.profilecmds;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.chat.ChatColor;
|
||||
import dev.zontreck.otemod.chat.ChatColor.ColorOptions;
|
||||
import dev.zontreck.otemod.configs.Profile;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
|
||||
public class PrefixCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("prefix")
|
||||
.executes(c->setchatcolor(c.getSource(), "Member"))
|
||||
.then(Commands.argument("new_prefix", StringArgumentType.string())//StringArgumentType.string())
|
||||
.executes(c -> setchatcolor(c.getSource(), StringArgumentType.getString(c, "new_prefix")))// EnumArgument.getS(c, "color")))
|
||||
)
|
||||
);
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
public static int setchatcolor(CommandSourceStack source, String string) {
|
||||
|
||||
// Get profile
|
||||
if(source.getPlayer()==null){
|
||||
source.sendFailure(Component.literal(ChatColor.DARK_RED+"Only a player can use this command"));
|
||||
return 1;
|
||||
}
|
||||
Profile p = Profile.get_profile_of(source.getPlayer().getStringUUID());
|
||||
p.prefix = string;
|
||||
p.commit();
|
||||
OTEMod.PROFILES.put(source.getPlayer().getStringUUID(), p);
|
||||
|
||||
source.sendSuccess(Component.literal(ChatColor.DARK_GRAY+ "["+ChatColor.DARK_GREEN+ "OTEMOD" + ChatColor.DARK_GRAY + "] "+ChatColor.DARK_PURPLE + "Your prefix has been updated"), false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
69
src/main/java/dev/zontreck/otemod/configs/Profile.java
Normal file
69
src/main/java/dev/zontreck/otemod/configs/Profile.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package dev.zontreck.otemod.configs;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.chat.ChatColor;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class Profile {
|
||||
public String username;
|
||||
public String user_id;
|
||||
public String prefix;
|
||||
public String nickname;
|
||||
public String name_color; // ChatColor.X
|
||||
public String prefix_color;
|
||||
public String chat_color;
|
||||
|
||||
public Profile(String username, String prefix, String nickname, String name_color, String ID, String prefix_color, String chat_color) {
|
||||
this.username = username;
|
||||
this.prefix = prefix;
|
||||
this.nickname = nickname;
|
||||
this.name_color = name_color;
|
||||
this.user_id = ID;
|
||||
this.prefix_color = prefix_color;
|
||||
this.chat_color = chat_color;
|
||||
}
|
||||
|
||||
|
||||
public static Profile get_profile_of(String UUID)
|
||||
{
|
||||
if(OTEMod.PROFILES.containsKey(UUID)){
|
||||
return OTEMod.PROFILES.get(UUID);
|
||||
}else {
|
||||
// profile does not exist!
|
||||
// how can this happen?
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Profile factory(ServerPlayer play)
|
||||
{
|
||||
Profile p = new Profile(play.getName().getString(), "Member", play.getDisplayName().getString(), ChatColor.GREEN, play.getStringUUID(), ChatColor.AQUA, ChatColor.WHITE);
|
||||
return p;
|
||||
}
|
||||
|
||||
public void commit()
|
||||
{
|
||||
// Send player to server!
|
||||
Connection con = OTEMod.DB.getConnection();
|
||||
String SQL = "REPLACE INTO `profiles` (username, uuid, prefix, nickname, name_color, prefix_color, chat_color) values (?, ?, ?, ?, ?, ?, ?);";
|
||||
try {
|
||||
PreparedStatement pstat = con.prepareStatement(SQL);
|
||||
pstat.setString(1, username);
|
||||
pstat.setString(2, user_id);
|
||||
pstat.setString(3, prefix);
|
||||
pstat.setString(4, nickname);
|
||||
pstat.setString(5, name_color);
|
||||
pstat.setString(6, prefix_color);
|
||||
pstat.setString(7, chat_color);
|
||||
|
||||
pstat.execute();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,5 +25,8 @@
|
|||
"dev.zontreck.otemod.msgs.homes.goto.fail": "§cHome was not found, or a error occured",
|
||||
"dev.zontreck.otemod.msgs.homes.goto.success": "§2Home found, warping home now",
|
||||
"dev.zontreck.otemod.msgs.homes.del.success": "§2Home was deleted successfully",
|
||||
"dev.zontreck.otemod.msgs.homes.del.fail": "§cHome could not be deleted due to an error"
|
||||
"dev.zontreck.otemod.msgs.homes.del.fail": "§cHome could not be deleted due to an error",
|
||||
"minecraft.player.joined": "",
|
||||
"minecraft.player.joined.renamed": "",
|
||||
"minecraft.player.quit": ""
|
||||
}
|
Reference in a new issue