diff --git a/pom.xml b/pom.xml index c11d121..47401a7 100644 --- a/pom.xml +++ b/pom.xml @@ -94,7 +94,5 @@ reflections 0.10.2 - - diff --git a/src/main/java/me/efekos/simpler/Simpler.java b/src/main/java/me/efekos/simpler/Simpler.java index f8ef6fa..f411fde 100644 --- a/src/main/java/me/efekos/simpler/Simpler.java +++ b/src/main/java/me/efekos/simpler/Simpler.java @@ -25,9 +25,6 @@ public static Simpler getPlugin() { @Override public void onEnable() { plugin = this; - - getServer().getPluginManager().registerEvents(new MenuEvents(),this); - getServer().getPluginManager().registerEvents(new PlayerEvents(),this); } @Override diff --git a/src/main/java/me/efekos/simpler/blocks/CustomBlock.java b/src/main/java/me/efekos/simpler/blocks/CustomBlock.java new file mode 100644 index 0000000..1e95ff1 --- /dev/null +++ b/src/main/java/me/efekos/simpler/blocks/CustomBlock.java @@ -0,0 +1,13 @@ +package me.efekos.simpler.blocks; + +import me.efekos.simpler.items.CustomItem; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; + +public abstract class CustomBlock extends CustomItem { + public abstract void onPlace(BlockPlaceEvent event); + public abstract void onBreak(BlockBreakEvent event); +} diff --git a/src/main/java/me/efekos/simpler/commands/BaseCommand.java b/src/main/java/me/efekos/simpler/commands/BaseCommand.java index 863b258..619cec1 100644 --- a/src/main/java/me/efekos/simpler/commands/BaseCommand.java +++ b/src/main/java/me/efekos/simpler/commands/BaseCommand.java @@ -129,7 +129,7 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab me.efekos.simpler.annotations.Command command = this.getClass().getAnnotation(me.efekos.simpler.annotations.Command.class); Player p = (Player) sender; - if(command.permission()!=null&&!p.hasPermission(command.permission())){ // @Command has a permission and player don't have the permission + if(!command.permission().equals("")&&!p.hasPermission(command.permission())){ // @Command has a permission and player don't have the permission p.sendMessage(ChatColor.RED+"You do not have permission to do that!"); diff --git a/src/main/java/me/efekos/simpler/exception/NoPluginException.java b/src/main/java/me/efekos/simpler/exception/NoPluginException.java new file mode 100644 index 0000000..bf9a834 --- /dev/null +++ b/src/main/java/me/efekos/simpler/exception/NoPluginException.java @@ -0,0 +1,22 @@ +package me.efekos.simpler.exception; + +public class NoPluginException extends Exception{ + public NoPluginException() { + } + + public NoPluginException(String message) { + super(message); + } + + public NoPluginException(String message, Throwable cause) { + super(message, cause); + } + + public NoPluginException(Throwable cause) { + super(cause); + } + + public NoPluginException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/me/efekos/simpler/exception/NotExtendedException.java b/src/main/java/me/efekos/simpler/exception/NotExtendedException.java deleted file mode 100644 index 7390d92..0000000 --- a/src/main/java/me/efekos/simpler/exception/NotExtendedException.java +++ /dev/null @@ -1,3 +0,0 @@ -package me.efekos.simpler.exception; - -public class NotExtendedException extends Exception{} diff --git a/src/main/java/me/efekos/simpler/items/ItemManager.java b/src/main/java/me/efekos/simpler/items/ItemManager.java index 35c8537..c108497 100644 --- a/src/main/java/me/efekos/simpler/items/ItemManager.java +++ b/src/main/java/me/efekos/simpler/items/ItemManager.java @@ -1,6 +1,8 @@ package me.efekos.simpler.items; import me.efekos.simpler.Simpler; +import me.efekos.simpler.events.PlayerEvents; +import me.efekos.simpler.exception.NoPluginException; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; @@ -10,34 +12,53 @@ import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; public class ItemManager { public static NamespacedKey itemTypeKey = new NamespacedKey(Simpler.getPlugin(),"item_id"); + private static JavaPlugin plugin; private static ArrayList registers = new ArrayList<>(); + private static boolean isSetup; - public static void registerItem(String name,Class itemClass){ - registers.add(new CustomItemRegister() - .setId(name) - .setClazz(itemClass) - ); + public static void setPlugin(JavaPlugin plugin) { + ItemManager.plugin = plugin; + } + + public static void registerItem(String name, Class itemClass){ + try{ + if(plugin==null) throw new NoPluginException("Call method me.efekos.simpler.items.ItemManager#setPlugin first."); + + if(!isSetup){ + plugin.getServer().getPluginManager().registerEvents(new PlayerEvents(),plugin); + isSetup = true; + } + + registers.add(new CustomItemRegister() + .setId(name) + .setClazz(itemClass) + ); + } catch (Exception e){ + e.printStackTrace(); + } } public static ArrayList getRegisters() { return registers; } - public static void giveItem(Player player, Material type){ + public static void giveItem(@NotNull Player player, Material type){ player.getInventory().addItem(new ItemStack(type,1)); } - public static void giveItem(Player player,ItemStack item){ + public static void giveItem(@NotNull Player player, ItemStack item){ player.getInventory().addItem(item); } - public static void giveItem(Player player,CustomItem item){ + public static void giveItem(@NotNull Player player, @NotNull CustomItem item){ ItemStack stack = new ItemStack(item.getMaterial()); ItemMeta meta = item.getDefaultMeta(); PersistentDataContainer container = meta.getPersistentDataContainer(); @@ -46,7 +67,7 @@ public static void giveItem(Player player,CustomItem item){ player.getInventory().addItem(stack); } - public static void giveSkull(Player player, OfflinePlayer skullOwner){ + public static void giveSkull(@NotNull Player player, OfflinePlayer skullOwner){ ItemStack stack = new ItemStack(Material.PLAYER_HEAD); SkullMeta meta = (SkullMeta) stack.getItemMeta(); @@ -57,7 +78,7 @@ public static void giveSkull(Player player, OfflinePlayer skullOwner){ player.getInventory().addItem(stack); } - public static void giveSkull(Player player,Player skullOwner){ + public static void giveSkull(@NotNull Player player, Player skullOwner){ ItemStack stack = new ItemStack(Material.PLAYER_HEAD); SkullMeta meta = (SkullMeta) stack.getItemMeta(); diff --git a/src/main/java/me/efekos/simpler/menu/MenuManager.java b/src/main/java/me/efekos/simpler/menu/MenuManager.java index 040dfaa..816add4 100644 --- a/src/main/java/me/efekos/simpler/menu/MenuManager.java +++ b/src/main/java/me/efekos/simpler/menu/MenuManager.java @@ -1,22 +1,39 @@ package me.efekos.simpler.menu; +import me.efekos.simpler.events.MenuEvents; +import me.efekos.simpler.exception.NoPluginException; import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Constructor; import java.util.HashMap; +import java.util.Map; public class MenuManager { private static HashMap menuDataStore = new HashMap<>(); + private static boolean isSetup = false; + private static JavaPlugin plugin; - public static void Open(Player p ,Class menuClazz){ - MenuData data = menuDataStore.get(p); - if(data==null){ - menuDataStore.put(p,new MenuData(p)); - data = menuDataStore.get(p); - } + public static void setPlugin(JavaPlugin plugin) { + MenuManager.plugin = plugin; + } + + public static void Open(Player p , Class menuClazz){ + try { + if(plugin==null) throw new NoPluginException("Call method me.efekos.simpler.menu.MenuManager#setPlugin first."); + + if(!isSetup){ + plugin.getServer().getPluginManager().registerEvents(new MenuEvents(),plugin); + isSetup = true; + } + + MenuData data = menuDataStore.get(p); + if(data==null){ + menuDataStore.put(p,new MenuData(p)); + data = menuDataStore.get(p); + } - try{ Constructor constructor = menuClazz.getConstructor(MenuData.class); constructor.setAccessible(true); @@ -26,5 +43,7 @@ public static void Open(Player p ,Class menuClazz){ } catch (Exception e){ e.printStackTrace(); } + + } }