Skip to content

Commit

Permalink
1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
efekos committed May 28, 2023
1 parent a4ac12a commit a37473e
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 26 deletions.
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,5 @@
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>


</dependencies>
</project>
3 changes: 0 additions & 3 deletions src/main/java/me/efekos/simpler/Simpler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/me/efekos/simpler/blocks/CustomBlock.java
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion src/main/java/me/efekos/simpler/commands/BaseCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!");

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/me/efekos/simpler/exception/NoPluginException.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

This file was deleted.

41 changes: 31 additions & 10 deletions src/main/java/me/efekos/simpler/items/ItemManager.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<CustomItemRegister> registers = new ArrayList<>();
private static boolean isSetup;

public static void registerItem(String name,Class<? extends CustomItem> 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<? extends CustomItem> 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<CustomItemRegister> 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();
Expand All @@ -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();

Expand All @@ -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();

Expand Down
33 changes: 26 additions & 7 deletions src/main/java/me/efekos/simpler/menu/MenuManager.java
Original file line number Diff line number Diff line change
@@ -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<Player,MenuData> menuDataStore = new HashMap<>();
private static boolean isSetup = false;
private static JavaPlugin plugin;

public static void Open(Player p ,Class<? extends Menu> 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<? extends Menu> 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<? extends Menu> constructor = menuClazz.getConstructor(MenuData.class);
constructor.setAccessible(true);

Expand All @@ -26,5 +43,7 @@ public static void Open(Player p ,Class<? extends Menu> menuClazz){
} catch (Exception e){
e.printStackTrace();
}


}
}

0 comments on commit a37473e

Please sign in to comment.