1
0
mirror of https://github.com/lucko/LuckPerms.git synced 2025-09-01 18:32:33 +02:00

Add logging, prepare for import/export system

This commit is contained in:
Luck
2016-08-15 01:51:36 +02:00
parent fbf062933f
commit e216c235ce
139 changed files with 4240 additions and 1439 deletions

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>2.2</version>
<version>2.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -40,8 +40,11 @@ public interface Datastore {
Async async();
Sync sync();
Future future();
interface Async {
void logAction(LogEntry entry, Callback<Boolean> callback);
void getLog(Callback<Log> callback);
void loadOrCreateUser(UUID uuid, String username, Callback<Boolean> callback);
void loadUser(UUID uuid, Callback<Boolean> callback);
void saveUser(User user, Callback<Boolean> callback);
@@ -60,6 +63,8 @@ public interface Datastore {
}
interface Sync {
boolean logAction(LogEntry entry);
Log getLog();
boolean loadOrCreateUser(UUID uuid, String username);
boolean loadUser(UUID uuid);
boolean saveUser(User user);
@@ -76,4 +81,24 @@ public interface Datastore {
boolean saveUUIDData(String username, UUID uuid);
UUID getUUID(String username);
}
interface Future {
java.util.concurrent.Future<Boolean> logAction(LogEntry entry);
java.util.concurrent.Future<Log> getLog();
java.util.concurrent.Future<Boolean> loadOrCreateUser(UUID uuid, String username);
java.util.concurrent.Future<Boolean> loadUser(UUID uuid);
java.util.concurrent.Future<Boolean> saveUser(User user);
java.util.concurrent.Future<Boolean> createAndLoadGroup(String name);
java.util.concurrent.Future<Boolean> loadGroup(String name);
java.util.concurrent.Future<Boolean> loadAllGroups();
java.util.concurrent.Future<Boolean> saveGroup(Group group);
java.util.concurrent.Future<Boolean> deleteGroup(Group group);
java.util.concurrent.Future<Boolean> createAndLoadTrack(String name);
java.util.concurrent.Future<Boolean> loadTrack(String name);
java.util.concurrent.Future<Boolean> loadAllTracks();
java.util.concurrent.Future<Boolean> saveTrack(Track track);
java.util.concurrent.Future<Boolean> deleteTrack(Track track);
java.util.concurrent.Future<Boolean> saveUUIDData(String username, UUID uuid);
java.util.concurrent.Future<UUID> getUUID(String username);
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.api;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.UUID;
/**
* Represents the internal LuckPerms log.
* All content is immutable. You can add to the log using the {@link Datastore}, and then request an updated copy.
*/
@SuppressWarnings("unused")
public interface Log {
/**
* @return a {@link SortedSet} of all of the {@link LogEntry} objects in this {@link Log}
*/
SortedSet<LogEntry> getContent();
SortedSet<LogEntry> getRecent();
SortedMap<Integer, LogEntry> getRecent(int pageNo);
int getRecentMaxPages();
SortedSet<LogEntry> getRecent(UUID actor);
SortedMap<Integer, LogEntry> getRecent(int pageNo, UUID actor);
int getRecentMaxPages(UUID actor);
SortedSet<LogEntry> getUserHistory(UUID uuid);
SortedMap<Integer, LogEntry> getUserHistory(int pageNo, UUID uuid);
int getUserHistoryMaxPages(UUID uuid);
SortedSet<LogEntry> getGroupHistory(String name);
SortedMap<Integer, LogEntry> getGroupHistory(int pageNo, String name);
int getGroupHistoryMaxPages(String name);
SortedSet<LogEntry> getTrackHistory(String name);
SortedMap<Integer, LogEntry> getTrackHistory(int pageNo, String name);
int getTrackHistoryMaxPages(String name);
SortedSet<LogEntry> getSearch(String query);
SortedMap<Integer, LogEntry> getSearch(int pageNo, String query);
int getSearchMaxPages(String query);
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.api;
import lombok.*;
import java.util.UUID;
@Getter
@Builder
@ToString
@EqualsAndHashCode
@AllArgsConstructor
public final class LogEntry implements Comparable<LogEntry> {
private static final String FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s";
@NonNull private final long timestamp;
@NonNull private final UUID actor;
@NonNull private final String actorName;
@NonNull private final char type;
private final UUID acted;
@NonNull private final String actedName;
@NonNull private final String action;
@Override
public int compareTo(LogEntry o) {
return Long.compare(timestamp, o.getTimestamp());
}
public boolean matchesSearch(String query) {
query = query.toLowerCase();
return actorName.toLowerCase().contains(query) || actedName.toLowerCase().contains(query)
|| action.toLowerCase().contains(query);
}
public String getFormatted() {
return String.format(FORMAT,
getActorName(),
Character.toString(getType()),
getActedName(),
getAction()
);
}
}

View File

@@ -23,6 +23,7 @@
package me.lucko.luckperms.api;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
/**
@@ -82,7 +83,7 @@ public interface LuckPermsApi {
/**
* Gets a wrapped user object from the user storage
* @param name the username of the user to get
* @return a a {@link User} object, if one matching the uuid is loaded, or null if not
* @return a {@link User} object, if one matching the uuid is loaded, or null if not
*/
User getUser(String name);
@@ -93,6 +94,12 @@ public interface LuckPermsApi {
*/
Optional<User> getUserSafe(String name);
/**
* Gets a set of all loaded users.
* @return a {@link Set} of {@link User} objects
*/
Set<User> getUsers();
/**
* Check if a user is loaded in memory
* @param uuid the uuid to check for
@@ -114,6 +121,12 @@ public interface LuckPermsApi {
*/
Optional<Group> getGroupSafe(String name);
/**
* Gets a set of all loaded groups.
* @return a {@link Set} of {@link Group} objects
*/
Set<Group> getGroups();
/**
* Check if a group is loaded in memory
* @param name the name to check for
@@ -135,6 +148,12 @@ public interface LuckPermsApi {
*/
Optional<Track> getTrackSafe(String name);
/**
* Gets a set of all loaded tracks.
* @return a {@link Set} of {@link Track} objects
*/
Set<Track> getTracks();
/**
* Check if a track is loaded in memory
* @param name the name to check for

View File

@@ -22,8 +22,24 @@
package me.lucko.luckperms.api.data;
import lombok.NonNull;
import java.util.function.Consumer;
public interface Callback<T> {
void onComplete(T t);
static <T> Callback<T> empty() {
return t -> {};
}
static <T> Callback<T> of(@NonNull Runnable runnable) {
return t -> runnable.run();
}
static <T> Callback<T> of(@NonNull Consumer<T> consumer) {
return consumer::accept;
}
}