Skip to content

Commit

Permalink
Use JetBrains annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
EsotericEnderman committed Oct 11, 2024
1 parent 1cd8f47 commit 080a088
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import org.bukkit.NamespacedKey;
import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;

import dev.jorel.commandapi.CommandAPI;
import dev.jorel.commandapi.CommandAPIBukkitConfig;
Expand All @@ -25,65 +22,48 @@
import org.esoteric.minecraft.plugins.template.language.Message;
import org.esoteric.minecraft.plugins.template.resourcepack.ResourcePackManager;

@DefaultQualifier(NonNull.class)
public final class TemplatePaperPlugin extends JavaPlugin {

@Nullable
private FileManager fileManager;
@Nullable
private PlayerDataManager playerDataManager;
@Nullable
private LanguageManager languageManager;
@Nullable
private ResourcePackManager resourcePackManager;
@Nullable
private HttpServerManager httpServerManager;
@Nullable
private CustomItemManager customItemManager;
@Nullable
private CustomMultientityManager customMultientityManager;
@Nullable
private CustomMultiblockManager customMultiblockManager;

private final NamespacedKey customItemIdKey = new NamespacedKey(this, "custom_item_id");
private final NamespacedKey customEntityIdKey = new NamespacedKey(this, "custom_entity_id");

@Nullable
public FileManager getFileManager() {
return fileManager;
}

@Nullable
public PlayerDataManager getPlayerDataManager() {
return playerDataManager;
}

@Nullable
public LanguageManager getLanguageManager() {
return languageManager;
}

@Nullable
public ResourcePackManager getResourcePackManager() {
return resourcePackManager;
}

@Nullable
public HttpServerManager getHttpServerManager() {
return httpServerManager;
}

@Nullable
public CustomItemManager getCustomItemManager() {
return customItemManager;
}

@Nullable
public CustomMultientityManager getCustomMultientityManager() {
return customMultientityManager;
}

@Nullable
public CustomMultiblockManager getCustomMultiblockManager() {
return customMultiblockManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import org.esoteric.minecraft.plugins.template.language.LanguageManager;
import org.esoteric.minecraft.plugins.template.language.Message;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;

public class SetLanguageCommand extends CommandAPICommand {

public SetLanguageCommand(TemplatePaperPlugin plugin) {
public SetLanguageCommand(@NotNull TemplatePaperPlugin plugin) {
super("set-language");

LanguageManager languageManager = plugin.getLanguageManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.esoteric.minecraft.plugins.template.TemplatePaperPlugin;
import org.jetbrains.annotations.NotNull;

public abstract class AbstractCustomItem implements Listener {

Expand All @@ -17,7 +17,7 @@ public abstract class AbstractCustomItem implements Listener {
private final CustomItem itemId;
private final Material material;

public AbstractCustomItem(CustomItemManager customItemManager, CustomItem itemId, Material material) {
public AbstractCustomItem(@NotNull CustomItemManager customItemManager, CustomItem itemId, Material material) {
this.plugin = customItemManager.getPlugin();

this.itemId = itemId;
Expand Down Expand Up @@ -57,7 +57,7 @@ public boolean isItem(ItemStack itemStack) {
}
}

public void give(@NonNull Player player) {
public void give(@NotNull Player player) {
player.getInventory().addItem(getCustomItem(player));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.esoteric.minecraft.plugins.template.TemplatePaperPlugin;
import org.esoteric.minecraft.plugins.template.util.types.BlockLocation;
import org.jetbrains.annotations.NotNull;

public abstract class AbstractCustomMultiblock implements Listener {

Expand All @@ -25,7 +26,7 @@ public void addMultiblocks(List<List<BlockLocation>> addedMultiblocks) {
multiblocks.addAll(addedMultiblocks);
}

public AbstractCustomMultiblock(CustomMultiblockManager customMultiblockManager, CustomMultiblock multiblockId) {
public AbstractCustomMultiblock(@NotNull CustomMultiblockManager customMultiblockManager, CustomMultiblock multiblockId) {
this.plugin = customMultiblockManager.getPlugin();

Bukkit.getPluginManager().registerEvents(this, plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.google.gson.Gson;

import org.esoteric.minecraft.plugins.template.TemplatePaperPlugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;

public class CustomMultiblockManager {

Expand All @@ -34,7 +34,7 @@ public TemplatePaperPlugin getPlugin() {
return plugin;
}

public CustomMultiblockManager(TemplatePaperPlugin plugin) {
public CustomMultiblockManager(@NotNull TemplatePaperPlugin plugin) {
this.plugin = plugin;

multiblocksFilePath = plugin.getDataFolder() + File.separator + multiblocksResourceFilePath;
Expand Down Expand Up @@ -114,7 +114,7 @@ public void save() {
}
}

public void loadStoredCustomMultiblocks(@NonNull StoredCustomMultiblocks multiblocks) {
public void loadStoredCustomMultiblocks(@NotNull StoredCustomMultiblocks multiblocks) {
for (StoredCustomMultiblock multiblock : multiblocks.getStoredCustomMultiblocks()) {
customMultiblockMap.get(multiblock.getMultiblockId()).addMultiblocks(multiblock.getBlockLocations());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Map.Entry;

import org.esoteric.minecraft.plugins.template.util.types.BlockLocation;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;

public class StoredCustomMultiblock {
private final List<List<BlockLocation>> blockLocations;
Expand All @@ -23,7 +23,7 @@ public StoredCustomMultiblock(List<List<BlockLocation>> blockLocations, CustomMu
this.multiblockId = multiblockId;
}

public StoredCustomMultiblock(@NonNull Entry<CustomMultiblock, AbstractCustomMultiblock> multiblockInfo) {
public StoredCustomMultiblock(@NotNull Entry<CustomMultiblock, AbstractCustomMultiblock> multiblockInfo) {
this(multiblockInfo.getValue().getMultiblocks(), multiblockInfo.getKey());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import org.bukkit.persistence.PersistentDataType;

import org.esoteric.minecraft.plugins.template.TemplatePaperPlugin;
import org.jetbrains.annotations.NotNull;

public abstract class AbstractCustomMultientity<E extends Entity> implements Listener {

protected final TemplatePaperPlugin plugin;

private final CustomMultientity entityId;

protected AbstractCustomMultientity(CustomMultientityManager customMultientityManager, CustomMultientity entityId) {
protected AbstractCustomMultientity(@NotNull CustomMultientityManager customMultientityManager, CustomMultientity entityId) {
this.plugin = customMultientityManager.getPlugin();

this.entityId = entityId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.google.gson.Gson;

import org.esoteric.minecraft.plugins.template.TemplatePaperPlugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;

public class PlayerDataManager {

Expand All @@ -28,7 +28,7 @@ public class PlayerDataManager {

private final Map<UUID, PlayerProfile> playerData = new HashMap<>();

public PlayerDataManager(TemplatePaperPlugin plugin) {
public PlayerDataManager(@NotNull TemplatePaperPlugin plugin) {
this.plugin = plugin;

playerDataFolderPath = plugin.getDataPath() + File.separator + playerDataFolderName;
Expand Down Expand Up @@ -121,7 +121,7 @@ public PlayerProfile getPlayerProfile(UUID uuid) {
return getPlayerProfile(uuid, true);
}

public PlayerProfile getPlayerProfile(@NonNull Player player, boolean createNewProfile) {
public PlayerProfile getPlayerProfile(@NotNull Player player, boolean createNewProfile) {
return getPlayerProfile(player.getUniqueId(), createNewProfile);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import java.security.NoSuchAlgorithmException;

import net.lingala.zip4j.ZipFile;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class FileUtil {

Expand Down Expand Up @@ -53,7 +53,7 @@ public static List<String> getResourceFileFolderResourceFilePaths(String resourc
}
}

public static @NonNull List<String> getResourceFileFolderResourceFilePathsRecursively(String resourceFileFolderPath) throws IOException {
public static @NotNull List<String> getResourceFileFolderResourceFilePathsRecursively(String resourceFileFolderPath) throws IOException {
List<String> paths = new ArrayList<>();

for (String resourceFilePath : getResourceFileFolderResourceFilePaths(resourceFileFolderPath)) {
Expand All @@ -68,7 +68,7 @@ public static List<String> getResourceFileFolderResourceFilePaths(String resourc
return paths;
}

public static void zipFolder(@NonNull File sourceFolder, File zipFile) throws IOException {
public static void zipFolder(@NotNull File sourceFolder, File zipFile) throws IOException {
try (ZipFile zipFileInstance = new ZipFile(zipFile)) {
for (File file : sourceFolder.listFiles()) {
if (file.isDirectory()) {
Expand All @@ -80,7 +80,7 @@ public static void zipFolder(@NonNull File sourceFolder, File zipFile) throws IO
}
}

public static boolean isDirectoryRecursivelyEmpty(@NonNull File directory) {
public static boolean isDirectoryRecursivelyEmpty(@NotNull File directory) {
if (!directory.isDirectory()) {
throw new IllegalArgumentException("The specified path is not a directory");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.net.InetSocketAddress;

import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;

public class HttpServerManager {

Expand All @@ -42,7 +43,7 @@ public String getSocketAddress() {
return getHostName() + ":" + getPort();
}

public HttpServerManager(TemplatePaperPlugin plugin) {
public HttpServerManager(@NotNull TemplatePaperPlugin plugin) {
if (plugin.getResourcePackManager().getResourcePackZipFile() == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
import org.esoteric.minecraft.plugins.template.http.server.HttpServerManager;
import net.kyori.adventure.resource.ResourcePackInfo;
import net.kyori.adventure.resource.ResourcePackRequest;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;

public class PlayerJoinListener implements Listener {

private ResourcePackInfo resourcePackInfo;

public PlayerJoinListener(TemplatePaperPlugin plugin, HttpServerManager httpServerManager) {
public PlayerJoinListener(@NotNull TemplatePaperPlugin plugin, @NotNull HttpServerManager httpServerManager) {
resourcePackInfo = ResourcePackInfo.resourcePackInfo().hash(FileUtil.getSha1HexString(plugin.getResourcePackManager().getResourcePackZipFile()))
.uri(URI.create("http://" + httpServerManager.getSocketAddress() + "/")).build();
}

@EventHandler
public void onPlayerJoin(@NonNull PlayerJoinEvent event) {
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
Player player = event.getPlayer();
player.sendResourcePacks(ResourcePackRequest.resourcePackRequest().packs(resourcePackInfo).required(true).build());
}
Expand Down
Loading

0 comments on commit 080a088

Please sign in to comment.