Skip to content

Commit

Permalink
1.12.2-0.2.0-beta Release
Browse files Browse the repository at this point in the history
Added configuration file and a command to manually set a name colour
  • Loading branch information
uberifix committed Feb 7, 2019
1 parent 00983b9 commit cb1abeb
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 141 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "1.12.2-0.1.0-beta"
version = "1.12.2-0.2.0-beta"
group = "network.pxl8.colouredchat" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "colouredchat"

Expand Down
61 changes: 0 additions & 61 deletions src/main/java/network/pxl8/colouredchat/ChatListener.java

This file was deleted.

17 changes: 10 additions & 7 deletions src/main/java/network/pxl8/colouredchat/ColouredChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import network.pxl8.colouredchat.lib.LibMisc;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import network.pxl8.colouredchat.chat.ChatCommand;
import network.pxl8.colouredchat.lib.LibMeta;
import network.pxl8.colouredchat.proxy.Proxy;
import org.apache.logging.log4j.Logger;


@Mod(modid = LibMisc.MOD_ID, version = LibMisc.VERSION, acceptableRemoteVersions = "*")
@Mod(modid = LibMeta.MOD_ID, version = LibMeta.VERSION, acceptableRemoteVersions = "*")
public class ColouredChat {
@SidedProxy(clientSide = "network.pxl8.colouredchat.proxy.ClientProxy", serverSide = "network.pxl8.colouredchat.proxy.CommonProxy", modId = LibMisc.MOD_ID)
@SidedProxy(clientSide = LibMeta.CLIENT_PROXY, serverSide = LibMeta.SERVER_PROXY, modId = LibMeta.MOD_ID)
public static Proxy proxy;

@Mod.Instance
public static ColouredChat instance;

public static Logger log;

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
proxy.preInit();
log = event.getModLog();
}

public void init(FMLInitializationEvent event) {
Expand All @@ -34,4 +32,9 @@ public void init(FMLInitializationEvent event) {
public void postInit(FMLPostInitializationEvent event) {
proxy.postInit();
}

@Mod.EventHandler
public void serverLoad(FMLServerStartingEvent event) {
event.registerServerCommand(new ChatCommand());
}
}
131 changes: 131 additions & 0 deletions src/main/java/network/pxl8/colouredchat/chat/ChatCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package network.pxl8.colouredchat.chat;

import com.google.common.collect.Lists;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import network.pxl8.colouredchat.config.Configuration;
import network.pxl8.colouredchat.data.colourData;
import network.pxl8.colouredchat.lib.LibColour;
import network.pxl8.colouredchat.lib.LibMeta;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

public class ChatCommand extends CommandBase{
public ChatCommand() {
aliases = new ArrayList<>();
aliases.add(LibMeta.MOD_ID);
aliases.add("colchat");
colours = new ArrayList<>();
colours.add("DARK_GREEN");
colours.add("DARK_AQUA");
colours.add("DARK_RED");
colours.add("DARK_PURPLE");
colours.add("GOLD");
colours.add("BLUE");
colours.add("GREEN");
colours.add("AQUA");
colours.add("RED");
colours.add("LIGHT_PURPLE");
colours.add("YELLOW");
}

private final List<String> aliases;
private final List<String> colours;

@Override
@Nonnull
public String getName() {
return "colouredchat";
}

@Override
@Nonnull
public String getUsage(@Nonnull ICommandSender sender) {
return "colouredchat clear|set <colour>";
}

@Override
@Nonnull
public List<String> getAliases() {
return aliases;
}

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 1) throw new WrongUsageException(getUsage(sender));

String cmd = args[0].toLowerCase(Locale.ENGLISH);
if (cmd.equals("set")) {
if (!Configuration.command_config.allowCustomColours) throw new CommandException("Command is disabled");
if (args.length < 2) throw new WrongUsageException("Please specify <colour>");

String colour = args[1].toUpperCase(Locale.ENGLISH);
switch (colour) {
case ("DARK_GREEN"): break;
case ("DARK_AQUA"): break;
case ("DARK_RED"): break;
case ("DARK_PURPLE"): break;
case ("GOLD"): break;
case ("BLUE"): break;
case ("GREEN"): break;
case ("AQUA"): break;
case ("RED"): break;
case ("LIGHT_PURPLE"): break;
case ("YELLOW"): break;
default : throw new WrongUsageException("Not a valid colour option");
}
if (LibColour.getColourFromName(colour) == null) throw new WrongUsageException("Colour returned null");
colourData data = colourData.get(sender.getEntityWorld());

if (sender instanceof EntityPlayer) {
data.addDefaultColour((EntityPlayerMP) sender, LibColour.getColourFromName(colour));
}

data.markDirty();
sender.sendMessage(new TextComponentString(TextFormatting.GRAY + "Set default name colour to " + LibColour.getColourFromName(colour) + colour));
} else if (cmd.equals("clear")) {
if (!Configuration.command_config.allowCustomColours) throw new CommandException("Command is disabled");
colourData data = colourData.get(sender.getEntityWorld());

if (sender instanceof EntityPlayer) {
data.removeDefaultColour((EntityPlayerMP) sender);
}

data.markDirty();
sender.sendMessage(new TextComponentString(TextFormatting.GRAY + "Cleared custom name colour"));
} else { throw new WrongUsageException(getUsage(sender)); }

}

