Skip to content

Commit 6a80390

Browse files
committed
Fix some IDE warnings
1 parent 95ecb2c commit 6a80390

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,11 @@ private DataManager attemptDatabaseMigration(@NotNull DataManager oldManager) {
515515

516516
// PREV: Delete storage-old.yml if it exists (from a previous migration)
517517
final File storageOld = new File(dataFolder, "storage-old.yml");
518-
if (storageOld.exists() && !storageOld.delete()) log(Level.SEVERE, "&cFailed to delete previous &4storage-old.yml!");
518+
if (storageOld.exists()) try {
519+
Files.delete(storageOld.toPath());
520+
} catch (final IOException e) {
521+
log(Level.SEVERE, "&cFailed to delete previous &4storage-old.yml!");
522+
}
519523

520524
// Rename files
521525
final File storage = oldManager.storageConfig.file.file;

src/main/java/xyz/srnyx/annoyingapi/AnnoyingUpdate.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import com.google.gson.JsonElement;
55
import com.google.gson.JsonObject;
66

7-
import org.bukkit.plugin.java.JavaPlugin;
7+
import org.bukkit.plugin.PluginBase;
8+
import org.bukkit.plugin.PluginDescriptionFile;
89

910
import org.jetbrains.annotations.NotNull;
1011
import org.jetbrains.annotations.Nullable;
@@ -32,9 +33,9 @@ public class AnnoyingUpdate extends Stringable implements Annoyable {
3233
*/
3334
@NotNull private final AnnoyingPlugin annoyingPlugin;
3435
/**
35-
* The {@link JavaPlugin plugin} to check for updates
36+
* The name of the plugin to check for updates
3637
*/
37-
@NotNull private final JavaPlugin plugin;
38+
@NotNull private final String pluginName;
3839
/**
3940
* The current version of the plugin
4041
*/
@@ -55,14 +56,14 @@ public class AnnoyingUpdate extends Stringable implements Annoyable {
5556
/**
5657
* Creates a new {@link AnnoyingUpdate} object
5758
*
58-
* @param annoyingPlugin {@link #annoyingPlugin}
59-
* @param plugin {@link #plugin}
60-
* @param platforms {@link #platforms}
59+
* @param annoyingPlugin {@link #annoyingPlugin}
60+
* @param pluginDescription {@link #pluginName} and {@link #currentVersion}
61+
* @param platforms {@link #platforms}
6162
*/
62-
public AnnoyingUpdate(@NotNull AnnoyingPlugin annoyingPlugin, @NotNull JavaPlugin plugin, @NotNull PluginPlatform.Multi platforms) {
63+
public AnnoyingUpdate(@NotNull AnnoyingPlugin annoyingPlugin, @NotNull PluginDescriptionFile pluginDescription, @NotNull PluginPlatform.Multi platforms) {
6364
this.annoyingPlugin = annoyingPlugin;
64-
this.plugin = plugin;
65-
this.currentVersion = new SemanticVersion(plugin.getDescription().getVersion());
65+
this.pluginName = pluginDescription.getName();
66+
this.currentVersion = new SemanticVersion(pluginDescription.getVersion());
6667
this.userAgent = annoyingPlugin.getName() + "/" + annoyingPlugin.getDescription().getVersion() + " via Annoying API (update)";
6768
this.platforms = platforms;
6869
final String latestVersionString = getLatestVersion();
@@ -72,7 +73,18 @@ public AnnoyingUpdate(@NotNull AnnoyingPlugin annoyingPlugin, @NotNull JavaPlugi
7273
/**
7374
* Creates a new {@link AnnoyingUpdate} object
7475
*
75-
* @param plugin {@link #annoyingPlugin} and {@link #plugin}
76+
* @param annoyingPlugin {@link #annoyingPlugin}
77+
* @param plugin {@link #pluginName} and {@link #currentVersion}
78+
* @param platforms {@link #platforms}
79+
*/
80+
public AnnoyingUpdate(@NotNull AnnoyingPlugin annoyingPlugin, @NotNull PluginBase plugin, @NotNull PluginPlatform.Multi platforms) {
81+
this(annoyingPlugin, plugin.getDescription(), platforms);
82+
}
83+
84+
/**
85+
* Creates a new {@link AnnoyingUpdate} object
86+
*
87+
* @param plugin {@link #annoyingPlugin}, {@link #pluginName}, and {@link #currentVersion}
7688
* @param platforms {@link #platforms}
7789
*/
7890
public AnnoyingUpdate(@NotNull AnnoyingPlugin plugin, @NotNull PluginPlatform.Multi platforms) {
@@ -93,7 +105,7 @@ public AnnoyingPlugin getAnnoyingPlugin() {
93105
public boolean checkUpdate() {
94106
final boolean update = isUpdateAvailable();
95107
if (update && latestVersion != null) new AnnoyingMessage(annoyingPlugin, annoyingPlugin.options.messagesOptions.keys.updateAvailable)
96-
.replace("%plugin%", plugin.getName())
108+
.replace("%plugin%", pluginName)
97109
.replace("%current%", currentVersion.version)
98110
.replace("%new%", latestVersion.version)
99111
.log(Level.WARNING);

src/main/java/xyz/srnyx/annoyingapi/command/AnnoyingCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public AnnoyingCommand() {
4242
*/
4343
@NotNull
4444
public String getName() {
45-
return getClass().getSimpleName().toLowerCase().replace("command", "").replace("cmd", "");
45+
return getClass().getSimpleName().replace("Command", "").replace("Cmd", "").toLowerCase();
4646
}
4747

4848
/**

src/main/java/xyz/srnyx/annoyingapi/message/AnnoyingMessage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,13 @@ public void broadcast(@NotNull BroadcastType type, @Nullable AnnoyingSender send
343343
fadeIn, stay, fadeOut);
344344
return;
345345
}
346-
final BaseComponent[] components = getComponents(sender);
346+
final BaseComponent[] compiledComponents = getComponents(sender);
347347

348348
// Action bar
349349
if (type.equals(BroadcastType.ACTIONBAR) && PLAYER_SPIGOT_SEND_MESSAGE_METHOD != null) {
350350
Bukkit.getOnlinePlayers().forEach(player -> {
351351
try {
352-
PLAYER_SPIGOT_SEND_MESSAGE_METHOD.invoke(player.spigot(), ChatMessageType.ACTION_BAR, components);
352+
PLAYER_SPIGOT_SEND_MESSAGE_METHOD.invoke(player.spigot(), ChatMessageType.ACTION_BAR, compiledComponents);
353353
} catch (final IllegalAccessException | InvocationTargetException e) {
354354
e.printStackTrace();
355355
}
@@ -358,7 +358,7 @@ public void broadcast(@NotNull BroadcastType type, @Nullable AnnoyingSender send
358358
}
359359

360360
// Chat
361-
Bukkit.spigot().broadcast(components);
361+
Bukkit.spigot().broadcast(compiledComponents);
362362
}
363363

364364
/**

0 commit comments

Comments
 (0)