Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Fix Config
Browse files Browse the repository at this point in the history
  • Loading branch information
eagely committed Mar 19, 2022
1 parent 7ae88a7 commit 0e706f2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/main/java/me/mlg/rat/Default.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import me.mlg.rat.utils.Utils;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class Default {
@SubscribeEvent
public void onChat(ClientChatReceivedEvent event) {
String message = StringUtils.stripControlCodes(event.message.getUnformattedText());
if(message.startsWith("From ")) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/me/mlg/rat/RatAddons.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.mlg.rat;

import me.mlg.rat.commands.DebugCommand;
import me.mlg.rat.commands.ReloadConfigCommand;
import me.mlg.rat.commands.SetPosition;
import me.mlg.rat.commands.ToggleCommand;
Expand Down Expand Up @@ -29,6 +30,7 @@ public void preInit(FMLPreInitializationEvent event) {
ClientCommandHandler.instance.registerCommand(new SetPosition());
ClientCommandHandler.instance.registerCommand(new ToggleCommand());
ClientCommandHandler.instance.registerCommand(new ReloadConfigCommand());
ClientCommandHandler.instance.registerCommand(new DebugCommand());
}
@EventHandler
public void init(FMLInitializationEvent event)
Expand All @@ -38,6 +40,7 @@ public void init(FMLInitializationEvent event)
FMLCommonHandler.instance().bus().register(new GreetGuild());
FMLCommonHandler.instance().bus().register(new MessageResponder());
FMLCommonHandler.instance().bus().register(new WatcherDisplay());
FMLCommonHandler.instance().bus().register(new Default());

ConfigHandler.reloadConfig();
}
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/me/mlg/rat/commands/DebugCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package me.mlg.rat.commands;

import me.mlg.rat.handlers.ConfigHandler;
import me.mlg.rat.utils.Utils;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText;

public class DebugCommand extends CommandBase {
@Override
public String getCommandName() {
return "rat";
}

@Override
public String getCommandUsage(ICommandSender sender) {
return "rat istoggled/addchatmessage value type";
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
return true;
}

@Override
public int getRequiredPermissionLevel() {
return 0;
}

@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
switch(args[0]) {
case "istoggled":
switch(args[2]) {
case "boolean":
Utils.mc.thePlayer.addChatMessage(new ChatComponentText("" + ConfigHandler.getBoolean("toggle", args[1])));
break;
case "string":
Utils.mc.thePlayer.addChatMessage(new ChatComponentText(ConfigHandler.getString("toggle", args[1])));
break;
case "integer":
Utils.mc.thePlayer.addChatMessage(new ChatComponentText("" + ConfigHandler.getInt("toggle", args[1])));
break;
case "double":
Utils.mc.thePlayer.addChatMessage(new ChatComponentText("" + ConfigHandler.getDouble("toggle", args[1])));
break;
default:
Utils.printErrorMessage("Invalid argument at istoggled; args[1]");
}
break;
case "addchatmessage":
Utils.mc.thePlayer.addChatMessage(new ChatComponentText(args[1]));
break;
default:
Utils.mc.thePlayer.addChatMessage(new ChatComponentText(getCommandUsage(sender)));
break;
}
}
}
12 changes: 6 additions & 6 deletions src/main/java/me/mlg/rat/modules/GreetGuild.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.mlg.rat.modules;

import me.mlg.rat.handlers.ConfigHandler;
import me.mlg.rat.commands.ToggleCommand;
import net.minecraft.client.Minecraft;
import me.mlg.rat.handlers.ConfigHandler;
import me.mlg.rat.utils.Utils;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -18,10 +18,10 @@ public void onChat(ClientChatReceivedEvent event) {
String message = StringUtils.stripControlCodes(event.message.getUnformattedText());
if (message.startsWith("Guild > ") && message.endsWith("joined.") && !message.contains(":") && ToggleCommand.greetToggle) {
String username = message.split(" ", 0)[2];
ConfigHandler.initInt("lastSeen", username, 111970);
if (ConfigHandler.getInt("lastSeen", username) != date) {
Minecraft.getMinecraft().thePlayer.sendChatMessage("/gc Good morning " + username);
ConfigHandler.writeIntConfig("lastSeen", username, date);
if (ConfigHandler.initInt("lastseen", username, 111970) != date) {
Utils.mc.thePlayer.sendChatMessage("/gc Good morning " + username);
date = Integer.parseInt(LocalDate.now().format(DateTimeFormatter.ofPattern("dMy")));
ConfigHandler.writeIntConfig("lastseen", username, date);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/mlg/rat/modules/MessageResponder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MessageResponder {
public void onChat(ClientChatReceivedEvent event) {
ToggleCommand.responderToggle = ConfigHandler.getBoolean("toggle", "responder");
String message = StringUtils.stripControlCodes(event.message.getUnformattedText());
if(message.startsWith("Guild > ") || message.startsWith("Party > ") && ToggleCommand.responderToggle) {
if(message.startsWith("Guild > ") && ToggleCommand.responderToggle || message.startsWith("Party > ") && ToggleCommand.responderToggle) {
if (message.toLowerCase().contains("@smiler"))
Minecraft.getMinecraft().thePlayer.sendChatMessage("/" + message.split(" ", 0)[0] + " chat " + ":)");
else if (message.toLowerCase().contains("@truer"))
Expand Down

0 comments on commit 0e706f2

Please sign in to comment.