Adjust to better align with code specs

This commit is contained in:
Paul Reilly 2023-05-21 21:47:10 -05:00
parent 288e32b47d
commit 49ad109671
36 changed files with 273 additions and 246 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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()

View File

@ -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;

View File

@ -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());
}
@ -125,10 +129,10 @@ public class Cager extends Service
* @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());

View File

@ -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()))
{

View File

@ -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)
{

View File

@ -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 ->
{

View File

@ -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++) {

View File

@ -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;

View File

@ -1,6 +1,6 @@
package me.totalfreedom.fossil.command;
import me.totalfreedom.command.*;
import me.totalfreedom.command.CommandBase;
import me.totalfreedom.command.annotation.Base;
import me.totalfreedom.command.annotation.Info;
import me.totalfreedom.command.annotation.Permissive;
@ -14,23 +14,17 @@ import org.bukkit.entity.Player;
@Permissive(perm = "fossil.kick")
public class KickCommand extends CommandBase
{
public KickCommand(Fossil plugin) {
public KickCommand(final Fossil plugin) {
super(plugin);
}
@Base
public void run(CommandSender sender) {
public void run(final CommandSender sender) {
sender.sendMessage(Component.text("You must specify a player to kick."));
}
@Subcommand(permission = "fossil.kick", args = {Player.class, String.class})
public void kickPlayer(Player player, String string) {
public void kickPlayer(final Player player, final String string) {
player.kick(Component.text(string));
}
// TODO: Write the code to make this work properly.
@Subcommand(name = "info", permission = "fossil.kick.info", args = {Player.class})
public void playerinfo(Player player) {
}
}

View File

@ -1,6 +1,12 @@
package me.totalfreedom.base;
import me.totalfreedom.data.*;
import me.totalfreedom.data.GroupRegistry;
import me.totalfreedom.data.BanRegistry;
import me.totalfreedom.data.ConfigRegistry;
import me.totalfreedom.data.ModuleRegistry;
import me.totalfreedom.data.ServiceRegistry;
import me.totalfreedom.data.UserRegistry;
import me.totalfreedom.data.EventRegistry;
public class Registration
{
@ -9,6 +15,8 @@ public class Registration
private final ServiceRegistry serviceRegistry;
private final ModuleRegistry moduleRegistry;
private final GroupRegistry groupRegistry;
private final BanRegistry banRegistry;
private final ConfigRegistry configRegistry;
public Registration()
{
@ -17,6 +25,8 @@ public class Registration
this.serviceRegistry = new ServiceRegistry();
this.moduleRegistry = new ModuleRegistry();
this.groupRegistry = new GroupRegistry();
this.banRegistry = new BanRegistry();
this.configRegistry = new ConfigRegistry();
}
public ModuleRegistry getModuleRegistry()
@ -43,4 +53,14 @@ public class Registration
{
return groupRegistry;
}
public BanRegistry getBanRegistry()
{
return banRegistry;
}
public ConfigRegistry getConfigRegistry()
{
return configRegistry;
}
}

View File

@ -1,6 +1,5 @@
package me.totalfreedom.command;
import jdk.jshell.MethodSnippet;
import me.totalfreedom.api.Context;
import me.totalfreedom.command.annotation.Subcommand;
import me.totalfreedom.provider.ContextProvider;
@ -14,11 +13,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class BukkitDelegator extends Command implements PluginIdentifiableCommand
@ -41,7 +36,9 @@ public class BukkitDelegator extends Command implements PluginIdentifiableComman
}
@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args)
public boolean execute(@NotNull final CommandSender sender,
@NotNull final String commandLabel,
@NotNull final String[] args)
{
if (commandLabel.isEmpty() || !commandLabel.equalsIgnoreCase(getName()))
return false;
@ -63,23 +60,26 @@ public class BukkitDelegator extends Command implements PluginIdentifiableComman
if (args.length > 0)
{
ContextProvider provider = new ContextProvider();
Set<Subcommand> nodes = command.getSubcommands().keySet();
for (Subcommand node : nodes) {
Class<?>[] argTypes = node.args();
final ContextProvider provider = new ContextProvider();
final Set<Subcommand> nodes = command.getSubcommands().keySet();
for (final Subcommand node : nodes)
{
final Class<?>[] argTypes = node.args();
if (argTypes.length != args.length)
continue;
Object[] objects = new Object[0];
for (int i = 0; i < argTypes.length; i++) {
Class<?> argType = argTypes[i];
String arg = args[i];
for (int i = 0; i < argTypes.length; i++)
{
final Class<?> argType = argTypes[i];
final String arg = args[i];
if (argType == String.class)
continue;
Context<?> context = () -> provider.fromString(arg);
if (!argType.isInstance(context.get())) {
final Context<?> context = () -> provider.fromString(arg);
if (!argType.isInstance(context.get()))
{
throw new IllegalStateException();
}
objects = Arrays.copyOf(objects, objects.length + 1);
@ -98,7 +98,8 @@ public class BukkitDelegator extends Command implements PluginIdentifiableComman
return false;
}
if (command.getBaseMethodPair() != null) {
if (command.getBaseMethodPair() != null)
{
try
{
command.getBaseMethodPair().getValue().invoke(command, sender);

View File

@ -29,7 +29,7 @@ public abstract class CommandBase
if (this.getClass().isAnnotationPresent(Base.class))
{
Method method = Stream.of(this.getClass().getDeclaredMethods())
final Method method = Stream.of(this.getClass().getDeclaredMethods())
.filter(m -> m.isAnnotationPresent(Base.class))
.findFirst()
.orElseThrow(() -> new RuntimeException("Base annotation present but no method found."));

View File

@ -1,14 +1,13 @@
package me.totalfreedom.command;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
public class CommandHandler
{
private final JavaPlugin plugin;
public CommandHandler(JavaPlugin plugin)
public CommandHandler(final JavaPlugin plugin)
{
this.plugin = plugin;
}
@ -17,8 +16,9 @@ public class CommandHandler
// We need to find a way to resolve PluginCommands so we can
// set the executor and tab completer as necessary.
// OR we need to find an alternative way to process tab completions.
public <T extends CommandBase> void registerCommand(T command) {
BukkitDelegator delegate = new BukkitDelegator(plugin, command);
public <T extends CommandBase> void registerCommand(final T command)
{
final BukkitDelegator delegate = new BukkitDelegator(plugin, command);
Bukkit.getCommandMap().register(plugin.getName(), delegate);
}

View File

@ -2,7 +2,6 @@ package me.totalfreedom.data;
import me.totalfreedom.security.ban.Ban;
import me.totalfreedom.security.ban.BanID;
import me.totalfreedom.sql.SQL;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@ -12,18 +11,18 @@ public class BanRegistry
{
private final List<Ban> bansList = new ArrayList<>();
public boolean addBan(Ban ban) {
public boolean addBan(final Ban ban) {
return bansList.add(ban);
}
public boolean removeBan(Ban ban) {
public boolean removeBan(final Ban ban) {
return bansList.remove(ban);
}
@Nullable
public Ban getBan(BanID banID)
public Ban getBan(final BanID banID)
{
for (Ban ban : bansList)
for (final Ban ban : bansList)
{
if (ban.getBanID().matches(banID))
{

View File

@ -9,17 +9,17 @@ public class ConfigRegistry
{
private final Map<String, Configuration> configurationList = new HashMap<>();
public void register(String name, Configuration configuration)
public void register(final String name, final Configuration configuration)
{
configurationList.put(name, configuration);
}
public void unregister(String name)
public void unregister(final String name)
{
configurationList.remove(name);
}
public Configuration getConfiguration(String name)
public Configuration getConfiguration(final String name)
{
return configurationList.get(name);
}

View File

@ -15,18 +15,18 @@ public class GroupRegistry
this.groups = new ArrayList<>();
}
public boolean registerGroup(Group group) {
public boolean registerGroup(final Group group) {
return groups.add(group);
}
public boolean unregisterGroup(Group group) {
public boolean unregisterGroup(final Group group) {
return groups.remove(group);
}
public Group getGroup(String name) {
PlainTextComponentSerializer s = PlainTextComponentSerializer.plainText();
for (Group group : groups) {
String n = s.serialize(group.getName());
public Group getGroup(final String name) {
final PlainTextComponentSerializer s = PlainTextComponentSerializer.plainText();
for (final Group group : groups) {
final String n = s.serialize(group.getName());
if (n.equalsIgnoreCase(name)) {
return group;
}

View File

@ -29,9 +29,9 @@ public class ModuleRegistry
}
@SuppressWarnings("unchecked")
public <T extends JavaPlugin> ModuleProvider<T> getModule(Class<T> clazz)
public <T extends JavaPlugin> ModuleProvider<T> getModule(final Class<T> clazz)
{
for (JavaPlugin plugin : plugins)
for (final JavaPlugin plugin : plugins)
{
if (clazz.isInstance(plugin))
{

View File

@ -20,7 +20,7 @@ public class ServiceRegistry
public void startAll()
{
for (Service service : this.services)
for (final Service service : this.services)
{
service.start();
}
@ -28,7 +28,7 @@ public class ServiceRegistry
public void stopAll()
{
for (Service service : this.services)
for (final Service service : this.services)
{
service.stop();
}
@ -39,7 +39,7 @@ public class ServiceRegistry
// and calling getClass() on this object would effectively be Class<T>, though we may lose
// the identity of the code signature in the process.
// In this case, that is fine.
public <T extends Service> void register(Plugin plugin, final T service)
public <T extends Service> void register(final Plugin plugin, final T service)
{
this.services.add(service);
if (!service.getClass().isInstance(service))
@ -57,12 +57,12 @@ public class ServiceRegistry
ServicePriority.Normal);
}
public <T extends Service> RegisteredServiceProvider<T> getService(Class<T> clazz)
public <T extends Service> RegisteredServiceProvider<T> getService(final Class<T> clazz)
{
return Bukkit.getServicesManager().getRegistration(clazz);
}
public void unregister(Class<? extends Service> clazz, Service service)
public void unregister(final Class<? extends Service> clazz, final Service service)
{
this.services.remove(service);
Bukkit.getServicesManager().unregister(clazz, service);

View File

@ -15,17 +15,17 @@ public class UserRegistry
this.userDataMap = new HashMap<>();
}
public UserData getUserData(User user)
public UserData getUserData(final User user)
{
return userDataMap.get(user);
}
public void registerUserData(User user, UserData userData)
public void registerUserData(final User user, final UserData userData)
{
userDataMap.put(user, userData);
}
public void unregisterUserData(User user)
public void unregisterUserData(final User user)
{
userDataMap.remove(user);
}

View File

@ -13,20 +13,20 @@ public class EventBus extends Service
private final Set<FEvent> eventSet = new HashSet<>();
private final SubscriptionBox<?> runningSubscriptions = new SubscriptionBox<>();
public EventBus(CommonsBase plugin)
public EventBus(final CommonsBase plugin)
{
super("event_bus");
this.plugin = plugin;
}
public void addEvent(FEvent event)
public void addEvent(final FEvent event)
{
eventSet.add(event);
}
public <T extends FEvent> T getEvent(Class<T> eventClass)
public <T extends FEvent> T getEvent(final Class<T> eventClass)
{
FEvent e = eventSet.stream()
final FEvent e = eventSet.stream()
.filter(event -> event.getEventClass().equals(eventClass))
.findFirst()
.orElse(null);
@ -34,9 +34,9 @@ public class EventBus extends Service
return eventClass.cast(e);
}
public <T extends FEvent> EventSubscription<T> subscribe(Class<T> eventClass, Callback<T> callback)
public <T extends FEvent> EventSubscription<T> subscribe(final Class<T> eventClass, final Callback<T> callback)
{
Context<T> eventContext = () -> eventSet.stream()
final Context<T> eventContext = () -> eventSet.stream()
.filter(event -> event.getEventClass().equals(eventClass))
.findFirst()
.map(eventClass::cast)
@ -50,7 +50,7 @@ public class EventBus extends Service
return new EventSubscription<>(eventContext.get(), callback);
}
public void unsubscribe(EventSubscription<?> subscription)
public void unsubscribe(final EventSubscription<?> subscription)
{
runningSubscriptions.removeSubscription(subscription);
}

View File

@ -1,7 +1,5 @@
package me.totalfreedom.event;
import com.sun.source.tree.ContinueTree;
import java.util.ArrayList;
import java.util.List;
@ -13,11 +11,11 @@ class SubscriptionBox<T extends FEvent>
this.subscriptions = new ArrayList<>();
}
public void addSubscription(EventSubscription<T> subscription) {
public void addSubscription(final EventSubscription<T> subscription) {
subscriptions.add(subscription);
}
public void removeSubscription(EventSubscription<?> subscription) {
public void removeSubscription(final EventSubscription<?> subscription) {
subscriptions.remove(subscription);
}

View File

@ -14,7 +14,7 @@ import java.util.stream.Stream;
public class ContextProvider
{
public Object fromString(String string)
public Object fromString(final String string)
{
return Stream.of(toBoolean(string),
toDouble(string),
@ -31,7 +31,7 @@ public class ContextProvider
.orElse(string);
}
private @Nullable Boolean toBoolean(String string)
private @Nullable Boolean toBoolean(final String string)
{
try
{
@ -42,7 +42,7 @@ public class ContextProvider
}
}
private @Nullable Double toDouble(String string)
private @Nullable Double toDouble(final String string)
{
try
{
@ -53,7 +53,7 @@ public class ContextProvider
}
}
private @Nullable Integer toInt(String string)
private @Nullable Integer toInt(final String string)
{
try
{
@ -64,7 +64,7 @@ public class ContextProvider
}
}
private @Nullable Long toLong(String string)
private @Nullable Long toLong(final String string)
{
try
{
@ -75,7 +75,7 @@ public class ContextProvider
}
}
private @Nullable Float toFloat(String string)
private @Nullable Float toFloat(final String string)
{
try
{
@ -86,12 +86,12 @@ public class ContextProvider
}
}
private @Nullable Player toPlayer(String string)
private @Nullable Player toPlayer(final String string)
{
return Bukkit.getPlayer(string);
}
private @Nullable CommandSender toCommandSender(String string)
private @Nullable CommandSender toCommandSender(final String string)
{
if (toPlayer(string) == null) return null;
@ -103,9 +103,9 @@ public class ContextProvider
return Bukkit.getWorld(string);
}
private @Nullable Location toLocation(String string)
private @Nullable Location toLocation(final String string)
{
String[] split = string.split(",");
final String[] split = string.split(",");
if (split.length != 4 || toWorld(split[0]) == null) return null;
if (toDouble(split[1]) == null
|| toDouble(split[2]) == null
@ -114,7 +114,7 @@ public class ContextProvider
return new Location(toWorld(split[0]), toDouble(split[1]), toDouble(split[2]), toDouble(split[3]));
}
private @NotNull Component toComponent(String string)
private @NotNull Component toComponent(final String string)
{
return Component.text(string);
}

View File

@ -2,6 +2,7 @@ package me.totalfreedom.service;
import me.totalfreedom.base.CommonsBase;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.Executor;
@ -26,7 +27,7 @@ public class FreedomExecutor
return asyncExecutor;
}
public Executor scheduled(long delay, long period)
public Executor scheduled(final long delay, final long period)
{
return r -> Bukkit.getScheduler()
.runTaskTimer(
@ -36,7 +37,7 @@ public class FreedomExecutor
period);
}
public Executor scheduledAsync(long delay, long period)
public Executor scheduledAsync(final long delay, final long period)
{
return r -> Bukkit.getScheduler()
.runTaskTimerAsynchronously(
@ -46,12 +47,12 @@ public class FreedomExecutor
period);
}
public void runSync(Task task)
public void runSync(@NotNull final Task task)
{
getSync().execute(task);
}
public void runAsync(Task task)
public void runAsync(@NotNull final Task task)
{
getAsync().execute(task);
}

View File

@ -7,7 +7,7 @@ public abstract class Service
private final String name;
private boolean isActive = false;
protected Service(String name)
protected Service(final String name)
{
this.name = name;

View File

@ -7,15 +7,15 @@ import java.util.concurrent.CompletableFuture;
public interface SQL
{
CompletableFuture<Connection> getConnection(String url);
CompletableFuture<Connection> getConnection(final String url);
CompletableFuture<PreparedStatement> prepareStatement(String query, Object... args);
CompletableFuture<PreparedStatement> prepareStatement(final String query, final Object... args);
CompletableFuture<ResultSet> executeQuery(String query, Object... args);
CompletableFuture<ResultSet> executeQuery(final String query, final Object... args);
CompletableFuture<Integer> executeUpdate(String query, Object... args);
CompletableFuture<Integer> executeUpdate(final String query, final Object... args);
CompletableFuture<Boolean> execute(String query, Object... args);
CompletableFuture<Boolean> execute(final String query, final Object... args);
CompletableFuture<Boolean> createTable(String table, String... columns);
CompletableFuture<Boolean> createTable(final String table, final String... columns);
}

View File

@ -9,7 +9,7 @@ public interface SQLProperties
default Properties getDefaultProperties()
{
Properties properties = new Properties();
final Properties properties = new Properties();
properties.setProperty("driver", "sqlite");
properties.setProperty("host", "localhost");
properties.setProperty("port", "3306");

View File

@ -11,17 +11,17 @@ public class FreedomLogger
private final Logger logger;
private boolean debug = false;
private FreedomLogger(String moduleName)
private FreedomLogger(final String moduleName)
{
this.logger = LoggerFactory.getLogger("FreedomNetworkSuite::" + moduleName);
}
public static FreedomLogger getLogger(String moduleName)
public static FreedomLogger getLogger(final String moduleName)
{
return new FreedomLogger(moduleName);
}
public void setDebugMode(boolean debug)
public void setDebugMode(final boolean debug)
{
this.debug = debug;
}
@ -31,7 +31,7 @@ public class FreedomLogger
*
* @param message The message to send.
*/
public void info(String message)
public void info(final String message)
{
logger.info(message);
}
@ -44,7 +44,7 @@ public class FreedomLogger
* @param message The message to send.
* @return A component representation of the message.
*/
public Component info(Supplier<String> message)
public Component info(final Supplier<String> message)
{
logger.info(message.get());
return Component.text(message.get());
@ -55,7 +55,7 @@ public class FreedomLogger
*
* @param message The message to send.
*/
public void warn(String message)
public void warn(final String message)
{
logger.warn(message);
}
@ -67,7 +67,7 @@ public class FreedomLogger
*
* @param message The message to send.
*/
public void error(String message)
public void error(final String message)
{
logger.error(message);
}
@ -77,7 +77,7 @@ public class FreedomLogger
*
* @param th The exception to log.
*/
public void error(Throwable th)
public void error(final Throwable th)
{
logger.error("An error occurred:\n", th);
}
@ -92,7 +92,7 @@ public class FreedomLogger
* @param message The message to send.
* @return A component representation of the message.
*/
public Component error(Supplier<String> message)
public Component error(final Supplier<String> message)
{
logger.error(message.get());
return Component.text(message.get());
@ -104,7 +104,7 @@ public class FreedomLogger
*
* @param message The message to send.
*/
public void debug(String message)
public void debug(final String message)
{
if (debug)
logger.debug(message);
@ -119,7 +119,7 @@ public class FreedomLogger
* @param message The message to send.
* @return A component representation of the message.
*/
public Component debug(Supplier<String> message)
public Component debug(final Supplier<String> message)
{
if (debug)
{

View File

@ -8,7 +8,7 @@ public class Identity
private final UUID id;
public Identity(String key)
public Identity(final String key)
{
this.key = key;
this.id = UUID.nameUUIDFromBytes(key.getBytes());

View File

@ -1,14 +0,0 @@
package me.totalfreedom.utils;
public class MICheck
{
public double maintainabilityIndex(double fileLength, double vocabulary, double cyclomaticComplexity, double linesOfCode) {
double halsteadVolume = fileLength * (Math.log(vocabulary) / Math.log(2));
double maintainabilityIndexUnbounded = 171 - 5.2 * Math.log(halsteadVolume) - 0.23 * cyclomaticComplexity - 16.2 * Math.log(linesOfCode);
return Math.max(0, maintainabilityIndexUnbounded * 100 / 171);
}
public double complexity(double decisionPoints) {
return decisionPoints + 1;
}
}

View File

@ -5,7 +5,7 @@ public class Pair<K, V>
private final K key;
private final V value;
public Pair(K key, V value) {
public Pair(final K key, final V value) {
this.key = key;
this.value = value;
}

View File

@ -13,24 +13,24 @@ public class Shaper
private final double end;
private final World world;
public Shaper(World world, double start, double end)
public Shaper(final World world, final double start, final double end)
{
this.start = start;
this.end = end;
this.world = world;
}
public List<Location> generate(int count, DoubleUnaryOperator x, DoubleUnaryOperator y, DoubleUnaryOperator z)
public List<Location> generate(final int count, final DoubleUnaryOperator x, final DoubleUnaryOperator y, final DoubleUnaryOperator z)
{
double step = (start - end) / (count - 1);
LinkedList<Location> lset = new LinkedList<>();
final double step = (start - end) / (count - 1);
final LinkedList<Location> lset = new LinkedList<>();
for (int i = 0; i < count; i++)
{
double t = start + i * step;
double xp = x.applyAsDouble(t);
double yp = y.applyAsDouble(t);
double zp = z.applyAsDouble(t);
final double t = start + i * step;
final double xp = x.applyAsDouble(t);
final double yp = y.applyAsDouble(t);
final double zp = z.applyAsDouble(t);
lset.add(new Location(world, xp, yp, zp));
}

15
checkstyle.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://www.checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="FinalLocalVariable">
<property name="validateEnhancedForLoopVariable" value="true"/>
</module>
<module name="FinalParameters"/>
<module name="AvoidStaticImport"/>
<module name="UnusedImports"/>
<module name="AvoidStarImportCheck"/>
</module>
</module>