From 36e523af2320d0ed6c86896b6324d7d99fc6cf29 Mon Sep 17 00:00:00 2001 From: RealIndrit <32206640+RealIndrit@users.noreply.github.com> Date: Mon, 2 Mar 2020 23:06:33 +0100 Subject: [PATCH] [Added] MidClickFriends Closes #302 (#510) * [Added] MidClickFriends (Please triple double check that this works) * [Tweak] MidClickFriends, Removed debuginfo --- .../kami/command/commands/FriendCommand.java | 5 +- .../kami/event/ForgeEventProcessor.java | 9 ++- .../module/modules/misc/MidClickFriends.java | 71 +++++++++++++++++++ 3 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 src/main/java/me/zeroeightsix/kami/module/modules/misc/MidClickFriends.java diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/FriendCommand.java b/src/main/java/me/zeroeightsix/kami/command/commands/FriendCommand.java index 7b04feeb..6fb914db 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/FriendCommand.java +++ b/src/main/java/me/zeroeightsix/kami/command/commands/FriendCommand.java @@ -45,7 +45,6 @@ public class FriendCommand extends Command { return; } else { if (args[1] == null) { - Command.sendChatMessage(String.format(Friends.isFriend(args[0]) ? "Yes, %s is your friend." : "No, %s isn't a friend of yours.", args[0])); Command.sendChatMessage(String.format(Friends.isFriend(args[0]) ? "Yes, %s is your friend." : "No, %s isn't a friend of yours.", args[0])); return; } @@ -85,7 +84,7 @@ public class FriendCommand extends Command { } } - private Friends.Friend getFriendByName(String input) { + public Friends.Friend getFriendByName(String input) { ArrayList infoMap = new ArrayList(Minecraft.getMinecraft().getConnection().getPlayerInfoMap()); NetworkPlayerInfo profile = infoMap.stream().filter(networkPlayerInfo -> networkPlayerInfo.getGameProfile().getName().equalsIgnoreCase(input)).findFirst().orElse(null); if (profile == null) { @@ -144,7 +143,7 @@ public class FriendCommand extends Command { } } - private static String convertStreamToString(java.io.InputStream is) { + private static String convertStreamToString(InputStream is) { java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); String r = s.hasNext() ? s.next() : "/"; return r; diff --git a/src/main/java/me/zeroeightsix/kami/event/ForgeEventProcessor.java b/src/main/java/me/zeroeightsix/kami/event/ForgeEventProcessor.java index b2ab1cac..bcf151cb 100644 --- a/src/main/java/me/zeroeightsix/kami/event/ForgeEventProcessor.java +++ b/src/main/java/me/zeroeightsix/kami/event/ForgeEventProcessor.java @@ -145,12 +145,17 @@ public class ForgeEventProcessor { KamiMod.EVENT_BUS.post(event); } - @SubscribeEvent() + @SubscribeEvent public void onChunkLoaded(ChunkEvent.Load event) { KamiMod.EVENT_BUS.post(event); } - @SubscribeEvent() + @SubscribeEvent + public void onEventMouse(InputEvent.MouseInputEvent event) { + KamiMod.EVENT_BUS.post(event); + } + + @SubscribeEvent public void onChunkLoaded(ChunkEvent.Unload event) { KamiMod.EVENT_BUS.post(event); } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/MidClickFriends.java b/src/main/java/me/zeroeightsix/kami/module/modules/misc/MidClickFriends.java new file mode 100644 index 00000000..ed4472f4 --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/MidClickFriends.java @@ -0,0 +1,71 @@ +package me.zeroeightsix.kami.module.modules.misc; + +import me.zero.alpine.listener.EventHandler; +import me.zero.alpine.listener.Listener; +import me.zeroeightsix.kami.KamiMod; +import me.zeroeightsix.kami.command.Command; +import me.zeroeightsix.kami.command.commands.FriendCommand; +import me.zeroeightsix.kami.module.Module; +import me.zeroeightsix.kami.util.Friends; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityOtherPlayerMP; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.RayTraceResult; +import net.minecraftforge.fml.common.gameevent.InputEvent; +import org.lwjgl.input.Mouse; + +/** + * @author Indrit + * Updated by Indrit on 02/03/20 + */ + +@Module.Info(name = "MidClickFriends", category = Module.Category.MISC, description = "Middle click payers to friend/unfriend them") +public class MidClickFriends extends Module { + private int delay = 0; + + @Override + public void onUpdate(){ + if (delay > 0) { + delay--; + } + } + + @EventHandler + public Listener mouseListener = new Listener<>(event -> { + if (delay == 0) { + if(Mouse.getEventButton() == 2) { // Because 2 is middle click on mouse, wtf??? + if (Minecraft.getMinecraft().objectMouseOver.typeOfHit.equals(RayTraceResult.Type.ENTITY)) { + Entity uwu = Minecraft.getMinecraft().objectMouseOver.entityHit; + if (!(uwu instanceof EntityOtherPlayerMP)) { + return; + } + if (Friends.isFriend(uwu.getName())) { + remove(uwu.getName()); + } else { + add(uwu.getName()); + } + } + } + } + }); + + private void remove(String name){ + delay = 20; + Friends.Friend friend = Friends.INSTANCE.friends.getValue().stream().filter(friend1 -> friend1.getUsername().equalsIgnoreCase(name)).findFirst().get(); + Friends.INSTANCE.friends.getValue().remove(friend); + Command.sendChatMessage("&b" + friend.getUsername() + "&r has been unfriended."); + } + + private void add(String name){ + delay = 20; + new Thread(() -> { + Friends.Friend f = new FriendCommand().getFriendByName(name); + if (f == null) { + Command.sendChatMessage("Failed to find UUID of " + name); + return; + } + Friends.INSTANCE.friends.getValue().add(f); + Command.sendChatMessage("&b" + f.getUsername() + "&r has been friended."); + }).start(); + } +}