Skip to content

Commit

Permalink
Custom skull texture, reload config, optional parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
s1stemdev committed Feb 18, 2024
1 parent 857bf57 commit b80960a
Show file tree
Hide file tree
Showing 14 changed files with 556 additions and 16 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
- [ ] Ingame menu creating
- [ ] Connect different servers via BungeeCord/Velocity
- [x] Different click actions
- [x] Reload command
- [x] Optional parameters
- [ ] Custom heads

![bStats](https://bstats.org/signatures/bukkit/AestheticMenu.svg)
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ru.rivendell</groupId>
<artifactId>AestheticMenu</artifactId>
<version>0.3-BETA</version>
<version>0.3.1-BETA</version>
<packaging>jar</packaging>

<name>AestheticMenu</name>
Expand Down Expand Up @@ -85,6 +85,10 @@
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>minecraft-repo</id>
<url>https://libraries.minecraft.net/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -132,5 +136,11 @@
<version>2.11.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>1.5.21</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
28 changes: 27 additions & 1 deletion src/main/java/ru/rivendell/aestheticmenu/AestheticMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.java.JavaPlugin;
import ru.rivendell.aestheticmenu.commands.CommandRegistrar;
import ru.rivendell.aestheticmenu.commands.impl.ForceOpenCommand;
import ru.rivendell.aestheticmenu.commands.impl.ReloadCommand;
import ru.rivendell.aestheticmenu.config.ConfigLoader;
import ru.rivendell.aestheticmenu.config.configurations.ConfigRegistrar;
import ru.rivendell.aestheticmenu.config.configurations.gui.GuiConfig;
Expand All @@ -26,6 +28,7 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.logging.Logger;

@Singleton
Expand Down Expand Up @@ -63,7 +66,8 @@ public void onEnable() {

loadMenus();

commandRegistrar.registerCommand("aestheticmenu-forceopen", new ForceOpenCommand(menuRegistrar, "aestheticmenu.admin", configRegistrar.getMessagesConfig(), playerInventoriesBuffer));
commandRegistrar.registerCommand("aestheticmenu-forceopen", new ForceOpenCommand(menuRegistrar, "aestheticmenu.admin.forceopen", configRegistrar.getMessagesConfig(), playerInventoriesBuffer));
commandRegistrar.registerCommand("aestheticmenu-reload", new ReloadCommand("aestheticmenu.admin.reload", configRegistrar.getMessagesConfig(), this));

pluginMetrics.setupMetrics();
registerEvents();
Expand All @@ -88,6 +92,28 @@ public void onDisable() {
}
}

public void reload() {

for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
Inventory inventory = onlinePlayer.getOpenInventory().getTopInventory();
if(inventory != null) {
if(inventory instanceof MenuHolder) {
MenuHolder holder = (MenuHolder) inventory.getHolder();

if(holder.isBuffer()) {
onlinePlayer.getInventory().setContents(playerInventoriesBuffer.getBuffer().get(onlinePlayer.getUniqueId()));
playerInventoriesBuffer.getBuffer().remove(onlinePlayer.getUniqueId());
}
}
}
}

configRegistrar.loadConfig();
menuRegistrar.clear();

loadMenus();
}

