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

49 lines
1.5 KiB
Java
Raw Normal View History

2015-07-30 16:25:16 +02:00
package com.plotsquared.sponge.uuid;
import java.util.UUID;
2015-12-19 20:30:06 +01:00
import org.spongepowered.api.profile.GameProfile;
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;
2015-09-13 06:04:31 +02:00
public class SpongeUUIDHandler extends UUIDHandlerImplementation {
public SpongeUUIDHandler(final UUIDWrapper wrapper) {
super(wrapper);
}
2015-09-13 06:04:31 +02:00
@Override
2015-09-13 06:04:31 +02:00
public boolean startCaching(final Runnable whenDone) {
if (!super.startCaching(whenDone)) {
return false;
}
return cache(whenDone);
}
2015-09-13 06:04:31 +02:00
public boolean cache(final Runnable whenDone) {
add(new StringWrapper("*"), DBFunc.everyone);
2015-09-13 06:04:31 +02:00
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) {
add(new StringWrapper(profile.getName()), profile.getUniqueId());
}
return true;
}
2015-09-13 06:04:31 +02:00
@Override
2015-09-13 06:04:31 +02:00
public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
TaskManager.runTaskAsync(new Runnable() {
@Override
2015-09-13 06:04:31 +02:00
public void run() {
ifFetch.value = uuidWrapper.getUUID(name);
TaskManager.runTask(ifFetch);
}
});
}
2015-09-13 06:04:31 +02:00
}