Naghtrion Postado Fevereiro 25, 2018 Denunciar Compartilhar Postado Fevereiro 25, 2018 Olá, estou com uma duvida... qual é melhor usar? BukkitScheduler ou BukkitRunnable ? na verdade eu não entendi a diferença entre eles... alguém pode me explicar? o que entendi na documentação é que o BukkitRunnable "não são caros de criar" Vou usar para quando o player entrar no servidor, fazer uma pesquisa em assíncrono Link para o comentário Compartilhar em outros sites More sharing options...
0 TequilAxBr Postado Fevereiro 25, 2018 Denunciar Compartilhar Postado Fevereiro 25, 2018 Diferença em desempenho eu não sei se tem, mas BukkitScheduler é mais antigo. Eu sempre uso BukkitRunnable. 1 Link para o comentário Compartilhar em outros sites More sharing options...
0 zAth Postado Fevereiro 25, 2018 Denunciar Compartilhar Postado Fevereiro 25, 2018 BukkitScheduler é meio que um "manager" para criar/cancelar BukkitRunnables BukkitRunnable é um Runnable ;-; Eu uso BukkitRunnable porque acho que fica mais organizado e mais fácil de cancelar se criar uma classe que extende o BukkitRunnable ao invés de ficar mexendo no BukkitScheduler. BukkitScheduler // // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package org.bukkit.scheduler; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.Future; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitWorker; public interface BukkitScheduler { int scheduleSyncDelayedTask(Plugin var1, Runnable var2, long var3); /** @deprecated */ @Deprecated int scheduleSyncDelayedTask(Plugin var1, BukkitRunnable var2, long var3); int scheduleSyncDelayedTask(Plugin var1, Runnable var2); /** @deprecated */ @Deprecated int scheduleSyncDelayedTask(Plugin var1, BukkitRunnable var2); int scheduleSyncRepeatingTask(Plugin var1, Runnable var2, long var3, long var5); /** @deprecated */ @Deprecated int scheduleSyncRepeatingTask(Plugin var1, BukkitRunnable var2, long var3, long var5); /** @deprecated */ @Deprecated int scheduleAsyncDelayedTask(Plugin var1, Runnable var2, long var3); /** @deprecated */ @Deprecated int scheduleAsyncDelayedTask(Plugin var1, Runnable var2); /** @deprecated */ @Deprecated int scheduleAsyncRepeatingTask(Plugin var1, Runnable var2, long var3, long var5); <T> Future<T> callSyncMethod(Plugin var1, Callable<T> var2); void cancelTask(int var1); void cancelTasks(Plugin var1); void cancelAllTasks(); boolean isCurrentlyRunning(int var1); boolean isQueued(int var1); List<BukkitWorker> getActiveWorkers(); List<BukkitTask> getPendingTasks(); BukkitTask runTask(Plugin var1, Runnable var2) throws IllegalArgumentException; /** @deprecated */ @Deprecated BukkitTask runTask(Plugin var1, BukkitRunnable var2) throws IllegalArgumentException; BukkitTask runTaskAsynchronously(Plugin var1, Runnable var2) throws IllegalArgumentException; /** @deprecated */ @Deprecated BukkitTask runTaskAsynchronously(Plugin var1, BukkitRunnable var2) throws IllegalArgumentException; BukkitTask runTaskLater(Plugin var1, Runnable var2, long var3) throws IllegalArgumentException; /** @deprecated */ @Deprecated BukkitTask runTaskLater(Plugin var1, BukkitRunnable var2, long var3) throws IllegalArgumentException; BukkitTask runTaskLaterAsynchronously(Plugin var1, Runnable var2, long var3) throws IllegalArgumentException; /** @deprecated */ @Deprecated BukkitTask runTaskLaterAsynchronously(Plugin var1, BukkitRunnable var2, long var3) throws IllegalArgumentException; BukkitTask runTaskTimer(Plugin var1, Runnable var2, long var3, long var5) throws IllegalArgumentException; /** @deprecated */ @Deprecated BukkitTask runTaskTimer(Plugin var1, BukkitRunnable var2, long var3, long var5) throws IllegalArgumentException; BukkitTask runTaskTimerAsynchronously(Plugin var1, Runnable var2, long var3, long var5) throws IllegalArgumentException; /** @deprecated */ @Deprecated BukkitTask runTaskTimerAsynchronously(Plugin var1, BukkitRunnable var2, long var3, long var5) throws IllegalArgumentException; } BukkitRunnable // // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package org.bukkit.scheduler; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitTask; public abstract class BukkitRunnable implements Runnable { private int taskId = -1; public BukkitRunnable() { } public synchronized void cancel() throws IllegalStateException { Bukkit.getScheduler().cancelTask(this.getTaskId()); } public synchronized BukkitTask runTask(Plugin plugin) throws IllegalArgumentException, IllegalStateException { this.checkState(); return this.setupId(Bukkit.getScheduler().runTask(plugin, this)); } public synchronized BukkitTask runTaskAsynchronously(Plugin plugin) throws IllegalArgumentException, IllegalStateException { this.checkState(); return this.setupId(Bukkit.getScheduler().runTaskAsynchronously(plugin, this)); } public synchronized BukkitTask runTaskLater(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException { this.checkState(); return this.setupId(Bukkit.getScheduler().runTaskLater(plugin, this, delay)); } public synchronized BukkitTask runTaskLaterAsynchronously(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException { this.checkState(); return this.setupId(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, this, delay)); } public synchronized BukkitTask runTaskTimer(Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException { this.checkState(); return this.setupId(Bukkit.getScheduler().runTaskTimer(plugin, this, delay, period)); } public synchronized BukkitTask runTaskTimerAsynchronously(Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException { this.checkState(); return this.setupId(Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, this, delay, period)); } public synchronized int getTaskId() throws IllegalStateException { int id = this.taskId; if(id == -1) { throw new IllegalStateException("Not scheduled yet"); } else { return id; } } private void checkState() { if(this.taskId != -1) { throw new IllegalStateException("Already scheduled as " + this.taskId); } } private BukkitTask setupId(BukkitTask task) { this.taskId = task.getTaskId(); return task; } } 1 Link para o comentário Compartilhar em outros sites More sharing options...
0 Naghtrion Postado Fevereiro 25, 2018 Autor Denunciar Compartilhar Postado Fevereiro 25, 2018 Diferença em desempenho eu não sei se tem, mas BukkitScheduler é mais antigo. Eu sempre uso BukkitRunnable. BukkitScheduler é meio que um "manager" para criar/cancelar BukkitRunnables BukkitRunnable é um Runnable ;-; Eu uso BukkitRunnable porque acho que fica mais organizado e mais fácil de cancelar se criar uma classe que extende o BukkitRunnable ao invés de ficar mexendo no BukkitScheduler. BukkitScheduler // // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package org.bukkit.scheduler; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.Future; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitWorker; public interface BukkitScheduler { int scheduleSyncDelayedTask(Plugin var1, Runnable var2, long var3); /** @deprecated */ @Deprecated int scheduleSyncDelayedTask(Plugin var1, BukkitRunnable var2, long var3); int scheduleSyncDelayedTask(Plugin var1, Runnable var2); /** @deprecated */ @Deprecated int scheduleSyncDelayedTask(Plugin var1, BukkitRunnable var2); int scheduleSyncRepeatingTask(Plugin var1, Runnable var2, long var3, long var5); /** @deprecated */ @Deprecated int scheduleSyncRepeatingTask(Plugin var1, BukkitRunnable var2, long var3, long var5); /** @deprecated */ @Deprecated int scheduleAsyncDelayedTask(Plugin var1, Runnable var2, long var3); /** @deprecated */ @Deprecated int scheduleAsyncDelayedTask(Plugin var1, Runnable var2); /** @deprecated */ @Deprecated int scheduleAsyncRepeatingTask(Plugin var1, Runnable var2, long var3, long var5); <T> Future<T> callSyncMethod(Plugin var1, Callable<T> var2); void cancelTask(int var1); void cancelTasks(Plugin var1); void cancelAllTasks(); boolean isCurrentlyRunning(int var1); boolean isQueued(int var1); List<BukkitWorker> getActiveWorkers(); List<BukkitTask> getPendingTasks(); BukkitTask runTask(Plugin var1, Runnable var2) throws IllegalArgumentException; /** @deprecated */ @Deprecated BukkitTask runTask(Plugin var1, BukkitRunnable var2) throws IllegalArgumentException; BukkitTask runTaskAsynchronously(Plugin var1, Runnable var2) throws IllegalArgumentException; /** @deprecated */ @Deprecated BukkitTask runTaskAsynchronously(Plugin var1, BukkitRunnable var2) throws IllegalArgumentException; BukkitTask runTaskLater(Plugin var1, Runnable var2, long var3) throws IllegalArgumentException; /** @deprecated */ @Deprecated BukkitTask runTaskLater(Plugin var1, BukkitRunnable var2, long var3) throws IllegalArgumentException; BukkitTask runTaskLaterAsynchronously(Plugin var1, Runnable var2, long var3) throws IllegalArgumentException; /** @deprecated */ @Deprecated BukkitTask runTaskLaterAsynchronously(Plugin var1, BukkitRunnable var2, long var3) throws IllegalArgumentException; BukkitTask runTaskTimer(Plugin var1, Runnable var2, long var3, long var5) throws IllegalArgumentException; /** @deprecated */ @Deprecated BukkitTask runTaskTimer(Plugin var1, BukkitRunnable var2, long var3, long var5) throws IllegalArgumentException; BukkitTask runTaskTimerAsynchronously(Plugin var1, Runnable var2, long var3, long var5) throws IllegalArgumentException; /** @deprecated */ @Deprecated BukkitTask runTaskTimerAsynchronously(Plugin var1, BukkitRunnable var2, long var3, long var5) throws IllegalArgumentException; } BukkitRunnable // // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package org.bukkit.scheduler; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitTask; public abstract class BukkitRunnable implements Runnable { private int taskId = -1; public BukkitRunnable() { } public synchronized void cancel() throws IllegalStateException { Bukkit.getScheduler().cancelTask(this.getTaskId()); } public synchronized BukkitTask runTask(Plugin plugin) throws IllegalArgumentException, IllegalStateException { this.checkState(); return this.setupId(Bukkit.getScheduler().runTask(plugin, this)); } public synchronized BukkitTask runTaskAsynchronously(Plugin plugin) throws IllegalArgumentException, IllegalStateException { this.checkState(); return this.setupId(Bukkit.getScheduler().runTaskAsynchronously(plugin, this)); } public synchronized BukkitTask runTaskLater(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException { this.checkState(); return this.setupId(Bukkit.getScheduler().runTaskLater(plugin, this, delay)); } public synchronized BukkitTask runTaskLaterAsynchronously(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException { this.checkState(); return this.setupId(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, this, delay)); } public synchronized BukkitTask runTaskTimer(Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException { this.checkState(); return this.setupId(Bukkit.getScheduler().runTaskTimer(plugin, this, delay, period)); } public synchronized BukkitTask runTaskTimerAsynchronously(Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException { this.checkState(); return this.setupId(Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, this, delay, period)); } public synchronized int getTaskId() throws IllegalStateException { int id = this.taskId; if(id == -1) { throw new IllegalStateException("Not scheduled yet"); } else { return id; } } private void checkState() { if(this.taskId != -1) { throw new IllegalStateException("Already scheduled as " + this.taskId); } } private BukkitTask setupId(BukkitTask task) { this.taskId = task.getTaskId(); return task; } } Obrigado pela ajuda! olhando o código fonte ficou mais fácil entender, o BukkitRunnable é mais fácil de manipular que o BukkitScheduler, mas no final são a mesma coisa kkkkkkk Eu achava que havia alguma diferença... Link para o comentário Compartilhar em outros sites More sharing options...
0 nOthing Postado Fevereiro 25, 2018 Denunciar Compartilhar Postado Fevereiro 25, 2018 Sua dúvida foi marcada como [Resolvido] e movido à área de dúvidas resolvidas. Atenciosamente, Gamer's Board Sua dúvida foi marcada como [Resolvido] e movido à área de dúvidas resolvidas. Atenciosamente, Gamer's Board Link para o comentário Compartilhar em outros sites More sharing options...
Pergunta
Naghtrion
Olá, estou com uma duvida... qual é melhor usar?
BukkitScheduler ou BukkitRunnable ?
na verdade eu não entendi a diferença entre eles... alguém pode me explicar?
o que entendi na documentação é que o BukkitRunnable "não são caros de criar"
Vou usar para quando o player entrar no servidor, fazer uma pesquisa em assíncrono
Link para o comentário
Compartilhar em outros sites
4 respostass a esta questão
Posts Recomendados