Add /ld logs, fix horse disguise riding not moving
This commit is contained in:
parent
0cd7806d21
commit
ac2d3d8325
@ -1,6 +1,7 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.disguisetypes.*;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.AbstractHorseWatcher;
|
||||
@ -31,6 +32,8 @@ import java.util.Map;
|
||||
|
||||
public class DisguiseAPI {
|
||||
private static int selfDisguiseId = ReflectionManager.getNewEntityId(true);
|
||||
@Getter
|
||||
private static int entityAttachmentId = ReflectionManager.getNewEntityId(true);
|
||||
|
||||
public static void addCustomDisguise(String disguiseName, String disguiseInfo) throws DisguiseParseException {
|
||||
// Dirty fix for anyone that somehow got this far with a . in the name, invalid yaml!
|
||||
@ -58,8 +61,7 @@ public class DisguiseAPI {
|
||||
configuration.save(disguisesFile);
|
||||
|
||||
DisguiseUtilities.getLogger().info("Added new Custom Disguise " + disguiseName);
|
||||
}
|
||||
catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -71,8 +73,9 @@ public class DisguiseAPI {
|
||||
public static String getRawCustomDisguise(String disguiseName) {
|
||||
Map.Entry<DisguisePerm, String> entry = DisguiseConfig.getRawCustomDisguise(disguiseName);
|
||||
|
||||
if (entry == null)
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return entry.getValue();
|
||||
}
|
||||
@ -193,8 +196,7 @@ public class DisguiseAPI {
|
||||
}
|
||||
}
|
||||
watcherMethod.invoke(watcher, value);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -228,8 +230,9 @@ public class DisguiseAPI {
|
||||
}
|
||||
|
||||
// They prefer to have the opposite of whatever the view disguises option is
|
||||
if (hasSelfDisguisePreference(entity) && disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises())
|
||||
if (hasSelfDisguisePreference(entity) && disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) {
|
||||
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
|
||||
}
|
||||
|
||||
if (hasActionBarPreference(entity) && !isActionBarShown(entity)) {
|
||||
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
|
||||
|
@ -65,8 +65,9 @@ public class LDUploadLogs implements LDCommand {
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
for (SimpleEntry<String, String> entry : params) {
|
||||
if (output.length() > 0)
|
||||
if (output.length() > 0) {
|
||||
output.append('&');
|
||||
}
|
||||
|
||||
output.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
|
||||
output.append('=');
|
||||
@ -100,7 +101,7 @@ public class LDUploadLogs implements LDCommand {
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Arrays.asList("uploadlog", "uploadlogs", "uploadconfig", "uploadconfigs");
|
||||
return Arrays.asList("uploadlog", "uploadlogs", "uploadconfig", "uploadconfigs", "logs");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -181,8 +182,8 @@ public class LDUploadLogs implements LDCommand {
|
||||
|
||||
configText.append("\n================\n");
|
||||
|
||||
ArrayList<String> modified = DisguiseConfig
|
||||
.doOutput(LibsDisguises.getInstance().getConfig(), true, true);
|
||||
ArrayList<String> modified =
|
||||
DisguiseConfig.doOutput(LibsDisguises.getInstance().getConfig(), true, true);
|
||||
|
||||
for (String s : modified) {
|
||||
configText.append("\n").append(s);
|
||||
@ -218,15 +219,13 @@ public class LDUploadLogs implements LDCommand {
|
||||
sender.spigot().sendMessage(builder.create());
|
||||
}
|
||||
}.runTask(LibsDisguises.getInstance());
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sender.sendMessage(ChatColor.RED + "Unexpected error! Upload failed! " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(LibsDisguises.getInstance());
|
||||
}
|
||||
catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
@ -62,10 +62,8 @@ import org.bukkit.util.Vector;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.CopyOption;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
@ -260,6 +258,71 @@ public class DisguiseUtilities {
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeInvisibleSlime(Player player) {
|
||||
PacketContainer container = new PacketContainer(Server.ENTITY_DESTROY);
|
||||
container.getIntegerArrays().write(0, new int[]{DisguiseAPI.getEntityAttachmentId()});
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, container, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendInvisibleSlime(Player player, int horseId) {
|
||||
PacketContainer packet =
|
||||
ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.SPAWN_ENTITY_LIVING, player)
|
||||
.createPacket(player);
|
||||
|
||||
packet.getModifier().write(0, DisguiseAPI.getEntityAttachmentId());
|
||||
packet.getModifier().write(1, UUID.randomUUID());
|
||||
packet.getModifier().write(2, DisguiseType.SLIME.getTypeId());
|
||||
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
|
||||
WrappedDataWatcher.WrappedDataWatcherObject obj =
|
||||
ReflectionManager.createDataWatcherObject(MetaIndex.SLIME_SIZE, 0);
|
||||
|
||||
watcher.setObject(obj, 0);
|
||||
|
||||
if (NmsVersion.v1_15.isSupported()) {
|
||||
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
|
||||
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA,
|
||||
DisguiseAPI.getEntityAttachmentId(), watcher, true)
|
||||
.createPacket(DisguiseAPI.getEntityAttachmentId(), watcher, true);
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, metaPacket, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
packet.getDataWatcherModifier().write(0, watcher);
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
PacketContainer attachHorse = new PacketContainer(Server.MOUNT);
|
||||
attachHorse.getModifier().write(0, horseId);
|
||||
attachHorse.getModifier().write(1, new int[]{DisguiseAPI.getEntityAttachmentId()});
|
||||
|
||||
PacketContainer attachPlayer = new PacketContainer(Server.MOUNT);
|
||||
attachPlayer.getModifier().write(0, DisguiseAPI.getEntityAttachmentId());
|
||||
attachPlayer.getModifier().write(1, new int[]{player.getEntityId()});
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, attachHorse, false);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, attachPlayer, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadViewPreferences() {
|
||||
File viewPreferences = new File(LibsDisguises.getInstance().getDataFolder(), "preferences.json");
|
||||
|
||||
@ -1152,8 +1215,8 @@ public class DisguiseUtilities {
|
||||
|
||||
cachedNames.addAll(Arrays.asList(profileCache.list()));
|
||||
|
||||
invalidFile =
|
||||
LibsDisguises.getInstance().getFile().getName().toLowerCase(Locale.ENGLISH).matches(".*((crack)|(null)|(leak)).*");
|
||||
invalidFile = LibsDisguises.getInstance().getFile().getName().toLowerCase(Locale.ENGLISH)
|
||||
.matches(".*((crack)|(null)|(leak)).*");
|
||||
|
||||
for (String key : savedDisguises.list()) {
|
||||
try {
|
||||
|
@ -31,6 +31,7 @@ public class PacketsHandler {
|
||||
packetHandlers.add(new PacketHandlerCollect());
|
||||
packetHandlers.add(new PacketHandlerEntityStatus());
|
||||
packetHandlers.add(new PacketHandlerEquipment(this));
|
||||
packetHandlers.add(new PacketHandlerAttachEntity());
|
||||
|
||||
packetHandlers.add(new PacketHandlerHeadRotation());
|
||||
|
||||
@ -72,8 +73,7 @@ public class PacketsHandler {
|
||||
}
|
||||
|
||||
packets.setUnhandled();
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -146,6 +146,7 @@ public class PacketsManager {
|
||||
packetsToListen.add(Server.ENTITY_TELEPORT);
|
||||
packetsToListen.add(Server.REL_ENTITY_MOVE);
|
||||
packetsToListen.add(Server.ENTITY_VELOCITY);
|
||||
packetsToListen.add(Server.MOUNT);
|
||||
}
|
||||
|
||||
// Add equipment packet
|
||||
|
@ -0,0 +1,43 @@
|
||||
package me.libraryaddict.disguise.utilities.packets.packethandlers;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
|
||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 19/09/2020.
|
||||
*/
|
||||
public class PacketHandlerAttachEntity implements IPacketHandler {
|
||||
@Override
|
||||
public PacketType[] getHandledPackets() {
|
||||
return new PacketType[]{PacketType.Play.Server.MOUNT};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
|
||||
Entity entity) {
|
||||
if (observer.getVehicle() == null) {
|
||||
DisguiseUtilities.removeInvisibleSlime(observer);
|
||||
return;
|
||||
}
|
||||
|
||||
if (observer.getVehicle() != entity ||
|
||||
!AbstractHorse.class.isAssignableFrom(disguise.getType().getEntityClass())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int[] ints = sentPacket.getIntegerArrays().read(0);
|
||||
|
||||
if (ints.length > 0 && ints[0] == observer.getEntityId()) {
|
||||
packets.clear();
|
||||
|
||||
DisguiseUtilities.sendInvisibleSlime(observer, entity.getEntityId());
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package me.libraryaddict.disguise.utilities.packets.packethandlers;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
@ -13,6 +14,8 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 3/01/2019.
|
||||
*/
|
||||
@ -27,9 +30,15 @@ public class PacketHandlerHeadRotation implements IPacketHandler {
|
||||
Entity entity) {
|
||||
Float pitchLock = disguise.getWatcher().getPitchLock();
|
||||
Float yawLock = disguise.getWatcher().getYawLock();
|
||||
boolean riding = observer.getVehicle() == entity;
|
||||
|
||||
if (pitchLock == null && yawLock == null &&
|
||||
(!disguise.getType().isPlayer() || entity.getType() == EntityType.PLAYER)) {
|
||||
if (riding) {
|
||||
sentPacket = sentPacket.shallowClone();
|
||||
sentPacket.getModifier().write(0, DisguiseAPI.getEntityAttachmentId());
|
||||
packets.addPacket(sentPacket);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -122,5 +131,13 @@ public class PacketHandlerHeadRotation implements IPacketHandler {
|
||||
|
||||
packets.addPacket(look);
|
||||
packets.addPacket(rotation);
|
||||
|
||||
if (riding) {
|
||||
for (PacketContainer c : new ArrayList<>(packets.getPackets())) {
|
||||
c = c.shallowClone();
|
||||
c.getModifier().write(0, DisguiseAPI.getEntityAttachmentId());
|
||||
packets.addPacket(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package me.libraryaddict.disguise.utilities.packets.packethandlers;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
@ -13,6 +14,7 @@ import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
|
||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import org.apache.commons.lang.math.RandomUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
@ -189,7 +191,12 @@ public class PacketHandlerMovement implements IPacketHandler {
|
||||
bytes.write(0, yawValue);
|
||||
bytes.write(1, pitchValue);
|
||||
|
||||
if (sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT &&
|
||||
if (entity == observer.getVehicle() &&
|
||||
AbstractHorse.class.isAssignableFrom(disguise.getType().getEntityClass())) {
|
||||
PacketContainer packet = movePacket.shallowClone();
|
||||
packet.getModifier().write(0, DisguiseAPI.getEntityAttachmentId());
|
||||
packets.addPacket(packet);
|
||||
} else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT &&
|
||||
disguise.getType() == DisguiseType.ITEM_FRAME) {
|
||||
StructureModifier<Double> doubles = movePacket.getDoubles();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user