Skip to content

Commit

Permalink
Various minor warning & javadoc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
WizardCM committed Nov 21, 2023
1 parent 3e3311a commit ad1c33a
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ public AuthorizationHandler(RoyalCommands instance) {
this.plugin = instance;
}

private boolean chatLoaded() {
return this.plugin.vh.usingVault() && this.plugin.vh.getChat() != null;
}

private boolean economyLoaded() {
return this.plugin.vh.usingVault() && this.plugin.vh.getEconomy() != null;
}

private boolean iABlockCommandSender(BlockCommandSender cb, String node) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,13 @@ protected ChatColor byStringOrDefault(final String s) {

public ChatColor getChatColor() {
final String s;
switch (this) {
case NEGATIVE:
s = Config.negativeChatColor;
break;
case NEUTRAL:
s = Config.neutralChatColor;
break;
case POSITIVE:
s = Config.positiveChatColor;
break;
case RESET:
s = Config.resetChatColor;
break;
default:
s = null;
}
s = switch (this) {
case NEGATIVE -> Config.negativeChatColor;
case NEUTRAL -> Config.neutralChatColor;
case POSITIVE -> Config.positiveChatColor;
case RESET -> Config.resetChatColor;
default -> null;
};
return this.byStringOrDefault(s);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.regex.Pattern;
import net.milkbowl.vault.chat.Chat;
import org.bukkit.BanList;
Expand Down Expand Up @@ -55,7 +56,6 @@
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
import org.royaldev.royalchat.RoyalChat;
Expand Down Expand Up @@ -90,7 +90,6 @@ public static FancyMessage addCommandTo(FancyMessage fm, String command) {
}

public static FancyMessage addDataTo(FancyMessage fm, String[] fields, Object... values) {
final Iterator i = fm.iterator();
for (final Object o : fm) {
try {
RUtils.setFields(o, fields, values);
Expand Down Expand Up @@ -123,7 +122,7 @@ public static ItemStack addLore(ItemStack is, String newLore) {

public static ItemStack applySpawnLore(ItemStack stack) {
final ItemMeta im = stack.getItemMeta();
final List<String> lore = (im.hasLore()) ? im.getLore() : new ArrayList<String>();
final List<String> lore = (im.hasLore()) ? im.getLore() : new ArrayList<>();
for (String s : Config.itemSpawnTagLore) lore.add(RUtils.colorize(s));
im.setLore(lore);
stack.setItemMeta(im);
Expand Down Expand Up @@ -238,8 +237,7 @@ public static String colorize(final String text) {

/**
* Replaces processed color codes with raw color codes. Not to be confused with decolorize
* @param textToReverse
* @param altChar
* @param text
* @return Processed string
*/
public static String uncolorize(final String text) {
Expand Down Expand Up @@ -319,7 +317,7 @@ public static boolean deleteDirectory(File f) {
continue;
}
if (!delete.delete()) {
RoyalCommands.getInstance().getLogger().warning("Could not delete " + delete.getAbsolutePath());
RoyalCommands.getInstance().getLogger().log(Level.WARNING, "Could not delete {0}", delete.getAbsolutePath());
success = false;
}
}
Expand All @@ -334,7 +332,7 @@ public static boolean deleteDirectory(File f) {
*/
public static void dispNoPerms(CommandSender cs) {
cs.sendMessage(MessageColor.NEGATIVE + "You don't have permission for that!");
RoyalCommands.getInstance().getLogger().warning(cs.getName() + " was denied access to that!");
RoyalCommands.getInstance().getLogger().log(Level.WARNING, "{0} was denied access to that!", cs.getName());
}

/**
Expand All @@ -345,7 +343,7 @@ public static void dispNoPerms(CommandSender cs) {
*/
public static void dispNoPerms(CommandSender cs, String message) {
cs.sendMessage(message);
RoyalCommands.getInstance().getLogger().warning(cs.getName() + " was denied access to that!");
RoyalCommands.getInstance().getLogger().log(Level.WARNING, "{0} was denied access to that!", cs.getName());
}

public static void dispNoPerms(CommandSender cs, String... permissionsNeeded) {
Expand All @@ -359,7 +357,7 @@ public static void dispNoPerms(CommandSender cs, String... permissionsNeeded) {
.formattedTooltip(tooltip)
.send(cs);
// @formatter:on
RoyalCommands.getInstance().getLogger().warning(cs.getName() + " was denied access to that!");
RoyalCommands.getInstance().getLogger().log(Level.WARNING, "{0} was denied access to that!", cs.getName());
}

private static void executeBanActions(OfflinePlayer banned, CommandSender banner, String reason) {
Expand Down Expand Up @@ -429,8 +427,7 @@ public static String getAssignmentPath(ItemStack is, boolean customNames, boolea
if (customNames) {
ItemMeta im = is.getItemMeta();
if (im != null) {
String displayName = im.getDisplayName();
if (displayName != null) path.append(".").append(displayName.replace('.', ',')).append(".");
if (im.hasDisplayName()) path.append(".").append(im.getDisplayName().replace('.', ',')).append(".");
List<String> lore = im.getLore();
if (lore != null && !lore.isEmpty()) {
for (String l : lore) {
Expand All @@ -449,6 +446,7 @@ public static String getAssignmentPath(ItemStack is, boolean customNames, boolea
* Gets a player backpack
*
* @param u UUID of player to get backpack for
* @param w
* @return Backpack - never null
* @deprecated Use {@link org.royaldev.royalcommands.wrappers.player.MemoryRPlayer#getBackpack}.
*/
Expand Down Expand Up @@ -496,6 +494,8 @@ public static Command getCommand(String name) {
}

/**
* @param p
* @return
* @deprecated Use {@link org.royaldev.royalcommands.wrappers.player.MemoryRPlayer#getHomes}.size()
*/
@Deprecated
Expand All @@ -504,6 +504,8 @@ public static int getCurrentHomes(Player p) {
}

/**
* @param u
* @return
* @deprecated Use {@link org.royaldev.royalcommands.wrappers.player.MemoryRPlayer#getHomes}.size()
*/
@Deprecated
Expand Down Expand Up @@ -567,6 +569,8 @@ public static String getFriendlyEnumName(Enum e) {
}

/**
* @param p
* @return
* @deprecated Use {@link org.royaldev.royalcommands.wrappers.player.MemoryRPlayer#getHomeLimit}
*/
@Deprecated
Expand Down Expand Up @@ -780,8 +784,7 @@ public static List<FancyMessage> getPlayerTooltip(final Object o) {
}
}
if (o instanceof Player) {
final Player p = (Player) o;
if (tooltip.size() > 0) { // Replace Offline Player with Player
if (!tooltip.isEmpty()) { // Replace Offline Player with Player
tooltip.remove(0);
tooltip.add(0, new FancyMessage("Player").color(MessageColor.NEUTRAL.cc()).style(ChatColor.BOLD, ChatColor.UNDERLINE));
}
Expand All @@ -796,7 +799,6 @@ public static List<FancyMessage> getPlayerTooltip(final Object o) {

public static List<FancyMessage> getItemTooltip(final Object o) {
final List<FancyMessage> tooltip = new ArrayList<>();
final VaultHandler vh = RoyalCommands.getInstance().vh;
if (o instanceof Material) {
final Material item = (Material) o;
tooltip.add(new FancyMessage("Item").color(MessageColor.NEUTRAL.cc()).style(ChatColor.BOLD, ChatColor.UNDERLINE));
Expand Down Expand Up @@ -1068,6 +1070,7 @@ public static String join(Object[] i, String between) {
* Kicks a player and sets the last kick for history writing.
*
* @param kicked Player to kick
* @param kicker Who requested the kick
* @param reason Reason for kick
*/
public static void kickPlayer(final Player kicked, final CommandSender kicker, final String reason) {
Expand Down Expand Up @@ -1143,17 +1146,6 @@ public void run() {
return id;
}

/**
* Makes a scheduled Bukkit task for watching a player when he's warming up for teleport.
*
* @param p Player to teleport when warmup is finished
* @param t Entity to teleport to when warmup is finished
* @return ID of Bukkit task
*/
private static int makeTeleportRunner(final Player p, final Entity t) {
return makeTeleportRunner(p, t.getLocation());
}

public static boolean nearEqual(double a, double b, double margin) {
return Math.abs(a - b) < margin;
}
Expand All @@ -1174,7 +1166,7 @@ public static void playTeleportSound(Location at) {
try {
toPlay = Sound.valueOf(Config.teleportSoundName);
} catch (IllegalArgumentException e) {
RoyalCommands.getInstance().getLogger().warning("A teleport sound was attempted, but " + Config.teleportSoundName + " was not a valid sound name!");
RoyalCommands.getInstance().getLogger().log(Level.WARNING, "A teleport sound was attempted, but {0} was not a valid sound name!", Config.teleportSoundName);
return;
}
at.getWorld().playSound(at, toPlay, Config.teleportSoundVolume, Config.teleportSoundPitch);
Expand Down Expand Up @@ -1242,6 +1234,7 @@ public static void saveBackpack(Player p, Inventory i) {
* Saves player backpacks in a forwards-compatible method, using native Bukkit methods.
*
* @param u UUID of player to save backpack for
* @param w World of the backpack
* @param i Inventory to save as backpack
*/
public static void saveBackpack(UUID u, World w, Inventory i) {
Expand Down Expand Up @@ -1548,7 +1541,6 @@ public static void unbanPlayer(OfflinePlayer t) {
* @param len Length to wrap at
* @return Array of strings
*/
@SuppressWarnings("unchecked")
public static String[] wrapText(String text, int len) {
// return empty array for null text
if (text == null) return new String[]{};
Expand All @@ -1557,7 +1549,7 @@ public static String[] wrapText(String text, int len) {
// return text if less than length
if (text.length() <= len) return new String[]{text};
char[] chars = text.toCharArray();
java.util.Vector lines = new java.util.Vector();
List<String> lines = new ArrayList<String>();
StringBuilder line = new StringBuilder();
StringBuilder word = new StringBuilder();
for (char aChar : chars) {
Expand All @@ -1583,7 +1575,10 @@ public static String[] wrapText(String text, int len) {
if (line.length() > 0) lines.add(line.toString());
String[] ret = new String[lines.size()];
int c = 0; // counter
for (Enumeration e = lines.elements(); e.hasMoreElements(); c++) ret[c] = (String) e.nextElement();
for (String l : lines) {
ret[c] = l;
c++;
}
return ret;
}

Expand All @@ -1598,7 +1593,6 @@ public static void writeBanHistory(OfflinePlayer t) {
PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(t);
if (!pcm.exists()) pcm.createFile();
List<String> prevBans = pcm.getStringList("prevbans");
if (prevBans == null) prevBans = new ArrayList<>();
// banner,banreason,bannedat,istempban
prevBans.add(pcm.getString("banner") + "\u00b5" + pcm.getString("banreason") + "\u00b5" + pcm.getString("bannedat") + "\u00b5" + (pcm.get("bantime") != null));
pcm.set("prevbans", prevBans);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.util.*;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -187,15 +188,15 @@ public void run() {
String currentVersion = useVersion.toString();
if (!dev.equalsIgnoreCase(currentVersion) && currentVersion.contains("-SNAPSHOT")) {
RoyalCommands.this.getLogger().warning("A newer version of RoyalCommands is available!");
RoyalCommands.this.getLogger().warning("Currently installed: v" + currentVersion + ", newest: v" + dev);
RoyalCommands.this.getLogger().log(Level.WARNING, "Currently installed: v{0}, newest: v{1}", new Object[]{currentVersion, dev});
RoyalCommands.this.getLogger().warning("Development builds are available at https://jenkins.blny.me/");
} else if (!stable.equalsIgnoreCase(currentVersion) && !currentVersion.equalsIgnoreCase(dev)) {
RoyalCommands.this.getLogger().warning("A newer version of RoyalCommands is available!");
RoyalCommands.this.getLogger().warning("Currently installed: v" + currentVersion + ", newest: v" + stable);
RoyalCommands.this.getLogger().log(Level.WARNING, "Currently installed: v{0}, newest: v{1}", new Object[]{currentVersion, stable});
RoyalCommands.this.getLogger().warning("Stable builds are available at https://www.spigotmc.org/resources/royalcommands.4113/");
} else if (!stable.equalsIgnoreCase(currentVersion) && currentVersion.replace("-SNAPSHOT", "").equalsIgnoreCase(stable)) {
RoyalCommands.this.getLogger().warning("A newer version of RoyalCommands is available!");
RoyalCommands.this.getLogger().warning("Currently installed: v" + currentVersion + ", newest: v" + stable);
RoyalCommands.this.getLogger().log(Level.WARNING, "Currently installed: v{0}, newest: v{1}", new Object[]{currentVersion, stable});
RoyalCommands.this.getLogger().warning("Stable builds are available at https://www.spigotmc.org/resources/royalcommands.4113/");
}
} catch (Exception ignored) {}
Expand Down Expand Up @@ -244,7 +245,7 @@ private void registerCommand(CommandExecutor ce, String command) {
pc.setUsage(this.getUsage(command));
this.getCommandMap().register(this.getDescription().getName(), pc);
} catch (Exception e) {
this.getLogger().warning("Could not register command \"" + command + "\" - an error occurred: " + e.getMessage() + ".");
this.getLogger().log(Level.WARNING, "Could not register command \"{0}\" - an error occurred: {1}.", new Object[]{command, e.getMessage()});
}
}

Expand All @@ -268,9 +269,9 @@ public boolean accept(File dir, String name) {
playersToConvert.add(playerName);
}
final List<List<String>> partitions = this.partitionList(playersToConvert, 100);
this.getLogger().info("Converting " + playersToConvert.size() + " players in " + partitions.size() + " request" + (partitions.size() == 1 ? "" : "s") + ".");
this.getLogger().log(Level.INFO, "Converting {0} players in {1} request{2}.", new Object[]{playersToConvert.size(), partitions.size(), partitions.size() == 1 ? "" : "s"});
for (List<String> lookup : partitions) {
this.getLogger().info("Converting next " + lookup.size() + " players.");
this.getLogger().log(Level.INFO, "Converting next {0} players.", lookup.size());
final Map<String, UUID> uuids;
try {
uuids = new UUIDFetcher(lookup).call();
Expand All @@ -283,10 +284,10 @@ public boolean accept(File dir, String name) {
if (!userFile.exists()) continue;
try {
Files.move(userFile.toPath(), new File(userdataFolder, e.getValue() + ".yml").toPath());
this.getLogger().info("Converted " + e.getKey().toLowerCase() + ".yml to " + e.getValue() + ".yml");
this.getLogger().log(Level.INFO, "Converted {0}.yml to {1}.yml", new Object[]{e.getKey().toLowerCase(), e.getValue()});
playersConverted.add(e.getKey().toLowerCase());
} catch (IOException ex) {
this.getLogger().warning("Could not convert " + e.getKey() + ".yml: " + ex.getClass().getSimpleName() + " (" + ex.getMessage() + ")");
this.getLogger().log(Level.WARNING, "Could not convert {0}.yml: {1} ({2})", new Object[]{e.getKey(), ex.getClass().getSimpleName(), ex.getMessage()});
}
}
}
Expand All @@ -297,9 +298,9 @@ public boolean accept(File dir, String name) {
final UUID uuid = RUtils.getOfflinePlayer(name).getUniqueId();
try {
Files.move(new File(userdataFolder, name + ".yml").toPath(), new File(userdataFolder, uuid + ".yml").toPath());
this.getLogger().info("Converted offline-mode player " + name + ".yml to " + uuid + ".yml");
this.getLogger().log(Level.INFO, "Converted offline-mode player {0}.yml to {1}.yml", new Object[]{name, uuid});
} catch (IOException ex) {
this.getLogger().warning("Could not convert " + name + ".yml: " + ex.getClass().getSimpleName() + " (" + ex.getMessage() + ")");
this.getLogger().log(Level.WARNING, "Could not convert {0}.yml: {1} ({2})", new Object[]{name, ex.getClass().getSimpleName(), ex.getMessage()});
}
}
}
Expand Down Expand Up @@ -409,7 +410,7 @@ public void onDisable() {

//-- Save all userdata --//

this.getLogger().info("Saving userdata and configurations (" + (PlayerConfigurationManager.configurationsCreated() + Configuration.configurationsCreated()) + " files in all)...");
this.getLogger().log(Level.INFO, "Saving userdata and configurations ({0}{1} files in all)...", new Object[]{PlayerConfigurationManager.configurationsCreated(), Configuration.configurationsCreated()});
PlayerConfigurationManager.saveAllConfigurations();
Configuration.saveAllConfigurations();
this.getLogger().info("Userdata saved.");
Expand All @@ -420,7 +421,7 @@ public void onDisable() {

//-- We're done! --//

this.getLogger().info("RoyalCommands v" + this.version + " disabled.");
this.getLogger().log(Level.INFO, "RoyalCommands v{0} disabled.", this.version);
}

@Override
Expand Down Expand Up @@ -454,7 +455,7 @@ public void onEnable() {

if (!versionCheck()) {
this.getLogger().severe("This version of CraftBukkit is too old to run RoyalCommands!");
this.getLogger().severe("This version of RoyalCommands needs at least CraftBukkit " + this.minVersion + ".");
this.getLogger().log(Level.SEVERE, "This version of RoyalCommands needs at least CraftBukkit {0}.", this.minVersion);
this.getLogger().severe("Disabling plugin. You can turn this check off in the config.");
this.getServer().getPluginManager().disablePlugin(this);
return;
Expand Down Expand Up @@ -522,7 +523,7 @@ public void onEnable() {
if (!(o instanceof BaseCommand)) continue;
this.registerCommand((CommandExecutor) o, command);
} catch (Exception e) {
this.getLogger().warning("Could not register command \"" + command + "\" - an error occurred (" + e.getClass().getSimpleName() + "): " + e.getMessage() + ".");
this.getLogger().log(Level.WARNING, "Could not register command \"{0}\" - an error occurred ({1}): {2}.", new Object[]{command, e.getClass().getSimpleName(), e.getMessage()});
}
}

Expand All @@ -536,7 +537,7 @@ public void onEnable() {

//-- We're done! --//

this.getLogger().info("RoyalCommands v" + this.version + " initiated.");
this.getLogger().log(Level.INFO, "RoyalCommands v{0} initiated.", this.version);
}

private class BackpackConverter implements Listener {
Expand Down
Loading

0 comments on commit ad1c33a

Please sign in to comment.