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