mirror of
https://github.com/TotalFreedomMC/PlayerParticles.git
synced 2025-02-11 03:29:53 +00:00
Starting work on new GUI
This commit is contained in:
parent
a341870ad5
commit
f7eb08e48d
16 changed files with 1347 additions and 1080 deletions
4
pom.xml
4
pom.xml
|
@ -23,6 +23,8 @@
|
|||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<fork>true</fork>
|
||||
<executable>C:\Program Files\Java\jdk1.8.0_161\bin\javac</executable>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -195,7 +197,7 @@
|
|||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.23.1</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
/*
|
||||
* TODO: v5.3
|
||||
* + Add new style 'tornado'
|
||||
* * Adjust PParticles to use a Vector instead of a Location
|
||||
* * Setting in config.yml to disable non-event styles while the player is moving
|
||||
* * Finish rewriting the GUI
|
||||
*/
|
||||
|
||||
package com.esophose.playerparticles;
|
||||
|
@ -21,7 +23,7 @@ import com.esophose.playerparticles.command.ParticleCommandHandler;
|
|||
import com.esophose.playerparticles.database.DatabaseConnector;
|
||||
import com.esophose.playerparticles.database.MySqlDatabaseConnector;
|
||||
import com.esophose.playerparticles.database.SqliteDatabaseConnector;
|
||||
import com.esophose.playerparticles.gui.PlayerParticlesGui;
|
||||
import com.esophose.playerparticles.gui.GuiHandler;
|
||||
import com.esophose.playerparticles.manager.LangManager;
|
||||
import com.esophose.playerparticles.manager.ParticleManager;
|
||||
import com.esophose.playerparticles.manager.SettingManager;
|
||||
|
@ -69,7 +71,7 @@ public class PlayerParticles extends JavaPlugin {
|
|||
|
||||
Bukkit.getPluginManager().registerEvents(new ParticleManager(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new PluginUpdateListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerParticlesGui(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new GuiHandler(), this);
|
||||
|
||||
saveDefaultConfig();
|
||||
double configVersion = PSetting.VERSION.getDouble();
|
||||
|
@ -109,7 +111,7 @@ public class PlayerParticles extends JavaPlugin {
|
|||
*/
|
||||
public void onDisable() {
|
||||
databaseConnector.closeConnection();
|
||||
PlayerParticlesGui.forceCloseAllOpenGUIs();
|
||||
GuiHandler.forceCloseAllOpenGUIs();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,7 +126,7 @@ public class PlayerParticles extends JavaPlugin {
|
|||
particleTask = null;
|
||||
databaseConnector.closeConnection();
|
||||
databaseConnector = null;
|
||||
PlayerParticlesGui.forceCloseAllOpenGUIs();
|
||||
GuiHandler.forceCloseAllOpenGUIs();
|
||||
} else {
|
||||
DefaultStyles.registerStyles(); // Only ever load styles once
|
||||
}
|
||||
|
@ -136,7 +138,7 @@ public class PlayerParticles extends JavaPlugin {
|
|||
LangManager.reload(updatePluginSettings);
|
||||
ParticleGroup.reload();
|
||||
|
||||
PlayerParticlesGui.setup();
|
||||
GuiHandler.setup();
|
||||
|
||||
ParticleManager.refreshData();
|
||||
startParticleTask();
|
||||
|
@ -172,6 +174,11 @@ public class PlayerParticles extends JavaPlugin {
|
|||
if (useMySql) {
|
||||
databaseConnector = new MySqlDatabaseConnector();
|
||||
} else {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC"); // This is required to put here for Spigot 1.9 and 1.10 for some reason
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
databaseConnector = new SqliteDatabaseConnector(this.getDataFolder().getAbsolutePath());
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,10 @@ package com.esophose.playerparticles.command;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.esophose.playerparticles.gui.PlayerParticlesGui;
|
||||
import com.esophose.playerparticles.gui.PlayerParticlesGui.GuiState;
|
||||
import com.esophose.playerparticles.gui.GuiHandler;
|
||||
import com.esophose.playerparticles.manager.LangManager;
|
||||
import com.esophose.playerparticles.manager.PermissionManager;
|
||||
import com.esophose.playerparticles.manager.LangManager.Lang;
|
||||
import com.esophose.playerparticles.manager.PermissionManager;
|
||||
import com.esophose.playerparticles.particles.PPlayer;
|
||||
|
||||
public class GUICommandModule implements CommandModule {
|
||||
|
@ -18,7 +17,7 @@ public class GUICommandModule implements CommandModule {
|
|||
byDefault = true;
|
||||
}
|
||||
|
||||
if (PlayerParticlesGui.isGuiDisabled()) {
|
||||
if (GuiHandler.isGuiDisabled()) {
|
||||
if (byDefault) {
|
||||
LangManager.sendMessage(pplayer, Lang.COMMAND_ERROR_UNKNOWN);
|
||||
} else {
|
||||
|
@ -40,7 +39,7 @@ public class GUICommandModule implements CommandModule {
|
|||
LangManager.sendMessage(pplayer, Lang.GUI_BY_DEFAULT);
|
||||
}
|
||||
|
||||
PlayerParticlesGui.changeState(pplayer, GuiState.DEFAULT);
|
||||
GuiHandler.openDefault(pplayer);
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(PPlayer pplayer, String[] args) {
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
package com.esophose.playerparticles.gui;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
|
||||
|
||||
public class ColorData {
|
||||
private DyeColor dyeColor;
|
||||
private Material material;
|
||||
private OrdinaryColor ordinaryColor;
|
||||
private String name;
|
||||
|
||||
public ColorData(DyeColor dyeColor, Material material, OrdinaryColor ordinaryColor, String name) {
|
||||
this.dyeColor = dyeColor;
|
||||
this.material = material;
|
||||
this.ordinaryColor = ordinaryColor;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DyeColor
|
||||
*
|
||||
* @return The DyeColor
|
||||
*/
|
||||
public DyeColor getDyeColor() {
|
||||
return this.dyeColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Material representing this color
|
||||
*
|
||||
* @return The Material
|
||||
*/
|
||||
public Material getMaterial() {
|
||||
return this.material;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the OrdinaryColor representing this color
|
||||
*
|
||||
* @return The OrdinaryColor
|
||||
*/
|
||||
public OrdinaryColor getOrdinaryColor() {
|
||||
return this.ordinaryColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this color
|
||||
*
|
||||
* @return The name of this color
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
100
src/com/esophose/playerparticles/gui/GuiActionButton.java
Normal file
100
src/com/esophose/playerparticles/gui/GuiActionButton.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package com.esophose.playerparticles.gui;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class GuiActionButton {
|
||||
|
||||
private int slot;
|
||||
private Material[] icons;
|
||||
private String[] names;
|
||||
private String[] lore;
|
||||
private boolean glowing;
|
||||
private GuiActionButtonClickCallback onClick;
|
||||
private int iconIndex;
|
||||
|
||||
public GuiActionButton(int slot, Material[] icons, String[] names, String[] lore, boolean glowing, GuiActionButtonClickCallback onClick) {
|
||||
this.slot = slot;
|
||||
this.icons = icons;
|
||||
this.names = names;
|
||||
this.lore = lore;
|
||||
this.glowing = glowing;
|
||||
this.onClick = onClick;
|
||||
|
||||
if (icons.length != names.length)
|
||||
throw new IllegalArgumentException("icons and names must have the same length!");
|
||||
}
|
||||
|
||||
public GuiActionButton(int slot, Material icon, String name, String[] lore, boolean glowing, GuiActionButtonClickCallback onClick) {
|
||||
this(slot, new Material[] { icon }, new String[] { name }, lore, glowing, onClick);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the slot this GuiActionButton occupies in the GuiInventory
|
||||
*
|
||||
* @return The slot this GuiActionButton occupies in the GuiInventory
|
||||
*/
|
||||
public int getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ItemStack icon that goes into the GUI
|
||||
*
|
||||
* @return The icon ItemStack for the GUI
|
||||
*/
|
||||
public ItemStack getIcon() {
|
||||
ItemStack itemStack = new ItemStack(icons[this.iconIndex]);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
itemMeta.setDisplayName(this.names[this.iconIndex]);
|
||||
itemMeta.setLore(Arrays.asList(this.lore));
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_ENCHANTS);
|
||||
|
||||
if (this.glowing)
|
||||
itemMeta.addEnchant(Enchantment.ARROW_INFINITE, 1, false);
|
||||
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the onClick callback passed in the constructor
|
||||
*
|
||||
* @param isShiftClick If the player was holding shift when they clicked
|
||||
*/
|
||||
public void handleClick(boolean isShiftClick) {
|
||||
if (this.onClick != null)
|
||||
this.onClick.execute(isShiftClick);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ticked at an interval to allow the icon/name to update
|
||||
*/
|
||||
public void onTick() {
|
||||
this.iconIndex = (this.iconIndex + 1) % this.names.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this GuiActionButton has more than one icon/name that it can cycle through
|
||||
*
|
||||
* @return If this GuiActionButton has more than one icon/name
|
||||
*/
|
||||
public boolean isTickable() {
|
||||
return this.icons.length > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows button click callbacks as parameters
|
||||
*/
|
||||
public static interface GuiActionButtonClickCallback {
|
||||
public void execute(boolean isShiftClick);
|
||||
}
|
||||
|
||||
}
|
153
src/com/esophose/playerparticles/gui/GuiHandler.java
Normal file
153
src/com/esophose/playerparticles/gui/GuiHandler.java
Normal file
|
@ -0,0 +1,153 @@
|
|||
package com.esophose.playerparticles.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.esophose.playerparticles.PlayerParticles;
|
||||
import com.esophose.playerparticles.manager.DataManager;
|
||||
import com.esophose.playerparticles.manager.SettingManager.PSetting;
|
||||
import com.esophose.playerparticles.particles.PPlayer;
|
||||
|
||||
/**
|
||||
* This class provides a collection of static methods for modifying your
|
||||
* particle/style/data through the use of a GUI
|
||||
*/
|
||||
public class GuiHandler extends BukkitRunnable implements Listener {
|
||||
|
||||
private static List<GuiInventory> guiInventories = new ArrayList<GuiInventory>();
|
||||
|
||||
/**
|
||||
* Initializes all the static values for this class
|
||||
*/
|
||||
public static void setup() {
|
||||
new GuiHandler().runTaskTimer(PlayerParticles.getPlugin(), 0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ticks GuiInventories
|
||||
* Removes entries from playerGuiInventories if the player no longer has the inventory open or is offline
|
||||
*/
|
||||
public void run() {
|
||||
List<GuiInventory> toRemoveList = new ArrayList<GuiInventory>();
|
||||
|
||||
for (GuiInventory inventory : guiInventories) {
|
||||
PPlayer pplayer = DataManager.getPPlayer(inventory.getPPlayer().getUniqueId());
|
||||
if (pplayer == null) {
|
||||
toRemoveList.add(inventory);
|
||||
continue;
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(inventory.getPPlayer().getUniqueId());
|
||||
if (player == null) {
|
||||
toRemoveList.add(inventory);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inventory.getInventory().equals(player.getOpenInventory().getTopInventory())) {
|
||||
toRemoveList.add(inventory);
|
||||
continue;
|
||||
}
|
||||
|
||||
inventory.onTick();
|
||||
}
|
||||
|
||||
for (GuiInventory inventory : toRemoveList)
|
||||
guiInventories.remove(inventory);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player)) return;
|
||||
Player player = (Player)event.getWhoClicked();
|
||||
|
||||
GuiInventory inventory = getGuiInventory(player);
|
||||
if (inventory == null) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
inventory.onClick(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the GUI is disabled by the server owner or not
|
||||
*
|
||||
* @return True if the GUI is disabled
|
||||
*/
|
||||
public static boolean isGuiDisabled() {
|
||||
return !PSetting.GUI_ENABLED.getBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully closes all open PlayerParticles GUIs
|
||||
* Used for when the plugin unloads so players can't take items from the GUI
|
||||
*/
|
||||
public static void forceCloseAllOpenGUIs() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
for (GuiInventory inventory : guiInventories) {
|
||||
if (inventory.getPPlayer().getUniqueId().equals(player.getUniqueId()) && inventory.getInventory().equals(player.getOpenInventory().getTopInventory())) {
|
||||
player.closeInventory();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
guiInventories.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the default GUI screen for a player
|
||||
*
|
||||
* @param pplayer The PPlayer to open the GUI screen for
|
||||
*/
|
||||
public static void openDefault(PPlayer pplayer) {
|
||||
removeGuiInventory(pplayer);
|
||||
|
||||
GuiInventoryDefault defaultInventory = new GuiInventoryDefault(pplayer);
|
||||
guiInventories.add(defaultInventory);
|
||||
|
||||
pplayer.getPlayer().openInventory(defaultInventory.getInventory());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the player's inventory to another one
|
||||
*/
|
||||
protected static void transition(GuiInventory nextInventory) {
|
||||
removeGuiInventory(nextInventory.getPPlayer());
|
||||
guiInventories.add(nextInventory);
|
||||
nextInventory.getPPlayer().getPlayer().openInventory(nextInventory.getInventory());
|
||||
System.out.println("Transitioned inventories");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a GuiInventory by Player
|
||||
*
|
||||
* @param player The Player
|
||||
* @return The GuiInventory belonging to the Player, if any
|
||||
*/
|
||||
private static GuiInventory getGuiInventory(Player player) {
|
||||
for (GuiInventory inventory : guiInventories)
|
||||
if (inventory.getPPlayer().getUniqueId().equals(player.getUniqueId()))
|
||||
return inventory;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a GuiInventory from guiInventories by a PPlayer
|
||||
*
|
||||
* @param pplayer The PPlayer who owns the GuiInventory
|
||||
*/
|
||||
private static void removeGuiInventory(PPlayer pplayer) {
|
||||
for (GuiInventory inventory : guiInventories) {
|
||||
if (inventory.getPPlayer().getUniqueId().equals(pplayer.getUniqueId())) {
|
||||
guiInventories.remove(inventory);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
807
src/com/esophose/playerparticles/gui/GuiHandlerOLD.java
Normal file
807
src/com/esophose/playerparticles/gui/GuiHandlerOLD.java
Normal file
|
@ -0,0 +1,807 @@
|
|||
//package com.esophose.playerparticles.gui;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Arrays;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.Random;
|
||||
//import java.util.UUID;
|
||||
//
|
||||
//import org.bukkit.Bukkit;
|
||||
//import org.bukkit.ChatColor;
|
||||
//import org.bukkit.DyeColor;
|
||||
//import org.bukkit.Material;
|
||||
//import org.bukkit.Particle;
|
||||
//import org.bukkit.SkullType;
|
||||
//import org.bukkit.configuration.file.FileConfiguration;
|
||||
//import org.bukkit.enchantments.Enchantment;
|
||||
//import org.bukkit.entity.Player;
|
||||
//import org.bukkit.event.EventHandler;
|
||||
//import org.bukkit.event.Listener;
|
||||
//import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
//import org.bukkit.inventory.Inventory;
|
||||
//import org.bukkit.inventory.InventoryView;
|
||||
//import org.bukkit.inventory.ItemFlag;
|
||||
//import org.bukkit.inventory.ItemStack;
|
||||
//import org.bukkit.inventory.meta.ItemMeta;
|
||||
//import org.bukkit.inventory.meta.SkullMeta;
|
||||
//import org.bukkit.material.Dye;
|
||||
//import org.bukkit.scheduler.BukkitRunnable;
|
||||
//
|
||||
//import com.esophose.playerparticles.PlayerParticles;
|
||||
//import com.esophose.playerparticles.manager.DataManager;
|
||||
//import com.esophose.playerparticles.manager.LangManager;
|
||||
//import com.esophose.playerparticles.manager.LangManager.Lang;
|
||||
//import com.esophose.playerparticles.manager.PermissionManager;
|
||||
//import com.esophose.playerparticles.manager.SettingManager.PSetting;
|
||||
//import com.esophose.playerparticles.particles.PPlayer;
|
||||
//import com.esophose.playerparticles.particles.ParticleEffect;
|
||||
//import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
|
||||
//import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
|
||||
//import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
|
||||
//import com.esophose.playerparticles.styles.api.ParticleStyle;
|
||||
//import com.esophose.playerparticles.styles.api.ParticleStyleManager;
|
||||
//import com.esophose.playerparticles.util.ParticleUtils;
|
||||
//
|
||||
///**
|
||||
// * This class provides a collection of static methods for modifying your
|
||||
// * particle/style/data through the use of a GUI
|
||||
// */
|
||||
//public class GuiHandlerOLD extends BukkitRunnable implements Listener {
|
||||
//
|
||||
// public static final int INVENTORY_SIZE = 54;
|
||||
// private static HashMap<PPlayer, GuiInventory> playerGuiInventories;
|
||||
//
|
||||
// /**
|
||||
// * Cached icons to prevent calling config over and over
|
||||
// */
|
||||
// private static Material[] defaultMenuIcons = new Material[3];
|
||||
// private static HashMap<String, Material> effectIcons;
|
||||
// private static HashMap<String, Material> styleIcons;
|
||||
//
|
||||
// /**
|
||||
// * Maps to convert from clicked materials to particle colors
|
||||
// */
|
||||
// private static ColorData[] colorMapping;
|
||||
//
|
||||
// /**
|
||||
// * DyeColor array in the order of the rainbow
|
||||
// * Color index for the wool color to display next
|
||||
// */
|
||||
// private static DyeColor[] rainbowColors;
|
||||
// private static int rainbowColorsIndex = 0;
|
||||
//
|
||||
// /**
|
||||
// * Cached material data
|
||||
// */
|
||||
// private static final Random RANDOM = new Random();
|
||||
// private static List<Material> BLOCK_MATERIALS = new ArrayList<Material>();
|
||||
// private static List<Material> ITEM_MATERIALS = new ArrayList<Material>();
|
||||
//
|
||||
// static { // @formatter:off
|
||||
// colorMapping = new ColorData[] {
|
||||
// new ColorData(DyeColor.RED, ParticleUtils.closestMatch("ROSE_RED"), new OrdinaryColor(255, 0, 0), ChatColor.RED + "red"),
|
||||
// new ColorData(DyeColor.ORANGE, ParticleUtils.closestMatch("ORANGE_DYE"), new OrdinaryColor(255, 140, 0), ChatColor.GOLD + "orange"),
|
||||
// new ColorData(DyeColor.YELLOW, ParticleUtils.closestMatch("DANDELION_YELLOW"), new OrdinaryColor(255, 255, 0), ChatColor.YELLOW + "yellow"),
|
||||
// new ColorData(DyeColor.LIME, ParticleUtils.closestMatch("LIME_DYE"), new OrdinaryColor(50, 205, 50), ChatColor.GREEN + "lime green"),
|
||||
// new ColorData(DyeColor.GREEN, ParticleUtils.closestMatch("CACTUS_GREEN"), new OrdinaryColor(0, 128, 0), ChatColor.DARK_GREEN + "green"),
|
||||
// new ColorData(DyeColor.BLUE, ParticleUtils.closestMatch("LAPIZ_LAZULI"), new OrdinaryColor(0, 0, 255), ChatColor.DARK_BLUE + "blue"),
|
||||
// new ColorData(DyeColor.CYAN, ParticleUtils.closestMatch("CYAN_DYE"), new OrdinaryColor(0, 139, 139), ChatColor.DARK_AQUA + "cyan"),
|
||||
// new ColorData(DyeColor.LIGHT_BLUE, ParticleUtils.closestMatch("LIGHT_BLUE_DYE"), new OrdinaryColor(173, 216, 230), ChatColor.AQUA + "light blue"),
|
||||
// new ColorData(DyeColor.PURPLE, ParticleUtils.closestMatch("PURPLE_DYE"), new OrdinaryColor(138, 43, 226), ChatColor.DARK_PURPLE + "purple"),
|
||||
// new ColorData(DyeColor.MAGENTA, ParticleUtils.closestMatch("MAGENTA_DYE"), new OrdinaryColor(202, 31, 123), ChatColor.LIGHT_PURPLE + "magenta"),
|
||||
// new ColorData(DyeColor.PINK, ParticleUtils.closestMatch("PINK_DYE"), new OrdinaryColor(255, 182, 193), ChatColor.LIGHT_PURPLE + "pink"),
|
||||
// new ColorData(DyeColor.BROWN, ParticleUtils.closestMatch("COCOA_BEANS"), new OrdinaryColor(139, 69, 19), ChatColor.GOLD + "brown"),
|
||||
// new ColorData(DyeColor.BLACK, ParticleUtils.closestMatch("INK_SAC"), new OrdinaryColor(0, 0, 0), ChatColor.DARK_GRAY + "black"),
|
||||
// new ColorData(DyeColor.GRAY, ParticleUtils.closestMatch("GRAY_DYE"), new OrdinaryColor(128, 128, 128), ChatColor.DARK_GRAY + "gray"),
|
||||
// new ColorData(DyeColor.getByDyeData((byte)7), ParticleUtils.closestMatch("LIGHT_GRAY_DYE"), new OrdinaryColor(192, 192, 192), ChatColor.GRAY + "light gray"),
|
||||
// new ColorData(DyeColor.WHITE, ParticleUtils.closestMatch("BONE_MEAL"), new OrdinaryColor(255, 255, 255), ChatColor.WHITE + "white"),
|
||||
// };
|
||||
//
|
||||
// rainbowColors = new DyeColor[] {
|
||||
// DyeColor.RED,
|
||||
// DyeColor.ORANGE,
|
||||
// DyeColor.YELLOW,
|
||||
// DyeColor.LIME,
|
||||
// DyeColor.LIGHT_BLUE,
|
||||
// DyeColor.BLUE,
|
||||
// DyeColor.PURPLE
|
||||
// };
|
||||
//
|
||||
// Inventory testingInventory = Bukkit.createInventory(null, 9);
|
||||
// for (Material mat : Material.values()) {
|
||||
// // Verify an ItemStack of the material can be placed into an inventory. In 1.12 and up this can easily be checked with mat.isItem(), but that doesn't exist pre-1.12
|
||||
// testingInventory.clear();
|
||||
// testingInventory.setItem(0, new ItemStack(mat, 1));
|
||||
// ItemStack itemStack = testingInventory.getItem(0);
|
||||
// if (itemStack != null) {
|
||||
// if (mat.isBlock()) {
|
||||
// BLOCK_MATERIALS.add(mat);
|
||||
// } else if (!mat.isBlock()) {
|
||||
// ITEM_MATERIALS.add(mat);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } // @formatter:on
|
||||
//
|
||||
// /**
|
||||
// * Initializes all the static values for this class
|
||||
// */
|
||||
// public static void setup() {
|
||||
// FileConfiguration config = PlayerParticles.getPlugin().getConfig();
|
||||
//
|
||||
// if (!PSetting.GUI_ENABLED.getBoolean()) return;
|
||||
//
|
||||
// playerGuiInventories = new HashMap<UUID, GuiInventory>();
|
||||
// effectIcons = new HashMap<String, Material>();
|
||||
// styleIcons = new HashMap<String, Material>();
|
||||
//
|
||||
// defaultMenuIcons[0] = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.main-menu.EFFECT"));
|
||||
// defaultMenuIcons[1] = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.main-menu.STYLE"));
|
||||
// defaultMenuIcons[2] = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.main-menu.DATA"));
|
||||
//
|
||||
// // Grab a different effect icon set based on if the Minecraft version is >= 1.13 or not
|
||||
// String legacy;
|
||||
// try {
|
||||
// Particle.valueOf("NAUTILUS");
|
||||
// legacy = "";
|
||||
// } catch (Exception ex) {
|
||||
// legacy = "-legacy";
|
||||
// }
|
||||
//
|
||||
// for (ParticleEffect effect : ParticleEffect.getSupportedEffects()) {
|
||||
// String effectName = effect.getName().toUpperCase();
|
||||
// Material iconMaterial = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.effect" + legacy + "." + effectName));
|
||||
// effectIcons.put(effectName, iconMaterial);
|
||||
// }
|
||||
//
|
||||
// for (ParticleStyle style : ParticleStyleManager.getStyles()) {
|
||||
// String styleName = style.getName().toUpperCase();
|
||||
// Material iconMaterial = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.style" + legacy + "." + styleName));
|
||||
// styleIcons.put(styleName, iconMaterial);
|
||||
// }
|
||||
//
|
||||
// new GuiHandlerOLD().runTaskTimer(PlayerParticles.getPlugin(), 0, 10);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Updates all color/note data inventories to display the rainbow icon
|
||||
// * Removes any players who are no longer online from playerGuiInventoriesd
|
||||
// */
|
||||
// public void run() {
|
||||
// List<UUID> toRemoveList = new ArrayList<UUID>();
|
||||
//
|
||||
// for (Map.Entry<UUID, GuiInventory> entry : playerGuiInventories.entrySet()) {
|
||||
// UUID playerUUID = entry.getKey();
|
||||
// PPlayer pplayer = DataManager.getPPlayer(playerUUID);
|
||||
// if (pplayer == null) {
|
||||
// toRemoveList.add(playerUUID);
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// Player player = Bukkit.getPlayer(playerUUID);
|
||||
// if (player == null) {
|
||||
// toRemoveList.add(playerUUID);
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// GuiInventory guiInventory = entry.getValue();
|
||||
// Inventory inventory = guiInventory.getInventory();
|
||||
//
|
||||
// if (player.getOpenInventory().getTopInventory().equals(inventory) && guiInventory.getGuiState() == GuiState.DATA && getPPlayerEffect(pplayer).hasProperty(ParticleProperty.COLORABLE)) {
|
||||
// ItemStack rainbowIcon;
|
||||
// if (getPPlayerEffect(pplayer) != ParticleEffect.NOTE) {
|
||||
// rainbowIcon = getItemForRainbowColorData(getPPlayerColor(pplayer), rainbowColors[rainbowColorsIndex]);
|
||||
// } else {
|
||||
// rainbowIcon = getItemForRainbowNoteData(getPPlayerNoteColor(pplayer), rainbowColors[rainbowColorsIndex]);
|
||||
// }
|
||||
// inventory.setItem(40, rainbowIcon);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (UUID uuid : toRemoveList)
|
||||
// playerGuiInventories.remove(uuid);
|
||||
//
|
||||
// rainbowColorsIndex++;
|
||||
// rainbowColorsIndex %= rainbowColors.length;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets if the GUI is disabled by the server owner or not
|
||||
// *
|
||||
// * @return True if the GUI is disabled
|
||||
// */
|
||||
// public static boolean isGuiDisabled() {
|
||||
// return !PSetting.GUI_ENABLED.getBoolean();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Forcefully closes all open PlayerParticles GUIs
|
||||
// * Used for when the plugin unloads so players can't take items from the GUI
|
||||
// */
|
||||
// public static void forceCloseAllOpenGUIs() {
|
||||
// for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
// InventoryView openInventory = p.getOpenInventory();
|
||||
// if (openInventory == null) continue;
|
||||
// Inventory topInventory = openInventory.getTopInventory();
|
||||
// if (topInventory == null) continue;
|
||||
//
|
||||
// // Check if any of the inventories are the one the user has open, close if true
|
||||
// for (GuiInventory guiInventory : playerGuiInventories.values()) {
|
||||
// if (topInventory.equals(guiInventory.getInventory())) {
|
||||
// p.closeInventory();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Opens the default GUI screen for a player
|
||||
// *
|
||||
// * @param pplayer The PPlayer to open the GUI screen for
|
||||
// */
|
||||
// public static void openDefault(PPlayer pplayer) {
|
||||
// if (playerGuiInventories.containsKey(pplayer)) {
|
||||
// playerGuiInventories.remove(pplayer);
|
||||
// }
|
||||
//
|
||||
// GuiInventoryDefault defaultInventory = new GuiInventoryDefault(pplayer, Bukkit.createInventory(pplayer.getPlayer(), INVENTORY_SIZE, "PlayerParticles"));
|
||||
// playerGuiInventories.put(pplayer, defaultInventory);
|
||||
//
|
||||
// pplayer.getPlayer().openInventory(defaultInventory.getInventory());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Changes the player's inventory to another one
|
||||
// */
|
||||
// protected static void transition(PPlayer pplayer, GuiInventory nextInventory) {
|
||||
// playerGuiInventories.replace(pplayer, nextInventory);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Changes the GUI to the indicated state
|
||||
// * If the GUI isn't open yet, it gets opened
|
||||
// *
|
||||
// * @param pplayer The pplayer
|
||||
// * @param state The new state
|
||||
// */
|
||||
// public static void changeState(PPlayer pplayer, GuiState state) {
|
||||
// Player player = pplayer.getPlayer();
|
||||
//
|
||||
// if ((state == GuiState.EFFECT && PermissionManager.getEffectsUserHasPermissionFor(player).isEmpty()) || (state == GuiState.STYLE && PermissionManager.getStylesUserHasPermissionFor(player).size() == 1) || (state == GuiState.DATA && getPPlayerSpawnMaterial(pplayer) == null && getPPlayerSpawnColor(pplayer) == null)) return;
|
||||
//
|
||||
// // Update the state and create an inventory for the player if one isn't already open for them
|
||||
// // If they have the wrong inventory open for some reason, create a new one and open it for them
|
||||
// if (playerGuiInventories.containsKey(pplayer.getUniqueId())) {
|
||||
// GuiInventory guiInventory = playerGuiInventories.get(pplayer.getUniqueId());
|
||||
// guiInventory.setGuiState(state);
|
||||
// if (!player.getOpenInventory().getTopInventory().equals(guiInventory.getInventory())) {
|
||||
// player.openInventory(guiInventory.getInventory());
|
||||
// }
|
||||
// } else {
|
||||
// Inventory ppInventory = Bukkit.createInventory(null, INVENTORY_SIZE, "PlayerParticles");
|
||||
// player.openInventory(ppInventory);
|
||||
// playerGuiInventories.put(pplayer.getUniqueId(), new GuiInventory(ppInventory, state));
|
||||
// }
|
||||
//
|
||||
// switch (state) {
|
||||
// case DEFAULT:
|
||||
// populateDefault(pplayer);
|
||||
// break;
|
||||
// case EFFECT:
|
||||
// populateEffect(pplayer);
|
||||
// break;
|
||||
// case STYLE:
|
||||
// populateStyle(pplayer);
|
||||
// break;
|
||||
// case DATA:
|
||||
// populateData(pplayer);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Opens the menu to go to other menus: effect, style, data
|
||||
// *
|
||||
// * @param pplayer The PPlayer
|
||||
// */
|
||||
// private static void populateDefault(PPlayer pplayer) {
|
||||
// Player player = pplayer.getPlayer();
|
||||
// Inventory inventory = player.getOpenInventory().getTopInventory();
|
||||
//
|
||||
// inventory.clear(); // Make sure the inventory is always empty before we start adding items
|
||||
//
|
||||
// ItemStack currentIcon;
|
||||
// Material playerHead = ParticleUtils.closestMatch("PLAYER_HEAD");
|
||||
// if (playerHead != null) {
|
||||
// currentIcon = new ItemStack(playerHead, 1);
|
||||
// } else {
|
||||
// currentIcon = new ItemStack(ParticleUtils.closestMatch("SKULL_ITEM"), 1, (short) SkullType.PLAYER.ordinal());
|
||||
// }
|
||||
//
|
||||
// SkullMeta currentIconMeta = (SkullMeta) currentIcon.getItemMeta();
|
||||
// currentIconMeta.setDisplayName(ChatColor.GREEN + player.getName());
|
||||
// String[] currentIconLore = new String[3];
|
||||
// currentIconLore[0] = ChatColor.YELLOW + "Effect: " + ChatColor.AQUA + getPPlayerEffect(pplayer).getName();
|
||||
// currentIconLore[1] = ChatColor.YELLOW + "Style: " + ChatColor.AQUA + getPPlayerStyle(pplayer).getName();
|
||||
// currentIconLore[2] = ChatColor.YELLOW + "Active Data: " + ChatColor.AQUA + getPPlayerDataString(pplayer);
|
||||
// currentIconMeta.setLore(Arrays.asList(currentIconLore));
|
||||
// currentIconMeta.setOwner(player.getName());
|
||||
// // currentIconMeta.setOwningPlayer(Bukkit.getOfflinePlayer(player.getUniqueId())); // This doesn't exist in 1.9
|
||||
// currentIcon.setItemMeta(currentIconMeta);
|
||||
//
|
||||
// ItemStack effectIcon = new ItemStack(defaultMenuIcons[0], 1);
|
||||
// ItemMeta effectIconMeta = effectIcon.getItemMeta();
|
||||
// effectIconMeta.setDisplayName(ChatColor.GREEN + "Effect");
|
||||
// effectIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SET_YOUR, "effect")));
|
||||
// if (PermissionManager.getEffectsUserHasPermissionFor(player).isEmpty()) {
|
||||
// effectIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_NO_ACCESS_TO, "effects")));
|
||||
// }
|
||||
// effectIcon.setItemMeta(effectIconMeta);
|
||||
//
|
||||
// ItemStack styleIcon = new ItemStack(defaultMenuIcons[1], 1);
|
||||
// ItemMeta styleIconMeta = styleIcon.getItemMeta();
|
||||
// styleIconMeta.setDisplayName(ChatColor.GREEN + "Style");
|
||||
// styleIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SET_YOUR, "style")));
|
||||
// if (PermissionManager.getStylesUserHasPermissionFor(player).size() == 1) { // Always has access to NORMAL
|
||||
// styleIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_NO_ACCESS_TO, "styles")));
|
||||
// }
|
||||
// styleIcon.setItemMeta(styleIconMeta);
|
||||
//
|
||||
// ItemStack dataIcon = new ItemStack(defaultMenuIcons[2], 1);
|
||||
// ItemMeta dataIconMeta = dataIcon.getItemMeta();
|
||||
// dataIconMeta.setDisplayName(ChatColor.GREEN + "Data");
|
||||
// ParticleEffect pe = getPPlayerEffect(pplayer);
|
||||
// String dataType = "data";
|
||||
// if (pe.hasProperty(ParticleProperty.COLORABLE)) // @formatter:off
|
||||
// if (pe == ParticleEffect.NOTE) dataType = "note " + dataType;
|
||||
// else dataType = "color " + dataType;
|
||||
// else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) if (pe == ParticleEffect.ITEM) dataType = "item " + dataType;
|
||||
// else dataType = "block " + dataType; // @formatter:on
|
||||
// dataIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SET_YOUR, dataType)));
|
||||
// if (getPPlayerSpawnMaterial(pplayer) == null && getPPlayerSpawnColor(pplayer) == null) {
|
||||
// dataIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_NO_DATA)));
|
||||
// }
|
||||
// dataIcon.setItemMeta(dataIconMeta);
|
||||
//
|
||||
// inventory.setItem(13, currentIcon);
|
||||
// inventory.setItem(38, effectIcon);
|
||||
// inventory.setItem(40, styleIcon);
|
||||
// inventory.setItem(42, dataIcon);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Opens the menu that allows you to select an effect you have permission for
|
||||
// *
|
||||
// * @param pplayer The PPlayer
|
||||
// */
|
||||
// private static void populateEffect(PPlayer pplayer) {
|
||||
// Player player = pplayer.getPlayer();
|
||||
// Inventory inventory = player.getOpenInventory().getTopInventory();
|
||||
// inventory.clear(); // Make sure the inventory is always empty before we start adding items
|
||||
//
|
||||
// List<String> effectsUserHasPermissionFor = PermissionManager.getEffectsUserHasPermissionFor(player);
|
||||
// for (int i = 0; i < effectsUserHasPermissionFor.size(); i++) {
|
||||
// String s = effectsUserHasPermissionFor.get(i);
|
||||
// ParticleEffect effect = ParticleEffect.fromName(s);
|
||||
// inventory.setItem(i, getItemForEffect(effect, effect == getPPlayerEffect(pplayer)));
|
||||
// }
|
||||
//
|
||||
// inventory.setItem(INVENTORY_SIZE - 1, getItemForBack());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Opens the menu that allows you to select a style you have permission for
|
||||
// *
|
||||
// * @param pplayer The PPlayer
|
||||
// */
|
||||
// private static void populateStyle(PPlayer pplayer) {
|
||||
// Player player = pplayer.getPlayer();
|
||||
// Inventory inventory = player.getOpenInventory().getTopInventory();
|
||||
//
|
||||
// inventory.clear(); // Make sure the inventory is always empty before we start adding items
|
||||
//
|
||||
// List<String> stylesUserHasPermissionFor = PermissionManager.getStylesUserHasPermissionFor(player);
|
||||
// for (int i = 0; i < stylesUserHasPermissionFor.size(); i++) {
|
||||
// String s = stylesUserHasPermissionFor.get(i);
|
||||
// ParticleStyle style = ParticleStyle.fromName(s);
|
||||
// inventory.setItem(i, getItemForStyle(style, style == getPPlayerStyle(pplayer)));
|
||||
// }
|
||||
//
|
||||
// inventory.setItem(INVENTORY_SIZE - 1, getItemForBack());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Opens the menu that allows you to select some preset data
|
||||
// *
|
||||
// * @param pplayer The PPlayer
|
||||
// */
|
||||
// private static void populateData(PPlayer pplayer) {
|
||||
// Player player = pplayer.getPlayer();
|
||||
// Inventory inventory = player.getOpenInventory().getTopInventory();
|
||||
//
|
||||
// inventory.clear(); // Make sure the inventory is always empty before we start adding items
|
||||
//
|
||||
// // There are a lot of for loops here, somebody submit a pull request if you have a better way of doing this
|
||||
// ParticleEffect pe = getPPlayerEffect(pplayer);
|
||||
// if (pe.hasProperty(ParticleProperty.COLORABLE)) {
|
||||
// if (pe == ParticleEffect.NOTE) { // Note data
|
||||
// NoteColor currentNote = getPPlayerNoteColor(pplayer);
|
||||
// int noteIndex = 0;
|
||||
// for (int i = 1; i <= 7; i++) { // Top row
|
||||
// inventory.setItem(i, getItemForNoteData(currentNote, noteIndex));
|
||||
// noteIndex++;
|
||||
// }
|
||||
// for (int i = 10; i <= 16; i++) { // Middle 1 row
|
||||
// inventory.setItem(i, getItemForNoteData(currentNote, noteIndex));
|
||||
// noteIndex++;
|
||||
// }
|
||||
// for (int i = 19; i <= 25; i++) { // Middle 2 row
|
||||
// inventory.setItem(i, getItemForNoteData(currentNote, noteIndex));
|
||||
// noteIndex++;
|
||||
// }
|
||||
// for (int i = 28; i <= 30; i++) { // Bottom row
|
||||
// inventory.setItem(i, getItemForNoteData(currentNote, noteIndex));
|
||||
// noteIndex++;
|
||||
// }
|
||||
//
|
||||
// inventory.setItem(40, getItemForRainbowNoteData(getPPlayerNoteColor(pplayer), rainbowColors[rainbowColorsIndex]));
|
||||
// } else { // Color data
|
||||
// OrdinaryColor currentColor = getPPlayerColor(pplayer);
|
||||
// int colorIndex = 0;
|
||||
// for (int i = 10; i <= 16; i++) { // Top row
|
||||
// inventory.setItem(i, getItemForColorData(currentColor, colorIndex));
|
||||
// colorIndex++;
|
||||
// }
|
||||
// for (int i = 19; i <= 25; i++) { // Middle row
|
||||
// inventory.setItem(i, getItemForColorData(currentColor, colorIndex));
|
||||
// colorIndex++;
|
||||
// }
|
||||
// for (int i = 28; i <= 29; i++) { // Bottom row
|
||||
// inventory.setItem(i, getItemForColorData(currentColor, colorIndex));
|
||||
// colorIndex++;
|
||||
// }
|
||||
//
|
||||
// inventory.setItem(40, getItemForRainbowColorData(getPPlayerColor(pplayer), rainbowColors[rainbowColorsIndex]));
|
||||
// }
|
||||
// } else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
||||
// List<Material> materialBag = new ArrayList<Material>();
|
||||
// int materialIndex = 0;
|
||||
//
|
||||
// if (pe == ParticleEffect.ITEM) { // Item data
|
||||
// Material currentItemMaterial = getPPlayerItemMaterial(pplayer);
|
||||
//
|
||||
// while (materialBag.size() < 28) { // Grab 28 random materials that are an item
|
||||
// Material randomMaterial = ITEM_MATERIALS.get(RANDOM.nextInt(ITEM_MATERIALS.size()));
|
||||
// if (!materialBag.contains(randomMaterial)) materialBag.add(randomMaterial);
|
||||
// }
|
||||
//
|
||||
// for (int i = 10; i <= 16; i++) { // Top row
|
||||
// inventory.setItem(i, getItemForMaterialData(currentItemMaterial, "item", materialBag.get(materialIndex)));
|
||||
// materialIndex++;
|
||||
// }
|
||||
// for (int i = 19; i <= 25; i++) { // Middle 1 row
|
||||
// inventory.setItem(i, getItemForMaterialData(currentItemMaterial, "item", materialBag.get(materialIndex)));
|
||||
// materialIndex++;
|
||||
// }
|
||||
// for (int i = 28; i <= 34; i++) { // Middle 2 row
|
||||
// inventory.setItem(i, getItemForMaterialData(currentItemMaterial, "item", materialBag.get(materialIndex)));
|
||||
// materialIndex++;
|
||||
// }
|
||||
// for (int i = 37; i <= 43; i++) { // Bottom row
|
||||
// inventory.setItem(i, getItemForMaterialData(currentItemMaterial, "item", materialBag.get(materialIndex)));
|
||||
// materialIndex++;
|
||||
// }
|
||||
// } else { // Block data
|
||||
// Material currentBlockMaterial = getPPlayerBlockMaterial(pplayer);
|
||||
//
|
||||
// while (materialBag.size() < 28) { // Grab 28 random materials that are an item
|
||||
// Material randomMaterial = BLOCK_MATERIALS.get(RANDOM.nextInt(BLOCK_MATERIALS.size()));
|
||||
// if (!materialBag.contains(randomMaterial)) materialBag.add(randomMaterial);
|
||||
// }
|
||||
//
|
||||
// for (int i = 10; i <= 16; i++) { // Top row
|
||||
// inventory.setItem(i, getItemForMaterialData(currentBlockMaterial, "block", materialBag.get(materialIndex)));
|
||||
// materialIndex++;
|
||||
// }
|
||||
// for (int i = 19; i <= 25; i++) { // Middle 1 row
|
||||
// inventory.setItem(i, getItemForMaterialData(currentBlockMaterial, "block", materialBag.get(materialIndex)));
|
||||
// materialIndex++;
|
||||
// }
|
||||
// for (int i = 28; i <= 34; i++) { // Middle 2 row
|
||||
// inventory.setItem(i, getItemForMaterialData(currentBlockMaterial, "block", materialBag.get(materialIndex)));
|
||||
// materialIndex++;
|
||||
// }
|
||||
// for (int i = 37; i <= 43; i++) { // Bottom row
|
||||
// inventory.setItem(i, getItemForMaterialData(currentBlockMaterial, "block", materialBag.get(materialIndex)));
|
||||
// materialIndex++;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// inventory.setItem(INVENTORY_SIZE - 1, getItemForBack());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Called whenever something is clicked in an inventory
|
||||
// * Will return immediately if not the particlesInventory
|
||||
// *
|
||||
// * @param e The InventoryClickEvent fired from this event
|
||||
// */
|
||||
// @EventHandler
|
||||
// public void onInventoryInteract(InventoryClickEvent e) {
|
||||
// if (isGuiDisabled()) return; // Don't worry about processing anything if the GUI is disabled
|
||||
//
|
||||
// if (!(e.getWhoClicked() instanceof Player)) return; // Not sure if I actually have to check this
|
||||
//
|
||||
// Player player = (Player) e.getWhoClicked();
|
||||
// GuiInventory guiInventory = playerGuiInventories.get(player.getUniqueId());
|
||||
//
|
||||
// if (guiInventory == null || !guiInventory.getInventory().equals(e.getView().getTopInventory())) return; // Make sure it is the right inventory
|
||||
//
|
||||
// e.setCancelled(true); // In the PlayerParticles GUI, can't let them take anything out
|
||||
//
|
||||
// if (!guiInventory.getInventory().equals(e.getClickedInventory())) return; // Clicked bottom inventory
|
||||
//
|
||||
// PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
|
||||
// if (pplayer == null) {
|
||||
// player.closeInventory();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// ItemStack clicked = e.getCurrentItem();
|
||||
// if (clicked == null || clicked.getType() == Material.AIR) return; // Clicked on an empty slot, do nothing
|
||||
//
|
||||
// // Check back button. This is common for most menus
|
||||
// if (clicked.getItemMeta().getDisplayName().equals(LangManager.getText(Lang.GUI_BACK_BUTTON))) {
|
||||
// changeState(pplayer, GuiState.DEFAULT);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName());
|
||||
// switch (guiInventory.getGuiState()) {
|
||||
// case DEFAULT:
|
||||
// if (name.equals("Effect")) {
|
||||
// changeState(pplayer, GuiState.EFFECT);
|
||||
// } else if (name.equals("Style")) {
|
||||
// changeState(pplayer, GuiState.STYLE);
|
||||
// } else if (name.equals("Data")) {
|
||||
// changeState(pplayer, GuiState.DATA);
|
||||
// }
|
||||
// break;
|
||||
// case EFFECT:
|
||||
// setPPlayerEffect(pplayer, ParticleEffect.fromName(name));
|
||||
// changeState(pplayer, GuiState.DEFAULT);
|
||||
// break;
|
||||
// case STYLE:
|
||||
// setPPlayerStyle(pplayer, ParticleStyle.fromName(name));
|
||||
// changeState(pplayer, GuiState.DEFAULT);
|
||||
// break;
|
||||
// case DATA:
|
||||
// ParticleEffect pe = getPPlayerEffect(pplayer);
|
||||
// if (pe.hasProperty(ParticleProperty.COLORABLE)) {
|
||||
// if (pe == ParticleEffect.NOTE) {
|
||||
// if (clicked.getItemMeta().getDisplayName().equals(LangManager.getText(Lang.RAINBOW))) {
|
||||
// setPPlayerNoteColor(pplayer, new NoteColor(99));
|
||||
// } else {
|
||||
// int note = Integer.parseInt(ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).substring(6));
|
||||
// setPPlayerNoteColor(pplayer, new NoteColor(note));
|
||||
// }
|
||||
// } else {
|
||||
// if (clicked.getItemMeta().getDisplayName().equals(LangManager.getText(Lang.RAINBOW))) {
|
||||
// setPPlayerColor(pplayer, new OrdinaryColor(999, 999, 999));
|
||||
// } else {
|
||||
// for (int i = 0; i < colorMapping.length; i++) {
|
||||
// if (clicked.getItemMeta().getDisplayName().equals(colorMapping[i].getName())) {
|
||||
// setPPlayerColor(pplayer, colorMapping[i].getOrdinaryColor());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
||||
// Material clickedMaterial = clicked.getType(); // All preset materials have a data value of 0
|
||||
// if (pe == ParticleEffect.ITEM) {
|
||||
// setPPlayerItemMaterial(pplayer, clickedMaterial);
|
||||
// } else {
|
||||
// setPPlayerBlockMaterial(pplayer, clickedMaterial);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// changeState(pplayer, GuiState.DEFAULT);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the icon for a given particle effect from the config
|
||||
// *
|
||||
// * @param effect The effect
|
||||
// * @param isActive If this effect is the current one active
|
||||
// * @return An ItemStack formatted to be displayed in the GUI
|
||||
// */
|
||||
// private static ItemStack getItemForEffect(ParticleEffect effect, boolean isActive) {
|
||||
// ItemStack icon = new ItemStack(effectIcons.get(effect.name()), 1);
|
||||
// ItemMeta iconMeta = icon.getItemMeta();
|
||||
//
|
||||
// iconMeta.setDisplayName(LangManager.getText(Lang.GUI_ICON_NAME_COLOR) + effect.getName());
|
||||
// if (!isActive) {
|
||||
// iconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "effect") + effect.getName()));
|
||||
// } else {
|
||||
// iconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "effect") + effect.getName(), LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "effect")));
|
||||
// iconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
// iconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
// }
|
||||
// icon.setItemMeta(iconMeta);
|
||||
//
|
||||
// return icon;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the icon for a given particle style from the config
|
||||
// *
|
||||
// * @param style The style
|
||||
// * @param isActive If this style is the current one active
|
||||
// * @return An ItemStack formatted to be displayed in the GUI
|
||||
// */
|
||||
// private static ItemStack getItemForStyle(ParticleStyle style, boolean isActive) {
|
||||
// ItemStack icon = new ItemStack(styleIcons.get(style.getName().toUpperCase()), 1);
|
||||
// ItemMeta iconMeta = icon.getItemMeta();
|
||||
//
|
||||
// iconMeta.setDisplayName(LangManager.getText(Lang.GUI_ICON_NAME_COLOR) + style.getName());
|
||||
// if (!isActive) {
|
||||
// iconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "style") + style.getName()));
|
||||
// } else {
|
||||
// iconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "style") + style.getName(), LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "style")));
|
||||
// iconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
// iconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
// }
|
||||
// icon.setItemMeta(iconMeta);
|
||||
//
|
||||
// return icon;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the icon for a given material to be used for data
|
||||
// *
|
||||
// * @param currentMaterial What material the player is currently using
|
||||
// * @param dataType What type of data this is (block/item)
|
||||
// * @param material The material to use for the icon
|
||||
// * @return An ItemStack formatted to be displayed in the GUI
|
||||
// */
|
||||
// private static ItemStack getItemForMaterialData(Material currentMaterial, String dataType, Material material) {
|
||||
// ItemStack materialIcon = new ItemStack(material, 1);
|
||||
// ItemMeta materialIconMeta = materialIcon.getItemMeta();
|
||||
//
|
||||
// materialIconMeta.setDisplayName(LangManager.getText(Lang.GUI_ICON_NAME_COLOR) + material.name().toLowerCase());
|
||||
// if (currentMaterial != material) {
|
||||
// materialIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, dataType + " data") + material.name().toLowerCase()));
|
||||
// } else {
|
||||
// materialIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, dataType + " data") + material.name().toLowerCase(), LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, dataType + " data")));
|
||||
// materialIconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
// materialIconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
// }
|
||||
// materialIcon.setItemMeta(materialIconMeta);
|
||||
//
|
||||
// return materialIcon;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the icon for a color to be used for data
|
||||
// *
|
||||
// * @param currentColor What color the player is currently using
|
||||
// * @param colorIndex What color to use
|
||||
// * @return An ItemStack formatted to be displayed in the GUI
|
||||
// */
|
||||
// private static ItemStack getItemForColorData(OrdinaryColor currentColor, int colorIndex) {
|
||||
// ColorData colorData = colorMapping[colorIndex];
|
||||
// String formattedDisplayColor = ChatColor.RED.toString() + colorData.getOrdinaryColor().getRed() + " " + ChatColor.GREEN + colorData.getOrdinaryColor().getGreen() + " " + ChatColor.AQUA + colorData.getOrdinaryColor().getBlue();
|
||||
//
|
||||
// ItemStack colorIcon;
|
||||
// if (colorData.getMaterial() != null) { // Use 1.13 materials
|
||||
// colorIcon = new ItemStack(colorData.getMaterial());
|
||||
// } else { // Use < 1.13 dye colors
|
||||
// colorIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
|
||||
// }
|
||||
// ItemMeta colorIconMeta = colorIcon.getItemMeta();
|
||||
//
|
||||
// colorIconMeta.setDisplayName(colorData.getName());
|
||||
// if (!currentColor.equals(colorData.getOrdinaryColor())) {
|
||||
// colorIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "color data") + formattedDisplayColor));
|
||||
// } else {
|
||||
// colorIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "color data") + formattedDisplayColor, LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "color data")));
|
||||
// colorIconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
// colorIconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
// }
|
||||
// colorIcon.setItemMeta(colorIconMeta);
|
||||
//
|
||||
// return colorIcon;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the icon for a note to be used for data
|
||||
// *
|
||||
// * @param currentNote What note the player is currently using
|
||||
// * @param noteIndex What note to use
|
||||
// * @return An ItemStack formatted to be displayed in the GUI
|
||||
// */
|
||||
// private static ItemStack getItemForNoteData(NoteColor currentNote, int noteIndex) {
|
||||
// ItemStack noteIcon = new ItemStack(Material.NOTE_BLOCK, noteIndex + 1);
|
||||
// ItemMeta noteIconMeta = noteIcon.getItemMeta();
|
||||
//
|
||||
// noteIconMeta.setDisplayName(LangManager.getText(Lang.GUI_ICON_NAME_COLOR) + "note #" + noteIndex);
|
||||
// if (currentNote.getValueX() * 24 != noteIndex) {
|
||||
// noteIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "note data") + "note #" + noteIndex));
|
||||
// } else {
|
||||
// noteIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "note data") + "note #" + noteIndex, LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "note data")));
|
||||
// noteIconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
// noteIconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
// }
|
||||
// noteIcon.setItemMeta(noteIconMeta);
|
||||
//
|
||||
// return noteIcon;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the icon for rainbow color/note data
|
||||
// *
|
||||
// * @param currentColor The player's current color data
|
||||
// * @param dyeColor The color of the rainbow we're on
|
||||
// * @return An ItemStack formatted to be displayed in the GUI
|
||||
// */
|
||||
// private static ItemStack getItemForRainbowColorData(OrdinaryColor currentColor, DyeColor dyeColor) {
|
||||
// ColorData colorData = getColorDataFromOrdinaryColor(dyeColor);
|
||||
// ItemStack rainbowIcon;
|
||||
// if (colorData.getMaterial() != null) { // Use 1.13 materials
|
||||
// rainbowIcon = new ItemStack(colorData.getMaterial());
|
||||
// } else { // Use < 1.13 dye colors
|
||||
// rainbowIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
|
||||
// }
|
||||
// ItemMeta rainbowIconMeta = rainbowIcon.getItemMeta();
|
||||
//
|
||||
// rainbowIconMeta.setDisplayName(LangManager.getText(Lang.RAINBOW));
|
||||
// if (currentColor.getRed() == 999 && currentColor.getGreen() == 999 && currentColor.getBlue() == 999) {
|
||||
// rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "color data") + LangManager.getText(Lang.RAINBOW), LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "color data")));
|
||||
// rainbowIconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
// rainbowIconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
// } else {
|
||||
// rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "color data") + LangManager.getText(Lang.RAINBOW)));
|
||||
// }
|
||||
// rainbowIcon.setItemMeta(rainbowIconMeta);
|
||||
//
|
||||
// return rainbowIcon;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the icon for rainbow color/note data
|
||||
// *
|
||||
// * @param currentColor The player's current note data
|
||||
// * @param dyeColor The color of the rainbow we're on
|
||||
// * @return An ItemStack formatted to be displayed in the GUI
|
||||
// */
|
||||
// private static ItemStack getItemForRainbowNoteData(NoteColor currentColor, DyeColor dyeColor) {
|
||||
// ColorData colorData = getColorDataFromOrdinaryColor(dyeColor);
|
||||
// ItemStack rainbowIcon;
|
||||
// if (colorData.getMaterial() != null) { // Use 1.13 materials
|
||||
// rainbowIcon = new ItemStack(colorData.getMaterial());
|
||||
// } else { // Use < 1.13 dye colors
|
||||
// rainbowIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
|
||||
// }
|
||||
// ItemMeta rainbowIconMeta = rainbowIcon.getItemMeta();
|
||||
//
|
||||
// rainbowIconMeta.setDisplayName(LangManager.getText(Lang.RAINBOW));
|
||||
// if (currentColor.getValueX() * 24 == 99) {
|
||||
// rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "note data") + LangManager.getText(Lang.RAINBOW), LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "note data")));
|
||||
// rainbowIconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
// rainbowIconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
// } else {
|
||||
// rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "note data") + LangManager.getText(Lang.RAINBOW)));
|
||||
// }
|
||||
// rainbowIcon.setItemMeta(rainbowIconMeta);
|
||||
//
|
||||
// return rainbowIcon;
|
||||
// }
|
||||
//
|
||||
//}
|
|
@ -1,53 +1,143 @@
|
|||
package com.esophose.playerparticles.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.material.Dye;
|
||||
|
||||
import com.esophose.playerparticles.gui.PlayerParticlesGui.GuiState;
|
||||
import com.esophose.playerparticles.particles.PPlayer;
|
||||
import com.esophose.playerparticles.util.ParticleUtils;
|
||||
|
||||
public class GuiInventory {
|
||||
|
||||
private Inventory inventory;
|
||||
private GuiState guiState;
|
||||
|
||||
public GuiInventory(Inventory inventory, GuiState guiState) {
|
||||
public abstract class GuiInventory {
|
||||
|
||||
protected enum BorderColor {
|
||||
WHITE(DyeColor.WHITE, "WHITE_STAINED_GLASS_PANE"),
|
||||
ORANGE(DyeColor.ORANGE, "ORANGE_STAINED_GLASS_PANE"),
|
||||
RED(DyeColor.RED, "RED_STAINED_GLASS_PANE"),
|
||||
BROWN(DyeColor.BROWN, "BROWN_STAINED_GLASS_PANE"),
|
||||
GREEN(DyeColor.GREEN, "GREEN_STAINED_GLASS_PANE");
|
||||
|
||||
private DyeColor dyeColor;
|
||||
private Material material;
|
||||
|
||||
private BorderColor(DyeColor dyeColor, String materialName) {
|
||||
this.dyeColor = dyeColor;
|
||||
this.material = ParticleUtils.closestMatch(materialName);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
protected ItemStack getIcon() {
|
||||
ItemStack borderIcon;
|
||||
if (this.material != null) { // Use 1.13 materials
|
||||
borderIcon = new ItemStack(this.material, 1);
|
||||
} else { // Use < 1.13 dye colors
|
||||
borderIcon = new Dye(this.dyeColor).toItemStack(1);
|
||||
}
|
||||
|
||||
ItemMeta meta = borderIcon.getItemMeta();
|
||||
meta.setDisplayName(" ");
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_ENCHANTS);
|
||||
borderIcon.setItemMeta(meta);
|
||||
|
||||
return borderIcon;
|
||||
}
|
||||
}
|
||||
|
||||
protected static final int INVENTORY_SIZE = 54;
|
||||
protected PPlayer pplayer;
|
||||
protected Inventory inventory;
|
||||
protected List<GuiActionButton> actionButtons;
|
||||
|
||||
public GuiInventory(PPlayer pplayer, Inventory inventory) {
|
||||
this.pplayer = pplayer;
|
||||
this.inventory = inventory;
|
||||
this.guiState = guiState;
|
||||
this.actionButtons = new ArrayList<GuiActionButton>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replaces the current inventory with a new inventory
|
||||
* Gets the PPlayer this GuiInventory is managing
|
||||
*
|
||||
* @param inventory The inventory this GuiInventory now manages
|
||||
* @return The PPlayer this GuiInventory is managing
|
||||
*/
|
||||
public void setInventory(Inventory inventory) {
|
||||
this.inventory = inventory;
|
||||
public PPlayer getPPlayer() {
|
||||
return this.pplayer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the current GuiState
|
||||
* Gets the Inventory this GuiInventory is managing
|
||||
*
|
||||
* @param guiState The new GuiState
|
||||
*/
|
||||
public void setGuiState(GuiState guiState) {
|
||||
this.guiState = guiState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Inventory
|
||||
*
|
||||
* @return The Inventory
|
||||
* @return The Inventory this GuiInventory is managing
|
||||
*/
|
||||
public Inventory getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the GuiState
|
||||
* Fills the border of the inventory with a given color
|
||||
*
|
||||
* @return The GuiState
|
||||
* @param borderColor The color of the border
|
||||
*/
|
||||
public GuiState getGuiState() {
|
||||
return this.guiState;
|
||||
protected void fillBorder(BorderColor borderColor) {
|
||||
ItemStack itemStack = borderColor.getIcon();
|
||||
|
||||
// Top
|
||||
for (int i = 0; i < 9; i++)
|
||||
this.inventory.setItem(i, itemStack);
|
||||
|
||||
// Bottom
|
||||
for (int i = INVENTORY_SIZE - 9; i < INVENTORY_SIZE; i++)
|
||||
this.inventory.setItem(i, itemStack);
|
||||
|
||||
// Left
|
||||
for (int i = 0; i < INVENTORY_SIZE; i += 9)
|
||||
this.inventory.setItem(i, itemStack);
|
||||
|
||||
// Right
|
||||
for (int i = 8; i < INVENTORY_SIZE; i += 9)
|
||||
this.inventory.setItem(i, itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the Inventory with the contents of actionButtons
|
||||
*/
|
||||
protected void populate() {
|
||||
for (GuiActionButton button : actionButtons) {
|
||||
this.inventory.setItem(button.getSlot(), button.getIcon());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ticked at an interval to animate GuiActionButton icons
|
||||
*/
|
||||
public void onTick() {
|
||||
for (GuiActionButton button : this.actionButtons) {
|
||||
if (button.isTickable()) {
|
||||
button.onTick();
|
||||
this.inventory.setItem(button.getSlot(), button.getIcon());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles clicks of GuiActionButtons
|
||||
*/
|
||||
public void onClick(InventoryClickEvent event) {
|
||||
int slot = event.getSlot();
|
||||
boolean isShiftClick = event.isShiftClick();
|
||||
|
||||
for (GuiActionButton button : this.actionButtons) {
|
||||
if (button.getSlot() == slot) {
|
||||
button.handleClick(isShiftClick);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
package com.esophose.playerparticles.gui;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.SkullType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import com.esophose.playerparticles.particles.PPlayer;
|
||||
import com.esophose.playerparticles.util.ParticleUtils;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class GuiInventoryDefault extends GuiInventory {
|
||||
|
||||
public GuiInventoryDefault(PPlayer pplayer) {
|
||||
super(pplayer, Bukkit.createInventory(pplayer.getPlayer(), INVENTORY_SIZE, "PlayerParticles"));
|
||||
|
||||
this.fillBorder(BorderColor.WHITE);
|
||||
|
||||
// PPlayer information icon
|
||||
ItemStack headIcon;
|
||||
Material playerHead = ParticleUtils.closestMatch("PLAYER_HEAD");
|
||||
if (playerHead != null) {
|
||||
headIcon = new ItemStack(playerHead, 1);
|
||||
} else {
|
||||
headIcon = new ItemStack(ParticleUtils.closestMatch("SKULL_ITEM"), 1, (short) SkullType.PLAYER.ordinal());
|
||||
}
|
||||
|
||||
SkullMeta currentIconMeta = (SkullMeta) headIcon.getItemMeta();
|
||||
currentIconMeta.setDisplayName(ChatColor.GREEN + pplayer.getPlayer().getName());
|
||||
String[] currentIconLore = new String[] {
|
||||
ChatColor.YELLOW + "Active Particles: " + ChatColor.AQUA + pplayer.getActiveParticles().size(),
|
||||
ChatColor.YELLOW + "Saved Groups: " + ChatColor.AQUA + pplayer.getParticleGroups().size(),
|
||||
ChatColor.YELLOW + "Fixed Effects: " + ChatColor.AQUA + pplayer.getFixedEffectIds().size()
|
||||
};
|
||||
currentIconMeta.setLore(Arrays.asList(currentIconLore));
|
||||
currentIconMeta.setOwner(pplayer.getPlayer().getName());
|
||||
headIcon.setItemMeta(currentIconMeta);
|
||||
|
||||
this.inventory.setItem(13, headIcon);
|
||||
|
||||
// Manage Your Particles button
|
||||
GuiActionButton manageYourParticlesButton = new GuiActionButton(38, Material.BLAZE_POWDER, ChatColor.GREEN + "Manage Your Particles", new String[] { ChatColor.YELLOW + "Create, edit, and delete your particles" }, false, (isShiftClick) -> {
|
||||
GuiHandler.transition(new GuiInventoryManageParticles(pplayer));
|
||||
});
|
||||
this.actionButtons.add(manageYourParticlesButton);
|
||||
|
||||
// Manage Your Groups button
|
||||
GuiActionButton manageYourGroupsButton = new GuiActionButton(40, Material.CHEST, ChatColor.GREEN + "Manage Your Groups", new String[] { ChatColor.YELLOW + "Create, delete, and load particle groups" }, false, (isShiftClick) -> {
|
||||
// transition to GuiInventoryManageGroups
|
||||
});
|
||||
this.actionButtons.add(manageYourGroupsButton);
|
||||
|
||||
// Load Preset Groups
|
||||
GuiActionButton loadPresetGroups = new GuiActionButton(42, Material.ENDER_CHEST, ChatColor.GREEN + "Load Preset Groups", new String[] { ChatColor.YELLOW + "Load pre-existing particle groups" }, false, (isShiftClick) -> {
|
||||
// transition to GuiInventoryPresetGroups
|
||||
});
|
||||
this.actionButtons.add(loadPresetGroups);
|
||||
|
||||
this.populate();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.esophose.playerparticles.gui;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.esophose.playerparticles.particles.PPlayer;
|
||||
|
||||
public class GuiInventoryManageParticles extends GuiInventory {
|
||||
|
||||
public GuiInventoryManageParticles(PPlayer pplayer) {
|
||||
super(pplayer, Bukkit.createInventory(pplayer.getPlayer(), INVENTORY_SIZE));
|
||||
|
||||
this.fillBorder(BorderColor.ORANGE);
|
||||
|
||||
GuiActionButton button = new GuiActionButton(0, new Material[] { Material.BLAZE_POWDER, Material.BLAZE_ROD }, new String[] { "Test 2!", "Look at that!" } , new String[] { "To be continued..." }, true, (isShiftClick) -> {
|
||||
GuiHandler.transition(new GuiInventoryDefault(pplayer));
|
||||
});
|
||||
this.actionButtons.add(button);
|
||||
|
||||
this.populate();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,964 +0,0 @@
|
|||
package com.esophose.playerparticles.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.SkullType;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.material.Dye;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.esophose.playerparticles.PlayerParticles;
|
||||
import com.esophose.playerparticles.manager.DataManager;
|
||||
import com.esophose.playerparticles.manager.LangManager;
|
||||
import com.esophose.playerparticles.manager.LangManager.Lang;
|
||||
import com.esophose.playerparticles.manager.PermissionManager;
|
||||
import com.esophose.playerparticles.manager.SettingManager.PSetting;
|
||||
import com.esophose.playerparticles.particles.PPlayer;
|
||||
import com.esophose.playerparticles.particles.ParticleEffect;
|
||||
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
|
||||
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
|
||||
import com.esophose.playerparticles.particles.ParticleEffect.ParticleColor;
|
||||
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
|
||||
import com.esophose.playerparticles.particles.ParticleGroup;
|
||||
import com.esophose.playerparticles.particles.ParticlePair;
|
||||
import com.esophose.playerparticles.styles.DefaultStyles;
|
||||
import com.esophose.playerparticles.styles.api.ParticleStyle;
|
||||
import com.esophose.playerparticles.styles.api.ParticleStyleManager;
|
||||
import com.esophose.playerparticles.util.ParticleUtils;
|
||||
|
||||
/**
|
||||
* This class provides a collection of static methods for modifying your
|
||||
* particle/style/data through the use of a GUI
|
||||
*/
|
||||
// TODO: This entire GUI is currently hardwired to only work with the first particle in the player's list, make it work with everything
|
||||
public class PlayerParticlesGui extends BukkitRunnable implements Listener {
|
||||
|
||||
/**
|
||||
* The possible states that the GUI can be in
|
||||
* Used to figure out what the InventoryClickEvent should do
|
||||
*/
|
||||
public enum GuiState { // @formatter:off
|
||||
DEFAULT,
|
||||
EFFECT,
|
||||
STYLE,
|
||||
DATA
|
||||
} // @formatter:on
|
||||
|
||||
private static final int INVENTORY_SIZE = 54;
|
||||
private static HashMap<UUID, GuiInventory> playerGuiInventories;
|
||||
|
||||
/**
|
||||
* Cached icons to prevent calling config over and over
|
||||
*/
|
||||
private static Material[] defaultMenuIcons = new Material[3];
|
||||
private static HashMap<String, Material> effectIcons;
|
||||
private static HashMap<String, Material> styleIcons;
|
||||
|
||||
/**
|
||||
* Maps to convert from clicked materials to particle colors
|
||||
*/
|
||||
private static ColorData[] colorMapping;
|
||||
|
||||
/**
|
||||
* DyeColor array in the order of the rainbow
|
||||
* Color index for the wool color to display next
|
||||
*/
|
||||
private static DyeColor[] rainbowColors;
|
||||
private static int rainbowColorsIndex = 0;
|
||||
|
||||
/**
|
||||
* Cached material data
|
||||
*/
|
||||
private static final Random RANDOM = new Random();
|
||||
private static List<Material> BLOCK_MATERIALS = new ArrayList<Material>();
|
||||
private static List<Material> ITEM_MATERIALS = new ArrayList<Material>();
|
||||
|
||||
static { // @formatter:off
|
||||
colorMapping = new ColorData[] {
|
||||
new ColorData(DyeColor.RED, ParticleUtils.closestMatch("ROSE_RED"), new OrdinaryColor(255, 0, 0), ChatColor.RED + "red"),
|
||||
new ColorData(DyeColor.ORANGE, ParticleUtils.closestMatch("ORANGE_DYE"), new OrdinaryColor(255, 140, 0), ChatColor.GOLD + "orange"),
|
||||
new ColorData(DyeColor.YELLOW, ParticleUtils.closestMatch("DANDELION_YELLOW"), new OrdinaryColor(255, 255, 0), ChatColor.YELLOW + "yellow"),
|
||||
new ColorData(DyeColor.LIME, ParticleUtils.closestMatch("LIME_DYE"), new OrdinaryColor(50, 205, 50), ChatColor.GREEN + "lime green"),
|
||||
new ColorData(DyeColor.GREEN, ParticleUtils.closestMatch("CACTUS_GREEN"), new OrdinaryColor(0, 128, 0), ChatColor.DARK_GREEN + "green"),
|
||||
new ColorData(DyeColor.BLUE, ParticleUtils.closestMatch("LAPIZ_LAZULI"), new OrdinaryColor(0, 0, 255), ChatColor.DARK_BLUE + "blue"),
|
||||
new ColorData(DyeColor.CYAN, ParticleUtils.closestMatch("CYAN_DYE"), new OrdinaryColor(0, 139, 139), ChatColor.DARK_AQUA + "cyan"),
|
||||
new ColorData(DyeColor.LIGHT_BLUE, ParticleUtils.closestMatch("LIGHT_BLUE_DYE"), new OrdinaryColor(173, 216, 230), ChatColor.AQUA + "light blue"),
|
||||
new ColorData(DyeColor.PURPLE, ParticleUtils.closestMatch("PURPLE_DYE"), new OrdinaryColor(138, 43, 226), ChatColor.DARK_PURPLE + "purple"),
|
||||
new ColorData(DyeColor.MAGENTA, ParticleUtils.closestMatch("MAGENTA_DYE"), new OrdinaryColor(202, 31, 123), ChatColor.LIGHT_PURPLE + "magenta"),
|
||||
new ColorData(DyeColor.PINK, ParticleUtils.closestMatch("PINK_DYE"), new OrdinaryColor(255, 182, 193), ChatColor.LIGHT_PURPLE + "pink"),
|
||||
new ColorData(DyeColor.BROWN, ParticleUtils.closestMatch("COCOA_BEANS"), new OrdinaryColor(139, 69, 19), ChatColor.GOLD + "brown"),
|
||||
new ColorData(DyeColor.BLACK, ParticleUtils.closestMatch("INK_SAC"), new OrdinaryColor(0, 0, 0), ChatColor.DARK_GRAY + "black"),
|
||||
new ColorData(DyeColor.GRAY, ParticleUtils.closestMatch("GRAY_DYE"), new OrdinaryColor(128, 128, 128), ChatColor.DARK_GRAY + "gray"),
|
||||
new ColorData(DyeColor.getByDyeData((byte)7), ParticleUtils.closestMatch("LIGHT_GRAY_DYE"), new OrdinaryColor(192, 192, 192), ChatColor.GRAY + "light gray"),
|
||||
new ColorData(DyeColor.WHITE, ParticleUtils.closestMatch("BONE_MEAL"), new OrdinaryColor(255, 255, 255), ChatColor.WHITE + "white"),
|
||||
};
|
||||
|
||||
rainbowColors = new DyeColor[] {
|
||||
DyeColor.RED,
|
||||
DyeColor.ORANGE,
|
||||
DyeColor.YELLOW,
|
||||
DyeColor.LIME,
|
||||
DyeColor.LIGHT_BLUE,
|
||||
DyeColor.BLUE,
|
||||
DyeColor.PURPLE
|
||||
};
|
||||
|
||||
Inventory testingInventory = Bukkit.createInventory(null, 9);
|
||||
for (Material mat : Material.values()) {
|
||||
// Verify an ItemStack of the material can be placed into an inventory. In 1.12 and up this can easily be checked with mat.isItem(), but that doesn't exist pre-1.12
|
||||
testingInventory.clear();
|
||||
testingInventory.setItem(0, new ItemStack(mat, 1));
|
||||
ItemStack itemStack = testingInventory.getItem(0);
|
||||
if (itemStack != null) {
|
||||
if (mat.isBlock()) {
|
||||
BLOCK_MATERIALS.add(mat);
|
||||
} else if (!mat.isBlock()) {
|
||||
ITEM_MATERIALS.add(mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // @formatter:on
|
||||
|
||||
/**
|
||||
* Initializes all the static values for this class
|
||||
*/
|
||||
public static void setup() {
|
||||
FileConfiguration config = PlayerParticles.getPlugin().getConfig();
|
||||
|
||||
if (!PSetting.GUI_ENABLED.getBoolean()) return;
|
||||
|
||||
playerGuiInventories = new HashMap<UUID, GuiInventory>();
|
||||
effectIcons = new HashMap<String, Material>();
|
||||
styleIcons = new HashMap<String, Material>();
|
||||
|
||||
defaultMenuIcons[0] = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.main-menu.EFFECT"));
|
||||
defaultMenuIcons[1] = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.main-menu.STYLE"));
|
||||
defaultMenuIcons[2] = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.main-menu.DATA"));
|
||||
|
||||
// Grab a different effect icon set based on if the Minecraft version is >= 1.13 or not
|
||||
String legacy;
|
||||
try {
|
||||
Particle.valueOf("NAUTILUS");
|
||||
legacy = "";
|
||||
} catch (Exception ex) {
|
||||
legacy = "-legacy";
|
||||
}
|
||||
|
||||
for (ParticleEffect effect : ParticleEffect.getSupportedEffects()) {
|
||||
String effectName = effect.getName().toUpperCase();
|
||||
Material iconMaterial = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.effect" + legacy + "." + effectName));
|
||||
effectIcons.put(effectName, iconMaterial);
|
||||
}
|
||||
|
||||
for (ParticleStyle style : ParticleStyleManager.getStyles()) {
|
||||
String styleName = style.getName().toUpperCase();
|
||||
Material iconMaterial = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.style" + legacy + "." + styleName));
|
||||
styleIcons.put(styleName, iconMaterial);
|
||||
}
|
||||
|
||||
new PlayerParticlesGui().runTaskTimer(PlayerParticles.getPlugin(), 0, 10);
|
||||
}
|
||||
|
||||
// TODO: Delete these specialized getter methods once the new GUI is finished
|
||||
private static ParticleEffect getPPlayerEffect(PPlayer pplayer) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
if (particles.isEmpty()) return ParticleEffect.FLAME;
|
||||
return particles.get(0).getEffect();
|
||||
}
|
||||
|
||||
private static ParticleStyle getPPlayerStyle(PPlayer pplayer) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
if (particles.isEmpty()) return DefaultStyles.NORMAL;
|
||||
return particles.get(0).getStyle();
|
||||
}
|
||||
|
||||
private static Material getPPlayerItemMaterial(PPlayer pplayer) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
if (particles.isEmpty()) return ParticlePair.getDefault().getItemMaterial();
|
||||
return particles.get(0).getItemMaterial();
|
||||
}
|
||||
|
||||
private static Material getPPlayerBlockMaterial(PPlayer pplayer) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
if (particles.isEmpty()) return ParticlePair.getDefault().getBlockMaterial();
|
||||
return particles.get(0).getBlockMaterial();
|
||||
}
|
||||
|
||||
private static OrdinaryColor getPPlayerColor(PPlayer pplayer) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
if (particles.isEmpty()) return ParticlePair.getDefault().getColor();
|
||||
return particles.get(0).getColor();
|
||||
}
|
||||
|
||||
private static NoteColor getPPlayerNoteColor(PPlayer pplayer) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
if (particles.isEmpty()) return ParticlePair.getDefault().getNoteColor();
|
||||
return particles.get(0).getNoteColor();
|
||||
}
|
||||
|
||||
private static Material getPPlayerSpawnMaterial(PPlayer pplayer) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
if (particles.isEmpty()) return ParticlePair.getDefault().getSpawnMaterial();
|
||||
return particles.get(0).getSpawnMaterial();
|
||||
}
|
||||
|
||||
private static ParticleColor getPPlayerSpawnColor(PPlayer pplayer) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
if (particles.isEmpty()) return ParticlePair.getDefault().getSpawnColor();
|
||||
return particles.get(0).getSpawnColor();
|
||||
}
|
||||
|
||||
private static String getPPlayerDataString(PPlayer pplayer) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
if (particles.isEmpty()) return ParticlePair.getDefault().getDataString();
|
||||
return particles.get(0).getDataString();
|
||||
}
|
||||
|
||||
private static void setPPlayerEffect(PPlayer pplayer, ParticleEffect effect) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
ParticlePair particle;
|
||||
if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
|
||||
else particle = particles.get(0);
|
||||
|
||||
particle.setEffect(effect);
|
||||
particles.clear();
|
||||
particles.add(particle);
|
||||
|
||||
ParticleGroup group = new ParticleGroup(ParticleGroup.DEFAULT_NAME, particles);
|
||||
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
|
||||
}
|
||||
|
||||
private static void setPPlayerStyle(PPlayer pplayer, ParticleStyle style) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
ParticlePair particle;
|
||||
if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
|
||||
else particle = particles.get(0);
|
||||
|
||||
particle.setStyle(style);
|
||||
particles.clear();
|
||||
particles.add(particle);
|
||||
|
||||
ParticleGroup group = new ParticleGroup(ParticleGroup.DEFAULT_NAME, particles);
|
||||
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
|
||||
}
|
||||
|
||||
private static void setPPlayerItemMaterial(PPlayer pplayer, Material material) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
ParticlePair particle;
|
||||
if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
|
||||
else particle = particles.get(0);
|
||||
|
||||
particle.setItemMaterial(material);
|
||||
particles.clear();
|
||||
particles.add(particle);
|
||||
|
||||
ParticleGroup group = new ParticleGroup(ParticleGroup.DEFAULT_NAME, particles);
|
||||
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
|
||||
}
|
||||
|
||||
private static void setPPlayerBlockMaterial(PPlayer pplayer, Material material) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
ParticlePair particle;
|
||||
if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
|
||||
else particle = particles.get(0);
|
||||
|
||||
particle.setBlockMaterial(material);
|
||||
particles.clear();
|
||||
particles.add(particle);
|
||||
|
||||
ParticleGroup group = new ParticleGroup(ParticleGroup.DEFAULT_NAME, particles);
|
||||
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
|
||||
}
|
||||
|
||||
private static void setPPlayerColor(PPlayer pplayer, OrdinaryColor color) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
ParticlePair particle;
|
||||
if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
|
||||
else particle = particles.get(0);
|
||||
|
||||
particle.setColor(color);
|
||||
particles.clear();
|
||||
particles.add(particle);
|
||||
|
||||
ParticleGroup group = new ParticleGroup(ParticleGroup.DEFAULT_NAME, particles);
|
||||
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
|
||||
}
|
||||
|
||||
private static void setPPlayerNoteColor(PPlayer pplayer, NoteColor noteColor) {
|
||||
List<ParticlePair> particles = pplayer.getActiveParticles();
|
||||
ParticlePair particle;
|
||||
if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
|
||||
else particle = particles.get(0);
|
||||
|
||||
particle.setNoteColor(noteColor);
|
||||
particles.clear();
|
||||
particles.add(particle);
|
||||
|
||||
ParticleGroup group = new ParticleGroup(ParticleGroup.DEFAULT_NAME, particles);
|
||||
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all color/note data inventories to display the rainbow icon
|
||||
* Removes any players who are no longer online from playerGuiInventoriesd
|
||||
*/
|
||||
public void run() {
|
||||
List<UUID> toRemoveList = new ArrayList<UUID>();
|
||||
|
||||
for (Map.Entry<UUID, GuiInventory> entry : playerGuiInventories.entrySet()) {
|
||||
UUID playerUUID = entry.getKey();
|
||||
PPlayer pplayer = DataManager.getPPlayer(playerUUID);
|
||||
if (pplayer == null) {
|
||||
toRemoveList.add(playerUUID);
|
||||
continue;
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(playerUUID);
|
||||
if (player == null) {
|
||||
toRemoveList.add(playerUUID);
|
||||
continue;
|
||||
}
|
||||
|
||||
GuiInventory guiInventory = entry.getValue();
|
||||
Inventory inventory = guiInventory.getInventory();
|
||||
|
||||
if (player.getOpenInventory().getTopInventory().equals(inventory) && guiInventory.getGuiState() == GuiState.DATA && getPPlayerEffect(pplayer).hasProperty(ParticleProperty.COLORABLE)) {
|
||||
ItemStack rainbowIcon;
|
||||
if (getPPlayerEffect(pplayer) != ParticleEffect.NOTE) {
|
||||
rainbowIcon = getItemForRainbowColorData(getPPlayerColor(pplayer), rainbowColors[rainbowColorsIndex]);
|
||||
} else {
|
||||
rainbowIcon = getItemForRainbowNoteData(getPPlayerNoteColor(pplayer), rainbowColors[rainbowColorsIndex]);
|
||||
}
|
||||
inventory.setItem(40, rainbowIcon);
|
||||
}
|
||||
}
|
||||
|
||||
for (UUID uuid : toRemoveList)
|
||||
playerGuiInventories.remove(uuid);
|
||||
|
||||
rainbowColorsIndex++;
|
||||
rainbowColorsIndex %= rainbowColors.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the GUI is disabled by the server owner or not
|
||||
*
|
||||
* @return True if the GUI is disabled
|
||||
*/
|
||||
public static boolean isGuiDisabled() {
|
||||
return !PSetting.GUI_ENABLED.getBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully closes all open PlayerParticles GUIs
|
||||
* Used for when the plugin unloads so players can't take items from the GUI
|
||||
*/
|
||||
public static void forceCloseAllOpenGUIs() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
InventoryView openInventory = p.getOpenInventory();
|
||||
if (openInventory == null) continue;
|
||||
Inventory topInventory = openInventory.getTopInventory();
|
||||
if (topInventory == null) continue;
|
||||
|
||||
// Check if any of the inventories are the one the user has open, close if true
|
||||
for (GuiInventory guiInventory : playerGuiInventories.values()) {
|
||||
if (topInventory.equals(guiInventory.getInventory())) {
|
||||
p.closeInventory();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the GUI to the indicated state
|
||||
* If the GUI isn't open yet, it gets opened
|
||||
*
|
||||
* @param pplayer The pplayer
|
||||
* @param state The new state
|
||||
*/
|
||||
public static void changeState(PPlayer pplayer, GuiState state) {
|
||||
Player player = pplayer.getPlayer();
|
||||
|
||||
if ((state == GuiState.EFFECT && PermissionManager.getEffectsUserHasPermissionFor(player).isEmpty()) || (state == GuiState.STYLE && PermissionManager.getStylesUserHasPermissionFor(player).size() == 1) || (state == GuiState.DATA && getPPlayerSpawnMaterial(pplayer) == null && getPPlayerSpawnColor(pplayer) == null)) return;
|
||||
|
||||
// Update the state and create an inventory for the player if one isn't already open for them
|
||||
// If they have the wrong inventory open for some reason, create a new one and open it for them
|
||||
if (playerGuiInventories.containsKey(pplayer.getUniqueId())) {
|
||||
GuiInventory guiInventory = playerGuiInventories.get(pplayer.getUniqueId());
|
||||
guiInventory.setGuiState(state);
|
||||
if (!player.getOpenInventory().getTopInventory().equals(guiInventory.getInventory())) {
|
||||
player.openInventory(guiInventory.getInventory());
|
||||
}
|
||||
} else {
|
||||
Inventory ppInventory = Bukkit.createInventory(null, INVENTORY_SIZE, "PlayerParticles");
|
||||
player.openInventory(ppInventory);
|
||||
playerGuiInventories.put(pplayer.getUniqueId(), new GuiInventory(ppInventory, state));
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case DEFAULT:
|
||||
populateDefault(pplayer);
|
||||
break;
|
||||
case EFFECT:
|
||||
populateEffect(pplayer);
|
||||
break;
|
||||
case STYLE:
|
||||
populateStyle(pplayer);
|
||||
break;
|
||||
case DATA:
|
||||
populateData(pplayer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the menu to go to other menus: effect, style, data
|
||||
*
|
||||
* @param pplayer The PPlayer
|
||||
*/
|
||||
private static void populateDefault(PPlayer pplayer) {
|
||||
Player player = pplayer.getPlayer();
|
||||
Inventory inventory = player.getOpenInventory().getTopInventory();
|
||||
|
||||
inventory.clear(); // Make sure the inventory is always empty before we start adding items
|
||||
|
||||
ItemStack currentIcon;
|
||||
Material playerHead = ParticleUtils.closestMatch("PLAYER_HEAD");
|
||||
if (playerHead != null) {
|
||||
currentIcon = new ItemStack(playerHead, 1);
|
||||
} else {
|
||||
currentIcon = new ItemStack(ParticleUtils.closestMatch("SKULL_ITEM"), 1, (short) SkullType.PLAYER.ordinal());
|
||||
}
|
||||
|
||||
SkullMeta currentIconMeta = (SkullMeta) currentIcon.getItemMeta();
|
||||
currentIconMeta.setDisplayName(ChatColor.GREEN + player.getName());
|
||||
String[] currentIconLore = new String[3];
|
||||
currentIconLore[0] = ChatColor.YELLOW + "Effect: " + ChatColor.AQUA + getPPlayerEffect(pplayer).getName();
|
||||
currentIconLore[1] = ChatColor.YELLOW + "Style: " + ChatColor.AQUA + getPPlayerStyle(pplayer).getName();
|
||||
currentIconLore[2] = ChatColor.YELLOW + "Active Data: " + ChatColor.AQUA + getPPlayerDataString(pplayer);
|
||||
currentIconMeta.setLore(Arrays.asList(currentIconLore));
|
||||
currentIconMeta.setOwner(player.getName());
|
||||
// currentIconMeta.setOwningPlayer(Bukkit.getOfflinePlayer(player.getUniqueId())); // This doesn't exist in 1.9
|
||||
currentIcon.setItemMeta(currentIconMeta);
|
||||
|
||||
ItemStack effectIcon = new ItemStack(defaultMenuIcons[0], 1);
|
||||
ItemMeta effectIconMeta = effectIcon.getItemMeta();
|
||||
effectIconMeta.setDisplayName(ChatColor.GREEN + "Effect");
|
||||
effectIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SET_YOUR, "effect")));
|
||||
if (PermissionManager.getEffectsUserHasPermissionFor(player).isEmpty()) {
|
||||
effectIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_NO_ACCESS_TO, "effects")));
|
||||
}
|
||||
effectIcon.setItemMeta(effectIconMeta);
|
||||
|
||||
ItemStack styleIcon = new ItemStack(defaultMenuIcons[1], 1);
|
||||
ItemMeta styleIconMeta = styleIcon.getItemMeta();
|
||||
styleIconMeta.setDisplayName(ChatColor.GREEN + "Style");
|
||||
styleIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SET_YOUR, "style")));
|
||||
if (PermissionManager.getStylesUserHasPermissionFor(player).size() == 1) { // Always has access to NORMAL
|
||||
styleIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_NO_ACCESS_TO, "styles")));
|
||||
}
|
||||
styleIcon.setItemMeta(styleIconMeta);
|
||||
|
||||
ItemStack dataIcon = new ItemStack(defaultMenuIcons[2], 1);
|
||||
ItemMeta dataIconMeta = dataIcon.getItemMeta();
|
||||
dataIconMeta.setDisplayName(ChatColor.GREEN + "Data");
|
||||
ParticleEffect pe = getPPlayerEffect(pplayer);
|
||||
String dataType = "data";
|
||||
if (pe.hasProperty(ParticleProperty.COLORABLE)) // @formatter:off
|
||||
if (pe == ParticleEffect.NOTE) dataType = "note " + dataType;
|
||||
else dataType = "color " + dataType;
|
||||
else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) if (pe == ParticleEffect.ITEM) dataType = "item " + dataType;
|
||||
else dataType = "block " + dataType; // @formatter:on
|
||||
dataIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SET_YOUR, dataType)));
|
||||
if (getPPlayerSpawnMaterial(pplayer) == null && getPPlayerSpawnColor(pplayer) == null) {
|
||||
dataIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_NO_DATA)));
|
||||
}
|
||||
dataIcon.setItemMeta(dataIconMeta);
|
||||
|
||||
inventory.setItem(13, currentIcon);
|
||||
inventory.setItem(38, effectIcon);
|
||||
inventory.setItem(40, styleIcon);
|
||||
inventory.setItem(42, dataIcon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the menu that allows you to select an effect you have permission for
|
||||
*
|
||||
* @param pplayer The PPlayer
|
||||
*/
|
||||
private static void populateEffect(PPlayer pplayer) {
|
||||
Player player = pplayer.getPlayer();
|
||||
Inventory inventory = player.getOpenInventory().getTopInventory();
|
||||
inventory.clear(); // Make sure the inventory is always empty before we start adding items
|
||||
|
||||
List<String> effectsUserHasPermissionFor = PermissionManager.getEffectsUserHasPermissionFor(player);
|
||||
for (int i = 0; i < effectsUserHasPermissionFor.size(); i++) {
|
||||
String s = effectsUserHasPermissionFor.get(i);
|
||||
ParticleEffect effect = ParticleEffect.fromName(s);
|
||||
inventory.setItem(i, getItemForEffect(effect, effect == getPPlayerEffect(pplayer)));
|
||||
}
|
||||
|
||||
inventory.setItem(INVENTORY_SIZE - 1, getItemForBack());
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the menu that allows you to select a style you have permission for
|
||||
*
|
||||
* @param pplayer The PPlayer
|
||||
*/
|
||||
private static void populateStyle(PPlayer pplayer) {
|
||||
Player player = pplayer.getPlayer();
|
||||
Inventory inventory = player.getOpenInventory().getTopInventory();
|
||||
|
||||
inventory.clear(); // Make sure the inventory is always empty before we start adding items
|
||||
|
||||
List<String> stylesUserHasPermissionFor = PermissionManager.getStylesUserHasPermissionFor(player);
|
||||
for (int i = 0; i < stylesUserHasPermissionFor.size(); i++) {
|
||||
String s = stylesUserHasPermissionFor.get(i);
|
||||
ParticleStyle style = ParticleStyle.fromName(s);
|
||||
inventory.setItem(i, getItemForStyle(style, style == getPPlayerStyle(pplayer)));
|
||||
}
|
||||
|
||||
inventory.setItem(INVENTORY_SIZE - 1, getItemForBack());
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the menu that allows you to select some preset data
|
||||
*
|
||||
* @param pplayer The PPlayer
|
||||
*/
|
||||
private static void populateData(PPlayer pplayer) {
|
||||
Player player = pplayer.getPlayer();
|
||||
Inventory inventory = player.getOpenInventory().getTopInventory();
|
||||
|
||||
inventory.clear(); // Make sure the inventory is always empty before we start adding items
|
||||
|
||||
// There are a lot of for loops here, somebody submit a pull request if you have a better way of doing this
|
||||
ParticleEffect pe = getPPlayerEffect(pplayer);
|
||||
if (pe.hasProperty(ParticleProperty.COLORABLE)) {
|
||||
if (pe == ParticleEffect.NOTE) { // Note data
|
||||
NoteColor currentNote = getPPlayerNoteColor(pplayer);
|
||||
int noteIndex = 0;
|
||||
for (int i = 1; i <= 7; i++) { // Top row
|
||||
inventory.setItem(i, getItemForNoteData(currentNote, noteIndex));
|
||||
noteIndex++;
|
||||
}
|
||||
for (int i = 10; i <= 16; i++) { // Middle 1 row
|
||||
inventory.setItem(i, getItemForNoteData(currentNote, noteIndex));
|
||||
noteIndex++;
|
||||
}
|
||||
for (int i = 19; i <= 25; i++) { // Middle 2 row
|
||||
inventory.setItem(i, getItemForNoteData(currentNote, noteIndex));
|
||||
noteIndex++;
|
||||
}
|
||||
for (int i = 28; i <= 30; i++) { // Bottom row
|
||||
inventory.setItem(i, getItemForNoteData(currentNote, noteIndex));
|
||||
noteIndex++;
|
||||
}
|
||||
|
||||
inventory.setItem(40, getItemForRainbowNoteData(getPPlayerNoteColor(pplayer), rainbowColors[rainbowColorsIndex]));
|
||||
} else { // Color data
|
||||
OrdinaryColor currentColor = getPPlayerColor(pplayer);
|
||||
int colorIndex = 0;
|
||||
for (int i = 10; i <= 16; i++) { // Top row
|
||||
inventory.setItem(i, getItemForColorData(currentColor, colorIndex));
|
||||
colorIndex++;
|
||||
}
|
||||
for (int i = 19; i <= 25; i++) { // Middle row
|
||||
inventory.setItem(i, getItemForColorData(currentColor, colorIndex));
|
||||
colorIndex++;
|
||||
}
|
||||
for (int i = 28; i <= 29; i++) { // Bottom row
|
||||
inventory.setItem(i, getItemForColorData(currentColor, colorIndex));
|
||||
colorIndex++;
|
||||
}
|
||||
|
||||
inventory.setItem(40, getItemForRainbowColorData(getPPlayerColor(pplayer), rainbowColors[rainbowColorsIndex]));
|
||||
}
|
||||
} else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
||||
List<Material> materialBag = new ArrayList<Material>();
|
||||
int materialIndex = 0;
|
||||
|
||||
if (pe == ParticleEffect.ITEM) { // Item data
|
||||
Material currentItemMaterial = getPPlayerItemMaterial(pplayer);
|
||||
|
||||
while (materialBag.size() < 28) { // Grab 28 random materials that are an item
|
||||
Material randomMaterial = ITEM_MATERIALS.get(RANDOM.nextInt(ITEM_MATERIALS.size()));
|
||||
if (!materialBag.contains(randomMaterial)) materialBag.add(randomMaterial);
|
||||
}
|
||||
|
||||
for (int i = 10; i <= 16; i++) { // Top row
|
||||
inventory.setItem(i, getItemForMaterialData(currentItemMaterial, "item", materialBag.get(materialIndex)));
|
||||
materialIndex++;
|
||||
}
|
||||
for (int i = 19; i <= 25; i++) { // Middle 1 row
|
||||
inventory.setItem(i, getItemForMaterialData(currentItemMaterial, "item", materialBag.get(materialIndex)));
|
||||
materialIndex++;
|
||||
}
|
||||
for (int i = 28; i <= 34; i++) { // Middle 2 row
|
||||
inventory.setItem(i, getItemForMaterialData(currentItemMaterial, "item", materialBag.get(materialIndex)));
|
||||
materialIndex++;
|
||||
}
|
||||
for (int i = 37; i <= 43; i++) { // Bottom row
|
||||
inventory.setItem(i, getItemForMaterialData(currentItemMaterial, "item", materialBag.get(materialIndex)));
|
||||
materialIndex++;
|
||||
}
|
||||
} else { // Block data
|
||||
Material currentBlockMaterial = getPPlayerBlockMaterial(pplayer);
|
||||
|
||||
while (materialBag.size() < 28) { // Grab 28 random materials that are an item
|
||||
Material randomMaterial = BLOCK_MATERIALS.get(RANDOM.nextInt(BLOCK_MATERIALS.size()));
|
||||
if (!materialBag.contains(randomMaterial)) materialBag.add(randomMaterial);
|
||||
}
|
||||
|
||||
for (int i = 10; i <= 16; i++) { // Top row
|
||||
inventory.setItem(i, getItemForMaterialData(currentBlockMaterial, "block", materialBag.get(materialIndex)));
|
||||
materialIndex++;
|
||||
}
|
||||
for (int i = 19; i <= 25; i++) { // Middle 1 row
|
||||
inventory.setItem(i, getItemForMaterialData(currentBlockMaterial, "block", materialBag.get(materialIndex)));
|
||||
materialIndex++;
|
||||
}
|
||||
for (int i = 28; i <= 34; i++) { // Middle 2 row
|
||||
inventory.setItem(i, getItemForMaterialData(currentBlockMaterial, "block", materialBag.get(materialIndex)));
|
||||
materialIndex++;
|
||||
}
|
||||
for (int i = 37; i <= 43; i++) { // Bottom row
|
||||
inventory.setItem(i, getItemForMaterialData(currentBlockMaterial, "block", materialBag.get(materialIndex)));
|
||||
materialIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inventory.setItem(INVENTORY_SIZE - 1, getItemForBack());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever something is clicked in an inventory
|
||||
* Will return immediately if not the particlesInventory
|
||||
*
|
||||
* @param e The InventoryClickEvent fired from this event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onInventoryInteract(InventoryClickEvent e) {
|
||||
if (isGuiDisabled()) return; // Don't worry about processing anything if the GUI is disabled
|
||||
|
||||
if (!(e.getWhoClicked() instanceof Player)) return; // Not sure if I actually have to check this
|
||||
|
||||
Player player = (Player) e.getWhoClicked();
|
||||
GuiInventory guiInventory = playerGuiInventories.get(player.getUniqueId());
|
||||
|
||||
if (guiInventory == null || !guiInventory.getInventory().equals(e.getView().getTopInventory())) return; // Make sure it is the right inventory
|
||||
|
||||
e.setCancelled(true); // In the PlayerParticles GUI, can't let them take anything out
|
||||
|
||||
if (!guiInventory.getInventory().equals(e.getClickedInventory())) return; // Clicked bottom inventory
|
||||
|
||||
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
|
||||
if (pplayer == null) {
|
||||
player.closeInventory();
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack clicked = e.getCurrentItem();
|
||||
if (clicked == null || clicked.getType() == Material.AIR) return; // Clicked on an empty slot, do nothing
|
||||
|
||||
// Check back button. This is common for most menus
|
||||
if (clicked.getItemMeta().getDisplayName().equals(LangManager.getText(Lang.GUI_BACK_BUTTON))) {
|
||||
changeState(pplayer, GuiState.DEFAULT);
|
||||
return;
|
||||
}
|
||||
|
||||
String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName());
|
||||
switch (guiInventory.getGuiState()) {
|
||||
case DEFAULT:
|
||||
if (name.equals("Effect")) {
|
||||
changeState(pplayer, GuiState.EFFECT);
|
||||
} else if (name.equals("Style")) {
|
||||
changeState(pplayer, GuiState.STYLE);
|
||||
} else if (name.equals("Data")) {
|
||||
changeState(pplayer, GuiState.DATA);
|
||||
}
|
||||
break;
|
||||
case EFFECT:
|
||||
setPPlayerEffect(pplayer, ParticleEffect.fromName(name));
|
||||
changeState(pplayer, GuiState.DEFAULT);
|
||||
break;
|
||||
case STYLE:
|
||||
setPPlayerStyle(pplayer, ParticleStyle.fromName(name));
|
||||
changeState(pplayer, GuiState.DEFAULT);
|
||||
break;
|
||||
case DATA:
|
||||
ParticleEffect pe = getPPlayerEffect(pplayer);
|
||||
if (pe.hasProperty(ParticleProperty.COLORABLE)) {
|
||||
if (pe == ParticleEffect.NOTE) {
|
||||
if (clicked.getItemMeta().getDisplayName().equals(LangManager.getText(Lang.RAINBOW))) {
|
||||
setPPlayerNoteColor(pplayer, new NoteColor(99));
|
||||
} else {
|
||||
int note = Integer.parseInt(ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).substring(6));
|
||||
setPPlayerNoteColor(pplayer, new NoteColor(note));
|
||||
}
|
||||
} else {
|
||||
if (clicked.getItemMeta().getDisplayName().equals(LangManager.getText(Lang.RAINBOW))) {
|
||||
setPPlayerColor(pplayer, new OrdinaryColor(999, 999, 999));
|
||||
} else {
|
||||
for (int i = 0; i < colorMapping.length; i++) {
|
||||
if (clicked.getItemMeta().getDisplayName().equals(colorMapping[i].getName())) {
|
||||
setPPlayerColor(pplayer, colorMapping[i].getOrdinaryColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
||||
Material clickedMaterial = clicked.getType(); // All preset materials have a data value of 0
|
||||
if (pe == ParticleEffect.ITEM) {
|
||||
setPPlayerItemMaterial(pplayer, clickedMaterial);
|
||||
} else {
|
||||
setPPlayerBlockMaterial(pplayer, clickedMaterial);
|
||||
}
|
||||
}
|
||||
|
||||
changeState(pplayer, GuiState.DEFAULT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon for a given particle effect from the config
|
||||
*
|
||||
* @param effect The effect
|
||||
* @param isActive If this effect is the current one active
|
||||
* @return An ItemStack formatted to be displayed in the GUI
|
||||
*/
|
||||
private static ItemStack getItemForEffect(ParticleEffect effect, boolean isActive) {
|
||||
ItemStack icon = new ItemStack(effectIcons.get(effect.name()), 1);
|
||||
ItemMeta iconMeta = icon.getItemMeta();
|
||||
|
||||
iconMeta.setDisplayName(LangManager.getText(Lang.GUI_ICON_NAME_COLOR) + effect.getName());
|
||||
if (!isActive) {
|
||||
iconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "effect") + effect.getName()));
|
||||
} else {
|
||||
iconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "effect") + effect.getName(), LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "effect")));
|
||||
iconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
iconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
icon.setItemMeta(iconMeta);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon for a given particle style from the config
|
||||
*
|
||||
* @param style The style
|
||||
* @param isActive If this style is the current one active
|
||||
* @return An ItemStack formatted to be displayed in the GUI
|
||||
*/
|
||||
private static ItemStack getItemForStyle(ParticleStyle style, boolean isActive) {
|
||||
ItemStack icon = new ItemStack(styleIcons.get(style.getName().toUpperCase()), 1);
|
||||
ItemMeta iconMeta = icon.getItemMeta();
|
||||
|
||||
iconMeta.setDisplayName(LangManager.getText(Lang.GUI_ICON_NAME_COLOR) + style.getName());
|
||||
if (!isActive) {
|
||||
iconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "style") + style.getName()));
|
||||
} else {
|
||||
iconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "style") + style.getName(), LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "style")));
|
||||
iconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
iconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
icon.setItemMeta(iconMeta);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon for a given material to be used for data
|
||||
*
|
||||
* @param currentMaterial What material the player is currently using
|
||||
* @param dataType What type of data this is (block/item)
|
||||
* @param material The material to use for the icon
|
||||
* @return An ItemStack formatted to be displayed in the GUI
|
||||
*/
|
||||
private static ItemStack getItemForMaterialData(Material currentMaterial, String dataType, Material material) {
|
||||
ItemStack materialIcon = new ItemStack(material, 1);
|
||||
ItemMeta materialIconMeta = materialIcon.getItemMeta();
|
||||
|
||||
materialIconMeta.setDisplayName(LangManager.getText(Lang.GUI_ICON_NAME_COLOR) + material.name().toLowerCase());
|
||||
if (currentMaterial != material) {
|
||||
materialIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, dataType + " data") + material.name().toLowerCase()));
|
||||
} else {
|
||||
materialIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, dataType + " data") + material.name().toLowerCase(), LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, dataType + " data")));
|
||||
materialIconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
materialIconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
materialIcon.setItemMeta(materialIconMeta);
|
||||
|
||||
return materialIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon for a color to be used for data
|
||||
*
|
||||
* @param currentColor What color the player is currently using
|
||||
* @param colorIndex What color to use
|
||||
* @return An ItemStack formatted to be displayed in the GUI
|
||||
*/
|
||||
private static ItemStack getItemForColorData(OrdinaryColor currentColor, int colorIndex) {
|
||||
ColorData colorData = colorMapping[colorIndex];
|
||||
String formattedDisplayColor = ChatColor.RED.toString() + colorData.getOrdinaryColor().getRed() + " " + ChatColor.GREEN + colorData.getOrdinaryColor().getGreen() + " " + ChatColor.AQUA + colorData.getOrdinaryColor().getBlue();
|
||||
|
||||
ItemStack colorIcon;
|
||||
if (colorData.getMaterial() != null) { // Use 1.13 materials
|
||||
colorIcon = new ItemStack(colorData.getMaterial());
|
||||
} else { // Use < 1.13 dye colors
|
||||
colorIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
|
||||
}
|
||||
ItemMeta colorIconMeta = colorIcon.getItemMeta();
|
||||
|
||||
colorIconMeta.setDisplayName(colorData.getName());
|
||||
if (!currentColor.equals(colorData.getOrdinaryColor())) {
|
||||
colorIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "color data") + formattedDisplayColor));
|
||||
} else {
|
||||
colorIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "color data") + formattedDisplayColor, LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "color data")));
|
||||
colorIconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
colorIconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
colorIcon.setItemMeta(colorIconMeta);
|
||||
|
||||
return colorIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon for a note to be used for data
|
||||
*
|
||||
* @param currentNote What note the player is currently using
|
||||
* @param noteIndex What note to use
|
||||
* @return An ItemStack formatted to be displayed in the GUI
|
||||
*/
|
||||
private static ItemStack getItemForNoteData(NoteColor currentNote, int noteIndex) {
|
||||
ItemStack noteIcon = new ItemStack(Material.NOTE_BLOCK, noteIndex + 1);
|
||||
ItemMeta noteIconMeta = noteIcon.getItemMeta();
|
||||
|
||||
noteIconMeta.setDisplayName(LangManager.getText(Lang.GUI_ICON_NAME_COLOR) + "note #" + noteIndex);
|
||||
if (currentNote.getValueX() * 24 != noteIndex) {
|
||||
noteIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "note data") + "note #" + noteIndex));
|
||||
} else {
|
||||
noteIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "note data") + "note #" + noteIndex, LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "note data")));
|
||||
noteIconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
noteIconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
noteIcon.setItemMeta(noteIconMeta);
|
||||
|
||||
return noteIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon for rainbow color/note data
|
||||
*
|
||||
* @param currentColor The player's current color data
|
||||
* @param dyeColor The color of the rainbow we're on
|
||||
* @return An ItemStack formatted to be displayed in the GUI
|
||||
*/
|
||||
private static ItemStack getItemForRainbowColorData(OrdinaryColor currentColor, DyeColor dyeColor) {
|
||||
ColorData colorData = getColorDataFromOrdinaryColor(dyeColor);
|
||||
ItemStack rainbowIcon;
|
||||
if (colorData.getMaterial() != null) { // Use 1.13 materials
|
||||
rainbowIcon = new ItemStack(colorData.getMaterial());
|
||||
} else { // Use < 1.13 dye colors
|
||||
rainbowIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
|
||||
}
|
||||
ItemMeta rainbowIconMeta = rainbowIcon.getItemMeta();
|
||||
|
||||
rainbowIconMeta.setDisplayName(LangManager.getText(Lang.RAINBOW));
|
||||
if (currentColor.getRed() == 999 && currentColor.getGreen() == 999 && currentColor.getBlue() == 999) {
|
||||
rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "color data") + LangManager.getText(Lang.RAINBOW), LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "color data")));
|
||||
rainbowIconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
rainbowIconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
} else {
|
||||
rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "color data") + LangManager.getText(Lang.RAINBOW)));
|
||||
}
|
||||
rainbowIcon.setItemMeta(rainbowIconMeta);
|
||||
|
||||
return rainbowIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon for rainbow color/note data
|
||||
*
|
||||
* @param currentColor The player's current note data
|
||||
* @param dyeColor The color of the rainbow we're on
|
||||
* @return An ItemStack formatted to be displayed in the GUI
|
||||
*/
|
||||
private static ItemStack getItemForRainbowNoteData(NoteColor currentColor, DyeColor dyeColor) {
|
||||
ColorData colorData = getColorDataFromOrdinaryColor(dyeColor);
|
||||
ItemStack rainbowIcon;
|
||||
if (colorData.getMaterial() != null) { // Use 1.13 materials
|
||||
rainbowIcon = new ItemStack(colorData.getMaterial());
|
||||
} else { // Use < 1.13 dye colors
|
||||
rainbowIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
|
||||
}
|
||||
ItemMeta rainbowIconMeta = rainbowIcon.getItemMeta();
|
||||
|
||||
rainbowIconMeta.setDisplayName(LangManager.getText(Lang.RAINBOW));
|
||||
if (currentColor.getValueX() * 24 == 99) {
|
||||
rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "note data") + LangManager.getText(Lang.RAINBOW), LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "note data")));
|
||||
rainbowIconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
|
||||
rainbowIconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
} else {
|
||||
rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "note data") + LangManager.getText(Lang.RAINBOW)));
|
||||
}
|
||||
rainbowIcon.setItemMeta(rainbowIconMeta);
|
||||
|
||||
return rainbowIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon used to return to the previous menu
|
||||
*
|
||||
* @return An ItemStack formatted to be displayed in the GUI
|
||||
*/
|
||||
private static ItemStack getItemForBack() {
|
||||
ItemStack icon = new ItemStack(Material.ARROW, 1);
|
||||
ItemMeta iconMeta = icon.getItemMeta();
|
||||
iconMeta.setDisplayName(LangManager.getText(Lang.GUI_BACK_BUTTON));
|
||||
icon.setItemMeta(iconMeta);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a ColorData object from its DyeColor
|
||||
*
|
||||
* @param color The DyeColor
|
||||
* @return The found ColorData object, null if not found
|
||||
*/
|
||||
private static ColorData getColorDataFromOrdinaryColor(DyeColor color) {
|
||||
for (ColorData colorData : colorMapping)
|
||||
if (colorData.getDyeColor().equals(color)) return colorData;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,10 @@ import java.io.InputStream;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -26,7 +29,7 @@ import com.esophose.playerparticles.util.ParticleUtils;
|
|||
public class ParticleGroup {
|
||||
|
||||
public static final String DEFAULT_NAME = "active";
|
||||
private static List<ParticleGroup> presetGroups;
|
||||
private static HashMap<ParticleGroup, Material> presetGroups;
|
||||
|
||||
private String name;
|
||||
private List<ParticlePair> particles;
|
||||
|
@ -85,7 +88,7 @@ public class ParticleGroup {
|
|||
* @param pluginDataFolder
|
||||
*/
|
||||
public static void reload() {
|
||||
presetGroups = new ArrayList<ParticleGroup>();
|
||||
presetGroups = new HashMap<ParticleGroup, Material>();
|
||||
|
||||
File pluginDataFolder = PlayerParticles.getPlugin().getDataFolder();
|
||||
File groupsFile = new File(pluginDataFolder.getAbsolutePath() + File.separator + "groups.yml");
|
||||
|
@ -105,10 +108,16 @@ public class ParticleGroup {
|
|||
for (String groupName : groupNames) {
|
||||
try {
|
||||
List<ParticlePair> particles = new ArrayList<ParticlePair>();
|
||||
Material iconMaterial = null;
|
||||
ConfigurationSection groupSection = groupsYaml.getConfigurationSection(groupName);
|
||||
|
||||
Set<String> particleKeys = groupSection.getKeys(false);
|
||||
for (String stringId : particleKeys) {
|
||||
if (stringId.equalsIgnoreCase("icon")) {
|
||||
iconMaterial = Material.valueOf(groupSection.getString("icon"));
|
||||
continue;
|
||||
}
|
||||
|
||||
ConfigurationSection particleSection = groupSection.getConfigurationSection(stringId);
|
||||
|
||||
int id = Integer.parseInt(stringId);
|
||||
|
@ -203,13 +212,25 @@ public class ParticleGroup {
|
|||
particles.add(new ParticlePair(null, id, effect, style, blockData, blockData, colorData, noteColorData));
|
||||
}
|
||||
|
||||
presetGroups.add(new ParticleGroup(groupName, particles));
|
||||
if (iconMaterial == null) {
|
||||
|
||||
}
|
||||
|
||||
presetGroups.put(new ParticleGroup(groupName, particles), iconMaterial);
|
||||
} catch (Exception ex) {
|
||||
PlayerParticles.getPlugin().getLogger().severe("An error occurred while parsing the groups.yml file!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<Entry<ParticleGroup, Material>> getPresetGroupsForGUIForPlayer(Player player) {
|
||||
Set<Entry<ParticleGroup, Material>> groups = new HashSet<Entry<ParticleGroup, Material>>();
|
||||
for (Entry<ParticleGroup, Material> entry : presetGroups.entrySet())
|
||||
if (entry.getKey().canPlayerUse(player))
|
||||
groups.add(entry);
|
||||
return groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the preset ParticleGroups that a player can use
|
||||
*
|
||||
|
@ -217,7 +238,7 @@ public class ParticleGroup {
|
|||
* @return a List of preset ParticleGroups the player can use
|
||||
*/
|
||||
public static List<ParticleGroup> getPresetGroupsForPlayer(Player player) {
|
||||
return presetGroups.stream().filter(x -> x.canPlayerUse(player)).collect(Collectors.toList());
|
||||
return presetGroups.keySet().stream().filter(x -> x.canPlayerUse(player)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -227,7 +248,7 @@ public class ParticleGroup {
|
|||
* @return The preset ParticleGroup if it exists, otherwise null
|
||||
*/
|
||||
public static ParticleGroup getPresetGroup(String groupName) {
|
||||
for (ParticleGroup group : presetGroups)
|
||||
for (ParticleGroup group : presetGroups.keySet())
|
||||
if (group.getName().equalsIgnoreCase(groupName))
|
||||
return group;
|
||||
return null;
|
||||
|
|
|
@ -50,8 +50,10 @@ public class ParticlePair {
|
|||
* @param effect The player's new particle effect
|
||||
*/
|
||||
public void setEffect(ParticleEffect effect) {
|
||||
if (effect == null) effect = ParticleEffect.FLAME;
|
||||
this.effect = effect;
|
||||
if (effect == null)
|
||||
this.effect = getDefault().getEffect();
|
||||
else
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,8 +62,10 @@ public class ParticlePair {
|
|||
* @param style The player's new particle style
|
||||
*/
|
||||
public void setStyle(ParticleStyle style) {
|
||||
if (style == null) style = DefaultStyles.NORMAL;
|
||||
this.style = style;
|
||||
if (style == null)
|
||||
this.style = getDefault().getStyle();
|
||||
else
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,8 +74,10 @@ public class ParticlePair {
|
|||
* @param itemMaterial The player's new item material
|
||||
*/
|
||||
public void setItemMaterial(Material itemMaterial) {
|
||||
if (itemMaterial == null || itemMaterial.isBlock()) itemMaterial = ParticleUtils.closestMatchWithFallback("IRON_SHOVEL", "IRON_SPADE");
|
||||
this.itemMaterial = itemMaterial;
|
||||
if (itemMaterial == null || itemMaterial.isBlock())
|
||||
this.itemMaterial = getDefault().getItemMaterial();
|
||||
else
|
||||
this.itemMaterial = itemMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,8 +86,10 @@ public class ParticlePair {
|
|||
* @param blockMaterial The player's new block material
|
||||
*/
|
||||
public void setBlockMaterial(Material blockMaterial) {
|
||||
if (blockMaterial == null) blockMaterial = Material.STONE;
|
||||
this.blockMaterial = blockMaterial;
|
||||
if (blockMaterial == null || !blockMaterial.isBlock())
|
||||
this.blockMaterial = getDefault().getBlockMaterial();
|
||||
else
|
||||
this.blockMaterial = blockMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,8 +98,10 @@ public class ParticlePair {
|
|||
* @param colorData The player's new color data
|
||||
*/
|
||||
public void setColor(OrdinaryColor colorData) {
|
||||
if (colorData == null) colorData = new OrdinaryColor(0, 0, 0);
|
||||
this.color = colorData;
|
||||
if (colorData == null)
|
||||
this.color = getDefault().getColor();
|
||||
else
|
||||
this.color = colorData;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,8 +110,10 @@ public class ParticlePair {
|
|||
* @param noteColorData The player's new note color data
|
||||
*/
|
||||
public void setNoteColor(NoteColor noteColorData) {
|
||||
if (noteColorData == null) noteColorData = new NoteColor(0);
|
||||
this.noteColor = noteColorData;
|
||||
if (noteColorData == null)
|
||||
this.noteColor = getDefault().getNoteColor();
|
||||
else
|
||||
this.noteColor = noteColorData;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,7 +266,6 @@ public class ParticlePair {
|
|||
*
|
||||
* @return A ParticlePair with default values
|
||||
*/
|
||||
@Deprecated // TODO: REMOVE ONCE NEW GUI IS DONE
|
||||
public static ParticlePair getDefault() {
|
||||
return new ParticlePair(null, // @formatter:off
|
||||
-1,
|
||||
|
|
|
@ -49,10 +49,12 @@ disabled-worlds: []
|
|||
# - add_more_under_these
|
||||
|
||||
# The maximum number of particles a player can apply at once
|
||||
# The GUI will only display up to 14, don't set this any higher than that
|
||||
# Default: 3
|
||||
max-particles: 3
|
||||
|
||||
# The maximum number of groups a player can have saved
|
||||
# The GUI will only display up to 14, don't set this any higher than that
|
||||
# Default: 10
|
||||
max-groups: 10
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
# * The groups listed within this file will be #
|
||||
# available to all players who have access to the #
|
||||
# effect and style! #
|
||||
# * The GUI is capable of displaying up to 28 groups. #
|
||||
# * Feel free to create your own, they will be #
|
||||
# available for users to select within the GUI! #
|
||||
# * This file is not automatically updated. If you #
|
||||
|
@ -11,7 +12,11 @@
|
|||
# delete it and run the command '/pp reload'. #
|
||||
# ==================================================== #
|
||||
|
||||
# Icons MUST use the names found at the link below:
|
||||
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
|
||||
|
||||
raincloud:
|
||||
icon: 'ENDER_CHEST'
|
||||
1:
|
||||
effect: 'cloud'
|
||||
style: 'overhead'
|
||||
|
@ -21,6 +26,7 @@ raincloud:
|
|||
style: 'overhead'
|
||||
data: ''
|
||||
rainbows:
|
||||
icon: 'ENDER_CHEST'
|
||||
1:
|
||||
effect: 'dust'
|
||||
style: 'orbit'
|
||||
|
|
|
@ -2,7 +2,7 @@ name: PlayerParticles
|
|||
main: com.esophose.playerparticles.PlayerParticles
|
||||
version: 5.3
|
||||
api-version: 1.13
|
||||
description: Make particles around players in fancy ways.
|
||||
description: Display particles around your player using customized styles and data!
|
||||
author: Esophose
|
||||
website: https://dev.bukkit.org/projects/playerparticles
|
||||
commands:
|
||||
|
|
Loading…
Reference in a new issue