aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/ftbsc/bscv/Boscovicino.java8
-rw-r--r--src/main/java/ftbsc/bscv/system/Friends.java122
2 files changed, 130 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/bscv/Boscovicino.java b/src/main/java/ftbsc/bscv/Boscovicino.java
index f5e4f93..4754182 100644
--- a/src/main/java/ftbsc/bscv/Boscovicino.java
+++ b/src/main/java/ftbsc/bscv/Boscovicino.java
@@ -3,6 +3,7 @@ package ftbsc.bscv;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import ftbsc.bscv.api.IModule;
+import ftbsc.bscv.system.Friends;
import ftbsc.bscv.system.ModManager;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.screen.IngameMenuScreen;
@@ -39,6 +40,9 @@ public class Boscovicino implements ICommons {
public static ForgeConfigSpec spec;
+ private static Friends friends;
+ public static Friends friends() { return Boscovicino.friends; }
+
public Boscovicino() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);
@@ -50,8 +54,12 @@ public class Boscovicino implements ICommons {
Boscovicino.spec = cfg.build();
+ ForgeConfigSpec.Builder friendSpec = new ForgeConfigSpec.Builder();
+ Boscovicino.friends = new Friends(friendSpec, dp);
+
// register config handler
ModLoadingContext.get().registerConfig(Type.CLIENT, spec, "bscv.toml");
+ ModLoadingContext.get().registerConfig(Type.CLIENT, friendSpec.build(), "friends.toml");
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
diff --git a/src/main/java/ftbsc/bscv/system/Friends.java b/src/main/java/ftbsc/bscv/system/Friends.java
new file mode 100644
index 0000000..322f604
--- /dev/null
+++ b/src/main/java/ftbsc/bscv/system/Friends.java
@@ -0,0 +1,122 @@
+package ftbsc.bscv.system;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import javax.annotation.Nullable;
+
+import com.google.common.collect.Lists;
+import com.mojang.authlib.GameProfile;
+import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.arguments.StringArgumentType;
+
+import ftbsc.bscv.Boscovicino;
+import ftbsc.bscv.ICommons;
+import net.minecraft.client.network.play.ClientPlayNetHandler;
+import net.minecraft.client.network.play.NetworkPlayerInfo;
+import net.minecraft.command.CommandSource;
+import net.minecraft.command.Commands;
+import net.minecraftforge.common.ForgeConfigSpec;
+
+public class Friends implements ICommons {
+
+ @Nullable
+ public static GameProfile fromName(String name) {
+ ClientPlayNetHandler connection = MC.getConnection();
+ if (connection == null) return null;
+ for (NetworkPlayerInfo info : connection.getOnlinePlayers()) {
+ if (info.getProfile().getName().equals(name)) {
+ return new GameProfile(info.getProfile().getId(), info.getProfile().getName());
+ }
+ }
+ return null;
+ }
+
+ private ForgeConfigSpec.ConfigValue<List<? extends String>> store;
+
+ public Friends(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
+ this.store = builder.comment("actual friend list").defineList("data", () -> new ArrayList<String>(), u -> {
+ try{
+ UUID.fromString(u.toString());
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ });
+
+ dispatcher.register(
+ Commands.literal("friends")
+ .then(
+ Commands.literal("add")
+ .then(
+ Commands.argument("name", StringArgumentType.word())
+ .executes( ctx -> {
+ String name = ctx.getArgument("name", String.class);
+ GameProfile profile = Friends.fromName(name);
+ if (profile == null) return 0;
+ this.addFriend(profile);
+ Boscovicino.log(String.format("> added %s <", profile.getName()));
+ return 1;
+ })
+ )
+ )
+ .then(
+ Commands.literal("remove")
+ .then(
+ Commands.argument("name", StringArgumentType.word())
+ .executes( ctx -> {
+ String name = ctx.getArgument("name", String.class);
+ GameProfile profile = Friends.fromName(name);
+ if (profile == null) return 0;
+ this.removeFriend(profile);
+ Boscovicino.log(String.format("> removed %s <", profile.getName()));
+ return 1;
+ })
+ )
+ )
+ .executes(ctx -> {
+ for (String friend : this.store.get()) {
+ Boscovicino.log(String.format("%s", friend));
+ }
+ return 1;
+ })
+ );
+ }
+
+ public boolean isFriend(String name) {
+ GameProfile usr = fromName(name);
+ if (usr != null) {
+ return isFriend(usr);
+ }
+ return false;
+ }
+
+ public boolean isFriend(GameProfile friend) { return isFriend(friend.getId()); }
+
+ public boolean isFriend(UUID friend) {
+ return this.store.get().contains(friend.toString());
+ }
+
+ public boolean removeFriend(GameProfile friend) {
+ if (this.store.get().contains(friend.getId().toString())) {
+ this.store.get().remove(friend.getId().toString());
+ this.store.save();
+ return true;
+ }
+ return false;
+ }
+
+ public boolean addFriend(GameProfile friend) {
+ if (!this.store.get().contains(friend.getId().toString())) {
+ ArrayList<String> botch = Lists.newArrayList(this.store.get());
+ botch.add(friend.getId().toString());
+ this.store.set((List<? extends String>) botch);
+ this.store.save();
+ return true;
+ }
+ return false;
+ }
+
+}
+