diff --git a/build.gradle.kts b/build.gradle.kts index 0e1c9a5..dabef48 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,7 +38,7 @@ fun pascalcase(kebabcaseString: String): String { return pascalCaseString } -description = "Test plugin for paperweight-userdev" +description = "A plugin for displaying titles." val mainProjectAuthor = "Slqmy" val projectAuthors = listOfNotNull(mainProjectAuthor) diff --git a/settings.gradle.kts b/settings.gradle.kts index 8d192e3..f8a147c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,4 +2,4 @@ plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" } -rootProject.name = "template-paper-plugin" +rootProject.name = "title-plugin" diff --git a/src/main/java/net/slqmy/template_paper_plugin/TemplatePaperPlugin.java b/src/main/java/net/slqmy/template_paper_plugin/TemplatePaperPlugin.java deleted file mode 100644 index 60edbc9..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/TemplatePaperPlugin.java +++ /dev/null @@ -1,132 +0,0 @@ -package net.slqmy.template_paper_plugin; - -import org.bukkit.NamespacedKey; -import org.bukkit.plugin.java.JavaPlugin; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.framework.qual.DefaultQualifier; - -import dev.jorel.commandapi.CommandAPI; -import dev.jorel.commandapi.CommandAPIBukkitConfig; -import net.slqmy.template_paper_plugin.commands.GiveCustomItemCommand; -import net.slqmy.template_paper_plugin.commands.PlaceCustomMultiblockCommand; -import net.slqmy.template_paper_plugin.commands.SetLanguageCommand; -import net.slqmy.template_paper_plugin.commands.SpawnCustomMultientityCommand; -import net.slqmy.template_paper_plugin.custom_item.CustomItem; -import net.slqmy.template_paper_plugin.custom_item.CustomItemManager; -import net.slqmy.template_paper_plugin.custom_multiblock.CustomMultiblock; -import net.slqmy.template_paper_plugin.custom_multiblock.CustomMultiblockManager; -import net.slqmy.template_paper_plugin.custom_multientity.CustomMultientity; -import net.slqmy.template_paper_plugin.custom_multientity.CustomMultientityManager; -import net.slqmy.template_paper_plugin.data.player.PlayerDataManager; -import net.slqmy.template_paper_plugin.file.FileManager; -import net.slqmy.template_paper_plugin.http_server.HttpServerManager; -import net.slqmy.template_paper_plugin.language.LanguageManager; -import net.slqmy.template_paper_plugin.language.Message; -import net.slqmy.template_paper_plugin.resource_pack.ResourcePackManager; - -@DefaultQualifier(NonNull.class) -public final class TemplatePaperPlugin extends JavaPlugin { - - private FileManager fileManager; - private PlayerDataManager playerDataManager; - private LanguageManager languageManager; - private ResourcePackManager resourcePackManager; - private HttpServerManager httpServerManager; - private CustomItemManager customItemManager; - private CustomMultientityManager customMultientityManager; - private CustomMultiblockManager customMultiblockManager; - - private final NamespacedKey customItemIdKey = new NamespacedKey(this, "custom_item_id"); - private final NamespacedKey customEntityIdKey = new NamespacedKey(this, "custom_entity_id"); - - public FileManager getFileManager() { - return fileManager; - } - - public PlayerDataManager getPlayerDataManager() { - return playerDataManager; - } - - public LanguageManager getLanguageManager() { - return languageManager; - } - - public ResourcePackManager getResourcePackManager() { - return resourcePackManager; - } - - public HttpServerManager getHttpServerManager() { - return httpServerManager; - } - - public CustomItemManager getCustomItemManager() { - return customItemManager; - } - - public CustomMultientityManager getCustomMultientityManager() { - return customMultientityManager; - } - - public CustomMultiblockManager getCustomMultiblockManager() { - return customMultiblockManager; - } - - public NamespacedKey getCustomItemIdKey() { - return customItemIdKey; - } - - public NamespacedKey getCustomEntityIdKey() { - return customEntityIdKey; - } - - @Override - public void onEnable() { - getDataFolder().mkdir(); - saveDefaultConfig(); - - CommandAPIBukkitConfig commandAPIConfig = new CommandAPIBukkitConfig(this); - - CommandAPI.onLoad(commandAPIConfig); - CommandAPI.onEnable(); - - fileManager = new FileManager(this); - playerDataManager = new PlayerDataManager(this); - if (Message.isEnabled()) { - languageManager = new LanguageManager(this); - } - resourcePackManager = new ResourcePackManager(this); - httpServerManager = new HttpServerManager(this); - if (CustomItem.isEnabled()) { - customItemManager = new CustomItemManager(this); - } - if (CustomMultientity.isEnabled()) { - customMultientityManager = new CustomMultientityManager(this); - } - if (CustomMultiblock.isEnabled()) { - customMultiblockManager = new CustomMultiblockManager(this); - } - - if (Message.isEnabled()) { - new SetLanguageCommand(this); - } - if (CustomItem.isEnabled()) { - new GiveCustomItemCommand(this); - } - if (CustomMultientity.isEnabled()) { - new SpawnCustomMultientityCommand(this); - } - if (CustomMultiblock.isEnabled()) { - new PlaceCustomMultiblockCommand(this); - } - } - - @Override - public void onDisable() { - if (playerDataManager != null) { - playerDataManager.save(); - } - if (customMultiblockManager != null) { - customMultiblockManager.save(); - } - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/TitlePlugin.java b/src/main/java/net/slqmy/template_paper_plugin/TitlePlugin.java new file mode 100644 index 0000000..49f3009 --- /dev/null +++ b/src/main/java/net/slqmy/template_paper_plugin/TitlePlugin.java @@ -0,0 +1,55 @@ +package net.slqmy.template_paper_plugin; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerResourcePackStatusEvent; +import org.bukkit.plugin.java.JavaPlugin; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.md_5.bungee.api.ChatColor; + +import java.util.List; +import java.util.stream.Stream; + +@DefaultQualifier(NonNull.class) +public final class TitlePlugin extends JavaPlugin implements Listener { + + private final MiniMessage miniMessage = MiniMessage.miniMessage(); + + private Component titleComponent; + + private List changingSubtitleComponents; + + private int secondsBeforeChaning; + + @Override + public void onEnable() { + getDataFolder().mkdir(); + saveDefaultConfig(); + + FileConfiguration configuration = getConfig(); + + titleComponent = Component.text(ChatColor.translateAlternateColorCodes('&', configuration.getString("title"))); + + changingSubtitleComponents = Stream.of((List) configuration.getList("subtitle")).map((string) -> Component.text(ChatColor.translateAlternateColorCodes('&', ""))).toList(); + + secondsBeforeChaning = configuration.getInt("seconds-before-changing"); + } + + @EventHandler + public void onResourcePackLoad(PlayerResourcePackStatusEvent event) { + PlayerResourcePackStatusEvent.Status status = event.getStatus(); + + if (status.equals(PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED)) { + Player player = event.getPlayer(); + + player.sendMessage(titleComponent); + } + } +} diff --git a/src/main/java/net/slqmy/template_paper_plugin/commands/GiveCustomItemCommand.java b/src/main/java/net/slqmy/template_paper_plugin/commands/GiveCustomItemCommand.java deleted file mode 100644 index 8421685..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/commands/GiveCustomItemCommand.java +++ /dev/null @@ -1,46 +0,0 @@ -package net.slqmy.template_paper_plugin.commands; - -import java.util.stream.Stream; - -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.CommandPermission; -import dev.jorel.commandapi.arguments.Argument; -import dev.jorel.commandapi.arguments.ArgumentSuggestions; -import dev.jorel.commandapi.arguments.CustomArgument; -import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException; -import dev.jorel.commandapi.arguments.StringArgument; -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; -import net.slqmy.template_paper_plugin.custom_item.CustomItem; -import net.slqmy.template_paper_plugin.language.Message; - -public class GiveCustomItemCommand extends CommandAPICommand { - - public GiveCustomItemCommand(TemplatePaperPlugin plugin) { - super("give-custom-item"); - - String customItemArgumentNodeName = "custom-item-id"; - - String[] customItemIds = Stream.of(CustomItem.values()).map((customItem) -> customItem.name()).toArray(String[]::new); - - Argument customItemArgument = new CustomArgument<>(new StringArgument(customItemArgumentNodeName), (info) -> { - String input = info.currentInput(); - - try { - return CustomItem.valueOf(input); - } catch (IllegalArgumentException exception) { - throw CustomArgumentException.fromAdventureComponent(plugin.getLanguageManager().getMessage(Message.UNKNOWN_CUSTOM_ITEM, info.sender(), input)); - } - }).includeSuggestions(ArgumentSuggestions.strings(customItemIds)); - - executesPlayer((info) -> { - CustomItem item = (CustomItem) info.args().get(customItemArgumentNodeName); - - plugin.getCustomItemManager().giveCustomItem(item, info.sender()); - }); - - withPermission(CommandPermission.OP); - withArguments(customItemArgument); - - register(plugin); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/commands/PlaceCustomMultiblockCommand.java b/src/main/java/net/slqmy/template_paper_plugin/commands/PlaceCustomMultiblockCommand.java deleted file mode 100644 index 236125a..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/commands/PlaceCustomMultiblockCommand.java +++ /dev/null @@ -1,46 +0,0 @@ -package net.slqmy.template_paper_plugin.commands; - -import java.util.stream.Stream; - -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.CommandPermission; -import dev.jorel.commandapi.arguments.Argument; -import dev.jorel.commandapi.arguments.ArgumentSuggestions; -import dev.jorel.commandapi.arguments.CustomArgument; -import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException; -import dev.jorel.commandapi.arguments.StringArgument; -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; -import net.slqmy.template_paper_plugin.custom_multiblock.CustomMultiblock; -import net.slqmy.template_paper_plugin.language.Message; - -public class PlaceCustomMultiblockCommand extends CommandAPICommand { - - public PlaceCustomMultiblockCommand(TemplatePaperPlugin plugin) { - super("place-custom-multiblock"); - - String customMultiblockArgumentNodeName = "custom-multiblock-id"; - - String[] customMultiblockIds = Stream.of(CustomMultiblock.values()).map((customMultiblock) -> customMultiblock.name()).toArray(String[]::new); - - Argument customMultiblockArgument = new CustomArgument<>(new StringArgument(customMultiblockArgumentNodeName), (info) -> { - String input = info.currentInput(); - - try { - return CustomMultiblock.valueOf(input); - } catch (IllegalArgumentException exception) { - throw CustomArgumentException.fromAdventureComponent(plugin.getLanguageManager().getMessage(Message.UNKNOWN_CUSTOM_MULTIBLOCK, info.sender(), input)); - } - }).includeSuggestions(ArgumentSuggestions.strings(customMultiblockIds)); - - executesPlayer((info) -> { - CustomMultiblock multiblock = (CustomMultiblock) info.args().get(customMultiblockArgumentNodeName); - - plugin.getCustomMultiblockManager().placeCustomMultiblock(multiblock, info.sender().getLocation()); - }); - - withPermission(CommandPermission.OP); - withArguments(customMultiblockArgument); - - register(plugin); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/commands/SetLanguageCommand.java b/src/main/java/net/slqmy/template_paper_plugin/commands/SetLanguageCommand.java deleted file mode 100644 index 58d648d..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/commands/SetLanguageCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -package net.slqmy.template_paper_plugin.commands; - -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.arguments.Argument; -import dev.jorel.commandapi.arguments.ArgumentSuggestions; -import dev.jorel.commandapi.arguments.CustomArgument; -import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException; -import dev.jorel.commandapi.arguments.GreedyStringArgument; - -import java.util.Set; - -import net.kyori.adventure.text.Component; -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; -import net.slqmy.template_paper_plugin.language.LanguageManager; -import net.slqmy.template_paper_plugin.language.Message; - -public class SetLanguageCommand extends CommandAPICommand { - - public SetLanguageCommand(TemplatePaperPlugin plugin) { - super("set-language"); - - LanguageManager languageManager = plugin.getLanguageManager(); - Set languages = languageManager.getLanguages(); - - String languageArgumentNodeName = "language"; - - Argument languageArgument = new CustomArgument<>(new GreedyStringArgument(languageArgumentNodeName), (info) -> { - String selectedLanguage = info.currentInput(); - if (!languages.contains(selectedLanguage)) { - Component errorMessage = languageManager.getMessage(Message.UNKNOWN_LANGUAGE, info.sender(), selectedLanguage); - throw CustomArgumentException.fromAdventureComponent(errorMessage); - } - - return selectedLanguage; - }).includeSuggestions(ArgumentSuggestions.strings(languageManager.getLanguages().toArray(String[]::new))); - - withArguments(languageArgument); - - executesPlayer((player, arguments) -> { - String selectedLanguage = (String) arguments.get(languageArgumentNodeName); - languageManager.setLanguage(player, selectedLanguage); - - languageManager.sendMessage(Message.SET_LANGUAGE_SUCCESSFULLY, player, selectedLanguage); - }); - - register(plugin); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/commands/SpawnCustomMultientityCommand.java b/src/main/java/net/slqmy/template_paper_plugin/commands/SpawnCustomMultientityCommand.java deleted file mode 100644 index 249d67b..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/commands/SpawnCustomMultientityCommand.java +++ /dev/null @@ -1,46 +0,0 @@ -package net.slqmy.template_paper_plugin.commands; - -import java.util.stream.Stream; - -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.CommandPermission; -import dev.jorel.commandapi.arguments.Argument; -import dev.jorel.commandapi.arguments.ArgumentSuggestions; -import dev.jorel.commandapi.arguments.CustomArgument; -import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException; -import dev.jorel.commandapi.arguments.StringArgument; -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; -import net.slqmy.template_paper_plugin.custom_multientity.CustomMultientity; -import net.slqmy.template_paper_plugin.language.Message; - -public class SpawnCustomMultientityCommand extends CommandAPICommand { - - public SpawnCustomMultientityCommand(TemplatePaperPlugin plugin) { - super("spawn-custom-multientity"); - - String customMultientityArgumentNodeName = "custom-multientity-id"; - - String[] customMultientityIds = Stream.of(CustomMultientity.values()).map((customMultientity) -> customMultientity.name()).toArray(String[]::new); - - Argument customMultientityArgument = new CustomArgument<>(new StringArgument(customMultientityArgumentNodeName), (info) -> { - String input = info.currentInput(); - - try { - return CustomMultientity.valueOf(input); - } catch (IllegalArgumentException exception) { - throw CustomArgumentException.fromAdventureComponent(plugin.getLanguageManager().getMessage(Message.UNKNOWN_CUSTOM_MULTIENTITY, info.sender(), input)); - } - }).includeSuggestions(ArgumentSuggestions.strings(customMultientityIds)); - - executesPlayer((info) -> { - CustomMultientity multientity = (CustomMultientity) info.args().get(customMultientityArgumentNodeName); - - plugin.getCustomMultientityManager().spawnEntity(multientity, info.sender().getLocation()); - }); - - withPermission(CommandPermission.OP); - withArguments(customMultientityArgument); - - register(plugin); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_item/AbstractCustomItem.java b/src/main/java/net/slqmy/template_paper_plugin/custom_item/AbstractCustomItem.java deleted file mode 100644 index 90ed4d7..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/custom_item/AbstractCustomItem.java +++ /dev/null @@ -1,62 +0,0 @@ -package net.slqmy.template_paper_plugin.custom_item; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; -import org.bukkit.inventory.ItemStack; -import org.bukkit.persistence.PersistentDataType; - -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; - -public abstract class AbstractCustomItem implements Listener { - - protected final TemplatePaperPlugin plugin; - - private final CustomItem itemId; - private final Material material; - - public AbstractCustomItem(TemplatePaperPlugin plugin, CustomItemManager customItemManager, CustomItem itemId, Material material) { - this.plugin = plugin; - - this.itemId = itemId; - this.material = material; - - Bukkit.getPluginManager().registerEvents(this, plugin); - - customItemManager.addCustomItem(itemId, this); - } - - protected abstract ItemStack generateCustomItem(ItemStack baseCustomItem, Player player); - - public ItemStack getCustomItem(Player player) { - ItemStack item = new ItemStack(material); - item.editMeta((meta) -> meta.getPersistentDataContainer().set(plugin.getCustomItemIdKey(), PersistentDataType.STRING, itemId.name())); - return generateCustomItem(item, player); - } - - public boolean isItem(ItemStack itemStack) { - if (itemStack == null) { - return false; - } - - if (!itemStack.hasItemMeta()) { - return false; - } - - String dataContainerItemIdValue = itemStack.getItemMeta().getPersistentDataContainer().get(plugin.getCustomItemIdKey(), PersistentDataType.STRING); - if (dataContainerItemIdValue == null) { - return false; - } - - try { - return itemId == CustomItem.valueOf(dataContainerItemIdValue); - } catch (IllegalArgumentException exception) { - return false; - } - } - - public void give(Player player) { - player.getInventory().addItem(getCustomItem(player)); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_item/CustomItem.java b/src/main/java/net/slqmy/template_paper_plugin/custom_item/CustomItem.java deleted file mode 100644 index cc34700..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/custom_item/CustomItem.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.slqmy.template_paper_plugin.custom_item; - -public enum CustomItem { - ; - - public static boolean isEnabled() { - return values().length != 0; - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_item/CustomItemManager.java b/src/main/java/net/slqmy/template_paper_plugin/custom_item/CustomItemManager.java deleted file mode 100644 index f350c6a..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/custom_item/CustomItemManager.java +++ /dev/null @@ -1,30 +0,0 @@ -package net.slqmy.template_paper_plugin.custom_item; - -import java.util.HashMap; -import java.util.Map; - -import org.bukkit.entity.Player; - -import net.slqmy.template_paper_plugin.custom_item.AbstractCustomItem; -import net.slqmy.template_paper_plugin.custom_item.CustomItem; -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; - -public class CustomItemManager { - - private final Map customItemMap = new HashMap<>(); - - public CustomItemManager(TemplatePaperPlugin plugin) { - } - - public void addCustomItem(CustomItem itemId, AbstractCustomItem customItem) { - customItemMap.put(itemId, customItem); - } - - public AbstractCustomItem getAbstractCustomItem(CustomItem itemId) { - return customItemMap.get(itemId); - } - - public void giveCustomItem(CustomItem itemId, Player player) { - customItemMap.get(itemId).give(player); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/AbstractCustomMultiblock.java b/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/AbstractCustomMultiblock.java deleted file mode 100644 index 664721d..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/AbstractCustomMultiblock.java +++ /dev/null @@ -1,55 +0,0 @@ -package net.slqmy.template_paper_plugin.custom_multiblock; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.event.Listener; - -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; -import net.slqmy.template_paper_plugin.util.types.BlockLocation; - -public abstract class AbstractCustomMultiblock implements Listener { - - protected final TemplatePaperPlugin plugin; - - private final List> multiblocks = new ArrayList<>(); - - public List> getMultiblocks() { - return multiblocks; - } - - public void addMultiblocks(List> addedMultiblocks) { - multiblocks.addAll(addedMultiblocks); - } - - public AbstractCustomMultiblock(TemplatePaperPlugin plugin, CustomMultiblockManager customMultiblockManager, CustomMultiblock multiblockId) { - this.plugin = plugin; - - Bukkit.getPluginManager().registerEvents(this, plugin); - - customMultiblockManager.addCustomMultiblock(multiblockId, this); - } - - protected abstract List generateCustomMultiblock(Location placeLocation); - - public List getCustomMultiblock(Location placeLocation) { - List multiblock = generateCustomMultiblock(placeLocation); - - multiblocks.add(multiblock.stream().map((block) -> new BlockLocation(block)).toList()); - - return multiblock; - } - - public boolean isBlock(Block block) { - for (List multiblock : multiblocks) { - if (multiblock.contains(new BlockLocation(block))) { - return true; - } - } - - return false; - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblock.java b/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblock.java deleted file mode 100644 index d1b006b..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblock.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.slqmy.template_paper_plugin.custom_multiblock; - -public enum CustomMultiblock { - ; - - public static boolean isEnabled() { - return values().length != 0; - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblockManager.java b/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblockManager.java deleted file mode 100644 index ede235c..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblockManager.java +++ /dev/null @@ -1,129 +0,0 @@ -package net.slqmy.template_paper_plugin.custom_multiblock; - -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.bukkit.Location; - -import com.google.gson.Gson; - -import net.slqmy.template_paper_plugin.custom_multiblock.AbstractCustomMultiblock; -import net.slqmy.template_paper_plugin.custom_multiblock.CustomMultiblock; -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; - -public class CustomMultiblockManager { - - private final TemplatePaperPlugin plugin; - - private final String multiblocksFileExtension = ".json"; - private final String multiblocksResourceFilePath = "data" + File.separator + "multiblocks" + multiblocksFileExtension; - private final String multiblocksFilePath; - private final File multiblocksFile; - - private final Map customMultiblockMap = new HashMap<>(); - - public CustomMultiblockManager(TemplatePaperPlugin plugin) { - this.plugin = plugin; - - multiblocksFilePath = plugin.getDataFolder() + File.separator + multiblocksResourceFilePath; - multiblocksFile = new File(multiblocksFilePath); - - load(); - } - - public void addCustomMultiblock(CustomMultiblock multiblockId, AbstractCustomMultiblock abstractCustomMultiblock) { - customMultiblockMap.put(multiblockId, abstractCustomMultiblock); - } - - public AbstractCustomMultiblock getAbstractCustomMultiblock(CustomMultiblock multiblockId) { - return customMultiblockMap.get(multiblockId); - } - - public void placeCustomMultiblock(CustomMultiblock multiblockId, Location location) { - customMultiblockMap.get(multiblockId).getCustomMultiblock(location); - } - - public List getAllMultiblocks() { - List allMultiblocks = new ArrayList<>(); - - for (Entry multiblockInfo : customMultiblockMap.entrySet()) { - allMultiblocks.add(new StoredCustomMultiblock(multiblockInfo)); - } - - return allMultiblocks; - } - - private void load() { - if (!multiblocksFile.exists()) { - return; - } - - StoredCustomMultiblocks multiblocks; - - Gson gson = new Gson(); - try { - Reader reader = new FileReader(multiblocksFile); - - multiblocks = gson.fromJson(reader, StoredCustomMultiblocks.class); - - reader.close(); - } catch (IOException exception) { - exception.printStackTrace(); - return; - } - - loadStoredCustomMultiblocks(multiblocks); - } - - public void save() { - StoredCustomMultiblocks dataToSave = getStoredCustomMultiblocks(); - - if (dataToSave.getStoredCustomMultiblocks().size() == 0) { - return; - } - - if (!multiblocksFile.exists()) { - plugin.saveResource(multiblocksResourceFilePath, false); - } - - Gson gson = new Gson(); - - try { - Writer writer = new FileWriter(multiblocksFile); - - String json = gson.toJson(dataToSave); - - writer.write(json); - - writer.flush(); - writer.close(); - } catch (IOException exception) { - exception.printStackTrace(); - } - } - - public void loadStoredCustomMultiblocks(StoredCustomMultiblocks multiblocks) { - for (StoredCustomMultiblock multiblock : multiblocks.getStoredCustomMultiblocks()) { - customMultiblockMap.get(multiblock.getMultiblockId()).addMultiblocks(multiblock.getBlockLocations()); - } - } - - public StoredCustomMultiblocks getStoredCustomMultiblocks() { - StoredCustomMultiblocks output = new StoredCustomMultiblocks(); - - for (Entry multiblockInfo : customMultiblockMap.entrySet()) { - output.addCustomMultiblock(new StoredCustomMultiblock(multiblockInfo)); - } - - return output; - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/StoredCustomMultiblock.java b/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/StoredCustomMultiblock.java deleted file mode 100644 index 1b48991..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/StoredCustomMultiblock.java +++ /dev/null @@ -1,28 +0,0 @@ -package net.slqmy.template_paper_plugin.custom_multiblock; - -import java.util.List; -import java.util.Map.Entry; - -import net.slqmy.template_paper_plugin.util.types.BlockLocation; - -public class StoredCustomMultiblock { - private final List> blockLocations; - private final CustomMultiblock multiblockId; - - public List> getBlockLocations() { - return blockLocations; - } - - public CustomMultiblock getMultiblockId() { - return multiblockId; - } - - public StoredCustomMultiblock(List> blockLocations, CustomMultiblock multiblockId) { - this.blockLocations = blockLocations; - this.multiblockId = multiblockId; - } - - public StoredCustomMultiblock(Entry multiblockInfo) { - this(multiblockInfo.getValue().getMultiblocks(), multiblockInfo.getKey()); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/StoredCustomMultiblocks.java b/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/StoredCustomMultiblocks.java deleted file mode 100644 index 2e858e7..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/StoredCustomMultiblocks.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.slqmy.template_paper_plugin.custom_multiblock; - -import java.util.ArrayList; -import java.util.List; - -public class StoredCustomMultiblocks { - private List storedCustomMultiblocks = new ArrayList<>(); - - public List getStoredCustomMultiblocks() { - return storedCustomMultiblocks; - } - - public void addCustomMultiblock(StoredCustomMultiblock addedCustomMultiblocks) { - storedCustomMultiblocks.add(addedCustomMultiblocks); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_multientity/AbstractCustomMultientity.java b/src/main/java/net/slqmy/template_paper_plugin/custom_multientity/AbstractCustomMultientity.java deleted file mode 100644 index dcce3fe..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/custom_multientity/AbstractCustomMultientity.java +++ /dev/null @@ -1,51 +0,0 @@ -package net.slqmy.template_paper_plugin.custom_multientity; - -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.event.Listener; -import org.bukkit.persistence.PersistentDataType; - -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; - -public abstract class AbstractCustomMultientity implements Listener { - - protected final TemplatePaperPlugin plugin; - - private final CustomMultientity entityId; - - protected AbstractCustomMultientity(TemplatePaperPlugin plugin, CustomMultientityManager customMultientityManager, CustomMultientity entityId) { - this.plugin = plugin; - - this.entityId = entityId; - - Bukkit.getPluginManager().registerEvents(this, plugin); - - customMultientityManager.addCustomEntity(entityId, this); - } - - protected abstract List generateCustomEntity(Location spawnLocation); - - public List getCustomEntity(Location spawnLocation) { - List entities = generateCustomEntity(spawnLocation); - for (E entity : entities) { - entity.getPersistentDataContainer().set(plugin.getCustomEntityIdKey(), PersistentDataType.STRING, entityId.name()); - } - - return entities; - } - - public boolean isEntity(Entity entity) { - if (entity == null) { - return false; - } - - try { - return entityId == CustomMultientity.valueOf(entity.getPersistentDataContainer().get(plugin.getCustomEntityIdKey(), PersistentDataType.STRING)); - } catch (IllegalArgumentException | NullPointerException exception) { - return false; - } - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_multientity/CustomMultientity.java b/src/main/java/net/slqmy/template_paper_plugin/custom_multientity/CustomMultientity.java deleted file mode 100644 index f1103e3..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/custom_multientity/CustomMultientity.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.slqmy.template_paper_plugin.custom_multientity; - -public enum CustomMultientity { - ; - - public static boolean isEnabled() { - return values().length != 0; - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_multientity/CustomMultientityManager.java b/src/main/java/net/slqmy/template_paper_plugin/custom_multientity/CustomMultientityManager.java deleted file mode 100644 index 0953b29..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/custom_multientity/CustomMultientityManager.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.slqmy.template_paper_plugin.custom_multientity; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.bukkit.Location; -import org.bukkit.entity.Entity; - -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; -import net.slqmy.template_paper_plugin.custom_multientity.AbstractCustomMultientity; -import net.slqmy.template_paper_plugin.custom_multientity.CustomMultientity; - -public class CustomMultientityManager { - - private final Map> customMultientityMap = new HashMap<>(); - - public CustomMultientityManager(TemplatePaperPlugin plugin) { - - } - - public void addCustomEntity(CustomMultientity itemId, AbstractCustomMultientity customMultientity) { - customMultientityMap.put(itemId, customMultientity); - } - - public AbstractCustomMultientity getAbstractCustomEntity(CustomMultientity entityId) { - return customMultientityMap.get(entityId); - } - - public List spawnEntity(CustomMultientity entityId, Location location) { - return (List) getAbstractCustomEntity(entityId).getCustomEntity(location); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/data/player/PlayerDataManager.java b/src/main/java/net/slqmy/template_paper_plugin/data/player/PlayerDataManager.java deleted file mode 100644 index bfdd0f7..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/data/player/PlayerDataManager.java +++ /dev/null @@ -1,128 +0,0 @@ -package net.slqmy.template_paper_plugin.data.player; - -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.UUID; - -import org.bukkit.entity.Player; - -import com.google.gson.Gson; - -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; - -public class PlayerDataManager { - - private final TemplatePaperPlugin plugin; - - private final String playerDataFilesExtension = ".json"; - - private final String playerDataFolderName = "data" + File.separator + "player"; - private final String playerDataFolderPath; - private final File playerDataFolder; - - private final Map playerData = new HashMap<>(); - - public PlayerDataManager(TemplatePaperPlugin plugin) { - this.plugin = plugin; - - playerDataFolderPath = plugin.getDataPath() + File.separator + playerDataFolderName; - playerDataFolder = new File(playerDataFolderPath); - - load(); - } - - private void load() { - if (!playerDataFolder.exists()) { - return; - } - - Gson gson = new Gson(); - - File[] playerDataFiles = playerDataFolder.listFiles(); - for (File playerDataFile : playerDataFiles) { - String fileName = playerDataFile.getName(); - String playerUuidString = fileName.split("\\.", 2)[0]; - - UUID playerUuid = UUID.fromString(playerUuidString); - PlayerProfile profile; - - try { - FileReader reader = new FileReader(playerDataFile); - - profile = gson.fromJson(reader, PlayerProfile.class); - - reader.close(); - } catch (IOException exception) { - exception.printStackTrace(); - continue; - } - - playerData.put(playerUuid, profile); - } - } - - public void save() { - if (playerData.size() == 0) { - return; - } - - playerDataFolder.mkdir(); - - Gson gson = new Gson(); - - for (Entry entry : playerData.entrySet()) { - UUID uuid = entry.getKey(); - PlayerProfile profile = entry.getValue(); - - File file = new File(playerDataFolderPath + File.separator + uuid.toString() + playerDataFilesExtension); - - try { - file.createNewFile(); - - FileWriter writer = new FileWriter(file); - - String json = gson.toJson(profile); - - writer.write(json); - - writer.flush(); - writer.close(); - } catch (IOException exception) { - exception.printStackTrace(); - } - } - } - - public PlayerProfile getPlayerProfile(UUID uuid, boolean createNewProfile) { - PlayerProfile profile = playerData.get(uuid); - - if (profile == null) { - if (!createNewProfile) { - return null; - } - - profile = new PlayerProfile(uuid, plugin.getLanguageManager().getDefaultLanguage()); - - playerData.put(uuid, profile); - } - - return playerData.get(uuid); - } - - public PlayerProfile getPlayerProfile(UUID uuid) { - return getPlayerProfile(uuid, true); - } - - public PlayerProfile getPlayerProfile(Player player, boolean createNewProfile) { - return getPlayerProfile(player.getUniqueId(), createNewProfile); - } - - public PlayerProfile getPlayerProfile(Player player) { - return getPlayerProfile(player, true); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/data/player/PlayerProfile.java b/src/main/java/net/slqmy/template_paper_plugin/data/player/PlayerProfile.java deleted file mode 100644 index 64f3f52..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/data/player/PlayerProfile.java +++ /dev/null @@ -1,27 +0,0 @@ -package net.slqmy.template_paper_plugin.data.player; - -import java.util.UUID; - -public class PlayerProfile { - - private final UUID uuid; - - private String language; - - public UUID getUuid() { - return uuid; - } - - public String getLanguage() { - return language; - } - - public void setLanguage(String language) { - this.language = language; - } - - public PlayerProfile(UUID uuid, String language) { - this.uuid = uuid; - this.language = language; - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/file/FileManager.java b/src/main/java/net/slqmy/template_paper_plugin/file/FileManager.java deleted file mode 100644 index 0909b2e..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/file/FileManager.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.slqmy.template_paper_plugin.file; - -import java.io.File; -import java.io.IOException; - -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; - -public class FileManager { - - private final TemplatePaperPlugin plugin; - - public FileManager(TemplatePaperPlugin plugin) { - this.plugin = plugin; - } - - public File saveResourceFileFolder(String resourceFileFolderPath, boolean shouldReplaceExistingFiles) { - try { - FileUtil.getResourceFileFolderResourceFilePathsRecursively(resourceFileFolderPath).forEach((resourceFilePath) -> { - plugin.saveResource(resourceFilePath, shouldReplaceExistingFiles); - }); - return new File(plugin.getDataPath() + File.separator + resourceFileFolderPath); - } catch (IOException exception) { - exception.printStackTrace(); - return null; - } - } - - public File saveResourceFileFolder(String resourceFileFolderPath) { - return saveResourceFileFolder(resourceFileFolderPath, true); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/file/FileUtil.java b/src/main/java/net/slqmy/template_paper_plugin/file/FileUtil.java deleted file mode 100644 index 17ed3a6..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/file/FileUtil.java +++ /dev/null @@ -1,140 +0,0 @@ -package net.slqmy.template_paper_plugin.file; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.jar.JarFile; -import java.util.jar.JarEntry; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import net.lingala.zip4j.ZipFile; - -public class FileUtil { - - private static final String FILE_EXTENSION_SEPARATOR = "."; - - private static final String FILE_MIME_TYPE_TYPE_SUBTYPE_SEPARATOR = "/"; - - public static String getFileExtensionSeparator() { - return FILE_EXTENSION_SEPARATOR; - } - - public static String getFileMimeTypeTypeSubtypeSeparator() { - return FILE_MIME_TYPE_TYPE_SUBTYPE_SEPARATOR; - } - - public static List getResourceFileFolderResourceFilePaths(String resourceFileFolderPath) throws IOException { - ClassLoader classLoader = FileUtil.class.getClassLoader(); - - URL jarURL = classLoader.getResource(resourceFileFolderPath); - if (jarURL == null) { - return Collections.emptyList(); - } - - String jarPath = jarURL.getPath(); - int exclamationMarkIndex = jarPath.indexOf("!"); - - String jarPathPrefix = "file:"; - String jarFilePath = jarPath.substring(jarPathPrefix.length(), exclamationMarkIndex); - - try (JarFile jarFile = new JarFile(jarFilePath)) { - List paths = jarFile.stream().map(JarEntry::getName).filter(name -> name.startsWith(resourceFileFolderPath) && !name.equals(resourceFileFolderPath)) - .map(name -> name.substring(resourceFileFolderPath.length())).filter(name -> !"/".equals(name)).map(name -> resourceFileFolderPath + name).toList(); - - return paths; - } - } - - public static List getResourceFileFolderResourceFilePathsRecursively(String resourceFileFolderPath) throws IOException { - List paths = new ArrayList<>(); - - for (String resourceFilePath : getResourceFileFolderResourceFilePaths(resourceFileFolderPath)) { - List subFiles = getResourceFileFolderResourceFilePathsRecursively(resourceFilePath); - if (subFiles.isEmpty()) { - paths.add(resourceFilePath); - } else { - paths.addAll(subFiles); - } - } - - return paths; - } - - public static void zipFolder(File sourceFolder, File zipFile) throws IOException { - try (ZipFile zipFileInstance = new ZipFile(zipFile)) { - for (File file : sourceFolder.listFiles()) { - if (file.isDirectory()) { - zipFileInstance.addFolder(file); - } else { - zipFileInstance.addFile(file); - } - } - } - } - - public static boolean isDirectoryRecursivelyEmpty(File directory) { - if (!directory.isDirectory()) { - throw new IllegalArgumentException("The specified path is not a directory"); - } - - File[] files = directory.listFiles(); - - if (files == null || files.length == 0) { - return true; - } - - for (File file : files) { - if (file.isFile()) { - return false; - } else if (file.isDirectory()) { - if (!isDirectoryRecursivelyEmpty(file)) { - return false; - } - } - } - - return true; - } - - public static String getSha1HexString(File file) { - String algorithm = "SHA-1"; - - MessageDigest digest; - try (InputStream fileInputStream = new FileInputStream(file)) { - digest = MessageDigest.getInstance(algorithm); - - int n = 0; - byte[] buffer = new byte[8192]; - - while (n != -1) { - n = fileInputStream.read(buffer); - if (n > 0) { - digest.update(buffer, 0, n); - } - } - } catch (IOException | NoSuchAlgorithmException exception) { - exception.printStackTrace(); - return null; - } - - byte[] hashBytes = digest.digest(); - StringBuilder hexString = new StringBuilder(2 * hashBytes.length); - for (byte hashByte : hashBytes) { - String hex = Integer.toHexString(0xff & hashByte); - - if (hex.length() == 1) { - hexString.append('0'); - } - - hexString.append(hex); - } - - return hexString.toString(); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/http_server/HttpServerManager.java b/src/main/java/net/slqmy/template_paper_plugin/http_server/HttpServerManager.java deleted file mode 100644 index 580740d..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/http_server/HttpServerManager.java +++ /dev/null @@ -1,98 +0,0 @@ -package net.slqmy.template_paper_plugin.http_server; - -import com.sun.net.httpserver.HttpServer; -import com.sun.net.httpserver.HttpHandler; -import com.sun.net.httpserver.HttpExchange; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.net.InetSocketAddress; - -import org.bukkit.Bukkit; - -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; -import net.slqmy.template_paper_plugin.file.FileUtil; -import net.slqmy.template_paper_plugin.http_server.event.listeners.PlayerJoinListener; -import net.slqmy.template_paper_plugin.resource_pack.ResourcePackManager; - -public class HttpServerManager { - - private TemplatePaperPlugin plugin; - - private String hostName; - private int port; - - private final int successResponseCode = 200; - private final int notFoundResponseCode = 404; - - private HttpServer server; - - public int getPort() { - return server.getAddress().getPort(); - } - - public String getHostName() { - return server.getAddress().getHostName(); - } - - public String getSocketAddress() { - return getHostName() + ":" + getPort(); - } - - public HttpServerManager(TemplatePaperPlugin plugin) { - if (plugin.getResourcePackManager().getResourcePackZipFile() == null) { - return; - } - - this.plugin = plugin; - - hostName = Bukkit.getServer().getIp(); - port = plugin.getConfig().getInt("http-server.port"); - - try { - server = HttpServer.create(new InetSocketAddress(hostName, port), 0); - } catch (IOException exception) { - exception.printStackTrace(); - return; - } - - server.createContext("/", new ResourcePackDownloadHandler()); - - server.setExecutor(null); - server.start(); - - Bukkit.getPluginManager().registerEvents(new PlayerJoinListener(plugin, this), plugin); - } - - class ResourcePackDownloadHandler implements HttpHandler { - @Override - public void handle(HttpExchange exchange) throws IOException { - ResourcePackManager resourcePackManager = plugin.getResourcePackManager(); - - File file = new File(resourcePackManager.getResourceZipFilePath()); - - if (file.exists()) { - exchange.getResponseHeaders().set("Content-Type", resourcePackManager.getResourcePackFileMimeType()); - exchange.getResponseHeaders().set("Content-Disposition", "attachment; filename=\"" + resourcePackManager.getResourcePackResourceFolderName() + FileUtil.getFileExtensionSeparator() + resourcePackManager.getResourcePackFileExtension() + "\""); - - exchange.sendResponseHeaders(successResponseCode, file.length()); - - try (FileInputStream fileInputStream = new FileInputStream(file); OutputStream outputStream = exchange.getResponseBody()) { - byte[] buffer = new byte[1024]; - int count; - while ((count = fileInputStream.read(buffer)) != -1) { - outputStream.write(buffer, 0, count); - } - } - } else { - String response = "404 (Not Found)\n"; - exchange.sendResponseHeaders(notFoundResponseCode, response.length()); - OutputStream outputStream = exchange.getResponseBody(); - outputStream.write(response.getBytes()); - outputStream.close(); - } - } - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/http_server/event/listeners/PlayerJoinListener.java b/src/main/java/net/slqmy/template_paper_plugin/http_server/event/listeners/PlayerJoinListener.java deleted file mode 100644 index e1e6222..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/http_server/event/listeners/PlayerJoinListener.java +++ /dev/null @@ -1,30 +0,0 @@ -package net.slqmy.template_paper_plugin.http_server.event.listeners; - -import java.net.URI; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -import net.kyori.adventure.resource.ResourcePackInfo; -import net.kyori.adventure.resource.ResourcePackRequest; -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; -import net.slqmy.template_paper_plugin.file.FileUtil; -import net.slqmy.template_paper_plugin.http_server.HttpServerManager; - -public class PlayerJoinListener implements Listener { - - private ResourcePackInfo resourcePackInfo; - - public PlayerJoinListener(TemplatePaperPlugin plugin, HttpServerManager httpServerManager) { - resourcePackInfo = ResourcePackInfo.resourcePackInfo().hash(FileUtil.getSha1HexString(plugin.getResourcePackManager().getResourcePackZipFile())) - .uri(URI.create("http://" + httpServerManager.getSocketAddress() + "/")).build(); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - player.sendResourcePacks(ResourcePackRequest.resourcePackRequest().packs(resourcePackInfo).required(true).build()); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/language/LanguageManager.java b/src/main/java/net/slqmy/template_paper_plugin/language/LanguageManager.java deleted file mode 100644 index 4170bc6..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/language/LanguageManager.java +++ /dev/null @@ -1,317 +0,0 @@ -package net.slqmy.template_paper_plugin.language; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextReplacementConfig; -import net.kyori.adventure.text.minimessage.MiniMessage; -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; -import net.slqmy.template_paper_plugin.data.player.PlayerProfile; - -import java.util.UUID; -import java.util.stream.Stream; -import java.util.Map; -import java.util.Set; -import java.util.HashMap; -import java.util.Locale; -import java.io.File; - -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -public class LanguageManager { - - private final MiniMessage miniMessage = MiniMessage.miniMessage(); - - private final TemplatePaperPlugin plugin; - - private final String languageMessageFilesExtension = ".yaml"; - - private final String languagesFolderName = "languages"; - private final String languagesFolderPath; - private final File languagesFolder; - - private final String defaultLanguage; - - private final Map> languages = new HashMap<>(); - - public String getDefaultLanguage() { - return defaultLanguage; - } - - public Set getLanguages() { - return languages.keySet(); - } - - public LanguageManager(TemplatePaperPlugin plugin) { - this.plugin = plugin; - - languagesFolderPath = plugin.getDataPath() + File.separator + languagesFolderName; - languagesFolder = new File(languagesFolderPath); - - saveLanguageFiles(); - loadLanguageMessages(); - - defaultLanguage = plugin.getConfig().getString("language.default-language"); - } - - private void saveLanguageFiles() { - String languagesResourceFolderName = languagesFolderName; - plugin.getFileManager().saveResourceFileFolder(languagesResourceFolderName, !plugin.getConfig().getBoolean("language.use-custom-messages")); - } - - private void loadLanguageMessages() { - for (File languageMessagesFile : languagesFolder.listFiles()) { - String languageName = languageMessagesFile.getName().split("\\.", 2)[0]; - - String languageMessagesResourcePath = languagesFolderName + File.separator + languageName + languageMessageFilesExtension; - plugin.saveResource(languageMessagesResourcePath, false); - - YamlConfiguration messagesConfiguration = YamlConfiguration.loadConfiguration(languageMessagesFile); - Map messages = new HashMap<>(); - - for (Message message : Message.values()) { - String mappedResult = messagesConfiguration.getString(message.name()); - - if (mappedResult != null) { - messages.put(message, mappedResult); - } - } - - languages.put(languageName, messages); - } - } - - public String getLanguage(CommandSender commandSender) { - String language = getProfileLanguage(commandSender); - - if (language == null) { - language = getLocale(commandSender); - } - - return language; - } - - public String getLanguage(UUID uuid) { - String language = getProfileLanguage(uuid); - - if (language == null) { - language = getLocale(uuid); - } - - return language; - } - - public String getLanguage(PlayerProfile profile) { - return getLanguage(profile.getUuid()); - } - - public void setLanguage(PlayerProfile profile, String language) { - profile.setLanguage(language); - } - - public void setLanguage(UUID uuid, String language) { - setLanguage(plugin.getPlayerDataManager().getPlayerProfile(uuid), language); - } - - public void setLanguage(Player player, String language) { - setLanguage(player.getUniqueId(), language); - } - - private String getLocale(CommandSender commandSender) { - if (!(commandSender instanceof Player player)) { - return defaultLanguage; - } - - Locale playerLocale = player.locale(); - String localeDisplayName = playerLocale.getDisplayName(); - - if (!getLanguages().contains(localeDisplayName)) { - return defaultLanguage; - } - - return localeDisplayName; - } - - private String getLocale(UUID uuid) { - Player player = Bukkit.getPlayer(uuid); - return getLocale(player); - } - - private String getLocale(PlayerProfile profile) { - return getLocale(profile.getUuid()); - } - - private String getProfileLanguage(PlayerProfile profile) { - if (profile == null) { - return null; - } - - return profile.getLanguage(); - } - - private String getProfileLanguage(UUID uuid) { - return getProfileLanguage(plugin.getPlayerDataManager().getPlayerProfile(uuid)); - } - - private String getProfileLanguage(CommandSender commandSender) { - if (commandSender == null) { - return null; - } else if (commandSender instanceof Player player) { - return getProfileLanguage(player.getUniqueId()); - } else { - return defaultLanguage; - } - } - - private String getRawMessageString(Message message, String language, boolean fallbackOnDefaultLanguage) { - Map languageMessageMap = languages.get(language); - String miniMessageString = languageMessageMap.get(message); - - if (miniMessageString == null) { - return fallbackOnDefaultLanguage ? getRawMessageString(message, defaultLanguage, false) : null; - } - - return miniMessageString; - } - - private String getRawMessageString(Message message, String language) { - return getRawMessageString(message, language, true); - } - - private Component getMessage(Message message, String language, boolean fallbackOnDefaultLanguage, Component... arguments) { - String miniMessageString = getRawMessageString(message, language, fallbackOnDefaultLanguage); - - Component result = miniMessage.deserialize(miniMessageString); - - for (int i = 0; i < arguments.length; i++) { - final int argumentIndex = i; - - result = result.replaceText(TextReplacementConfig.builder().matchLiteral("{" + i + "}").replacement((matchResult, builder) -> { - return arguments[argumentIndex]; - }).build()); - } - - return result; - } - - private Component getMessage(Message message, String language, Component... arguments) { - return getMessage(message, language, true, arguments); - } - - private Component getMessage(Message message, String language, boolean fallbackOnDefaultLanguage, Object... arguments) { - return getMessage(message, language, fallbackOnDefaultLanguage, toComponents(arguments)); - } - - private Component getMessage(Message message, String language, Object... arguments) { - return getMessage(message, language, true, arguments); - } - - public Component getMessage(Message message, CommandSender commandSender, boolean fallbackOnDefaultLanguage, Component... arguments) { - return getMessage(message, getLanguage(commandSender), fallbackOnDefaultLanguage, arguments); - } - - public Component getMessage(Message message, CommandSender commandSender, Component... arguments) { - return getMessage(message, commandSender, true, arguments); - } - - public Component getMessage(Message message, CommandSender commandSender, boolean fallbackOnDefaultLanguage, Object... arguments) { - return getMessage(message, commandSender, fallbackOnDefaultLanguage, toComponents(arguments)); - } - - public Component getMessage(Message message, CommandSender commandSender, Object... arguments) { - return getMessage(message, commandSender, true, arguments); - } - - public Component getMessage(Message message, UUID uuid, boolean fallbackOnDefaultLanguage, Component... arguments) { - return getMessage(message, getLanguage(uuid), fallbackOnDefaultLanguage, arguments); - } - - public Component getMessage(Message message, UUID uuid, Component... arguments) { - return getMessage(message, uuid, true, arguments); - } - - public Component getMessage(Message message, UUID uuid, boolean fallbackOnDefaultLanguage, Object... arguments) { - return getMessage(message, uuid, fallbackOnDefaultLanguage, toComponents(arguments)); - } - - public Component getMessage(Message message, UUID uuid, Object... arguments) { - return getMessage(message, uuid, true, arguments); - } - - public Component getMessage(Message message, PlayerProfile playerProfile, boolean fallbackOnDefaultLanguage, Component... arguments) { - return getMessage(message, getLanguage(playerProfile), fallbackOnDefaultLanguage, arguments); - } - - public Component getMessage(Message message, PlayerProfile playerProfile, Component... arguments) { - return getMessage(message, playerProfile, true, arguments); - } - - public Component getMessage(Message message, PlayerProfile playerProfile, boolean fallbackOnDefaultLanguage, Object... arguments) { - return getMessage(message, playerProfile, fallbackOnDefaultLanguage, toComponents(arguments)); - } - - public Component getMessage(Message message, PlayerProfile playerProfile, Object... arguments) { - return getMessage(message, playerProfile, true, arguments); - } - - public void sendMessage(Message message, CommandSender commandSender, boolean fallbackOnDefaultLanguage, Component... arguments) { - commandSender.sendMessage(getMessage(message, getLanguage(commandSender), fallbackOnDefaultLanguage, arguments)); - } - - public void sendMessage(Message message, CommandSender commandSender, Component... arguments) { - commandSender.sendMessage(getMessage(message, commandSender, true, arguments)); - } - - public void sendMessage(Message message, CommandSender commandSender, boolean fallbackOnDefaultLanguage, Object... arguments) { - commandSender.sendMessage(getMessage(message, commandSender, fallbackOnDefaultLanguage, toComponents(arguments))); - } - - public void sendMessage(Message message, CommandSender commandSender, Object... arguments) { - commandSender.sendMessage(getMessage(message, commandSender, true, arguments)); - } - - public void sendMessage(Message message, UUID uuid, boolean fallbackOnDefaultLanguage, Component... arguments) { - Bukkit.getPlayer(uuid).sendMessage(getMessage(message, getLanguage(uuid), fallbackOnDefaultLanguage, arguments)); - } - - public void sendMessage(Message message, UUID uuid, Component... arguments) { - Bukkit.getPlayer(uuid).sendMessage(getMessage(message, uuid, true, arguments)); - } - - public void sendMessage(Message message, UUID uuid, boolean fallbackOnDefaultLanguage, Object... arguments) { - Bukkit.getPlayer(uuid).sendMessage(getMessage(message, uuid, fallbackOnDefaultLanguage, toComponents(arguments))); - } - - public void sendMessage(Message message, UUID uuid, Object... arguments) { - Bukkit.getPlayer(uuid).sendMessage(getMessage(message, uuid, true, arguments)); - } - - public void sendMessage(Message message, PlayerProfile playerProfile, boolean fallbackOnDefaultLanguage, Component... arguments) { - Bukkit.getPlayer(playerProfile.getUuid()).sendMessage(getMessage(message, getLanguage(playerProfile), fallbackOnDefaultLanguage, arguments)); - } - - public void sendMessage(Message message, PlayerProfile playerProfile, Component... arguments) { - Bukkit.getPlayer(playerProfile.getUuid()).sendMessage(getMessage(message, playerProfile, true, arguments)); - } - - public void sendMessage(Message message, PlayerProfile playerProfile, boolean fallbackOnDefaultLanguage, Object... arguments) { - Bukkit.getPlayer(playerProfile.getUuid()).sendMessage(getMessage(message, playerProfile, fallbackOnDefaultLanguage, toComponents(arguments))); - } - - public void sendMessage(Message message, PlayerProfile playerProfile, Object... arguments) { - Bukkit.getPlayer(playerProfile.getUuid()).sendMessage(getMessage(message, playerProfile, true, arguments)); - } - - private Component[] toComponents(Object... objects) { - return Stream.of(objects).map((object) -> toComponent(object)).toArray(Component[]::new); - } - - private Component toComponent(Object object) { - if (object instanceof Component component) { - return component; - } - - return Component.text(String.valueOf(object)); - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/language/Message.java b/src/main/java/net/slqmy/template_paper_plugin/language/Message.java deleted file mode 100644 index f1f1c77..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/language/Message.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.slqmy.template_paper_plugin.language; - -import java.util.function.BooleanSupplier; - -import net.slqmy.template_paper_plugin.custom_item.CustomItem; -import net.slqmy.template_paper_plugin.custom_multiblock.CustomMultiblock; -import net.slqmy.template_paper_plugin.custom_multientity.CustomMultientity; - -public enum Message { - SET_LANGUAGE_SUCCESSFULLY(() -> false), - UNKNOWN_LANGUAGE(() -> false), - - UNKNOWN_CUSTOM_ITEM(() -> CustomItem.isEnabled()), - UNKNOWN_CUSTOM_MULTIENTITY(() -> CustomMultientity.isEnabled()), - UNKNOWN_CUSTOM_MULTIBLOCK(() -> CustomMultiblock.isEnabled()); - - private final BooleanSupplier isMessageInUseSupplier; - - public boolean isMessageInUse() { - return isMessageInUseSupplier.getAsBoolean(); - } - - Message(BooleanSupplier isMessageInUseSupplier) { - this.isMessageInUseSupplier = isMessageInUseSupplier; - } - - Message() { - this(() -> true); - } - - public static boolean isEnabled() { - for (Message message : values()) { - if (message.isMessageInUse()) { - return true; - } - } - - return false; - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/resource_pack/ResourcePackManager.java b/src/main/java/net/slqmy/template_paper_plugin/resource_pack/ResourcePackManager.java deleted file mode 100644 index 10e83d6..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/resource_pack/ResourcePackManager.java +++ /dev/null @@ -1,84 +0,0 @@ -package net.slqmy.template_paper_plugin.resource_pack; - -import java.io.File; -import java.util.List; - -import org.apache.commons.io.FileUtils; - -import net.slqmy.template_paper_plugin.TemplatePaperPlugin; -import net.slqmy.template_paper_plugin.file.FileUtil; - -public class ResourcePackManager { - - private final TemplatePaperPlugin plugin; - - private final String resourcePackResourceFolderName = String.join(" ", TemplatePaperPlugin.class.getSimpleName().split("(?=[A-Z])")) + " Resource Pack"; - - private final String resourcePackFileType = "application"; - private final String resourcePackFileExtension = "zip"; - private final String resourcePackFileMimeType = resourcePackFileType + FileUtil.getFileMimeTypeTypeSubtypeSeparator() + resourcePackFileExtension; - - private final String resourcePackAssetsFolderName = "assets"; - - private String resourcePackZipFilePath; - private File resourcePackZipFile; - - public String getResourcePackFileType() { - return resourcePackFileType; - } - - public String getResourcePackFileExtension() { - return resourcePackFileExtension; - } - - public String getResourcePackFileMimeType() { - return resourcePackFileMimeType; - } - - public String getResourcePackResourceFolderName() { - return resourcePackResourceFolderName; - } - - public String getResourceZipFilePath() { - return resourcePackZipFilePath; - } - - public File getResourcePackZipFile() { - return resourcePackZipFile; - } - - public ResourcePackManager(TemplatePaperPlugin plugin) { - this.plugin = plugin; - - saveResourcepackZipFile(); - } - - private void saveResourcepackZipFile() { - File resourcePackFolder = plugin.getFileManager().saveResourceFileFolder(resourcePackResourceFolderName); - - String[] resourcePackFiles = resourcePackFolder.list(); - if (resourcePackFiles == null || resourcePackFiles.length == 0) { - return; - } - - if (!List.of(resourcePackFiles).contains(resourcePackAssetsFolderName)) { - return; - } - - File assetsFile = new File(plugin.getDataPath() + File.separator + resourcePackResourceFolderName + File.separator + resourcePackAssetsFolderName); - if (FileUtil.isDirectoryRecursivelyEmpty(assetsFile)) { - return; - } - - resourcePackZipFilePath = plugin.getDataPath() + File.separator + resourcePackResourceFolderName + FileUtil.getFileExtensionSeparator() + resourcePackFileExtension; - - try { - resourcePackZipFile = new File(resourcePackZipFilePath); - FileUtil.zipFolder(resourcePackFolder, resourcePackZipFile); - - FileUtils.deleteDirectory(resourcePackFolder); - } catch (Exception exception) { - exception.printStackTrace(); - } - } -} diff --git a/src/main/java/net/slqmy/template_paper_plugin/util/types/BlockLocation.java b/src/main/java/net/slqmy/template_paper_plugin/util/types/BlockLocation.java deleted file mode 100644 index da9c6c2..0000000 --- a/src/main/java/net/slqmy/template_paper_plugin/util/types/BlockLocation.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.slqmy.template_paper_plugin.util.types; - -import org.bukkit.Location; -import org.bukkit.block.Block; - -public class BlockLocation { - - private String worldName; - - private int x; - private int y; - private int z; - - public String getWorldName() { - return worldName; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public int getZ() { - return z; - } - - public BlockLocation(String worldName, int x, int y, int z) { - this.worldName = worldName; - this.x = x; - this.y = y; - this.z = z; - } - - public BlockLocation(Location location) { - this(location.getWorld().getName(), (int) location.getX(), (int) location.getY(), (int) location.getZ()); - } - - public BlockLocation(Block block) { - this(block.getLocation()); - } -} diff --git a/src/main/resources/Template Paper Plugin Resource Pack/pack.mcmeta b/src/main/resources/Template Paper Plugin Resource Pack/pack.mcmeta deleted file mode 100644 index df0d960..0000000 --- a/src/main/resources/Template Paper Plugin Resource Pack/pack.mcmeta +++ /dev/null @@ -1,6 +0,0 @@ -{ - "pack": { - "pack_format": 34, - "description": "The resource pack for the Template Paper Plugin" - } -} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 850e2bf..1f7e46f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,6 +1,9 @@ -language: - default-language: English (United Kingdom) - use-custom-messages: false +# This is the title that will be displayed once a player joins. +title: "&atitle" -http-server: - port: 8000 \ No newline at end of file +subtitle: + - "&asub1" + - "&asub2" + - "&asub3" + +seconds-before-changing: 5 diff --git a/src/main/resources/data/multiblock.json b/src/main/resources/data/multiblock.json deleted file mode 100644 index 0637a08..0000000 --- a/src/main/resources/data/multiblock.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/src/main/resources/languages/English (United Kingdom).yaml b/src/main/resources/languages/English (United Kingdom).yaml deleted file mode 100644 index 7c4cc11..0000000 --- a/src/main/resources/languages/English (United Kingdom).yaml +++ /dev/null @@ -1,6 +0,0 @@ -SET_LANGUAGE_SUCCESSFULLY: "Successfully set your language to {0}!" -UNKNOWN_LANGUAGE: "Unsupported or unknown language: '{0}'." - -UNKNOWN_CUSTOM_ITEM: "Unknown custom item: '{0}'." -UNKNOWN_CUSTOM_MULTIENTITY: "Unknown custom multientity: '{0}'." -UNKNOWN_CUSTOM_MULTIBLOCK: "Unknown custom multiblock: '{0}'." diff --git a/src/main/resources/languages/English (United States).yaml b/src/main/resources/languages/English (United States).yaml deleted file mode 100644 index 7c4cc11..0000000 --- a/src/main/resources/languages/English (United States).yaml +++ /dev/null @@ -1,6 +0,0 @@ -SET_LANGUAGE_SUCCESSFULLY: "Successfully set your language to {0}!" -UNKNOWN_LANGUAGE: "Unsupported or unknown language: '{0}'." - -UNKNOWN_CUSTOM_ITEM: "Unknown custom item: '{0}'." -UNKNOWN_CUSTOM_MULTIENTITY: "Unknown custom multientity: '{0}'." -UNKNOWN_CUSTOM_MULTIBLOCK: "Unknown custom multiblock: '{0}'."