Fix sleeping disguises
This commit is contained in:
parent
291942b9b4
commit
6e77551f2e
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>LibsDisguises</groupId>
|
||||
<artifactId>LibsDisguises</artifactId>
|
||||
<version>9.0.7</version>
|
||||
<version>9.0.7-SNAPSHOT</version>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
|
@ -53,9 +53,11 @@ public class DisguiseListener implements Listener
|
||||
public DisguiseListener(LibsDisguises libsDisguises)
|
||||
{
|
||||
plugin = libsDisguises;
|
||||
|
||||
if (plugin.getConfig().getBoolean("NotifyUpdate"))
|
||||
{
|
||||
currentVersion = plugin.getDescription().getVersion();
|
||||
|
||||
updaterTask = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
@ -65,10 +67,16 @@ public class DisguiseListener implements Listener
|
||||
{
|
||||
UpdateChecker updateChecker = new UpdateChecker();
|
||||
updateChecker.checkUpdate("v" + currentVersion);
|
||||
|
||||
latestVersion = updateChecker.getLatestVersion();
|
||||
if (latestVersion != null)
|
||||
|
||||
if (latestVersion == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
latestVersion = "v" + latestVersion;
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
@ -76,16 +84,17 @@ public class DisguiseListener implements Listener
|
||||
{
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (p.hasPermission(DisguiseConfig.getUpdateNotificationPermission()))
|
||||
if (!p.hasPermission(DisguiseConfig.getUpdateNotificationPermission()))
|
||||
{
|
||||
p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion,
|
||||
latestVersion));
|
||||
continue;
|
||||
}
|
||||
|
||||
p.sendMessage(
|
||||
String.format(DisguiseConfig.getUpdateMessage(), currentVersion, latestVersion));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.print(String.format("[LibsDisguises] Failed to check for update: %s", ex.getMessage()));
|
||||
@ -102,10 +111,12 @@ public class DisguiseListener implements Listener
|
||||
{
|
||||
r.cancel();
|
||||
}
|
||||
|
||||
for (Disguise d : disguiseEntity.values())
|
||||
{
|
||||
d.removeDisguise();
|
||||
}
|
||||
|
||||
disguiseClone.clear();
|
||||
updaterTask.cancel();
|
||||
}
|
||||
@ -113,9 +124,11 @@ public class DisguiseListener implements Listener
|
||||
private void checkPlayerCanBlowDisguise(Player entity)
|
||||
{
|
||||
Disguise[] disguises = DisguiseAPI.getDisguises(entity);
|
||||
|
||||
if (disguises.length > 0)
|
||||
{
|
||||
DisguiseAPI.undisguiseToAll(entity);
|
||||
|
||||
if (DisguiseConfig.getDisguiseBlownMessage().length() > 0)
|
||||
{
|
||||
entity.sendMessage(DisguiseConfig.getDisguiseBlownMessage());
|
||||
@ -127,6 +140,7 @@ public class DisguiseListener implements Listener
|
||||
{
|
||||
try
|
||||
{
|
||||
// Resend the bed chunks
|
||||
for (PacketContainer packet : DisguiseUtilities.getBedChunkPacket(newLoc, oldLoc))
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
@ -138,11 +152,19 @@ public class DisguiseListener implements Listener
|
||||
{
|
||||
for (TargetedDisguise disguise : list)
|
||||
{
|
||||
if (disguise.isPlayerDisguise() && disguise.canSee(player)
|
||||
&& ((PlayerDisguise) disguise).getWatcher().isSleeping()
|
||||
&& DisguiseUtilities.getPerverts(disguise).contains(player))
|
||||
{
|
||||
PacketContainer[] packets = DisguiseUtilities.getBedPackets(player,
|
||||
if (!disguise.isPlayerDisguise())
|
||||
continue;
|
||||
|
||||
if (!disguise.canSee(player))
|
||||
continue;
|
||||
|
||||
if (!((PlayerDisguise) disguise).getWatcher().isSleeping())
|
||||
continue;
|
||||
|
||||
if (!DisguiseUtilities.getPerverts(disguise).contains(player))
|
||||
continue;
|
||||
|
||||
PacketContainer[] packets = DisguiseUtilities.getBedPackets(
|
||||
disguise.getEntity() == player ? newLoc : disguise.getEntity().getLocation(), newLoc,
|
||||
(PlayerDisguise) disguise);
|
||||
|
||||
@ -162,7 +184,6 @@ public class DisguiseListener implements Listener
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace(System.out);
|
||||
@ -190,10 +211,12 @@ public class DisguiseListener implements Listener
|
||||
public void onJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player p = event.getPlayer();
|
||||
|
||||
if (latestVersion != null && p.hasPermission(DisguiseConfig.getUpdateNotificationPermission()))
|
||||
{
|
||||
p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion, latestVersion));
|
||||
}
|
||||
|
||||
if (DisguiseConfig.isBedPacketsEnabled())
|
||||
{
|
||||
chunkMove(p, p.getLocation(), null);
|
||||
@ -210,11 +233,9 @@ public class DisguiseListener implements Listener
|
||||
{
|
||||
Location to = event.getTo();
|
||||
Location from = event.getFrom();
|
||||
int x1 = (int) Math.floor(to.getX() / 16D) - 17;
|
||||
int x2 = (int) Math.floor(from.getX() / 16D) - 17;
|
||||
int z1 = (int) Math.floor(to.getZ() / 16D) - 17;
|
||||
int z2 = (int) Math.floor(from.getZ() / 16D) - 17;
|
||||
if (x1 - (x1 % 8) != x2 - (x2 % 8) || z1 - (z1 % 8) != z2 - (z2 % 8))
|
||||
|
||||
if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities.getChunkCord(from.getBlockX())
|
||||
|| DisguiseUtilities.getChunkCord(to.getBlockZ()) != DisguiseUtilities.getChunkCord(from.getBlockZ()))
|
||||
{
|
||||
chunkMove(event.getPlayer(), to, from);
|
||||
}
|
||||
@ -223,14 +244,17 @@ public class DisguiseListener implements Listener
|
||||
if (DisguiseConfig.isStopShulkerDisguisesFromMoving())
|
||||
{
|
||||
Disguise disguise;
|
||||
|
||||
if ((disguise = DisguiseAPI.getDisguise(event.getPlayer())) != null)
|
||||
{
|
||||
if (disguise.getType() == DisguiseType.SHULKER)
|
||||
{ // Stop Shulker disguises from moving their coordinates
|
||||
Location from = event.getFrom();
|
||||
Location to = event.getTo();
|
||||
|
||||
to.setX(from.getX());
|
||||
to.setZ(from.getZ());
|
||||
|
||||
event.setTo(to);
|
||||
}
|
||||
}
|
||||
@ -247,6 +271,7 @@ public class DisguiseListener implements Listener
|
||||
public void onRespawn(PlayerRespawnEvent event)
|
||||
{
|
||||
Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer());
|
||||
|
||||
for (Disguise disguise : disguises)
|
||||
{
|
||||
if (disguise.isRemoveDisguiseOnDeath())
|
||||
@ -254,6 +279,22 @@ public class DisguiseListener implements Listener
|
||||
disguise.removeDisguise();
|
||||
}
|
||||
}
|
||||
|
||||
if (DisguiseConfig.isBedPacketsEnabled())
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
chunkMove(event.getPlayer(), null, player.getLocation());
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
chunkMove(player, player.getLocation(), null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -262,10 +303,13 @@ public class DisguiseListener implements Listener
|
||||
if (disguiseEntity.containsKey(event.getPlayer().getName()) || disguiseClone.containsKey(event.getPlayer().getName()))
|
||||
{
|
||||
Player p = event.getPlayer();
|
||||
|
||||
event.setCancelled(true);
|
||||
disguiseRunnable.remove(p.getName()).cancel();
|
||||
|
||||
Entity entity = event.getRightClicked();
|
||||
String entityName;
|
||||
|
||||
if (entity instanceof Player && !disguiseClone.containsKey(p.getName()))
|
||||
{
|
||||
entityName = entity.getName();
|
||||
@ -274,10 +318,13 @@ public class DisguiseListener implements Listener
|
||||
{
|
||||
entityName = DisguiseType.getType(entity).toReadable();
|
||||
}
|
||||
|
||||
if (disguiseClone.containsKey(p.getName()))
|
||||
{
|
||||
Boolean[] options = disguiseClone.remove(p.getName());
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise(p, entity);
|
||||
|
||||
if (disguise == null)
|
||||
{
|
||||
disguise = DisguiseAPI.constructDisguise(entity, options[0], options[1], options[2]);
|
||||
@ -286,22 +333,28 @@ public class DisguiseListener implements Listener
|
||||
{
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
|
||||
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
|
||||
|
||||
String reference = null;
|
||||
int referenceLength = Math.max(2, (int) Math.ceil((0.1D + DisguiseConfig.getMaxClonedDisguises()) / 26D));
|
||||
int attempts = 0;
|
||||
|
||||
while (reference == null && attempts++ < 1000)
|
||||
{
|
||||
reference = "@";
|
||||
|
||||
for (int i = 0; i < referenceLength; i++)
|
||||
{
|
||||
reference += alphabet[DisguiseUtilities.random.nextInt(alphabet.length)];
|
||||
}
|
||||
|
||||
if (DisguiseUtilities.getClonedDisguise(reference) != null)
|
||||
{
|
||||
reference = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (reference != null && DisguiseUtilities.addClonedDisguise(reference, disguise))
|
||||
{
|
||||
p.sendMessage(ChatColor.RED + "Constructed a " + entityName + " disguise! Your reference is " + reference);
|
||||
@ -316,6 +369,7 @@ public class DisguiseListener implements Listener
|
||||
else if (disguiseEntity.containsKey(p.getName()))
|
||||
{
|
||||
Disguise disguise = disguiseEntity.remove(p.getName());
|
||||
|
||||
if (disguise != null)
|
||||
{
|
||||
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()
|
||||
@ -331,14 +385,18 @@ public class DisguiseListener implements Listener
|
||||
if (disguise.getWatcher() instanceof LivingWatcher)
|
||||
{
|
||||
disguise.getWatcher().setCustomName(((Player) entity).getDisplayName());
|
||||
|
||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible())
|
||||
{
|
||||
disguise.getWatcher().setCustomNameVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DisguiseAPI.disguiseToAll(entity, disguise);
|
||||
|
||||
String disguiseName = "a ";
|
||||
|
||||
if (disguise instanceof PlayerDisguise)
|
||||
{
|
||||
disguiseName = "the player " + ((PlayerDisguise) disguise).getName();
|
||||
@ -347,6 +405,7 @@ public class DisguiseListener implements Listener
|
||||
{
|
||||
disguiseName += disguise.getType().toReadable();
|
||||
}
|
||||
|
||||
if (disguise.isDisguiseInUse())
|
||||
{
|
||||
p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName
|
||||
@ -364,6 +423,7 @@ public class DisguiseListener implements Listener
|
||||
if (DisguiseAPI.isDisguised(entity))
|
||||
{
|
||||
DisguiseAPI.undisguiseToAll(entity);
|
||||
|
||||
p.sendMessage(ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName);
|
||||
}
|
||||
else
|
||||
@ -396,40 +456,35 @@ public class DisguiseListener implements Listener
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onTeleport(final PlayerTeleportEvent event)
|
||||
public void onTeleport(PlayerTeleportEvent event)
|
||||
{
|
||||
if (!DisguiseAPI.isDisguised(event.getPlayer()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
final Player player = event.getPlayer();
|
||||
Location to = event.getTo();
|
||||
Location from = event.getFrom();
|
||||
|
||||
if (DisguiseConfig.isBedPacketsEnabled())
|
||||
{
|
||||
int x1 = (int) Math.floor(to.getX() / 16D) - 17;
|
||||
int x2 = (int) Math.floor(from.getX() / 16D) - 17;
|
||||
int z1 = (int) Math.floor(to.getZ() / 16D) - 17;
|
||||
int z2 = (int) Math.floor(from.getZ() / 16D) - 17;
|
||||
if (x1 - (x1 % 8) != x2 - (x2 % 8) || z1 - (z1 % 8) != z2 - (z2 % 8))
|
||||
if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities.getChunkCord(from.getBlockX())
|
||||
|| DisguiseUtilities.getChunkCord(to.getBlockZ()) != DisguiseUtilities.getChunkCord(from.getBlockZ()))
|
||||
{
|
||||
chunkMove(event.getPlayer(), null, from);
|
||||
chunkMove(player, null, from);
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!event.isCancelled())
|
||||
{
|
||||
chunkMove(event.getPlayer(), event.getTo(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
chunkMove(event.getPlayer(), event.getPlayer().getLocation(), null);
|
||||
}
|
||||
chunkMove(player, player.getLocation(), null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!DisguiseAPI.isDisguised(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (DisguiseConfig.isUndisguiseOnWorldChange() && to.getWorld() != null && from.getWorld() != null
|
||||
&& to.getWorld() != from.getWorld())
|
||||
{
|
||||
@ -446,6 +501,7 @@ public class DisguiseListener implements Listener
|
||||
if (event.getEntered() instanceof Player && DisguiseAPI.isDisguised((Player) event.getEntered(), event.getEntered()))
|
||||
{
|
||||
DisguiseUtilities.removeSelfDisguise((Player) event.getEntered());
|
||||
|
||||
((Player) event.getEntered()).updateInventory();
|
||||
}
|
||||
}
|
||||
@ -456,6 +512,7 @@ public class DisguiseListener implements Listener
|
||||
if (event.getExited() instanceof Player)
|
||||
{
|
||||
final Disguise disguise = DisguiseAPI.getDisguise((Player) event.getExited(), event.getExited());
|
||||
|
||||
if (disguise != null)
|
||||
{
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable()
|
||||
@ -464,6 +521,7 @@ public class DisguiseListener implements Listener
|
||||
public void run()
|
||||
{
|
||||
DisguiseUtilities.setupFakeDisguise(disguise);
|
||||
|
||||
((Player) disguise.getEntity()).updateInventory();
|
||||
}
|
||||
});
|
||||
@ -474,14 +532,16 @@ public class DisguiseListener implements Listener
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onWorldSwitch(final PlayerChangedWorldEvent event)
|
||||
{
|
||||
if (!DisguiseAPI.isDisguised(event.getPlayer()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (DisguiseConfig.isBedPacketsEnabled())
|
||||
{
|
||||
chunkMove(event.getPlayer(), event.getPlayer().getLocation(), null);
|
||||
}
|
||||
|
||||
if (!DisguiseAPI.isDisguised(event.getPlayer()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (DisguiseConfig.isUndisguiseOnWorldChange())
|
||||
{
|
||||
for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer()))
|
||||
@ -493,10 +553,13 @@ public class DisguiseListener implements Listener
|
||||
{
|
||||
// Stupid hack to fix worldswitch invisibility bug
|
||||
final boolean viewSelfToggled = DisguiseAPI.isViewSelfToggled(event.getPlayer());
|
||||
|
||||
if (viewSelfToggled)
|
||||
{
|
||||
final Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer());
|
||||
|
||||
disguise.setViewSelfDisguise(false);
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
@ -517,6 +580,7 @@ public class DisguiseListener implements Listener
|
||||
run.cancel();
|
||||
run.run();
|
||||
}
|
||||
|
||||
BukkitRunnable runnable = new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
@ -526,7 +590,9 @@ public class DisguiseListener implements Listener
|
||||
disguiseRunnable.remove(player);
|
||||
}
|
||||
};
|
||||
|
||||
runnable.runTaskLater(plugin, 20 * DisguiseConfig.getDisguiseCloneExpire());
|
||||
|
||||
disguiseRunnable.put(player, runnable);
|
||||
disguiseClone.put(player, options);
|
||||
}
|
||||
@ -539,6 +605,7 @@ public class DisguiseListener implements Listener
|
||||
run.cancel();
|
||||
run.run();
|
||||
}
|
||||
|
||||
BukkitRunnable runnable = new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
@ -548,7 +615,9 @@ public class DisguiseListener implements Listener
|
||||
disguiseRunnable.remove(player);
|
||||
}
|
||||
};
|
||||
|
||||
runnable.runTaskLater(plugin, 20 * DisguiseConfig.getDisguiseEntityExpire());
|
||||
|
||||
disguiseRunnable.put(player, runnable);
|
||||
disguiseEntity.put(player, disguise);
|
||||
}
|
||||
|
@ -197,9 +197,9 @@ public class PlayerWatcher extends LivingWatcher
|
||||
{
|
||||
this.sleepingDirection = BlockFace.values()[sleepingDirection.ordinal() % 4];
|
||||
}
|
||||
if (sleeping != isSleeping())
|
||||
{
|
||||
|
||||
isInBed = sleeping;
|
||||
|
||||
if (DisguiseConfig.isBedPacketsEnabled() && DisguiseUtilities.isDisguiseInUse(getDisguise()))
|
||||
{
|
||||
try
|
||||
@ -208,15 +208,17 @@ public class PlayerWatcher extends LivingWatcher
|
||||
{
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise()))
|
||||
{
|
||||
PacketContainer[] packets = DisguiseUtilities.getBedPackets(player,
|
||||
this.getDisguise().getEntity().getLocation(), player.getLocation(),
|
||||
(PlayerDisguise) this.getDisguise());
|
||||
PacketContainer[] packets = DisguiseUtilities.getBedPackets(getDisguise().getEntity().getLocation(),
|
||||
player.getLocation(), (PlayerDisguise) getDisguise());
|
||||
|
||||
if (getDisguise().getEntity() == player)
|
||||
{
|
||||
for (PacketContainer packet : packets)
|
||||
{
|
||||
packet = packet.shallowClone();
|
||||
|
||||
packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
}
|
||||
@ -232,13 +234,15 @@ public class PlayerWatcher extends LivingWatcher
|
||||
else
|
||||
{
|
||||
PacketContainer packet = new PacketContainer(Server.ANIMATION);
|
||||
|
||||
StructureModifier<Integer> mods = packet.getIntegers();
|
||||
|
||||
mods.write(0, getDisguise().getEntity().getEntityId());
|
||||
mods.write(1, 3);
|
||||
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise()))
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -248,7 +252,6 @@ public class PlayerWatcher extends LivingWatcher
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setSkinFlags(int i, boolean flag)
|
||||
{
|
||||
|
@ -36,10 +36,12 @@ import org.bukkit.scoreboard.Team.OptionStatus;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
|
||||
@ -63,7 +65,6 @@ public class DisguiseUtilities
|
||||
* the plugin to do that.
|
||||
*/
|
||||
private static HashSet<String> addedByPlugins = new HashSet<>();
|
||||
private static Object bedChunk;
|
||||
private static LinkedHashMap<String, Disguise> clonedDisguises = new LinkedHashMap<>();
|
||||
/**
|
||||
* A hashmap of the uuid's of entitys, alive and dead. And their disguises in use
|
||||
@ -81,8 +82,8 @@ public class DisguiseUtilities
|
||||
private static LibsDisguises libsDisguises;
|
||||
private static HashMap<String, ArrayList<Object>> runnables = new HashMap<>();
|
||||
private static HashSet<UUID> selfDisguised = new HashSet<>();
|
||||
private static Field xChunk, zChunk;
|
||||
private static Thread mainThread;
|
||||
private static PacketContainer spawnChunk;
|
||||
|
||||
static
|
||||
{
|
||||
@ -91,7 +92,7 @@ public class DisguiseUtilities
|
||||
Object server = ReflectionManager.getNmsMethod("MinecraftServer", "getServer").invoke(null);
|
||||
Object world = ((List) server.getClass().getField("worlds").get(server)).get(0);
|
||||
|
||||
bedChunk = ReflectionManager.getNmsClass("Chunk")
|
||||
Object bedChunk = ReflectionManager.getNmsClass("Chunk")
|
||||
.getConstructor(ReflectionManager.getNmsClass("World"), int.class, int.class).newInstance(world, 0, 0);
|
||||
|
||||
Field cSection = bedChunk.getClass().getDeclaredField("sections");
|
||||
@ -100,18 +101,8 @@ public class DisguiseUtilities
|
||||
Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class, boolean.class)
|
||||
.newInstance(0, true);
|
||||
|
||||
Object block;
|
||||
|
||||
try
|
||||
{
|
||||
block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class).invoke(null,
|
||||
Object block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class).invoke(null,
|
||||
Material.BED_BLOCK.getId());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
block = ((Object[]) ReflectionManager.getNmsField(ReflectionManager.getNmsClass("Block"), "byId")
|
||||
.get(null))[Material.BED_BLOCK.getId()];
|
||||
}
|
||||
|
||||
Method fromLegacyData = block.getClass().getMethod("fromLegacyData", int.class);
|
||||
Method setType = chunkSection.getClass().getMethod("setType", int.class, int.class, int.class,
|
||||
@ -141,11 +132,8 @@ public class DisguiseUtilities
|
||||
|
||||
cSection.set(bedChunk, array);
|
||||
|
||||
xChunk = bedChunk.getClass().getField("locX");
|
||||
xChunk.setAccessible(true);
|
||||
|
||||
zChunk = bedChunk.getClass().getField("locZ");
|
||||
zChunk.setAccessible(true);
|
||||
spawnChunk = ProtocolLibrary.getProtocolManager()
|
||||
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, 65535).createPacket(bedChunk, 65535);
|
||||
|
||||
Field threadField = ReflectionManager.getNmsField("MinecraftServer", "primaryThread");
|
||||
threadField.setAccessible(true);
|
||||
@ -439,105 +427,75 @@ public class DisguiseUtilities
|
||||
return addedByPlugins;
|
||||
}
|
||||
|
||||
public static int getChunkCord(int blockCord)
|
||||
{
|
||||
int cord = (int) Math.floor(blockCord / 16D) - 17;
|
||||
|
||||
cord -= (cord % 8);
|
||||
|
||||
return cord;
|
||||
}
|
||||
|
||||
public static PacketContainer[] getBedChunkPacket(Location newLoc, Location oldLoc)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
PacketContainer[] packets = new PacketContainer[newLoc != null ? 2 + (oldLoc != null ? 1 : 0) : 1];
|
||||
PacketContainer[] packets = new PacketContainer[(newLoc != null ? 1 : 0) + (oldLoc != null ? 1 : 0)];
|
||||
|
||||
for (Location loc : new Location[]
|
||||
if (oldLoc != null)
|
||||
{
|
||||
oldLoc, newLoc
|
||||
})
|
||||
{
|
||||
if (loc == null)
|
||||
{
|
||||
continue;
|
||||
PacketContainer despawn = new PacketContainer(Server.UNLOAD_CHUNK);
|
||||
|
||||
StructureModifier<Object> modifier = despawn.getModifier();
|
||||
|
||||
modifier.write(0, getChunkCord(oldLoc.getBlockX()));
|
||||
modifier.write(1, getChunkCord(oldLoc.getBlockZ()));
|
||||
|
||||
packets[i++] = despawn;
|
||||
}
|
||||
|
||||
int chunkX = (int) Math.floor(loc.getX() / 16D) - 17, chunkZ = (int) Math.floor(loc.getZ() / 16D) - 17;
|
||||
|
||||
chunkX -= chunkX % 8;
|
||||
chunkZ -= chunkZ % 8;
|
||||
|
||||
// Make unload packets
|
||||
|
||||
packets[i] = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.UNLOAD_CHUNK, chunkX, chunkZ)
|
||||
.createPacket(chunkX, chunkZ);
|
||||
|
||||
i++;
|
||||
|
||||
// Make load packets
|
||||
if (oldLoc == null || i > 1)
|
||||
if (newLoc != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
xChunk.set(bedChunk, chunkX);
|
||||
zChunk.set(bedChunk, chunkZ);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
PacketContainer spawn = spawnChunk.shallowClone();
|
||||
|
||||
// MAP_CHUNK_BULK was replaced in 1.9 with several seperated chunk packets
|
||||
// packets[i] = ProtocolLibrary.getProtocolManager()
|
||||
// .createPacketConstructor(Server.MAP_CHUNK_BULK, Arrays.asList(bedChunk))
|
||||
// .createPacket(Arrays.asList(bedChunk));
|
||||
// Make unload packets
|
||||
try
|
||||
{
|
||||
packets[i] = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.MAP_CHUNK, bedChunk, 0)
|
||||
.createPacket(bedChunk, 0);
|
||||
}
|
||||
catch (IllegalArgumentException ex)
|
||||
{
|
||||
packets[i] = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.MAP_CHUNK, bedChunk, true, 0)
|
||||
.createPacket(bedChunk, true, 0);
|
||||
}
|
||||
StructureModifier<Object> modifier = spawn.getModifier();
|
||||
|
||||
i++;
|
||||
}
|
||||
modifier.write(0, getChunkCord(newLoc.getBlockX()));
|
||||
modifier.write(1, getChunkCord(newLoc.getBlockZ()));
|
||||
|
||||
packets[i++] = spawn;
|
||||
}
|
||||
|
||||
return packets;
|
||||
}
|
||||
|
||||
public static PacketContainer[] getBedPackets(Player player, Location loc, Location playerLocation, PlayerDisguise disguise)
|
||||
public static PacketContainer[] getBedPackets(Location sleepingLocation, Location playerLocation, PlayerDisguise disguise)
|
||||
{
|
||||
Entity entity = disguise.getEntity();
|
||||
int entity = disguise.getEntity().getEntityId();
|
||||
PlayerWatcher watcher = disguise.getWatcher();
|
||||
|
||||
PacketContainer setBed = new PacketContainer(Server.BED);
|
||||
|
||||
int chunkX = (int) Math.floor(playerLocation.getX() / 16D) - 17,
|
||||
chunkZ = (int) Math.floor(playerLocation.getZ() / 16D) - 17;
|
||||
chunkX -= chunkX % 8;
|
||||
chunkZ -= chunkZ % 8;
|
||||
int bX = (getChunkCord(playerLocation.getBlockX()) * 16) + 1 + watcher.getSleepingDirection().getModX();
|
||||
int bZ = (getChunkCord(playerLocation.getBlockZ()) * 16) + 1 + watcher.getSleepingDirection().getModZ();
|
||||
|
||||
PlayerWatcher watcher = disguise.getWatcher();
|
||||
|
||||
StructureModifier<Integer> bedInts = setBed.getIntegers();
|
||||
bedInts.write(0, entity.getEntityId());
|
||||
|
||||
bedInts.write(1, (chunkX * 16) + 1 + watcher.getSleepingDirection().getModX());
|
||||
bedInts.write(3, (chunkZ * 16) + 1 + watcher.getSleepingDirection().getModZ());
|
||||
setBed.getIntegers().write(0, entity);
|
||||
setBed.getBlockPositionModifier().write(0, new BlockPosition(bX, 0, bZ));
|
||||
|
||||
PacketContainer teleport = new PacketContainer(Server.ENTITY_TELEPORT);
|
||||
|
||||
StructureModifier<Integer> ints = teleport.getIntegers();
|
||||
ints.write(0, entity.getEntityId());
|
||||
|
||||
StructureModifier<Double> doubles = teleport.getDoubles();
|
||||
|
||||
doubles.write(0, loc.getX());
|
||||
doubles.write(1, PacketsManager.getYModifier(disguise.getEntity(), disguise) + loc.getY());
|
||||
doubles.write(2, loc.getZ());
|
||||
teleport.getIntegers().write(0, entity);
|
||||
|
||||
doubles.write(0, sleepingLocation.getX());
|
||||
doubles.write(1, PacketsManager.getYModifier(disguise.getEntity(), disguise) + sleepingLocation.getY());
|
||||
doubles.write(2, sleepingLocation.getZ());
|
||||
|
||||
return new PacketContainer[]
|
||||
{
|
||||
setBed, teleport
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public static Disguise getClonedDisguise(String key)
|
||||
|
@ -260,7 +260,7 @@ public class PacketsManager
|
||||
newPackets[0] = spawnPackets[0];
|
||||
spawnPackets = newPackets;
|
||||
|
||||
PacketContainer[] bedPackets = DisguiseUtilities.getBedPackets(observer,
|
||||
PacketContainer[] bedPackets = DisguiseUtilities.getBedPackets(
|
||||
loc.clone().subtract(0, PacketsManager.getYModifier(disguisedEntity, disguise), 0),
|
||||
observer.getLocation(), ((PlayerDisguise) disguise));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user