From c1b5780d77c9e5d77e7385207926d588303ce6d5 Mon Sep 17 00:00:00 2001 From: riking Date: Fri, 13 Jun 2014 23:19:23 -0700 Subject: [PATCH 1/2] Use new-style runTask methods --- .../libraryaddict/disguise/DisguiseListener.java | 6 +++--- .../disguise/disguisetypes/Disguise.java | 15 ++++++++------- .../disguise/utilities/DisguiseUtilities.java | 6 +++--- .../disguise/utilities/PacketsManager.java | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index 17eb09cf..556b3f21 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -45,7 +45,7 @@ public class DisguiseListener implements Listener { updateNotifyPermission = plugin.getConfig().getString("Permission"); if (plugin.getConfig().getBoolean("NotifyUpdate")) { currentVersion = plugin.getDescription().getVersion(); - Bukkit.getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() { + Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { public void run() { try { UpdateChecker updateChecker = new UpdateChecker(); @@ -53,7 +53,7 @@ public class DisguiseListener implements Listener { latestVersion = updateChecker.getLatestVersion(); if (latestVersion != null) { latestVersion = "v" + latestVersion; - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + Bukkit.getScheduler().runTask(plugin, new Runnable() { public void run() { for (Player p : Bukkit.getOnlinePlayers()) if (p.hasPermission(updateNotifyPermission)) @@ -239,7 +239,7 @@ public class DisguiseListener implements Listener { if (event.getExited() instanceof Player) { final Disguise disguise = DisguiseAPI.getDisguise((Player) event.getExited(), event.getExited()); if (disguise != null) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + Bukkit.getScheduler().runTask(plugin, new Runnable() { public void run() { DisguiseUtilities.setupFakeDisguise(disguise); ((Player) disguise.getEntity()).updateInventory(); diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index c6719982..ff956897 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -25,6 +25,7 @@ import org.bukkit.entity.Horse.Variant; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.Vector; import com.comphenix.protocol.PacketType; @@ -45,7 +46,7 @@ public abstract class Disguise { private boolean keepDisguisePlayerLogout = DisguiseConfig.isKeepDisguiseOnPlayerLogout(); private boolean modifyBoundingBox = DisguiseConfig.isModifyBoundingBox(); private boolean replaceSounds = DisguiseConfig.isSoundEnabled(); - private int taskId = -1; + private BukkitTask task = null; private Runnable velocityRunnable; private boolean velocitySent = DisguiseConfig.isVelocitySent(); private boolean viewSelfDisguise = DisguiseConfig.isViewDisguises(); @@ -188,8 +189,8 @@ public abstract class Disguise { } else { entity = null; watcher = getWatcher().clone(disguise); - Bukkit.getScheduler().cancelTask(taskId); - taskId = -1; + task.cancel(); + task = null; } } } else { @@ -404,9 +405,9 @@ public abstract class Disguise { public void removeDisguise() { if (disguiseInUse) { disguiseInUse = false; - if (taskId != -1) { - Bukkit.getScheduler().cancelTask(taskId); - taskId = -1; + if (task != null) { + task.cancel(); + task = null; } HashMap> disguises = DisguiseUtilities.getDisguises(); // If this disguise has a entity set @@ -657,7 +658,7 @@ public abstract class Disguise { throw new RuntimeException("No entity is assigned to this disguise!"); } disguiseInUse = true; - taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, velocityRunnable, 1, 1); + task = Bukkit.getScheduler().runTaskTimer(plugin, velocityRunnable, 1, 1); // Stick the disguise in the disguises bin DisguiseUtilities.addDisguise(entity.getUniqueId(), (TargetedDisguise) this); // Resend the disguised entity's packet diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 83c26058..28051f5e 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -387,11 +387,11 @@ public class DisguiseUtilities { } // Add null so that if this is called again. I already know I'm doing something about it gameProfiles.put(playerName, null); - Bukkit.getScheduler().scheduleAsyncDelayedTask(libsDisguises, new Runnable() { + Bukkit.getScheduler().runTaskAsynchronously(libsDisguises, new Runnable() { public void run() { try { final WrappedGameProfile gameProfile = lookupGameProfile(playerName); - Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { + Bukkit.getScheduler().runTask(libsDisguises, new Runnable() { public void run() { if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) { gameProfiles.put(playerName, gameProfile); @@ -647,7 +647,7 @@ public class DisguiseUtilities { // If it is, then this method will be run again in one tick. Which is when it should be constructed. // Else its going to run in a infinite loop hue hue hue.. // At least until this disguise is discarded - Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { + Bukkit.getScheduler().runTask(libsDisguises, new Runnable() { public void run() { if (DisguiseAPI.getDisguise(player, player) == disguise) { sendSelfDisguise(player, disguise); diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 6e3742ea..06a973c5 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -909,7 +909,7 @@ public class PacketsManager { if (clickedItem != null && clickedItem.getType() != Material.AIR) { // Rather than predict the clients actions // Lets just update the entire inventory.. - Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { + Bukkit.getScheduler().runTask(libsDisguises, new Runnable() { public void run() { event.getPlayer().updateInventory(); } From 4766d2a0d1b764d3edf0e8127f0c768a4f2976b2 Mon Sep 17 00:00:00 2001 From: riking Date: Sat, 14 Jun 2014 10:16:36 -0700 Subject: [PATCH 2/2] Some wording cleanup --- .../disguise/commands/DisguiseCloneCommand.java | 14 +++++++------- .../disguise/commands/LibsDisguisesCommand.java | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java index ef1373d6..513070d8 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java @@ -28,12 +28,12 @@ public class DisguiseCloneCommand extends BaseDisguiseCommand { return true; } if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) { - boolean doEnquipment = true; + boolean doEquipment = true; boolean doSneak = false; boolean doSprint = false; for (String option : args) { - if (StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) { - doEnquipment = false; + if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip") || StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) { + doEquipment = false; } else if (option.equalsIgnoreCase("doSneakSprint")) { doSneak = true; doSprint = true; @@ -43,11 +43,11 @@ public class DisguiseCloneCommand extends BaseDisguiseCommand { doSprint = true; } else { sender.sendMessage(ChatColor.DARK_RED + "Unknown option '" + option - + "' - Valid options are 'IgnoreEnquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"); + + "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"); return true; } } - listener.setDisguiseClone(sender.getName(), new Boolean[] { doEnquipment, doSneak, doSprint }); + listener.setDisguiseClone(sender.getName(), new Boolean[] { doEquipment, doSneak, doSprint }); sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseCloneExpire() + " seconds to grab the disguise reference!"); } else { @@ -62,8 +62,8 @@ public class DisguiseCloneCommand extends BaseDisguiseCommand { protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { sender.sendMessage(ChatColor.DARK_GREEN + "Right click a entity to get a disguise reference you can pass to other disguise commands!"); - sender.sendMessage(ChatColor.DARK_GREEN + "Beware however, the reference bypasses all permissions checks"); - sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseclone IgnoreEnquipment" + ChatColor.DARK_GREEN + "(" + sender.sendMessage(ChatColor.DARK_GREEN + "Security note: Any references you create will be available to all players able to use disguise references."); + sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"); } } diff --git a/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java b/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java index fe2c2ba1..8a46a6ab 100644 --- a/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java +++ b/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java @@ -10,6 +10,7 @@ public class LibsDisguisesCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + // TODO is public version disclosure a problem? sender.sendMessage(ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises "