mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 16:09:05 +00:00
PlayerEvent.MouseClickedEvent:
-Added isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed, and keysDown fields for button combinations.
This commit is contained in:
1 parent
1c10f2ebf1
commit
9bd644f84a
4 files changed
+47
-5
No files matched your search
@@ -442,9 +442,9 @@ public class EventHooks {
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerMouseClicked(EntityPlayerMP player, int button, int mouseWheel, boolean buttonDown) {
|
||||
public static void onPlayerMouseClicked(EntityPlayerMP player, int button, int mouseWheel, boolean buttonDown, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed, int[] heldKeys) {
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
PlayerEvent.MouseClickedEvent event = new PlayerEvent.MouseClickedEvent((IPlayer)NpcAPI.Instance().getIEntity(player), button, mouseWheel, buttonDown);
|
||||
PlayerEvent.MouseClickedEvent event = new PlayerEvent.MouseClickedEvent((IPlayer)NpcAPI.Instance().getIEntity(player), button, mouseWheel, buttonDown, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed, heldKeys);
|
||||
handler.callScript(EnumScriptType.MOUSE_CLICKED, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,33 @@ public class PacketHandlerPlayer{
|
||||
return;
|
||||
}
|
||||
|
||||
EventHooks.onPlayerMouseClicked(player, buffer.readInt(), buffer.readInt(), buffer.readBoolean());
|
||||
int button = buffer.readInt();
|
||||
int mouseWheel = buffer.readInt();
|
||||
boolean buttonDown = buffer.readBoolean();
|
||||
|
||||
boolean isCtrlPressed = buffer.readBoolean();
|
||||
boolean isShiftPressed = buffer.readBoolean();
|
||||
boolean isAltPressed = buffer.readBoolean();
|
||||
boolean isMetaPressed = buffer.readBoolean();
|
||||
|
||||
String ints = Server.readString(buffer);
|
||||
String[] split = ints.split(",");
|
||||
int[] keysDown;
|
||||
|
||||
if(ints.length() > 0) {
|
||||
keysDown = new int[split.length];
|
||||
try {
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
keysDown[i] = Integer.parseInt(split[i]);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ignored){
|
||||
}
|
||||
} else {
|
||||
keysDown = new int[0];
|
||||
}
|
||||
|
||||
EventHooks.onPlayerMouseClicked(player, button, mouseWheel, buttonDown, isCtrlPressed, isShiftPressed, isAltPressed, isMetaPressed, keysDown);
|
||||
}
|
||||
else if(type == EnumPlayerPacket.FollowerHire){
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
|
||||
@@ -50,7 +50,12 @@ public class ClientTickHandler{
|
||||
if(Mouse.getEventButton() == -1 && Mouse.getDWheel() == 0)
|
||||
return;
|
||||
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.MouseClicked, new Object[]{Mouse.getEventButton(),Mouse.getEventDWheel(),Mouse.isButtonDown(Mouse.getEventButton())});
|
||||
boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29);
|
||||
boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42);
|
||||
boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56);
|
||||
boolean isMetaPressed = Keyboard.isKeyDown(220) || Keyboard.isKeyDown(219);
|
||||
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.MouseClicked, new Object[]{Mouse.getEventButton(),Mouse.getEventDWheel(),Mouse.isButtonDown(Mouse.getEventButton()), Boolean.valueOf(isCtrlPressed), Boolean.valueOf(isShiftPressed), Boolean.valueOf(isAltPressed), Boolean.valueOf(isMetaPressed)});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -58,15 +58,26 @@ public class PlayerEvent extends CustomNPCsEvent {
|
||||
}
|
||||
|
||||
public static class MouseClickedEvent extends PlayerEvent {
|
||||
public final boolean isCtrlPressed;
|
||||
public final boolean isAltPressed;
|
||||
public final boolean isShiftPressed;
|
||||
public final boolean isMetaPressed;
|
||||
public final int[] keysDown;
|
||||
|
||||
public final int button;
|
||||
public final int mouseWheel;
|
||||
public final boolean buttonDown;
|
||||
|
||||
public MouseClickedEvent(IPlayer player, int button, int mouseWheel, boolean buttonDown){
|
||||
public MouseClickedEvent(IPlayer player, int button, int mouseWheel, boolean buttonDown, boolean isCtrlPressed, boolean isAltPressed, boolean isShiftPressed, boolean isMetaPressed, int[] heldKeys){
|
||||
super(player);
|
||||
this.button = button;
|
||||
this.mouseWheel = mouseWheel;
|
||||
this.buttonDown = buttonDown;
|
||||
this.isCtrlPressed = isCtrlPressed;
|
||||
this.isAltPressed = isAltPressed;
|
||||
this.isShiftPressed = isShiftPressed;
|
||||
this.isMetaPressed = isMetaPressed;
|
||||
this.keysDown = heldKeys;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user