mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2025-06-26 19:44:27 +00:00
Adjust to better align with code specs
This commit is contained in:
@ -22,7 +22,7 @@ public final class BanUID implements BanID
|
||||
|
||||
final Instant instant = Instant.now();
|
||||
|
||||
String stringBuilder = String.valueOf(instant.get(ChronoField.DAY_OF_YEAR)) + // The first three numbers between 001 -> 365
|
||||
final String stringBuilder = String.valueOf(instant.get(ChronoField.DAY_OF_YEAR)) + // The first three numbers between 001 -> 365
|
||||
instant.get(ChronoField.HOUR_OF_DAY) + // next two numbers between 00 -> 23
|
||||
instant.get(ChronoField.MINUTE_OF_HOUR) + // next two numbers between 00 -> 59
|
||||
instant.get(ChronoField.MILLI_OF_SECOND); // last three numbers between 000 -> 999
|
||||
|
@ -7,7 +7,7 @@ public class UserDataUpdateEvent extends FEvent
|
||||
{
|
||||
private final UserData data;
|
||||
|
||||
public UserDataUpdateEvent(UserData data)
|
||||
public UserDataUpdateEvent(final UserData data)
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
|
@ -27,12 +27,12 @@ public class FreedomGroup implements Group
|
||||
private final Set<Node> permissions;
|
||||
private final PermissionAttachment attachment;
|
||||
|
||||
public FreedomGroup(Component name,
|
||||
Component prefix,
|
||||
Component abbreviation,
|
||||
int weight,
|
||||
boolean isDefault,
|
||||
boolean isHidden)
|
||||
public FreedomGroup(final Component name,
|
||||
final Component prefix,
|
||||
final Component abbreviation,
|
||||
final int weight,
|
||||
final boolean isDefault,
|
||||
final boolean isHidden)
|
||||
{
|
||||
this.name = name;
|
||||
this.prefix = prefix;
|
||||
@ -94,21 +94,21 @@ public class FreedomGroup implements Group
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addPermission(Node node)
|
||||
public boolean addPermission(final Node node)
|
||||
{
|
||||
return permissions().add(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePermission(Node node)
|
||||
public boolean removePermission(final Node node)
|
||||
{
|
||||
return permissions().remove(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(@NotNull String name)
|
||||
public boolean isPermissionSet(@NotNull final String name)
|
||||
{
|
||||
Node node = permissions().stream()
|
||||
final Node node = permissions().stream()
|
||||
.filter(n -> n.key().equalsIgnoreCase(name))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
@ -117,9 +117,9 @@ public class FreedomGroup implements Group
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(@NotNull Permission perm)
|
||||
public boolean isPermissionSet(@NotNull final Permission perm)
|
||||
{
|
||||
Node node = permissions()
|
||||
final Node node = permissions()
|
||||
.stream()
|
||||
.filter(n -> n.bukkit().equals(perm))
|
||||
.findFirst()
|
||||
@ -129,9 +129,9 @@ public class FreedomGroup implements Group
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull String name)
|
||||
public boolean hasPermission(@NotNull final String name)
|
||||
{
|
||||
Node node = permissions().stream()
|
||||
final Node node = permissions().stream()
|
||||
.filter(n -> n.key().equalsIgnoreCase(name))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
@ -140,9 +140,9 @@ public class FreedomGroup implements Group
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull Permission perm)
|
||||
public boolean hasPermission(@NotNull final Permission perm)
|
||||
{
|
||||
Node node = permissions()
|
||||
final Node node = permissions()
|
||||
.stream()
|
||||
.filter(n -> n.bukkit().equals(perm))
|
||||
.findFirst()
|
||||
@ -164,33 +164,33 @@ public class FreedomGroup implements Group
|
||||
* @return This group's PermissionAttachment.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value)
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull final Plugin plugin, @NotNull final String name, final boolean value)
|
||||
{
|
||||
attachment.setPermission(name, value);
|
||||
return attachment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin)
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull final Plugin plugin)
|
||||
{
|
||||
return new PermissionAttachment(plugin, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value, int ticks)
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull final Plugin plugin, @NotNull final String name, final boolean value, final int ticks)
|
||||
{
|
||||
attachment.setPermission(name, value);
|
||||
return attachment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks)
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull final Plugin plugin, final int ticks)
|
||||
{
|
||||
return new PermissionAttachment(plugin, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(@NotNull PermissionAttachment attachment)
|
||||
public void removeAttachment(@NotNull final PermissionAttachment attachment)
|
||||
{
|
||||
// This method shouldn't do anything, because we don't want to remove our attachment.
|
||||
}
|
||||
@ -217,7 +217,7 @@ public class FreedomGroup implements Group
|
||||
@Override
|
||||
public boolean isOp()
|
||||
{
|
||||
Node node = permissions()
|
||||
final Node node = permissions()
|
||||
.stream()
|
||||
.filter(n -> n.equals(DefaultNodes.OP))
|
||||
.findFirst()
|
||||
@ -227,7 +227,7 @@ public class FreedomGroup implements Group
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value)
|
||||
public void setOp(final boolean value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
|
@ -16,7 +16,11 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* The superinterface User extends PermissionHolder,
|
||||
@ -32,13 +36,13 @@ public class FreedomUser implements User
|
||||
private final String NOT_ONLINE = "Player is not online";
|
||||
private final UserData userData;
|
||||
|
||||
public FreedomUser(Player player)
|
||||
public FreedomUser(final Player player)
|
||||
{
|
||||
this.uuid = player.getUniqueId();
|
||||
this.permissions = new HashSet<>();
|
||||
this.displayName = player.displayName();
|
||||
|
||||
Datura datura = CommonsBase.getInstance()
|
||||
final Datura datura = CommonsBase.getInstance()
|
||||
.getRegistrations()
|
||||
.getModuleRegistry()
|
||||
.getModule(Datura.class)
|
||||
@ -77,15 +81,15 @@ public class FreedomUser implements User
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addPermission(Node node)
|
||||
public boolean addPermission(final Node node)
|
||||
{
|
||||
PermissionAttachment attachment = addAttachment(CommonsBase.getInstance(), node.key(), node.value());
|
||||
final PermissionAttachment attachment = addAttachment(CommonsBase.getInstance(), node.key(), node.value());
|
||||
bukkitAttachments.put(node, attachment);
|
||||
return permissions().add(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePermission(Node node)
|
||||
public boolean removePermission(final Node node)
|
||||
{
|
||||
removeAttachment(bukkitAttachments.get(node));
|
||||
bukkitAttachments.remove(node);
|
||||
@ -105,37 +109,37 @@ public class FreedomUser implements User
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(@NotNull String name)
|
||||
public boolean isPermissionSet(@NotNull final String name)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
return player != null && player.isPermissionSet(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(@NotNull Permission perm)
|
||||
public boolean isPermissionSet(@NotNull final Permission perm)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
return player != null && player.isPermissionSet(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull String name)
|
||||
public boolean hasPermission(@NotNull final String name)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
return player != null && player.hasPermission(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull Permission perm)
|
||||
public boolean hasPermission(@NotNull final Permission perm)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
return player != null && player.hasPermission(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value)
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull final Plugin plugin, @NotNull final String name, final boolean value)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null)
|
||||
{
|
||||
return player.addAttachment(plugin, name, value);
|
||||
@ -145,9 +149,9 @@ public class FreedomUser implements User
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin)
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull final Plugin plugin)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null)
|
||||
{
|
||||
return player.addAttachment(plugin);
|
||||
@ -157,9 +161,9 @@ public class FreedomUser implements User
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value, int ticks)
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull final Plugin plugin, @NotNull final String name, final boolean value, final int ticks)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null)
|
||||
{
|
||||
return player.addAttachment(plugin, name, value, ticks);
|
||||
@ -169,9 +173,9 @@ public class FreedomUser implements User
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks)
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull final Plugin plugin, final int ticks)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null)
|
||||
{
|
||||
return player.addAttachment(plugin, ticks);
|
||||
@ -181,9 +185,9 @@ public class FreedomUser implements User
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(@NotNull PermissionAttachment attachment)
|
||||
public void removeAttachment(@NotNull final PermissionAttachment attachment)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null)
|
||||
{
|
||||
player.removeAttachment(attachment);
|
||||
@ -195,7 +199,7 @@ public class FreedomUser implements User
|
||||
@Override
|
||||
public void recalculatePermissions()
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null)
|
||||
{
|
||||
player.recalculatePermissions();
|
||||
@ -207,7 +211,7 @@ public class FreedomUser implements User
|
||||
@Override
|
||||
public @NotNull Set<PermissionAttachmentInfo> getEffectivePermissions()
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null)
|
||||
{
|
||||
return player.getEffectivePermissions();
|
||||
@ -223,7 +227,7 @@ public class FreedomUser implements User
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value)
|
||||
public void setOp(final boolean value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ record PermissionNode(String key,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compare(Node node)
|
||||
public boolean compare(final Node node)
|
||||
{
|
||||
return node.key().equalsIgnoreCase(key())
|
||||
&& node.value() == value()
|
||||
|
@ -14,42 +14,42 @@ public class PermissionNodeBuilder implements NodeBuilder
|
||||
private boolean negated = false;
|
||||
|
||||
@Override
|
||||
public NodeBuilder key(String key)
|
||||
public NodeBuilder key(final String key)
|
||||
{
|
||||
this.key = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeBuilder value(boolean value)
|
||||
public NodeBuilder value(final boolean value)
|
||||
{
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeBuilder expiry(long expiry)
|
||||
public NodeBuilder expiry(final long expiry)
|
||||
{
|
||||
this.expiry = expiry;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeBuilder type(NodeType type)
|
||||
public NodeBuilder type(final NodeType type)
|
||||
{
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeBuilder wildcard(boolean wildcard)
|
||||
public NodeBuilder wildcard(final boolean wildcard)
|
||||
{
|
||||
this.wildcard = wildcard;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeBuilder negated(boolean negated)
|
||||
public NodeBuilder negated(final boolean negated)
|
||||
{
|
||||
this.negated = negated;
|
||||
return this;
|
||||
|
@ -12,7 +12,11 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.DoubleUnaryOperator;
|
||||
|
||||
public class Cager extends Service
|
||||
@ -34,18 +38,18 @@ public class Cager extends Service
|
||||
*
|
||||
* @param uuid The UUID of the player to cage.
|
||||
*/
|
||||
public void cagePlayer(UUID uuid)
|
||||
public void cagePlayer(final UUID uuid)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) return;
|
||||
|
||||
cagedPlayers.add(uuid);
|
||||
cageLocations.put(uuid, createCage(player.getLocation(), Material.GLASS));
|
||||
}
|
||||
|
||||
public void cagePlayer(UUID uuid, Material material)
|
||||
public void cagePlayer(final UUID uuid, final Material material)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) return;
|
||||
|
||||
cagedPlayers.add(uuid);
|
||||
@ -57,10 +61,10 @@ public class Cager extends Service
|
||||
*
|
||||
* @param uuid The UUID of the player to uncage.
|
||||
*/
|
||||
public void uncagePlayer(UUID uuid)
|
||||
public void uncagePlayer(final UUID uuid)
|
||||
{
|
||||
cagedPlayers.remove(uuid);
|
||||
Location location = cageLocations.get(uuid);
|
||||
final Location location = cageLocations.get(uuid);
|
||||
|
||||
createCage(location, Material.AIR); // Remove the cage (set all blocks to air).
|
||||
|
||||
@ -78,12 +82,12 @@ public class Cager extends Service
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
for (UUID uuid : cagedPlayers)
|
||||
for (final UUID uuid : cagedPlayers)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) continue;
|
||||
|
||||
Location cageLocation = getCageLocation(player);
|
||||
final Location cageLocation = getCageLocation(player);
|
||||
|
||||
final boolean inside;
|
||||
if (!player.getWorld().equals(cageLocation.getWorld()))
|
||||
@ -108,7 +112,7 @@ public class Cager extends Service
|
||||
* @param player The player to check.
|
||||
* @return Whether the player is caged.
|
||||
*/
|
||||
public Location getCageLocation(Player player)
|
||||
public Location getCageLocation(final Player player)
|
||||
{
|
||||
return cageLocations.get(player.getUniqueId());
|
||||
}
|
||||
@ -119,16 +123,16 @@ public class Cager extends Service
|
||||
* We use the {@link Shaper} 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 location The location to center the cube around.
|
||||
* @param material The material to use for the cube.
|
||||
* @return The center location of the cube (the passed location).
|
||||
* @see Shaper
|
||||
* @see DoubleUnaryOperator
|
||||
*/
|
||||
public Location createCage(Location location, Material material)
|
||||
public Location createCage(final Location location, final Material material)
|
||||
{
|
||||
Shaper shaper = new Shaper(location.getWorld(), 0.0, 4.0);
|
||||
List<Location> cubed = new LinkedList<>();
|
||||
final Shaper shaper = new Shaper(location.getWorld(), 0.0, 4.0);
|
||||
final List<Location> cubed = new LinkedList<>();
|
||||
cubed.addAll(shaper.generate(5, t -> t, t -> 4.0, t -> t));
|
||||
cubed.addAll(shaper.generate(5, t -> t, t -> 0.0, t -> t));
|
||||
cubed.addAll(shaper.generate(5, t -> 0.0, t -> t, t -> t));
|
||||
@ -136,7 +140,7 @@ public class Cager extends Service
|
||||
cubed.addAll(shaper.generate(5, t -> t, t -> t, t -> 0.0));
|
||||
cubed.addAll(shaper.generate(5, t -> t, t -> t, t -> 4.0));
|
||||
|
||||
for (Location l : cubed)
|
||||
for (final Location l : cubed)
|
||||
{
|
||||
location.getWorld().getBlockAt(l).setType(material);
|
||||
}
|
||||
@ -147,7 +151,7 @@ public class Cager extends Service
|
||||
private final class CageListener implements Listener
|
||||
{
|
||||
@EventHandler
|
||||
public void blockBreakEvent(BlockBreakEvent event)
|
||||
public void blockBreakEvent(final BlockBreakEvent event)
|
||||
{
|
||||
if (cagedPlayers.contains(event.getPlayer().getUniqueId()))
|
||||
{
|
||||
@ -156,7 +160,8 @@ public class Cager extends Service
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerLeaveEvent(PlayerQuitEvent event) {
|
||||
public void playerLeaveEvent(final PlayerQuitEvent event)
|
||||
{
|
||||
if (cagedPlayers.contains(event.getPlayer().getUniqueId()))
|
||||
{
|
||||
uncagePlayer(event.getPlayer().getUniqueId());
|
||||
|
@ -23,7 +23,7 @@ public class Halter implements Listener
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerMove(PlayerMoveEvent event)
|
||||
public void playerMove(final PlayerMoveEvent event)
|
||||
{
|
||||
if (haltedPlayers.contains(event.getPlayer().getUniqueId()))
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ public class Locker extends Service
|
||||
super("locker-service");
|
||||
}
|
||||
|
||||
public void lock(UUID uuid)
|
||||
public void lock(final UUID uuid)
|
||||
{
|
||||
lockedPlayers.add(uuid);
|
||||
}
|
||||
@ -32,19 +32,19 @@ public class Locker extends Service
|
||||
{
|
||||
lockedPlayers.removeIf(uuid -> !CommonsBase.getInstance().getServer().getOfflinePlayer(uuid).isOnline());
|
||||
|
||||
for (UUID uuid : lockedPlayers)
|
||||
for (final UUID uuid : lockedPlayers)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) continue;
|
||||
|
||||
lockingMethod(player);
|
||||
}
|
||||
}
|
||||
|
||||
private void lockingMethod(@NotNull Player player)
|
||||
private void lockingMethod(@NotNull final Player player)
|
||||
{
|
||||
double x = player.getLocation().getX();
|
||||
double z = player.getLocation().getZ();
|
||||
final double x = player.getLocation().getX();
|
||||
final double z = player.getLocation().getZ();
|
||||
|
||||
if ((x / z % 0.001) < 1)
|
||||
{
|
||||
|
@ -16,12 +16,12 @@ public class DBBan
|
||||
{
|
||||
private final SQL sql;
|
||||
|
||||
public DBBan(SQL sql)
|
||||
public DBBan(final SQL sql)
|
||||
{
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
public CompletableFuture<Ban> fromSQL(BanID id)
|
||||
public CompletableFuture<Ban> fromSQL(final BanID id)
|
||||
{
|
||||
return sql.executeQuery("SELECT * FROM bans WHERE id = ?", id.getID())
|
||||
.thenApplyAsync(result ->
|
||||
@ -30,11 +30,11 @@ public class DBBan
|
||||
{
|
||||
if (result.next())
|
||||
{
|
||||
UUID uuid = UUID.fromString(result.getString("uuid"));
|
||||
Instant timestamp = Instant.parse(result.getString("timestamp"));
|
||||
final UUID uuid = UUID.fromString(result.getString("uuid"));
|
||||
final Instant timestamp = Instant.parse(result.getString("timestamp"));
|
||||
|
||||
final Instant expiry;
|
||||
String ex = result.getString("expiry");
|
||||
final String ex = result.getString("expiry");
|
||||
if (ex.equals("-1"))
|
||||
{
|
||||
expiry = null;
|
||||
@ -58,7 +58,7 @@ public class DBBan
|
||||
}, CommonsBase.getInstance().getExecutor().getAsync());
|
||||
}
|
||||
|
||||
public void addBan(Ban ban)
|
||||
public void addBan(final Ban ban)
|
||||
{
|
||||
sql.executeUpdate("INSERT INTO bans (id, uuid, reason, issuer, timestamp, expiry) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
ban.getBanID().getID(),
|
||||
@ -70,7 +70,7 @@ public class DBBan
|
||||
);
|
||||
}
|
||||
|
||||
public boolean hasEntry(UUID uuid) {
|
||||
public boolean hasEntry(final UUID uuid) {
|
||||
return sql.executeQuery("SELECT * FROM bans WHERE uuid = ?", uuid.toString())
|
||||
.thenApplyAsync(result ->
|
||||
{
|
||||
|
@ -3,7 +3,11 @@ package me.totalfreedom.datura.sql;
|
||||
import me.totalfreedom.base.CommonsBase;
|
||||
import me.totalfreedom.sql.SQL;
|
||||
|
||||
import java.sql.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
|
||||
@ -11,7 +15,7 @@ public class MySQL implements SQL
|
||||
{
|
||||
private String url = "jdbc:mysql://";
|
||||
|
||||
public MySQL(String host, int port, String database) {
|
||||
public MySQL(final String host, final int port, final String database) {
|
||||
url += host + ":" + port + "/" + database;
|
||||
}
|
||||
|
||||
@ -22,7 +26,7 @@ public class MySQL implements SQL
|
||||
* @param username The username to add
|
||||
* @param password The password to add
|
||||
*/
|
||||
public void addCredentials(String username, String password) {
|
||||
public void addCredentials(final String username, final String password) {
|
||||
if (url.contains("?user=")) {
|
||||
url = url.split("\\x3f")[0];
|
||||
}
|
||||
@ -31,7 +35,7 @@ public class MySQL implements SQL
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Connection> getConnection(String url)
|
||||
public CompletableFuture<Connection> getConnection(final String url)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
@ -44,12 +48,12 @@ public class MySQL implements SQL
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<PreparedStatement> prepareStatement(String query, Object... args)
|
||||
public CompletableFuture<PreparedStatement> prepareStatement(final String query, final Object... args)
|
||||
{
|
||||
return getConnection(url)
|
||||
.thenApplyAsync(connection -> {
|
||||
try {
|
||||
PreparedStatement statement = connection.prepareStatement(query);
|
||||
final PreparedStatement statement = connection.prepareStatement(query);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
statement.setObject(i + 1, args[i]);
|
||||
}
|
||||
@ -62,7 +66,7 @@ public class MySQL implements SQL
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ResultSet> executeQuery(String query, Object... args)
|
||||
public CompletableFuture<ResultSet> executeQuery(final String query, final Object... args)
|
||||
{
|
||||
return prepareStatement(query, args)
|
||||
.thenApplyAsync(statement -> {
|
||||
@ -76,7 +80,7 @@ public class MySQL implements SQL
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Integer> executeUpdate(String query, Object... args)
|
||||
public CompletableFuture<Integer> executeUpdate(final String query, final Object... args)
|
||||
{
|
||||
return prepareStatement(query, args)
|
||||
.thenApplyAsync(statement -> {
|
||||
@ -90,7 +94,7 @@ public class MySQL implements SQL
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(String query, Object... args)
|
||||
public CompletableFuture<Boolean> execute(final String query, final Object... args)
|
||||
{
|
||||
return prepareStatement(query, args)
|
||||
.thenApplyAsync(statement -> {
|
||||
@ -104,9 +108,9 @@ public class MySQL implements SQL
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> createTable(String table, String... columns)
|
||||
public CompletableFuture<Boolean> createTable(final String table, final String... columns)
|
||||
{
|
||||
StringBuilder query = new StringBuilder();
|
||||
final StringBuilder query = new StringBuilder();
|
||||
|
||||
query.append("CREATE TABLE IF NOT EXISTS ? (");
|
||||
for (int i = 0; i < columns.length; i++) {
|
||||
|
@ -58,7 +58,7 @@ public class SimpleUserData implements UserData
|
||||
this.caged = caged;
|
||||
}
|
||||
|
||||
public static SimpleUserData fromSQL(SQL sql, String uuid)
|
||||
public static SimpleUserData fromSQL(final SQL sql, final String uuid)
|
||||
{
|
||||
return sql.executeQuery("SELECT * FROM users WHERE UUID = ?", uuid)
|
||||
.thenApplyAsync(result ->
|
||||
@ -67,30 +67,30 @@ public class SimpleUserData implements UserData
|
||||
{
|
||||
if (result.next())
|
||||
{
|
||||
String g = result.getString("group");
|
||||
final String g = result.getString("group");
|
||||
|
||||
UUID u = UUID.fromString(uuid);
|
||||
String username = result.getString("username");
|
||||
final UUID u = UUID.fromString(uuid);
|
||||
final String username = result.getString("username");
|
||||
|
||||
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!");
|
||||
|
||||
User user = new FreedomUser(player);
|
||||
Group group = CommonsBase.getInstance()
|
||||
final User user = new FreedomUser(player);
|
||||
final Group group = CommonsBase.getInstance()
|
||||
.getRegistrations()
|
||||
.getGroupRegistry()
|
||||
.getGroup(g);
|
||||
long playtime = result.getLong("playtime");
|
||||
boolean frozen = result.getBoolean("frozen");
|
||||
boolean canInteract = result.getBoolean("canInteract");
|
||||
boolean caged = result.getBoolean("caged");
|
||||
final long playtime = result.getLong("playtime");
|
||||
final boolean frozen = result.getBoolean("frozen");
|
||||
final boolean canInteract = result.getBoolean("canInteract");
|
||||
final boolean caged = result.getBoolean("caged");
|
||||
return new SimpleUserData(u, username, user, group, playtime, frozen, canInteract, caged);
|
||||
}
|
||||
} catch (SQLException ex)
|
||||
{
|
||||
String sb = "An error occurred while trying to retrieve user data for UUID " +
|
||||
final String sb = "An error occurred while trying to retrieve user data for UUID " +
|
||||
uuid +
|
||||
" from the database." +
|
||||
"\nCaused by: " +
|
||||
@ -102,7 +102,7 @@ public class SimpleUserData implements UserData
|
||||
.error(sb);
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(UUID.fromString(uuid));
|
||||
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()
|
||||
@ -136,7 +136,7 @@ public class SimpleUserData implements UserData
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGroup(@Nullable Group group)
|
||||
public void setGroup(@Nullable final Group group)
|
||||
{
|
||||
event.ping();
|
||||
this.group = group;
|
||||
@ -149,14 +149,14 @@ public class SimpleUserData implements UserData
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlaytime(long playtime)
|
||||
public void setPlaytime(final long playtime)
|
||||
{
|
||||
event.ping();
|
||||
this.playtime = playtime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlaytime(long playtime)
|
||||
public void addPlaytime(final long playtime)
|
||||
{
|
||||
event.ping();
|
||||
this.playtime += playtime;
|
||||
@ -176,7 +176,7 @@ public class SimpleUserData implements UserData
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFrozen(boolean frozen)
|
||||
public void setFrozen(final boolean frozen)
|
||||
{
|
||||
event.ping();
|
||||
this.frozen = true;
|
||||
@ -189,7 +189,7 @@ public class SimpleUserData implements UserData
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInteractionState(boolean canInteract)
|
||||
public void setInteractionState(final boolean canInteract)
|
||||
{
|
||||
event.ping();
|
||||
this.canInteract = canInteract;
|
||||
@ -202,7 +202,7 @@ public class SimpleUserData implements UserData
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCaged(boolean caged)
|
||||
public void setCaged(final boolean caged)
|
||||
{
|
||||
event.ping();
|
||||
this.caged = caged;
|
||||
|
Reference in New Issue
Block a user