我试图从另一个类别中称作一种回归类型方法,但我却发现,这一类型没有界定。 在这里,Im试图呼吁:
public MyTask() {
id = plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,this,plugin.getConfig().getInt("StunDuration") * 20);
if(id == -1)
{
plugin.getLogger().warning("BLARG");
}
}
我将如何从另一类人中来看待这种方法?
public class DamageListener implements Listener{
private antirelog plugin;
public DamageListener (antirelog plugin) {
this.plugin = plugin;
}
Player realplayer1;
Player realplayer2;
boolean playeradd = false;
private MyTask task;
public static boolean isDamaged = false;
public static boolean timerTask = true;
static Set<Player> Damagelist = Collections.newSetFromMap(new WeakHashMap<Player,Boolean>());
@EventHandler
public void damage (EntityDamageEvent event) {
Entity victim = event.getEntity();
if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent edbeEvent = (EntityDamageByEntityEvent) event;
if(edbeEvent.getDamager() instanceof Player && victim instanceof Player) {
EntityDamageByEntityEvent edbeEvent1 = (EntityDamageByEntityEvent) event;
Entity attacker = edbeEvent1.getDamager();
Player player = (Player) victim;
realplayer1 = player;
Player player2 = (Player) attacker;
realplayer2 = player2;
if(Damagelist.contains(realplayer1) || Damagelist.contains(realplayer2)) {
isDamaged = true;
timerTask = false;
System.out.println("Cancel");
MyTask();
} else {
Damagelist.add(realplayer1);
Damagelist.add(realplayer2);
isDamaged = true;
Pause ps = new Pause(plugin);
MyTask();
}
}
}
这里是MyTask阶级。
public class MyTask implements Runnable
{
private antirelog plugin;
private int id = -1;
/**
* Generic constructor
* @param Plugin task is associated with
* @return
*/
public MyTask (antirelog plugin) {
this.plugin = plugin;
}
public void MyTask() {
id = plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,this,plugin.getConfig().getInt("StunDuration") * 20);
if(id == -1)
{
plugin.getLogger().warning("BLARG");
}
}
/**
* Do stuff when scheduler tells task to run
*/
@Override
public void run()
{
if (DamageListener.timerTask == true) {
DamageListener dl = new DamageListener(plugin);
dl.Then();
}
else if (DamageListener.timerTask == false) {
plugin.getServer().getScheduler().cancelTask(id);
DamageListener.timerTask = true;
}
}
/**
* Remove task from scheduler
* @return True if successfully stopped. Else false.
*/
public boolean stopTask()
{
if(id != -1)
{
plugin.getServer().getScheduler().cancelTask(id);
return true;
}
return false;
}
}