Update formatting
This commit is contained in:
1 parent
0c6b5e6245
commit
3705eafbc3
3 files changed
+596
-596
No files matched your search
@@ -28,549 +28,549 @@ import com.github.jasync.sql.db.Connection;
|
||||
// TODO: Add in-game integration testing.
|
||||
public class FastOfflinePlayer implements OfflinePlayer {
|
||||
|
||||
// Container for player UUID (always available).
|
||||
private final UUID uuid;
|
||||
// Container for player username (requires lookup).
|
||||
private String cachedName;
|
||||
// Container for safe concurrent updates to async futures.
|
||||
private final AtomicReference<CompletableFuture<String>> lookup = new AtomicReference<>();
|
||||
// Fake Postgres connection without using UtilitiesOG.java.
|
||||
private static volatile Supplier<Connection> connectionSupplier;
|
||||
// Container for player UUID (always available).
|
||||
private final UUID uuid;
|
||||
// Container for player username (requires lookup).
|
||||
private String cachedName;
|
||||
// Container for safe concurrent updates to async futures.
|
||||
private final AtomicReference<CompletableFuture<String>> lookup = new AtomicReference<>();
|
||||
// Fake Postgres connection without using UtilitiesOG.java.
|
||||
private static volatile Supplier<Connection> connectionSupplier;
|
||||
|
||||
// Test-only supplier hook.
|
||||
static void overrideConnectionSupplierForTests(Supplier<Connection> supplier) {
|
||||
// Test-only supplier hook.
|
||||
static void overrideConnectionSupplierForTests(Supplier<Connection> supplier) {
|
||||
|
||||
// Enable the test supplier.
|
||||
connectionSupplier = supplier;
|
||||
// Enable the test supplier.
|
||||
connectionSupplier = supplier;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Supply a connection to jasync Postgres.
|
||||
private Connection connection() {
|
||||
// Supply a connection to jasync Postgres.
|
||||
private Connection connection() {
|
||||
|
||||
// If a test supplier is available, do this...
|
||||
final Supplier<Connection> s = connectionSupplier;
|
||||
if (s != null) {
|
||||
// If a test supplier is available, do this...
|
||||
final Supplier<Connection> s = connectionSupplier;
|
||||
if (s != null) {
|
||||
|
||||
// Return the test supplier.
|
||||
return s.get();
|
||||
// Return the test supplier.
|
||||
return s.get();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Return the real provider.
|
||||
return UtilitiesOG.getPostgres();
|
||||
// Return the real provider.
|
||||
return UtilitiesOG.getPostgres();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Runs after each individual unit test.
|
||||
static void resetConnectionSupplierForTests() {
|
||||
// Runs after each individual unit test.
|
||||
static void resetConnectionSupplierForTests() {
|
||||
|
||||
// Reset the jasync Postgres connection supplier.
|
||||
connectionSupplier = null;
|
||||
// Reset the jasync Postgres connection supplier.
|
||||
connectionSupplier = null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Class constructor.
|
||||
public FastOfflinePlayer(UUID inputtedUUID) {
|
||||
// Class constructor.
|
||||
public FastOfflinePlayer(UUID inputtedUUID) {
|
||||
|
||||
// Cache the provided UUID.
|
||||
this.uuid = inputtedUUID;
|
||||
// Cache the provided UUID.
|
||||
this.uuid = inputtedUUID;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Internal constructor for deserialization.
|
||||
private FastOfflinePlayer(@NotNull UUID uuid, @Nullable String username) {
|
||||
// Internal constructor for deserialization.
|
||||
private FastOfflinePlayer(@NotNull UUID uuid, @Nullable String username) {
|
||||
|
||||
// Pass the provided UUID.
|
||||
this.uuid = uuid;
|
||||
// Pass the username (will be set to 'usernameLookupError' if not found).
|
||||
this.cachedName = username;
|
||||
// Pass the provided UUID.
|
||||
this.uuid = uuid;
|
||||
// Pass the username (will be set to 'usernameLookupError' if not found).
|
||||
this.cachedName = username;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Fast re-implementation of OfflinePlayer.serialize() from Bukkit API.
|
||||
@Override
|
||||
public @NotNull Map<String, Object> serialize() {
|
||||
// Fast re-implementation of OfflinePlayer.serialize() from Bukkit API.
|
||||
@Override
|
||||
public @NotNull Map<String, Object> serialize() {
|
||||
|
||||
// Construct a map to hold player data.
|
||||
final Map<String, Object> map = new LinkedHashMap<>();
|
||||
// Construct a map to hold player data.
|
||||
final Map<String, Object> map = new LinkedHashMap<>();
|
||||
|
||||
// Add the player data to the map.
|
||||
map.put("name", getName());
|
||||
// Add the player data to the map.
|
||||
map.put("name", getName());
|
||||
|
||||
// Return the combined serialized object.
|
||||
return map;
|
||||
// Return the combined serialized object.
|
||||
return map;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Fast re-implementation of OfflinePlayer.deserialize() from Bukkit API.
|
||||
public static @NotNull FastOfflinePlayer deserialize(@NotNull UUID uuid, @NotNull Map<String, Object> values) {
|
||||
// Fast re-implementation of OfflinePlayer.deserialize() from Bukkit API.
|
||||
public static @NotNull FastOfflinePlayer deserialize(@NotNull UUID uuid, @NotNull Map<String, Object> values) {
|
||||
|
||||
// Extract the player name from the serialized map as a String.
|
||||
final String name = (String) values.get("name");
|
||||
// Extract the player name from the serialized map as a String.
|
||||
final String name = (String) values.get("name");
|
||||
|
||||
// Return the UUID from cache.
|
||||
return new FastOfflinePlayer(uuid, name);
|
||||
// Return the UUID from cache.
|
||||
return new FastOfflinePlayer(uuid, name);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Fast re-implementation of OfflinePlayer.getName() from Bukkit API.
|
||||
@Override
|
||||
public @Nullable String getName() {
|
||||
// Fast re-implementation of OfflinePlayer.getName() from Bukkit API.
|
||||
@Override
|
||||
public @Nullable String getName() {
|
||||
|
||||
// If the name is already in the cache, do this...
|
||||
if (cachedName != null) {
|
||||
// If the name is already in the cache, do this...
|
||||
if (cachedName != null) {
|
||||
|
||||
// Return the name from cache instead of querying the database.
|
||||
return cachedName;
|
||||
// Return the name from cache instead of querying the database.
|
||||
return cachedName;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Get existing lookup future if present.
|
||||
CompletableFuture<String> future = lookup.get();
|
||||
// Get existing lookup future if present.
|
||||
CompletableFuture<String> future = lookup.get();
|
||||
|
||||
// If there is no existing lookup future, do this...
|
||||
if (future == null) {
|
||||
// If there is no existing lookup future, do this...
|
||||
if (future == null) {
|
||||
|
||||
// Create new jasync Postgres query for username.
|
||||
CompletableFuture<String> created = connection()
|
||||
.sendPreparedStatement("SELECT username FROM offline_players WHERE uuid = $1 LIMIT 1;",
|
||||
Collections.singletonList(uuid))
|
||||
// On success, cache and return username.
|
||||
.thenApply(res ->
|
||||
{
|
||||
// Create new jasync Postgres query for username.
|
||||
CompletableFuture<String> created = connection()
|
||||
.sendPreparedStatement("SELECT username FROM offline_players WHERE uuid = $1 LIMIT 1;",
|
||||
Collections.singletonList(uuid))
|
||||
// On success, cache and return username.
|
||||
.thenApply(res ->
|
||||
{
|
||||
|
||||
// If the query returned rows, do this...
|
||||
if (!res.getRows().isEmpty()) {
|
||||
// If the query returned rows, do this...
|
||||
if (!res.getRows().isEmpty()) {
|
||||
|
||||
// Extract the "username" value from the first row.
|
||||
final String name = res.getRows().get(0).getString("username");
|
||||
// Extract the "username" value from the first row.
|
||||
final String name = res.getRows().get(0).getString("username");
|
||||
|
||||
// Store the retrieved username in the cache.
|
||||
cachedName = name;
|
||||
// Store the retrieved username in the cache.
|
||||
cachedName = name;
|
||||
|
||||
// Return the retrieved username.
|
||||
return name;
|
||||
// Return the retrieved username.
|
||||
return name;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// If no rows are found, return null.
|
||||
return null;
|
||||
// If no rows are found, return null.
|
||||
return null;
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
// If there was an error with finding the name, do this...
|
||||
.exceptionally(ex ->
|
||||
{
|
||||
// If there was an error with finding the name, do this...
|
||||
.exceptionally(ex ->
|
||||
{
|
||||
|
||||
// Set a placeholder name to avoid a crash.
|
||||
cachedName = "usernameLookupError";
|
||||
// Set a placeholder name to avoid a crash.
|
||||
cachedName = "usernameLookupError";
|
||||
|
||||
UtilitiesOG.logToConsole(InternalFunctions.getPrefix(),
|
||||
"ERROR: FastOfflinePlayer getName() failed!" + ex.getMessage());
|
||||
UtilitiesOG.logToConsole(InternalFunctions.getPrefix(),
|
||||
"ERROR: FastOfflinePlayer getName() failed!" + ex.getMessage());
|
||||
|
||||
// Return the placeholder name.
|
||||
return cachedName;
|
||||
// Return the placeholder name.
|
||||
return cachedName;
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// Attempt to set the lookup future only if it is currently null.
|
||||
if (!lookup.compareAndSet(null, created)) {
|
||||
// Attempt to set the lookup future only if it is currently null.
|
||||
if (!lookup.compareAndSet(null, created)) {
|
||||
|
||||
// If another thread already set the future, use the existing one instead.
|
||||
created = lookup.get();
|
||||
// If another thread already set the future, use the existing one instead.
|
||||
created = lookup.get();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Store created future.
|
||||
future = created;
|
||||
// Store created future.
|
||||
future = created;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Return cached name (may still be null until async query completes).
|
||||
return cachedName;
|
||||
// Return cached name (may still be null until async query completes).
|
||||
return cachedName;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Non-cached version of getName() for testing
|
||||
public @NotNull CompletableFuture<@Nullable String> getNameAsync() {
|
||||
// Non-cached version of getName() for testing
|
||||
public @NotNull CompletableFuture<@Nullable String> getNameAsync() {
|
||||
|
||||
// If cached name exists, return it as completed future
|
||||
if (cachedName != null) {
|
||||
// If cached name exists, return it as completed future
|
||||
if (cachedName != null) {
|
||||
|
||||
return CompletableFuture.completedFuture(cachedName);
|
||||
return CompletableFuture.completedFuture(cachedName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure lookup starts by calling getName()
|
||||
getName();
|
||||
// Ensure lookup starts by calling getName()
|
||||
getName();
|
||||
|
||||
// Return lookup future
|
||||
return lookup.get();
|
||||
// Return lookup future
|
||||
return lookup.get();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Fast re-implementation OfflinePlayer.getUniqueId() from Bukkit API.
|
||||
@Override
|
||||
public @NotNull UUID getUniqueId() {
|
||||
// Fast re-implementation OfflinePlayer.getUniqueId() from Bukkit API.
|
||||
@Override
|
||||
public @NotNull UUID getUniqueId() {
|
||||
|
||||
// Pass on UUID from constructor.
|
||||
return uuid;
|
||||
// Pass on UUID from constructor.
|
||||
return uuid;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PlayerProfile getPlayerProfile() {
|
||||
@Override
|
||||
public @NotNull PlayerProfile getPlayerProfile() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBanned() {
|
||||
@Override
|
||||
public boolean isBanned() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWhitelisted() {
|
||||
@Override
|
||||
public boolean isWhitelisted() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhitelisted(boolean value) {
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void setWhitelisted(boolean value) {
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Player getPlayer() {
|
||||
@Override
|
||||
public @Nullable Player getPlayer() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFirstPlayed() {
|
||||
@Override
|
||||
public long getFirstPlayed() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated The getLastPlayed API contract is ambiguous and the
|
||||
* implementation may or may not return the correct value. Use
|
||||
* {@link #getLastSeen()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public long getLastPlayed() {
|
||||
/**
|
||||
* @deprecated The getLastPlayed API contract is ambiguous and the
|
||||
* implementation may or may not return the correct value. Use
|
||||
* {@link #getLastSeen()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public long getLastPlayed() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return getLastSeen();
|
||||
// TODO Auto-generated method stub.
|
||||
return getLastSeen();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlayedBefore() {
|
||||
@Override
|
||||
public boolean hasPlayedBefore() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Location getBedSpawnLocation() {
|
||||
@Override
|
||||
public @Nullable Location getBedSpawnLocation() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastLogin() {
|
||||
@Override
|
||||
public long getLastLogin() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastSeen() {
|
||||
@Override
|
||||
public long getLastSeen() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void incrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void decrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(@NotNull Statistic statistic, int amount) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void incrementStatistic(@NotNull Statistic statistic, int amount) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(@NotNull Statistic statistic, int amount) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void decrementStatistic(@NotNull Statistic statistic, int amount) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatistic(@NotNull Statistic statistic, int newValue) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void setStatistic(@NotNull Statistic statistic, int newValue) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatistic(@NotNull Statistic statistic) throws IllegalArgumentException {
|
||||
@Override
|
||||
public int getStatistic(@NotNull Statistic statistic) throws IllegalArgumentException {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException {
|
||||
@Override
|
||||
public int getStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int amount)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int amount)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int amount)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int amount)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatistic(@NotNull Statistic statistic, @NotNull Material material, int newValue)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void setStatistic(@NotNull Statistic statistic, @NotNull Material material, int newValue)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
@Override
|
||||
public int getStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int amount)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int amount)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int amount) {
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int amount) {
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int newValue) {
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void setStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int newValue) {
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Location getLastDeathLocation() {
|
||||
@Override
|
||||
public @Nullable Location getLastDeathLocation() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAllowFlight() {
|
||||
@Override
|
||||
public boolean getAllowFlight() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllowFlight(boolean flight) {
|
||||
@Override
|
||||
public void setAllowFlight(boolean flight) {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlying() {
|
||||
@Override
|
||||
public boolean isFlying() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlying(boolean value) {
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void setFlying(boolean value) {
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlySpeed(float value) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void setFlySpeed(float value) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWalkSpeed(float value) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
@Override
|
||||
public void setWalkSpeed(float value) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFlySpeed() {
|
||||
@Override
|
||||
public float getFlySpeed() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWalkSpeed() {
|
||||
@Override
|
||||
public float getWalkSpeed() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
// TODO Auto-generated method stub.
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Location getLocation() {
|
||||
@Override
|
||||
public @Nullable Location getLocation() {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleportOffline(@NotNull Location destination) {
|
||||
@Override
|
||||
public boolean teleportOffline(@NotNull Location destination) {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleportOffline(@NotNull Location destination, @NotNull TeleportCause cause) {
|
||||
@Override
|
||||
public boolean teleportOffline(@NotNull Location destination, @NotNull TeleportCause cause) {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
// TODO Auto-generated method stub.
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<Boolean> teleportOfflineAsync(@NotNull Location destination) {
|
||||
@Override
|
||||
public @NotNull CompletableFuture<Boolean> teleportOfflineAsync(@NotNull Location destination) {
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<Boolean> teleportOfflineAsync(@NotNull Location destination,
|
||||
@NotNull TeleportCause cause)
|
||||
{
|
||||
@Override
|
||||
public @NotNull CompletableFuture<Boolean> teleportOfflineAsync(@NotNull Location destination,
|
||||
@NotNull TeleportCause cause)
|
||||
{
|
||||
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
// TODO Auto-generated method stub.
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,401 +50,401 @@ import net.trueog.utilitiesog.utils.TextUtils;
|
||||
// Declare main plugin class.
|
||||
public final class UtilitiesOG extends JavaPlugin {
|
||||
|
||||
private File file;
|
||||
private static Plugin instance;
|
||||
private static FileConfiguration config;
|
||||
private static File phantomPreferencesFile;
|
||||
private static YamlConfiguration phantomPreferences;
|
||||
private static StateFlag FlippyFlag;
|
||||
private static ConnectionPool<PostgreSQLConnection> POOL;
|
||||
private File file;
|
||||
private static Plugin instance;
|
||||
private static FileConfiguration config;
|
||||
private static File phantomPreferencesFile;
|
||||
private static YamlConfiguration phantomPreferences;
|
||||
private static StateFlag FlippyFlag;
|
||||
private static ConnectionPool<PostgreSQLConnection> POOL;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
instance = this;
|
||||
instance = this;
|
||||
|
||||
this.file = new File(this.getDataFolder(), "config.yml");
|
||||
if (!this.file.exists()) {
|
||||
this.file = new File(this.getDataFolder(), "config.yml");
|
||||
if (!this.file.exists()) {
|
||||
|
||||
this.saveDefaultConfig();
|
||||
this.saveDefaultConfig();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
config = this.getConfig();
|
||||
config = this.getConfig();
|
||||
|
||||
POOL = initPsql();
|
||||
POOL = initPsql();
|
||||
|
||||
phantomPreferencesFile = new File(this.getDataFolder(), "phantomDisabledUsers.yml");
|
||||
phantomPreferencesFile = new File(this.getDataFolder(), "phantomDisabledUsers.yml");
|
||||
|
||||
try {
|
||||
try {
|
||||
|
||||
if (!phantomPreferencesFile.exists()) {
|
||||
if (!phantomPreferencesFile.exists()) {
|
||||
|
||||
phantomPreferencesFile.createNewFile();
|
||||
phantomPreferencesFile.createNewFile();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException error) {
|
||||
} catch (IOException error) {
|
||||
|
||||
this.getLogger().severe("ERROR: Failed to create the phantom toggle cache file! " + error.getMessage());
|
||||
this.getLogger().severe("ERROR: Failed to create the phantom toggle cache file! " + error.getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
phantomPreferences = YamlConfiguration.loadConfiguration(phantomPreferencesFile);
|
||||
phantomPreferences = YamlConfiguration.loadConfiguration(phantomPreferencesFile);
|
||||
|
||||
if (this.getConfig().getBoolean("ChainArmor")) {
|
||||
if (this.getConfig().getBoolean("ChainArmor")) {
|
||||
|
||||
ChainArmorModule.Enable();
|
||||
ChainArmorModule.Enable();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("ColorCodes")) {
|
||||
if (this.getConfig().getBoolean("ColorCodes")) {
|
||||
|
||||
this.getCommand("colorcodes").setExecutor(new ColorCodesCommand());
|
||||
this.getCommand("colorcodes").setExecutor(new ColorCodesCommand());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("DisableEntityCramming")) {
|
||||
if (this.getConfig().getBoolean("DisableEntityCramming")) {
|
||||
|
||||
getServer().getPluginManager().registerEvents(new DisableEntityCrammingListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new DisableEntityCrammingListener(), this);
|
||||
|
||||
this.getCommand("togglecramming").setExecutor(new ToggleCrammingCommand());
|
||||
this.getCommand("togglecramming").setExecutor(new ToggleCrammingCommand());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("MiniPlaceholders")) {
|
||||
if (this.getConfig().getBoolean("MiniPlaceholders")) {
|
||||
|
||||
// Registering a global MiniPlaceholder.
|
||||
registerGlobalPlaceholder("servers_name", () -> "&aTrue&cOG &eNetwork");
|
||||
// Registering a global MiniPlaceholder.
|
||||
registerGlobalPlaceholder("servers_name", () -> "&aTrue&cOG &eNetwork");
|
||||
|
||||
// Registering an Audience MiniPlaceholder.
|
||||
registerAudiencePlaceholder("player_display_name", (Player player) -> {
|
||||
// Registering an Audience MiniPlaceholder.
|
||||
registerAudiencePlaceholder("player_display_name", (Player player) -> {
|
||||
|
||||
final LuckPerms luckPerms = LuckPermsProvider.get();
|
||||
final User user = luckPerms.getUserManager().getUser(player.getUniqueId());
|
||||
if (user == null) {
|
||||
final LuckPerms luckPerms = LuckPermsProvider.get();
|
||||
final User user = luckPerms.getUserManager().getUser(player.getUniqueId());
|
||||
if (user == null) {
|
||||
|
||||
getLogger().info("ERROR: MiniPlaceholder processing error. Player: " + player.getName()
|
||||
+ " has no User object in LuckPerms!");
|
||||
getLogger().info("ERROR: MiniPlaceholder processing error. Player: " + player.getName()
|
||||
+ " has no User object in LuckPerms!");
|
||||
|
||||
return player.getName();
|
||||
return player.getName();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
final String primaryGroup = user.getPrimaryGroup();
|
||||
final Group group = luckPerms.getGroupManager().getGroup(primaryGroup);
|
||||
if (group == null) {
|
||||
final String primaryGroup = user.getPrimaryGroup();
|
||||
final Group group = luckPerms.getGroupManager().getGroup(primaryGroup);
|
||||
if (group == null) {
|
||||
|
||||
getLogger().info("ERROR: MiniPlaceholder processing error. User: " + player.getName()
|
||||
+ " has no Group assignment in LuckPerms!");
|
||||
getLogger().info("ERROR: MiniPlaceholder processing error. User: " + player.getName()
|
||||
+ " has no Group assignment in LuckPerms!");
|
||||
|
||||
return player.getName();
|
||||
return player.getName();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
String prefix = null;
|
||||
for (Node node : group.getNodes()) {
|
||||
String prefix = null;
|
||||
for (Node node : group.getNodes()) {
|
||||
|
||||
if (node instanceof PrefixNode) {
|
||||
if (node instanceof PrefixNode) {
|
||||
|
||||
prefix = ((PrefixNode) node).getMetaValue();
|
||||
prefix = ((PrefixNode) node).getMetaValue();
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix == null) {
|
||||
if (prefix == null) {
|
||||
|
||||
return player.getName();
|
||||
return player.getName();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
final String colorCode = prefix.replaceAll(".*\\](.*)", "$1");
|
||||
final String colorCode = prefix.replaceAll(".*\\](.*)", "$1");
|
||||
|
||||
return "<luckperms_prefix>" + colorCode + " " + player.getName();
|
||||
return "<luckperms_prefix>" + colorCode + " " + player.getName();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("MockBamboo")) {
|
||||
if (this.getConfig().getBoolean("MockBamboo")) {
|
||||
|
||||
MockBambooModule.Enable();
|
||||
MockBambooModule.Enable();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("NoFlippy")) {
|
||||
if (this.getConfig().getBoolean("NoFlippy")) {
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
|
||||
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
|
||||
|
||||
getServer().getPluginManager().registerEvents(new NoFlippyListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new NoFlippyListener(), this);
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
this.getLogger().severe("WorldGuard is not installed! Disabling NoFlippy...");
|
||||
this.getLogger().severe("WorldGuard is not installed! Disabling NoFlippy...");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("Ping")) {
|
||||
if (this.getConfig().getBoolean("Ping")) {
|
||||
|
||||
this.getCommand("ping").setExecutor(new PingCommand());
|
||||
this.getCommand("bing").setExecutor(new BingCommand());
|
||||
this.getCommand("ping").setExecutor(new PingCommand());
|
||||
this.getCommand("bing").setExecutor(new BingCommand());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("RanksMenu")) {
|
||||
if (this.getConfig().getBoolean("RanksMenu")) {
|
||||
|
||||
this.getCommand("ranks").setExecutor(new RanksCommand());
|
||||
this.getCommand("ranks").setExecutor(new RanksCommand());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("TogglePhantoms")) {
|
||||
if (this.getConfig().getBoolean("TogglePhantoms")) {
|
||||
|
||||
getServer().getPluginManager().registerEvents(new TogglePhantomsListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new TogglePhantomsListener(), this);
|
||||
|
||||
this.getCommand("togglephantoms").setExecutor(new TogglePhantomsCommand());
|
||||
this.getCommand("togglephantoms").setExecutor(new TogglePhantomsCommand());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("AdvancementsOnlyInSurvival")) {
|
||||
if (this.getConfig().getBoolean("AdvancementsOnlyInSurvival")) {
|
||||
|
||||
getServer().getPluginManager().registerEvents(new AdvancementsOnlyInSurvivalListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new AdvancementsOnlyInSurvivalListener(), this);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
this.getCommand("utilities").setExecutor(new AboutCommand());
|
||||
this.getCommand("utilities").setExecutor(new AboutCommand());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
@Override
|
||||
public void onLoad() {
|
||||
|
||||
try {
|
||||
try {
|
||||
|
||||
FlippyFlag = NoFlippyListener.registerNoFlippyWorldGuardFlag(FlippyFlag);
|
||||
FlippyFlag = NoFlippyListener.registerNoFlippyWorldGuardFlag(FlippyFlag);
|
||||
|
||||
} catch (FlagRegistrationException error) {
|
||||
} catch (FlagRegistrationException error) {
|
||||
|
||||
this.getLogger()
|
||||
.severe("ERROR: Failed to register the can-flippy Flag with WorldGuard. " + error.getMessage());
|
||||
this.getLogger()
|
||||
.severe("ERROR: Failed to register the can-flippy Flag with WorldGuard. " + error.getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
PlaceholderUtils.unregisterAll();
|
||||
PlaceholderUtils.unregisterAll();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static FileConfiguration config() {
|
||||
static FileConfiguration config() {
|
||||
|
||||
return config;
|
||||
return config;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static String prefix() {
|
||||
static String prefix() {
|
||||
|
||||
return "&7[&6Utilities&f-&4OG&7] ";
|
||||
return "&7[&6Utilities&f-&4OG&7] ";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static StateFlag flippyFlag() {
|
||||
static StateFlag flippyFlag() {
|
||||
|
||||
return FlippyFlag;
|
||||
return FlippyFlag;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static File phantomDisabledPlayersFile() {
|
||||
static File phantomDisabledPlayersFile() {
|
||||
|
||||
return phantomPreferencesFile;
|
||||
return phantomPreferencesFile;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static YamlConfiguration phantomPreferences() {
|
||||
static YamlConfiguration phantomPreferences() {
|
||||
|
||||
return phantomPreferences;
|
||||
return phantomPreferences;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static Plugin plugin() {
|
||||
static Plugin plugin() {
|
||||
|
||||
return instance;
|
||||
return instance;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Unified method for sending a message to a player with placeholders processed.
|
||||
public static void trueogMessage(Player player, String message) {
|
||||
// Unified method for sending a message to a player with placeholders processed.
|
||||
public static void trueogMessage(Player player, String message) {
|
||||
|
||||
TextUtils.trueogMessage(player, message);
|
||||
TextUtils.trueogMessage(player, message);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Handle messages to offline players (based on UUID).
|
||||
public static void trueogMessage(UUID playerUUID, String message) {
|
||||
// Handle messages to offline players (based on UUID).
|
||||
public static void trueogMessage(UUID playerUUID, String message) {
|
||||
|
||||
final Player player = Bukkit.getPlayer(playerUUID);
|
||||
if (player != null) {
|
||||
final Player player = Bukkit.getPlayer(playerUUID);
|
||||
if (player != null) {
|
||||
|
||||
TextUtils.trueogMessage(player, message);
|
||||
TextUtils.trueogMessage(player, message);
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
logToConsole("[Utilities-OG]", "Player with UUID " + playerUUID + " is not online.");
|
||||
logToConsole("[Utilities-OG]", "Player with UUID " + playerUUID + " is not online.");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Formats a message without MiniPlaceholder expansion.
|
||||
public static TextComponent trueogColorize(String message) {
|
||||
// Formats a message without MiniPlaceholder expansion.
|
||||
public static TextComponent trueogColorize(String message) {
|
||||
|
||||
return (TextComponent) MiniMessage.miniMessage().deserialize(TextUtils.processColorCodes(message));
|
||||
return (TextComponent) MiniMessage.miniMessage().deserialize(TextUtils.processColorCodes(message));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Expands Global MiniPlaceholders.
|
||||
public static TextComponent trueogExpand(String message) {
|
||||
// Expands Global MiniPlaceholders.
|
||||
public static TextComponent trueogExpand(String message) {
|
||||
|
||||
// MiniPlaceholder expansion with legacy and modern formatting.
|
||||
return TextUtils.expandTextWithPlaceholders(message);
|
||||
// MiniPlaceholder expansion with legacy and modern formatting.
|
||||
return TextUtils.expandTextWithPlaceholders(message);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Expands Audience MiniPlaceholders.
|
||||
public static TextComponent trueogExpand(String message, Player player) {
|
||||
// Expands Audience MiniPlaceholders.
|
||||
public static TextComponent trueogExpand(String message, Player player) {
|
||||
|
||||
// MiniPlaceholder expansion with legacy and modern formatting.
|
||||
return TextUtils.expandTextWithPlaceholders(message, player);
|
||||
// MiniPlaceholder expansion with legacy and modern formatting.
|
||||
return TextUtils.expandTextWithPlaceholders(message, player);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Expands Relational MiniPlaceholders.
|
||||
public static TextComponent trueogExpand(String message, Player player, Player target) {
|
||||
// Expands Relational MiniPlaceholders.
|
||||
public static TextComponent trueogExpand(String message, Player player, Player target) {
|
||||
|
||||
// MiniPlaceholder expansion with legacy and modern formatting.
|
||||
return TextUtils.expandTextWithPlaceholders(message, player, target);
|
||||
// MiniPlaceholder expansion with legacy and modern formatting.
|
||||
return TextUtils.expandTextWithPlaceholders(message, player, target);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Variation of MiniPlaceholder expansion for when Bukkit API is unavailable.
|
||||
public static TextComponent trueogExpand(String message, UUID playerUUID) {
|
||||
// Variation of MiniPlaceholder expansion for when Bukkit API is unavailable.
|
||||
public static TextComponent trueogExpand(String message, UUID playerUUID) {
|
||||
|
||||
final Player player = Bukkit.getPlayer(playerUUID);
|
||||
if (player != null) {
|
||||
final Player player = Bukkit.getPlayer(playerUUID);
|
||||
if (player != null) {
|
||||
|
||||
return TextUtils.expandTextWithPlaceholders(message, player);
|
||||
return TextUtils.expandTextWithPlaceholders(message, player);
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
logToConsole("[Utilities-OG]", "Player with UUID " + playerUUID + " is not online.");
|
||||
logToConsole("[Utilities-OG]", "Player with UUID " + playerUUID + " is not online.");
|
||||
|
||||
return TextUtils.expandTextWithPlaceholders(message);
|
||||
return TextUtils.expandTextWithPlaceholders(message);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Global placeholder without arguments.
|
||||
public static void registerGlobalPlaceholder(String name, Supplier<String> valueSupplier) {
|
||||
// Global placeholder without arguments.
|
||||
public static void registerGlobalPlaceholder(String name, Supplier<String> valueSupplier) {
|
||||
|
||||
PlaceholderUtils.trueogRegisterMiniPlaceholder(name,
|
||||
placeholder -> placeholder.setGlobalPlaceholder(valueSupplier));
|
||||
PlaceholderUtils.trueogRegisterMiniPlaceholder(name,
|
||||
placeholder -> placeholder.setGlobalPlaceholder(valueSupplier));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Global placeholder with arguments.
|
||||
public static void registerGlobalPlaceholder(String name, Function<List<String>, String> valueFunction) {
|
||||
// Global placeholder with arguments.
|
||||
public static void registerGlobalPlaceholder(String name, Function<List<String>, String> valueFunction) {
|
||||
|
||||
PlaceholderUtils.trueogRegisterMiniPlaceholder(name,
|
||||
placeholder -> placeholder.setGlobalPlaceholder(valueFunction));
|
||||
PlaceholderUtils.trueogRegisterMiniPlaceholder(name,
|
||||
placeholder -> placeholder.setGlobalPlaceholder(valueFunction));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Audience placeholder without arguments.
|
||||
public static void registerAudiencePlaceholder(String name, Function<Player, String> valueFunction) {
|
||||
// Audience placeholder without arguments.
|
||||
public static void registerAudiencePlaceholder(String name, Function<Player, String> valueFunction) {
|
||||
|
||||
PlaceholderUtils.trueogRegisterMiniPlaceholder(name,
|
||||
placeholder -> placeholder.setAudiencePlaceholder(valueFunction));
|
||||
PlaceholderUtils.trueogRegisterMiniPlaceholder(name,
|
||||
placeholder -> placeholder.setAudiencePlaceholder(valueFunction));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Audience placeholder with arguments.
|
||||
public static void registerAudiencePlaceholder(String name,
|
||||
BiFunction<Player, List<String>, String> valueFunction)
|
||||
{
|
||||
// Audience placeholder with arguments.
|
||||
public static void registerAudiencePlaceholder(String name,
|
||||
BiFunction<Player, List<String>, String> valueFunction)
|
||||
{
|
||||
|
||||
PlaceholderUtils.trueogRegisterMiniPlaceholder(name,
|
||||
placeholder -> placeholder.setAudiencePlaceholder(valueFunction));
|
||||
PlaceholderUtils.trueogRegisterMiniPlaceholder(name,
|
||||
placeholder -> placeholder.setAudiencePlaceholder(valueFunction));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Relational placeholder without arguments.
|
||||
public static void registerRelationalPlaceholder(String name, BiFunction<Player, Player, String> valueFunction) {
|
||||
// Relational placeholder without arguments.
|
||||
public static void registerRelationalPlaceholder(String name, BiFunction<Player, Player, String> valueFunction) {
|
||||
|
||||
PlaceholderUtils.trueogRegisterMiniPlaceholder(name,
|
||||
placeholder -> placeholder.setRelationalPlaceholder(valueFunction));
|
||||
PlaceholderUtils.trueogRegisterMiniPlaceholder(name,
|
||||
placeholder -> placeholder.setRelationalPlaceholder(valueFunction));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Relational placeholder with arguments.
|
||||
public static void registerRelationalPlaceholder(String name,
|
||||
TriFunction<Player, Player, List<String>, String> valueFunction)
|
||||
{
|
||||
// Relational placeholder with arguments.
|
||||
public static void registerRelationalPlaceholder(String name,
|
||||
TriFunction<Player, Player, List<String>, String> valueFunction)
|
||||
{
|
||||
|
||||
PlaceholderUtils.trueogRegisterMiniPlaceholder(name,
|
||||
placeholder -> placeholder.setRelationalPlaceholder(valueFunction));
|
||||
PlaceholderUtils.trueogRegisterMiniPlaceholder(name,
|
||||
placeholder -> placeholder.setRelationalPlaceholder(valueFunction));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// API to strip legacy and modern formatting in Strings.
|
||||
public static String stripFormatting(String content) {
|
||||
// API to strip legacy and modern formatting in Strings.
|
||||
public static String stripFormatting(String content) {
|
||||
|
||||
return TextUtils.stripColors(content);
|
||||
return TextUtils.stripColors(content);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Console logging API that automatically strips legacy and modern formatting.
|
||||
public static void logToConsole(String prefix, String message) {
|
||||
// Console logging API that automatically strips legacy and modern formatting.
|
||||
public static void logToConsole(String prefix, String message) {
|
||||
|
||||
Bukkit.getLogger().info(TextUtils.stripColors(prefix + " " + message));
|
||||
Bukkit.getLogger().info(TextUtils.stripColors(prefix + " " + message));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize postgres connection;
|
||||
private ConnectionPool<PostgreSQLConnection> initPsql() {
|
||||
// Initialize postgres connection;
|
||||
private ConnectionPool<PostgreSQLConnection> initPsql() {
|
||||
|
||||
// Reads the values from config.yml;
|
||||
final String baseUrl = getConfig().getString("postgresUrl"); // e.g. jdbc:postgresql://localhost:5432/diamond
|
||||
final String user = getConfig().getString("postgresUser"); // e.g. postgres
|
||||
final String password = getConfig().getString("postgresPassword"); // e.g. postgresPassword
|
||||
// Reads the values from config.yml;
|
||||
final String baseUrl = getConfig().getString("postgresUrl"); // e.g. jdbc:postgresql://localhost:5432/diamond
|
||||
final String user = getConfig().getString("postgresUser"); // e.g. postgres
|
||||
final String password = getConfig().getString("postgresPassword"); // e.g. postgresPassword
|
||||
|
||||
// Appends credentials to the URL (only if they are not already present)
|
||||
final String jdbcUrl = "%s?user=%s&password=%s".formatted(baseUrl, user, password);
|
||||
// Appends credentials to the URL (only if they are not already present)
|
||||
final String jdbcUrl = "%s?user=%s&password=%s".formatted(baseUrl, user, password);
|
||||
|
||||
// Create postgres connection.
|
||||
return PostgreSQLConnectionBuilder.createConnectionPool(jdbcUrl);
|
||||
// Create postgres connection.
|
||||
return PostgreSQLConnectionBuilder.createConnectionPool(jdbcUrl);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static ConnectionPool<PostgreSQLConnection> getPostgres() {
|
||||
public static ConnectionPool<PostgreSQLConnection> getPostgres() {
|
||||
|
||||
return POOL;
|
||||
return POOL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Functional interface to support TriFunction.
|
||||
@FunctionalInterface
|
||||
public interface TriFunction<T, U, V, R> {
|
||||
// Functional interface to support TriFunction.
|
||||
@FunctionalInterface
|
||||
public interface TriFunction<T, U, V, R> {
|
||||
|
||||
R apply(T t, U u, V v);
|
||||
R apply(T t, U u, V v);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+6
-6
@@ -11,15 +11,15 @@ import com.destroystokyo.paper.event.player.PlayerAdvancementCriterionGrantEvent
|
||||
|
||||
public class AdvancementsOnlyInSurvivalListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onAdvancementProgress(PlayerAdvancementCriterionGrantEvent event) {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onAdvancementProgress(PlayerAdvancementCriterionGrantEvent event) {
|
||||
|
||||
if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) {
|
||||
if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) {
|
||||
|
||||
event.setCancelled(true);
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user