English 中文(简体)
Java-How do I Call ameth with A Return 类型
原标题:Java-How do I Call a Method With A Return Type
  • 时间:2012-04-14 23:45:21
  •  标签:
  • java

我试图从另一个类别中称作一种回归类型方法,但我却发现,这一类型没有界定。 在这里,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;
  }
}
最佳回答

由于<代码>MyTask()是拟在另一类中即时使用的类别<代码>MyTask的构造者,必须先于<代码>new。 关键词类似:

...
isDamaged = true;
Pause ps = new Pause(plugin);
task = new MyTask(plugin); //Note the `new` keyword
...

也允许确定其他一些内容。

public MyTask (antirelog plugin)
{
    this.plugin = plugin;
    if (plugin != null) {
        id = plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,this,plugin.getConfig().getInt("StunDuration") * 20);
        if (id == -1)
        {
            plugin.getLogger().warning("BLARG");
        }
    }
}

//public MyTask() //Remove the void, this is a constructor
//{
//  this(null); //Call the extended constructor
//}
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签