mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2025-06-26 19:44:27 +00:00
Beans
This commit is contained in:
@ -34,7 +34,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Info(name = "cage", description = "Cage a player.",
|
||||
usage = "/cage <player> <on|off> [material]")
|
||||
usage = "/cage <player> <on|off> [material]")
|
||||
@Permissive(perm = "datura.cage")
|
||||
public class CageCommand extends Commander
|
||||
{
|
||||
@ -68,7 +68,7 @@ public class CageCommand extends Commander
|
||||
@Completion(args = {"[material]"}, index = 2)
|
||||
@Subcommand(permission = "datura.cage.custom", args = {Player.class, String.class, Material.class})
|
||||
public void cagePlayer(final CommandSender sender, final Player player, final String string,
|
||||
final Material material)
|
||||
final Material material)
|
||||
{
|
||||
switch (string.toLowerCase())
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Info(name = "locker", description = "Lock a player, preventing them from interacting with their game client.",
|
||||
usage = "/locker <player> <on|off>", aliases = {"lock", "lockup"})
|
||||
usage = "/locker <player> <on|off>", aliases = {"lock", "lockup"})
|
||||
@Permissive(perm = "datura.locker")
|
||||
public final class LockerCommand extends Commander
|
||||
{
|
||||
|
@ -6,33 +6,33 @@ import me.totalfreedom.security.NodeType;
|
||||
public class DefaultNodes
|
||||
{
|
||||
public static final Node OP = new PermissionNodeBuilder()
|
||||
.key("freedom.master_key")
|
||||
.value(true)
|
||||
.type(NodeType.PERMISSION)
|
||||
.negated(false)
|
||||
.wildcard(true)
|
||||
.build();
|
||||
.key("freedom.master_key")
|
||||
.value(true)
|
||||
.type(NodeType.PERMISSION)
|
||||
.negated(false)
|
||||
.wildcard(true)
|
||||
.build();
|
||||
public static final Node NON_OP = new PermissionNodeBuilder()
|
||||
.key("freedom.default")
|
||||
.value(true)
|
||||
.type(NodeType.PERMISSION)
|
||||
.negated(false)
|
||||
.wildcard(false)
|
||||
.build();
|
||||
.key("freedom.default")
|
||||
.value(true)
|
||||
.type(NodeType.PERMISSION)
|
||||
.negated(false)
|
||||
.wildcard(false)
|
||||
.build();
|
||||
public static final Node ALL = new PermissionNodeBuilder()
|
||||
.key("*")
|
||||
.value(true)
|
||||
.type(NodeType.PERMISSION)
|
||||
.negated(false)
|
||||
.wildcard(true)
|
||||
.build();
|
||||
.key("*")
|
||||
.value(true)
|
||||
.type(NodeType.PERMISSION)
|
||||
.negated(false)
|
||||
.wildcard(true)
|
||||
.build();
|
||||
public static final Node NONE = new PermissionNodeBuilder()
|
||||
.key("freedom.none")
|
||||
.value(true)
|
||||
.type(NodeType.PERMISSION)
|
||||
.negated(false)
|
||||
.wildcard(false)
|
||||
.build();
|
||||
.key("freedom.none")
|
||||
.value(true)
|
||||
.type(NodeType.PERMISSION)
|
||||
.negated(false)
|
||||
.wildcard(false)
|
||||
.build();
|
||||
|
||||
private DefaultNodes()
|
||||
{
|
||||
|
@ -28,11 +28,11 @@ public class FreedomGroup implements Group
|
||||
private final PermissionAttachment attachment;
|
||||
|
||||
public FreedomGroup(final Component name,
|
||||
final Component prefix,
|
||||
final Component abbreviation,
|
||||
final int weight,
|
||||
final boolean isDefault,
|
||||
final boolean isHidden)
|
||||
final Component prefix,
|
||||
final Component abbreviation,
|
||||
final int weight,
|
||||
final boolean isDefault,
|
||||
final boolean isHidden)
|
||||
{
|
||||
this.name = name;
|
||||
this.prefix = prefix;
|
||||
@ -121,11 +121,11 @@ public class FreedomGroup implements Group
|
||||
public boolean isPermissionSet(@NotNull final Permission perm)
|
||||
{
|
||||
final Node node = permissions()
|
||||
.stream()
|
||||
.filter(n -> n.bukkit()
|
||||
.equals(perm))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
.stream()
|
||||
.filter(n -> n.bukkit()
|
||||
.equals(perm))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
return node != null && node.value();
|
||||
}
|
||||
@ -146,30 +146,29 @@ public class FreedomGroup implements Group
|
||||
public boolean hasPermission(@NotNull final Permission perm)
|
||||
{
|
||||
final Node node = permissions()
|
||||
.stream()
|
||||
.filter(n -> n.bukkit()
|
||||
.equals(perm))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
.stream()
|
||||
.filter(n -> n.bukkit()
|
||||
.equals(perm))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
return node != null && node.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a permission to the relative PermissionAttachment for this group.
|
||||
* This method is not thread-safe and should not be called asynchronously.
|
||||
* Adds a permission to the relative PermissionAttachment for this group. This method is not thread-safe and should
|
||||
* not be called asynchronously.
|
||||
* <p>
|
||||
* This method is only here for compatibility with the Bukkit API.
|
||||
*
|
||||
* @param plugin The plugin responsible for this attachment. May not be null
|
||||
* or disabled.
|
||||
* @param plugin The plugin responsible for this attachment. May not be null or disabled.
|
||||
* @param name Name of the permission to attach
|
||||
* @param value Value of the permission
|
||||
* @return This group's PermissionAttachment.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull final Plugin plugin, @NotNull final String name,
|
||||
final boolean value)
|
||||
final boolean value)
|
||||
{
|
||||
attachment.setPermission(name, value);
|
||||
return attachment;
|
||||
@ -183,7 +182,7 @@ public class FreedomGroup implements Group
|
||||
|
||||
@Override
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull final Plugin plugin, @NotNull final String name,
|
||||
final boolean value, final int ticks)
|
||||
final boolean value, final int ticks)
|
||||
{
|
||||
attachment.setPermission(name, value);
|
||||
return attachment;
|
||||
@ -211,23 +210,23 @@ public class FreedomGroup implements Group
|
||||
public @NotNull Set<PermissionAttachmentInfo> getEffectivePermissions()
|
||||
{
|
||||
return permissions()
|
||||
.stream()
|
||||
.map(n -> new PermissionAttachmentInfo(
|
||||
this,
|
||||
n.key(),
|
||||
attachment,
|
||||
n.value()))
|
||||
.collect(Collectors.toSet());
|
||||
.stream()
|
||||
.map(n -> new PermissionAttachmentInfo(
|
||||
this,
|
||||
n.key(),
|
||||
attachment,
|
||||
n.value()))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp()
|
||||
{
|
||||
final Node node = permissions()
|
||||
.stream()
|
||||
.filter(n -> n.equals(DefaultNodes.OP))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
.stream()
|
||||
.filter(n -> n.equals(DefaultNodes.OP))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
return node != null && node.value();
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* The superinterface User extends PermissionHolder,
|
||||
* which is an extension of {@link org.bukkit.permissions.Permissible}.
|
||||
* This means that our permission data can be interchanged with other permission plugins.
|
||||
* The superinterface User extends PermissionHolder, which is an extension of
|
||||
* {@link org.bukkit.permissions.Permissible}. This means that our permission data can be interchanged with other
|
||||
* permission plugins.
|
||||
*/
|
||||
public class FreedomUser implements User
|
||||
{
|
||||
@ -139,7 +139,7 @@ public class FreedomUser implements User
|
||||
|
||||
@Override
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull final Plugin plugin, @NotNull final String name,
|
||||
final boolean value)
|
||||
final boolean value)
|
||||
{
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null)
|
||||
@ -164,7 +164,7 @@ public class FreedomUser implements User
|
||||
|
||||
@Override
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull final Plugin plugin, @NotNull final String name,
|
||||
final boolean value, final int ticks)
|
||||
final boolean value, final int ticks)
|
||||
{
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null)
|
||||
|
@ -16,9 +16,9 @@ record PermissionNode(String key,
|
||||
public Permission bukkit()
|
||||
{
|
||||
return new Permission(key(),
|
||||
value()
|
||||
? PermissionDefault.TRUE
|
||||
: PermissionDefault.FALSE);
|
||||
value()
|
||||
? PermissionDefault.TRUE
|
||||
: PermissionDefault.FALSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,8 +26,8 @@ record PermissionNode(String key,
|
||||
{
|
||||
return node.key()
|
||||
.equalsIgnoreCase(key())
|
||||
&& node.value() == value()
|
||||
&& node.type() == type();
|
||||
&& node.value() == value()
|
||||
&& node.type() == type();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,10 +51,9 @@ public class Cager extends Service
|
||||
}
|
||||
|
||||
/**
|
||||
* This method generates a cube centered around the passed location,
|
||||
* made of the provided material. This method returns the passed location object.
|
||||
* We use the {@link ShapeUtils} class to generate the cube, which allows us to define
|
||||
* custom shapes using {@link DoubleUnaryOperator}s.
|
||||
* This method generates a cube centered around the passed location, made of the provided material. This method
|
||||
* returns the passed location object. We use the {@link ShapeUtils} class to generate the cube, which allows us to
|
||||
* define custom shapes using {@link DoubleUnaryOperator}s.
|
||||
*
|
||||
* @param location The location to center the cube around.
|
||||
* @param material The material to use for the cube.
|
||||
@ -108,8 +107,7 @@ public class Cager extends Service
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will check to make sure each caged player remains within their cage.
|
||||
* We use
|
||||
* This method will check to make sure each caged player remains within their cage. We use
|
||||
* <p>
|
||||
* <code>{@link Location#distanceSquared(Location)} * {@link Math#pow(double, double)}</code>
|
||||
* <p>
|
||||
|
@ -81,9 +81,9 @@ public class Locker extends Service
|
||||
final SplittableRandom random = new SplittableRandom();
|
||||
player.getEyeLocation()
|
||||
.add(new Vector(
|
||||
random.nextDouble(-1.0, 1.0),
|
||||
random.nextDouble(-1.0, 1.0),
|
||||
random.nextDouble(-1.0, 1.0)
|
||||
random.nextDouble(-1.0, 1.0),
|
||||
random.nextDouble(-1.0, 1.0),
|
||||
random.nextDouble(-1.0, 1.0)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,7 @@ public class MySQL implements SQL
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds credentials to the MySQL URL.
|
||||
* If the URL already contains credentials, they will be overwritten.
|
||||
* Adds credentials to the MySQL URL. If the URL already contains credentials, they will be overwritten.
|
||||
*
|
||||
* @param username The username to add
|
||||
* @param password The password to add
|
||||
@ -61,25 +60,24 @@ public class MySQL implements SQL
|
||||
public CompletableFuture<PreparedStatement> prepareStatement(final String query, final Object... args)
|
||||
{
|
||||
return getConnection()
|
||||
.thenApplyAsync(connection ->
|
||||
{
|
||||
try
|
||||
{
|
||||
final PreparedStatement statement = connection.prepareStatement(query);
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
statement.setObject(i + 1, args[i]);
|
||||
}
|
||||
return statement;
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
throw new CompletionException("Failed to prepare statement: "
|
||||
+ query + "\n", ex);
|
||||
}
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
.thenApplyAsync(connection ->
|
||||
{
|
||||
try
|
||||
{
|
||||
final PreparedStatement statement = connection.prepareStatement(query);
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
statement.setObject(i + 1, args[i]);
|
||||
}
|
||||
return statement;
|
||||
} catch (SQLException ex)
|
||||
{
|
||||
throw new CompletionException("Failed to prepare statement: "
|
||||
+ query + "\n", ex);
|
||||
}
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
}
|
||||
|
||||
private CompletableFuture<Connection> getConnection()
|
||||
@ -89,11 +87,10 @@ public class MySQL implements SQL
|
||||
try
|
||||
{
|
||||
return DriverManager.getConnection(url.toString());
|
||||
}
|
||||
catch (SQLException ex)
|
||||
} catch (SQLException ex)
|
||||
{
|
||||
throw new CompletionException("Failed to connect to the database: "
|
||||
+ url.toString() + "\n", ex);
|
||||
+ url.toString() + "\n", ex);
|
||||
}
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
@ -104,61 +101,58 @@ public class MySQL implements SQL
|
||||
public CompletableFuture<ResultSet> executeQuery(final String query, final Object... args)
|
||||
{
|
||||
return prepareStatement(query, args)
|
||||
.thenApplyAsync(statement ->
|
||||
{
|
||||
try
|
||||
{
|
||||
return statement.executeQuery();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
throw new CompletionException(
|
||||
"Failed to retrieve a result set from query: "
|
||||
+ query + "\n", ex);
|
||||
}
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
.thenApplyAsync(statement ->
|
||||
{
|
||||
try
|
||||
{
|
||||
return statement.executeQuery();
|
||||
} catch (SQLException ex)
|
||||
{
|
||||
throw new CompletionException(
|
||||
"Failed to retrieve a result set from query: "
|
||||
+ query + "\n", ex);
|
||||
}
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Integer> executeUpdate(final String query, final Object... args)
|
||||
{
|
||||
return prepareStatement(query, args)
|
||||
.thenApplyAsync(statement ->
|
||||
{
|
||||
try
|
||||
{
|
||||
return statement.executeUpdate();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
throw new CompletionException("Failed to execute update: "
|
||||
+ query + "\n", ex);
|
||||
}
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
.thenApplyAsync(statement ->
|
||||
{
|
||||
try
|
||||
{
|
||||
return statement.executeUpdate();
|
||||
} catch (SQLException ex)
|
||||
{
|
||||
throw new CompletionException("Failed to execute update: "
|
||||
+ query + "\n", ex);
|
||||
}
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(final String query, final Object... args)
|
||||
{
|
||||
return prepareStatement(query, args)
|
||||
.thenApplyAsync(statement ->
|
||||
{
|
||||
try
|
||||
{
|
||||
return statement.execute();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
throw new CompletionException("Failed to execute statement: "
|
||||
+ query + "\n", ex);
|
||||
}
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
.thenApplyAsync(statement ->
|
||||
{
|
||||
try
|
||||
{
|
||||
return statement.execute();
|
||||
} catch (SQLException ex)
|
||||
{
|
||||
throw new CompletionException("Failed to execute statement: "
|
||||
+ query + "\n", ex);
|
||||
}
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -181,46 +175,45 @@ public class MySQL implements SQL
|
||||
}
|
||||
|
||||
public <T> CompletableFuture<T> getColumn(final String table, final String column, final String key,
|
||||
final Identity identity, final Class<T> type)
|
||||
final Identity identity, final Class<T> type)
|
||||
{
|
||||
return executeQuery("SELECT ? FROM ? WHERE ? = ?", column, table, key, identity.getId())
|
||||
.thenApplyAsync(resultSet ->
|
||||
{
|
||||
try
|
||||
{
|
||||
if (resultSet.next())
|
||||
{
|
||||
return resultSet.getObject(column, type);
|
||||
}
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
throw new CompletionException(
|
||||
"Failed to retrieve column: " + column + " from table: " + table + " " +
|
||||
"where primary key: " + key + " is equal to: " + identity.getId() + "\n",
|
||||
ex);
|
||||
}
|
||||
return null;
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
.thenApplyAsync(resultSet ->
|
||||
{
|
||||
try
|
||||
{
|
||||
if (resultSet.next())
|
||||
{
|
||||
return resultSet.getObject(column, type);
|
||||
}
|
||||
} catch (SQLException ex)
|
||||
{
|
||||
throw new CompletionException(
|
||||
"Failed to retrieve column: " + column + " from table: " + table + " " +
|
||||
"where primary key: " + key + " is equal to: " + identity.getId() + "\n",
|
||||
ex);
|
||||
}
|
||||
return null;
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> updateColumn(final String table, final String column, final Object value,
|
||||
final String key, final Identity identity)
|
||||
final String key, final Identity identity)
|
||||
{
|
||||
return executeUpdate("UPDATE ? SET ? = ? WHERE ? = ?", table, column, value, key, identity.getId())
|
||||
.thenApplyAsync(result -> result > 0, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
.thenApplyAsync(result -> result > 0, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> deleteRow(final String table, final String key, final Identity identity)
|
||||
{
|
||||
return executeUpdate("DELETE FROM ? WHERE ? = ?", table, key, identity.getId())
|
||||
.thenApplyAsync(result -> result > 0, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
.thenApplyAsync(result -> result > 0, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync());
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> insertRow(final String table, final Object... values)
|
||||
|
@ -7,18 +7,16 @@ import me.totalfreedom.economy.EconomicEntityData;
|
||||
* Represents the server's economy holder.
|
||||
* <br>
|
||||
* <br>
|
||||
* This is effectively a Bank object which is meant to represent the server itself,
|
||||
* which can store a balance and perform transactions with other EconomicEntity objects.
|
||||
* This is effectively a Bank object which is meant to represent the server itself, which can store a balance and
|
||||
* perform transactions with other EconomicEntity objects.
|
||||
* <br>
|
||||
* <br>
|
||||
* The server is initially given a maximum balance of {@link Long#MAX_VALUE}, though this can be changed
|
||||
* using the constructor {@link #ServerEconomyHolder(String, long)}. The value that this
|
||||
* bank object holds is persistent, which means that the total economic resources available
|
||||
* are of limited supply.
|
||||
* The server is initially given a maximum balance of {@link Long#MAX_VALUE}, though this can be changed using the
|
||||
* constructor {@link #ServerEconomyHolder(String, long)}. The value that this bank object holds is persistent, which
|
||||
* means that the total economic resources available are of limited supply.
|
||||
* <br>
|
||||
* <br>
|
||||
* Please be aware, if the server's economy falls below 0,
|
||||
* it will have drastic consequences.
|
||||
* Please be aware, if the server's economy falls below 0, it will have drastic consequences.
|
||||
*/
|
||||
public class ServerEconomyHolder implements EconomicEntity, EconomicEntityData
|
||||
{
|
||||
@ -49,9 +47,9 @@ public class ServerEconomyHolder implements EconomicEntity, EconomicEntityData
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will return this object, as it is both the EconomicEntity and the EconomicEntityData.
|
||||
* This is due to the fact that the server should only ever have one singular concrete representation
|
||||
* of it's economic entity and the respective data.
|
||||
* This method will return this object, as it is both the EconomicEntity and the EconomicEntityData. This is due to
|
||||
* the fact that the server should only ever have one singular concrete representation of it's economic entity and
|
||||
* the respective data.
|
||||
*
|
||||
* @return this object.
|
||||
*/
|
||||
@ -71,8 +69,7 @@ public class ServerEconomyHolder implements EconomicEntity, EconomicEntityData
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will always return false, as the server should not ever be
|
||||
* prevented from performing transactions.
|
||||
* This method will always return false, as the server should not ever be prevented from performing transactions.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
@ -103,8 +100,7 @@ public class ServerEconomyHolder implements EconomicEntity, EconomicEntityData
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified amount to the server's balance.
|
||||
* This method mutates the balance and returns the new balance.
|
||||
* Adds the specified amount to the server's balance. This method mutates the balance and returns the new balance.
|
||||
*
|
||||
* @param amount The amount to add.
|
||||
* @return The new balance.
|
||||
@ -117,8 +113,8 @@ public class ServerEconomyHolder implements EconomicEntity, EconomicEntityData
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified amount from the server's balance.
|
||||
* This method mutates the balance and returns the new balance.
|
||||
* Removes the specified amount from the server's balance. This method mutates the balance and returns the new
|
||||
* balance.
|
||||
*
|
||||
* @param amount The amount to remove.
|
||||
* @return The new balance.
|
||||
|
@ -42,14 +42,14 @@ public class SimpleUserData implements UserData
|
||||
}
|
||||
|
||||
private SimpleUserData(
|
||||
final UUID uuid,
|
||||
final String username,
|
||||
final User user,
|
||||
final Group group,
|
||||
final long playtime,
|
||||
final boolean canInteract,
|
||||
final long balance,
|
||||
final boolean transactionsFrozen)
|
||||
final UUID uuid,
|
||||
final String username,
|
||||
final User user,
|
||||
final Group group,
|
||||
final long playtime,
|
||||
final boolean canInteract,
|
||||
final long balance,
|
||||
final boolean transactionsFrozen)
|
||||
{
|
||||
this.uuid = uuid;
|
||||
this.username = username;
|
||||
@ -66,57 +66,56 @@ public class SimpleUserData implements UserData
|
||||
return sql.executeQuery("SELECT * FROM users WHERE UUID = ?", uuid)
|
||||
.thenApplyAsync(result ->
|
||||
{
|
||||
try
|
||||
{
|
||||
if (result.next())
|
||||
{
|
||||
final String g = result.getString("group");
|
||||
try
|
||||
{
|
||||
if (result.next())
|
||||
{
|
||||
final String g = result.getString("group");
|
||||
|
||||
final UUID u = UUID.fromString(uuid);
|
||||
final String username = result.getString("username");
|
||||
final UUID u = UUID.fromString(uuid);
|
||||
final String username = result.getString("username");
|
||||
|
||||
final Player player = Bukkit.getPlayer(u);
|
||||
final Player player = Bukkit.getPlayer(u);
|
||||
|
||||
if (player == null)
|
||||
throw new IllegalStateException("Player should be online but they are not!");
|
||||
if (player == null)
|
||||
throw new IllegalStateException("Player should be online but they are not!");
|
||||
|
||||
final User user = new FreedomUser(player);
|
||||
final Group group = CommonsBase.getInstance()
|
||||
.getRegistrations()
|
||||
.getGroupRegistry()
|
||||
.getGroup(g);
|
||||
final User user = new FreedomUser(player);
|
||||
final Group group = CommonsBase.getInstance()
|
||||
.getRegistrations()
|
||||
.getGroupRegistry()
|
||||
.getGroup(g);
|
||||
|
||||
final long playtime = result.getLong("playtime");
|
||||
final boolean canInteract = result.getBoolean("canInteract");
|
||||
final long balance = result.getLong("balance");
|
||||
final boolean transactionsFrozen = result.getBoolean("transactionsFrozen");
|
||||
|
||||
return new SimpleUserData(u, username, user, group, playtime,
|
||||
canInteract, balance, transactionsFrozen);
|
||||
}
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
final String sb = "An error occurred while trying to retrieve user data for" +
|
||||
" UUID " +
|
||||
uuid +
|
||||
" from the database." +
|
||||
"\nCaused by: " +
|
||||
ExceptionUtils.getRootCauseMessage(ex) +
|
||||
"\nStack trace: " +
|
||||
ExceptionUtils.getStackTrace(ex);
|
||||
final long playtime = result.getLong("playtime");
|
||||
final boolean canInteract = result.getBoolean("canInteract");
|
||||
final long balance = result.getLong("balance");
|
||||
final boolean transactionsFrozen = result.getBoolean("transactionsFrozen");
|
||||
|
||||
FreedomLogger.getLogger("Datura")
|
||||
.error(sb);
|
||||
}
|
||||
return new SimpleUserData(u, username, user, group, playtime,
|
||||
canInteract, balance, transactionsFrozen);
|
||||
}
|
||||
} catch (SQLException ex)
|
||||
{
|
||||
final String sb = "An error occurred while trying to retrieve user data for" +
|
||||
" UUID " +
|
||||
uuid +
|
||||
" from the database." +
|
||||
"\nCaused by: " +
|
||||
ExceptionUtils.getRootCauseMessage(ex) +
|
||||
"\nStack trace: " +
|
||||
ExceptionUtils.getStackTrace(ex);
|
||||
|
||||
final Player player = Bukkit.getPlayer(UUID.fromString(uuid));
|
||||
if (player == null) throw new IllegalStateException("Player should be online but they are not!");
|
||||
|
||||
return new SimpleUserData(player);
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync())
|
||||
FreedomLogger.getLogger("Datura")
|
||||
.error(sb);
|
||||
}
|
||||
|
||||
final Player player = Bukkit.getPlayer(UUID.fromString(uuid));
|
||||
if (player == null) throw new IllegalStateException("Player should be online but they are not!");
|
||||
|
||||
return new SimpleUserData(player);
|
||||
}, CommonsBase.getInstance()
|
||||
.getExecutor()
|
||||
.getAsync())
|
||||
.join();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user