@Su37Erich: Oh, I'm sorry, I think I overlooked your post. I will edit this post when I got an answer for you.
//Edit:
Your CommandEntry Problem:
I will have to see your full code for the CommandEntry problem, because when I test it, it works perfectly fine. Is your Command in a CommandGroup, or is it directly registered in the PlayerCommandManager?
Your Timer Problem:
Your Timer will be destroyed if you don't save the instance. You said your variable is an instance variable, but where do you declare it? Do you declare it in the method or did you define it in the class? If you defined it in the method, the variable will be destroyed. You can create a "trash list" with timers in it, which will be cleared after X seconds depending if the timer is still running or not (use the timer.isRunning() method).
Here is an example (I think I will add this to shoebill-common):
PHP код:
package org.marvin;
import net.gtaun.shoebill.object.Timer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Created by marvin on 24.04.16.
* Copyright © Marvin Haschker 2016.
*/
public class TemporaryTimer implements Timer {
private static Timer recycleTimer;
private static List<TemporaryTimer> timers;
static {
timers = new ArrayList<>();
recycleTimer = Timer.create(5000, i -> {
Iterator<TemporaryTimer> iterator = timers.iterator();
while(iterator.hasNext()) {
TemporaryTimer timer = iterator.next();
if(!timer.isRunning() && timer.hasBeenStarted()) {
timer.destroy();
iterator.remove();
System.out.println("Timer destroyed.");
}
}
});
recycleTimer.start();
}
public static TemporaryTimer create(int interval, TimerCallback callback) {
return create(interval, Timer.COUNT_INFINITE, callback);
}
public static TemporaryTimer create(int interval, int count, TimerCallback callback) {
return new TemporaryTimer(interval, count, callback);
}
private Timer timer;
private boolean hasBeenStarted = false;
private TemporaryTimer(int interval, int count, TimerCallback callback) {
timer = Timer.create(interval, count, callback);
timers.add(this);
}
@Override
public int getInterval() {
return timer.getInterval();
}
@Override
public int getCount() {
return timer.getCount();
}
@Override
public boolean isRunning() {
return timer.isRunning();
}
@Override
public void setInterval(int ms) {
timer.setInterval(ms);
}
@Override
public void setCount(int count) {
timer.setCount(count);
}
@Override
public void start() {
timer.start();
hasBeenStarted = true;
System.out.println("Timer started.");
}
@Override
public void stop() {
timer.stop();
}
@Override
public void setCallback(TimerCallback callback) {
timer.setCallback(callback);
}
@Override
public void destroy() {
timer.destroy();
}
@Override
public boolean isDestroyed() {
return timer.isDestroyed();
}
private boolean hasBeenStarted() {
return hasBeenStarted;
}
}
Usage:
PHP код:
TemporaryTimer.create(1000, 5, i -> {
System.out.println("Iteration #" + String.valueOf(i));
}).start();
This timer will be destroyed after it finished.