Initial commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ProjectCranked</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>LunarAPI</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.lunarclient.bukkitapi;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public interface LCPacketWrapper<T extends LCPacket> {
|
||||
|
||||
/**
|
||||
* The packet that will be sent to the player
|
||||
* that is formed in the wrapper implementation.
|
||||
*
|
||||
* @return A LCPacket to send to the Lunar Client player
|
||||
*/
|
||||
T getPacket();
|
||||
|
||||
/**
|
||||
* Send the wrapped packet to the player.
|
||||
*
|
||||
* @param player The online Lunar Client user to receive the packet.
|
||||
*/
|
||||
default void send(Player player) {
|
||||
send(player, getPacket());
|
||||
}
|
||||
|
||||
/**
|
||||
* Send any LCPacket to a Lunar Client user. This is used in `send` method above.
|
||||
*
|
||||
* NOTE: This is intended to send only the wrapped packet, but can be used to
|
||||
* send other packets. Although it technically can be done, in most cases it would
|
||||
* be better to use {@link LunarClientAPI} to send a packet.
|
||||
*
|
||||
* @param player An online Lunar client user to receive the packet.
|
||||
* @param packet The packet to send to the user.
|
||||
*/
|
||||
default void send(Player player, LCPacket packet) {
|
||||
LunarClientAPI.getInstance().sendPacket(player, packet);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
package com.lunarclient.bukkitapi;
|
||||
|
||||
import com.lunarclient.bukkitapi.event.LCPacketReceivedEvent;
|
||||
import com.lunarclient.bukkitapi.event.LCPacketSentEvent;
|
||||
import com.lunarclient.bukkitapi.event.LCPlayerUnregisterEvent;
|
||||
import com.lunarclient.bukkitapi.listener.LunarClientLoginListener;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.*;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCNetHandlerServer;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCPacketWaypointAdd;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCPacketWaypointRemove;
|
||||
import com.lunarclient.bukkitapi.object.LCWaypoint;
|
||||
import com.lunarclient.bukkitapi.object.StaffModule;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.messaging.Messenger;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class LunarClientAPI extends JavaPlugin implements Listener {
|
||||
|
||||
public static final String MESSAGE_CHANNEL = "lunarclient:pm";
|
||||
|
||||
@Getter private static LunarClientAPI instance;
|
||||
|
||||
@Setter private LCNetHandlerServer netHandlerServer = new LunarClientDefaultNetHandler();
|
||||
private final Set<UUID> playersRunningLunarClient = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
private final Set<UUID> playersNotRegistered = new HashSet<>();
|
||||
private final Map<UUID, List<LCPacket>> packetQueue = new HashMap<>();
|
||||
private final Map<UUID, Function<World, String>> worldIdentifiers = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
registerPluginChannel(MESSAGE_CHANNEL);
|
||||
getServer().getPluginManager().registerEvents(new LunarClientLoginListener(this), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the bukkit plugin channel based on configuration of allowed players
|
||||
*
|
||||
* @param bukkitChannel The incoming plugin channel based on Minecraft Version.
|
||||
*/
|
||||
private void registerPluginChannel(String bukkitChannel) {
|
||||
Messenger messenger = getServer().getMessenger();
|
||||
messenger.registerOutgoingPluginChannel(this, bukkitChannel);
|
||||
messenger.registerIncomingPluginChannel(this, bukkitChannel, (channel, player, bytes) -> {
|
||||
LCPacket packet = LCPacket.handle(bytes, player);
|
||||
Bukkit.getPluginManager().callEvent(new LCPacketReceivedEvent(player, packet));
|
||||
packet.process(netHandlerServer);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player has been online for 2 seconds without
|
||||
* sending any sort of registration stating they're on lunar client.
|
||||
*
|
||||
* This will remove all queued packets that we've saved, and prevent further packets
|
||||
* from being stored for this player.
|
||||
*
|
||||
* Used in {@link LunarClientLoginListener}. Do not use unless you are certain you need this.
|
||||
*
|
||||
* @param player The player that has been online for at least 2 seconds.
|
||||
*/
|
||||
public void failPlayerRegister(Player player) {
|
||||
playersNotRegistered.add(player.getUniqueId());
|
||||
packetQueue.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the player as a Lunar Client player based off of their
|
||||
* bukkit plugin channel registration.
|
||||
*
|
||||
* NOTE: Do NOT use this as an anticheat method as this can be spoofed,
|
||||
* or changed. This is intended for cosmetic use only!
|
||||
*
|
||||
* @param player The player registering as a Lunar Client user.
|
||||
*/
|
||||
public void registerPlayer(Player player) {
|
||||
playersNotRegistered.remove(player.getUniqueId());
|
||||
playersRunningLunarClient.add(player.getUniqueId());
|
||||
if (packetQueue.containsKey(player.getUniqueId())) {
|
||||
packetQueue.get(player.getUniqueId()).forEach(p -> sendPacket(player, p));
|
||||
|
||||
packetQueue.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a player as a LunarClient player. This can be done by the client
|
||||
* or by quitting. Either way we remove the player from the set, if they did not
|
||||
* quit we don't want to remove them from NotRegistered players as we would
|
||||
* continue to hold packets for them.
|
||||
*
|
||||
* If they did not quit, we don't want to hold packets for them forever so we
|
||||
* add them to the not registered players set.
|
||||
*
|
||||
* @param player The player who has unregistered themself from the plugin channel.
|
||||
* @param quit A {@link Boolean} value of weather the player quit or simply unregistered from the channel.
|
||||
*/
|
||||
public void unregisterPlayer(Player player, boolean quit) {
|
||||
playersRunningLunarClient.remove(player.getUniqueId());
|
||||
if (quit) {
|
||||
playersNotRegistered.remove(player.getUniqueId());
|
||||
} else {
|
||||
playersNotRegistered.add(player.getUniqueId());
|
||||
getServer().getPluginManager().callEvent(new LCPlayerUnregisterEvent(player));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player is currently running lunar client.
|
||||
* @param player {@link Player} suspect of using Lunar Client.
|
||||
* @return The {@link Boolean} value of weather the online player is currently using Lunar Client.
|
||||
*/
|
||||
public boolean isRunningLunarClient(Player player) {
|
||||
return isRunningLunarClient(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a user is currently running LunarClient on the server.
|
||||
* @param playerUuid The ID of the suspect LunarClient user.
|
||||
*
|
||||
* @return The {@link Boolean} value of weather the player is currently running Lunar Client.
|
||||
*/
|
||||
public boolean isRunningLunarClient(UUID playerUuid) {
|
||||
return playersRunningLunarClient.contains(playerUuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an immutable set of all the bukkit {@link Player} currently running lunar client.
|
||||
*
|
||||
* NOTE: This would only be ideal for displaying an object of the player, for computation
|
||||
* it would probably be better to use the raw UUID of the players.
|
||||
*
|
||||
* @return An unmodifiableSet of the players currentl running lunar client.
|
||||
*/
|
||||
public Set<Player> getPlayersRunningLunarClient() {
|
||||
return Collections.unmodifiableSet(playersRunningLunarClient.stream().map(Bukkit::getPlayer).collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Force set a specific {@link StaffModule} for a specific player.
|
||||
* Useful for enabling only a few {@link StaffModule}
|
||||
*
|
||||
* @param player The player receiving the staff modules.
|
||||
* @param module The staff module to set to a state.
|
||||
* @param state The new state of the StaffModule.
|
||||
*/
|
||||
public void setStaffModuleState(Player player, StaffModule module, boolean state) {
|
||||
sendPacket(player, new LCPacketStaffModState(module.name(), state));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives a player ALL staff modules.
|
||||
* Not recommended, a better path would to explicitly give a player each module.
|
||||
*
|
||||
* @param player The player to receive the enabled staff modules.
|
||||
*/
|
||||
public void giveAllStaffModules(Player player) {
|
||||
for (StaffModule module : StaffModule.values()) {
|
||||
setStaffModuleState(player, module, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables ALL staff modules for a specific player
|
||||
* regardless of if they are enabled.
|
||||
*
|
||||
* @param player The player receiving the new staff module state.
|
||||
*/
|
||||
public void disableAllStaffModules(Player player) {
|
||||
for (StaffModule module : StaffModule.values()) {
|
||||
setStaffModuleState(player, module, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a validated teammate object to the player.
|
||||
* Tells the player of all its known team mates, ensure they're both online and in the world.
|
||||
*
|
||||
* @param player The player to receive the team mates
|
||||
* @param packet The teammates to send to the player.
|
||||
*/
|
||||
public void sendTeammates(Player player, LCPacketTeammates packet) {
|
||||
validatePlayers(player, packet);
|
||||
sendPacket(player, packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate teammates for the player (sendingTo).
|
||||
* Ensures the teammates are online and in the same world before sending the location.
|
||||
* Used above in sendTeammates.
|
||||
*
|
||||
* @param sendingTo The player we're sending teammates to.
|
||||
* @param packet The teammates packet to verify.
|
||||
*/
|
||||
private void validatePlayers(Player sendingTo, LCPacketTeammates packet) {
|
||||
packet.getPlayers().entrySet().removeIf(entry -> Bukkit.getPlayer(entry.getKey()) != null && !Bukkit.getPlayer(entry.getKey()).getWorld().equals(sendingTo.getWorld()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a hologram for a player on the server.
|
||||
*
|
||||
* @param player The observer of the new hologram.
|
||||
* @param id The randomly generated UUID for the hologram. This will need to be saved for other hologram actions.
|
||||
* @param position The location (x, y, z) of where the hologram will be placed in the world.
|
||||
* @param lines The lines of the hologram to be sent to the player.
|
||||
*/
|
||||
public void addHologram(Player player, UUID id, Vector position, String[] lines) {
|
||||
sendPacket(player, new LCPacketHologram(id, position.getX(), position.getY(), position.getZ(), Arrays.asList(lines)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the lines of a previously added hologram for a specific player.
|
||||
*
|
||||
* @param player The observer of the new hologram lines.
|
||||
* @param id The ID of the previously placed hologram.
|
||||
* @param lines The new lines to show to the player.
|
||||
*/
|
||||
public void updateHologram(Player player, UUID id, String[] lines) {
|
||||
sendPacket(player, new LCPacketHologramUpdate(id, Arrays.asList(lines)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a previously set hologram for a specific player.
|
||||
*
|
||||
* @param player The player to remove the hologram for.
|
||||
* @param id The ID of the previously created hologram.
|
||||
*/
|
||||
public void removeHologram(Player player, UUID id) {
|
||||
sendPacket(player, new LCPacketHologramRemove(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the normal (bukkit) nametag with lunar client nametags.
|
||||
* This supports multiple lines, so index 0 will be bottom of the nametags.
|
||||
*
|
||||
* @param target The player whos nametag will be affected for the viewer.
|
||||
* @param nametag The list of nametags that will be sent to the viewer. Supports color codes.
|
||||
* @param viewer The observer who will see the targets nametag as a lunar client nametag.
|
||||
*/
|
||||
public void overrideNametag(Player target, List<String> nametag, Player viewer) {
|
||||
sendPacket(viewer, new LCPacketNametagsOverride(target.getUniqueId(), nametag));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset anything done to the nametag.
|
||||
* This will reset hideNametag or any
|
||||
* other action done to the nametag.
|
||||
*
|
||||
* @param target The player's nametag that will be reset for the viewer.
|
||||
* @param viewer The observer who will see the targets nametag as normal (bukkit).
|
||||
*/
|
||||
public void resetNametag(Player target, Player viewer) {
|
||||
sendPacket(viewer, new LCPacketNametagsOverride(target.getUniqueId(), null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the target's username from the viewer.
|
||||
*
|
||||
*
|
||||
* @param target This player's nametag will be hidden from the viewer.
|
||||
* @param viewer The observer who will hide the targets nametag.
|
||||
*/
|
||||
public void hideNametag(Player target, Player viewer) {
|
||||
sendPacket(viewer, new LCPacketNametagsOverride(target.getUniqueId(), Collections.emptyList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the world identifier weather that is custom or
|
||||
* the worlds generated Id for sending waypoints to the client.
|
||||
*
|
||||
* @param world The world to get the identifier for
|
||||
* @return {@link String} of the set name of the world, or default to the worlds unique id.
|
||||
*/
|
||||
public String getWorldIdentifier(World world) {
|
||||
String worldIdentifier = world.getUID().toString();
|
||||
|
||||
if (worldIdentifiers.containsKey(world.getUID())) {
|
||||
worldIdentifier = worldIdentifiers.get(world.getUID()).apply(world);
|
||||
}
|
||||
|
||||
return worldIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a custom name for the world to be identified as on the client.
|
||||
*
|
||||
* Not required, if not set it will default to the unquie id of the world.
|
||||
*
|
||||
* @param world The bukkit object for the world.
|
||||
* @param identifier The new function identifier.
|
||||
*/
|
||||
public void registerWorldIdentifier(World world, Function<World, String> identifier) {
|
||||
worldIdentifiers.put(world.getUID(), identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a waypoint to a lunarclient player.
|
||||
*
|
||||
* Note: You will likely need to persist this object in order to remove it later.
|
||||
*
|
||||
* @param player A player running lunar client.
|
||||
* @param waypoint A new waypoint object to send to the player.
|
||||
*/
|
||||
public void sendWaypoint(Player player, LCWaypoint waypoint) {
|
||||
sendPacket(player, new LCPacketWaypointAdd(waypoint.getName(), waypoint.getWorld(), waypoint.getColor(), waypoint.getX(), waypoint.getY(), waypoint.getZ(), waypoint.isForced(), waypoint.isVisible()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a waypoint that the server sent from a player.
|
||||
*
|
||||
* @param player A player running lunar client.
|
||||
* @param waypoint A waypoint object that the server has previously sent.
|
||||
*/
|
||||
public void removeWaypoint(Player player, LCWaypoint waypoint) {
|
||||
sendPacket(player, new LCPacketWaypointRemove(waypoint.getName(), waypoint.getWorld()));
|
||||
}
|
||||
|
||||
/**
|
||||
* The most basic component of the Lunar Client API used
|
||||
* to send packets to the Lunar Client player.
|
||||
* Implementation with direct method calls is not recommended,
|
||||
* and will likely be very brittle in regards to functionality.
|
||||
*
|
||||
* sendPacket will either send the packet immediately to the Lunar Client player
|
||||
* or if for some reason there is a delay in the connection, it will queue the packet for
|
||||
* consumption at a later date, when the player registers.
|
||||
*
|
||||
* @param player The bukkit representation of the {@link Player} to receive the packet.
|
||||
* @param packet The Lunar Client packet that should be sent to the Lunar Client player.
|
||||
* @return {@link Boolean} value of weather the packet was sent.
|
||||
*/
|
||||
public boolean sendPacket(Player player, LCPacket packet) {
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (isRunningLunarClient(playerId)) {
|
||||
String channel = MESSAGE_CHANNEL;
|
||||
player.sendPluginMessage(this, channel, LCPacket.getPacketData(packet));
|
||||
Bukkit.getPluginManager().callEvent(new LCPacketSentEvent(player, packet));
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the player hasn't been on for 2 seconds, but also
|
||||
// hasn't registered we hold on to hope they are just lagging
|
||||
// and so we save packets for them until they are proven not
|
||||
// lunar client players.
|
||||
// Either way, the packet failed to send (this time).
|
||||
|
||||
if (!playersNotRegistered.contains(playerId)) {
|
||||
if (!packetQueue.containsKey(playerId)) {
|
||||
packetQueue.put(playerId, new ArrayList<>());
|
||||
}
|
||||
packetQueue.get(playerId).add(packet);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.lunarclient.bukkitapi;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCPacketClientVoice;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCPacketVoiceMute;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.obj.ServerRule;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCPacketVoiceChannelSwitch;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCNetHandlerServer;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCPacketStaffModStatus;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCPacketEmoteBroadcast;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCPacketWaypointAdd;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCPacketWaypointRemove;
|
||||
|
||||
/**
|
||||
* An empty implementation of the server nethandler.
|
||||
*/
|
||||
public class LunarClientDefaultNetHandler implements LCNetHandlerServer {
|
||||
|
||||
/**
|
||||
* Called when a player changes their staff mode state.
|
||||
* Not currently implemented.
|
||||
* @param lcPacketStaffModStatus All the status of the players staff mode.
|
||||
*/
|
||||
@Override
|
||||
public void handleStaffModStatus(LCPacketStaffModStatus lcPacketStaffModStatus) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the client adds or edits a waypoint when the server controls waypoints.
|
||||
* A waypoint that is edited will call handleRemoveWaypoint before creating the new waypoint.
|
||||
* See {@link ServerRule} for how to control waypoints.
|
||||
*
|
||||
* @param lcPacketWaypointAdd The waypoint added by the client.
|
||||
*/
|
||||
@Override
|
||||
public void handleAddWaypoint(LCPacketWaypointAdd lcPacketWaypointAdd) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player removes a waypoint. See above (handleAddWaypoint) for more detail.
|
||||
* @param lcPacketWaypointRemove The waypoint name and world removed by the player.
|
||||
*/
|
||||
@Override
|
||||
public void handleRemoveWaypoint(LCPacketWaypointRemove lcPacketWaypointRemove) {
|
||||
|
||||
}
|
||||
|
||||
// Do not implement these, they do nothing and will not work.
|
||||
|
||||
|
||||
/**
|
||||
* Deprecated entirely from a time when Emotes went through the server.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void handleEmote(LCPacketEmoteBroadcast lcPacketEmoteBroadcast) {
|
||||
// DO NOT ATTEMPT TO IMPLEMENT
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated entirely, may return once a solution for voice is found.
|
||||
*
|
||||
* Not currently a work in progress.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void handleVoice(LCPacketClientVoice lcPacketClientVoice) {
|
||||
// DO NOT ATTEMPT TO IMPLEMENT
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated entirely, may return once a solution for voice is found.
|
||||
*
|
||||
* Not currently a work in progress.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void handleVoiceMute(LCPacketVoiceMute lcPacketVoiceMute) {
|
||||
// DO NOT ATTEMPT TO IMPLEMENT
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated entirely, may return once a solution for voice is found.
|
||||
*
|
||||
* Not currently a work in progress.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void handleVoiceChannelSwitch(LCPacketVoiceChannelSwitch lcPacketVoiceChannelSwitch) {
|
||||
// DO NOT ATTEMPT TO IMPLEMENT
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.lunarclient.bukkitapi.cooldown;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCPacketCooldown;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.lunarclient.bukkitapi.LCPacketWrapper;
|
||||
import lombok.Data;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Data
|
||||
public class LCCooldown implements LCPacketWrapper<LCPacketCooldown> {
|
||||
|
||||
private final String name;
|
||||
private final long millis;
|
||||
private final Material itemId;
|
||||
// The packet that will be sent to the Lunar Client player
|
||||
// Because of @Data, we don't need a getter.
|
||||
private final LCPacketCooldown packet;
|
||||
|
||||
/**
|
||||
* Used to create a persisting cooldown that can be sent to many players.
|
||||
*
|
||||
* @param name A unique name that is not null
|
||||
* @param millis The duration for the cooldown in milliseconds, that is greater (or equal to reset) to 0.
|
||||
* @param itemId The icon that will be displayed in Lunar Client.
|
||||
*/
|
||||
public LCCooldown(String name, long millis, Material itemId) {
|
||||
Preconditions.checkArgument(millis > 0, "Cooldown must have a valid time > 0.");
|
||||
this.name = Preconditions.checkNotNull(name, "Cooldown Name cannot be null.");
|
||||
this.millis = millis;
|
||||
this.itemId = Preconditions.checkNotNull(itemId, "Cooldown Icon cannot be null.");
|
||||
packet = new LCPacketCooldown(name, millis, itemId.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply creates a LCCooldown with seconds instead of milliseconds.
|
||||
*
|
||||
* @param name A unique name that is not null
|
||||
* @param seconds the duration for the cooldown in seconds, that is greater (or equal to reset) to 0.
|
||||
* @param item The icon that will be displayed in Lunar Client.
|
||||
*/
|
||||
public LCCooldown(String name, int seconds, Material item) {
|
||||
this(name, seconds * 1000L, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply creates a LCCooldown with a variable amount of time
|
||||
*
|
||||
* @param name A unique name that is not null
|
||||
* @param time A duration greater than 0 milliseconds.
|
||||
* @param unit A unit of measurement to put the cooldown in
|
||||
* @param item The icon that will be displayed in Lunar Client.
|
||||
*/
|
||||
public LCCooldown(String name, int time, TimeUnit unit, Material item) {
|
||||
this(name, unit.toMillis(time), item);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the cooldown from a player before it naturally expires.
|
||||
*
|
||||
* @param player The player to clear the cooldown for.
|
||||
*/
|
||||
public void clear(Player player) {
|
||||
send(player, new LCPacketCooldown(name, 0, itemId.getId()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.lunarclient.bukkitapi.cooldown;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@UtilityClass
|
||||
public class LunarClientAPICooldown {
|
||||
|
||||
private final Map<String, LCCooldown> registeredCooldowns = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Used to register a persisting cooldown.
|
||||
* Ideally 1 {@link LCCooldown} will be created for each task.
|
||||
* Create the {@link LCCooldown} once, register it and then send it to each player.
|
||||
*
|
||||
* @param cooldown The cooldown to register
|
||||
*/
|
||||
public void registerCooldown(LCCooldown cooldown) {
|
||||
registeredCooldowns.put(cooldown.getName().toLowerCase(), cooldown);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to unregister a persisting cooldown.
|
||||
* If a cooldown will no longer be used or in shutdown, unregistering is a good idea.
|
||||
*
|
||||
* @param cooldown The cooldown to register
|
||||
*/
|
||||
public void unregisterCooldown(LCCooldown cooldown) {
|
||||
registeredCooldowns.remove(cooldown.getName().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a cooldown to a Lunar Client player that has previously been registered.
|
||||
* This could be used instead of passing around a {@link LCCooldown} instance.
|
||||
*
|
||||
* @param player The player to send a cooldown to
|
||||
* @param cooldownName The name of the {@link LCCooldown} that is sent.
|
||||
*/
|
||||
public void sendCooldown(Player player, String cooldownName) {
|
||||
String cooldownId = cooldownName.toLowerCase();
|
||||
if (!registeredCooldowns.containsKey(cooldownId)) {
|
||||
throw new IllegalStateException("Attempted to send a cooldown that isn't registered [" + cooldownName + "]");
|
||||
}
|
||||
registeredCooldowns.get(cooldownId).send(player);
|
||||
}
|
||||
|
||||
public void clearCooldown(Player player, String cooldownName) {
|
||||
String cooldownId = cooldownName.toLowerCase();
|
||||
if (!registeredCooldowns.containsKey(cooldownId)) {
|
||||
throw new IllegalStateException("Attempted to send a cooldown that isn't registered [" + cooldownName + "]");
|
||||
}
|
||||
registeredCooldowns.get(cooldownId).clear(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
# Lunar Client Cooldown API
|
||||
|
||||
`The object with creating the cooldown API is to provide a really easy solution for creating cooldowns in Lunar Client.`
|
||||
|
||||
`Below are a few examples of how this can be implemented and what each implementation works well for.`
|
||||
|
||||
``Note that while the API provides an easy path for most use cases, if your use case requires something different you can always send the packet using LunarClientAPI.``
|
||||
|
||||
## Examples:
|
||||
|
||||
---
|
||||
### Example 1 - Static Timers.
|
||||
```java
|
||||
/**
|
||||
* Called when your plugin loads, used to register a static
|
||||
* cooldown, where the time doesn't change.
|
||||
*
|
||||
* This will allow you to reuse the object without keeping track of it yourself.
|
||||
*/
|
||||
private void loadPlugin() {
|
||||
LunarClientAPICooldown.registerCooldown(new LCCooldown("CombatTag", 30, Material.DIAMOND_SWORD));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player attacks another player in your code.
|
||||
* This will apply our previously registered 30 second timer, with a diamond sword image.
|
||||
*
|
||||
* @param attacker One of the players to receive the 30 second timer.
|
||||
* @param victim One of the players to receive the 30 second timer.
|
||||
*/
|
||||
private void attackPlayer(Player attacker, Player victim) {
|
||||
LunarClientAPICooldown.sendCooldown(attacker.getPlayer(), "CombatTag");
|
||||
LunarClientAPICooldown.sendCooldown(victim.getPlayer(), "CombatTag");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player dies (or some other action) in your code.
|
||||
* This will remove our previously applied 30 second timer if it exists.
|
||||
*
|
||||
* @param player The player to clear the timer for.
|
||||
*/
|
||||
public void playerDeath(Player player) {
|
||||
LunarClientAPICooldown.clearCooldown(player, "CombatTag");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Example 2 - Dynamic Teleport Timers
|
||||
|
||||
```java
|
||||
/**
|
||||
* This is the least performant option, but sometimes a good option.
|
||||
* This will create a NON-TRACKED {@link LCCooldown} that will send to a player.
|
||||
*
|
||||
* This is best used if you need a one-off cooldown that has a dynamic time or icon, meaning
|
||||
* that it will change everytime. In this example, we have a player teleporting with a variable
|
||||
* amount of time with the EnderPearl icon.
|
||||
*
|
||||
* @param player The player to receive the timer.
|
||||
* @param variableTime The variable amount of time that should be applied to the cooldown.
|
||||
*/
|
||||
private void teleportTimer(Player player, int variableTime) {
|
||||
new LCCooldown("Teleport", variableTime, Material.ENDER_PEARL).send(player);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Example 3 - Limited Objects with Dynamic Timers
|
||||
|
||||
|
||||
```java
|
||||
/**
|
||||
* This is the most performant option, but will require you to keep the LCPacketCooldown object yourself.
|
||||
* If you don't understand what is going on in this, or you do not know how to persist and pass the object
|
||||
* properly, this probably isn't the best solution for you.
|
||||
*
|
||||
* This will create just a packet object, and send it to the player(s). This is best suited for extremely
|
||||
* performant servers, or servers that have a need for dynamic timers or icons and don't want the overhead of
|
||||
* 2 objects per cooldown.
|
||||
*
|
||||
* @param player The player to send the cooldown.
|
||||
* @param variableTime The amount of time (in seconds) to send in the cooldown.
|
||||
*/
|
||||
private void teleportTimerLimitedObjects(Player player, int variableTime) {
|
||||
LunarClientAPI.getInstance().sendPacket(player, new LCPacketCooldown("Teleport", variableTime * 1000L, Material.ENDER_PEARL.getId()));
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.lunarclient.bukkitapi.event;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
public final class LCPacketReceivedEvent extends PlayerEvent {
|
||||
|
||||
@Getter private static HandlerList handlerList = new HandlerList();
|
||||
|
||||
@Getter private final LCPacket packet;
|
||||
|
||||
/**
|
||||
* Called when the player sends a {@link LCPacket}
|
||||
* to the server from the client.
|
||||
*
|
||||
* @param player The LunarClient player sending the packet.
|
||||
* @param packet The incoming packet from the client.
|
||||
*/
|
||||
public LCPacketReceivedEvent(Player player, LCPacket packet) {
|
||||
super(player);
|
||||
this.packet = packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.lunarclient.bukkitapi.event;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
public final class LCPacketSentEvent extends PlayerEvent {
|
||||
|
||||
@Getter private static HandlerList handlerList = new HandlerList();
|
||||
|
||||
@Getter private final LCPacket packet;
|
||||
|
||||
/**
|
||||
* Called when the server sends a {@link LCPacket} to the Lunar Client user.
|
||||
* There is a chance the player does not receive the packet even if this event is
|
||||
* called. There is no way to be 100% certain the client has received and registered the packet.
|
||||
*
|
||||
* @param player The player receiving the incoming packet.
|
||||
* @param packet The {@link LCPacket} the server has sent to the Lunar Client user.
|
||||
*/
|
||||
public LCPacketSentEvent(Player player, LCPacket packet) {
|
||||
super(player);
|
||||
this.packet = packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.lunarclient.bukkitapi.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
|
||||
public final class LCPlayerRegisterEvent extends PlayerEvent {
|
||||
|
||||
@Getter private static HandlerList handlerList = new HandlerList();
|
||||
|
||||
/**
|
||||
* Called whenever a player registers the LC plugin channel
|
||||
*
|
||||
* @param player The player registering as a Lunar Client user.
|
||||
*/
|
||||
public LCPlayerRegisterEvent(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.lunarclient.bukkitapi.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
public final class LCPlayerUnregisterEvent extends PlayerEvent {
|
||||
|
||||
@Getter private static HandlerList handlerList = new HandlerList();
|
||||
|
||||
/**
|
||||
* Called whenever a player unregisters the LC plugin channel
|
||||
*
|
||||
* @param player The player who has unregistered from the plugin channel.
|
||||
*/
|
||||
public LCPlayerUnregisterEvent(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package com.lunarclient.bukkitapi.listener;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCPacketUpdateWorld;
|
||||
import com.lunarclient.bukkitapi.LunarClientAPI;
|
||||
import com.lunarclient.bukkitapi.event.LCPlayerRegisterEvent;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class LunarClientLoginListener implements Listener {
|
||||
|
||||
private final LunarClientAPI lunarClientAPI;
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(lunarClientAPI, () -> {
|
||||
if (!lunarClientAPI.isRunningLunarClient(player)) {
|
||||
lunarClientAPI.failPlayerRegister(player);
|
||||
}
|
||||
}, 2 * 20L);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRegister(PlayerRegisterChannelEvent event) {
|
||||
if (!event.getChannel().equalsIgnoreCase(LunarClientAPI.MESSAGE_CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
|
||||
lunarClientAPI.registerPlayer(player);
|
||||
|
||||
lunarClientAPI.getServer().getPluginManager().callEvent(new LCPlayerRegisterEvent(event.getPlayer()));
|
||||
updateWorld(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onUnregister(PlayerUnregisterChannelEvent event) {
|
||||
if (event.getChannel().equalsIgnoreCase(LunarClientAPI.MESSAGE_CHANNEL)) {
|
||||
lunarClientAPI.unregisterPlayer(event.getPlayer(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onUnregister(PlayerQuitEvent event) {
|
||||
lunarClientAPI.unregisterPlayer(event.getPlayer(), true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onWorldChange(PlayerChangedWorldEvent event) {
|
||||
updateWorld(event.getPlayer());
|
||||
}
|
||||
|
||||
private void updateWorld(Player player) {
|
||||
String worldIdentifier = lunarClientAPI.getWorldIdentifier(player.getWorld());
|
||||
|
||||
lunarClientAPI.sendPacket(player, new LCPacketUpdateWorld(worldIdentifier));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.lunarclient.bukkitapi.nethandler;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ByteBufWrapper {
|
||||
|
||||
private final ByteBuf buf;
|
||||
|
||||
public ByteBufWrapper(ByteBuf buf) {
|
||||
this.buf = buf;
|
||||
}
|
||||
|
||||
public void writeVarInt(int b) {
|
||||
while ((b & -128) != 0) {
|
||||
this.buf.writeByte(b & 127 | 128);
|
||||
b >>>= 7;
|
||||
}
|
||||
|
||||
this.buf.writeByte(b);
|
||||
}
|
||||
|
||||
public int readVarInt() {
|
||||
int i = 0;
|
||||
int chunk = 0;
|
||||
byte b;
|
||||
|
||||
do {
|
||||
b = this.buf.readByte();
|
||||
i |= (b & 127) << chunk++ * 7;
|
||||
|
||||
if (chunk > 5) {
|
||||
throw new RuntimeException("VarInt too big");
|
||||
}
|
||||
} while ((b & 128) == 128);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public void writeString(String s) {
|
||||
byte[] arr = s.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
this.writeVarInt(arr.length);
|
||||
this.buf.writeBytes(arr);
|
||||
}
|
||||
|
||||
public String readString() {
|
||||
int len = readVarInt();
|
||||
|
||||
byte[] buffer = new byte[len];
|
||||
buf.readBytes(buffer);
|
||||
|
||||
return new String(buffer, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public void writeUUID(UUID uuid) {
|
||||
this.buf.writeLong(uuid.getMostSignificantBits());
|
||||
this.buf.writeLong(uuid.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
public UUID readUUID() {
|
||||
long mostSigBits = this.buf.readLong();
|
||||
long leastSigBits = this.buf.readLong();
|
||||
|
||||
return new UUID(mostSigBits, leastSigBits);
|
||||
}
|
||||
|
||||
public ByteBuf buf() {
|
||||
return buf;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package com.lunarclient.bukkitapi.nethandler;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.client.*;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCPacketVoice;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCPacketVoiceChannel;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCPacketVoiceChannelRemove;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCPacketVoiceChannelUpdate;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCPacketEmoteBroadcast;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCPacketWaypointAdd;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCPacketWaypointRemove;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class LCPacket {
|
||||
|
||||
private static final Map<Class, Integer> classToId = new HashMap<>();
|
||||
private static final Map<Integer, Class> idToClass = new HashMap<>();
|
||||
|
||||
static {
|
||||
// server
|
||||
addPacket(0, LCPacketClientVoice.class);
|
||||
addPacket(16, LCPacketVoice.class);
|
||||
addPacket(1, LCPacketVoiceChannelSwitch.class);
|
||||
addPacket(2, LCPacketVoiceMute.class);
|
||||
|
||||
addPacket(17, LCPacketVoiceChannel.class);
|
||||
addPacket(18, LCPacketVoiceChannelRemove.class);
|
||||
addPacket(19, LCPacketVoiceChannelUpdate.class);
|
||||
|
||||
// client
|
||||
addPacket(3, LCPacketCooldown.class);
|
||||
addPacket(4, LCPacketHologram.class);
|
||||
addPacket(6, LCPacketHologramRemove.class);
|
||||
addPacket(5, LCPacketHologramUpdate.class);
|
||||
addPacket(7, LCPacketNametagsOverride.class);
|
||||
addPacket(8, LCPacketNametagsUpdate.class);
|
||||
addPacket(9, LCPacketNotification.class);
|
||||
addPacket(10, LCPacketServerRule.class);
|
||||
addPacket(11, LCPacketServerUpdate.class);
|
||||
addPacket(12, LCPacketStaffModState.class);
|
||||
addPacket(13, LCPacketTeammates.class);
|
||||
addPacket(14, LCPacketTitle.class);
|
||||
addPacket(15, LCPacketUpdateWorld.class);
|
||||
addPacket(20, LCPacketWorldBorder.class);
|
||||
addPacket(21, LCPacketWorldBorderRemove.class);
|
||||
addPacket(22, LCPacketWorldBorderUpdate.class);
|
||||
addPacket(25, LCPacketGhost.class);
|
||||
addPacket(28, LCPacketBossBar.class);
|
||||
addPacket(29, LCPacketWorldBorderCreateNew.class);
|
||||
addPacket(30, LCPacketWorldBorderUpdateNew.class);
|
||||
addPacket(31, LCPacketModSettings.class);
|
||||
|
||||
// shared
|
||||
addPacket(26, LCPacketEmoteBroadcast.class);
|
||||
addPacket(23, LCPacketWaypointAdd.class);
|
||||
addPacket(24, LCPacketWaypointRemove.class);
|
||||
}
|
||||
|
||||
private Object attachment;
|
||||
|
||||
public static LCPacket handle(byte[] data) {
|
||||
return handle(data, null);
|
||||
}
|
||||
|
||||
public static LCPacket handle(byte[] data, Object attachment) {
|
||||
ByteBufWrapper wrappedBuffer = new ByteBufWrapper(Unpooled.wrappedBuffer(data));
|
||||
|
||||
int packetId = wrappedBuffer.readVarInt();
|
||||
Class packetClass = idToClass.get(packetId);
|
||||
|
||||
if (packetClass != null) {
|
||||
try {
|
||||
LCPacket packet = (LCPacket) packetClass.newInstance();
|
||||
|
||||
packet.attach(attachment);
|
||||
packet.read(wrappedBuffer);
|
||||
|
||||
return packet;
|
||||
} catch (IOException | InstantiationException | IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static byte[] getPacketData(LCPacket packet) {
|
||||
return getPacketBuf(packet).array();
|
||||
}
|
||||
|
||||
public static ByteBuf getPacketBuf(LCPacket packet) {
|
||||
ByteBufWrapper wrappedBuffer = new ByteBufWrapper(Unpooled.buffer());
|
||||
wrappedBuffer.writeVarInt(classToId.get(packet.getClass()));
|
||||
|
||||
try {
|
||||
packet.write(wrappedBuffer);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return wrappedBuffer.buf();
|
||||
}
|
||||
|
||||
private static void addPacket(int id, Class clazz) {
|
||||
if (classToId.containsKey(clazz)) {
|
||||
throw new IllegalArgumentException("Duplicate packet class (" + clazz.getSimpleName() + "), already used by " + classToId.get(clazz));
|
||||
} else if (idToClass.containsKey(id)) {
|
||||
throw new IllegalArgumentException("Duplicate packet ID (" + id + "), already used by " + idToClass.get(id).getSimpleName());
|
||||
}
|
||||
|
||||
classToId.put(clazz, id);
|
||||
idToClass.put(id, clazz);
|
||||
}
|
||||
|
||||
public abstract void write(ByteBufWrapper buf) throws IOException;
|
||||
|
||||
public abstract void read(ByteBufWrapper buf) throws IOException;
|
||||
|
||||
public abstract void process(LCNetHandler handler);
|
||||
|
||||
public <T> void attach(T obj) {
|
||||
this.attachment = obj;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getAttachment() {
|
||||
return (T) attachment;
|
||||
}
|
||||
|
||||
protected void writeBlob(ByteBufWrapper b, byte[] bytes) {
|
||||
b.buf().writeShort(bytes.length);
|
||||
b.buf().writeBytes(bytes);
|
||||
}
|
||||
|
||||
protected byte[] readBlob(ByteBufWrapper b) {
|
||||
short key = b.buf().readShort();
|
||||
|
||||
if (key < 0) {
|
||||
System.out.println("Key was smaller than nothing! Weird key!");
|
||||
} else {
|
||||
byte[] blob = new byte[key];
|
||||
b.buf().readBytes(blob);
|
||||
return blob;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.lunarclient.bukkitapi.nethandler;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.client.obj.ModSettings;
|
||||
import com.google.gson.*;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModSettingsAdapter implements JsonDeserializer<ModSettings>, JsonSerializer<ModSettings> {
|
||||
@Override
|
||||
public ModSettings deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
ModSettings settings = new ModSettings();
|
||||
if (!jsonElement.isJsonObject()) {
|
||||
return settings;
|
||||
}
|
||||
|
||||
JsonObject object = jsonElement.getAsJsonObject();
|
||||
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
|
||||
if (!entry.getValue().isJsonObject()) {
|
||||
continue;
|
||||
}
|
||||
JsonObject modSettingObject = entry.getValue().getAsJsonObject();
|
||||
|
||||
settings.getModSettings().put(entry.getKey(), deserializeModSetting(modSettingObject));
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(ModSettings modSettings, Type type, JsonSerializationContext jsonSerializationContext) {
|
||||
JsonObject object = new JsonObject();
|
||||
for (Map.Entry<String, ModSettings.ModSetting> entry : modSettings.getModSettings().entrySet()) {
|
||||
object.add(entry.getKey(), serializeModSetting(entry.getValue()));
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
private JsonObject serializeModSetting(ModSettings.ModSetting setting) {
|
||||
JsonObject object = new JsonObject();
|
||||
JsonObject properties = new JsonObject();
|
||||
object.addProperty("enabled", setting.isEnabled());
|
||||
for (Map.Entry<String, Object> entry : setting.getProperties().entrySet()) {
|
||||
|
||||
JsonPrimitive primitive;
|
||||
if (entry.getValue() instanceof Boolean) {
|
||||
primitive = new JsonPrimitive((Boolean) entry.getValue());
|
||||
} else if (entry.getValue() instanceof String) {
|
||||
primitive = new JsonPrimitive((String) entry.getValue());
|
||||
} else if (entry.getValue() instanceof Number) {
|
||||
primitive = new JsonPrimitive((Number) entry.getValue());
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
properties.add(entry.getKey(), primitive);
|
||||
}
|
||||
object.add("properties", properties);
|
||||
return object;
|
||||
}
|
||||
|
||||
private ModSettings.ModSetting deserializeModSetting(JsonObject object) {
|
||||
JsonObject propertiesObject = object.get("properties").getAsJsonObject();
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
for (Map.Entry<String, JsonElement> entry : propertiesObject.entrySet()) {
|
||||
if (!entry.getValue().isJsonPrimitive()) {
|
||||
continue;
|
||||
}
|
||||
JsonPrimitive primitive = entry.getValue().getAsJsonPrimitive();
|
||||
Object toSet;
|
||||
if (primitive.isString()) {
|
||||
toSet = primitive.getAsString();
|
||||
} else if (primitive.isNumber()) {
|
||||
toSet = primitive.getAsNumber();
|
||||
} else if (primitive.isBoolean()) {
|
||||
toSet = primitive.getAsBoolean();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
properties.put(entry.getKey(), toSet);
|
||||
}
|
||||
return new ModSettings.ModSetting(object.get("enabled").getAsBoolean(), properties);
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCPacketVoice;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCPacketVoiceChannel;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCPacketVoiceChannelRemove;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCPacketVoiceChannelUpdate;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
|
||||
public interface LCNetHandlerClient extends LCNetHandler {
|
||||
|
||||
void handleBossBar(LCPacketBossBar packet);
|
||||
void handleCooldown(LCPacketCooldown packet);
|
||||
void handleGhost(LCPacketGhost packet);
|
||||
void handleAddHologram(LCPacketHologram packet);
|
||||
void handleRemoveHologram(LCPacketHologramRemove packet);
|
||||
void handleUpdateHologram(LCPacketHologramUpdate packet);
|
||||
void handleOverrideNametags(LCPacketNametagsOverride packet);
|
||||
void handleNametagsUpdate(LCPacketNametagsUpdate packet);
|
||||
void handleNotification(LCPacketNotification packet);
|
||||
void handleServerRule(LCPacketServerRule packet);
|
||||
void handleServerUpdate(LCPacketServerUpdate packet);
|
||||
void handleStaffModState(LCPacketStaffModState packet);
|
||||
void handleTeammates(LCPacketTeammates packet);
|
||||
void handleTitle(LCPacketTitle packet);
|
||||
void handleUpdateWorld(LCPacketUpdateWorld packet);
|
||||
void handleWorldBorder(LCPacketWorldBorder packet);
|
||||
void handleWorldBorderCreateNew(LCPacketWorldBorderCreateNew packet);
|
||||
void handleWorldBorderRemove(LCPacketWorldBorderRemove packet);
|
||||
void handleWorldBorderUpdate(LCPacketWorldBorderUpdate packet);
|
||||
void handleWorldBorderUpdateNew(LCPacketWorldBorderUpdateNew packet);
|
||||
void handleVoice(LCPacketVoice packet);
|
||||
void handleVoiceChannels(LCPacketVoiceChannel packet);
|
||||
void handleVoiceChannelUpdate(LCPacketVoiceChannelUpdate packet);
|
||||
void handleVoiceChannelDelete(LCPacketVoiceChannelRemove packet);
|
||||
void handleModSettings(LCPacketModSettings packetModSettings);
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketBossBar extends LCPacket {
|
||||
|
||||
@Getter private int action;
|
||||
@Getter private String text;
|
||||
@Getter private float health;
|
||||
|
||||
public LCPacketBossBar() {}
|
||||
|
||||
public LCPacketBossBar(int action, String text, float health) {
|
||||
this.action = action;
|
||||
this.text = text;
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeVarInt(action);
|
||||
|
||||
if (action == 0) {
|
||||
buf.writeString(text);
|
||||
buf.buf().writeFloat(health);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.action = buf.readVarInt();
|
||||
|
||||
if (action == 0) {
|
||||
text = buf.readString();
|
||||
health = buf.buf().readFloat();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleBossBar(this);
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCNetHandlerServer;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketClientVoice extends LCPacket {
|
||||
|
||||
@Getter private byte[] data;
|
||||
|
||||
public LCPacketClientVoice() {
|
||||
}
|
||||
|
||||
public LCPacketClientVoice(byte[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper b) throws IOException {
|
||||
writeBlob(b, this.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper b) throws IOException {
|
||||
this.data = readBlob(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerServer) handler).handleVoice(this);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketCooldown extends LCPacket {
|
||||
|
||||
@Getter private String message;
|
||||
@Getter private long durationMs;
|
||||
@Getter private int iconId;
|
||||
|
||||
public LCPacketCooldown() {}
|
||||
|
||||
public LCPacketCooldown(String message, long durationMs, int iconId) {
|
||||
this.message = message;
|
||||
this.durationMs = durationMs;
|
||||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(message);
|
||||
buf.buf().writeLong(durationMs);
|
||||
buf.buf().writeInt(iconId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
message = buf.readString();
|
||||
durationMs = buf.buf().readLong();
|
||||
iconId = buf.buf().readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleCooldown(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class LCPacketGhost extends LCPacket {
|
||||
|
||||
@Getter private List<UUID> addGhostList;
|
||||
@Getter private List<UUID> removeGhostList;
|
||||
|
||||
public LCPacketGhost() {}
|
||||
|
||||
public LCPacketGhost(List<UUID> uuidList, List<UUID> removeGhostList) {
|
||||
this.addGhostList = uuidList;
|
||||
this.removeGhostList = removeGhostList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeVarInt(addGhostList.size());
|
||||
|
||||
for (UUID uuid : addGhostList) {
|
||||
buf.writeUUID(uuid);
|
||||
}
|
||||
|
||||
buf.writeVarInt(removeGhostList.size());
|
||||
|
||||
for (UUID uuid : removeGhostList) {
|
||||
buf.writeUUID(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
int addListSize = buf.readVarInt();
|
||||
this.addGhostList = new ArrayList<>(addListSize);
|
||||
|
||||
for (int i = 0; i < addListSize; i++) {
|
||||
this.addGhostList.add(buf.readUUID());
|
||||
}
|
||||
|
||||
int removeListSize = buf.readVarInt();
|
||||
this.removeGhostList = new ArrayList<>(removeListSize);
|
||||
|
||||
for (int i = 0; i < removeListSize; i++) {
|
||||
this.removeGhostList.add(buf.readUUID());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleGhost(this);
|
||||
}
|
||||
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class LCPacketHologram extends LCPacket {
|
||||
|
||||
@Getter private UUID uuid;
|
||||
@Getter private double x;
|
||||
@Getter private double y;
|
||||
@Getter private double z;
|
||||
@Getter private List<String> lines;
|
||||
|
||||
public LCPacketHologram() {}
|
||||
|
||||
public LCPacketHologram(UUID uuid, double x, double y, double z, List<String> lines) {
|
||||
this.uuid = uuid;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeUUID(uuid);
|
||||
buf.buf().writeDouble(x);
|
||||
buf.buf().writeDouble(y);
|
||||
buf.buf().writeDouble(z);
|
||||
buf.writeVarInt(lines.size());
|
||||
|
||||
for (String s : lines) {
|
||||
buf.writeString(s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.uuid = buf.readUUID();
|
||||
this.x = buf.buf().readDouble();
|
||||
this.y = buf.buf().readDouble();
|
||||
this.z = buf.buf().readDouble();
|
||||
int linesSize = buf.readVarInt();
|
||||
this.lines = new ArrayList<>(linesSize);
|
||||
|
||||
for (int i = 0; i < linesSize; i++) {
|
||||
this.lines.add(buf.readString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleAddHologram(this);
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class LCPacketHologramRemove extends LCPacket {
|
||||
|
||||
@Getter private UUID uuid;
|
||||
|
||||
public LCPacketHologramRemove() {}
|
||||
|
||||
public LCPacketHologramRemove(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeUUID(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.uuid = buf.readUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleRemoveHologram(this);
|
||||
}
|
||||
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class LCPacketHologramUpdate extends LCPacket {
|
||||
|
||||
@Getter private UUID uuid;
|
||||
@Getter private List<String> lines;
|
||||
|
||||
public LCPacketHologramUpdate() {}
|
||||
|
||||
public LCPacketHologramUpdate(UUID uuid, List<String> lines) {
|
||||
this.uuid = uuid;
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeUUID(uuid);
|
||||
buf.writeVarInt(lines.size());
|
||||
|
||||
for (String s : lines) {
|
||||
buf.writeString(s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.uuid = buf.readUUID();
|
||||
int linesSize = buf.readVarInt();
|
||||
this.lines = new ArrayList<>(linesSize);
|
||||
|
||||
for (int i = 0; i < linesSize; i++) {
|
||||
this.lines.add(buf.readString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleUpdateHologram(this);
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.obj.ModSettings;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketModSettings extends LCPacket {
|
||||
|
||||
private ModSettings settings;
|
||||
|
||||
public LCPacketModSettings() {}
|
||||
|
||||
public LCPacketModSettings(ModSettings modSettings) {
|
||||
this.settings = modSettings;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(ModSettings.GSON.toJson(this.settings));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.settings = ModSettings.GSON.fromJson(buf.readString(), ModSettings.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleModSettings(this);
|
||||
}
|
||||
|
||||
public ModSettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class LCPacketNametagsOverride extends LCPacket {
|
||||
|
||||
@Getter private UUID player;
|
||||
@Getter private List<String> tags;
|
||||
|
||||
public LCPacketNametagsOverride() {}
|
||||
|
||||
public LCPacketNametagsOverride(UUID player, List<String> tags) {
|
||||
this.player = player;
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeUUID(this.player);
|
||||
buf.buf().writeBoolean(this.tags != null);
|
||||
|
||||
if (this.tags != null) {
|
||||
buf.writeVarInt(tags.size());
|
||||
|
||||
for (String tag : tags) {
|
||||
buf.writeString(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.player = buf.readUUID();
|
||||
|
||||
if (buf.buf().readBoolean()) {
|
||||
int tagsSize = buf.readVarInt();
|
||||
this.tags = new ArrayList<>(tagsSize);
|
||||
|
||||
for (int i = 0; i < tagsSize; i++) {
|
||||
tags.add(buf.readString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleOverrideNametags(this);
|
||||
}
|
||||
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public final class LCPacketNametagsUpdate extends LCPacket {
|
||||
|
||||
@Getter private Map<UUID, List<String>> playersMap;
|
||||
|
||||
public LCPacketNametagsUpdate() {}
|
||||
|
||||
public LCPacketNametagsUpdate(Map<UUID, List<String>> playersMap) {
|
||||
this.playersMap = playersMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeVarInt(playersMap == null ? -1 : playersMap.size());
|
||||
|
||||
if (playersMap != null) {
|
||||
playersMap.forEach((uuid, tags) -> {
|
||||
buf.writeUUID(uuid);
|
||||
buf.writeVarInt(tags.size());
|
||||
|
||||
for (String tag : tags) {
|
||||
buf.writeString(tag);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
int playersMapSize = buf.readVarInt();
|
||||
|
||||
if (playersMapSize != -1) {
|
||||
this.playersMap = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < playersMapSize; i++) {
|
||||
UUID uuid = buf.readUUID();
|
||||
int tagsSize = buf.readVarInt();
|
||||
List<String> tags = new ArrayList<>(tagsSize);
|
||||
|
||||
for (int j = 0; j < tagsSize; j++) {
|
||||
tags.add(buf.readString());
|
||||
}
|
||||
|
||||
this.playersMap.put(uuid, tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleNametagsUpdate(this);
|
||||
}
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketNotification extends LCPacket {
|
||||
|
||||
@Getter private String message;
|
||||
@Getter private long durationMs;
|
||||
@Getter private String level;
|
||||
|
||||
public LCPacketNotification() {}
|
||||
|
||||
public LCPacketNotification(String message, long durationMs, String level) {
|
||||
this.message = message;
|
||||
this.durationMs = durationMs;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(message);
|
||||
buf.buf().writeLong(durationMs);
|
||||
buf.writeString(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.message = buf.readString();
|
||||
this.durationMs = buf.buf().readLong();
|
||||
this.level = buf.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleNotification(this);
|
||||
}
|
||||
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.obj.ServerRule;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketServerRule extends LCPacket {
|
||||
|
||||
@Getter private ServerRule rule;
|
||||
@Getter private int intValue;
|
||||
@Getter private float floatValue;
|
||||
@Getter private boolean booleanValue;
|
||||
@Getter private String stringValue = "";
|
||||
|
||||
public LCPacketServerRule() {}
|
||||
|
||||
public LCPacketServerRule(ServerRule rule, float value) {
|
||||
this.rule = rule;
|
||||
this.floatValue = value;
|
||||
}
|
||||
|
||||
public LCPacketServerRule(ServerRule rule, boolean value) {
|
||||
this.rule = rule;
|
||||
this.booleanValue = value;
|
||||
}
|
||||
|
||||
public LCPacketServerRule(ServerRule rule, int value) {
|
||||
this.rule = rule;
|
||||
this.intValue = value;
|
||||
}
|
||||
|
||||
public LCPacketServerRule(ServerRule rule, String value) {
|
||||
this.rule = rule;
|
||||
this.stringValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(rule.getId());
|
||||
buf.buf().writeBoolean(booleanValue);
|
||||
buf.buf().writeInt(intValue);
|
||||
buf.buf().writeFloat(floatValue);
|
||||
buf.writeString(stringValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.rule = ServerRule.getRule(buf.readString());
|
||||
this.booleanValue = buf.buf().readBoolean();
|
||||
this.intValue = buf.buf().readInt();
|
||||
this.floatValue = buf.buf().readFloat();
|
||||
this.stringValue = buf.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleServerRule(this);
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketServerUpdate extends LCPacket {
|
||||
|
||||
@Getter private String server;
|
||||
|
||||
public LCPacketServerUpdate() {}
|
||||
|
||||
public LCPacketServerUpdate(String server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.server = buf.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleServerUpdate(this);
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketStaffModState extends LCPacket {
|
||||
|
||||
@Getter private String mod;
|
||||
@Getter private boolean state;
|
||||
|
||||
public LCPacketStaffModState() {}
|
||||
|
||||
public LCPacketStaffModState(String mod, boolean state) {
|
||||
this.mod = mod;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(mod);
|
||||
buf.buf().writeBoolean(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.mod = buf.readString();
|
||||
this.state = buf.buf().readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleStaffModState(this);
|
||||
}
|
||||
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class LCPacketTeammates extends LCPacket {
|
||||
|
||||
@Getter private UUID leader;
|
||||
@Getter private long lastMs;
|
||||
@Getter private Map<UUID, Map<String, Double>> players;
|
||||
|
||||
public LCPacketTeammates() {}
|
||||
|
||||
public LCPacketTeammates(UUID leader, long lastMs, Map<UUID, Map<String, Double>> players) {
|
||||
this.leader = leader;
|
||||
this.lastMs = lastMs;
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.buf().writeBoolean(leader != null);
|
||||
|
||||
if (leader != null) {
|
||||
buf.writeUUID(leader);
|
||||
}
|
||||
|
||||
buf.buf().writeLong(lastMs);
|
||||
buf.writeVarInt(this.players.size());
|
||||
|
||||
this.players.forEach((uuid, posMap) -> {
|
||||
buf.writeUUID(uuid);
|
||||
buf.writeVarInt(posMap.size());
|
||||
|
||||
posMap.forEach((key, val) -> {
|
||||
buf.writeString(key);
|
||||
buf.buf().writeDouble(val);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
if (buf.buf().readBoolean()) {
|
||||
this.leader = buf.readUUID();
|
||||
}
|
||||
|
||||
this.lastMs = buf.buf().readLong();
|
||||
|
||||
int playersSize = buf.readVarInt();
|
||||
this.players = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < playersSize; i++) {
|
||||
UUID uuid = buf.readUUID();
|
||||
int posMapSize = buf.readVarInt();
|
||||
Map<String, Double> posMap = new HashMap<>();
|
||||
|
||||
for (int j = 0; j < posMapSize; j++) {
|
||||
String key = buf.readString();
|
||||
double val = buf.buf().readDouble();
|
||||
|
||||
posMap.put(key, val);
|
||||
}
|
||||
|
||||
this.players.put(uuid, posMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleTeammates(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketTitle extends LCPacket {
|
||||
|
||||
@Getter private String type;
|
||||
@Getter private String message;
|
||||
@Getter private float scale;
|
||||
@Getter private long displayTimeMs;
|
||||
@Getter private long fadeInTimeMs;
|
||||
@Getter private long fadeOutTimeMs;
|
||||
|
||||
public LCPacketTitle() {}
|
||||
|
||||
public LCPacketTitle(String type, String message, long displayTimeMs, long fadeInTimeMs, long fadeOutTimeMs) {
|
||||
this(type, message, 1F, displayTimeMs, fadeInTimeMs, fadeOutTimeMs);
|
||||
}
|
||||
|
||||
public LCPacketTitle(String type, String message, float scale, long displayTimeMs, long fadeInTimeMs, long fadeOutTimeMs) {
|
||||
this.type = type;
|
||||
this.message = message;
|
||||
this.scale = scale;
|
||||
this.displayTimeMs = displayTimeMs;
|
||||
this.fadeInTimeMs = fadeInTimeMs;
|
||||
this.fadeOutTimeMs = fadeOutTimeMs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(type);
|
||||
buf.writeString(message);
|
||||
buf.buf().writeFloat(scale);
|
||||
buf.buf().writeLong(displayTimeMs);
|
||||
buf.buf().writeLong(fadeInTimeMs);
|
||||
buf.buf().writeLong(fadeOutTimeMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.type = buf.readString();
|
||||
this.message = buf.readString();
|
||||
this.scale = buf.buf().readFloat();
|
||||
this.displayTimeMs = buf.buf().readLong();
|
||||
this.fadeInTimeMs = buf.buf().readLong();
|
||||
this.fadeOutTimeMs = buf.buf().readLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleTitle(this);
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketUpdateWorld extends LCPacket {
|
||||
|
||||
@Getter private String world;
|
||||
|
||||
public LCPacketUpdateWorld() {}
|
||||
|
||||
public LCPacketUpdateWorld(String world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.world = buf.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleUpdateWorld(this);
|
||||
}
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCNetHandlerServer;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class LCPacketVoiceChannelSwitch extends LCPacket {
|
||||
|
||||
@Getter private UUID switchingTo;
|
||||
|
||||
public LCPacketVoiceChannelSwitch() {
|
||||
}
|
||||
|
||||
public LCPacketVoiceChannelSwitch(UUID switchingTo) {
|
||||
this.switchingTo = switchingTo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper b) throws IOException {
|
||||
b.writeUUID(switchingTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper b) throws IOException {
|
||||
this.switchingTo = b.readUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerServer) handler).handleVoiceChannelSwitch(this);
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.server.LCNetHandlerServer;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class LCPacketVoiceMute extends LCPacket {
|
||||
|
||||
@Getter private UUID muting;
|
||||
|
||||
@Getter private int volume;
|
||||
|
||||
public LCPacketVoiceMute() {
|
||||
}
|
||||
|
||||
public LCPacketVoiceMute(UUID muting) {
|
||||
this(muting, 0);
|
||||
}
|
||||
|
||||
public LCPacketVoiceMute(UUID muting, int volume) {
|
||||
this.muting = muting;
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper b) throws IOException {
|
||||
b.writeUUID(muting);
|
||||
b.writeVarInt(volume);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper b) throws IOException {
|
||||
this.muting = b.readUUID();
|
||||
this.volume = b.readVarInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerServer) handler).handleVoiceMute(this);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketWorldBorder extends LCPacket {
|
||||
|
||||
@Getter private String id;
|
||||
@Getter private String world;
|
||||
@Getter private boolean cancelsExit;
|
||||
@Getter private boolean canShrinkExpand;
|
||||
@Getter private int color = 0xFF3333FF;
|
||||
@Getter private double minX;
|
||||
@Getter private double minZ;
|
||||
@Getter private double maxX;
|
||||
@Getter private double maxZ;
|
||||
|
||||
public LCPacketWorldBorder() {}
|
||||
|
||||
public LCPacketWorldBorder(String id, String world, boolean cancelsExit, boolean canShrinkExpand, int color, double minX, double minZ, double maxX, double maxZ) {
|
||||
this.id = id;
|
||||
this.world = world;
|
||||
this.cancelsExit = cancelsExit;
|
||||
this.canShrinkExpand = canShrinkExpand;
|
||||
this.color = color;
|
||||
this.minX = minX;
|
||||
this.minZ = minZ;
|
||||
this.maxX = maxX;
|
||||
this.maxZ = maxZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.buf().writeBoolean(id != null);
|
||||
|
||||
if (id != null) {
|
||||
buf.writeString(id);
|
||||
}
|
||||
|
||||
buf.writeString(world);
|
||||
buf.buf().writeBoolean(cancelsExit);
|
||||
buf.buf().writeBoolean(canShrinkExpand);
|
||||
buf.buf().writeInt(color);
|
||||
buf.buf().writeDouble(minX);
|
||||
buf.buf().writeDouble(minZ);
|
||||
buf.buf().writeDouble(maxX);
|
||||
buf.buf().writeDouble(maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
if (buf.buf().readBoolean()) {
|
||||
this.id = buf.readString();
|
||||
}
|
||||
|
||||
this.world = buf.readString();
|
||||
this.cancelsExit = buf.buf().readBoolean();
|
||||
this.canShrinkExpand = buf.buf().readBoolean();
|
||||
this.color = buf.buf().readInt();
|
||||
this.minX = buf.buf().readDouble();
|
||||
this.minZ = buf.buf().readDouble();
|
||||
this.maxX = buf.buf().readDouble();
|
||||
this.maxZ = buf.buf().readDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleWorldBorder(this);
|
||||
}
|
||||
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LCPacketWorldBorderCreateNew extends LCPacket {
|
||||
|
||||
private String id;
|
||||
|
||||
private String world;
|
||||
|
||||
private boolean cancelsEntry, cancelsExit;
|
||||
|
||||
private boolean canShrinkExpand;
|
||||
|
||||
private int color = 0xFF3333FF;
|
||||
|
||||
private double minX, minZ, maxX, maxZ;
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper b) throws IOException {
|
||||
b.buf().writeBoolean(id != null);
|
||||
if (id != null) b.writeString(id);
|
||||
b.writeString(world);
|
||||
b.buf().writeBoolean(cancelsEntry);
|
||||
b.buf().writeBoolean(cancelsExit);
|
||||
b.buf().writeBoolean(canShrinkExpand);
|
||||
b.buf().writeInt(color);
|
||||
b.buf().writeDouble(minX);
|
||||
b.buf().writeDouble(minZ);
|
||||
b.buf().writeDouble(maxX);
|
||||
b.buf().writeDouble(maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper b) throws IOException {
|
||||
if (b.buf().readBoolean()) {
|
||||
this.id = b.readString();
|
||||
}
|
||||
|
||||
this.world = b.readString();
|
||||
this.cancelsEntry = b.buf().readBoolean();
|
||||
this.cancelsExit = b.buf().readBoolean();
|
||||
this.canShrinkExpand = b.buf().readBoolean();
|
||||
this.color = b.buf().readInt();
|
||||
this.minX = b.buf().readDouble();
|
||||
this.minZ = b.buf().readDouble();
|
||||
this.maxX = b.buf().readDouble();
|
||||
this.maxZ = b.buf().readDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleWorldBorderCreateNew(this);
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketWorldBorderRemove extends LCPacket {
|
||||
|
||||
@Getter private String id;
|
||||
|
||||
public LCPacketWorldBorderRemove() {}
|
||||
|
||||
public LCPacketWorldBorderRemove(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.id = buf.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleWorldBorderRemove(this);
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketWorldBorderUpdate extends LCPacket {
|
||||
|
||||
@Getter private String id;
|
||||
@Getter private double minX;
|
||||
@Getter private double minZ;
|
||||
@Getter private double maxX;
|
||||
@Getter private double maxZ;
|
||||
@Getter private int durationTicks;
|
||||
|
||||
public LCPacketWorldBorderUpdate() {}
|
||||
|
||||
public LCPacketWorldBorderUpdate(String id, double minX, double minZ, double maxX, double maxZ, int durationTicks) {
|
||||
this.id = id;
|
||||
this.minX = minX;
|
||||
this.minZ = minZ;
|
||||
this.maxX = maxX;
|
||||
this.maxZ = maxZ;
|
||||
this.durationTicks = durationTicks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(id);
|
||||
buf.buf().writeDouble(minX);
|
||||
buf.buf().writeDouble(minZ);
|
||||
buf.buf().writeDouble(maxX);
|
||||
buf.buf().writeDouble(maxZ);
|
||||
buf.buf().writeInt(durationTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.id = buf.readString();
|
||||
this.minX = buf.buf().readDouble();
|
||||
this.minZ = buf.buf().readDouble();
|
||||
this.maxX = buf.buf().readDouble();
|
||||
this.maxZ = buf.buf().readDouble();
|
||||
this.durationTicks = buf.buf().readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleWorldBorderUpdate(this);
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LCPacketWorldBorderUpdateNew extends LCPacket {
|
||||
|
||||
private String id;
|
||||
|
||||
private double minX, minZ, maxX, maxZ;
|
||||
private int durationTicks;
|
||||
|
||||
private boolean cancelsEntry, cancelsExit;
|
||||
private int color;
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper b) throws IOException {
|
||||
b.writeString(id);
|
||||
b.buf().writeDouble(minX);
|
||||
b.buf().writeDouble(minZ);
|
||||
b.buf().writeDouble(maxX);
|
||||
b.buf().writeDouble(maxZ);
|
||||
b.buf().writeInt(durationTicks);
|
||||
b.buf().writeBoolean(cancelsEntry);
|
||||
b.buf().writeBoolean(cancelsExit);
|
||||
b.buf().writeInt(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper b) throws IOException {
|
||||
this.id = b.readString();
|
||||
this.minX = b.buf().readDouble();
|
||||
this.minZ = b.buf().readDouble();
|
||||
this.maxX = b.buf().readDouble();
|
||||
this.maxZ = b.buf().readDouble();
|
||||
this.durationTicks = b.buf().readInt();
|
||||
this.cancelsEntry = b.buf().readBoolean();
|
||||
this.cancelsExit = b.buf().readBoolean();
|
||||
this.color = b.buf().readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleWorldBorderUpdateNew(this);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client.obj;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.lunarclient.bukkitapi.nethandler.ModSettingsAdapter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class ModSettings {
|
||||
|
||||
public static final Gson GSON = new GsonBuilder().registerTypeHierarchyAdapter(ModSettings.class, new ModSettingsAdapter()).create();
|
||||
|
||||
private Map<String, ModSetting> modSettings = new HashMap<>();
|
||||
|
||||
public ModSettings addModSetting(String modId, ModSetting setting) {
|
||||
modSettings.put(modId, setting);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModSetting getModSetting(String modId) {
|
||||
return this.modSettings.get(modId);
|
||||
}
|
||||
|
||||
public Map<String, ModSetting> getModSettings() {
|
||||
return modSettings;
|
||||
}
|
||||
|
||||
public static class ModSetting {
|
||||
private boolean enabled;
|
||||
private Map<String, Object> properties;
|
||||
|
||||
public ModSetting() { } // for serialization
|
||||
|
||||
public ModSetting(boolean enabled, Map<String, Object> properties) {
|
||||
this.enabled = enabled;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public Map<String, Object> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ModSetting{" +
|
||||
"enabled=" + enabled +
|
||||
", properties=" + properties +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ModSetting that = (ModSetting) o;
|
||||
return enabled == that.enabled &&
|
||||
Objects.equals(properties, that.properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(enabled, properties);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.client.obj;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum ServerRule {
|
||||
|
||||
/**
|
||||
* Whether or not minimap is allowed
|
||||
* Expected value: (String) NEUTRAL or FORCED_OFF
|
||||
*/
|
||||
MINIMAP_STATUS("minimapStatus", String.class),
|
||||
|
||||
/**
|
||||
* Whether or not the server will store waypoints, instead of the client
|
||||
*/
|
||||
SERVER_HANDLES_WAYPOINTS("serverHandlesWaypoints", Boolean.class),
|
||||
|
||||
/**
|
||||
* A warning message will be shown when attempting to disconnect if the current
|
||||
* game is competitive.
|
||||
*/
|
||||
COMPETITIVE_GAME("competitiveGame", Boolean.class),
|
||||
|
||||
/**
|
||||
* If this server forces shaders to be disabled
|
||||
*/
|
||||
SHADERS_DISABLED("shadersDisabled", Boolean.class),
|
||||
|
||||
/**
|
||||
* If the server runs legacy enchanting (pre 1.8)
|
||||
*/
|
||||
LEGACY_ENCHANTING("legacyEnchanting", Boolean.class),
|
||||
|
||||
/**
|
||||
* If this server has enabled voice chat
|
||||
*/
|
||||
VOICE_ENABLED("voiceEnabled", Boolean.class),
|
||||
|
||||
/**
|
||||
* Whether to revert combat mechanics to 1.7
|
||||
*/
|
||||
LEGACY_COMBAT("legacyCombat", Boolean.class);
|
||||
|
||||
@Getter private String id;
|
||||
@Getter private Class type;
|
||||
|
||||
ServerRule(String id, Class type) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static ServerRule getRule(String id) {
|
||||
for (ServerRule existing : ServerRule.values()) {
|
||||
if (existing.id.equals(id)) {
|
||||
return existing;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.server;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCPacketClientVoice;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCPacketVoiceMute;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCPacketVoiceChannelSwitch;
|
||||
|
||||
public interface LCNetHandlerServer extends LCNetHandler {
|
||||
|
||||
void handleStaffModStatus(LCPacketStaffModStatus packet);
|
||||
void handleVoice(LCPacketClientVoice packet);
|
||||
void handleVoiceMute(LCPacketVoiceMute packet);
|
||||
void handleVoiceChannelSwitch(LCPacketVoiceChannelSwitch packet);
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.server;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public final class LCPacketStaffModStatus extends LCPacket {
|
||||
|
||||
@Getter private Set<String> enabled;
|
||||
|
||||
public LCPacketStaffModStatus() {
|
||||
this.enabled = new HashSet<>();
|
||||
}
|
||||
|
||||
public LCPacketStaffModStatus(Set<String> enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeVarInt(enabled.size());
|
||||
|
||||
for (String mod : enabled) {
|
||||
buf.writeString(mod);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
int size = buf.readVarInt();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
enabled.add(buf.readString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerServer) handler).handleStaffModStatus(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.server;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCNetHandlerClient;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public final class LCPacketVoice extends LCPacket {
|
||||
/**
|
||||
* The UUID of all the senders, since we're using multiplex
|
||||
* we don't actually know the bytes per user
|
||||
*/
|
||||
@Getter private Set<UUID> uuids;
|
||||
|
||||
/**
|
||||
* The "smashed" bytes of all the voice.
|
||||
*/
|
||||
@Getter private byte[] data;
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper b) {
|
||||
b.writeVarInt(uuids.size());
|
||||
uuids.forEach(b::writeUUID);
|
||||
writeBlob(b, this.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper b) {
|
||||
uuids = new HashSet<>();
|
||||
int size = b.readVarInt();
|
||||
for (int i = 0; i < size; i++) {
|
||||
uuids.add(b.readUUID());
|
||||
}
|
||||
this.data = readBlob(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleVoice(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* For comparability, will be removed.
|
||||
* @return The 0 index of the sent players.
|
||||
*/
|
||||
@Deprecated
|
||||
public UUID getUuid() {
|
||||
return new ArrayList<>(uuids).get(0);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.server;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCNetHandlerClient;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public final class LCPacketVoiceChannel extends LCPacket {
|
||||
|
||||
@Getter private UUID uuid;
|
||||
|
||||
@Getter private String name;
|
||||
|
||||
@Getter private Map<UUID, String> players;
|
||||
|
||||
@Getter private Map<UUID, String> listening;
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper b) {
|
||||
b.writeUUID(uuid);
|
||||
b.writeString(name);
|
||||
writeMap(b, players);
|
||||
writeMap(b, listening);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper b) {
|
||||
this.uuid = b.readUUID();
|
||||
this.name = b.readString();
|
||||
this.players = readMap(b);
|
||||
this.listening = readMap(b);
|
||||
}
|
||||
|
||||
private void writeMap(ByteBufWrapper b, Map<UUID, String> players) {
|
||||
b.writeVarInt(players.size());
|
||||
for (Map.Entry<UUID, String> player : players.entrySet()) {
|
||||
b.writeUUID(player.getKey());
|
||||
b.writeString(player.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private Map<UUID, String> readMap(ByteBufWrapper b) {
|
||||
int size = b.readVarInt();
|
||||
|
||||
Map<UUID, String> players = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
UUID uuid = b.readUUID();
|
||||
String name = b.readString();
|
||||
|
||||
players.put(uuid, name);
|
||||
}
|
||||
|
||||
return players;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleVoiceChannels(this);
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.server;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCNetHandlerClient;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public final class LCPacketVoiceChannelRemove extends LCPacket {
|
||||
|
||||
@Getter private UUID uuid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper b) {
|
||||
b.writeUUID(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper b) {
|
||||
this.uuid = b.readUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleVoiceChannelDelete(this);
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.server;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCNetHandlerClient;
|
||||
import com.lunarclient.bukkitapi.nethandler.shared.LCNetHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public final class LCPacketVoiceChannelUpdate extends LCPacket {
|
||||
|
||||
/**
|
||||
* 0 for adding a player
|
||||
* 1 for removing a player
|
||||
* 2 for marking a player as listening
|
||||
* 3 for marking a player as deafened
|
||||
*/
|
||||
@Getter public int status;
|
||||
|
||||
@Getter private UUID channelUuid;
|
||||
|
||||
@Getter private UUID uuid;
|
||||
|
||||
@Getter private String name;
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper b) {
|
||||
b.writeVarInt(status);
|
||||
b.writeUUID(channelUuid);
|
||||
b.writeUUID(uuid);
|
||||
b.writeString(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper b) {
|
||||
this.status = b.readVarInt();
|
||||
this.channelUuid = b.readUUID();
|
||||
this.uuid = b.readUUID();
|
||||
this.name = b.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
((LCNetHandlerClient) handler).handleVoiceChannelUpdate(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.shared;
|
||||
|
||||
public interface LCNetHandler {
|
||||
|
||||
void handleAddWaypoint(LCPacketWaypointAdd packet);
|
||||
void handleRemoveWaypoint(LCPacketWaypointRemove packet);
|
||||
void handleEmote(LCPacketEmoteBroadcast packet);
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.shared;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class LCPacketEmoteBroadcast extends LCPacket {
|
||||
|
||||
@Getter private UUID uuid; // User doing the emote
|
||||
@Getter private int emoteId;
|
||||
|
||||
public LCPacketEmoteBroadcast() {}
|
||||
|
||||
public LCPacketEmoteBroadcast(UUID uuid, int emoteId) {
|
||||
this.uuid = uuid;
|
||||
this.emoteId = emoteId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeUUID(uuid);
|
||||
buf.buf().writeInt(emoteId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.uuid = buf.readUUID();
|
||||
this.emoteId = buf.buf().readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
handler.handleEmote(this);
|
||||
}
|
||||
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.shared;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketWaypointAdd extends LCPacket {
|
||||
|
||||
@Getter private String name;
|
||||
@Getter private String world;
|
||||
@Getter private int color;
|
||||
@Getter private int x;
|
||||
@Getter private int y;
|
||||
@Getter private int z;
|
||||
@Getter private boolean forced;
|
||||
@Getter private boolean visible;
|
||||
|
||||
public LCPacketWaypointAdd() {}
|
||||
|
||||
public LCPacketWaypointAdd(String name, String world, int color, int x, int y, int z, boolean forced, boolean visible) {
|
||||
this.name = name;
|
||||
this.world = world;
|
||||
this.color = color;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.forced = forced;
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(name);
|
||||
buf.writeString(world);
|
||||
buf.buf().writeInt(color);
|
||||
buf.buf().writeInt(x);
|
||||
buf.buf().writeInt(y);
|
||||
buf.buf().writeInt(z);
|
||||
buf.buf().writeBoolean(forced);
|
||||
buf.buf().writeBoolean(visible);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.name = buf.readString();
|
||||
this.world = buf.readString();
|
||||
this.color = buf.buf().readInt();
|
||||
this.x = buf.buf().readInt();
|
||||
this.y = buf.buf().readInt();
|
||||
this.z = buf.buf().readInt();
|
||||
this.forced = buf.buf().readBoolean();
|
||||
this.visible = buf.buf().readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
handler.handleAddWaypoint(this);
|
||||
}
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.lunarclient.bukkitapi.nethandler.shared;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.ByteBufWrapper;
|
||||
import com.lunarclient.bukkitapi.nethandler.LCPacket;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketWaypointRemove extends LCPacket {
|
||||
|
||||
@Getter private String name;
|
||||
@Getter private String world;
|
||||
|
||||
public LCPacketWaypointRemove() {}
|
||||
|
||||
public LCPacketWaypointRemove(String name, String world) {
|
||||
this.name = name;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(name);
|
||||
buf.writeString(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBufWrapper buf) throws IOException {
|
||||
this.name = buf.readString();
|
||||
this.world = buf.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(LCNetHandler handler) {
|
||||
handler.handleRemoveWaypoint(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.lunarclient.bukkitapi.object;
|
||||
|
||||
import com.lunarclient.bukkitapi.LunarClientAPI;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public final class LCWaypoint {
|
||||
|
||||
private final String name;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private final String world;
|
||||
private final int color;
|
||||
private final boolean forced;
|
||||
private final boolean visible;
|
||||
|
||||
/**
|
||||
* Create a waypoint with any visibility.
|
||||
*
|
||||
* NOTE: Just because a waypoint object is created, that doesn't mean
|
||||
* it will be sent to users. To display the waypoint you must still send
|
||||
* it to the Lunar Client user.
|
||||
*
|
||||
* @param name The name of the waypoint (this is important if you need to edit it later, save the name).
|
||||
* @param location The bukkit {@link Location} to display the waypoint at. Whole blocks only, partial blocks aren't accounted for.
|
||||
* @param color The HEX color to set as the color for the waypoint.
|
||||
* @param forced If the client should be able to remove the waypoint, or if it is forced for gameplay reasons.
|
||||
* @param visible Weather or not the waypoint should be visible. This will likely always be true.
|
||||
*/
|
||||
public LCWaypoint(String name, Location location, int color, boolean forced, boolean visible) {
|
||||
this(name, location.getBlockX(), location.getBlockY(), location.getBlockZ(), LunarClientAPI.getInstance().getWorldIdentifier(location.getWorld()), color, forced, visible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a waypoint that is automatically visible when sent.
|
||||
*
|
||||
* NOTE: Just because a waypoint object is created, that doesn't mean
|
||||
* it will be sent to users. To display the waypoint you must still send
|
||||
* it to the Lunar Client user.
|
||||
*
|
||||
* @param name The name of the waypoint (this is important if you need to edit it later, save the name).
|
||||
* @param location The bukkit {@link Location} to display the waypoint at. Whole blocks only, partial blocks aren't accounted for.
|
||||
* @param color The HEX color to set as the color for the waypoint.
|
||||
* @param forced If the client should be able to remove the waypoint, or if it is forced for gameplay reasons.
|
||||
*/
|
||||
public LCWaypoint(String name, Location location, int color, boolean forced) {
|
||||
this(name, location, color, forced, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.lunarclient.bukkitapi.object;
|
||||
|
||||
/**
|
||||
* Lunar client has hidden StaffModule that can be
|
||||
* sent to a user at any given point.
|
||||
*
|
||||
* Currently only XRAY is implemented but there are
|
||||
* future plans to expand this to possibly NAME_TAGS,
|
||||
* and there is still discussion of whether BUNNY_HOP
|
||||
* will make a return.
|
||||
*
|
||||
* NOTE: Lunar Client will NOT check if the user is
|
||||
* actually staff, if the user is given any StaffModule
|
||||
* by the server it is assumed that the server knows what
|
||||
* it is doing and will not check permissions or other.
|
||||
*/
|
||||
public enum StaffModule {
|
||||
|
||||
XRAY,
|
||||
@Deprecated
|
||||
NAME_TAGS,
|
||||
@Deprecated
|
||||
BUNNY_HOP
|
||||
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.lunarclient.bukkitapi.serverrule;
|
||||
|
||||
import com.lunarclient.bukkitapi.LunarClientAPI;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCPacketServerRule;
|
||||
import com.lunarclient.bukkitapi.nethandler.client.obj.ServerRule;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class LunarClientAPIServerRule {
|
||||
|
||||
// The reason this is a Map is so that hopefully we will only have 1 server rule packet
|
||||
// per ServerRule. It would be extremely weird behavior if multiple with the same type were sent.
|
||||
private final Map<ServerRule, LCPacketServerRule> CUSTOM_SERVER_RULES = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Set a server rule to a boolean value.
|
||||
* All current server rules (02/02/2021)
|
||||
* use a boolean value.
|
||||
*
|
||||
* @param rule The ServerRule with type of boolean.
|
||||
* @param value The value of the ServerRule.
|
||||
*/
|
||||
public void setRule(ServerRule rule, Boolean value) {
|
||||
CUSTOM_SERVER_RULES.put(rule, new LCPacketServerRule(rule, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send all set server rules to player(s).
|
||||
* This will likely work best to be sent on join.
|
||||
*
|
||||
* If a server rule is updated, the players will need to be updated.
|
||||
* This is not an automatic process. The ideal usage would be to set
|
||||
* all server rules when the plugin loads, then when each player joins
|
||||
* send them all server rules.
|
||||
*
|
||||
* @param players The player(s) to get all the previously set server rules.
|
||||
*/
|
||||
public void sendServerRule(Player... players) {
|
||||
if (CUSTOM_SERVER_RULES.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (Player player : players) {
|
||||
for (LCPacketServerRule value : CUSTOM_SERVER_RULES.values()) {
|
||||
LunarClientAPI.getInstance().sendPacket(player, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.lunarclient.bukkitapi.title;
|
||||
|
||||
import com.lunarclient.bukkitapi.nethandler.client.LCPacketTitle;
|
||||
import com.lunarclient.bukkitapi.LunarClientAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public final class LCTitleBuilder {
|
||||
|
||||
/**
|
||||
* Create a LCTitle by type and message.
|
||||
* The message is final, but the type can be changed
|
||||
* until the packet is built.
|
||||
*
|
||||
* @param message The message that will be displayed.
|
||||
* @param type The {@link TitleType} to send to the client
|
||||
* @return A new title builder.
|
||||
*/
|
||||
public static LCTitleBuilder of(String message, TitleType type) {
|
||||
return new LCTitleBuilder(message, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a LCTitle with a message.
|
||||
* The type defaults to a title.
|
||||
*
|
||||
* @param message The message to display to the user.
|
||||
* @return The new title builder.
|
||||
*/
|
||||
public static LCTitleBuilder of(String message) {
|
||||
return of(message, TitleType.TITLE);
|
||||
}
|
||||
|
||||
private final String message;
|
||||
private TitleType type;
|
||||
private float scale;
|
||||
private Duration displayDuration;
|
||||
private Duration fadeInDuration;
|
||||
private Duration fadeOutDuration;
|
||||
|
||||
/**
|
||||
* Starts a new builder with default params.
|
||||
* If nothing else is specified then it will
|
||||
* default to a title with your message that lasts
|
||||
* 1.5 seconds and fades in and out for .5 seconds.
|
||||
*
|
||||
* @param message The final message specified to start the builder.
|
||||
* @param type The type to start the builder.
|
||||
*/
|
||||
private LCTitleBuilder(String message, TitleType type) {
|
||||
this.message = message;
|
||||
this.type = type;
|
||||
this.scale = 1;
|
||||
this.displayDuration = Duration.ofMillis(1500);
|
||||
this.fadeInDuration = Duration.ofMillis(500);
|
||||
this.fadeOutDuration = Duration.ofMillis(500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the {@link TitleType} for the title to be displayed.
|
||||
* @param type The type of type to display.
|
||||
* @return This builder with the updated value.
|
||||
*/
|
||||
public LCTitleBuilder type(TitleType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale up or down the title sent to the client.
|
||||
*
|
||||
* @param scale The new scale (greater than 0) that the message will be displayed on.
|
||||
* @return This builder with the updated value.
|
||||
*/
|
||||
public LCTitleBuilder scale(float scale) {
|
||||
this.scale = scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the display time for which this
|
||||
* title will be displayed to the user.
|
||||
*
|
||||
* The title will display for fade in + DISPLAY TIME + fade out = total display time.
|
||||
*
|
||||
* @param duration The {@link Duration} of how long to display the title for.
|
||||
* @return This builder with the updated value.
|
||||
*/
|
||||
public LCTitleBuilder displayFor(Duration duration) {
|
||||
this.displayDuration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the amount of time it takes
|
||||
* the title to fade in for the user.
|
||||
*
|
||||
* The title will display for FADE IN + duration + fade out = total display time.
|
||||
*
|
||||
* @param duration The {@link Duration} of how long to fade in the title for.
|
||||
* @return This builder with the updated value.
|
||||
*/
|
||||
public LCTitleBuilder fadeInFor(Duration duration) {
|
||||
this.fadeInDuration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the amount of time it takes
|
||||
* the title to fade out for the user.
|
||||
*
|
||||
* The title will display for fade in + duration + FADE OUT = total display time.
|
||||
*
|
||||
* @param duration The {@link Duration} of how long to fade in the title for.
|
||||
* @return This builder with the updated value.
|
||||
*/
|
||||
public LCTitleBuilder fadeOutFor(Duration duration) {
|
||||
this.fadeOutDuration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Take all the inputs from the builder and convert
|
||||
* it into a single LCPacketTitle you can use to
|
||||
* save and send to players as needed.
|
||||
*
|
||||
* Ideally if possible you would build the title packet once
|
||||
* and then send it to all the players that can see it.
|
||||
* A good example of this would be a welcome title, where
|
||||
* its entirely static but needs to be sent to all users.
|
||||
*
|
||||
* @return The {@link LCPacketTitle} to send to Lunar Client users as needed.
|
||||
*/
|
||||
public LCPacketTitle build() {
|
||||
return new LCPacketTitle(type.name().toLowerCase(), message, scale, displayDuration.toMillis(), fadeInDuration.toMillis(), fadeOutDuration.toMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the current packet and sends it to all players required.
|
||||
*
|
||||
* A good use case for this would be if all players online need
|
||||
* to see the same message, at the same time and it won't be sent again.
|
||||
* Like an announcement for an objective in a mini-game.
|
||||
*
|
||||
* @param players All the {@link Player} that need to see the title.
|
||||
* @return The {@link LCPacketTitle} generated that can be used later if needed.
|
||||
*/
|
||||
public LCPacketTitle sendAndBuild(Player... players) {
|
||||
LCPacketTitle title = build();
|
||||
for (Player player : players) {
|
||||
LunarClientAPI.getInstance().sendPacket(player, title);
|
||||
}
|
||||
return title;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.lunarclient.bukkitapi.title;
|
||||
|
||||
public enum TitleType {
|
||||
TITLE,
|
||||
SUBTITLE,
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
name: CrankedLunarAPI
|
||||
version: ${git.commit.id.abbrev}
|
||||
description: A server interface for the Lunar Client
|
||||
author: Moonsworth LLC Development Team
|
||||
main: com.lunarclient.bukkitapi.LunarClientAPI
|
||||
load: STARTUP
|
||||
website: https://www.lunarclient.com/
|
||||
Reference in New Issue
Block a user