Bed chunk fix
This commit is contained in:
parent
3e493fdda6
commit
e0293227dd
@ -39,7 +39,8 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.UpdateChecker;
|
||||
|
||||
public class DisguiseListener implements Listener {
|
||||
public class DisguiseListener implements Listener
|
||||
{
|
||||
|
||||
private String currentVersion;
|
||||
private HashMap<String, Boolean[]> disguiseClone = new HashMap<>();
|
||||
@ -49,24 +50,34 @@ public class DisguiseListener implements Listener {
|
||||
private LibsDisguises plugin;
|
||||
private BukkitTask updaterTask;
|
||||
|
||||
public DisguiseListener(LibsDisguises libsDisguises) {
|
||||
public DisguiseListener(LibsDisguises libsDisguises)
|
||||
{
|
||||
plugin = libsDisguises;
|
||||
if (plugin.getConfig().getBoolean("NotifyUpdate")) {
|
||||
if (plugin.getConfig().getBoolean("NotifyUpdate"))
|
||||
{
|
||||
currentVersion = plugin.getDescription().getVersion();
|
||||
updaterTask = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
||||
updaterTask = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
UpdateChecker updateChecker = new UpdateChecker();
|
||||
updateChecker.checkUpdate("v" + currentVersion);
|
||||
latestVersion = updateChecker.getLatestVersion();
|
||||
if (latestVersion != null) {
|
||||
if (latestVersion != null)
|
||||
{
|
||||
latestVersion = "v" + latestVersion;
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) {
|
||||
public void run()
|
||||
{
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (p.hasPermission(DisguiseConfig.getUpdateNotificationPermission()))
|
||||
{
|
||||
p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion,
|
||||
latestVersion));
|
||||
}
|
||||
@ -74,7 +85,9 @@ public class DisguiseListener implements Listener {
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.print(String.format("[LibsDisguises] Failed to check for update: %s", ex.getMessage()));
|
||||
}
|
||||
}
|
||||
@ -83,77 +96,106 @@ public class DisguiseListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
for (BukkitRunnable r : disguiseRunnable.values()) {
|
||||
public void cleanup()
|
||||
{
|
||||
for (BukkitRunnable r : disguiseRunnable.values())
|
||||
{
|
||||
r.cancel();
|
||||
}
|
||||
for (Disguise d : disguiseEntity.values()) {
|
||||
for (Disguise d : disguiseEntity.values())
|
||||
{
|
||||
d.removeDisguise();
|
||||
}
|
||||
disguiseClone.clear();
|
||||
updaterTask.cancel();
|
||||
}
|
||||
|
||||
private void checkPlayerCanBlowDisguise(Player entity) {
|
||||
private void checkPlayerCanBlowDisguise(Player entity)
|
||||
{
|
||||
Disguise[] disguises = DisguiseAPI.getDisguises(entity);
|
||||
if (disguises.length > 0) {
|
||||
if (disguises.length > 0)
|
||||
{
|
||||
DisguiseAPI.undisguiseToAll(entity);
|
||||
if (DisguiseConfig.getDisguiseBlownMessage().length() > 0) {
|
||||
if (DisguiseConfig.getDisguiseBlownMessage().length() > 0)
|
||||
{
|
||||
entity.sendMessage(DisguiseConfig.getDisguiseBlownMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void chunkMove(Player player, Location newLoc, Location oldLoc) {
|
||||
try {
|
||||
for (PacketContainer packet : DisguiseUtilities.getBedChunkPacket(newLoc, oldLoc)) {
|
||||
private void chunkMove(Player player, Location newLoc, Location oldLoc)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (PacketContainer packet : DisguiseUtilities.getBedChunkPacket(newLoc, oldLoc))
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
if (newLoc != null) {
|
||||
for (HashSet<TargetedDisguise> list : DisguiseUtilities.getDisguises().values()) {
|
||||
for (TargetedDisguise disguise : list) {
|
||||
|
||||
if (newLoc != null)
|
||||
{
|
||||
for (HashSet<TargetedDisguise> list : DisguiseUtilities.getDisguises().values())
|
||||
{
|
||||
for (TargetedDisguise disguise : list)
|
||||
{
|
||||
if (disguise.isPlayerDisguise() && disguise.canSee(player)
|
||||
&& ((PlayerDisguise) disguise).getWatcher().isSleeping()
|
||||
&& DisguiseUtilities.getPerverts(disguise).contains(player)) {
|
||||
&& DisguiseUtilities.getPerverts(disguise).contains(player))
|
||||
{
|
||||
PacketContainer[] packets = DisguiseUtilities.getBedPackets(player,
|
||||
disguise.getEntity() == player ? newLoc : disguise.getEntity().getLocation(), newLoc,
|
||||
(PlayerDisguise) disguise);
|
||||
if (disguise.getEntity() == player) {
|
||||
for (PacketContainer packet : packets) {
|
||||
|
||||
if (disguise.getEntity() == player)
|
||||
{
|
||||
for (PacketContainer packet : packets)
|
||||
{
|
||||
packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
}
|
||||
for (PacketContainer packet : packets) {
|
||||
|
||||
for (PacketContainer packet : packets)
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onAttack(EntityDamageByEntityEvent event) {
|
||||
if (DisguiseConfig.isDisguiseBlownOnAttack()) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
public void onAttack(EntityDamageByEntityEvent event)
|
||||
{
|
||||
if (DisguiseConfig.isDisguiseBlownOnAttack())
|
||||
{
|
||||
if (event.getEntity() instanceof Player)
|
||||
{
|
||||
checkPlayerCanBlowDisguise((Player) event.getEntity());
|
||||
}
|
||||
if (event.getDamager() instanceof Player) {
|
||||
|
||||
if (event.getDamager() instanceof Player)
|
||||
{
|
||||
checkPlayerCanBlowDisguise((Player) event.getDamager());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
public void onJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player p = event.getPlayer();
|
||||
if (latestVersion != null && p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) {
|
||||
if (latestVersion != null && p.hasPermission(DisguiseConfig.getUpdateNotificationPermission()))
|
||||
{
|
||||
p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion, latestVersion));
|
||||
}
|
||||
if (DisguiseConfig.isBedPacketsEnabled()) {
|
||||
if (DisguiseConfig.isBedPacketsEnabled())
|
||||
{
|
||||
chunkMove(p, p.getLocation(), null);
|
||||
}
|
||||
}
|
||||
@ -162,23 +204,29 @@ public class DisguiseListener implements Listener {
|
||||
* Most likely faster if we don't bother doing checks if he sees a player disguise
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onMove(PlayerMoveEvent event) {
|
||||
if (DisguiseConfig.isBedPacketsEnabled()) {
|
||||
public void onMove(PlayerMoveEvent event)
|
||||
{
|
||||
if (DisguiseConfig.isBedPacketsEnabled())
|
||||
{
|
||||
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 (x1 - (x1 % 8) != x2 - (x2 % 8) || z1 - (z1 % 8) != z2 - (z2 % 8))
|
||||
{
|
||||
chunkMove(event.getPlayer(), to, from);
|
||||
}
|
||||
}
|
||||
|
||||
if (DisguiseConfig.isStopShulkerDisguisesFromMoving()) {
|
||||
if (DisguiseConfig.isStopShulkerDisguisesFromMoving())
|
||||
{
|
||||
Disguise disguise;
|
||||
if ((disguise = DisguiseAPI.getDisguise(event.getPlayer())) != null) {
|
||||
if (disguise.getType() == DisguiseType.SHULKER) { //Stop Shulker disguises from moving their coordinates
|
||||
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());
|
||||
@ -190,97 +238,136 @@ public class DisguiseListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
public void onQuit(PlayerQuitEvent event)
|
||||
{
|
||||
ReflectionManager.removePlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
public void onRespawn(PlayerRespawnEvent event)
|
||||
{
|
||||
Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer());
|
||||
for (Disguise disguise : disguises) {
|
||||
if (disguise.isRemoveDisguiseOnDeath()) {
|
||||
for (Disguise disguise : disguises)
|
||||
{
|
||||
if (disguise.isRemoveDisguiseOnDeath())
|
||||
{
|
||||
disguise.removeDisguise();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRightClick(PlayerInteractEntityEvent event) {
|
||||
if (disguiseEntity.containsKey(event.getPlayer().getName()) || disguiseClone.containsKey(event.getPlayer().getName())) {
|
||||
public void onRightClick(PlayerInteractEntityEvent event)
|
||||
{
|
||||
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())) {
|
||||
if (entity instanceof Player && !disguiseClone.containsKey(p.getName()))
|
||||
{
|
||||
entityName = entity.getName();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
entityName = DisguiseType.getType(entity).toReadable();
|
||||
}
|
||||
if (disguiseClone.containsKey(p.getName())) {
|
||||
if (disguiseClone.containsKey(p.getName()))
|
||||
{
|
||||
Boolean[] options = disguiseClone.remove(p.getName());
|
||||
Disguise disguise = DisguiseAPI.getDisguise(p, entity);
|
||||
if (disguise == null) {
|
||||
if (disguise == null)
|
||||
{
|
||||
disguise = DisguiseAPI.constructDisguise(entity, options[0], options[1], options[2]);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
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) {
|
||||
while (reference == null && attempts++ < 1000)
|
||||
{
|
||||
reference = "@";
|
||||
for (int i = 0; i < referenceLength; i++) {
|
||||
for (int i = 0; i < referenceLength; i++)
|
||||
{
|
||||
reference += alphabet[DisguiseUtilities.random.nextInt(alphabet.length)];
|
||||
}
|
||||
if (DisguiseUtilities.getClonedDisguise(reference) != null) {
|
||||
if (DisguiseUtilities.getClonedDisguise(reference) != null)
|
||||
{
|
||||
reference = null;
|
||||
}
|
||||
}
|
||||
if (reference != null && DisguiseUtilities.addClonedDisguise(reference, disguise)) {
|
||||
if (reference != null && DisguiseUtilities.addClonedDisguise(reference, disguise))
|
||||
{
|
||||
p.sendMessage(ChatColor.RED + "Constructed a " + entityName + " disguise! Your reference is " + reference);
|
||||
p.sendMessage(ChatColor.RED + "Example usage: /disguise " + reference);
|
||||
} else {
|
||||
p.sendMessage(ChatColor.RED
|
||||
+ "Failed to store the reference due to lack of size. Please set this in the config");
|
||||
}
|
||||
} else if (disguiseEntity.containsKey(p.getName())) {
|
||||
else
|
||||
{
|
||||
p.sendMessage(
|
||||
ChatColor.RED + "Failed to store the reference due to lack of size. Please set this in the config");
|
||||
}
|
||||
}
|
||||
else if (disguiseEntity.containsKey(p.getName()))
|
||||
{
|
||||
Disguise disguise = disguiseEntity.remove(p.getName());
|
||||
if (disguise != null) {
|
||||
if (disguise != null)
|
||||
{
|
||||
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()
|
||||
&& entity instanceof LivingEntity) {
|
||||
&& entity instanceof LivingEntity)
|
||||
{
|
||||
p.sendMessage(ChatColor.RED
|
||||
+ "Can't disguise a living entity as a misc disguise. This has been disabled in the config!");
|
||||
} else {
|
||||
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise())
|
||||
{
|
||||
if (disguise.getWatcher() instanceof LivingWatcher)
|
||||
{
|
||||
disguise.getWatcher().setCustomName(((Player) entity).getDisplayName());
|
||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible())
|
||||
{
|
||||
disguise.getWatcher().setCustomNameVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
DisguiseAPI.disguiseToAll(entity, disguise);
|
||||
String disguiseName = "a ";
|
||||
if (disguise instanceof PlayerDisguise) {
|
||||
if (disguise instanceof PlayerDisguise)
|
||||
{
|
||||
disguiseName = "the player " + ((PlayerDisguise) disguise).getName();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
disguiseName += disguise.getType().toReadable();
|
||||
}
|
||||
if (disguise.isDisguiseInUse()) {
|
||||
if (disguise.isDisguiseInUse())
|
||||
{
|
||||
p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName
|
||||
+ " as " + disguiseName + "!");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
p.sendMessage(ChatColor.RED + "Failed to disguise " + (entity instanceof Player ? "" : "the ")
|
||||
+ entityName + " as " + disguiseName + "!");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (DisguiseAPI.isDisguised(entity)) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DisguiseAPI.isDisguised(entity))
|
||||
{
|
||||
DisguiseAPI.undisguiseToAll(entity);
|
||||
p.sendMessage(ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
p.sendMessage(ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!");
|
||||
}
|
||||
}
|
||||
@ -289,42 +376,54 @@ public class DisguiseListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTarget(EntityTargetEvent event) {
|
||||
public void onTarget(EntityTargetEvent event)
|
||||
{
|
||||
if (DisguiseConfig.isMonstersIgnoreDisguises() && event.getTarget() != null && event.getTarget() instanceof Player
|
||||
&& DisguiseAPI.isDisguised(event.getTarget())) {
|
||||
switch (event.getReason()) {
|
||||
case TARGET_ATTACKED_ENTITY:
|
||||
case TARGET_ATTACKED_OWNER:
|
||||
case OWNER_ATTACKED_TARGET:
|
||||
case CUSTOM:
|
||||
break;
|
||||
default:
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
&& DisguiseAPI.isDisguised(event.getTarget()))
|
||||
{
|
||||
switch (event.getReason())
|
||||
{
|
||||
case TARGET_ATTACKED_ENTITY:
|
||||
case TARGET_ATTACKED_OWNER:
|
||||
case OWNER_ATTACKED_TARGET:
|
||||
case CUSTOM:
|
||||
break;
|
||||
default:
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onTeleport(final PlayerTeleportEvent event) {
|
||||
if (!DisguiseAPI.isDisguised(event.getPlayer())) {
|
||||
public void onTeleport(final PlayerTeleportEvent event)
|
||||
{
|
||||
if (!DisguiseAPI.isDisguised(event.getPlayer()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Location to = event.getTo();
|
||||
Location from = event.getFrom();
|
||||
if (DisguiseConfig.isBedPacketsEnabled()) {
|
||||
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 (x1 - (x1 % 8) != x2 - (x2 % 8) || z1 - (z1 % 8) != z2 - (z2 % 8))
|
||||
{
|
||||
chunkMove(event.getPlayer(), null, from);
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
if (!event.isCancelled()) {
|
||||
public void run()
|
||||
{
|
||||
if (!event.isCancelled())
|
||||
{
|
||||
chunkMove(event.getPlayer(), event.getTo(), null);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
chunkMove(event.getPlayer(), event.getPlayer().getLocation(), null);
|
||||
}
|
||||
}
|
||||
@ -332,29 +431,38 @@ public class DisguiseListener implements Listener {
|
||||
}
|
||||
}
|
||||
if (DisguiseConfig.isUndisguiseOnWorldChange() && to.getWorld() != null && from.getWorld() != null
|
||||
&& to.getWorld() != from.getWorld()) {
|
||||
for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) {
|
||||
&& to.getWorld() != from.getWorld())
|
||||
{
|
||||
for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer()))
|
||||
{
|
||||
disguise.removeDisguise();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onVehicleEnter(VehicleEnterEvent event) {
|
||||
if (event.getEntered() instanceof Player && DisguiseAPI.isDisguised((Player) event.getEntered(), event.getEntered())) {
|
||||
public void onVehicleEnter(VehicleEnterEvent event)
|
||||
{
|
||||
if (event.getEntered() instanceof Player && DisguiseAPI.isDisguised((Player) event.getEntered(), event.getEntered()))
|
||||
{
|
||||
DisguiseUtilities.removeSelfDisguise((Player) event.getEntered());
|
||||
((Player) event.getEntered()).updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onVehicleLeave(VehicleExitEvent event) {
|
||||
if (event.getExited() instanceof Player) {
|
||||
public void onVehicleLeave(VehicleExitEvent event)
|
||||
{
|
||||
if (event.getExited() instanceof Player)
|
||||
{
|
||||
final Disguise disguise = DisguiseAPI.getDisguise((Player) event.getExited(), event.getExited());
|
||||
if (disguise != null) {
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
if (disguise != null)
|
||||
{
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
DisguiseUtilities.setupFakeDisguise(disguise);
|
||||
((Player) disguise.getEntity()).updateInventory();
|
||||
}
|
||||
@ -364,42 +472,56 @@ public class DisguiseListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onWorldSwitch(final PlayerChangedWorldEvent event) {
|
||||
if (!DisguiseAPI.isDisguised(event.getPlayer())) {
|
||||
public void onWorldSwitch(final PlayerChangedWorldEvent event)
|
||||
{
|
||||
if (!DisguiseAPI.isDisguised(event.getPlayer()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (DisguiseConfig.isBedPacketsEnabled()) {
|
||||
if (DisguiseConfig.isBedPacketsEnabled())
|
||||
{
|
||||
chunkMove(event.getPlayer(), event.getPlayer().getLocation(), null);
|
||||
}
|
||||
if (DisguiseConfig.isUndisguiseOnWorldChange()) {
|
||||
for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) {
|
||||
if (DisguiseConfig.isUndisguiseOnWorldChange())
|
||||
{
|
||||
for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer()))
|
||||
{
|
||||
disguise.removeDisguise();
|
||||
}
|
||||
} else {
|
||||
//Stupid hack to fix worldswitch invisibility bug
|
||||
}
|
||||
else
|
||||
{
|
||||
// Stupid hack to fix worldswitch invisibility bug
|
||||
final boolean viewSelfToggled = DisguiseAPI.isViewSelfToggled(event.getPlayer());
|
||||
if (viewSelfToggled) {
|
||||
if (viewSelfToggled)
|
||||
{
|
||||
final Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer());
|
||||
disguise.setViewSelfDisguise(false);
|
||||
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
|
||||
Bukkit.getScheduler().runTaskLater(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
disguise.setViewSelfDisguise(true);
|
||||
}
|
||||
}, 20L); //I wish I could use lambdas here, so badly
|
||||
}, 20L); // I wish I could use lambdas here, so badly
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setDisguiseClone(final String player, Boolean[] options) {
|
||||
if (disguiseRunnable.containsKey(player)) {
|
||||
public void setDisguiseClone(final String player, Boolean[] options)
|
||||
{
|
||||
if (disguiseRunnable.containsKey(player))
|
||||
{
|
||||
BukkitRunnable run = disguiseRunnable.remove(player);
|
||||
run.cancel();
|
||||
run.run();
|
||||
}
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
BukkitRunnable runnable = new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
disguiseClone.remove(player);
|
||||
disguiseRunnable.remove(player);
|
||||
}
|
||||
@ -409,15 +531,19 @@ public class DisguiseListener implements Listener {
|
||||
disguiseClone.put(player, options);
|
||||
}
|
||||
|
||||
public void setDisguiseEntity(final String player, Disguise disguise) {
|
||||
if (disguiseRunnable.containsKey(player)) {
|
||||
public void setDisguiseEntity(final String player, Disguise disguise)
|
||||
{
|
||||
if (disguiseRunnable.containsKey(player))
|
||||
{
|
||||
BukkitRunnable run = disguiseRunnable.remove(player);
|
||||
run.cancel();
|
||||
run.run();
|
||||
}
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
BukkitRunnable runnable = new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
disguiseEntity.remove(player);
|
||||
disguiseRunnable.remove(player);
|
||||
}
|
||||
|
@ -124,19 +124,26 @@ public class DisguiseUtilities
|
||||
BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH
|
||||
})
|
||||
{
|
||||
setType.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(),
|
||||
fromLegacyData.invoke(block, face.ordinal()));
|
||||
setSky.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
|
||||
setEmitted.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
|
||||
int x = 1 + face.getModX();
|
||||
|
||||
int z = 1 + face.getModZ();
|
||||
|
||||
setType.invoke(chunkSection, x, 0, z, fromLegacyData.invoke(block, face.ordinal()));
|
||||
|
||||
setSky.invoke(chunkSection, x, 0, z, 0);
|
||||
|
||||
setEmitted.invoke(chunkSection, x, 0, z, 0);
|
||||
}
|
||||
|
||||
Object[] array = (Object[]) Array.newInstance(chunkSection.getClass(), 16);
|
||||
|
||||
array[0] = chunkSection;
|
||||
|
||||
cSection.set(bedChunk, array);
|
||||
|
||||
xChunk = bedChunk.getClass().getField("locX");
|
||||
xChunk.setAccessible(true);
|
||||
|
||||
zChunk = bedChunk.getClass().getField("locZ");
|
||||
zChunk.setAccessible(true);
|
||||
}
|
||||
@ -445,6 +452,7 @@ public class DisguiseUtilities
|
||||
|
||||
chunkX -= chunkX % 8;
|
||||
chunkZ -= chunkZ % 8;
|
||||
|
||||
xChunk.set(bedChunk, chunkX);
|
||||
zChunk.set(bedChunk, chunkZ);
|
||||
}
|
||||
@ -452,16 +460,25 @@ public class DisguiseUtilities
|
||||
{
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
|
||||
// Make unload packets
|
||||
try
|
||||
{
|
||||
packets[i] = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.MAP_CHUNK, bedChunk, true, 0, 40)
|
||||
.createPacket(bedChunk, true, 0, 48);
|
||||
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);
|
||||
try
|
||||
{
|
||||
packets[i] = ProtocolLibrary.getProtocolManager()
|
||||
.createPacketConstructor(Server.MAP_CHUNK, bedChunk, true, 0, 40).createPacket(bedChunk, true, 0, 48);
|
||||
}
|
||||
catch (IllegalArgumentException ex1)
|
||||
{
|
||||
packets[i] = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.MAP_CHUNK, bedChunk, true, 0)
|
||||
.createPacket(bedChunk, true, 0);
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
|
Loading…
Reference in New Issue
Block a user