View difference between Paste ID: Gi2K1cer and 3GeUJPBU
SHOW: | | - or go back to the newest paste.
1
public class ArrowRemoval {
2
	public ArrowRemoval(){
3
		enable();
4
	}
5
	
6
	public static PriorityQueue<ArrowLandData> q = new PriorityQueue<ArrowLandData>();
7
	
8
	public void enable(){
9
		plugin.getInstance().getServer().getScheduler().scheduleSyncRepeatingTask(plugin.getInstance(), new Runnable(){
10
11
			@Override
12
			public void run() {
13
				ArrowLandData ald;
14-
				ArrowLandData a = q.peek();
14+
				while ((ald = q.peek()) != null && ald.isReady()) {
15-
				if(a.getTime() / 1000 >= 10 && a.getArrow().isValid()){
15+
					q.poll().removeArrow();
16-
					a.getArrow();
16+
17-
					q.remove(a);
17+
18
			}	
19
		}, 100L, 100L);
20
	}
21
	
22
}
23
24
public class ArrowLandData {
25
	private Arrow arrow;
26
	private long landTime;
27
	public ArrowLandData(Arrow a) {
28
		arrow = a;
29
		landTime = System.currentTimeMillis();
30
	}
31
	public boolean isReady() {
32
		if (!arrow.isValid()) return true;
33
		return System.currentTimeMillis() > landTime + (1000 * 10);
34
	}
35
	public void removeArrow() {
36
		arrow.remove();
37
		arrow = null; // drop ref
38
	}
39
}