PlotSquared/Sponge/src/main/java/com/plotsquared/sponge/uuid/SpongeUUIDHandler.java

51 lines
1.6 KiB
Java
Raw Normal View History

2015-07-30 16:25:16 +02:00
package com.plotsquared.sponge.uuid;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
2015-07-30 16:25:16 +02:00
import com.plotsquared.sponge.SpongeMain;
import org.spongepowered.api.profile.GameProfile;
import java.util.UUID;
2015-09-13 06:04:31 +02:00
public class SpongeUUIDHandler extends UUIDHandlerImplementation {
2016-04-06 05:50:04 +02:00
public SpongeUUIDHandler(UUIDWrapper wrapper) {
super(wrapper);
}
2015-09-13 06:04:31 +02:00
@Override
2016-04-06 05:50:04 +02:00
public boolean startCaching(Runnable whenDone) {
2015-09-13 06:04:31 +02:00
if (!super.startCaching(whenDone)) {
return false;
}
return cache(whenDone);
}
2016-04-06 05:50:04 +02:00
public boolean cache(Runnable whenDone) {
add(new StringWrapper("*"), DBFunc.everyone);
2016-04-06 05:50:04 +02:00
for (GameProfile profile : SpongeMain.THIS.getServer().getGameProfileManager().getCache().getProfiles()) {
String name = profile.getName().orElse(null);
if (name != null) {
add(new StringWrapper(name), profile.getUniqueId());
}
}
return true;
}
2015-09-13 06:04:31 +02:00
@Override
2016-04-06 05:50:04 +02:00
public void fetchUUID(String name, RunnableVal<UUID> ifFetch) {
2015-09-13 06:04:31 +02:00
TaskManager.runTaskAsync(new Runnable() {
@Override
2015-09-13 06:04:31 +02:00
public void run() {
2016-04-06 05:50:04 +02:00
ifFetch.value = SpongeUUIDHandler.this.uuidWrapper.getUUID(name);
TaskManager.runTask(ifFetch);
}
});
}
2015-09-13 06:04:31 +02:00
}