[Added] MidClickFriends Closes #302 (#510)

* [Added] MidClickFriends (Please triple double check that this works)

* [Tweak] MidClickFriends, Removed debuginfo
This commit is contained in:
RealIndrit 2020-03-02 23:06:33 +01:00 committed by GitHub
parent de1d3360e3
commit 36e523af23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 5 deletions

View File

@ -45,7 +45,6 @@ public class FriendCommand extends Command {
return; return;
} else { } else {
if (args[1] == null) { 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])); Command.sendChatMessage(String.format(Friends.isFriend(args[0]) ? "Yes, %s is your friend." : "No, %s isn't a friend of yours.", args[0]));
return; return;
} }
@ -85,7 +84,7 @@ public class FriendCommand extends Command {
} }
} }
private Friends.Friend getFriendByName(String input) { public Friends.Friend getFriendByName(String input) {
ArrayList<NetworkPlayerInfo> infoMap = new ArrayList<NetworkPlayerInfo>(Minecraft.getMinecraft().getConnection().getPlayerInfoMap()); ArrayList<NetworkPlayerInfo> infoMap = new ArrayList<NetworkPlayerInfo>(Minecraft.getMinecraft().getConnection().getPlayerInfoMap());
NetworkPlayerInfo profile = infoMap.stream().filter(networkPlayerInfo -> networkPlayerInfo.getGameProfile().getName().equalsIgnoreCase(input)).findFirst().orElse(null); NetworkPlayerInfo profile = infoMap.stream().filter(networkPlayerInfo -> networkPlayerInfo.getGameProfile().getName().equalsIgnoreCase(input)).findFirst().orElse(null);
if (profile == 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"); java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
String r = s.hasNext() ? s.next() : "/"; String r = s.hasNext() ? s.next() : "/";
return r; return r;

View File

@ -145,12 +145,17 @@ public class ForgeEventProcessor {
KamiMod.EVENT_BUS.post(event); KamiMod.EVENT_BUS.post(event);
} }
@SubscribeEvent() @SubscribeEvent
public void onChunkLoaded(ChunkEvent.Load event) { public void onChunkLoaded(ChunkEvent.Load event) {
KamiMod.EVENT_BUS.post(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) { public void onChunkLoaded(ChunkEvent.Unload event) {
KamiMod.EVENT_BUS.post(event); KamiMod.EVENT_BUS.post(event);
} }

View File

@ -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<InputEvent.MouseInputEvent> 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();
}
}