├── .gitignore
├── README.md
├── pom.xml
└── src
└── main
├── java
└── dev
│ └── _2lstudios
│ └── interfacemaker
│ ├── InterfaceMaker.java
│ ├── commands
│ ├── HotbarCommand.java
│ ├── InterfaceMakerCommand.java
│ ├── ListCommand.java
│ ├── MenuCommand.java
│ └── ReloadCommand.java
│ ├── configs
│ ├── ConfigManager.java
│ ├── HotbarConfigProcessor.java
│ ├── ItemConfigProcessor.java
│ └── MenuConfigProcessor.java
│ ├── interfaces
│ ├── Buildable.java
│ ├── InterfaceHotbar.java
│ ├── InterfaceItem.java
│ ├── InterfaceMakerAPI.java
│ ├── InterfaceMenu.java
│ ├── QueuedBuildable.java
│ ├── contexts
│ │ ├── HotbarBuildContext.java
│ │ └── MenuBuildContext.java
│ └── holders
│ │ ├── InterfaceInventoryHolder.java
│ │ └── InterfaceItemHolder.java
│ ├── listeners
│ ├── InventoryClickListener.java
│ ├── InventoryCloseListener.java
│ ├── InventoryDragListener.java
│ ├── PlayerCommandPreProcessListener.java
│ ├── PlayerDropItemListener.java
│ ├── PlayerInteractListener.java
│ ├── PlayerJoinListener.java
│ └── PlayerQuitListener.java
│ ├── placeholders
│ └── Formatter.java
│ ├── player
│ ├── InterfacePlayer.java
│ └── InterfacePlayerManager.java
│ ├── tasks
│ └── RefreshTask.java
│ ├── utils
│ ├── InventoryUtils.java
│ └── ProxyUtils.java
│ └── vault
│ └── VaultProvider.java
└── resources
├── config.yml
├── hotbars
└── default.yml
├── menus
└── default.yml
└── plugin.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Eclipse
2 | .settings/
3 | bin/
4 | tmp/
5 | .metadata
6 | .classpath
7 | .project
8 | *.tmp
9 | *.bak
10 | *.swp
11 | *~.nib
12 | local.properties
13 | .loadpath
14 | .factorypath
15 |
16 | ## IntelliJ
17 | out/
18 | .idea/
19 | .idea_modules/
20 | *.iml
21 | *.ipr
22 | *.iws
23 |
24 | ## Java
25 | .mtj.tmp/
26 | *.class
27 | *.jar
28 | *.war
29 | *.ear
30 | *.nar
31 | hs_err_pid*
32 |
33 | ## Maven
34 | target/
35 | pom.xml.tag
36 | pom.xml.releaseBackup
37 | pom.xml.versionsBackup
38 | pom.xml.next
39 | pom.xml.bak
40 | release.properties
41 | dependency-reduced-pom.xml
42 | buildNumber.properties
43 | .mvn/timing.properties
44 | .mvn/wrapper/maven-wrapper.jar
45 |
46 | ## NetBeans
47 | nbproject/private/
48 | build/
49 | nbbuild/
50 | dist/
51 | nbdist/
52 | nbactions.xml
53 | nb-configuration.xml
54 |
55 | ## OS X
56 | .DS_Store
57 |
58 | ## VS Code
59 | .vscode/
60 | .code-workspace
61 |
62 | # Dev Tools
63 | build.sh
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Interface Maker
2 |
3 | InterfaceMaker is a modern plugin to handle and customize join items, hotbars and menus with a developer friendly API.
4 |
5 | # Features
6 |
7 | * Simple to understand configuration for server administrator.
8 |
9 | * Complex but easy to use API to simplify item handling for inventories and hotbars on custom plugins like Minigames or Lobby/Hub Cores.
10 |
11 | * HEX Support for everything to achieve a beautiful server design.
12 |
13 | * Fast operations to achieve good performance results.
14 |
15 | # How to (Server Admins)
16 |
17 | You can get a copy of InterfaceMaker on MC-Market.
18 |
19 | # How to (Developers)
20 |
21 | Clone this repository, run `mvn package` and get the binaries from `./target/` folder.
22 |
23 | ## Creating a Menu
24 |
25 | Create a new menu `new InterfaceMenu()` create items `new InterfaceItem()` set them `menu.setItem(Integer, InterfaceItem)` and build it `menu.build(Player)`.
26 |
27 | Menus can be extended and use the `onBuild(MenuBuildContext)` event. Items can be extended to use the `onInteract(Player)` and `onClick(Player, Inventory)` events.
28 |
29 | ## Creating a Hotbar
30 |
31 | Create a new hotbar `new InterfaceHotbar()` create items `new InterfaceItem()` set them `hotbar.setItem(slot, item)` and build it `hotbar.build(player)`.
32 |
33 | # Join us
34 |
35 | 
36 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | dev._2lstudios
5 | InterfaceMaker
6 | jar
7 |
8 | InterfaceMaker
9 | InterfaceMaker is a modern plugin to handle and customize join items, hotbars and menus with a developer and administrator friendly API.
10 | 1.0.0
11 | https://github.com/2lstudios-mc/InterfaceMaker
12 |
13 |
14 | 2LStudios
15 | dev._2lstudios.interfacemaker.InterfaceMaker
16 | UTF-8
17 |
18 |
19 |
20 |
21 | spigot-repo
22 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
23 |
24 |
25 | placeholderapi
26 | https://repo.extendedclip.com/content/repositories/placeholderapi/
27 |
28 |
29 | jitpack.io
30 | https://jitpack.io
31 |
32 |
33 | 2lstudios
34 | https://ci.2lstudios.dev/plugin/repository/everything/
35 |
36 |
37 |
38 |
39 |
40 | org.spigotmc
41 | spigot-api
42 | 1.18.2-R0.1-SNAPSHOT
43 | provided
44 |
45 |
46 | me.clip
47 | placeholderapi
48 | 2.11.1
49 | provided
50 |
51 |
52 | com.iridium
53 | IridiumColorAPI
54 | 1.0.6
55 |
56 |
57 | com.github.MilkBowl
58 | VaultAPI
59 | 1.7
60 | provided
61 |
62 |
63 |
64 |
65 | ${project.artifactId}
66 | src/main/java
67 | clean install
68 |
69 |
70 | src/main/resources
71 | true
72 |
73 | **/*.java
74 |
75 |
76 |
77 |
78 |
79 |
80 | maven-compiler-plugin
81 | 3.8.1
82 |
83 | 1.8
84 | 1.8
85 |
86 |
87 |
88 |
89 | maven-assembly-plugin
90 | 3.3.0
91 |
92 |
93 | jar-with-dependencies
94 |
95 | false
96 |
97 |
98 |
99 | make-assembly
100 | package
101 |
102 | single
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/InterfaceMaker.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker;
2 |
3 | import java.io.File;
4 |
5 | import org.bukkit.Server;
6 | import org.bukkit.configuration.Configuration;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.plugin.PluginManager;
9 | import org.bukkit.plugin.java.JavaPlugin;
10 |
11 | import dev._2lstudios.interfacemaker.commands.InterfaceMakerCommand;
12 | import dev._2lstudios.interfacemaker.configs.ConfigManager;
13 | import dev._2lstudios.interfacemaker.configs.HotbarConfigProcessor;
14 | import dev._2lstudios.interfacemaker.configs.ItemConfigProcessor;
15 | import dev._2lstudios.interfacemaker.configs.MenuConfigProcessor;
16 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
17 | import dev._2lstudios.interfacemaker.listeners.InventoryClickListener;
18 | import dev._2lstudios.interfacemaker.listeners.InventoryCloseListener;
19 | import dev._2lstudios.interfacemaker.listeners.InventoryDragListener;
20 | import dev._2lstudios.interfacemaker.listeners.PlayerCommandPreProcessListener;
21 | import dev._2lstudios.interfacemaker.listeners.PlayerDropItemListener;
22 | import dev._2lstudios.interfacemaker.listeners.PlayerInteractListener;
23 | import dev._2lstudios.interfacemaker.listeners.PlayerJoinListener;
24 | import dev._2lstudios.interfacemaker.listeners.PlayerQuitListener;
25 | import dev._2lstudios.interfacemaker.player.InterfacePlayerManager;
26 | import dev._2lstudios.interfacemaker.tasks.RefreshTask;
27 |
28 | public class InterfaceMaker extends JavaPlugin {
29 | private static InterfaceMaker plugin;
30 |
31 | public static InterfaceMaker getPlugin() {
32 | return plugin;
33 | }
34 |
35 | public void reloadFiles() {
36 | plugin = this;
37 |
38 | saveDefaultConfig();
39 |
40 | api.clearConfiguredHotbars();
41 | api.clearConfiguredInventories();
42 |
43 | ConfigManager configManager = new ConfigManager(this);
44 | ItemConfigProcessor itemConfigProcessor = new ItemConfigProcessor();
45 | HotbarConfigProcessor hotbarConfigProcessor = new HotbarConfigProcessor(api, itemConfigProcessor);
46 | MenuConfigProcessor menuConfigProcessor = new MenuConfigProcessor(api, itemConfigProcessor);
47 | File hotBarsFolder = new File(getDataFolder(), "hotbars");
48 | File menusFolder = new File(getDataFolder(), "menus");
49 |
50 | if (!hotBarsFolder.exists()) {
51 | configManager.saveConfig("hotbars/default.yml");
52 | }
53 |
54 | if (!menusFolder.exists()) {
55 | configManager.saveConfig("menus/default.yml");
56 | }
57 |
58 | for (File file : hotBarsFolder.listFiles()) {
59 | Configuration config = configManager.getConfig(file);
60 |
61 | hotbarConfigProcessor.process(file.getName().replace(".yml", ""), config);
62 | }
63 |
64 | for (File file : menusFolder.listFiles()) {
65 | Configuration config = configManager.getConfig(file);
66 |
67 | menuConfigProcessor.process(file.getName().replace(".yml", ""), config);
68 | }
69 | }
70 |
71 | @Override
72 | public void onEnable() {
73 | Server server = getServer();
74 | InterfaceMaker.api = new InterfaceMakerAPI(this);
75 | PluginManager pluginManager = server.getPluginManager();
76 |
77 | reloadFiles();
78 |
79 | InterfacePlayerManager interfacePlayerManager = api.getInterfacePlayerManager();
80 |
81 | for (Player player : server.getOnlinePlayers()) {
82 | interfacePlayerManager.create(player);
83 | }
84 |
85 | pluginManager.registerEvents(new InventoryClickListener(api), this);
86 | pluginManager.registerEvents(new InventoryCloseListener(api), this);
87 | pluginManager.registerEvents(new InventoryDragListener(api), this);
88 | pluginManager.registerEvents(new PlayerCommandPreProcessListener(api), this);
89 | pluginManager.registerEvents(new PlayerDropItemListener(api), this);
90 | pluginManager.registerEvents(new PlayerInteractListener(api), this);
91 | pluginManager.registerEvents(new PlayerJoinListener(api), this);
92 | pluginManager.registerEvents(new PlayerQuitListener(api), this);
93 |
94 | server.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
95 |
96 | getCommand("interfacemaker").setExecutor(new InterfaceMakerCommand(api, this));
97 |
98 | server.getScheduler().runTaskTimer(this, new RefreshTask(api), 1L, 1L);
99 | }
100 |
101 | private static InterfaceMakerAPI api;
102 |
103 | public static InterfaceMakerAPI getAPI() {
104 | return InterfaceMaker.api;
105 | }
106 | }
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/commands/HotbarCommand.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.commands;
2 |
3 | import org.bukkit.command.Command;
4 | import org.bukkit.command.CommandExecutor;
5 | import org.bukkit.command.CommandSender;
6 | import org.bukkit.configuration.Configuration;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.plugin.Plugin;
9 |
10 | import dev._2lstudios.interfacemaker.interfaces.InterfaceHotbar;
11 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
12 | import dev._2lstudios.interfacemaker.placeholders.Formatter;
13 |
14 | public class HotbarCommand implements CommandExecutor {
15 | private InterfaceMakerAPI api;
16 | private Plugin plugin;
17 | private Configuration config;
18 |
19 | public HotbarCommand(InterfaceMakerAPI api, Plugin plugin, Configuration config) {
20 | this.api = api;
21 | this.plugin = plugin;
22 | this.config = config;
23 | }
24 |
25 | @Override
26 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
27 | if (args.length <= 1) {
28 | Formatter.sendMessage(sender,
29 | config.getString("messages.menu-usage").replace("%label%", label));
30 | } else {
31 | String hotbarName = args[1];
32 | InterfaceHotbar hotbar = api.getConfiguredHotbar(hotbarName);
33 |
34 | if (hotbar == null) {
35 | Formatter.sendMessage(sender,
36 | config.getString("messages.unexistant-hotbar").replace("%hotbar%", hotbarName));
37 | } else {
38 | Player target = null;
39 |
40 | if (args.length <= 2 && !(sender instanceof Player)) {
41 | Formatter.sendMessage(sender,
42 | config.getString("messages.no-console"));
43 | } else {
44 | if (args.length > 2) {
45 | target = plugin.getServer().getPlayerExact(args[2]);
46 | } else {
47 | target = (Player) sender;
48 | }
49 |
50 | if (target == null || !target.isOnline()) {
51 | Formatter.sendMessage(sender,
52 | config.getString("messages.offline").replace("%player%", args[2]));
53 | } else {
54 | String openPermission = "interfacemaker.hotbar." + hotbarName;
55 | String otherPermission = "interfacemaker.open-others";
56 |
57 | if (target != sender && !sender.hasPermission(otherPermission)) {
58 | Formatter.sendMessage(sender, config.getString("messages.no-permission-hotbar-others")
59 | .replace("%hotbar%", hotbarName).replace("%permission%", otherPermission));
60 | } else if (!sender.hasPermission(openPermission)) {
61 | Formatter.sendMessage(sender, config.getString("messages.no-permission-hotbar")
62 | .replace("%hotbar%", hotbarName).replace("%permission%", openPermission));
63 | } else {
64 | hotbar.build(target);
65 |
66 | if (target == sender) {
67 | Formatter.sendMessage(sender, config.getString("messages.opened-hotbar")
68 | .replace("%hotbar%", hotbarName));
69 | } else {
70 | Formatter.sendMessage(sender, config.getString("messages.opened-hotbar-other")
71 | .replace("%hotbar%", hotbarName).replace("%player%", target.getName()));
72 | }
73 | }
74 | }
75 | }
76 | }
77 | }
78 |
79 | return true;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/commands/InterfaceMakerCommand.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.commands;
2 |
3 | import org.bukkit.command.Command;
4 | import org.bukkit.command.CommandExecutor;
5 | import org.bukkit.command.CommandSender;
6 | import org.bukkit.configuration.Configuration;
7 |
8 | import dev._2lstudios.interfacemaker.InterfaceMaker;
9 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
10 | import dev._2lstudios.interfacemaker.placeholders.Formatter;
11 |
12 | public class InterfaceMakerCommand implements CommandExecutor {
13 | private InterfaceMakerAPI api;
14 | private InterfaceMaker plugin;
15 |
16 | public InterfaceMakerCommand(InterfaceMakerAPI api, InterfaceMaker plugin) {
17 | this.api = api;
18 | this.plugin = plugin;
19 | }
20 |
21 | @Override
22 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
23 | Configuration config = api.getConfig();
24 |
25 | if (args.length > 0) {
26 | String arg0 = args[0].toLowerCase();
27 |
28 | if (arg0.equals("reload")) {
29 | new ReloadCommand(plugin, config).onCommand(sender, command, label, args);
30 | } else if (arg0.equals("menu")) {
31 | new MenuCommand(api, plugin, config).onCommand(sender, command, label, args);
32 | } else if (arg0.equals("hotbar")) {
33 | new HotbarCommand(api, plugin, config).onCommand(sender, command, label, args);
34 | } else if (arg0.equals("list")) {
35 | new ListCommand(api, config).onCommand(sender, command, label, args);
36 | } else {
37 | Formatter.sendMessage(sender, config.getString("messages.no-subcommand").replace("%argument%", arg0));
38 | }
39 | } else {
40 | Formatter.sendMessage(sender, config.getString("messages.interfacemaker-usage"));
41 | }
42 |
43 | return true;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/commands/ListCommand.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.commands;
2 |
3 | import java.util.Map;
4 | import java.util.Map.Entry;
5 |
6 | import org.bukkit.command.Command;
7 | import org.bukkit.command.CommandExecutor;
8 | import org.bukkit.command.CommandSender;
9 | import org.bukkit.configuration.Configuration;
10 |
11 | import dev._2lstudios.interfacemaker.interfaces.InterfaceHotbar;
12 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
13 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMenu;
14 | import dev._2lstudios.interfacemaker.placeholders.Formatter;
15 |
16 | public class ListCommand implements CommandExecutor {
17 | private InterfaceMakerAPI api;
18 | private Configuration config;
19 |
20 | public ListCommand(InterfaceMakerAPI api, Configuration config) {
21 | this.api = api;
22 | this.config = config;
23 | }
24 |
25 | @Override
26 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
27 | if (args.length > 1) {
28 | String arg1 = args[1].toLowerCase();
29 |
30 | if (arg1.startsWith("m")) {
31 | Map menus = api.getConfiguredMenus();
32 |
33 | if (menus.isEmpty()) {
34 | Formatter.sendMessage(sender,
35 | config.getString("messages.no-menus"));
36 | } else {
37 | Formatter.sendMessage(sender,
38 | config.getString("messages.menu-list-header"));
39 |
40 | for (Entry entry : menus.entrySet()) {
41 | Formatter.sendMessage(sender,
42 | config.getString("messages.menu-list-entry").replace("%entry%", entry.getKey()));
43 | }
44 | }
45 | } else if (arg1.startsWith("h")) {
46 | Map hotbars = api.getConfiguredHotbars();
47 |
48 | if (hotbars.isEmpty()) {
49 | Formatter.sendMessage(sender,
50 | config.getString("messages.no-hotbars"));
51 | } else {
52 | Formatter.sendMessage(sender,
53 | config.getString("messages.hotbar-list-header"));
54 |
55 | for (Entry entry : hotbars.entrySet()) {
56 | Formatter.sendMessage(sender,
57 | config.getString("messages.hotbar-list-entry").replace("%entry%", entry.getKey()));
58 | }
59 | }
60 | } else {
61 | Formatter.sendMessage(sender,
62 | config.getString("messages.list-invalid-argument").replace("%argument%", arg1));
63 | }
64 | } else {
65 | Formatter.sendMessage(sender,
66 | config.getString("messages.list-usage").replace("%label%", label));
67 | }
68 |
69 | return true;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/commands/MenuCommand.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.commands;
2 |
3 | import org.bukkit.command.Command;
4 | import org.bukkit.command.CommandExecutor;
5 | import org.bukkit.command.CommandSender;
6 | import org.bukkit.configuration.Configuration;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.plugin.Plugin;
9 |
10 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
11 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMenu;
12 | import dev._2lstudios.interfacemaker.placeholders.Formatter;
13 |
14 | public class MenuCommand implements CommandExecutor {
15 | private InterfaceMakerAPI api;
16 | private Plugin plugin;
17 | private Configuration config;
18 |
19 | public MenuCommand(InterfaceMakerAPI api, Plugin plugin, Configuration config) {
20 | this.api = api;
21 | this.plugin = plugin;
22 | this.config = config;
23 | }
24 |
25 | @Override
26 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
27 | if (args.length <= 1) {
28 | Formatter.sendMessage(sender,
29 | config.getString("messages.menu-usage").replace("%label%", label));
30 | } else {
31 | String menuName = args[1];
32 | InterfaceMenu menu = api.getConfiguredMenu(menuName);
33 |
34 | if (menu == null) {
35 | Formatter.sendMessage(sender,
36 | config.getString("messages.unexistant-menu").replace("%menu%", menuName));
37 | } else {
38 | Player target = null;
39 |
40 | if (args.length <= 2 && !(sender instanceof Player)) {
41 | Formatter.sendMessage(sender,
42 | config.getString("messages.no-console"));
43 | } else {
44 | if (args.length > 2) {
45 | target = plugin.getServer().getPlayerExact(args[2]);
46 | } else {
47 | target = (Player) sender;
48 | }
49 |
50 | if (target == null || !target.isOnline()) {
51 | Formatter.sendMessage(sender,
52 | config.getString("messages.offline").replace("%player%", args[2]));
53 | } else {
54 | String openPermission = "interfacemaker.menu." + menuName;
55 | String otherPermission = "interfacemaker.open-others";
56 |
57 | if (target != sender && !sender.hasPermission(otherPermission)) {
58 | Formatter.sendMessage(sender, config.getString("messages.no-permission-menu-others")
59 | .replace("%menu%", menuName).replace("%permission%", otherPermission));
60 | } else if (!sender.hasPermission(openPermission)) {
61 | Formatter.sendMessage(sender, config.getString("messages.no-permission-menu")
62 | .replace("%menu%", menuName).replace("%permission%", openPermission));
63 | } else {
64 | menu.build(target);
65 |
66 | if (target == sender) {
67 | Formatter.sendMessage(sender, config.getString("messages.opened-menu")
68 | .replace("%menu%", menuName));
69 | } else {
70 | Formatter.sendMessage(sender, config.getString("messages.opened-menu-other")
71 | .replace("%menu%", menuName).replace("%player%", target.getName()));
72 | }
73 | }
74 | }
75 | }
76 | }
77 | }
78 |
79 | return true;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/commands/ReloadCommand.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.commands;
2 |
3 | import org.bukkit.command.Command;
4 | import org.bukkit.command.CommandExecutor;
5 | import org.bukkit.command.CommandSender;
6 | import org.bukkit.configuration.Configuration;
7 |
8 | import dev._2lstudios.interfacemaker.InterfaceMaker;
9 | import dev._2lstudios.interfacemaker.placeholders.Formatter;
10 |
11 | public class ReloadCommand implements CommandExecutor {
12 | private InterfaceMaker plugin;
13 | private Configuration config;
14 |
15 | public ReloadCommand(InterfaceMaker plugin, Configuration config) {
16 | this.plugin = plugin;
17 | this.config = config;
18 | }
19 |
20 | @Override
21 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
22 | String permission = "interfacemaker.reload";
23 |
24 | if (!sender.hasPermission(permission)) {
25 | Formatter.sendMessage(sender,
26 | config.getString("messages.no-permission")
27 | .replace("%permission%", permission)
28 | );
29 | } else {
30 | plugin.reloadFiles();
31 | Formatter.sendMessage(sender, config.getString("messages.reload"));
32 | }
33 |
34 | return true;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/configs/ConfigManager.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.configs;
2 |
3 | import java.io.File;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 |
7 | import org.bukkit.configuration.Configuration;
8 | import org.bukkit.configuration.file.YamlConfiguration;
9 | import org.bukkit.plugin.Plugin;
10 |
11 | public class ConfigManager {
12 | private Map configs;
13 | private Plugin plugin;
14 |
15 | public ConfigManager(Plugin plugin) {
16 | this.configs = new HashMap<>();
17 | this.plugin = plugin;
18 | }
19 |
20 | public Configuration getConfig(File file) {
21 | Configuration config;
22 |
23 | try {
24 | config = YamlConfiguration.loadConfiguration(file);
25 | } catch (IllegalArgumentException ex) {
26 | config = new YamlConfiguration();
27 | }
28 |
29 | return config;
30 | }
31 |
32 | public Configuration getConfig(String name) {
33 | if (configs.containsKey(name)) {
34 | return configs.get(name);
35 | }
36 |
37 | File file = new File(plugin.getDataFolder(), name);
38 | Configuration config = getConfig(file);
39 |
40 | configs.put(name, config);
41 |
42 | return config;
43 | }
44 |
45 | public Configuration saveConfig(String name) {
46 | File configFile = new File(plugin.getDataFolder(), name);
47 |
48 | if (!configFile.exists()) {
49 | configFile.getParentFile().mkdirs();
50 | plugin.saveResource(name, false);
51 | }
52 |
53 | return getConfig(name);
54 | }
55 | }
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/configs/HotbarConfigProcessor.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.configs;
2 |
3 | import org.bukkit.configuration.Configuration;
4 | import org.bukkit.configuration.ConfigurationSection;
5 |
6 | import dev._2lstudios.interfacemaker.interfaces.InterfaceHotbar;
7 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
8 |
9 | public class HotbarConfigProcessor {
10 | private InterfaceMakerAPI api;
11 | private ItemConfigProcessor itemConfigProcessor;
12 |
13 | public HotbarConfigProcessor(InterfaceMakerAPI api, ItemConfigProcessor itemConfigProcessor) {
14 | this.api = api;
15 | this.itemConfigProcessor = itemConfigProcessor;
16 | }
17 |
18 | public void process(String menuName, Configuration config) {
19 | InterfaceHotbar interfaceHotbar = new InterfaceHotbar();
20 | ConfigurationSection hotbarSettings = config.getConfigurationSection("hotbar-settings");
21 | int autoRefresh = hotbarSettings.getInt("auto-refresh");
22 | int giveDelay = hotbarSettings.getInt("give-delay");
23 | boolean giveOnSpawn = hotbarSettings.getBoolean("give-on-spawn");
24 | boolean dropOldItems = hotbarSettings.getBoolean("drop-old-items");
25 | boolean replaceOldItems = hotbarSettings.getBoolean("replace-old-items", true);
26 | boolean clearInventory = hotbarSettings.getBoolean("clear-inventory-on-give");
27 | boolean allowMovement = hotbarSettings.getBoolean("allow-movements");
28 |
29 | interfaceHotbar.setAutoRefresh(autoRefresh);
30 | interfaceHotbar.setGiveDelay(giveDelay);
31 | interfaceHotbar.setGiveOnSpawn(giveOnSpawn);
32 | interfaceHotbar.setDropOldItems(dropOldItems);
33 | interfaceHotbar.setReplaceOldItems(replaceOldItems);
34 | interfaceHotbar.setClearInventory(clearInventory);
35 | interfaceHotbar.setAllowsMovement(allowMovement);
36 |
37 | for (String sectionName : config.getKeys(false)) {
38 | if (!sectionName.equals("hotbar-settings")) {
39 | if (config.isConfigurationSection(sectionName)) {
40 | ConfigurationSection itemSection = config.getConfigurationSection(sectionName);
41 |
42 | itemConfigProcessor.process(interfaceHotbar, itemSection);
43 | }
44 | }
45 | }
46 |
47 | api.addConfiguredHotbar(menuName, interfaceHotbar);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/configs/ItemConfigProcessor.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.configs;
2 |
3 | import java.util.List;
4 |
5 | import org.bukkit.Color;
6 | import org.bukkit.Material;
7 | import org.bukkit.configuration.ConfigurationSection;
8 |
9 | import dev._2lstudios.interfacemaker.interfaces.InterfaceItem;
10 | import dev._2lstudios.interfacemaker.interfaces.holders.InterfaceInventoryHolder;
11 |
12 | public class ItemConfigProcessor {
13 | public void process(InterfaceInventoryHolder interfaceInventoryHolder, ConfigurationSection itemSection) {
14 | InterfaceItem interfaceItem = new InterfaceItem();
15 | String materialName = itemSection.getString("material").toUpperCase();
16 | Material material = Material.getMaterial(materialName == null ? "STONE" : materialName);
17 | int durability = itemSection.getInt("durability");
18 | int positionX = Math.max(0, itemSection.getInt("position-x") - 1);
19 | int positionY = Math.max(0, itemSection.getInt("position-y") - 1);
20 | int slot = positionX + (positionY * 9);
21 | int customModel = itemSection.getInt("custom-model", -1);
22 | String name = itemSection.getString("name");
23 | List lore = itemSection.getStringList("lore");
24 | List enchantments = itemSection.getStringList("enchantments");
25 | boolean keepOpen = itemSection.getBoolean("keep-open");
26 | String permission = itemSection.getString("permission");
27 | String viewPermission = itemSection.getString("view-permission");
28 | String permissionMessage = itemSection.getString("permission-message");
29 | List requiredItems = itemSection.getStringList("required-items");
30 | int levels = itemSection.getInt("levels");
31 | int price = itemSection.getInt("price");
32 | List actions = itemSection.getStringList("actions");
33 | String skullOwner = itemSection.getString("skull-owner");
34 | String potionEffect = itemSection.getString("potion-effect");
35 | int leatherArmorColor = itemSection.getInt("leather-armor-color");
36 | List flags = itemSection.getStringList("flags");
37 |
38 | if (material != null) {
39 | interfaceItem.setType(material);
40 | interfaceItem.setDurability(durability);
41 | interfaceItem.setName(name);
42 | interfaceItem.setLore(lore);
43 | interfaceItem.setEnchantments(enchantments);
44 | interfaceItem.setKeepOpen(keepOpen);
45 | interfaceItem.setPermission(permission);
46 | interfaceItem.setViewPermission(viewPermission);
47 | interfaceItem.setPermissionMessage(permissionMessage);
48 | interfaceItem.setRequiredItems(requiredItems);
49 | interfaceItem.setLevels(levels);
50 | interfaceItem.setPrice(price);
51 | interfaceItem.setActions(actions);
52 | interfaceItem.setSkullOwner(skullOwner);
53 | interfaceItem.setMainPotionEffect(potionEffect);
54 | interfaceItem.setFlags(flags);
55 | interfaceItem.setCustomModel(customModel);
56 |
57 | if (leatherArmorColor > 0) {
58 | interfaceItem.setLeatherArmorColor(Color.fromRGB(leatherArmorColor));
59 | }
60 |
61 | interfaceInventoryHolder.setItem(slot, interfaceItem);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/configs/MenuConfigProcessor.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.configs;
2 |
3 | import java.util.List;
4 |
5 | import org.bukkit.ChatColor;
6 | import org.bukkit.Material;
7 | import org.bukkit.configuration.Configuration;
8 | import org.bukkit.configuration.ConfigurationSection;
9 |
10 | import dev._2lstudios.interfacemaker.interfaces.InterfaceItem;
11 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
12 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMenu;
13 |
14 | public class MenuConfigProcessor {
15 | private InterfaceMakerAPI api;
16 | private ItemConfigProcessor itemConfigProcessor;
17 |
18 | public MenuConfigProcessor(InterfaceMakerAPI api, ItemConfigProcessor itemConfigProcessor) {
19 | this.api = api;
20 | this.itemConfigProcessor = itemConfigProcessor;
21 | }
22 |
23 | public void process(String menuName, Configuration config) {
24 | InterfaceMenu interfaceMenu = new InterfaceMenu();
25 | ConfigurationSection menuSettings = config.getConfigurationSection("menu-settings");
26 | String title = menuSettings.getString("name");
27 | int rows = menuSettings.getInt("rows");
28 | List commands = menuSettings.getStringList("commands");
29 | int autoRefresh = menuSettings.getInt("auto-refresh");
30 | List openActions = menuSettings.getStringList("open-actions");
31 |
32 | interfaceMenu.setTitle(title);
33 | interfaceMenu.setRows(rows);
34 | interfaceMenu.setCommands(commands);
35 | interfaceMenu.setAutoRefresh(autoRefresh);
36 | interfaceMenu.setOpenActions(openActions);
37 |
38 | if (menuSettings.contains("open-with-item")) {
39 | ConfigurationSection openWithItem = menuSettings.getConfigurationSection("open-with-item");
40 | String materialName = openWithItem.getString("material").toUpperCase();
41 | Material material = Material.getMaterial(materialName);
42 | boolean leftClick = openWithItem.getBoolean("left-click");
43 | boolean rightClick = openWithItem.getBoolean("right-click");
44 |
45 | if (material != null) {
46 | interfaceMenu.setOpenWithItem(material, leftClick, rightClick);
47 | }
48 | }
49 |
50 | if (menuSettings.contains("style.fill")) {
51 | String name = menuSettings.getString("style.fill.name");
52 | short durability = (short) menuSettings.getInt("style.fill.durability", 0);
53 | String materilaName = menuSettings.getString("style.fill.material");
54 | Material material = Material.getMaterial(materilaName);
55 |
56 | if (material != null) {
57 | interfaceMenu.fillEmpty(new InterfaceItem()
58 | .setType(material)
59 | .setDurability(durability)
60 | .setName(ChatColor.translateAlternateColorCodes('&', name))
61 | );
62 | }
63 | }
64 |
65 | for (String sectionName : config.getKeys(false)) {
66 | if (!sectionName.equals("menu-settings")) {
67 | if (config.isConfigurationSection(sectionName)) {
68 | ConfigurationSection itemSection = config.getConfigurationSection(sectionName);
69 |
70 | itemConfigProcessor.process(interfaceMenu, itemSection);
71 | }
72 | }
73 | }
74 |
75 | api.addConfiguredMenu(menuName, interfaceMenu);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/interfaces/Buildable.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.interfaces;
2 |
3 | import org.bukkit.entity.Player;
4 | import org.bukkit.inventory.Inventory;
5 |
6 | public interface Buildable {
7 | public Buildable build(Player player);
8 |
9 | public Buildable build(Player player, Inventory inventory);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/interfaces/InterfaceHotbar.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.interfaces;
2 |
3 | import java.util.Map;
4 |
5 | import org.bukkit.entity.Player;
6 | import org.bukkit.inventory.Inventory;
7 |
8 | import dev._2lstudios.interfacemaker.InterfaceMaker;
9 | import dev._2lstudios.interfacemaker.interfaces.contexts.HotbarBuildContext;
10 | import dev._2lstudios.interfacemaker.interfaces.holders.InterfaceInventoryHolder;
11 |
12 | public class InterfaceHotbar extends InterfaceInventoryHolder implements Buildable {
13 | private InterfaceMakerAPI api = InterfaceMaker.getAPI();
14 | private int autoRefresh = 0;
15 | private int giveDelay = 0;
16 | private boolean allowMovements = false;
17 | private boolean giveOnSpawn = false;
18 | private boolean dropOldItems = false;
19 | private boolean replaceOldItems = true;
20 | private boolean clearInventory = false;
21 |
22 | public InterfaceHotbar() {
23 | super(9, "Hotbar");
24 | }
25 |
26 | public InterfaceHotbar setItem(int slot, InterfaceItem item) {
27 | super.setItem(slot, item);
28 | return this;
29 | }
30 |
31 | public InterfaceHotbar populateItems(Player player, Inventory inventory, Map items) {
32 | super.populateItems(player, inventory, items, dropOldItems, replaceOldItems);
33 | return this;
34 | }
35 |
36 | public InterfaceHotbar populateItems(Player player, Inventory inventory) {
37 | super.populateItems(player, inventory);
38 | return this;
39 | }
40 |
41 | public InterfaceHotbar setRows(int rows) {
42 | super.setRows(rows);
43 | return this;
44 | }
45 |
46 | public InterfaceHotbar fill(int gap, InterfaceItem... items) {
47 | super.fill(gap, items);
48 | return this;
49 | }
50 |
51 | public InterfaceHotbar fillEmpty(InterfaceItem item) {
52 | super.fillEmpty(item);
53 | return this;
54 | }
55 |
56 | public boolean allowsMovement() {
57 | return this.allowMovements;
58 | }
59 |
60 | public InterfaceHotbar build(Player player, Inventory inventory) {
61 | HotbarBuildContext context = new HotbarBuildContext(player, this);
62 |
63 | if (this.clearInventory) {
64 | inventory.clear();
65 | }
66 |
67 | context.setInventory(inventory);
68 | context.addItems(getItems());
69 |
70 | onBuild(context);
71 |
72 | context.populateItems(player, inventory);
73 |
74 | api.setHotbar(player, context);
75 |
76 | return this;
77 | }
78 |
79 | public InterfaceHotbar build(Player player) {
80 | return build(player, player.getInventory());
81 | }
82 |
83 | public InterfaceHotbar setGiveOnSpawn(boolean giveOnSpawn) {
84 | this.giveOnSpawn = giveOnSpawn;
85 | return this;
86 | }
87 |
88 | public boolean giveOnSpawn() {
89 | return giveOnSpawn;
90 | }
91 |
92 | public InterfaceHotbar setDropOldItems(boolean dropOldItems) {
93 | this.dropOldItems = dropOldItems;
94 | return this;
95 | }
96 |
97 | public boolean dropOldItems() {
98 | return dropOldItems;
99 | }
100 |
101 | public InterfaceHotbar setReplaceOldItems(boolean replaceOldItems) {
102 | this.replaceOldItems = replaceOldItems;
103 | return this;
104 | }
105 |
106 | public boolean replaceOldItems() {
107 | return replaceOldItems;
108 | }
109 |
110 | public InterfaceHotbar setAutoRefresh(int autoRefresh) {
111 | this.autoRefresh = autoRefresh;
112 | return this;
113 | }
114 |
115 | public int getAutoRefresh() {
116 | return autoRefresh;
117 | }
118 |
119 | public void setClearInventory(boolean clearInventory) {
120 | this.clearInventory = clearInventory;
121 | }
122 |
123 | public void setAllowsMovement(boolean allowMovements) {
124 | this.allowMovements = allowMovements;
125 | }
126 |
127 | public void setGiveDelay(int giveDelay) {
128 | this.giveDelay = giveDelay;
129 | }
130 |
131 | public int getGiveDelay() {
132 | return giveDelay;
133 | }
134 |
135 | public InterfaceHotbar buildLater(Player player, int giveDelay) {
136 | api.queueBuild(player, this, giveDelay);
137 | return this;
138 | }
139 |
140 | public void onBuild(HotbarBuildContext context) {
141 | // Overriden by super class
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/interfaces/InterfaceItem.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.interfaces;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.Collection;
6 | import java.util.HashMap;
7 | import java.util.HashSet;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.Map.Entry;
11 |
12 | import org.bukkit.Color;
13 | import org.bukkit.Material;
14 | import org.bukkit.enchantments.Enchantment;
15 | import org.bukkit.entity.Player;
16 | import org.bukkit.inventory.Inventory;
17 | import org.bukkit.inventory.ItemFlag;
18 | import org.bukkit.inventory.ItemStack;
19 | import org.bukkit.inventory.meta.ItemMeta;
20 | import org.bukkit.inventory.meta.LeatherArmorMeta;
21 | import org.bukkit.inventory.meta.PotionMeta;
22 | import org.bukkit.inventory.meta.SkullMeta;
23 | import org.bukkit.potion.Potion;
24 | import org.bukkit.potion.PotionEffectType;
25 | import org.bukkit.potion.PotionType;
26 |
27 | import dev._2lstudios.interfacemaker.InterfaceMaker;
28 | import dev._2lstudios.interfacemaker.placeholders.Formatter;
29 |
30 | public class InterfaceItem {
31 | private Material type = Material.DIRT;
32 | private Map enchantments = new HashMap<>();
33 | private List lore = new ArrayList<>();
34 | private Collection actions = new HashSet<>();
35 | private Collection requiredItems = new HashSet<>();
36 | private Collection flags = new HashSet<>();
37 | private String name = "InterfaceMaker";
38 | private String permission = null;
39 | private String viewPermission = null;
40 | private String permissionMessage = null;
41 | private String skullOwner = null;
42 | private String mainPotionEffect = null;
43 | private Color leatherArmorColor = null;
44 | private int amount = 1;
45 | private int levels = 0;
46 | private int price = 0;
47 | private int customModel = -1;
48 | private short durability = 0;
49 | private boolean movement = false;
50 | private boolean interaction = false;
51 | private boolean keepOpen = false;
52 |
53 | public ItemStack build(Player player) {
54 | ItemStack item = new ItemStack(type, amount);
55 | ItemMeta itemMeta = item.getItemMeta();
56 |
57 | if (mainPotionEffect != null && itemMeta instanceof PotionMeta) {
58 | PotionEffectType potionEffectType = PotionEffectType.getByName(mainPotionEffect);
59 |
60 | if (potionEffectType != null) {
61 | PotionType type = PotionType.getByEffect(potionEffectType);
62 | Potion potion = new Potion(type);
63 |
64 | item = potion.toItemStack(amount);
65 | itemMeta = item.getItemMeta();
66 | }
67 | }
68 |
69 | itemMeta.setDisplayName(Formatter.format(player, name));
70 |
71 | if (customModel != -1) {
72 | try {
73 | itemMeta.getClass().getMethod("setCustomModelData", Integer.class);
74 | itemMeta.setCustomModelData(this.customModel);
75 | } catch (NoSuchMethodException | SecurityException ignored) {
76 | InterfaceMaker.getPlugin().getLogger().warning("This version of Spigot does not support CustomModelData.");
77 | }
78 | }
79 |
80 | if (lore != null && !lore.isEmpty()) {
81 | itemMeta.setLore(Formatter.format(player, new ArrayList<>(lore)));
82 | }
83 |
84 | if (skullOwner != null && itemMeta instanceof SkullMeta) {
85 | ((SkullMeta) itemMeta).setOwner(skullOwner.replace("%player%", player.getName()));
86 | item.setDurability((short) 3);
87 | }
88 |
89 | if (leatherArmorColor != null && itemMeta instanceof LeatherArmorMeta) {
90 | ((LeatherArmorMeta) itemMeta).setColor(leatherArmorColor);
91 | }
92 |
93 | for (Entry entry : enchantments.entrySet()) {
94 | itemMeta.addEnchant(entry.getKey(), entry.getValue(), true);
95 | }
96 |
97 | for (ItemFlag flag : flags) {
98 | itemMeta.addItemFlags(flag);
99 | }
100 |
101 | item.setItemMeta(itemMeta);
102 | item.setAmount(amount);
103 |
104 | if (durability != 0) {
105 | item.setDurability(durability);
106 | }
107 |
108 | return item;
109 | }
110 |
111 | public InterfaceItem setLeatherArmorColor(Color color) {
112 | this.leatherArmorColor = color;
113 | return this;
114 | }
115 |
116 | public Color getLeatherArmorColor() {
117 | return leatherArmorColor;
118 | }
119 |
120 | public InterfaceItem setMainPotionEffect(String potionEffect) {
121 | this.mainPotionEffect = potionEffect;
122 | return this;
123 | }
124 |
125 | public String getMainPotionEffect() {
126 | return mainPotionEffect;
127 | }
128 |
129 | public InterfaceItem setSkullOwner(String owner) {
130 | this.skullOwner = owner;
131 | return this;
132 | }
133 |
134 | public String getSkullOwner() {
135 | return skullOwner;
136 | }
137 |
138 | public InterfaceItem setName(String name) {
139 | this.name = name;
140 | return this;
141 | }
142 |
143 | public InterfaceItem setLore(List lore) {
144 | this.lore = lore;
145 | return this;
146 | }
147 |
148 | public InterfaceItem setLore(String... lore) {
149 | return setLore(Arrays.asList(lore));
150 | }
151 |
152 | public InterfaceItem setLore(String lore) {
153 | return setLore(lore.split("\n"));
154 | }
155 |
156 | public InterfaceItem addLoreLine(String line) {
157 | this.lore.add(line);
158 | return this;
159 | }
160 |
161 | public InterfaceItem setType(Material type) {
162 | this.type = type == null ? Material.DIRT : type;
163 | return this;
164 | }
165 |
166 | public InterfaceItem setType(String name) {
167 | Material type = Material.getMaterial(name);
168 |
169 | return setType(type);
170 | }
171 |
172 | public InterfaceItem setAmount(int amount) {
173 | this.amount = amount;
174 | return this;
175 | }
176 |
177 | public InterfaceItem setAllowsMovement(boolean movement) {
178 | this.movement = movement;
179 | return this;
180 | }
181 |
182 | public InterfaceItem setInteraction(boolean interaction) {
183 | this.interaction = interaction;
184 | return this;
185 | }
186 |
187 | public boolean allowsMovement() {
188 | return movement;
189 | }
190 |
191 | public boolean allowsInteraction() {
192 | return interaction;
193 | }
194 |
195 | public InterfaceItem setDurability(short durability) {
196 | this.durability = durability;
197 | return this;
198 | }
199 |
200 | public InterfaceItem setDurability(int durability) {
201 | return setDurability((short) durability);
202 | }
203 |
204 | public InterfaceItem addEnchantment(Enchantment enchantment, int level) {
205 | enchantments.put(enchantment, level);
206 | return this;
207 | }
208 |
209 | public InterfaceItem setCustomModel(int model) {
210 | this.customModel = model;
211 | return this;
212 | }
213 |
214 | public InterfaceItem setEnchantments(List enchantments) {
215 | this.enchantments.clear();
216 |
217 | if (this.enchantments != null) {
218 | for (String text : enchantments) {
219 | String[] splittedText = text.split(", ");
220 | String enchantmentName = splittedText[0].toUpperCase();
221 | String enchantmentLevelString = splittedText[1];
222 |
223 | try {
224 | Enchantment enchantment = Enchantment.getByName(enchantmentName);
225 | int level = Integer.parseInt(enchantmentLevelString);
226 |
227 | if (enchantment != null) {
228 | addEnchantment(enchantment, level);
229 | }
230 | } catch (NumberFormatException ex) {
231 | // Ignored
232 | }
233 | }
234 | }
235 |
236 | return this;
237 | }
238 |
239 | public InterfaceItem setKeepOpen(boolean keepOpen) {
240 | this.keepOpen = keepOpen;
241 | return this;
242 | }
243 |
244 | public InterfaceItem setPermission(String permission) {
245 | this.permission = permission;
246 | return this;
247 | }
248 |
249 | public InterfaceItem setViewPermission(String viewPermission) {
250 | this.viewPermission = viewPermission;
251 | return this;
252 | }
253 |
254 | public InterfaceItem setPermissionMessage(String permissionMessage) {
255 | this.permissionMessage = permissionMessage;
256 | return this;
257 | }
258 |
259 | public InterfaceItem setRequiredItems(List requiredItems) {
260 | for (String text : requiredItems) {
261 | String[] splittedText = text.split(", ");
262 | String[] splittedMaterial = splittedText[0].split(":");
263 | String materialName = splittedMaterial[0].toUpperCase();
264 | String amountString = splittedText[1];
265 | Material type = Material.getMaterial(materialName);
266 |
267 | if (type != null) {
268 | try {
269 | int amount = Integer.parseInt(amountString);
270 | short data = 0;
271 |
272 | if (splittedMaterial.length > 1) {
273 | try {
274 | data = Short.parseShort(splittedMaterial[1]);
275 | } catch (NumberFormatException ex) {
276 | // Ignored
277 | }
278 | }
279 |
280 | ItemStack item = new ItemStack(type, amount, data);
281 | this.requiredItems.add(item);
282 | } catch (NumberFormatException ex) {
283 | // Ignored
284 | }
285 | }
286 | }
287 |
288 | return this;
289 | }
290 |
291 | public InterfaceItem setLevels(int levels) {
292 | this.levels = levels;
293 | return this;
294 | }
295 |
296 | public InterfaceItem setPrice(int price) {
297 | this.price = price;
298 | return this;
299 | }
300 |
301 | public InterfaceItem setActions(List actions) {
302 | this.actions = actions;
303 | return this;
304 | }
305 |
306 | public Material getType() {
307 | return type;
308 | }
309 |
310 | public Map getEnchantments() {
311 | return enchantments;
312 | }
313 |
314 | public InterfaceItem setEnchantments(Map enchantments) {
315 | this.enchantments = enchantments;
316 | return this;
317 | }
318 |
319 | public List getLore() {
320 | return lore;
321 | }
322 |
323 | public Collection getActions() {
324 | return actions;
325 | }
326 |
327 | public Collection getRequiredItems() {
328 | return requiredItems;
329 | }
330 |
331 | public InterfaceItem setRequiredItems(Collection requiredItems) {
332 | this.requiredItems = requiredItems;
333 | return this;
334 | }
335 |
336 | public String getName() {
337 | return name;
338 | }
339 |
340 | public String getPermission() {
341 | return permission;
342 | }
343 |
344 | public String getViewPermission() {
345 | return viewPermission;
346 | }
347 |
348 | public String getPermissionMessage() {
349 | return permissionMessage;
350 | }
351 |
352 | public int getAmount() {
353 | return amount;
354 | }
355 |
356 | public int getLevels() {
357 | return levels;
358 | }
359 |
360 | public int getPrice() {
361 | return price;
362 | }
363 |
364 | public short getDurability() {
365 | return durability;
366 | }
367 |
368 | public boolean isMovement() {
369 | return movement;
370 | }
371 |
372 | public boolean isInteraction() {
373 | return interaction;
374 | }
375 |
376 | public boolean isKeepOpen() {
377 | return keepOpen;
378 | }
379 |
380 | public void setFlags(Collection flags) {
381 | this.flags.clear();
382 |
383 | for (String flag : flags) {
384 | try {
385 | this.flags.add(ItemFlag.valueOf(flag));
386 | } catch (IllegalArgumentException ex) {
387 | // Ignored
388 | }
389 | }
390 | }
391 |
392 | public void setFlags(String... flags) {
393 | this.flags.clear();
394 |
395 | for (String flag : flags) {
396 | try {
397 | this.flags.add(ItemFlag.valueOf(flag));
398 | } catch (IllegalArgumentException ex) {
399 | // Ignored
400 | }
401 | }
402 | }
403 |
404 | public Collection getFlags() {
405 | return flags;
406 | }
407 |
408 | public void runActions(InterfaceMakerAPI api, Player player) {
409 | api.runActions(player, this.getActions());
410 | }
411 |
412 | public void onClick(Player player, Inventory clickedInventory) {
413 | // Overriden by super class
414 | }
415 |
416 | public void onRightClick(Player player, Inventory clickedInventory) {
417 | // Overriden by super class
418 | }
419 |
420 | public void onLeftClick(Player player, Inventory clickedInventory) {
421 | // Overriden by super class
422 | }
423 |
424 | public void onInteract(Player player) {
425 | // Overriden by super class
426 | }
427 |
428 | public void onRightInteract(Player player) {
429 | // Overriden by super class
430 | }
431 |
432 | public void onLeftInteract(Player player) {
433 | // Overriden by super class
434 | }
435 | }
436 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/interfaces/InterfaceMakerAPI.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.interfaces;
2 |
3 | import java.util.Collection;
4 | import java.util.HashMap;
5 | import java.util.HashSet;
6 | import java.util.Map;
7 |
8 | import org.bukkit.Server;
9 | import org.bukkit.Sound;
10 | import org.bukkit.configuration.Configuration;
11 | import org.bukkit.entity.Player;
12 | import org.bukkit.inventory.Inventory;
13 |
14 | import dev._2lstudios.interfacemaker.InterfaceMaker;
15 | import dev._2lstudios.interfacemaker.interfaces.contexts.HotbarBuildContext;
16 | import dev._2lstudios.interfacemaker.interfaces.contexts.MenuBuildContext;
17 | import dev._2lstudios.interfacemaker.placeholders.Formatter;
18 | import dev._2lstudios.interfacemaker.player.InterfacePlayerManager;
19 | import dev._2lstudios.interfacemaker.utils.ProxyUtils;
20 | import dev._2lstudios.interfacemaker.vault.VaultProvider;
21 |
22 | public class InterfaceMakerAPI {
23 | private InterfaceMaker plugin;
24 | private InterfacePlayerManager interfacePlayerManager;
25 | private VaultProvider vaultProvider;
26 |
27 | private Map configuredMenus = new HashMap<>();
28 | private Map configuredHotbars = new HashMap<>();
29 | private Map openedMenus = new HashMap<>();
30 | private Map openedHotbars = new HashMap<>();
31 |
32 | private Collection queuedBuildables = new HashSet<>();
33 |
34 | public InterfaceMakerAPI(InterfaceMaker plugin) {
35 | this.plugin = plugin;
36 | this.interfacePlayerManager = new InterfacePlayerManager(this);
37 | this.vaultProvider = new VaultProvider(plugin.getServer());
38 | }
39 |
40 | public InterfacePlayerManager getInterfacePlayerManager() {
41 | return interfacePlayerManager;
42 | }
43 |
44 | public InterfaceMenu getConfiguredMenu(String name) {
45 | return configuredMenus.getOrDefault(name, null);
46 | }
47 |
48 | public Collection getConfiguredMenusValues() {
49 | return configuredMenus.values();
50 | }
51 |
52 | public Map getConfiguredMenus() {
53 | return configuredMenus;
54 | }
55 |
56 | public void addConfiguredMenu(String name, InterfaceMenu interfaceMenu) {
57 | configuredMenus.put(name, interfaceMenu);
58 | }
59 |
60 | public InterfaceHotbar getConfiguredHotbar(String name) {
61 | return configuredHotbars.getOrDefault(name, null);
62 | }
63 |
64 | public Collection getConfiguredHotbarsValues() {
65 | return configuredHotbars.values();
66 | }
67 |
68 | public Map getConfiguredHotbars() {
69 | return configuredHotbars;
70 | }
71 |
72 | public void addConfiguredHotbar(String name, InterfaceHotbar interfaceHotbar) {
73 | configuredHotbars.put(name, interfaceHotbar);
74 | }
75 |
76 | public MenuBuildContext getOpenedMenuContext(Inventory inventory) {
77 | return openedMenus.getOrDefault(inventory, null);
78 | }
79 |
80 | public InterfaceMenu getOpenedMenu(Inventory inventory) {
81 | MenuBuildContext context = getOpenedMenuContext(inventory);
82 |
83 | if (context != null) {
84 | return context.getMenu();
85 | }
86 |
87 | return null;
88 | }
89 |
90 | public void setMenu(Inventory inventory, MenuBuildContext context) {
91 | openedMenus.put(inventory, context);
92 | }
93 |
94 | public void unsetMenu(Inventory inventory) {
95 | openedMenus.remove(inventory);
96 | }
97 |
98 | public HotbarBuildContext getHotbarContext(Player player) {
99 | return openedHotbars.getOrDefault(player, null);
100 | }
101 |
102 | public InterfaceHotbar getHotbar(Player player) {
103 | HotbarBuildContext context = getHotbarContext(player);
104 |
105 | if (context != null) {
106 | return context.getHotbar();
107 | }
108 |
109 | return null;
110 | }
111 |
112 | public void setHotbar(Player player, HotbarBuildContext context) {
113 | openedHotbars.put(player, context);
114 | }
115 |
116 | public void unsetHotbar(Player player) {
117 | openedHotbars.remove(player);
118 | }
119 |
120 | public void clearConfiguredHotbars() {
121 | configuredHotbars.clear();
122 | }
123 |
124 | public void clearConfiguredInventories() {
125 | configuredMenus.clear();
126 | }
127 |
128 | public Configuration getConfig() {
129 | return plugin.getConfig();
130 | }
131 |
132 | public VaultProvider getVaultProvider() {
133 | return vaultProvider;
134 | }
135 |
136 | public void runActions(Player player, Collection actions) {
137 | for (String rawAction : actions) {
138 | String[] parts = rawAction.split(":");
139 |
140 | if (parts.length > 0) {
141 | String action = parts[0].trim().toLowerCase();
142 | String arg = parts[1].trim().replace("%player_name%", player.getName());
143 |
144 | switch (action) {
145 | case "tell": {
146 | player.sendMessage(Formatter.format(player, arg));
147 | break;
148 | }
149 | case "open-menu": {
150 | InterfaceMenu inventory = this.getConfiguredMenu(arg);
151 |
152 | if (inventory != null) {
153 | inventory.build(player);
154 | }
155 |
156 | break;
157 | }
158 | case "give-hotbar": {
159 | InterfaceHotbar hotbar = this.getConfiguredHotbar(arg);
160 |
161 | if (hotbar != null) {
162 | hotbar.build(player);
163 | }
164 |
165 | break;
166 | }
167 | case "console": {
168 | Server server = player.getServer();
169 | server.dispatchCommand(server.getConsoleSender(), arg.replace("%player%", player.getName()));
170 | break;
171 | }
172 | case "player": {
173 | player.chat("/" + arg);
174 | break;
175 | }
176 | case "server": {
177 | ProxyUtils.sendToServer(this.plugin, player, arg);
178 | break;
179 | }
180 | case "sound": {
181 | String soundName = arg.toUpperCase();
182 |
183 | try {
184 | player.playSound(player.getLocation(), Sound.valueOf(soundName), 1, 1);
185 | } catch (IllegalArgumentException ex) {
186 | plugin.getLogger().warning("Tried to play invalid sound: " + soundName);
187 | }
188 | break;
189 | }
190 | }
191 | }
192 | }
193 | }
194 |
195 | public Map getOpenedMenuContexts() {
196 | return openedMenus;
197 | }
198 |
199 | public Map getOpenedHotbarContexts() {
200 | return openedHotbars;
201 | }
202 |
203 | public void queueBuild(Player player, Buildable buildable, int giveDelay) {
204 | queuedBuildables.add(new QueuedBuildable(buildable, player, giveDelay));
205 | }
206 |
207 | public Collection getQueuedBuildables() {
208 | return queuedBuildables;
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/interfaces/InterfaceMenu.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.interfaces;
2 |
3 | import java.util.Collection;
4 | import java.util.HashSet;
5 | import java.util.Map;
6 |
7 | import org.bukkit.Bukkit;
8 | import org.bukkit.Material;
9 | import org.bukkit.Server;
10 | import org.bukkit.entity.Player;
11 | import org.bukkit.inventory.Inventory;
12 |
13 | import dev._2lstudios.interfacemaker.InterfaceMaker;
14 | import dev._2lstudios.interfacemaker.interfaces.contexts.MenuBuildContext;
15 | import dev._2lstudios.interfacemaker.interfaces.holders.InterfaceInventoryHolder;
16 | import dev._2lstudios.interfacemaker.placeholders.Formatter;
17 |
18 | public class InterfaceMenu extends InterfaceInventoryHolder implements Buildable {
19 | private InterfaceMakerAPI api = InterfaceMaker.getAPI();
20 | private Server server = Bukkit.getServer();
21 | private boolean movement = false;
22 | private Collection commands = new HashSet<>();
23 | private int autoRefresh = 0;
24 | private Collection openActions = new HashSet<>();
25 | private Material openWithItemMaterial = null;
26 | private boolean openWithItemLeftClick = false;
27 | private boolean openWithItemRightClick = true;
28 |
29 | public InterfaceMenu() {
30 | super(27, "InterfaceMaker");
31 | }
32 |
33 | public InterfaceMenu setItem(int slot, InterfaceItem item) {
34 | super.setItem(slot, item);
35 | return this;
36 | }
37 |
38 | public InterfaceMenu populateItems(Player player, Inventory inventory, Map items) {
39 | super.populateItems(player, inventory, items);
40 | return this;
41 | }
42 |
43 | public InterfaceMenu populateItems(Player player, Inventory inventory) {
44 | super.populateItems(player, inventory);
45 | return this;
46 | }
47 |
48 | public InterfaceMenu setRows(int rows) {
49 | super.setRows(rows);
50 | return this;
51 | }
52 |
53 | public InterfaceMenu fill(int gap, InterfaceItem... items) {
54 | super.fill(gap, items);
55 | return this;
56 | }
57 |
58 | public InterfaceMenu fillEmpty(InterfaceItem item) {
59 | super.fillEmpty(item);
60 | return this;
61 | }
62 |
63 | public InterfaceMenu build(Player player, Inventory inventory) {
64 | int size = getSize();
65 | MenuBuildContext context = new MenuBuildContext(player, this, getTitle(), size);
66 |
67 | if (inventory == null) {
68 | inventory = server.createInventory(context, size, Formatter.format(player, context.getTitle()));
69 | }
70 |
71 | context.setInventory(inventory);
72 | context.addItems(getItems());
73 |
74 | onBuild(context);
75 |
76 | context.populateItems(player, inventory);
77 |
78 | if (player.getInventory() != inventory) {
79 | player.closeInventory();
80 | player.openInventory(inventory);
81 | }
82 |
83 | api.setMenu(inventory, context);
84 | api.runActions(player, this.getOpenActions());
85 |
86 | return this;
87 | }
88 |
89 | public InterfaceMenu build(Player player) {
90 | return build(player, null);
91 | }
92 |
93 | public boolean allowsMovement() {
94 | return movement;
95 | }
96 |
97 | public InterfaceMenu setCommands(Collection commands) {
98 | this.commands = commands;
99 | return this;
100 | }
101 |
102 | public InterfaceMenu setAutoRefresh(int autoRefresh) {
103 | this.autoRefresh = autoRefresh;
104 | return this;
105 | }
106 |
107 | public InterfaceMenu setOpenActions(Collection openActions) {
108 | this.openActions = openActions;
109 | return this;
110 | }
111 |
112 | public InterfaceMenu setOpenWithItem(Material openWithItemMaterial, boolean openWithItemLeftClick,
113 | boolean openWithItemRightClick) {
114 | this.openWithItemMaterial = openWithItemMaterial;
115 | this.openWithItemLeftClick = openWithItemLeftClick;
116 | this.openWithItemRightClick = openWithItemRightClick;
117 | return this;
118 | }
119 |
120 | public boolean isMovement() {
121 | return movement;
122 | }
123 |
124 | public InterfaceMenu setAllowsMovement(boolean movement) {
125 | this.movement = movement;
126 | return this;
127 | }
128 |
129 | public Collection getCommands() {
130 | return commands;
131 | }
132 |
133 | public int getAutoRefresh() {
134 | return autoRefresh;
135 | }
136 |
137 | public Collection getOpenActions() {
138 | return openActions;
139 | }
140 |
141 | public Material getOpenWithItemMaterial() {
142 | return openWithItemMaterial;
143 | }
144 |
145 | public boolean isOpenWithItemLeftClick() {
146 | return openWithItemLeftClick;
147 | }
148 |
149 | public boolean isOpenWithItemRightClick() {
150 | return openWithItemRightClick;
151 | }
152 |
153 | public InterfaceMenu buildLater(Player player, int giveDelay) {
154 | api.queueBuild(player, this, giveDelay);
155 | return this;
156 | }
157 |
158 | public void onBuild(MenuBuildContext context) {
159 | // Overriden by super class
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/interfaces/QueuedBuildable.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.interfaces;
2 |
3 | import org.bukkit.entity.Player;
4 |
5 | public class QueuedBuildable {
6 | private Buildable buildable;
7 | private Player player;
8 | private int ticks;
9 |
10 | public QueuedBuildable(Buildable buildable, Player player, int ticks) {
11 | this.buildable = buildable;
12 | this.player = player;
13 | this.ticks = ticks;
14 | }
15 |
16 | public int tick() {
17 | return --ticks;
18 | }
19 |
20 | public void build() {
21 | if (player != null && player.isOnline()) {
22 | buildable.build(player);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/interfaces/contexts/HotbarBuildContext.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.interfaces.contexts;
2 |
3 | import org.bukkit.entity.Player;
4 |
5 | import dev._2lstudios.interfacemaker.interfaces.InterfaceHotbar;
6 | import dev._2lstudios.interfacemaker.interfaces.holders.InterfaceInventoryHolder;
7 |
8 | public class HotbarBuildContext extends InterfaceInventoryHolder {
9 | private Player player;
10 | private InterfaceHotbar hotbar;
11 |
12 | public HotbarBuildContext(Player player, InterfaceHotbar hotbar) {
13 | super(9, "Hotbar");
14 | this.player = player;
15 | this.hotbar = hotbar;
16 | }
17 |
18 | public Player getPlayer() {
19 | return player;
20 | }
21 |
22 | public InterfaceHotbar getHotbar() {
23 | return hotbar;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/interfaces/contexts/MenuBuildContext.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.interfaces.contexts;
2 |
3 | import org.bukkit.entity.Player;
4 |
5 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMenu;
6 | import dev._2lstudios.interfacemaker.interfaces.holders.InterfaceInventoryHolder;
7 |
8 | public class MenuBuildContext extends InterfaceInventoryHolder {
9 | private Player player;
10 | private InterfaceMenu menu;
11 |
12 | public MenuBuildContext(Player player, InterfaceMenu menu, String title, int inventorySize) {
13 | super(inventorySize, title);
14 | this.player = player;
15 | this.menu = menu;
16 | }
17 |
18 | public MenuBuildContext(Player player, InterfaceMenu menu) {
19 | super(menu.getSize(), menu.getTitle());
20 | this.player = player;
21 | }
22 |
23 | public Player getPlayer() {
24 | return player;
25 | }
26 |
27 | public InterfaceMenu getMenu() {
28 | return menu;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/interfaces/holders/InterfaceInventoryHolder.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.interfaces.holders;
2 |
3 | import org.bukkit.inventory.Inventory;
4 | import org.bukkit.inventory.InventoryHolder;
5 |
6 | import dev._2lstudios.interfacemaker.interfaces.InterfaceItem;
7 |
8 | public class InterfaceInventoryHolder extends InterfaceItemHolder implements InventoryHolder {
9 | private Inventory inventory;
10 | private String title;
11 | private int size;
12 |
13 | public String getTitle() {
14 | return title;
15 | }
16 |
17 | public InterfaceInventoryHolder setTitle(String title) {
18 | this.title = title;
19 | return this;
20 | }
21 |
22 | public InterfaceInventoryHolder(int inventorySize, String title) {
23 | this.size = inventorySize;
24 | this.title = title;
25 | }
26 |
27 | public InterfaceInventoryHolder setRows(int rows) {
28 | this.size = rows * 9;
29 | return this;
30 | }
31 |
32 | public int getSize() {
33 | return size;
34 | }
35 |
36 | public InterfaceInventoryHolder fill(int gap, InterfaceItem ...items) {
37 | int firstSlot = gap * 8 + gap * 2;
38 | int itemIndex = 1;
39 |
40 | for (int slot = firstSlot; slot < size; slot++) {
41 | if (itemIndex - 1 >= items.length) {
42 | break;
43 | }
44 |
45 | setItem(slot, items[itemIndex - 1]);
46 |
47 | if (itemIndex % (9 - gap * 2) == 0) {
48 | slot += (gap * 2);
49 | }
50 |
51 | itemIndex++;
52 | }
53 | return this;
54 | }
55 |
56 | public InterfaceInventoryHolder fillEmpty(InterfaceItem item) {
57 | for (int i = 0; i < size; i++) {
58 | if (!hasItem(i)) {
59 | setItem(i, item);
60 | }
61 | }
62 | return this;
63 | }
64 |
65 | public void setInventory(Inventory inventory) {
66 | this.inventory = inventory;
67 | }
68 |
69 | @Override
70 | public Inventory getInventory() {
71 | return inventory;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/interfaces/holders/InterfaceItemHolder.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.interfaces.holders;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 | import java.util.Map.Entry;
6 |
7 | import org.bukkit.Location;
8 | import org.bukkit.Material;
9 | import org.bukkit.World;
10 | import org.bukkit.entity.Player;
11 | import org.bukkit.inventory.Inventory;
12 | import org.bukkit.inventory.ItemStack;
13 |
14 | import dev._2lstudios.interfacemaker.interfaces.InterfaceItem;
15 |
16 | public class InterfaceItemHolder {
17 | private Map items = new HashMap<>();
18 |
19 | public Map getItems() {
20 | return items;
21 | }
22 |
23 | public InterfaceItem getItem(int slot) {
24 | return items.getOrDefault(slot, null);
25 | }
26 |
27 | public void addItems(Map items) {
28 | this.items.putAll(items);
29 | }
30 |
31 | public InterfaceItemHolder setItem(int startSlot, int endSlot, InterfaceItem item) {
32 | while (startSlot <= endSlot) {
33 | setItem(startSlot++, item);
34 | }
35 | return this;
36 | }
37 |
38 | public InterfaceItemHolder setItem(int slot, InterfaceItem item) {
39 | items.put(slot, item);
40 | return this;
41 | }
42 |
43 | public boolean hasItem(int slot) {
44 | return items.containsKey(slot);
45 | }
46 |
47 | public InterfaceItemHolder populateItems(Player player, Inventory inventory, Map items,
48 | boolean dropOldItems, boolean replaceOldItems) {
49 | Location location = player.getLocation();
50 | World world = location.getWorld();
51 | int inventorySize = inventory.getSize();
52 |
53 | for (Entry entry : items.entrySet()) {
54 | int slot = entry.getKey();
55 | InterfaceItem interfaceItem = entry.getValue();
56 |
57 | if (interfaceItem != null) {
58 | String viewPermission = interfaceItem.getViewPermission();
59 |
60 | if (viewPermission != null && !player.hasPermission(viewPermission)) {
61 | continue;
62 | }
63 |
64 | ItemStack item = interfaceItem.build(player);
65 |
66 | if (slot < inventorySize) {
67 | try {
68 | ItemStack oldItem = inventory.getItem(slot);
69 |
70 | if (dropOldItems && oldItem != null && oldItem.getType() != Material.AIR) {
71 | world.dropItem(location, item);
72 | }
73 |
74 | if (replaceOldItems || oldItem != null) {
75 | inventory.setItem(slot, item);
76 | }
77 | } catch (IndexOutOfBoundsException ex) {
78 | // Ignored
79 | }
80 | }
81 | }
82 | }
83 |
84 | return this;
85 | }
86 |
87 | public InterfaceItemHolder populateItems(Player player, Inventory inventory, Map items,
88 | boolean dropOldItems) {
89 | return populateItems(player, inventory, items, dropOldItems, true);
90 | }
91 |
92 | public InterfaceItemHolder populateItems(Player player, Inventory inventory, Map items) {
93 | return populateItems(player, inventory, items, false);
94 | }
95 |
96 | public InterfaceItemHolder populateItems(Player player, Inventory inventory) {
97 | populateItems(player, inventory, items);
98 | return this;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/listeners/InventoryClickListener.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.listeners;
2 |
3 | import java.util.Collection;
4 |
5 | import org.bukkit.entity.HumanEntity;
6 | import org.bukkit.entity.Player;
7 | import org.bukkit.event.EventHandler;
8 | import org.bukkit.event.Listener;
9 | import org.bukkit.event.Event.Result;
10 | import org.bukkit.event.inventory.ClickType;
11 | import org.bukkit.event.inventory.InventoryAction;
12 | import org.bukkit.event.inventory.InventoryClickEvent;
13 | import org.bukkit.inventory.Inventory;
14 | import org.bukkit.inventory.InventoryHolder;
15 | import org.bukkit.inventory.InventoryView;
16 | import org.bukkit.inventory.ItemStack;
17 | import org.bukkit.inventory.PlayerInventory;
18 |
19 | import dev._2lstudios.interfacemaker.interfaces.InterfaceHotbar;
20 | import dev._2lstudios.interfacemaker.interfaces.InterfaceItem;
21 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
22 | import dev._2lstudios.interfacemaker.interfaces.contexts.MenuBuildContext;
23 | import dev._2lstudios.interfacemaker.placeholders.Formatter;
24 | import dev._2lstudios.interfacemaker.player.InterfacePlayer;
25 | import dev._2lstudios.interfacemaker.utils.InventoryUtils;
26 | import dev._2lstudios.interfacemaker.vault.VaultProvider;
27 |
28 | public class InventoryClickListener implements Listener {
29 | private InterfaceMakerAPI api;
30 |
31 | public InventoryClickListener(InterfaceMakerAPI api) {
32 | this.api = api;
33 | }
34 |
35 | @EventHandler(ignoreCancelled = true)
36 | public void onInventoryClick(InventoryClickEvent event) {
37 | HumanEntity humanEntity = event.getWhoClicked();
38 |
39 | if (humanEntity instanceof Player) {
40 | Player player = (Player) humanEntity;
41 | InventoryView view = event.getView();
42 | Inventory clickedInventory = event.getClickedInventory();
43 |
44 | if (clickedInventory != null) {
45 | Inventory bottomInventory = view.getBottomInventory();
46 | Inventory topInventory = view.getTopInventory();
47 |
48 | InterfaceHotbar interfaceHotbar = api.getHotbar(player);
49 |
50 | int slot = event.getSlot();
51 |
52 | if (clickedInventory == bottomInventory && interfaceHotbar != null) {
53 | InterfaceItem interfaceItem = interfaceHotbar.getItem(slot);
54 |
55 | if (interfaceItem != null) {
56 | if (!interfaceHotbar.allowsMovement() || !interfaceItem.allowsMovement()) {
57 | cancelEvent(event);
58 | }
59 |
60 | InterfacePlayer interfacePlayer = api.getInterfacePlayerManager().get(player);
61 |
62 | if (interfacePlayer.isClickCooling()) {
63 | Formatter.sendMessage(player,
64 | api.getConfig().getString("messages.click-cooldown"));
65 | } else {
66 | interfacePlayer.setLastClick();
67 |
68 | ClickType click = event.getClick();
69 |
70 | interfaceItem.runActions(api, player);
71 | interfaceItem.onClick(player, clickedInventory);
72 |
73 | if (click == ClickType.LEFT) {
74 | interfaceItem.onLeftClick(player, clickedInventory);
75 | } else if (click == ClickType.RIGHT) {
76 | interfaceItem.onRightClick(player, clickedInventory);
77 | }
78 | }
79 | }
80 | }
81 |
82 | InventoryHolder inventoryHolder = clickedInventory.getHolder();
83 |
84 | if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY
85 | && clickedInventory == bottomInventory) {
86 | inventoryHolder = topInventory.getHolder();
87 | }
88 |
89 | if (inventoryHolder instanceof MenuBuildContext) {
90 | MenuBuildContext menuBuildContext = (MenuBuildContext) inventoryHolder;
91 |
92 | if (menuBuildContext != null) {
93 | if (!menuBuildContext.getMenu().allowsMovement()) {
94 | cancelEvent(event);
95 | }
96 |
97 | InterfaceItem interfaceItem = menuBuildContext.getItem(slot);
98 |
99 | if (interfaceItem != null) {
100 | if (!interfaceItem.allowsMovement()) {
101 | cancelEvent(event);
102 | }
103 |
104 | InterfacePlayer interfacePlayer = api.getInterfacePlayerManager().get(player);
105 |
106 | if (interfacePlayer.isClickCooling()) {
107 | Formatter.sendMessage(player,
108 | api.getConfig().getString("messages.click-cooldown"));
109 | } else {
110 | int levels = interfaceItem.getLevels();
111 |
112 | if (levels > 0) {
113 | int playerLevel = player.getLevel();
114 |
115 | if (playerLevel >= levels) {
116 | player.setLevel(playerLevel - levels);
117 | } else {
118 | Formatter.sendMessage(player,
119 | api.getConfig().getString("messages.no-levels")
120 | .replace("%levels%", String.valueOf(levels)));
121 | return;
122 | }
123 | }
124 |
125 | String permission = interfaceItem.getPermission();
126 |
127 | if (permission != null && !player.hasPermission(permission)) {
128 | String permissionMessage = interfaceItem.getPermissionMessage();
129 |
130 | if (permissionMessage != null) {
131 | Formatter.sendMessage(player, permissionMessage);
132 | }
133 |
134 | return;
135 | }
136 |
137 | Collection requiredItems = interfaceItem.getRequiredItems();
138 |
139 | if (!requiredItems.isEmpty()) {
140 | ItemStack[] requiredItemsArray = requiredItems.toArray(new ItemStack[0]);
141 | PlayerInventory inventory = player.getInventory();
142 |
143 | if (!InventoryUtils.contains(inventory, requiredItemsArray)) {
144 | Formatter.sendMessage(player,
145 | api.getConfig().getString("messages.no-items"));
146 | return;
147 | }
148 |
149 | InventoryUtils.remove(inventory, requiredItemsArray);
150 |
151 | player.updateInventory();
152 | }
153 |
154 | int price = interfaceItem.getPrice();
155 |
156 | if (price > 0) {
157 | VaultProvider vaultProvider = api.getVaultProvider();
158 |
159 | if (!vaultProvider.isEconomyRegistered()) {
160 | Formatter.sendMessage(player,
161 | api.getConfig().getString("messages.no-economy"));
162 | return;
163 | } else if (!vaultProvider.getEconomy().has(player, price)) {
164 | Formatter.sendMessage(player,
165 | api.getConfig().getString("messages.no-balance")
166 | .replace("%price%", String.valueOf(price)));
167 | return;
168 | }
169 | }
170 |
171 | interfacePlayer.setLastClick();
172 |
173 | ClickType click = event.getClick();
174 |
175 | interfaceItem.runActions(api, player);
176 | interfaceItem.onClick(player, clickedInventory);
177 |
178 | if (click == ClickType.LEFT) {
179 | interfaceItem.onLeftClick(player, clickedInventory);
180 | } else if (click == ClickType.RIGHT) {
181 | interfaceItem.onRightClick(player, clickedInventory);
182 | }
183 | }
184 | }
185 | }
186 | }
187 | }
188 | }
189 | }
190 |
191 | private void cancelEvent(InventoryClickEvent event) {
192 | boolean isPickup = event.getAction().name().contains("PICKUP");
193 |
194 | if (isPickup) {
195 | event.setCursor(null);
196 | }
197 |
198 | event.setResult(Result.DENY);
199 | event.setCancelled(true);
200 | }
201 | }
202 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/listeners/InventoryCloseListener.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.listeners;
2 |
3 | import org.bukkit.event.EventHandler;
4 | import org.bukkit.event.Listener;
5 | import org.bukkit.event.inventory.InventoryCloseEvent;
6 | import org.bukkit.inventory.Inventory;
7 |
8 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
9 |
10 | public class InventoryCloseListener implements Listener {
11 | private InterfaceMakerAPI api;
12 |
13 | public InventoryCloseListener(InterfaceMakerAPI api) {
14 | this.api = api;
15 | }
16 |
17 | @EventHandler
18 | public void onInventoryClose(InventoryCloseEvent event) {
19 | Inventory inventory = event.getInventory();
20 |
21 | api.unsetMenu(inventory);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/listeners/InventoryDragListener.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.listeners;
2 |
3 | import java.util.Collection;
4 |
5 | import org.bukkit.event.EventHandler;
6 | import org.bukkit.event.Listener;
7 | import org.bukkit.event.Event.Result;
8 | import org.bukkit.event.inventory.InventoryDragEvent;
9 | import org.bukkit.inventory.Inventory;
10 | import org.bukkit.inventory.InventoryView;
11 |
12 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMenu;
13 | import dev._2lstudios.interfacemaker.interfaces.InterfaceItem;
14 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
15 |
16 | public class InventoryDragListener implements Listener {
17 | private InterfaceMakerAPI api;
18 |
19 | public InventoryDragListener(InterfaceMakerAPI api) {
20 | this.api = api;
21 | }
22 |
23 | @EventHandler(ignoreCancelled = true)
24 | public void onInventoryDrag(InventoryDragEvent event) {
25 | InventoryView view = event.getView();
26 | Inventory topInventory = view.getTopInventory();
27 | InterfaceMenu interfaceMenu = api.getOpenedMenu(topInventory);
28 |
29 | if (interfaceMenu != null) {
30 | if (interfaceMenu.allowsMovement()) {
31 | Collection slots = event.getInventorySlots();
32 |
33 | for (int slot : slots) {
34 | InterfaceItem interfaceItem = interfaceMenu.getItem(slot);
35 |
36 | if (interfaceItem != null) {
37 | if (!interfaceItem.allowsMovement()) {
38 | cancelEvent(event);
39 | }
40 | }
41 | }
42 | } else {
43 | cancelEvent(event);
44 | }
45 | }
46 | }
47 |
48 | private void cancelEvent(InventoryDragEvent event) {
49 | event.setResult(Result.DENY);
50 | event.setCancelled(true);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/listeners/PlayerCommandPreProcessListener.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.listeners;
2 |
3 | import java.util.Map.Entry;
4 |
5 | import org.bukkit.entity.Player;
6 | import org.bukkit.event.EventHandler;
7 | import org.bukkit.event.Listener;
8 | import org.bukkit.event.player.PlayerCommandPreprocessEvent;
9 |
10 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMenu;
11 | import dev._2lstudios.interfacemaker.placeholders.Formatter;
12 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
13 |
14 | public class PlayerCommandPreProcessListener implements Listener {
15 | private InterfaceMakerAPI api;
16 |
17 | public PlayerCommandPreProcessListener(InterfaceMakerAPI api) {
18 | this.api = api;
19 | }
20 |
21 | @EventHandler(ignoreCancelled = true)
22 | public void onPlayerCommandPreProcess(PlayerCommandPreprocessEvent event) {
23 | String message = event.getMessage();
24 |
25 | if (message.startsWith("/") && message.length() > 1) {
26 | String alias = message.substring(message.indexOf("/") + 1);
27 |
28 | for (Entry entry : api.getConfiguredMenus().entrySet()) {
29 | InterfaceMenu inventory = entry.getValue();
30 |
31 | if (inventory.getCommands().contains(alias)) {
32 | String menuName = entry.getKey();
33 | Player player = event.getPlayer();
34 |
35 | String openPermission = "interfacemaker.menu." + menuName;
36 |
37 | if (player.hasPermission(openPermission)) {
38 | inventory.build(player);
39 | event.setCancelled(true);
40 | } else {
41 | Formatter.sendMessage(player, api.getConfig().getString("messages.no-permission-menu")
42 | .replace("%menu%", menuName).replace("%permission%", openPermission));
43 | }
44 |
45 | break;
46 | }
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/listeners/PlayerDropItemListener.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.listeners;
2 |
3 | import org.bukkit.entity.Player;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.Listener;
6 | import org.bukkit.event.player.PlayerDropItemEvent;
7 |
8 | import dev._2lstudios.interfacemaker.interfaces.InterfaceHotbar;
9 | import dev._2lstudios.interfacemaker.interfaces.InterfaceItem;
10 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
11 |
12 | public class PlayerDropItemListener implements Listener {
13 | private InterfaceMakerAPI api;
14 |
15 | public PlayerDropItemListener(InterfaceMakerAPI api) {
16 | this.api = api;
17 | }
18 |
19 | @EventHandler(ignoreCancelled = true)
20 | public void onPlayerDropItem(PlayerDropItemEvent event) {
21 | Player player = event.getPlayer();
22 | int slot = player.getInventory().getHeldItemSlot();
23 | InterfaceHotbar interfaceHotbar = api.getHotbar(player);
24 |
25 | if (interfaceHotbar != null) {
26 | if (!interfaceHotbar.allowsMovement()) {
27 | event.setCancelled(true);
28 | } else {
29 | InterfaceItem interfaceItem = interfaceHotbar.getItem(slot);
30 |
31 | if (interfaceItem != null) {
32 | if (!interfaceItem.allowsMovement()) {
33 | event.setCancelled(true);
34 | }
35 | }
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/listeners/PlayerInteractListener.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.listeners;
2 |
3 | import java.util.Collection;
4 |
5 | import org.bukkit.Material;
6 | import org.bukkit.entity.Player;
7 | import org.bukkit.event.EventHandler;
8 | import org.bukkit.event.Listener;
9 | import org.bukkit.event.block.Action;
10 | import org.bukkit.event.player.PlayerInteractEvent;
11 | import org.bukkit.inventory.ItemStack;
12 | import org.bukkit.inventory.PlayerInventory;
13 |
14 | import dev._2lstudios.interfacemaker.interfaces.InterfaceHotbar;
15 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMenu;
16 | import dev._2lstudios.interfacemaker.placeholders.Formatter;
17 | import dev._2lstudios.interfacemaker.player.InterfacePlayer;
18 | import dev._2lstudios.interfacemaker.utils.InventoryUtils;
19 | import dev._2lstudios.interfacemaker.vault.VaultProvider;
20 | import dev._2lstudios.interfacemaker.interfaces.InterfaceItem;
21 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
22 |
23 | public class PlayerInteractListener implements Listener {
24 | private InterfaceMakerAPI api;
25 |
26 | public PlayerInteractListener(InterfaceMakerAPI api) {
27 | this.api = api;
28 | }
29 |
30 | @EventHandler
31 | public void onPlayerInteract(PlayerInteractEvent event) {
32 | if (event.getAction() != Action.PHYSICAL) {
33 | Player player = event.getPlayer();
34 | InterfaceHotbar interfaceHotbar = api.getHotbar(player);
35 | PlayerInventory playerInventory = player.getInventory();
36 | int slot = playerInventory.getHeldItemSlot();
37 | ItemStack item = playerInventory.getItem(slot);
38 |
39 | if (item != null) {
40 | Material material = item.getType();
41 |
42 | for (InterfaceMenu inventory : api.getConfiguredMenusValues()) {
43 | Action action = event.getAction();
44 | boolean isActionLeft = action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK;
45 | boolean isActionRight = action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK;
46 |
47 | if (inventory.getOpenWithItemMaterial() == material &&
48 | ((inventory.isOpenWithItemLeftClick() && isActionLeft) ||
49 | (inventory.isOpenWithItemRightClick() && isActionRight))) {
50 | InterfacePlayer interfacePlayer = api.getInterfacePlayerManager().get(player);
51 |
52 | if (interfacePlayer.isInteractCooling()) {
53 | Formatter.sendMessage(player, api.getConfig().getString("messages.interact-cooldown"));
54 | } else {
55 | inventory.build(player);
56 | }
57 |
58 | return;
59 | }
60 | }
61 | }
62 |
63 | if (interfaceHotbar != null) {
64 | InterfaceItem interfaceItem = interfaceHotbar.getItem(slot);
65 |
66 | if (interfaceItem != null) {
67 | if (!interfaceItem.allowsInteraction()) {
68 | event.setCancelled(true);
69 | }
70 |
71 | InterfacePlayer interfacePlayer = api.getInterfacePlayerManager().get(player);
72 |
73 | if (interfacePlayer.isInteractCooling()) {
74 | Formatter.sendMessage(player, api.getConfig().getString("messages.interact-cooldown"));
75 | } else {
76 | int levels = interfaceItem.getLevels();
77 |
78 | if (levels > 0) {
79 | int playerLevel = player.getLevel();
80 |
81 | if (playerLevel >= levels) {
82 | player.setLevel(playerLevel - levels);
83 | } else {
84 | Formatter.sendMessage(player,
85 | api.getConfig().getString("messages.no-levels")
86 | .replace("%levels%", String.valueOf(levels)));
87 | return;
88 | }
89 | }
90 |
91 | String permission = interfaceItem.getPermission();
92 |
93 | if (permission != null && !player.hasPermission(permission)) {
94 | String permissionMessage = interfaceItem.getPermissionMessage();
95 |
96 | if (permissionMessage != null) {
97 | Formatter.sendMessage(player, permissionMessage);
98 | }
99 |
100 | return;
101 | }
102 |
103 | Collection requiredItems = interfaceItem.getRequiredItems();
104 |
105 | if (!requiredItems.isEmpty()) {
106 | ItemStack[] requiredItemsArray = requiredItems.toArray(new ItemStack[0]);
107 | PlayerInventory inventory = player.getInventory();
108 |
109 | if (!InventoryUtils.contains(inventory, requiredItemsArray)) {
110 | Formatter.sendMessage(player,
111 | api.getConfig().getString("messages.no-items"));
112 | return;
113 | }
114 |
115 | InventoryUtils.remove(inventory, requiredItemsArray);
116 |
117 | player.updateInventory();
118 | }
119 |
120 | int price = interfaceItem.getPrice();
121 |
122 | if (price > 0) {
123 | VaultProvider vaultProvider = api.getVaultProvider();
124 |
125 | if (!vaultProvider.isEconomyRegistered()) {
126 | Formatter.sendMessage(player,
127 | api.getConfig().getString("messages.no-economy"));
128 | return;
129 | } else if (!vaultProvider.getEconomy().has(player, price)) {
130 | Formatter.sendMessage(player,
131 | api.getConfig().getString("messages.no-balance")
132 | .replace("%price%", String.valueOf(price)));
133 | return;
134 | }
135 | }
136 |
137 | interfacePlayer.setLastInteract();
138 | interfaceItem.runActions(api, player);
139 | interfaceItem.onInteract(player);
140 |
141 | Action action = event.getAction();
142 |
143 | if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
144 | interfaceItem.onLeftInteract(player);
145 | } else if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
146 | interfaceItem.onRightInteract(player);
147 | }
148 | }
149 | }
150 | }
151 | }
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/listeners/PlayerJoinListener.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.listeners;
2 |
3 | import org.bukkit.entity.Player;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.EventPriority;
6 | import org.bukkit.event.Listener;
7 | import org.bukkit.event.player.PlayerJoinEvent;
8 |
9 | import dev._2lstudios.interfacemaker.interfaces.InterfaceHotbar;
10 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
11 |
12 | public class PlayerJoinListener implements Listener {
13 | private InterfaceMakerAPI api;
14 |
15 | public PlayerJoinListener(InterfaceMakerAPI api) {
16 | this.api = api;
17 | }
18 |
19 | @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
20 | public void onPlayerJoin(PlayerJoinEvent event) {
21 | Player player = event.getPlayer();
22 |
23 | api.getInterfacePlayerManager().create(player.getUniqueId());
24 |
25 | for (InterfaceHotbar hotbar : api.getConfiguredHotbarsValues()) {
26 | if (hotbar.giveOnSpawn()) {
27 | int giveDelay = hotbar.getGiveDelay();
28 |
29 | if (giveDelay > 0) {
30 | hotbar.buildLater(player, giveDelay);
31 | } else {
32 | hotbar.build(player);
33 | }
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/listeners/PlayerQuitListener.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.listeners;
2 |
3 | import org.bukkit.entity.Player;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.Listener;
6 | import org.bukkit.event.player.PlayerQuitEvent;
7 |
8 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
9 |
10 | public class PlayerQuitListener implements Listener {
11 | private InterfaceMakerAPI api;
12 |
13 | public PlayerQuitListener(InterfaceMakerAPI api) {
14 | this.api = api;
15 | }
16 |
17 | @EventHandler(ignoreCancelled = true)
18 | public void onPlayerQuit(PlayerQuitEvent event) {
19 | Player player = event.getPlayer();
20 |
21 | api.getInterfacePlayerManager().remove(player.getUniqueId());
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/placeholders/Formatter.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.placeholders;
2 |
3 | import java.util.List;
4 |
5 | import com.iridium.iridiumcolorapi.IridiumColorAPI;
6 |
7 | import org.bukkit.ChatColor;
8 | import org.bukkit.command.CommandSender;
9 | import org.bukkit.entity.Player;
10 |
11 | import me.clip.placeholderapi.PlaceholderAPI;
12 |
13 | public class Formatter {
14 | public static String color(String text) {
15 | if (text != null) {
16 | return ChatColor.translateAlternateColorCodes('&',
17 | IridiumColorAPI.process(text));
18 | }
19 |
20 | return null;
21 | }
22 |
23 | public static String format(Player player, String text) {
24 |
25 | if (text != null) {
26 | if (player.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
27 | text = PlaceholderAPI.setPlaceholders(player, text);
28 | }
29 | return color(text).replace("%player_name%", player.getName())
30 | .replace("%display_name%", player.getDisplayName());
31 | }
32 |
33 | return null;
34 | }
35 |
36 | public static void sendMessage(CommandSender sender, String text) {
37 | if (text != null) {
38 | if (sender instanceof Player) {
39 | sender.sendMessage(format((Player) sender, text));
40 | } else {
41 | sender.sendMessage(color(text));
42 | }
43 | }
44 | }
45 |
46 | public static List format(Player player, List lore) {
47 | for (int i = 0; i < lore.size(); i++) {
48 | String line = lore.get(i);
49 |
50 | lore.set(i, format(player, line));
51 | }
52 |
53 | return lore;
54 | }
55 | }
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/player/InterfacePlayer.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.player;
2 |
3 | import org.bukkit.configuration.Configuration;
4 |
5 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
6 |
7 | public class InterfacePlayer {
8 | private int clickCooldown = 0;
9 | private int interactCooldown = 0;
10 |
11 | private long lastClick = 0;
12 | private long lastInteract = 0;
13 |
14 | public InterfacePlayer(InterfaceMakerAPI api) {
15 | Configuration config = api.getConfig();
16 |
17 | clickCooldown = config.getInt("anti-click-spam-delay");
18 | interactCooldown = config.getInt("anti-interact-spam-delay");
19 | }
20 |
21 | public long getLastClick() {
22 | return lastClick;
23 | }
24 |
25 | public void setLastClick() {
26 | this.lastClick = System.currentTimeMillis();
27 | }
28 |
29 | public long getLastInteract() {
30 | return lastInteract;
31 | }
32 |
33 | public void setLastInteract() {
34 | this.lastInteract = System.currentTimeMillis();
35 | }
36 |
37 | public boolean isClickCooling() {
38 | return System.currentTimeMillis() - lastClick <= clickCooldown;
39 | }
40 |
41 | public boolean isInteractCooling() {
42 | return System.currentTimeMillis() - lastInteract <= interactCooldown;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/player/InterfacePlayerManager.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.player;
2 |
3 | import java.util.Collection;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 | import java.util.UUID;
7 |
8 | import org.bukkit.entity.Player;
9 |
10 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
11 |
12 | public class InterfacePlayerManager {
13 | private InterfaceMakerAPI api;
14 | private Map players = new HashMap<>();
15 |
16 | public InterfacePlayerManager(InterfaceMakerAPI api) {
17 | this.api = api;
18 | }
19 |
20 | public InterfacePlayerManager create(UUID uuid) {
21 | players.put(uuid, new InterfacePlayer(api));
22 | return this;
23 | }
24 |
25 | public InterfacePlayerManager create(Player player) {
26 | return create(player.getUniqueId());
27 | }
28 |
29 | public InterfacePlayerManager remove(UUID uuid) {
30 | players.remove(uuid);
31 | return this;
32 | }
33 |
34 | public InterfacePlayer get(UUID uuid) {
35 | return players.getOrDefault(uuid, null);
36 | }
37 |
38 | public InterfacePlayer get(Player player) {
39 | return get(player.getUniqueId());
40 | }
41 |
42 | public Collection getPlayers() {
43 | return players.values();
44 | }
45 | }
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/tasks/RefreshTask.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.tasks;
2 |
3 | import java.util.Iterator;
4 | import java.util.Map.Entry;
5 |
6 | import org.bukkit.entity.Player;
7 | import org.bukkit.inventory.Inventory;
8 |
9 | import dev._2lstudios.interfacemaker.interfaces.Buildable;
10 | import dev._2lstudios.interfacemaker.interfaces.InterfaceMakerAPI;
11 | import dev._2lstudios.interfacemaker.interfaces.QueuedBuildable;
12 | import dev._2lstudios.interfacemaker.interfaces.contexts.HotbarBuildContext;
13 | import dev._2lstudios.interfacemaker.interfaces.contexts.MenuBuildContext;
14 |
15 | public class RefreshTask implements Runnable {
16 | private InterfaceMakerAPI api;
17 | private int ticks = 0;
18 |
19 | public RefreshTask(InterfaceMakerAPI api) {
20 | this.api = api;
21 | }
22 |
23 | @Override
24 | public void run() {
25 | ticks++;
26 |
27 | Iterator buildablesQueueIterator = api.getQueuedBuildables().iterator();
28 |
29 | while(buildablesQueueIterator.hasNext()) {
30 | QueuedBuildable queuedBuildable = buildablesQueueIterator.next();
31 |
32 | if (queuedBuildable.tick() <= 0) {
33 | buildablesQueueIterator.remove();
34 | queuedBuildable.build();
35 | }
36 | }
37 |
38 | for (Entry entry : api.getOpenedMenuContexts().entrySet()) {
39 | MenuBuildContext context = entry.getValue();
40 | Player player = context.getPlayer();
41 | int autoRefresh = context.getMenu().getAutoRefresh();
42 |
43 | if (autoRefresh > 0 && ticks % autoRefresh == 0) {
44 | context.populateItems(player, context.getInventory());
45 | }
46 | }
47 |
48 | for (Entry entry : api.getOpenedHotbarContexts().entrySet()) {
49 | Player player = entry.getKey();
50 | HotbarBuildContext context = entry.getValue();
51 | int autoRefresh = context.getHotbar().getAutoRefresh();
52 |
53 | if (autoRefresh > 0 && ticks % autoRefresh == 0) {
54 | context.populateItems(player, context.getInventory());
55 | }
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/utils/InventoryUtils.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.utils;
2 |
3 | import org.bukkit.inventory.Inventory;
4 | import org.bukkit.inventory.ItemStack;
5 |
6 | public class InventoryUtils {
7 | public static boolean contains(Inventory inventory, ItemStack item) {
8 | int amount = item.getAmount();
9 |
10 | for (ItemStack inventoryItem : inventory.getContents()) {
11 | if (inventoryItem != null && item.isSimilar(inventoryItem)) {
12 | amount -= inventoryItem.getAmount();
13 |
14 | if (amount <= 0) {
15 | return true;
16 | }
17 | }
18 | }
19 |
20 | return false;
21 | }
22 |
23 | public static boolean contains(Inventory inventory, ItemStack... items) {
24 | for (ItemStack item : items) {
25 | if (!contains(inventory, item)) {
26 | return false;
27 | }
28 | }
29 |
30 | return true;
31 | }
32 |
33 | public static void remove(Inventory inventory, ItemStack item) {
34 | int amount = item.getAmount();
35 |
36 | for (ItemStack inventoryItem : inventory.getContents()) {
37 | if (inventoryItem != null && item.isSimilar(inventoryItem)) {
38 | int inventoryItemAmount = inventoryItem.getAmount();
39 |
40 | inventoryItem.setAmount(inventoryItemAmount - amount);
41 |
42 | amount -= inventoryItemAmount;
43 |
44 | if (amount <= 0) {
45 | return;
46 | }
47 | }
48 | }
49 | }
50 |
51 | public static void remove(Inventory inventory, ItemStack... items) {
52 | for (ItemStack item : items) {
53 | remove(inventory, item);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/utils/ProxyUtils.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.utils;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.DataOutputStream;
5 |
6 | import org.bukkit.entity.Player;
7 | import org.bukkit.plugin.Plugin;
8 |
9 | public class ProxyUtils {
10 | public static void sendToServer(Plugin plugin, Player player, String server) {
11 | try {
12 | ByteArrayOutputStream b = new ByteArrayOutputStream();
13 | DataOutputStream out = new DataOutputStream(b);
14 | out.writeUTF("Connect");
15 | out.writeUTF(server);
16 | player.sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
17 | b.close();
18 | out.close();
19 | } catch (Exception e) {}
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/dev/_2lstudios/interfacemaker/vault/VaultProvider.java:
--------------------------------------------------------------------------------
1 | package dev._2lstudios.interfacemaker.vault;
2 |
3 | import org.bukkit.Server;
4 | import org.bukkit.plugin.RegisteredServiceProvider;
5 |
6 | import net.milkbowl.vault.economy.Economy;
7 |
8 | public class VaultProvider {
9 | private Economy economy = null;
10 |
11 | public VaultProvider(Server server) {
12 | if (server.getPluginManager().getPlugin("Vault") != null) {
13 | RegisteredServiceProvider rsp = server.getServicesManager().getRegistration(Economy.class);
14 |
15 | if (rsp != null) {
16 | economy = rsp.getProvider();
17 | }
18 | }
19 | }
20 |
21 | public boolean isEconomyRegistered() {
22 | return economy != null;
23 | }
24 |
25 | public Economy getEconomy() {
26 | return economy;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/resources/config.yml:
--------------------------------------------------------------------------------
1 | anti-click-spam-delay: 500
2 | anti-interact-spam-delay: 500
3 |
4 | messages:
5 | no-permission-menu-others: "&cNo permission to open menus for others &7(&c%permission%&7)"
6 | no-permission-hotbar-others: "&cNo permission to open hotbars for others &7(&c%permission%&7)"
7 | no-permission-menu: "&cNo permission to use menu %menu% &7(&c%permission%&7)"
8 | no-permission-hotbar: "&cNo permission to use hotbar %hotbar% &7(&c%permission%&7)"
9 | no-permission: "&cYou don't have permissions to run this command &7(&c%permission%&7)"
10 | no-items: "&cYou don't have the items required to use this!"
11 | no-levels: "&cNot enough levels. You need %levels% levels to use this!"
12 | no-balance: "&cNot enough money. You need $%price% to use this!"
13 | no-economy: "&cThis item cannot be used because vault is not installed!"
14 | list-usage: "&c/%label% list "
15 | list-invalid-argument: "&cInvalid argument: %argument%\nAvailable: hotbars, menus"
16 | hotbar-list-header: "&aAvailable hotbars:"
17 | hotbar-list-entry: "&b%entry%"
18 | menu-list-header: "&aAvailable menus:"
19 | menu-list-entry: "&b%entry%"
20 | no-hotbars: "&cThere are no hotbars configured!"
21 | no-menus: "&cThere are no menus configured!"
22 | menu-usage: "&c/%label% menu