本文整理汇总了Java中org.bukkit.scheduler.BukkitTask.isSync方法的典型用法代码示例。如果您正苦于以下问题:Java BukkitTask.isSync方法的具体用法?Java BukkitTask.isSync怎么用?Java BukkitTask.isSync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.scheduler.BukkitTask
的用法示例。
在下文中一共展示了BukkitTask.isSync方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTaskTimingsByPlugin
import org.bukkit.scheduler.BukkitTask; //导入方法依赖的package包/类
public static MonitorRecord getTaskTimingsByPlugin(Plugin plg) {
MonitorRecord monitorRecord = getMonitorRecord("Scheduler", 0L, 0L, 0L);
if (plg == null) {
return monitorRecord;
}
for (BukkitTask pendingTask : Bukkit.getScheduler().getPendingTasks()) {
if (pendingTask.isSync() && pendingTask.getOwner().equals(plg)) {
try {
FieldAccessor<Runnable> field = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);
Runnable runnable = field.get(pendingTask);
if (runnable instanceof SchedulerTaskInjector) {
SchedulerTaskInjector schedulerTaskInjector = (SchedulerTaskInjector) runnable;
monitorRecord = monitorRecord.merge(getMonitorRecord("Scheduler",
schedulerTaskInjector.getTotalTime(), schedulerTaskInjector.getTotalCount(),
schedulerTaskInjector.getMaxExecuteTime()));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return monitorRecord;
}
示例2: inject
import org.bukkit.scheduler.BukkitTask; //导入方法依赖的package包/类
/**
*
* @author jiongjionger,Vlvxingze
*/
// 替换原本的Runnable为带性能统计的版本
public static void inject(Plugin plg) {
if (plg != null) {
for (BukkitTask pendingTask : Bukkit.getScheduler().getPendingTasks()) {
if (pendingTask.isSync() && pendingTask.getOwner().equals(plg)) {
try {
FieldAccessor<Runnable> field = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);
field.set(pendingTask, new SchedulerTaskInjector(plg, field.get(pendingTask)));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
示例3: uninject
import org.bukkit.scheduler.BukkitTask; //导入方法依赖的package包/类
public static void uninject(Plugin plg) {
if (plg != null) {
for (BukkitTask pendingTask : Bukkit.getScheduler().getPendingTasks()) {
if (pendingTask.isSync() && pendingTask.getOwner().equals(plg)) {
try {
FieldAccessor<Runnable> field = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);
Runnable runnable = field.get(pendingTask);
if (runnable instanceof SchedulerTaskInjector) {
field.set(pendingTask, ((SchedulerTaskInjector) runnable).getRunnable());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
示例4: getTaskTimingsByPlugin
import org.bukkit.scheduler.BukkitTask; //导入方法依赖的package包/类
public static MonitorRecord getTaskTimingsByPlugin(Plugin plg) {
MonitorRecord monitorRecord = getMonitorRecord("Scheduler", 0L, 0L, 0L);
if (plg == null) {
return monitorRecord;
}
for (BukkitTask pendingTask : Bukkit.getScheduler().getPendingTasks()) {
if (pendingTask.isSync() && pendingTask.getOwner().equals(plg)) {
try {
FieldAccessor<Runnable> field = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);
Runnable runnable = field.get(pendingTask);
if (runnable instanceof SchedulerTaskInjector) {
SchedulerTaskInjector schedulerTaskInjector = (SchedulerTaskInjector) runnable;
monitorRecord = monitorRecord
.merge(getMonitorRecord("Scheduler", schedulerTaskInjector.getTotalTime(), schedulerTaskInjector.getTotalCount(), schedulerTaskInjector.getMaxExecuteTime()));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return monitorRecord;
}
示例5: inject
import org.bukkit.scheduler.BukkitTask; //导入方法依赖的package包/类
public static void inject(Plugin plg) {
if (plg != null) {
for (BukkitTask pendingTask : Bukkit.getScheduler().getPendingTasks()) {
if (pendingTask.isSync() && pendingTask.getOwner().equals(plg)) {
try {
FieldAccessor<Runnable> field = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);
field.set(pendingTask, new SchedulerTaskInjector(plg, field.get(pendingTask)));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
示例6: inject
import org.bukkit.scheduler.BukkitTask; //导入方法依赖的package包/类
public static void inject(Plugin plugin) {
BukkitScheduler scheduler = Bukkit.getScheduler();
List<BukkitTask> pendingTasks = scheduler.getPendingTasks();
for (BukkitTask pendingTask : pendingTasks) {
//we could ignore async tasks for now
if (pendingTask.isSync() && pendingTask.getOwner().equals(plugin)) {
FieldAccessor<Runnable> taskField = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);
Runnable originalTask = taskField.get(pendingTask);
TaskInjector taskInjector = new TaskInjector(originalTask);
taskField.set(pendingTask, taskInjector);
}
}
}
示例7: uninject
import org.bukkit.scheduler.BukkitTask; //导入方法依赖的package包/类
public static void uninject(Plugin plugin) {
BukkitScheduler scheduler = Bukkit.getScheduler();
List<BukkitTask> pendingTasks = scheduler.getPendingTasks();
for (BukkitTask pendingTask : pendingTasks) {
//we could ignore async tasks for now
if (pendingTask.isSync() && pendingTask.getOwner().equals(plugin)) {
FieldAccessor<Runnable> taskField = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);
Runnable task = taskField.get(pendingTask);
if (task instanceof TaskInjector) {
taskField.set(pendingTask, ((TaskInjector) task).originalTask);
}
}
}
}
示例8: onCommand
import org.bukkit.scheduler.BukkitTask; //导入方法依赖的package包/类
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!isAllowed(sender, command)) {
sender.sendMessage(org.bukkit.ChatColor.DARK_RED + "Not whitelisted");
return true;
}
List<BaseComponent[]> lines = Lists.newArrayList();
List<BukkitTask> pendingTasks = Bukkit.getScheduler().getPendingTasks();
for (BukkitTask pendingTask : pendingTasks) {
Plugin owner = pendingTask.getOwner();
int taskId = pendingTask.getTaskId();
boolean sync = pendingTask.isSync();
String id = Integer.toString(taskId);
if (sync) {
id += "-Sync";
} else if (Bukkit.getScheduler().isCurrentlyRunning(taskId)) {
id += "-Running";
}
lines.add(new ComponentBuilder(owner.getName())
.color(PRIMARY_COLOR)
.append('-' + id)
.color(SECONDARY_COLOR)
.create());
Class<?> runnableClass = getRunnableClass(pendingTask);
if (runnableClass != null) {
lines.add(new ComponentBuilder(" Task: ")
.color(PRIMARY_COLOR)
.append(runnableClass.getSimpleName())
.color(SECONDARY_COLOR)
.create());
}
}
Pagination pagination = new Pagination("Stacktrace", lines);
pagination.send(sender);
plugin.getPaginations().put(sender, pagination);
return true;
}