General cleanup and optimisations

feat/data-edit-commands
William 2 years ago
parent b5f447b20a
commit 22b7648b77

@ -8,6 +8,7 @@ import java.util.Optional;
/** /**
* A mapped player inventory, providing methods to easily access a player's inventory. * A mapped player inventory, providing methods to easily access a player's inventory.
*/ */
@SuppressWarnings("unused")
public class BukkitInventoryMap { public class BukkitInventoryMap {
private ItemStack[] contents; private ItemStack[] contents;

@ -1,13 +1,8 @@
package net.william278.husksync.event; package net.william278.husksync.event;
import net.william278.husksync.BukkitHuskSync; import net.william278.husksync.BukkitHuskSync;
import net.william278.husksync.player.BukkitPlayer;
import net.william278.husksync.player.OnlineUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;

@ -1,8 +1,6 @@
package net.william278.husksync.event; package net.william278.husksync.event;
import net.william278.husksync.data.UserData; import net.william278.husksync.data.UserData;
import net.william278.husksync.player.BukkitPlayer;
import net.william278.husksync.player.OnlineUser;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;

@ -1,7 +1,5 @@
package net.william278.husksync.event; package net.william278.husksync.event;
import net.william278.husksync.player.BukkitPlayer;
import net.william278.husksync.player.OnlineUser;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

@ -1,11 +1,9 @@
package net.william278.husksync.util; package net.william278.husksync.util;
import de.themoep.minedown.MineDown; import de.themoep.minedown.MineDown;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.logging.Level; import java.util.logging.Level;
public class BukkitLogger extends Logger { public class BukkitLogger extends Logger {

@ -2,7 +2,6 @@ package net.william278.husksync.command;
import net.william278.husksync.HuskSync; import net.william278.husksync.HuskSync;
import net.william278.husksync.data.DataSaveCause; import net.william278.husksync.data.DataSaveCause;
import net.william278.husksync.data.ItemData;
import net.william278.husksync.data.UserData; import net.william278.husksync.data.UserData;
import net.william278.husksync.data.UserDataSnapshot; import net.william278.husksync.data.UserDataSnapshot;
import net.william278.husksync.editor.ItemEditorMenu; import net.william278.husksync.editor.ItemEditorMenu;

@ -71,8 +71,9 @@ public class HuskSyncCommand extends CommandBase implements TabCompletable, Cons
switch (args[0].toLowerCase()) { switch (args[0].toLowerCase()) {
case "update", "version" -> case "update", "version" ->
new UpdateChecker(plugin.getPluginVersion(), plugin.getLoggingAdapter()).logToConsole(); new UpdateChecker(plugin.getPluginVersion(), plugin.getLoggingAdapter()).logToConsole();
case "info", "about" -> plugin.getLoggingAdapter().log(Level.INFO, new MineDown(plugin.getLocales().stripMineDown( case "info", "about" ->
Locales.PLUGIN_INFORMATION.replace("%version%", plugin.getPluginVersion().toString())))); plugin.getLoggingAdapter().log(Level.INFO, new MineDown(plugin.getLocales().stripMineDown(
Locales.PLUGIN_INFORMATION.replace("%version%", plugin.getPluginVersion().toString()))));
case "reload" -> { case "reload" -> {
plugin.reload(); plugin.reload();
plugin.getLoggingAdapter().log(Level.INFO, "Reloaded config & message files."); plugin.getLoggingAdapter().log(Level.INFO, "Reloaded config & message files.");
@ -92,7 +93,13 @@ public class HuskSyncCommand extends CommandBase implements TabCompletable, Cons
return; return;
} }
switch (args[2]) { switch (args[2]) {
case "start" -> migrator.start(); case "start" -> migrator.start().thenAccept(succeeded -> {
if (succeeded) {
plugin.getLoggingAdapter().log(Level.INFO, "Migration completed successfully!");
} else {
plugin.getLoggingAdapter().log(Level.WARNING, "Migration failed!");
}
});
case "set" -> migrator.handleConfigurationCommand(Arrays.copyOfRange(args, 3, args.length)); case "set" -> migrator.handleConfigurationCommand(Arrays.copyOfRange(args, 3, args.length));
default -> plugin.getLoggingAdapter().log(Level.INFO, default -> plugin.getLoggingAdapter().log(Level.INFO,
"Invalid syntax. Console usage: \"husksync migrate " + args[1] + " <start/set>"); "Invalid syntax. Console usage: \"husksync migrate " + args[1] + " <start/set>");

@ -2,7 +2,6 @@ package net.william278.husksync.command;
import net.william278.husksync.HuskSync; import net.william278.husksync.HuskSync;
import net.william278.husksync.data.DataSaveCause; import net.william278.husksync.data.DataSaveCause;
import net.william278.husksync.data.ItemData;
import net.william278.husksync.data.UserData; import net.william278.husksync.data.UserData;
import net.william278.husksync.data.UserDataSnapshot; import net.william278.husksync.data.UserDataSnapshot;
import net.william278.husksync.editor.ItemEditorMenu; import net.william278.husksync.editor.ItemEditorMenu;

@ -12,7 +12,7 @@ public interface TabCompletable {
/** /**
* What should be returned when the player or console attempts to TAB-complete a command * What should be returned when the player or console attempts to TAB-complete a command
* *
* @param args Current command argumentsrf * @param args Current command arguments
* @return List of String arguments to offer TAB suggestions * @return List of String arguments to offer TAB suggestions
*/ */
List<String> onTabComplete(@NotNull String[] args); List<String> onTabComplete(@NotNull String[] args);

@ -106,6 +106,7 @@ public abstract class Database {
* @return Array of string-formatted table creation schema statements * @return Array of string-formatted table creation schema statements
* @throws IOException if the resource could not be read * @throws IOException if the resource could not be read
*/ */
@SuppressWarnings("SameParameterValue")
protected final String[] getSchemaStatements(@NotNull String schemaFileName) throws IOException { protected final String[] getSchemaStatements(@NotNull String schemaFileName) throws IOException {
return formatStatementTables(new String(resourceReader.getResource(schemaFileName) return formatStatementTables(new String(resourceReader.getResource(schemaFileName)
.readAllBytes(), StandardCharsets.UTF_8)).split(";"); .readAllBytes(), StandardCharsets.UTF_8)).split(";");

@ -15,7 +15,7 @@ public class ItemEditorMenu {
public final ItemData itemData; public final ItemData itemData;
public final ItemEditorMenuType itemEditorMenuType; public final ItemEditorMenuType itemEditorMenuType;
public final MineDown menuTitle; public final MineDown menuTitle;
public boolean canEdit; public final boolean canEdit;
private CompletableFuture<ItemData> inventoryDataCompletableFuture; private CompletableFuture<ItemData> inventoryDataCompletableFuture;

@ -2,7 +2,10 @@ package net.william278.husksync.event;
public interface CancellableEvent extends Event { public interface CancellableEvent extends Event {
boolean isCancelled(); @SuppressWarnings("BooleanMethodIsAlwaysInverted")
default boolean isCancelled() {
return false;
}
void setCancelled(boolean cancelled); void setCancelled(boolean cancelled);

@ -11,7 +11,6 @@ import net.william278.husksync.util.Version;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;

@ -12,12 +12,12 @@ public class User {
/** /**
* The user's unique account ID * The user's unique account ID
*/ */
public UUID uuid; public final UUID uuid;
/** /**
* The user's username * The user's username
*/ */
public String username; public final String username;
public User(@NotNull UUID uuid, @NotNull String username) { public User(@NotNull UUID uuid, @NotNull String username) {
this.username = username; this.username = username;

@ -14,13 +14,13 @@ import java.util.concurrent.CompletableFuture;
public class DummyPlayer extends OnlineUser { public class DummyPlayer extends OnlineUser {
private DummyPlayer(@NotNull UUID uuid, @NotNull String username) { private DummyPlayer() {
super(uuid, username); super(UUID.fromString("00000000-0000-0000-0000-000000000000"),
"DummyPlayer");
} }
public static DummyPlayer create() { public static DummyPlayer create() {
return new DummyPlayer(UUID.fromString("00000000-0000-0000-0000-000000000000"), return new DummyPlayer();
"DummyPlayer");
} }
@Override @Override

Loading…
Cancel
Save