Don't load preferences if corrupted
This commit is contained in:
parent
bb009be826
commit
c8e08e91ff
@ -242,8 +242,7 @@ public class DisguiseUtilities {
|
|||||||
try {
|
try {
|
||||||
viewPreferences.delete();
|
viewPreferences.delete();
|
||||||
Files.write(viewPreferences.toPath(), json.getBytes(), StandardOpenOption.CREATE);
|
Files.write(viewPreferences.toPath(), json.getBytes(), StandardOpenOption.CREATE);
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,6 +260,11 @@ public class DisguiseUtilities {
|
|||||||
String disguiseText = new String(Files.readAllBytes(viewPreferences.toPath()));
|
String disguiseText = new String(Files.readAllBytes(viewPreferences.toPath()));
|
||||||
map = getGson().fromJson(disguiseText, HashMap.class);
|
map = getGson().fromJson(disguiseText, HashMap.class);
|
||||||
|
|
||||||
|
if (map == null) {
|
||||||
|
viewPreferences.delete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (map.containsKey("selfdisguise")) {
|
if (map.containsKey("selfdisguise")) {
|
||||||
getViewSelf().clear();
|
getViewSelf().clear();
|
||||||
map.get("selfdisguise").forEach(uuid -> getViewSelf().add(UUID.fromString(uuid)));
|
map.get("selfdisguise").forEach(uuid -> getViewSelf().add(UUID.fromString(uuid)));
|
||||||
@ -270,8 +274,7 @@ public class DisguiseUtilities {
|
|||||||
getViewBar().clear();
|
getViewBar().clear();
|
||||||
map.get("notifybar").forEach(uuid -> getViewBar().add(UUID.fromString(uuid)));
|
map.get("notifybar").forEach(uuid -> getViewBar().add(UUID.fromString(uuid)));
|
||||||
}
|
}
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,22 +365,26 @@ public class DisguiseUtilities {
|
|||||||
public static void saveDisguises() {
|
public static void saveDisguises() {
|
||||||
saveViewPreferances();
|
saveViewPreferances();
|
||||||
|
|
||||||
if (!LibsPremium.isPremium())
|
if (!LibsPremium.isPremium()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!DisguiseConfig.isSaveEntityDisguises() && !DisguiseConfig.isSavePlayerDisguises())
|
if (!DisguiseConfig.isSaveEntityDisguises() && !DisguiseConfig.isSavePlayerDisguises()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
getLogger().info("Now saving disguises..");
|
getLogger().info("Now saving disguises..");
|
||||||
|
|
||||||
for (Set<TargetedDisguise> list : getDisguises().values()) {
|
for (Set<TargetedDisguise> list : getDisguises().values()) {
|
||||||
for (TargetedDisguise disg : list) {
|
for (TargetedDisguise disg : list) {
|
||||||
if (disg.getEntity() == null)
|
if (disg.getEntity() == null) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (disg.getEntity() instanceof Player ? !DisguiseConfig.isSavePlayerDisguises() :
|
if (disg.getEntity() instanceof Player ? !DisguiseConfig.isSavePlayerDisguises() :
|
||||||
!DisguiseConfig.isSaveEntityDisguises())
|
!DisguiseConfig.isSaveEntityDisguises()) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
saveDisguises(disg.getEntity().getUniqueId(), list.toArray(new Disguise[0]));
|
saveDisguises(disg.getEntity().getUniqueId(), list.toArray(new Disguise[0]));
|
||||||
break;
|
break;
|
||||||
@ -427,11 +434,13 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void saveDisguises(UUID owningEntity, Disguise[] disguise) {
|
public static void saveDisguises(UUID owningEntity, Disguise[] disguise) {
|
||||||
if (!LibsPremium.isPremium())
|
if (!LibsPremium.isPremium()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!savedDisguises.exists())
|
if (!savedDisguises.exists()) {
|
||||||
savedDisguises.mkdirs();
|
savedDisguises.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File disguiseFile = new File(savedDisguises, owningEntity.toString());
|
File disguiseFile = new File(savedDisguises, owningEntity.toString());
|
||||||
@ -451,15 +460,15 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// I hear pirates don't obey standards
|
// I hear pirates don't obey standards
|
||||||
@SuppressWarnings("MismatchedStringCase") PrintWriter writer = new PrintWriter(disguiseFile,
|
@SuppressWarnings("MismatchedStringCase")
|
||||||
"12345".equals("%%__USER__%%") ? "US-ASCII" : "UTF-8");
|
PrintWriter writer =
|
||||||
|
new PrintWriter(disguiseFile, "12345".equals("%%__USER__%%") ? "US-ASCII" : "UTF-8");
|
||||||
writer.write(gson.toJson(disguises));
|
writer.write(gson.toJson(disguises));
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
savedDisguiseList.add(owningEntity);
|
savedDisguiseList.add(owningEntity);
|
||||||
}
|
}
|
||||||
}
|
} catch (StackOverflowError | Exception e) {
|
||||||
catch (StackOverflowError | Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -487,9 +496,9 @@ public class DisguiseUtilities {
|
|||||||
try {
|
try {
|
||||||
String cached;
|
String cached;
|
||||||
|
|
||||||
try (FileInputStream input = new FileInputStream(
|
try (FileInputStream input = new FileInputStream(disguiseFile);
|
||||||
disguiseFile); InputStreamReader inputReader = new InputStreamReader(input,
|
InputStreamReader inputReader = new InputStreamReader(input, StandardCharsets.UTF_8);
|
||||||
StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(inputReader)) {
|
BufferedReader reader = new BufferedReader(inputReader)) {
|
||||||
cached = reader.lines().collect(Collectors.joining("\n"));
|
cached = reader.lines().collect(Collectors.joining("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,8 +513,7 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return disguises;
|
return disguises;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
getLogger().severe("Malformed disguise for " + entityUUID);
|
getLogger().severe("Malformed disguise for " + entityUUID);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -514,11 +522,13 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void removeSavedDisguise(UUID entityUUID) {
|
public static void removeSavedDisguise(UUID entityUUID) {
|
||||||
if (!savedDisguiseList.remove(entityUUID))
|
if (!savedDisguiseList.remove(entityUUID)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!savedDisguises.exists())
|
if (!savedDisguises.exists()) {
|
||||||
savedDisguises.mkdirs();
|
savedDisguises.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
File disguiseFile = new File(savedDisguises, entityUUID.toString());
|
File disguiseFile = new File(savedDisguises, entityUUID.toString());
|
||||||
|
|
||||||
@ -645,8 +655,9 @@ public class DisguiseUtilities {
|
|||||||
|
|
||||||
public static void addGameProfile(String string, WrappedGameProfile gameProfile) {
|
public static void addGameProfile(String string, WrappedGameProfile gameProfile) {
|
||||||
try {
|
try {
|
||||||
if (!profileCache.exists())
|
if (!profileCache.exists()) {
|
||||||
profileCache.mkdirs();
|
profileCache.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
File file = new File(profileCache, string.toLowerCase());
|
File file = new File(profileCache, string.toLowerCase());
|
||||||
PrintWriter writer = new PrintWriter(file);
|
PrintWriter writer = new PrintWriter(file);
|
||||||
@ -654,8 +665,7 @@ public class DisguiseUtilities {
|
|||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
cachedNames.add(string.toLowerCase());
|
cachedNames.add(string.toLowerCase());
|
||||||
}
|
} catch (StackOverflowError | Exception e) {
|
||||||
catch (StackOverflowError | Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -735,17 +745,19 @@ public class DisguiseUtilities {
|
|||||||
* Sends entity removal packets, as this disguise was removed
|
* Sends entity removal packets, as this disguise was removed
|
||||||
*/
|
*/
|
||||||
public static void destroyEntity(TargetedDisguise disguise) {
|
public static void destroyEntity(TargetedDisguise disguise) {
|
||||||
if (!Bukkit.isPrimaryThread())
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
||||||
|
|
||||||
if (entityTrackerEntry == null)
|
if (entityTrackerEntry == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
Set trackedPlayers =
|
||||||
.get(entityTrackerEntry);
|
(Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
|
||||||
|
|
||||||
// If the tracker exists. Remove himself from his tracker
|
// If the tracker exists. Remove himself from his tracker
|
||||||
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
|
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
|
||||||
@ -762,8 +774,7 @@ public class DisguiseUtilities {
|
|||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -864,11 +875,13 @@ public class DisguiseUtilities {
|
|||||||
public static WrappedGameProfile getGameProfile(String playerName) {
|
public static WrappedGameProfile getGameProfile(String playerName) {
|
||||||
playerName = playerName.toLowerCase();
|
playerName = playerName.toLowerCase();
|
||||||
|
|
||||||
if (!hasGameProfile(playerName))
|
if (!hasGameProfile(playerName)) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!profileCache.exists())
|
if (!profileCache.exists()) {
|
||||||
profileCache.mkdirs();
|
profileCache.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
File file = new File(profileCache, playerName);
|
File file = new File(profileCache, playerName);
|
||||||
|
|
||||||
@ -883,14 +896,12 @@ public class DisguiseUtilities {
|
|||||||
reader.close();
|
reader.close();
|
||||||
|
|
||||||
return gson.fromJson(cached, WrappedGameProfile.class);
|
return gson.fromJson(cached, WrappedGameProfile.class);
|
||||||
}
|
} catch (JsonSyntaxException ex) {
|
||||||
catch (JsonSyntaxException ex) {
|
|
||||||
DisguiseUtilities.getLogger()
|
DisguiseUtilities.getLogger()
|
||||||
.warning("Gameprofile " + file.getName() + " had invalid gson and has been deleted");
|
.warning("Gameprofile " + file.getName() + " had invalid gson and has been deleted");
|
||||||
cachedNames.remove(playerName.toLowerCase());
|
cachedNames.remove(playerName.toLowerCase());
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -920,12 +931,14 @@ public class DisguiseUtilities {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static List<Player> getPerverts(Disguise disguise) {
|
public static List<Player> getPerverts(Disguise disguise) {
|
||||||
if (!Bukkit.isPrimaryThread())
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
||||||
|
}
|
||||||
|
|
||||||
if (disguise.getEntity() == null)
|
if (disguise.getEntity() == null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"The entity for the disguisetype " + disguise.getType().name() + " is null!");
|
"The entity for the disguisetype " + disguise.getType().name() + " is null!");
|
||||||
|
}
|
||||||
|
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = new ArrayList<>();
|
||||||
|
|
||||||
@ -945,8 +958,7 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -986,12 +998,12 @@ public class DisguiseUtilities {
|
|||||||
* using schedulers. The runnable is run once the GameProfile has been successfully dealt with
|
* using schedulers. The runnable is run once the GameProfile has been successfully dealt with
|
||||||
*/
|
*/
|
||||||
public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn,
|
public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn,
|
||||||
boolean contactMojang) {
|
boolean contactMojang) {
|
||||||
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, contactMojang);
|
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, contactMojang);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static WrappedGameProfile getProfileFromMojang(final String origName, final Object runnable,
|
private static WrappedGameProfile getProfileFromMojang(final String origName, final Object runnable,
|
||||||
boolean contactMojang) {
|
boolean contactMojang) {
|
||||||
final String playerName = origName.toLowerCase();
|
final String playerName = origName.toLowerCase();
|
||||||
|
|
||||||
if (DisguiseConfig.isSaveGameProfiles() && hasGameProfile(playerName)) {
|
if (DisguiseConfig.isSaveGameProfiles() && hasGameProfile(playerName)) {
|
||||||
@ -1046,8 +1058,7 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
synchronized (runnables) {
|
synchronized (runnables) {
|
||||||
runnables.remove(playerName);
|
runnables.remove(playerName);
|
||||||
}
|
}
|
||||||
@ -1082,7 +1093,7 @@ public class DisguiseUtilities {
|
|||||||
* using schedulers. The runnable is run once the GameProfile has been successfully dealt with
|
* using schedulers. The runnable is run once the GameProfile has been successfully dealt with
|
||||||
*/
|
*/
|
||||||
public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn,
|
public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn,
|
||||||
boolean contactMojang) {
|
boolean contactMojang) {
|
||||||
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, contactMojang);
|
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, contactMojang);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1094,8 +1105,7 @@ public class DisguiseUtilities {
|
|||||||
|
|
||||||
// Don't really need this here, but it's insurance!
|
// Don't really need this here, but it's insurance!
|
||||||
runningPaper = Class.forName("com.destroystokyo.paper.VersionHistoryManager$VersionData") != null;
|
runningPaper = Class.forName("com.destroystokyo.paper.VersionHistoryManager$VersionData") != null;
|
||||||
}
|
} catch (Exception ignored) {
|
||||||
catch (Exception ignored) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
@ -1117,22 +1127,23 @@ public class DisguiseUtilities {
|
|||||||
|
|
||||||
gson = gsonBuilder.create();
|
gson = gsonBuilder.create();
|
||||||
|
|
||||||
if (!profileCache.exists())
|
if (!profileCache.exists()) {
|
||||||
profileCache.mkdirs();
|
profileCache.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
if (!savedDisguises.exists())
|
if (!savedDisguises.exists()) {
|
||||||
savedDisguises.mkdirs();
|
savedDisguises.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
cachedNames.addAll(Arrays.asList(profileCache.list()));
|
cachedNames.addAll(Arrays.asList(profileCache.list()));
|
||||||
|
|
||||||
invalidFile = LibsDisguises.getInstance().getFile().getName().toLowerCase()
|
invalidFile =
|
||||||
.matches(".*((crack)|(null)|(leak)).*");
|
LibsDisguises.getInstance().getFile().getName().toLowerCase().matches(".*((crack)|(null)|(leak)).*");
|
||||||
|
|
||||||
for (String key : savedDisguises.list()) {
|
for (String key : savedDisguises.list()) {
|
||||||
try {
|
try {
|
||||||
savedDisguiseList.add(UUID.fromString(key));
|
savedDisguiseList.add(UUID.fromString(key));
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
getLogger().warning("The file '" + key + "' does not belong in " + savedDisguises.getAbsolutePath());
|
getLogger().warning("The file '" + key + "' does not belong in " + savedDisguises.getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1165,8 +1176,7 @@ public class DisguiseUtilities {
|
|||||||
|
|
||||||
bar.removeAll();
|
bar.removeAll();
|
||||||
Bukkit.removeBossBar(bar.getKey());
|
Bukkit.removeBossBar(bar.getKey());
|
||||||
}
|
} catch (IllegalArgumentException ignored) {
|
||||||
catch (IllegalArgumentException ignored) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1184,8 +1194,7 @@ public class DisguiseUtilities {
|
|||||||
LibsDisguises.getInstance().saveDefaultConfig();*/
|
LibsDisguises.getInstance().saveDefaultConfig();*/
|
||||||
DisguiseConfig.setViewDisguises(false);
|
DisguiseConfig.setViewDisguises(false);
|
||||||
}
|
}
|
||||||
}
|
} catch (NoSuchMethodException e) {
|
||||||
catch (NoSuchMethodException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1208,11 +1217,13 @@ public class DisguiseUtilities {
|
|||||||
* Resends the entity to this specific player
|
* Resends the entity to this specific player
|
||||||
*/
|
*/
|
||||||
public static void refreshTracker(final TargetedDisguise disguise, String player) {
|
public static void refreshTracker(final TargetedDisguise disguise, String player) {
|
||||||
if (!Bukkit.isPrimaryThread())
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
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;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
||||||
@ -1230,16 +1241,16 @@ public class DisguiseUtilities {
|
|||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
|
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}, 2);
|
}, 2);
|
||||||
} else {
|
} else {
|
||||||
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
||||||
|
|
||||||
if (entityTrackerEntry == null)
|
if (entityTrackerEntry == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
||||||
.get(entityTrackerEntry);
|
.get(entityTrackerEntry);
|
||||||
@ -1257,8 +1268,9 @@ public class DisguiseUtilities {
|
|||||||
for (final Object p : trackedPlayers) {
|
for (final Object p : trackedPlayers) {
|
||||||
Player pl = (Player) ReflectionManager.getBukkitEntity(p);
|
Player pl = (Player) ReflectionManager.getBukkitEntity(p);
|
||||||
|
|
||||||
if (pl == null || !player.equalsIgnoreCase((pl).getName()))
|
if (pl == null || !player.equalsIgnoreCase((pl).getName())) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
clear.invoke(entityTrackerEntry, p);
|
clear.invoke(entityTrackerEntry, p);
|
||||||
|
|
||||||
@ -1267,16 +1279,14 @@ public class DisguiseUtilities {
|
|||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
updatePlayer.invoke(entityTrackerEntry, p);
|
updatePlayer.invoke(entityTrackerEntry, p);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}, 2);
|
}, 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (
|
||||||
catch (
|
|
||||||
|
|
||||||
Exception ex) {
|
Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@ -1287,8 +1297,9 @@ public class DisguiseUtilities {
|
|||||||
* A convenience method for me to refresh trackers in other plugins
|
* A convenience method for me to refresh trackers in other plugins
|
||||||
*/
|
*/
|
||||||
public static void refreshTrackers(Entity entity) {
|
public static void refreshTrackers(Entity entity) {
|
||||||
if (!Bukkit.isPrimaryThread())
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
||||||
|
}
|
||||||
|
|
||||||
if (entity.isValid()) {
|
if (entity.isValid()) {
|
||||||
try {
|
try {
|
||||||
@ -1321,16 +1332,14 @@ public class DisguiseUtilities {
|
|||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
updatePlayer.invoke(entityTrackerEntry, p);
|
updatePlayer.invoke(entityTrackerEntry, p);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}, 2);
|
}, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1340,8 +1349,9 @@ public class DisguiseUtilities {
|
|||||||
* Resends the entity to all the watching players, which is where the magic begins
|
* Resends the entity to all the watching players, which is where the magic begins
|
||||||
*/
|
*/
|
||||||
public static void refreshTrackers(final TargetedDisguise disguise) {
|
public static void refreshTrackers(final TargetedDisguise disguise) {
|
||||||
if (!Bukkit.isPrimaryThread())
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
||||||
|
}
|
||||||
|
|
||||||
if (!disguise.getEntity().isValid()) {
|
if (!disguise.getEntity().isValid()) {
|
||||||
return;
|
return;
|
||||||
@ -1360,8 +1370,7 @@ public class DisguiseUtilities {
|
|||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
|
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}, 2);
|
}, 2);
|
||||||
@ -1395,16 +1404,14 @@ public class DisguiseUtilities {
|
|||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
updatePlayer.invoke(entityTrackerEntry, p);
|
updatePlayer.invoke(entityTrackerEntry, p);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}, 2);
|
}, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1437,8 +1444,9 @@ public class DisguiseUtilities {
|
|||||||
public static void removeGameProfile(String string) {
|
public static void removeGameProfile(String string) {
|
||||||
cachedNames.remove(string.toLowerCase());
|
cachedNames.remove(string.toLowerCase());
|
||||||
|
|
||||||
if (!profileCache.exists())
|
if (!profileCache.exists()) {
|
||||||
profileCache.mkdirs();
|
profileCache.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
File file = new File(profileCache, string.toLowerCase());
|
File file = new File(profileCache, string.toLowerCase());
|
||||||
|
|
||||||
@ -1446,8 +1454,9 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void removeSelfDisguise(Disguise disguise) {
|
public static void removeSelfDisguise(Disguise disguise) {
|
||||||
if (!Bukkit.isPrimaryThread())
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
||||||
|
}
|
||||||
|
|
||||||
Player player = (Player) disguise.getEntity();
|
Player player = (Player) disguise.getEntity();
|
||||||
|
|
||||||
@ -1463,8 +1472,7 @@ public class DisguiseUtilities {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1492,8 +1500,7 @@ public class DisguiseUtilities {
|
|||||||
.get(entityTrackerEntry)).remove(ReflectionManager.getNmsEntity(player));
|
.get(entityTrackerEntry)).remove(ReflectionManager.getNmsEntity(player));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1503,8 +1510,7 @@ public class DisguiseUtilities {
|
|||||||
.createPacketConstructor(Server.ENTITY_METADATA, player.getEntityId(),
|
.createPacketConstructor(Server.ENTITY_METADATA, player.getEntityId(),
|
||||||
WrappedDataWatcher.getEntityWatcher(player), true)
|
WrappedDataWatcher.getEntityWatcher(player), true)
|
||||||
.createPacket(player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true));
|
.createPacket(player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true));
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1785,8 +1791,9 @@ public class DisguiseUtilities {
|
|||||||
Team ldTeam = null;
|
Team ldTeam = null;
|
||||||
|
|
||||||
for (Team t : scoreboard.getTeams()) {
|
for (Team t : scoreboard.getTeams()) {
|
||||||
if (!t.hasEntry(player.getName()))
|
if (!t.hasEntry(player.getName())) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ldTeam = t;
|
ldTeam = t;
|
||||||
break;
|
break;
|
||||||
@ -1849,8 +1856,9 @@ public class DisguiseUtilities {
|
|||||||
String ldTeamName = "LD_Pushing";
|
String ldTeamName = "LD_Pushing";
|
||||||
|
|
||||||
for (Team t : scoreboard.getTeams()) {
|
for (Team t : scoreboard.getTeams()) {
|
||||||
if (!t.hasEntry(player.getName()))
|
if (!t.hasEntry(player.getName())) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
prevTeam = t;
|
prevTeam = t;
|
||||||
break;
|
break;
|
||||||
@ -1885,8 +1893,9 @@ public class DisguiseUtilities {
|
|||||||
|
|
||||||
disguiseTeam.put(player.getUniqueId(), ldTeam.getName());
|
disguiseTeam.put(player.getUniqueId(), ldTeam.getName());
|
||||||
|
|
||||||
if (!ldTeam.hasEntry(player.getName()))
|
if (!ldTeam.hasEntry(player.getName())) {
|
||||||
ldTeam.addEntry(player.getName());
|
ldTeam.addEntry(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
if (pOption == DisguisePushing.CREATE_SCOREBOARD && prevTeam != null) {
|
if (pOption == DisguisePushing.CREATE_SCOREBOARD && prevTeam != null) {
|
||||||
ldTeam.setAllowFriendlyFire(prevTeam.allowFriendlyFire());
|
ldTeam.setAllowFriendlyFire(prevTeam.allowFriendlyFire());
|
||||||
@ -2088,8 +2097,9 @@ public class DisguiseUtilities {
|
|||||||
* Sends the self disguise to the player
|
* Sends the self disguise to the player
|
||||||
*/
|
*/
|
||||||
public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) {
|
public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) {
|
||||||
if (!Bukkit.isPrimaryThread())
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!disguise.isDisguiseInUse() || !player.isValid() || !player.isOnline() ||
|
if (!disguise.isDisguiseInUse() || !player.isValid() || !player.isOnline() ||
|
||||||
@ -2118,8 +2128,8 @@ public class DisguiseUtilities {
|
|||||||
// Check for code differences in PaperSpigot vs Spigot
|
// Check for code differences in PaperSpigot vs Spigot
|
||||||
if (!runningPaper) {
|
if (!runningPaper) {
|
||||||
// Add himself to his own entity tracker
|
// Add himself to his own entity tracker
|
||||||
Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
Object trackedPlayersObj =
|
||||||
.get(entityTrackerEntry);
|
ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
|
||||||
|
|
||||||
((Set<Object>) trackedPlayersObj).add(ReflectionManager.getNmsEntity(player));
|
((Set<Object>) trackedPlayersObj).add(ReflectionManager.getNmsEntity(player));
|
||||||
} else {
|
} else {
|
||||||
@ -2147,8 +2157,7 @@ public class DisguiseUtilities {
|
|||||||
.getDeclaredField(NmsVersion.v1_14.isSupported() ? "q" : "isMoving");
|
.getDeclaredField(NmsVersion.v1_14.isSupported() ? "q" : "isMoving");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
isMoving = field.getBoolean(entityTrackerEntry);
|
isMoving = field.getBoolean(entityTrackerEntry);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2199,8 +2208,7 @@ public class DisguiseUtilities {
|
|||||||
manager.createPacketConstructor(Server.ENTITY_EFFECT, player.getEntityId(), mobEffect)
|
manager.createPacketConstructor(Server.ENTITY_EFFECT, player.getEntityId(), mobEffect)
|
||||||
.createPacket(player.getEntityId(), mobEffect));
|
.createPacket(player.getEntityId(), mobEffect));
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2446,8 +2454,9 @@ public class DisguiseUtilities {
|
|||||||
LibsPackets transformed = PacketsManager.getPacketsHandler().transformPacket(packet, disguise, player, player);
|
LibsPackets transformed = PacketsManager.getPacketsHandler().transformPacket(packet, disguise, player, player);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (transformed.isUnhandled())
|
if (transformed.isUnhandled()) {
|
||||||
transformed.addPacket(packet);
|
transformed.addPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
for (PacketContainer p : transformed.getPackets()) {
|
for (PacketContainer p : transformed.getPackets()) {
|
||||||
p = p.deepClone();
|
p = p.deepClone();
|
||||||
@ -2456,8 +2465,7 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transformed.sendDelayed(player);
|
transformed.sendDelayed(player);
|
||||||
}
|
} catch (InvocationTargetException e) {
|
||||||
catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2526,8 +2534,7 @@ public class DisguiseUtilities {
|
|||||||
if (f.get(null) != index) {
|
if (f.get(null) != index) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
} catch (IllegalAccessException e) {
|
||||||
catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2621,7 +2628,7 @@ public class DisguiseUtilities {
|
|||||||
* Create a new datawatcher but with the 'correct' values
|
* Create a new datawatcher but with the 'correct' values
|
||||||
*/
|
*/
|
||||||
public static WrappedDataWatcher createSanitizedDataWatcher(WrappedDataWatcher entityWatcher,
|
public static WrappedDataWatcher createSanitizedDataWatcher(WrappedDataWatcher entityWatcher,
|
||||||
FlagWatcher disguiseWatcher) {
|
FlagWatcher disguiseWatcher) {
|
||||||
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -2630,21 +2637,22 @@ public class DisguiseUtilities {
|
|||||||
disguiseWatcher.getWatchableObjects();
|
disguiseWatcher.getWatchableObjects();
|
||||||
|
|
||||||
for (WrappedWatchableObject watchableObject : list) {
|
for (WrappedWatchableObject watchableObject : list) {
|
||||||
if (watchableObject == null)
|
if (watchableObject == null) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (watchableObject.getValue() == null)
|
if (watchableObject.getValue() == null) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
MetaIndex metaIndex = MetaIndex.getMetaIndex(disguiseWatcher, watchableObject.getIndex());
|
MetaIndex metaIndex = MetaIndex.getMetaIndex(disguiseWatcher, watchableObject.getIndex());
|
||||||
|
|
||||||
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager
|
WrappedDataWatcher.WrappedDataWatcherObject obj =
|
||||||
.createDataWatcherObject(metaIndex, watchableObject.getValue());
|
ReflectionManager.createDataWatcherObject(metaIndex, watchableObject.getValue());
|
||||||
|
|
||||||
newWatcher.setObject(obj, watchableObject.getValue());
|
newWatcher.setObject(obj, watchableObject.getValue());
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2788,8 +2796,8 @@ public class DisguiseUtilities {
|
|||||||
val = true;
|
val = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager
|
WrappedDataWatcher.WrappedDataWatcherObject obj =
|
||||||
.createDataWatcherObject(index, val);
|
ReflectionManager.createDataWatcherObject(index, val);
|
||||||
|
|
||||||
watcher.setObject(obj, ReflectionManager.convertInvalidMeta(val));
|
watcher.setObject(obj, ReflectionManager.convertInvalidMeta(val));
|
||||||
}
|
}
|
||||||
@ -2875,8 +2883,9 @@ public class DisguiseUtilities {
|
|||||||
|
|
||||||
switch (disguise.getType()) {
|
switch (disguise.getType()) {
|
||||||
case BAT:
|
case BAT:
|
||||||
if (entity instanceof LivingEntity)
|
if (entity instanceof LivingEntity) {
|
||||||
return yMod + ((LivingEntity) entity).getEyeHeight();
|
return yMod + ((LivingEntity) entity).getEyeHeight();
|
||||||
|
}
|
||||||
|
|
||||||
return yMod;
|
return yMod;
|
||||||
case MINECART:
|
case MINECART:
|
||||||
|
Loading…
Reference in New Issue
Block a user