Skip to content

Commit

Permalink
Rephrased and added some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Scribee committed Apr 30, 2018
1 parent ab924b5 commit 875d842
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 7 additions & 11 deletions src/main/java/scribee/morePingsMod/MorePingsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
@Mod(modid = Reference.MODID, name = Reference.MOD_NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY, clientSideOnly = true)
public class MorePingsMod {

// used to make sure the disable/enable message sends only the first time WorldEvent.Load is fired
private static boolean scheduled = false;
private static boolean scheduled = false; // used to make sure the disable/enable message sends only the first time WorldEvent.Load is fired
private static boolean onHypixel = false;
private static String lastIP = "none";

Expand All @@ -46,7 +45,6 @@ public class MorePingsMod {

@EventHandler
public void preInit(FMLPreInitializationEvent event) {

ConfigHandler.init(event);
ConfigHandler.syncConfig();
}
Expand All @@ -62,13 +60,12 @@ public void init(FMLInitializationEvent event) {
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
if (event.modID.equals(Reference.MODID)) {
ConfigHandler.syncConfig();

ConfigHandler.syncConfig();
updateKeywords();
}
}

@SubscribeEvent(priority = EventPriority.LOW) // low priority improves compatibility with some other chat mods
@SubscribeEvent
public void onChatEvent(ClientChatReceivedEvent event) {
if (!ConfigHandler.disableMod && onHypixel) {
String message = event.message.getFormattedText();
Expand All @@ -91,7 +88,7 @@ public void onChatEvent(ClientChatReceivedEvent event) {
*/
if ((!message.substring(2, 7).equalsIgnoreCase("from ") || (ConfigHandler.privateChat && (message.substring(2, 7).equalsIgnoreCase("from ")))) && (!message.substring(2, 8).equalsIgnoreCase("party>") || (ConfigHandler.partyChat && (message.substring(2, 8).equalsIgnoreCase("party>")))) && (!message.substring(2, 8).equalsIgnoreCase("guild>") || (ConfigHandler.guildChat && (message.substring(2, 8).equalsIgnoreCase("guild>")))) && !message.substring(2, 5).equalsIgnoreCase("to ") && matcher.find()) {
int keywordInd = matcher.start(3);
// check if player is a non using the color code just before the colon
// check if player is a non, using the color code just before the colon
if (matcher.group(1).equals("7")) {
event.message = new ChatComponentText(message.substring(0, keywordInd) +
getFormattedKeyword(keyword, true) +
Expand Down Expand Up @@ -132,7 +129,6 @@ else if (message.length() == 31 && message.contains("Your nick has been reset!")
}
}


@SubscribeEvent
public void onPlayerLeaveEvent(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
onHypixel = false;
Expand Down Expand Up @@ -252,7 +248,7 @@ else if (!scheduled && ConfigHandler.sendStatusMessages && !lastIP.equals(FMLCli

lastIP = FMLClientHandler.instance().getClient().getCurrentServerData().serverIP;
}
// in singleplayer mode, messages enabled and wasn't last in singleplayer
// in singleplayer mode, messages enabled, and wasn't last in singleplayer
else if (!scheduled && ConfigHandler.sendStatusMessages && !lastIP.equals("singleplayer")) {
sendDisabledMessage("singleplayer mode");

Expand All @@ -262,7 +258,7 @@ else if (!scheduled && ConfigHandler.sendStatusMessages && !lastIP.equals("singl
}

/**
* Used to format keywords based on chosen preferences from the config file
* Used to format keywords with color and style specified in the config file
*
* @param keyword Keyword to add styling and color to
* @param isNon If the player is a non
Expand All @@ -271,7 +267,7 @@ else if (!scheduled && ConfigHandler.sendStatusMessages && !lastIP.equals("singl
public static String getFormattedKeyword(String keyword, boolean isNon) {
String ping = keyword + EnumChatFormatting.RESET;

ping += isNon ? EnumChatFormatting.GRAY : EnumChatFormatting.WHITE;
ping += isNon ? EnumChatFormatting.GRAY : EnumChatFormatting.WHITE; // set the rest of the message to match the color it should be

ping = ConfigHandler.pingStyle.equals("None") ? ping : ConfigHandler.pingStyle.substring(0, 2) + ping;
ping = ConfigHandler.pingColor.equals("None") ? ping : ConfigHandler.pingColor.substring(0, 2) + ping;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"modid": "mp",
"name": "More Pings Mod",
"description": "Highlights keywords by making them colorful and playing a ding sound when they show up in chat.\nAll settings are customizable via /morepings (or just /mp), or in the configuration file GUI :D",
"description": "Highlights keywords by making them colorful and playing a ding sound when they show up in chat.\nAll settings are customizable via /morepings (or just /mp), or in the configuration file GUI :D\n\nNOTE: There may be some compatibility issues between this and other chat mods.",
"version": "${version}",
"mcversion": "${mcversion}",
"url": "https://github.com/Scribee/MorePingsMod-1.8.9",
Expand Down

0 comments on commit 875d842

Please sign in to comment.