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