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.
*/
@SuppressWarnings("unused")
public class BukkitInventoryMap {
private ItemStack[] contents;

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

@ -1,8 +1,6 @@
package net.william278.husksync.event;
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.event.Cancellable;
import org.bukkit.event.HandlerList;

@ -1,7 +1,5 @@
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.event.HandlerList;
import org.jetbrains.annotations.NotNull;

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

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

@ -71,8 +71,9 @@ public class HuskSyncCommand extends CommandBase implements TabCompletable, Cons
switch (args[0].toLowerCase()) {
case "update", "version" ->
new UpdateChecker(plugin.getPluginVersion(), plugin.getLoggingAdapter()).logToConsole();
case "info", "about" -> plugin.getLoggingAdapter().log(Level.INFO, new MineDown(plugin.getLocales().stripMineDown(
Locales.PLUGIN_INFORMATION.replace("%version%", plugin.getPluginVersion().toString()))));
case "info", "about" ->
plugin.getLoggingAdapter().log(Level.INFO, new MineDown(plugin.getLocales().stripMineDown(
Locales.PLUGIN_INFORMATION.replace("%version%", plugin.getPluginVersion().toString()))));
case "reload" -> {
plugin.reload();
plugin.getLoggingAdapter().log(Level.INFO, "Reloaded config & message files.");
@ -92,7 +93,13 @@ public class HuskSyncCommand extends CommandBase implements TabCompletable, Cons
return;
}
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));
default -> plugin.getLoggingAdapter().log(Level.INFO,
"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.data.DataSaveCause;
import net.william278.husksync.data.ItemData;
import net.william278.husksync.data.UserData;
import net.william278.husksync.data.UserDataSnapshot;
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
*
* @param args Current command argumentsrf
* @param args Current command arguments
* @return List of String arguments to offer TAB suggestions
*/
List<String> onTabComplete(@NotNull String[] args);

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

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

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

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

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

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

Loading…
Cancel
Save