-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
12 changed files
with
394 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/main/java/network/pxl8/colouredchat/chat/ChatCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
src/main/java/network/pxl8/colouredchat/chat/ChatListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
src/main/java/network/pxl8/colouredchat/config/Configuration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); } | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.