@Override
@Nonnull
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetpos) {
Boolean cmd_set = args[0].equalsIgnoreCase("set");

if (args.length == 1) {
return getListOfStringsMatchingLastWord(args, Lists.newArrayList("clear", "set"));
} else if (args.length == 2 && cmd_set) {
return getListOfStringsMatchingLastWord(args, colours);
}

return Collections.emptyList();
}

@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
return true;
}
}
48 changes: 48 additions & 0 deletions src/main/java/network/pxl8/colouredchat/chat/ChatListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package network.pxl8.colouredchat.chat;

import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.event.ServerChatEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import network.pxl8.colouredchat.config.Configuration;
import network.pxl8.colouredchat.data.colourData;
import network.pxl8.colouredchat.lib.LibColour;

import java.util.EventListener;

public class ChatListener implements EventListener{
@SubscribeEvent
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
colourData data = colourData.get(event.player.world);
data.addRandomColour(event.player, LibColour.randomColour());
data.markDirty();
}
@SubscribeEvent
public void onPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event) {
colourData data = colourData.get(event.player.world);
data.removeRandomColour(event.player);
data.markDirty();
}

@SubscribeEvent
public void onServerMsg( ServerChatEvent event) {
colourData data = colourData.get(event.getPlayer().world);
event.setCanceled(true);

String delimL = Configuration.chat_config.nameDelimiterL;
String prefix = data.getRandomColour(event.getPlayer());
if (data.getDefaultColour(event.getPlayer()) != null) {
prefix = data.getDefaultColour(event.getPlayer());
}
String player = event.getPlayer().getDisplayNameString();
String suffix = TextFormatting.RESET.toString();
String delimR = Configuration.chat_config.nameDelimiterR;

String orgmsg = event.getMessage();
String newmsg = delimL + prefix + player + suffix + delimR + orgmsg;

FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().sendMessage(ForgeHooks.newChatWithLinks(newmsg));
}
}
51 changes: 51 additions & 0 deletions src/main/java/network/pxl8/colouredchat/config/Configuration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package network.pxl8.colouredchat.config;

import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import network.pxl8.colouredchat.lib.LibMeta;

@Config(modid = LibMeta.MOD_ID, name = LibMeta.MOD_ID)
public class Configuration {

public static ChatConf chat_config = new ChatConf();
public static ColourConf colour_config = new ColourConf();
public static CommandConf command_config = new CommandConf();

public static class ChatConf {
@Config.Comment("Modify left delimiter (Default:<)")
@Config.Name("Left Delimiter")
public String nameDelimiterL = "<";
@Config.Comment("Modify right delimiter (Default:> )")
@Config.Name("Right Delimiter")
public String nameDelimiterR = "> ";
}
public static class ColourConf {
public boolean DARK_GREEN = true;
public boolean DARK_AQUA = true;
public boolean DARK_RED = true;
public boolean DARK_PURPLE = true;
public boolean GOLD = true;
public boolean BLUE = true;
public boolean GREEN = true;
public boolean AQUA = true;
public boolean RED = true;
public boolean LIGHT_PURPLE = true;
public boolean YELLOW = true;
}
public static class CommandConf {
@Config.Comment("Allow players to customise their default colour")
public boolean allowCustomColours = true;
}

@Mod.EventBusSubscriber
public static class ConfigSync {
@SubscribeEvent
public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event){
if (event.getModID().equals(LibMeta.MOD_ID)) { ConfigManager.sync(LibMeta.MOD_ID, Config.Type.INSTANCE); }
}
}

}
Loading

0 comments on commit cb1abeb

Please sign in to comment.