Move a self disguises setter to a scheduled task
This commit is contained in:
parent
60730f4dcd
commit
8e255c5ccf
@ -6,6 +6,7 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.EntityEquipment;
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
@ -195,8 +196,23 @@ public class FlagWatcher
|
|||||||
if (newHealth > 0 && hasDied)
|
if (newHealth > 0 && hasDied)
|
||||||
{
|
{
|
||||||
hasDied = false;
|
hasDied = false;
|
||||||
|
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), disguise);
|
DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), disguise);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ex.printStackTrace(System.out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 2);
|
||||||
|
}
|
||||||
else if (newHealth <= 0 && !hasDied)
|
else if (newHealth <= 0 && !hasDied)
|
||||||
{
|
{
|
||||||
hasDied = true;
|
hasDied = true;
|
||||||
|
@ -880,8 +880,9 @@ public class DisguiseUtilities
|
|||||||
if (mainThread != Thread.currentThread())
|
if (mainThread != Thread.currentThread())
|
||||||
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
||||||
|
|
||||||
if (disguise.getEntity() != null && disguise.getEntity().isValid())
|
if (disguise.getEntity() == null || !disguise.getEntity().isValid())
|
||||||
{
|
return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
||||||
@ -943,6 +944,7 @@ public class DisguiseUtilities
|
|||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
@ -962,12 +964,14 @@ public class DisguiseUtilities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (
|
||||||
|
|
||||||
|
Exception ex)
|
||||||
|
|
||||||
{
|
{
|
||||||
ex.printStackTrace(System.out);
|
ex.printStackTrace(System.out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A convenience method for me to refresh trackers in other plugins
|
* A convenience method for me to refresh trackers in other plugins
|
||||||
@ -1099,6 +1103,7 @@ public class DisguiseUtilities
|
|||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
@ -1116,9 +1121,12 @@ public class DisguiseUtilities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (
|
||||||
|
|
||||||
|
Exception ex)
|
||||||
{
|
{
|
||||||
ex.printStackTrace(System.out);
|
ex.printStackTrace(System.out);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1155,8 +1163,11 @@ public class DisguiseUtilities
|
|||||||
if (mainThread != Thread.currentThread())
|
if (mainThread != Thread.currentThread())
|
||||||
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
||||||
|
|
||||||
if (selfDisguised.contains(player.getUniqueId()))
|
if (!selfDisguised.contains(player.getUniqueId()))
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Send a packet to destroy the fake entity
|
// Send a packet to destroy the fake entity
|
||||||
PacketContainer packet = getDestroyPacket(DisguiseAPI.getSelfDisguiseId());
|
PacketContainer packet = getDestroyPacket(DisguiseAPI.getSelfDisguiseId());
|
||||||
|
|
||||||
@ -1198,8 +1209,8 @@ public class DisguiseUtilities
|
|||||||
// If the tracker exists. Remove himself from his tracker
|
// If the tracker exists. Remove himself from his tracker
|
||||||
if (isHashSet(trackedPlayersObj))
|
if (isHashSet(trackedPlayersObj))
|
||||||
{
|
{
|
||||||
((Set<Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
((Set<Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry))
|
||||||
.get(entityTrackerEntry)).remove(ReflectionManager.getNmsEntity(player));
|
.remove(ReflectionManager.getNmsEntity(player));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1229,7 +1240,6 @@ public class DisguiseUtilities
|
|||||||
|
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the self disguise to the player
|
* Sends the self disguise to the player
|
||||||
@ -1394,6 +1404,11 @@ public class DisguiseUtilities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LibsDisguises getPlugin()
|
||||||
|
{
|
||||||
|
return libsDisguises;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to send a packet to the self disguise, translate his entity ID to the fake id.
|
* Method to send a packet to the self disguise, translate his entity ID to the fake id.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user