Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Code of eventHandler
- public class StMenuListener implements Listener {
- private final ConfigManager configManager;
- public StMenuListener(ConfigManager configManager) {
- this.configManager = configManager;
- }
- @EventHandler
- public void onInventoryDrag(InventoryDragEvent event) {
- String stMenuTitle = configManager.getString("lang.yml", "st.st-title");
- String stMenuColor = TextColorUtil.colorize(stMenuTitle);
- if (ChatColor.stripColor(event.getView().getTitle()).equals(ChatColor.stripColor(stMenuColor))) {
- event.setCancelled(true);
- }
- }
- }
- //ConfigManager
- public class ConfigManager {
- private static FileConfiguration getConfig(String fileName) {
- File pluginFolder = new File("plugins/EndiumMMO");
- if (!pluginFolder.exists()) {
- boolean created = pluginFolder.mkdirs();
- if (!created) {
- System.out.println("Unable to create: " + pluginFolder);
- }
- }
- File file = new File("plugins/EndiumMMO", fileName);
- if (!file.exists()) {
- try {
- file.createNewFile();
- } catch (IOException e) {
- System.out.println("Failed to create " + fileName);
- }
- }
- return YamlConfiguration.loadConfiguration(file);
- }
- public static String getString(String fileName, String path) {
- FileConfiguration config = getConfig(fileName);
- return config != null ? config.getString(path) : null;
- }
- public static int getInt(String fileName, String path) {
- FileConfiguration config = getConfig(fileName);
- return config != null ? config.getInt(path) : 0;
- }
- public static boolean getBoolean(String fileName, String path) {
- FileConfiguration config = getConfig(fileName);
- return config != null && config.getBoolean(path);
- }
- public static List<String> getStringList(String fileName, String path) {
- FileConfiguration config = getConfig(fileName);
- return config != null ? config.getStringList(path) : null;
- }
- public static List<Integer> getIntegerList(String fileName, String path) {
- FileConfiguration config = getConfig(fileName);
- return config != null ? config.getIntegerList(path) : null;
- }
- public static void setValue(String fileName, String path, Object value) {
- File file = new File("plugins/EndiumMMO", fileName);
- if (!file.exists()) {
- try {
- file.createNewFile();
- } catch (IOException e) {
- System.out.println("Failed to create " + fileName);
- }
- }
- FileConfiguration config = YamlConfiguration.loadConfiguration(file);
- config.set(path, value);
- try {
- config.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void setIntListInline(String fileName, String path, List<Integer> list) {
- String inlineList = list.toString();
- setValue(fileName, path, inlineList);
- }
- public static List<Integer> getIntListInline(String fileName, String path) {
- String listString = getString(fileName, path);
- if (listString == null || listString.isEmpty()) {
- return null;
- }
- return Arrays.stream(listString.replace("[", "").replace("]", "").split(","))
- .map(String::trim)
- .map(Integer::parseInt)
- .collect(Collectors.toList());
- }
- }
- //TextColorUtil
- public class TextColorUtil {
- public static String colorize(String text) {
- return ChatColor.translateAlternateColorCodes('&', text);
- }
- public static String removeColors(String text) {
- return ChatColor.stripColor(text);
- }
- }
- //GUI
- public class StatisticGUI {
- public StatisticGUI(Player player, Player target) {
- ConfigManager configManager = new ConfigManager();
- String targetName = target.getName();
- int sizeMenu = ConfigManager.getInt("guis/st.yml", "st.menu-size");
- String stMenuTitle = ConfigManager.getString("lang.yml", "st.st-title").replace("{player}", targetName);
- String stMenuColor = TextColorUtil.colorize(stMenuTitle);
- Inventory inventory = Bukkit.createInventory(null, sizeMenu, stMenuColor);
- List<Integer> fillMaterialList = configManager.getIntListInline("guis/st.yml", "st.material-slots");
- String materialFill = configManager.getString("guis/st.yml", "st.material-fill");
- Material materialConfigFill = Material.valueOf(materialFill);
- ItemStack materialStack = new ItemStack(materialConfigFill, 1);
- for (int slot : fillMaterialList) {
- if (slot >= 0 && slot < inventory.getSize()) {
- inventory.setItem(slot, materialStack);
- }
- player.openInventory(inventory);
- }
- }
- }
Add Comment
Please, Sign In to add comment