diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c3baed0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/projects.iml b/.idea/projects.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/projects.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/BlockShuffle/BlockShuffle.iml b/BlockShuffle/BlockShuffle.iml new file mode 100644 index 0000000..810de34 --- /dev/null +++ b/BlockShuffle/BlockShuffle.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ChatColors/src/main/java/com/tqqn/chatcolors/ChatColors.java b/ChatColors/src/main/java/com/tqqn/chatcolors/ChatColors.java new file mode 100644 index 0000000..1798247 --- /dev/null +++ b/ChatColors/src/main/java/com/tqqn/chatcolors/ChatColors.java @@ -0,0 +1,63 @@ +package com.tqqn.chatcolors; + +import com.tqqn.chatcolors.colors.Colors; +import com.tqqn.chatcolors.commands.ChooseChatColorCommand; +import com.tqqn.chatcolors.listeners.ChatListener; +import com.tqqn.chatcolors.listeners.InteractInventoryListener; +import com.tqqn.chatcolors.listeners.JoinListener; +import com.tqqn.chatcolors.listeners.QuitListener; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.HashMap; + +public final class ChatColors extends JavaPlugin { + + private PlayerManager playerManager; + private HashMap loadedColors; + + private static int colorSize; + + @Override + public void onEnable() { + this.playerManager = new PlayerManager(this); + loadColors(); + registerListeners(); + registerCommands(); + colorSize = loadedColors.size(); + } + + @Override + public void onDisable() { + // Plugin shutdown logic + } + + private void loadColors() { + loadedColors = new HashMap<>(); + for (Colors color : Colors.values()) { + loadedColors.put(color.getGuiMaterial(), color); + } + } + + public static int getColorsSize() { + return colorSize; + } + + private void registerListeners() { + PluginManager pluginManager = Bukkit.getPluginManager(); + pluginManager.registerEvents(new ChatListener(playerManager), this); + pluginManager.registerEvents(new JoinListener(playerManager), this); + pluginManager.registerEvents(new QuitListener(playerManager), this); + pluginManager.registerEvents(new InteractInventoryListener(playerManager), this); + } + + private void registerCommands() { + this.getCommand("chatcolor").setExecutor(new ChooseChatColorCommand(playerManager)); + } + + public HashMap getLoadedColors() { + return loadedColors; + } +} diff --git a/ChatColors/src/main/java/com/tqqn/chatcolors/PlayerManager.java b/ChatColors/src/main/java/com/tqqn/chatcolors/PlayerManager.java new file mode 100644 index 0000000..65af3ba --- /dev/null +++ b/ChatColors/src/main/java/com/tqqn/chatcolors/PlayerManager.java @@ -0,0 +1,53 @@ +package com.tqqn.chatcolors; + +import com.tqqn.chatcolors.data.PluginPlayer; +import com.tqqn.chatcolors.gui.ChatColorGUI; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.UUID; + +public class PlayerManager { + + private final ChatColors plugin; + private final HashMap loadedPlayers; + private final HashMap openInventories; + + public PlayerManager(ChatColors plugin) { + this.plugin = plugin; + this.loadedPlayers = new HashMap<>(); + this.openInventories = new HashMap<>(); + } + + public ChatColors getPlugin() { + return plugin; + } + + public PluginPlayer getPluginPlayer(UUID uuid) { + return loadedPlayers.get(uuid); + } + + public void loadPluginPlayer(Player player) { + if (loadedPlayers.containsKey(player.getUniqueId())) return; + loadedPlayers.put(player.getUniqueId(), new PluginPlayer(player)); + } + + public void unLoadPluginPlayer(Player player) { + loadedPlayers.remove(player.getUniqueId()); + } + + public void openInventory(PluginPlayer pluginPlayer) { + openInventories.put(pluginPlayer.getUuid(), new ChatColorGUI(pluginPlayer)); + openInventories.get(pluginPlayer.getUuid()).openInventory(); + new ChatColorGUI(pluginPlayer).openInventory(); + } + + public void closeInventory(PluginPlayer pluginPlayer) { + openInventories.get(pluginPlayer.getUuid()).closeInventory(); + openInventories.remove(pluginPlayer.getUuid()); + } + + public boolean existPlayerInventory(PluginPlayer player) { + return openInventories.containsKey(player.getUuid()); + } +} diff --git a/ChatColors/src/main/java/com/tqqn/chatcolors/colors/Colors.java b/ChatColors/src/main/java/com/tqqn/chatcolors/colors/Colors.java new file mode 100644 index 0000000..cbddc7a --- /dev/null +++ b/ChatColors/src/main/java/com/tqqn/chatcolors/colors/Colors.java @@ -0,0 +1,33 @@ +package com.tqqn.chatcolors.colors; + +import org.bukkit.Material; + +public enum Colors { + + NONE("", "None", Material.BARRIER), + BLACK("", "Black", Material.BLACK_WOOL), + DARK_RED("", "Dark Red", Material.REDSTONE); + + private final String color; + private final String prettyName; + private final Material guiMaterial; + Colors(String color, String prettyName, Material guiMaterial) { + this.color = color; + this.prettyName = prettyName; + this.guiMaterial = guiMaterial; + } + + public String getColor() { + return color; + } + + public String getPrettyName() { + return prettyName; + } + + public Material getGuiMaterial() { + return guiMaterial; + } + +} + diff --git a/ChatColors/src/main/java/com/tqqn/chatcolors/commands/ChooseChatColorCommand.java b/ChatColors/src/main/java/com/tqqn/chatcolors/commands/ChooseChatColorCommand.java new file mode 100644 index 0000000..96710a4 --- /dev/null +++ b/ChatColors/src/main/java/com/tqqn/chatcolors/commands/ChooseChatColorCommand.java @@ -0,0 +1,24 @@ +package com.tqqn.chatcolors.commands; + +import com.tqqn.chatcolors.PlayerManager; +import com.tqqn.chatcolors.gui.ChatColorGUI; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class ChooseChatColorCommand implements CommandExecutor { + + private final PlayerManager playerManager; + + public ChooseChatColorCommand(PlayerManager playerManager) { + this.playerManager = playerManager; + } + @Override + public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { + if (!(commandSender instanceof Player player)) return true; + playerManager.openInventory(playerManager.getPluginPlayer(player.getUniqueId())); + return true; + } +} diff --git a/ChatColors/src/main/java/com/tqqn/chatcolors/data/PluginPlayer.java b/ChatColors/src/main/java/com/tqqn/chatcolors/data/PluginPlayer.java new file mode 100644 index 0000000..6475ad1 --- /dev/null +++ b/ChatColors/src/main/java/com/tqqn/chatcolors/data/PluginPlayer.java @@ -0,0 +1,43 @@ +package com.tqqn.chatcolors.data; + +import com.tqqn.chatcolors.colors.Colors; +import org.bukkit.entity.Player; + +import java.util.UUID; + +public class PluginPlayer { + + private final Player player; + private final UUID uuid; + private final String name; + + + private Colors selectedColor; + + public PluginPlayer(Player player) { + this.player = player; + this.uuid = player.getUniqueId(); + this.name = player.getName(); + this.selectedColor = Colors.NONE; + } + + public Player getPlayer() { + return player; + } + + public UUID getUuid() { + return uuid; + } + + public String getName() { + return name; + } + + public Colors getSelectedColor() { + return selectedColor; + } + + public void setSelectedColor(Colors selectedColor) { + this.selectedColor = selectedColor; + } +} diff --git a/ChatColors/src/main/java/com/tqqn/chatcolors/gui/ChatColorGUI.java b/ChatColors/src/main/java/com/tqqn/chatcolors/gui/ChatColorGUI.java new file mode 100644 index 0000000..c2f2053 --- /dev/null +++ b/ChatColors/src/main/java/com/tqqn/chatcolors/gui/ChatColorGUI.java @@ -0,0 +1,75 @@ +package com.tqqn.chatcolors.gui; + +import com.tqqn.chatcolors.ChatColors; +import com.tqqn.chatcolors.colors.Colors; +import com.tqqn.chatcolors.data.PluginPlayer; +import com.tqqn.chatcolors.utils.ChatUtils; +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class ChatColorGUI { + + private final PluginPlayer player; + private final Inventory inventory; + + public ChatColorGUI(PluginPlayer player) { + this.player = player; + + this.inventory = Bukkit.createInventory(null, getFinalInventorySize(ChatColors.getColorsSize()), ChatUtils.format("ChatColor menu")); + initInventoryItems(); + } + + private int getFinalInventorySize(int size) { + if (size <= 9) return 9; + if (size <= 18) return 18; + if (size <= 27) return 27; + if (size <= 36) return 36; + if (size <= 45) return 45; + if (size <= 54) return 54; + return 0; + } + + private void initInventoryItems() { + int slot = 0; + for (Colors colors : Colors.values()) { + if (colors.equals(Colors.NONE)) continue; + inventory.setItem(slot, createGUIItem(colors, player.getSelectedColor().equals(colors))); + slot++; + } + + inventory.setItem(slot, createGUIItem(Colors.NONE, player.getSelectedColor().equals(Colors.NONE))); + } + + private ItemStack createGUIItem(Colors color, boolean isChosen) { + + ItemStack itemStack = new ItemStack(color.getGuiMaterial()); + ItemMeta meta = itemStack.getItemMeta(); + Component name; + + if (isChosen) { + name = ChatUtils.format("[Selected] " + color.getPrettyName()); + meta.addEnchant(Enchantment.DURABILITY, 0, true); + meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + } else { + name = ChatUtils.format(color.getPrettyName()); + } + + meta.displayName(name); + itemStack.setItemMeta(meta); + + return itemStack; + } + + public void openInventory() { + player.getPlayer().openInventory(inventory); + } + + public void closeInventory() { + player.getPlayer().closeInventory(); + } +} diff --git a/ChatColors/src/main/java/com/tqqn/chatcolors/listeners/ChatListener.java b/ChatColors/src/main/java/com/tqqn/chatcolors/listeners/ChatListener.java new file mode 100644 index 0000000..082a522 --- /dev/null +++ b/ChatColors/src/main/java/com/tqqn/chatcolors/listeners/ChatListener.java @@ -0,0 +1,27 @@ +package com.tqqn.chatcolors.listeners; + +import com.tqqn.chatcolors.PlayerManager; +import com.tqqn.chatcolors.data.PluginPlayer; +import com.tqqn.chatcolors.utils.ChatUtils; +import io.papermc.paper.event.player.AsyncChatEvent; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class ChatListener implements Listener { + + private final PlayerManager playerManager; + + public ChatListener(PlayerManager playerManager) { + this.playerManager = playerManager; + } + + @EventHandler + public void onAsyncChat(AsyncChatEvent event) { + event.setCancelled(true); + PluginPlayer pluginPlayer = playerManager.getPluginPlayer(event.getPlayer().getUniqueId()); + + Bukkit.getOnlinePlayers().forEach(players -> players.sendMessage(ChatUtils.format("" + pluginPlayer.getName() + ": " + pluginPlayer.getSelectedColor().getColor() + ((TextComponent)event.message()).content()))); + } +} diff --git a/ChatColors/src/main/java/com/tqqn/chatcolors/listeners/InteractInventoryListener.java b/ChatColors/src/main/java/com/tqqn/chatcolors/listeners/InteractInventoryListener.java new file mode 100644 index 0000000..6efec4f --- /dev/null +++ b/ChatColors/src/main/java/com/tqqn/chatcolors/listeners/InteractInventoryListener.java @@ -0,0 +1,54 @@ +package com.tqqn.chatcolors.listeners; + +import com.tqqn.chatcolors.PlayerManager; +import com.tqqn.chatcolors.colors.Colors; +import com.tqqn.chatcolors.data.PluginPlayer; +import com.tqqn.chatcolors.utils.ChatUtils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; + +public class InteractInventoryListener implements Listener { + + private final PlayerManager playerManager; + + public InteractInventoryListener(PlayerManager playerManager) { + this.playerManager = playerManager; + } + + @EventHandler + public void onInteract(InventoryClickEvent event) { + if (!(event.getWhoClicked() instanceof Player player)) return; + if (!(event.getView().getOriginalTitle().equalsIgnoreCase("§cChatColor menu"))) return; + event.setCancelled(true); + + if (event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR) return; + + PluginPlayer pluginPlayer = playerManager.getPluginPlayer(player.getUniqueId()); + + if (event.getCurrentItem().getType() == pluginPlayer.getSelectedColor().getGuiMaterial()) { + player.sendMessage(ChatUtils.format("You have already selected this.")); + playerManager.closeInventory(pluginPlayer); + return; + } + + if (playerManager.getPlugin().getLoadedColors().containsKey(event.getCurrentItem().getType())) { + Colors color = playerManager.getPlugin().getLoadedColors().get(event.getCurrentItem().getType()); + pluginPlayer.setSelectedColor(color); + player.sendMessage(ChatUtils.format("You have selected " + color.getColor() + color.getPrettyName() + "!")); + playerManager.closeInventory(pluginPlayer); + } + + + + } + + @EventHandler + public void onInventoryClose(InventoryCloseEvent event) { + if (playerManager.existPlayerInventory(playerManager.getPluginPlayer(event.getPlayer().getUniqueId()))) return; + playerManager.closeInventory(playerManager.getPluginPlayer(event.getPlayer().getUniqueId())); + } +} diff --git a/ChatColors/src/main/java/com/tqqn/chatcolors/listeners/JoinListener.java b/ChatColors/src/main/java/com/tqqn/chatcolors/listeners/JoinListener.java new file mode 100644 index 0000000..20a516e --- /dev/null +++ b/ChatColors/src/main/java/com/tqqn/chatcolors/listeners/JoinListener.java @@ -0,0 +1,20 @@ +package com.tqqn.chatcolors.listeners; + +import com.tqqn.chatcolors.PlayerManager; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class JoinListener implements Listener { + + private final PlayerManager playerManager; + + public JoinListener(PlayerManager playerManager) { + this.playerManager = playerManager; + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + playerManager.loadPluginPlayer(event.getPlayer()); + } +} diff --git a/ChatColors/src/main/java/com/tqqn/chatcolors/listeners/QuitListener.java b/ChatColors/src/main/java/com/tqqn/chatcolors/listeners/QuitListener.java new file mode 100644 index 0000000..b49ce1a --- /dev/null +++ b/ChatColors/src/main/java/com/tqqn/chatcolors/listeners/QuitListener.java @@ -0,0 +1,19 @@ +package com.tqqn.chatcolors.listeners; + +import com.tqqn.chatcolors.PlayerManager; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +public class QuitListener implements Listener { + + private final PlayerManager playerManager; + public QuitListener(PlayerManager playerManager) { + this.playerManager = playerManager; + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + playerManager.unLoadPluginPlayer(event.getPlayer()); + } +} diff --git a/ChatColors/src/main/java/com/tqqn/chatcolors/utils/ChatUtils.java b/ChatColors/src/main/java/com/tqqn/chatcolors/utils/ChatUtils.java new file mode 100644 index 0000000..7648c98 --- /dev/null +++ b/ChatColors/src/main/java/com/tqqn/chatcolors/utils/ChatUtils.java @@ -0,0 +1,12 @@ +package com.tqqn.chatcolors.utils; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; + +public class ChatUtils { + + public static Component format(String message) { + MiniMessage miniMessage = MiniMessage.builder().build(); + return miniMessage.deserialize(message); + } +} diff --git a/ChatColors/src/main/resources/plugin.yml b/ChatColors/src/main/resources/plugin.yml new file mode 100644 index 0000000..3c274f1 --- /dev/null +++ b/ChatColors/src/main/resources/plugin.yml @@ -0,0 +1,10 @@ +name: ChatColors +version: '${project.version}' +main: com.tqqn.chatcolors.ChatColors +api-version: '1.20' +load: STARTUP +commands: + chatcolor: + description: Choose a chatcolor + usage: / + permission: chatcolor.menu \ No newline at end of file diff --git a/ChatGames/ChatGames.iml b/ChatGames/ChatGames.iml new file mode 100644 index 0000000..f76df2b --- /dev/null +++ b/ChatGames/ChatGames.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/CustomItems/CustomItems.iml b/CustomItems/CustomItems.iml new file mode 100644 index 0000000..f76df2b --- /dev/null +++ b/CustomItems/CustomItems.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/DiscordVerification/DiscordVerification.iml b/DiscordVerification/DiscordVerification.iml new file mode 100644 index 0000000..f76df2b --- /dev/null +++ b/DiscordVerification/DiscordVerification.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/FreezeWand/FreezeWand.iml b/FreezeWand/FreezeWand.iml new file mode 100644 index 0000000..e84e8cd --- /dev/null +++ b/FreezeWand/FreezeWand.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/GrapplingHooks/GrapplingHooks.iml b/GrapplingHooks/GrapplingHooks.iml new file mode 100644 index 0000000..f76df2b --- /dev/null +++ b/GrapplingHooks/GrapplingHooks.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/InvSee/InvSee.iml b/InvSee/InvSee.iml new file mode 100644 index 0000000..f76df2b --- /dev/null +++ b/InvSee/InvSee.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Particles/Particles.iml b/Particles/Particles.iml new file mode 100644 index 0000000..f76df2b --- /dev/null +++ b/Particles/Particles.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ProximityChat/ProximityChat.iml b/ProximityChat/ProximityChat.iml new file mode 100644 index 0000000..f76df2b --- /dev/null +++ b/ProximityChat/ProximityChat.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/StaffChat/StaffChat.iml b/StaffChat/StaffChat.iml new file mode 100644 index 0000000..f76df2b --- /dev/null +++ b/StaffChat/StaffChat.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Warps/Warps.iml b/Warps/Warps.iml new file mode 100644 index 0000000..f76df2b --- /dev/null +++ b/Warps/Warps.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/WelcomeManager/WelcomeManager.iml b/WelcomeManager/WelcomeManager.iml new file mode 100644 index 0000000..f76df2b --- /dev/null +++ b/WelcomeManager/WelcomeManager.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file