private void loadDepends() {
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
log.info("PlaceholderAPI hooked successful!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
package ru.rivendell.aestheticmenu.commands.impl;

public class ReloadCommand {
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import ru.rivendell.aestheticmenu.AestheticMenu;
import ru.rivendell.aestheticmenu.commands.Command;
import ru.rivendell.aestheticmenu.config.configurations.messages.MessagesConfig;
import ru.rivendell.aestheticmenu.gui.PlayerInventoriesBuffer;
import ru.rivendell.aestheticmenu.gui.menu.MenuInventory;

public class ReloadCommand extends Command {

private AestheticMenu plugin;

public ReloadCommand(String permission, MessagesConfig messagesConfig, AestheticMenu plugin) {
super(permission, messagesConfig);
this.plugin = plugin;
}
@Override
public boolean onExecute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] args) {
plugin.reload();
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.rivendell.aestheticmenu.config.configurations.gui;

import lombok.Getter;
import lombok.Setter;

@Setter
public class EnchantmentConfig {

@Getter private String enchant;
private int level;

public int getLevel() {
if(level == 0) return 1;

return level;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,46 @@

import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import ru.rivendell.aestheticmenu.config.Configurable;

import java.util.HashMap;

@Getter @Setter
@Setter
public class GuiConfig extends Configurable {

private String menuId;
@Getter private String menuId;
private String command;
private String title;
private byte size;
private boolean usePlayerInventory;
@Getter private byte size;
@Getter private boolean usePlayerInventory;
private HashMap<String, ItemConfig> items;
private HashMap<String, ItemConfig> playerInvItems;

@Override
protected String getName() {
return null;
}

public String getCommand() {
if(command == null) return menuId + "_open";
return command;
}

public String getTitle() {
if(title == null) return menuId + " has no title";
return title;
}

public HashMap<String, ItemConfig> getItems() {
if(items == null) return new HashMap<>();

return items;
}

public HashMap<String, ItemConfig> getPlayerInvItems() {
if(playerInvItems == null) return new HashMap<>();

return playerInvItems;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,77 @@
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import ru.rivendell.aestheticmenu.config.Configurable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Getter @Setter
@Setter
public class ItemConfig {

private Material material;
@Getter private String headValue;
private byte amount;
private int custommodeldata;
@Getter private int custommodeldata;
private String name;
private List<String> lore;
private List<ItemFlag> flags;
private List<EnchantmentConfig> enchantments;
private ItemContainerConfig data;

public Material getMaterial() {
if(material == null) return Material.STONE;

return material;
}

public byte getAmount() {
if(amount == 0) return 1;

return amount;
}

public String getName() {

if(name == null) return processItemName();

return name;
}

public List<String> getLore() {
if(lore == null) return new ArrayList<>();

return lore;
}

public List<ItemFlag> getFlags() {
if(flags == null) return new ArrayList<>();

return flags;
}

public List<EnchantmentConfig> getEnchantments() {
if(enchantments == null) return new ArrayList<>();

return enchantments;
}

public ItemContainerConfig getData() {
if(data == null) return new ItemContainerConfig();

return data;
}

private String processItemName() {
String name = material.toString();

name = name.replaceAll("_", " ");
name = name.toLowerCase();
name = name.substring(0, 1).toUpperCase() + name.substring(1);

return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Getter @Setter
@Setter
public class ItemContainerConfig {

private List<ActionConfig> actions;
private RequirementsConfig requirement;
private String permission;
@Getter private String permission;

public List<ActionConfig> getActions() {
if(actions == null) return new ArrayList<>();

return actions;
}

public RequirementsConfig getRequirement() {
if(actions == null) return new RequirementsConfig();

return requirement;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class RequirementsConfig {
private List<RequirementValueConfig> requirements;
private boolean invert;

public RequirementsConfig() {
type = RequirementType.NONE;
requirements = new ArrayList<>();
invert = false;
}

public boolean result(Player player) {

if(requirements.isEmpty()) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public enum RequirementType {

ANY,
ALL;
ALL,
NONE;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.persistence.PersistentDataType;
import org.checkerframework.checker.units.qual.A;
import ru.rivendell.aestheticmenu.AestheticMenu;
import ru.rivendell.aestheticmenu.config.configurations.gui.ActionConfig;
import ru.rivendell.aestheticmenu.config.configurations.gui.ItemContainerConfig;
Expand Down Expand Up @@ -48,11 +49,13 @@ public void onClick(InventoryClickEvent event) {

Player player = (Player) event.getWhoClicked();

ItemContainerConfig config = deserializer.fromJson(event.getCurrentItem().getItemMeta().getPersistentDataContainer().get(AestheticMenu.COMMANDS_KEY, PersistentDataType.STRING), ItemContainerConfig.class);
if(config.getPermission() == null || player.hasPermission(config.getPermission())) {
if(event.getCurrentItem().getItemMeta().getPersistentDataContainer().has(AestheticMenu.COMMANDS_KEY, PersistentDataType.STRING)) {
ItemContainerConfig config = deserializer.fromJson(event.getCurrentItem().getItemMeta().getPersistentDataContainer().get(AestheticMenu.COMMANDS_KEY, PersistentDataType.STRING), ItemContainerConfig.class);
if (config.getPermission() == null || player.hasPermission(config.getPermission())) {

if(config.getRequirement() == null || config.getRequirement().result(player)) execute(player, config);
if (config.getRequirement() == null || config.getRequirement().result(player)) execute(player, config);

}
}

event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class MenuRegistrar {

public MenuRegistrar() { menus = new ArrayList<>(); }

public void clear() {
menus.clear();
}

public void registerMenu(GuiConfig config) {
MenuInventory menu = new MenuInventory(config, playerInventoriesBuffer);
menus.add(menu);
Expand Down
Loading

0 comments on commit b80960a

Please sign in to comment.