aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2020-03-03 00:26:40 +0100
committerCow <cow@volloeko.de>2020-03-03 00:26:40 +0100
commit508f872ba076f4e767ff2c374656bc47637eb229 (patch)
tree18f6b3505e878bca7c39ce8415f110917264c222 /src
parentea5963ad660c91640ec72bddd046d2e465f55f3f (diff)
downloadCowlection-508f872ba076f4e767ff2c374656bc47637eb229.tar.gz
Cowlection-508f872ba076f4e767ff2c374656bc47637eb229.tar.bz2
Cowlection-508f872ba076f4e767ff2c374656bc47637eb229.zip
Replaced best friend add and remove commands with a config gui
Diffstat (limited to 'src')
-rw-r--r--src/main/java/eu/olli/cowmoonication/Cowmoonication.java1
-rw-r--r--src/main/java/eu/olli/cowmoonication/Friends.java27
-rw-r--r--src/main/java/eu/olli/cowmoonication/command/MooCommand.java43
-rw-r--r--src/main/java/eu/olli/cowmoonication/config/MooConfig.java2
-rw-r--r--src/main/java/eu/olli/cowmoonication/util/TickDelay.java29
-rw-r--r--src/main/java/eu/olli/cowmoonication/util/Utils.java (renamed from src/main/java/eu/olli/cowmoonication/Utils.java)3
6 files changed, 38 insertions, 67 deletions
diff --git a/src/main/java/eu/olli/cowmoonication/Cowmoonication.java b/src/main/java/eu/olli/cowmoonication/Cowmoonication.java
index d07876c..3a93fe6 100644
--- a/src/main/java/eu/olli/cowmoonication/Cowmoonication.java
+++ b/src/main/java/eu/olli/cowmoonication/Cowmoonication.java
@@ -3,6 +3,7 @@ package eu.olli.cowmoonication;
import eu.olli.cowmoonication.command.MooCommand;
import eu.olli.cowmoonication.config.MooConfig;
import eu.olli.cowmoonication.listener.ChatListener;
+import eu.olli.cowmoonication.util.Utils;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
diff --git a/src/main/java/eu/olli/cowmoonication/Friends.java b/src/main/java/eu/olli/cowmoonication/Friends.java
index 0cbe517..2becc74 100644
--- a/src/main/java/eu/olli/cowmoonication/Friends.java
+++ b/src/main/java/eu/olli/cowmoonication/Friends.java
@@ -13,37 +13,10 @@ public class Friends {
this.main = main;
}
- public boolean addBestFriend(String name, boolean save) {
- if (name.isEmpty()) {
- return false;
- }
- boolean added = bestFriends.add(name);
- if (added && save) {
- saveBestFriends();
- }
- return added;
- }
-
- public boolean addBestFriend(String name) {
- return addBestFriend(name, false);
- }
-
- public boolean removeBestFriend(String name) {
- boolean removed = bestFriends.remove(name);
- if (removed) {
- saveBestFriends();
- }
- return removed;
- }
-
public boolean isBestFriend(String playerName) {
return bestFriends.contains(playerName);
}
- private void saveBestFriends() {
-
- }
-
public Set<String> getBestFriends() {
return new TreeSet<>(bestFriends);
}
diff --git a/src/main/java/eu/olli/cowmoonication/command/MooCommand.java b/src/main/java/eu/olli/cowmoonication/command/MooCommand.java
index ca4722c..f3d234b 100644
--- a/src/main/java/eu/olli/cowmoonication/command/MooCommand.java
+++ b/src/main/java/eu/olli/cowmoonication/command/MooCommand.java
@@ -2,6 +2,8 @@ package eu.olli.cowmoonication.command;
import eu.olli.cowmoonication.Cowmoonication;
import eu.olli.cowmoonication.config.MooConfig;
+import eu.olli.cowmoonication.config.MooGuiConfig;
+import eu.olli.cowmoonication.util.TickDelay;
import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
@@ -27,14 +29,8 @@ public class MooCommand extends CommandBase {
main.getUtils().sendMessage(new ChatComponentTranslation(getCommandUsage(sender)));
return;
}
- if (args.length == 2 && args[0].equalsIgnoreCase("add")) {
- main.getUtils().sendMessage(EnumChatFormatting.RED + "Edit the best friends list via ESC > Mod Options > Cowmoonication > Config > bestFriends.");
- // TODO replace with a proper command
- // handleBestFriendAdd(args[1]);
- } else if (args.length == 2 && args[0].equalsIgnoreCase("remove") && main.getUtils().isValidMcName(args[1])) {
- main.getUtils().sendMessage(EnumChatFormatting.RED + "Edit the best friends list via ESC > Mod Options > Cowmoonication > Config > bestFriends.");
- // TODO replace with a proper command
- // handleBestFriendRemove(args[1]);
+ if (args[0].equalsIgnoreCase("friends") || args[0].equalsIgnoreCase("f")) {
+ new TickDelay(() -> Minecraft.getMinecraft().displayGuiScreen(new MooGuiConfig(null)), 1); // delay by 1 tick, because the chat closing would close the new gui instantly as well.
} else if (args[0].equalsIgnoreCase("list")) {
handleListBestFriends();
} else if (args[0].equalsIgnoreCase("toggle")) {
@@ -54,35 +50,6 @@ public class MooCommand extends CommandBase {
}
}
- private void handleBestFriendAdd(String username) {
- if (!main.getUtils().isValidMcName(username)) {
- main.getUtils().sendMessage(EnumChatFormatting.DARK_RED + username + EnumChatFormatting.RED + "? This... doesn't look like a valid username.");
- return;
- }
-
- // TODO Add check if 'best friend' is on normal friend list
- boolean added = main.getFriends().addBestFriend(username, true);
- if (added) {
- main.getUtils().sendMessage(EnumChatFormatting.GREEN + "Added " + EnumChatFormatting.DARK_GREEN + username + EnumChatFormatting.GREEN + " as best friend.");
- } else {
- main.getUtils().sendMessage(EnumChatFormatting.DARK_RED + username + EnumChatFormatting.RED + " is a best friend already.");
- }
- }
-
- private void handleBestFriendRemove(String username) {
- if (!main.getUtils().isValidMcName(username)) {
- main.getUtils().sendMessage(EnumChatFormatting.DARK_RED + username + EnumChatFormatting.RED + "? This... doesn't look like a valid username.");
- return;
- }
-
- boolean removed = main.getFriends().removeBestFriend(username);
- if (removed) {
- main.getUtils().sendMessage(EnumChatFormatting.GREEN + "Removed " + EnumChatFormatting.DARK_GREEN + username + EnumChatFormatting.GREEN + " from best friends list.");
- } else {
- main.getUtils().sendMessage(EnumChatFormatting.DARK_RED + username + EnumChatFormatting.RED + " isn't a best friend.");
- }
- }
-
private void handleListBestFriends() {
Set<String> bestFriends = main.getFriends().getBestFriends();
@@ -108,7 +75,7 @@ public class MooCommand extends CommandBase {
@Override
public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) {
if (args.length == 1) {
- return getListOfStringsMatchingLastWord(args, "add", "remove", "list", "toggle", "guiscale");
+ return getListOfStringsMatchingLastWord(args, "friends", "list", "toggle", "guiscale");
}
return null;
}
diff --git a/src/main/java/eu/olli/cowmoonication/config/MooConfig.java b/src/main/java/eu/olli/cowmoonication/config/MooConfig.java
index 6165e54..97cea9b 100644
--- a/src/main/java/eu/olli/cowmoonication/config/MooConfig.java
+++ b/src/main/java/eu/olli/cowmoonication/config/MooConfig.java
@@ -1,7 +1,7 @@
package eu.olli.cowmoonication.config;
import eu.olli.cowmoonication.Cowmoonication;
-import eu.olli.cowmoonication.Utils;
+import eu.olli.cowmoonication.util.Utils;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
diff --git a/src/main/java/eu/olli/cowmoonication/util/TickDelay.java b/src/main/java/eu/olli/cowmoonication/util/TickDelay.java
new file mode 100644
index 0000000..d5d164a
--- /dev/null
+++ b/src/main/java/eu/olli/cowmoonication/util/TickDelay.java
@@ -0,0 +1,29 @@
+package eu.olli.cowmoonication.util;
+
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.gameevent.TickEvent;
+
+public class TickDelay {
+ private Runnable task;
+ private int waitingTicks;
+
+ public TickDelay(Runnable task, int ticks) {
+ this.task = task;
+ this.waitingTicks = ticks;
+
+ MinecraftForge.EVENT_BUS.register(this);
+ }
+
+ @SubscribeEvent
+ public void onTick(TickEvent.ClientTickEvent e) {
+ if (e.phase == TickEvent.Phase.START) {
+ if (waitingTicks < 1) {
+ // we're done waiting! Do stuff and exit.
+ task.run();
+ MinecraftForge.EVENT_BUS.unregister(this);
+ }
+ waitingTicks--;
+ }
+ }
+}
diff --git a/src/main/java/eu/olli/cowmoonication/Utils.java b/src/main/java/eu/olli/cowmoonication/util/Utils.java
index ac3167c..d10c2ed 100644
--- a/src/main/java/eu/olli/cowmoonication/Utils.java
+++ b/src/main/java/eu/olli/cowmoonication/util/Utils.java
@@ -1,5 +1,6 @@
-package eu.olli.cowmoonication;
+package eu.olli.cowmoonication.util;
+import eu.olli.cowmoonication.Cowmoonication;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;