mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-08-26 22:19:33 +02:00
Generics are cool
This commit is contained in:
parent
623b7b775c
commit
d32d6b5474
|
@ -1,5 +1,6 @@
|
|||
package me.lucko.luckperms.api;
|
||||
|
||||
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -19,21 +20,21 @@ public interface Datastore {
|
|||
Sync sync();
|
||||
|
||||
interface Async {
|
||||
void loadOrCreateUser(UUID uuid, String username, Callback callback);
|
||||
void loadUser(UUID uuid, Callback callback);
|
||||
void saveUser(User user, Callback callback);
|
||||
void createAndLoadGroup(String name, Callback callback);
|
||||
void loadGroup(String name, Callback callback);
|
||||
void loadAllGroups(Callback callback);
|
||||
void saveGroup(Group group, Callback callback);
|
||||
void deleteGroup(Group group, Callback callback);
|
||||
void createAndLoadTrack(String name, Callback callback);
|
||||
void loadTrack(String name, Callback callback);
|
||||
void loadAllTracks(Callback callback);
|
||||
void saveTrack(Track track, Callback callback);
|
||||
void deleteTrack(Track track, Callback callback);
|
||||
void saveUUIDData(String username, UUID uuid, Callback callback);
|
||||
void getUUID(String username, Callback.GetUUID callback);
|
||||
void loadOrCreateUser(UUID uuid, String username, Callback<Boolean> callback);
|
||||
void loadUser(UUID uuid, Callback<Boolean> callback);
|
||||
void saveUser(User user, Callback<Boolean> callback);
|
||||
void createAndLoadGroup(String name, Callback<Boolean> callback);
|
||||
void loadGroup(String name, Callback<Boolean> callback);
|
||||
void loadAllGroups(Callback<Boolean> callback);
|
||||
void saveGroup(Group group, Callback<Boolean> callback);
|
||||
void deleteGroup(Group group, Callback<Boolean> callback);
|
||||
void createAndLoadTrack(String name, Callback<Boolean> callback);
|
||||
void loadTrack(String name, Callback<Boolean> callback);
|
||||
void loadAllTracks(Callback<Boolean> callback);
|
||||
void saveTrack(Track track, Callback<Boolean> callback);
|
||||
void deleteTrack(Track track, Callback<Boolean> callback);
|
||||
void saveUUIDData(String username, UUID uuid, Callback<Boolean> callback);
|
||||
void getUUID(String username, Callback<UUID> callback);
|
||||
}
|
||||
|
||||
interface Sync {
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package me.lucko.luckperms.api.data;
|
||||
|
||||
import java.util.UUID;
|
||||
public interface Callback<T> {
|
||||
|
||||
public interface Callback {
|
||||
void onComplete(boolean success);
|
||||
void onComplete(T t);
|
||||
|
||||
interface GetUUID {
|
||||
void onComplete(UUID uuid);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,18 +43,10 @@ public class DatastoreLink implements Datastore {
|
|||
return s.toLowerCase();
|
||||
}
|
||||
|
||||
private static Callback checkCallback(Callback c) {
|
||||
private static <T> Callback<T> checkCallback(Callback<T> c) {
|
||||
// If no callback was given, just send an empty one
|
||||
if (c == null) {
|
||||
c = success -> {};
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private static Callback.GetUUID checkCallback(Callback.GetUUID c) {
|
||||
// If no callback was given, just send an empty one
|
||||
if (c == null) {
|
||||
c = success -> {};
|
||||
c = t -> {};
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
@ -84,82 +76,82 @@ public class DatastoreLink implements Datastore {
|
|||
private final me.lucko.luckperms.data.Datastore master;
|
||||
|
||||
@Override
|
||||
public void loadOrCreateUser(@NonNull UUID uuid, @NonNull String username, Callback callback) {
|
||||
public void loadOrCreateUser(@NonNull UUID uuid, @NonNull String username, Callback<Boolean> callback) {
|
||||
master.loadOrCreateUser(uuid, checkUsername(username), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUser(@NonNull UUID uuid, Callback callback) {
|
||||
public void loadUser(@NonNull UUID uuid, Callback<Boolean> callback) {
|
||||
master.loadUser(uuid, checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUser(@NonNull User user, Callback callback) {
|
||||
public void saveUser(@NonNull User user, Callback<Boolean> callback) {
|
||||
Utils.checkUser(user);
|
||||
master.saveUser(((UserLink) user).getMaster(), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAndLoadGroup(@NonNull String name, Callback callback) {
|
||||
public void createAndLoadGroup(@NonNull String name, Callback<Boolean> callback) {
|
||||
master.createAndLoadGroup(checkName(name), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadGroup(@NonNull String name, Callback callback) {
|
||||
public void loadGroup(@NonNull String name, Callback<Boolean> callback) {
|
||||
master.loadGroup(checkName(name), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAllGroups(Callback callback) {
|
||||
public void loadAllGroups(Callback<Boolean> callback) {
|
||||
master.loadAllGroups(checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveGroup(@NonNull Group group, Callback callback) {
|
||||
public void saveGroup(@NonNull Group group, Callback<Boolean> callback) {
|
||||
Utils.checkGroup(group);
|
||||
master.saveGroup(((GroupLink) group).getMaster(), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteGroup(@NonNull Group group, Callback callback) {
|
||||
public void deleteGroup(@NonNull Group group, Callback<Boolean> callback) {
|
||||
Utils.checkGroup(group);
|
||||
master.deleteGroup(((GroupLink) group).getMaster(), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAndLoadTrack(@NonNull String name, Callback callback) {
|
||||
public void createAndLoadTrack(@NonNull String name, Callback<Boolean> callback) {
|
||||
master.createAndLoadTrack(checkName(name), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadTrack(@NonNull String name, Callback callback) {
|
||||
public void loadTrack(@NonNull String name, Callback<Boolean> callback) {
|
||||
master.loadTrack(checkName(name), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAllTracks(Callback callback) {
|
||||
public void loadAllTracks(Callback<Boolean> callback) {
|
||||
master.loadAllTracks(checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveTrack(@NonNull Track track, Callback callback) {
|
||||
public void saveTrack(@NonNull Track track, Callback<Boolean> callback) {
|
||||
Utils.checkTrack(track);
|
||||
master.saveTrack(((TrackLink) track).getMaster(), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTrack(@NonNull Track track, Callback callback) {
|
||||
public void deleteTrack(@NonNull Track track, Callback<Boolean> callback) {
|
||||
Utils.checkTrack(track);
|
||||
master.deleteTrack(((TrackLink) track).getMaster(), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUUIDData(@NonNull String username, @NonNull UUID uuid, Callback callback) {
|
||||
public void saveUUIDData(@NonNull String username, @NonNull UUID uuid, Callback<Boolean> callback) {
|
||||
master.saveUUIDData(checkUsername(username), uuid, checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getUUID(@NonNull String username, Callback.GetUUID callback) {
|
||||
public void getUUID(@NonNull String username, Callback<UUID> callback) {
|
||||
master.getUUID(checkUsername(username), checkCallback(callback));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,12 +39,8 @@ public abstract class Datastore {
|
|||
plugin.doSync(r);
|
||||
}
|
||||
|
||||
private void runCallback(boolean result, Callback callback) {
|
||||
doSync(() -> callback.onComplete(result));
|
||||
}
|
||||
|
||||
private void runCallback(UUID result, Callback.GetUUID callback) {
|
||||
doSync(() -> callback.onComplete(result));
|
||||
private <T> void runCallback(T t, Callback<T> callback) {
|
||||
doSync(() -> callback.onComplete(t));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -74,63 +70,63 @@ public abstract class Datastore {
|
|||
These methods will schedule the operation to run async. The callback will be ran when the task is complete.
|
||||
Callbacks are ran on the main Bukkit server thread (if applicable)
|
||||
*/
|
||||
public void loadOrCreateUser(UUID uuid, String username, Callback callback) {
|
||||
public void loadOrCreateUser(UUID uuid, String username, Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(loadOrCreateUser(uuid, username), callback));
|
||||
}
|
||||
|
||||
public void loadUser(UUID uuid, Callback callback) {
|
||||
public void loadUser(UUID uuid, Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(loadUser(uuid), callback));
|
||||
}
|
||||
|
||||
public void saveUser(User user, Callback callback) {
|
||||
public void saveUser(User user, Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(saveUser(user), callback));
|
||||
}
|
||||
|
||||
public void createAndLoadGroup(String name, Callback callback) {
|
||||
public void createAndLoadGroup(String name, Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(createAndLoadGroup(name), callback));
|
||||
}
|
||||
|
||||
public void loadGroup(String name, Callback callback) {
|
||||
public void loadGroup(String name, Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(loadGroup(name), callback));
|
||||
}
|
||||
|
||||
public void loadAllGroups(Callback callback) {
|
||||
public void loadAllGroups(Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(loadAllGroups(), callback));
|
||||
}
|
||||
|
||||
public void saveGroup(Group group, Callback callback) {
|
||||
public void saveGroup(Group group, Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(saveGroup(group), callback));
|
||||
}
|
||||
|
||||
public void deleteGroup(Group group, Callback callback) {
|
||||
public void deleteGroup(Group group, Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(deleteGroup(group), callback));
|
||||
}
|
||||
|
||||
public void createAndLoadTrack(String name, Callback callback) {
|
||||
public void createAndLoadTrack(String name, Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(createAndLoadTrack(name), callback));
|
||||
}
|
||||
|
||||
public void loadTrack(String name, Callback callback) {
|
||||
public void loadTrack(String name, Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(loadTrack(name), callback));
|
||||
}
|
||||
|
||||
public void loadAllTracks(Callback callback) {
|
||||
public void loadAllTracks(Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(loadAllTracks(), callback));
|
||||
}
|
||||
|
||||
public void saveTrack(Track track, Callback callback) {
|
||||
public void saveTrack(Track track, Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(saveTrack(track), callback));
|
||||
}
|
||||
|
||||
public void deleteTrack(Track track, Callback callback) {
|
||||
public void deleteTrack(Track track, Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(deleteTrack(track), callback));
|
||||
}
|
||||
|
||||
public void saveUUIDData(String username, UUID uuid, Callback callback) {
|
||||
public void saveUUIDData(String username, UUID uuid, Callback<Boolean> callback) {
|
||||
doAsync(() -> runCallback(saveUUIDData(username, uuid), callback));
|
||||
}
|
||||
|
||||
public void getUUID(String username, Callback.GetUUID callback) {
|
||||
public void getUUID(String username, Callback<UUID> callback) {
|
||||
doAsync(() -> runCallback(getUUID(username), callback));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user