mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Add set player action event.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package org.apollo.game.event.impl;
|
||||
|
||||
import org.apollo.game.event.Event;
|
||||
|
||||
/**
|
||||
* An {@link Event} sent by the client to add an action to the menu when a player right-clicks another.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public final class SetPlayerActionEvent extends Event {
|
||||
|
||||
/**
|
||||
* This action's text (e.g. "Follow").
|
||||
*/
|
||||
private final String text;
|
||||
|
||||
/**
|
||||
* The menu slot this action will occupy.
|
||||
*/
|
||||
private final int slot;
|
||||
|
||||
/**
|
||||
* Whether or not this action is the primary action.
|
||||
*/
|
||||
private final boolean primaryAction;
|
||||
|
||||
/**
|
||||
* Creates the set player action event.
|
||||
*
|
||||
* @param text The action text.
|
||||
* @param slot The menu slot.
|
||||
*/
|
||||
public SetPlayerActionEvent(String text, int slot) {
|
||||
this(text, slot, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the set player action event.
|
||||
*
|
||||
* @param text The action text.
|
||||
* @param slot The menu slot.
|
||||
* @param primaryInteraction Whether or not the action is the primary action.
|
||||
*/
|
||||
public SetPlayerActionEvent(String text, int slot, boolean primaryInteraction) {
|
||||
this.text = text;
|
||||
this.slot = slot;
|
||||
this.primaryAction = primaryInteraction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the action text.
|
||||
*
|
||||
* @return The text.
|
||||
*/
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the menu slot this action occupies.
|
||||
*
|
||||
* @return The slot.
|
||||
*/
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this action is the primary one (i.e. should be displayed when the player hovers over the other
|
||||
* player).
|
||||
*
|
||||
* @return {@code true} if this action is the primary action, {@code false} if not.
|
||||
*/
|
||||
public boolean isPrimaryAction() {
|
||||
return primaryAction;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import org.apollo.game.event.impl.RegionChangeEvent;
|
||||
import org.apollo.game.event.impl.RemoveTileItemEvent;
|
||||
import org.apollo.game.event.impl.SendFriendEvent;
|
||||
import org.apollo.game.event.impl.ServerMessageEvent;
|
||||
import org.apollo.game.event.impl.SetPlayerActionEvent;
|
||||
import org.apollo.game.event.impl.UpdateTileItemEvent;
|
||||
import org.apollo.game.event.impl.SetWidgetItemModelEvent;
|
||||
import org.apollo.game.event.impl.SetWidgetModelAnimationEvent;
|
||||
@@ -175,8 +176,9 @@ public final class Release317 extends Release {
|
||||
register(PrivacyOptionEvent.class, new PrivacyOptionEventEncoder());
|
||||
register(OpenDialogueInterfaceEvent.class, new OpenDialogueInterfaceEventEncoder());
|
||||
register(UpdateWeightEvent.class, new UpdateWeightEventEncoder());
|
||||
register(AddGlobalTileItemEvent.class, new AddGlobalTileItemEventEncoder());
|
||||
register(SetPlayerActionEvent.class, new SetPlayerActionEventEncoder());
|
||||
|
||||
register(AddGlobalTileItemEvent.class, new AddGlobalTileItemEventEncoder());
|
||||
register(AddTileItemEvent.class, new AddTileItemEventEncoder());
|
||||
register(UpdateTileItemEvent.class, new UpdateTileItemEventEncoder());
|
||||
register(RemoveTileItemEvent.class, new RemoveTileItemEventEncoder());
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.apollo.net.release.r317;
|
||||
|
||||
import org.apollo.game.event.impl.SetPlayerActionEvent;
|
||||
import org.apollo.net.codec.game.DataTransformation;
|
||||
import org.apollo.net.codec.game.DataType;
|
||||
import org.apollo.net.codec.game.GamePacket;
|
||||
import org.apollo.net.codec.game.GamePacketBuilder;
|
||||
import org.apollo.net.release.EventEncoder;
|
||||
|
||||
/**
|
||||
* The {@link EventEncoder} for the {@link SetPlayerActionEvent}.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public final class SetPlayerActionEventEncoder extends EventEncoder<SetPlayerActionEvent> {
|
||||
|
||||
@Override
|
||||
public GamePacket encode(SetPlayerActionEvent event) {
|
||||
GamePacketBuilder builder = new GamePacketBuilder(104);
|
||||
builder.put(DataType.BYTE, DataTransformation.NEGATE, event.getSlot());
|
||||
builder.put(DataType.BYTE, DataTransformation.ADD, event.isPrimaryAction() ? 0 : 1);
|
||||
builder.putString(event.getText());
|
||||
return builder.toGamePacket();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import org.apollo.game.event.impl.RegionChangeEvent;
|
||||
import org.apollo.game.event.impl.RemoveTileItemEvent;
|
||||
import org.apollo.game.event.impl.SendFriendEvent;
|
||||
import org.apollo.game.event.impl.ServerMessageEvent;
|
||||
import org.apollo.game.event.impl.SetPlayerActionEvent;
|
||||
import org.apollo.game.event.impl.UpdateTileItemEvent;
|
||||
import org.apollo.game.event.impl.SetWidgetItemModelEvent;
|
||||
import org.apollo.game.event.impl.SetWidgetModelAnimationEvent;
|
||||
@@ -172,8 +173,9 @@ public final class Release377 extends Release {
|
||||
register(PrivacyOptionEvent.class, new PrivacyOptionEventEncoder());
|
||||
register(OpenDialogueInterfaceEvent.class, new OpenDialogueInterfaceEventEncoder());
|
||||
register(UpdateWeightEvent.class, new UpdateWeightEventEncoder());
|
||||
register(AddGlobalTileItemEvent.class, new AddGlobalTileItemEventEncoder());
|
||||
register(SetPlayerActionEvent.class, new SetPlayerActionEventEncoder());
|
||||
|
||||
register(AddGlobalTileItemEvent.class, new AddGlobalTileItemEventEncoder());
|
||||
register(AddTileItemEvent.class, new AddTileItemEventEncoder());
|
||||
register(UpdateTileItemEvent.class, new UpdateTileItemEventEncoder());
|
||||
register(RemoveTileItemEvent.class, new RemoveTileItemEventEncoder());
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.apollo.net.release.r377;
|
||||
|
||||
import org.apollo.game.event.impl.SetPlayerActionEvent;
|
||||
import org.apollo.net.codec.game.DataTransformation;
|
||||
import org.apollo.net.codec.game.DataType;
|
||||
import org.apollo.net.codec.game.GamePacket;
|
||||
import org.apollo.net.codec.game.GamePacketBuilder;
|
||||
import org.apollo.net.release.EventEncoder;
|
||||
|
||||
/**
|
||||
* The {@link EventEncoder} for the {@link SetPlayerActionEvent}.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public final class SetPlayerActionEventEncoder extends EventEncoder<SetPlayerActionEvent> {
|
||||
|
||||
@Override
|
||||
public GamePacket encode(SetPlayerActionEvent event) {
|
||||
GamePacketBuilder builder = new GamePacketBuilder(157);
|
||||
builder.put(DataType.BYTE, DataTransformation.NEGATE, event.getSlot());
|
||||
builder.putString(event.getText());
|
||||
builder.put(DataType.BYTE, event.isPrimaryAction() ? 0 : 1);
|
||||
return builder.toGamePacket();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user