-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
ListSet.java
36 lines (33 loc) · 1.22 KB
/
ListSet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package me.nallar.collections;
import java.util.Iterator;
import me.nallar.tickthreading.Log;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;
public class ListSet extends SynchronizedList {
@Override
public synchronized boolean add(final Object o) {
if (o instanceof World) {
World world = (World) o;
WorldProvider provider = world.provider;
if (provider == null) {
Log.severe("Tried to add world " + world + " with null provider to bukkit dimensions.", new Throwable());
return false;
}
Iterator<World> iterator = this.iterator();
while (iterator.hasNext()) {
World world_ = iterator.next();
if (world_ == world) {
return false;
} else if (world_.provider == null) {
Log.severe("World " + world_ + " with null provider still in bukkit dimensions.", new Throwable());
iterator.remove();
} else if (provider.dimensionId == world_.provider.dimensionId) {
Log.severe("Attempted to add " + Log.dumpWorld(world) + " to bukkit dimensions when " + Log.dumpWorld(world_) + " is already in it.", new Throwable());
return false;
}
}
return super.add(o);
}
return !this.contains(o) && super.add(o);
}
}