mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-02-23 22:21:19 +01:00
3.0.0-SNAPSHOT-U19
Started working on the Panel handling mechanics, as well as added ItemStackHolderConverter and ItemStackUtils.
This commit is contained in:
parent
1acd70265b
commit
39c2cf12ec
@ -12,7 +12,70 @@
|
||||
# Buttons: # buttons section #
|
||||
# BackButton: 9 # back button slot #
|
||||
# ExitButton: 9 # exit button slot #
|
||||
|
||||
MainPanel:
|
||||
name: '&cPlease choose one...'
|
||||
slots: 9
|
||||
Items:
|
||||
'1':
|
||||
type: '383:54'
|
||||
name: '&6&lCustom Bosses'
|
||||
lore:
|
||||
- '&eLeft Click »'
|
||||
- '&fEdit any of the already created'
|
||||
- '&fcustom bosses.'
|
||||
- '&7'
|
||||
- '&eRight Click »'
|
||||
- '&fCreate a new custom boss from'
|
||||
- '&fscratch.'
|
||||
Button: Bosses
|
||||
'3':
|
||||
type: 12
|
||||
name: '&6&lAuto Spawns'
|
||||
lore:
|
||||
- '&eLeft Click »'
|
||||
- '&fEdit any of the already created'
|
||||
- '&fauto spawns.'
|
||||
- '&7'
|
||||
- '&eRight Click »'
|
||||
- '&fCreate a new auto spawn from'
|
||||
- '&fscratch.'
|
||||
Button: AutoSpawns
|
||||
'5':
|
||||
type: 101
|
||||
name: '&6&lDrop Tables'
|
||||
lore:
|
||||
- '&eLeft Click »'
|
||||
- '&fEdit any of the already created'
|
||||
- '&fdrop tables.'
|
||||
- '&7'
|
||||
- '&eRight Click »'
|
||||
- '&fCreate a new drop table from'
|
||||
- '&fscratch.'
|
||||
Button: DropTables
|
||||
'7':
|
||||
type: 50
|
||||
name: '&6&lCustom Items'
|
||||
lore:
|
||||
- '&eLeft Click »'
|
||||
- '&fEdit any of the already created'
|
||||
- '&fcustom items.'
|
||||
- '&7'
|
||||
- '&eRight Click »'
|
||||
- '&fCreate a new custom item from'
|
||||
- '&fan item in your inventory.'
|
||||
Button: CustomItems
|
||||
'9':
|
||||
type: 101
|
||||
name: '&6&lCustom Skills'
|
||||
lore:
|
||||
- '&eLeft Click »'
|
||||
- '&fEdit any of the already created'
|
||||
- '&fcustom skills.'
|
||||
- '&7'
|
||||
- '&eRight Click »'
|
||||
- '&fCreate a new custom skill from'
|
||||
- '&fscratch.'
|
||||
Button: CustomSkills
|
||||
MainPanel:
|
||||
name: '&b&l{boss} Editor'
|
||||
slots: 45
|
||||
|
@ -2,6 +2,7 @@ package net.aminecraftdev.custombosses;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.aminecraftdev.custombosses.api.BossAPI;
|
||||
import net.aminecraftdev.custombosses.container.BossEntityContainer;
|
||||
import net.aminecraftdev.custombosses.file.BossesFileHandler;
|
||||
import net.aminecraftdev.custombosses.managers.files.BossItemFileManager;
|
||||
import net.aminecraftdev.custombosses.managers.BossMechanicManager;
|
||||
@ -16,14 +17,16 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
*/
|
||||
public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
|
||||
@Getter private BossEntityContainer bossEntityContainer;
|
||||
@Getter private BossMechanicManager bossMechanicManager;
|
||||
@Getter private BossItemFileManager itemStackManager;
|
||||
@Getter private BossesFileManager bossesFileManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
BossAPI.setPlugin(this);
|
||||
new BossAPI(this);
|
||||
|
||||
this.bossEntityContainer = new BossEntityContainer();
|
||||
this.itemStackManager = new BossItemFileManager(this);
|
||||
this.bossesFileManager = new BossesFileManager(this);
|
||||
this.bossMechanicManager = new BossMechanicManager(this);
|
||||
|
@ -20,6 +20,26 @@ public class BossAPI {
|
||||
|
||||
private static CustomBosses PLUGIN;
|
||||
|
||||
/**
|
||||
* Used to update the variable to the
|
||||
* plugin instance so the methods can
|
||||
* pull variables in the main class to use
|
||||
* in their method.
|
||||
*
|
||||
* This should only ever be used in house and
|
||||
* never to be used by an outside party.
|
||||
*
|
||||
* @param plugin - the plugin instance.
|
||||
*/
|
||||
public BossAPI(CustomBosses plugin) {
|
||||
if(PLUGIN != null) {
|
||||
Debug.ATTEMPTED_TO_UPDATE_PLUGIN.debug();
|
||||
return;
|
||||
}
|
||||
|
||||
PLUGIN = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to create a base BossEntity model which
|
||||
* can be used to fine tune and then once the main
|
||||
@ -52,34 +72,13 @@ public class BossAPI {
|
||||
mainStatsElement.setDisplayName(name);
|
||||
mainStatsElement.setHealth(50D);
|
||||
|
||||
boolean result = PLUGIN.getBossesFileManager().saveNewBossEntity(name, bossEntity);
|
||||
boolean result = PLUGIN.getBossEntityContainer().saveData(name, bossEntity);
|
||||
|
||||
if (!result) {
|
||||
Debug.BOSS_NAME_EXISTS.debug(name);
|
||||
return null;
|
||||
}
|
||||
|
||||
return bossEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to update the variable to the
|
||||
* plugin instance so the methods can
|
||||
* pull variables in the main class to use
|
||||
* in their method.
|
||||
*
|
||||
* This should only ever be used in house and
|
||||
* never to be used by an outside party.
|
||||
*
|
||||
* @param customBosses - the plugin instance.
|
||||
*/
|
||||
public static void setPlugin(CustomBosses customBosses) {
|
||||
if(PLUGIN != null) {
|
||||
Debug.ATTEMPTED_TO_UPDATE_PLUGIN.debug();
|
||||
return;
|
||||
}
|
||||
|
||||
PLUGIN = customBosses;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package net.aminecraftdev.custombosses.commands;
|
||||
|
||||
import net.aminecraftdev.custombosses.utils.command.SubCommandService;
|
||||
import net.aminecraftdev.custombosses.utils.command.attributes.Alias;
|
||||
import net.aminecraftdev.custombosses.utils.command.attributes.Description;
|
||||
import net.aminecraftdev.custombosses.utils.command.attributes.Name;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 18-Jul-18
|
||||
*/
|
||||
@Name("boss")
|
||||
@Alias({"bosses", "b", "bs"})
|
||||
@Description("Used to handle all CustomBosses related commands.")
|
||||
|
||||
public class BossCmd extends SubCommandService<CommandSender> {
|
||||
|
||||
public BossCmd() {
|
||||
super(BossCmd.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package net.aminecraftdev.custombosses.container;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.aminecraftdev.custombosses.entity.BossEntity;
|
||||
import net.aminecraftdev.custombosses.utils.Debug;
|
||||
import net.aminecraftdev.custombosses.utils.IContainer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 18-Jul-18
|
||||
*/
|
||||
public class BossEntityContainer implements IContainer<Map<String, BossEntity>> {
|
||||
|
||||
private Map<String, BossEntity> container = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Map<String, BossEntity> getData() {
|
||||
return new HashMap<>(this.container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveData(Map<String, BossEntity> stringBossEntityMap) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int completed = 0;
|
||||
int failed = 0;
|
||||
|
||||
for(Map.Entry<String, BossEntity> entry : stringBossEntityMap.entrySet()) {
|
||||
if(getData().containsKey(entry.getKey())) {
|
||||
failed += 1;
|
||||
stringBuilder.append(entry.getKey()).append("; ");
|
||||
}
|
||||
|
||||
this.container.put(entry.getKey(), entry.getValue());
|
||||
completed++;
|
||||
}
|
||||
|
||||
|
||||
if(failed > 0) {
|
||||
Debug.BOSS_CONTAINER_SAVE.debug(completed, failed, stringBuilder.toString());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean saveData(String string, BossEntity bossEntity) {
|
||||
return saveData(Collections.singletonMap(string, bossEntity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContainer() {
|
||||
this.container.clear();
|
||||
}
|
||||
}
|
@ -1,16 +1,14 @@
|
||||
package net.aminecraftdev.custombosses.managers.files;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.aminecraftdev.custombosses.CustomBosses;
|
||||
import net.aminecraftdev.custombosses.container.BossEntityContainer;
|
||||
import net.aminecraftdev.custombosses.entity.BossEntity;
|
||||
import net.aminecraftdev.custombosses.file.BossesFileHandler;
|
||||
import net.aminecraftdev.custombosses.utils.ILoadable;
|
||||
import net.aminecraftdev.custombosses.utils.IReloadable;
|
||||
import net.aminecraftdev.custombosses.utils.ISavable;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
@ -19,18 +17,20 @@ import java.util.Map;
|
||||
*/
|
||||
public class BossesFileManager implements ILoadable, ISavable, IReloadable {
|
||||
|
||||
private Map<String, BossEntity> bossEntityMap = new HashMap<>();
|
||||
private BossEntityContainer bossEntityContainer;
|
||||
private BossesFileHandler bossesFileHandler;
|
||||
|
||||
public BossesFileManager(JavaPlugin javaPlugin) {
|
||||
File file = new File(javaPlugin.getDataFolder(), "bosses.json");
|
||||
public BossesFileManager(CustomBosses customBosses) {
|
||||
File file = new File(customBosses.getDataFolder(), "bosses.json");
|
||||
|
||||
this.bossesFileHandler = new BossesFileHandler(javaPlugin, true, file);
|
||||
this.bossesFileHandler = new BossesFileHandler(customBosses, true, file);
|
||||
this.bossEntityContainer = customBosses.getBossEntityContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
this.bossEntityMap = this.bossesFileHandler.loadFile();
|
||||
this.bossEntityContainer.clearContainer();
|
||||
this.bossEntityContainer.saveData(this.bossesFileHandler.loadFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -40,19 +40,10 @@ public class BossesFileManager implements ILoadable, ISavable, IReloadable {
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
this.bossesFileHandler.saveFile(this.bossEntityMap);
|
||||
}
|
||||
|
||||
public boolean saveNewBossEntity(String name, BossEntity bossEntity) {
|
||||
if(this.bossEntityMap.containsKey(name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bossEntityMap.put(name, bossEntity);
|
||||
return true;
|
||||
this.bossesFileHandler.saveFile(this.bossEntityContainer.getData());
|
||||
}
|
||||
|
||||
public BossEntity getBossEntity(String name) {
|
||||
return this.bossEntityMap.getOrDefault(name, null);
|
||||
return this.bossEntityContainer.getData().getOrDefault(name, null);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package net.aminecraftdev.custombosses.panel;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 18-Jul-18
|
||||
*/
|
||||
public class MainBossPanel {
|
||||
}
|
@ -12,6 +12,7 @@ public enum Debug {
|
||||
MAX_HEALTH("You cannot set the max health higher than {0}. You can adjust your max health in the spigot.yml file and restart your server to increase this."),
|
||||
MECHANIC_APPLICATION_FAILED("Some mechanics have failed to be applied. It got stuck at {0} mechanic."),
|
||||
BOSS_NAME_EXISTS("A boss was attempted to be created with the name {0} but there is already a boss with that name."),
|
||||
BOSS_CONTAINER_SAVE("The BossEntity map was saved in, {0} succeeded, and {1} failed. Listed below are the saved data which already existed in the container: \n{2}"),
|
||||
|
||||
ATTEMPTED_TO_UPDATE_PLUGIN("Something has attempted to update the PLUGIN variable in the BossAPI class while it is already initialized."),
|
||||
ATTEMPTED_TO_SPAWN_WHILE_DISABLED("The {0} boss/minion attempted to spawn while editing is enabled."),
|
||||
|
@ -0,0 +1,16 @@
|
||||
package net.aminecraftdev.custombosses.utils;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 18-Jul-18
|
||||
*/
|
||||
public interface IContainer<StorageType> {
|
||||
|
||||
StorageType getData();
|
||||
|
||||
boolean saveData(StorageType storageType);
|
||||
|
||||
void clearContainer();
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package net.aminecraftdev.custombosses.utils;
|
||||
|
||||
import net.aminecraftdev.custombosses.utils.exceptions.NotImplementedException;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
@ -7,8 +9,8 @@ package net.aminecraftdev.custombosses.utils;
|
||||
*/
|
||||
public interface IConverter<OutputObject, InputObject> {
|
||||
|
||||
OutputObject to(InputObject inputObject);
|
||||
OutputObject to(InputObject inputObject) throws NotImplementedException;
|
||||
|
||||
InputObject from(OutputObject outputObject);
|
||||
InputObject from(OutputObject outputObject) throws NotImplementedException;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,118 @@
|
||||
package net.aminecraftdev.custombosses.utils.command;
|
||||
|
||||
import net.aminecraftdev.custombosses.utils.StringUtils;
|
||||
import net.aminecraftdev.custombosses.utils.command.attributes.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 28-Apr-18
|
||||
*/
|
||||
public abstract class CommandService<T extends CommandSender> extends BukkitCommand {
|
||||
|
||||
private static CommandMap _commandMap = null;
|
||||
|
||||
private String permission, noPermissionMsg;
|
||||
private String command, description;
|
||||
private Class<T> parameterClass;
|
||||
private String[] aliases;
|
||||
|
||||
public CommandService(Class<? extends CommandService> cmd) {
|
||||
super(cmd.getAnnotation(Name.class).value());
|
||||
|
||||
this.command = cmd.getAnnotation(Name.class).value();
|
||||
this.description = cmd.getAnnotation(Description.class).value();
|
||||
this.aliases = new String[]{};
|
||||
|
||||
if(cmd.isAnnotationPresent(Alias.class))
|
||||
this.aliases = cmd.getAnnotation(Alias.class).value();
|
||||
|
||||
if(cmd.isAnnotationPresent(Permission.class))
|
||||
this.permission = cmd.getAnnotation(Permission.class).value();
|
||||
|
||||
if(cmd.isAnnotationPresent(NoPermission.class))
|
||||
this.noPermissionMsg = cmd.getAnnotation(NoPermission.class).value();
|
||||
|
||||
getGenericClass();
|
||||
register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean execute(CommandSender commandSender, String s, String[] args) {
|
||||
if(this.permission != null && !testPermission(commandSender)) return false;
|
||||
|
||||
|
||||
if(!parameterClass.isInstance(commandSender)) {
|
||||
commandSender.sendMessage(StringUtils.get().translateColor("&4You cannot use that command."));
|
||||
return false;
|
||||
}
|
||||
|
||||
execute(parameterClass.cast(commandSender), args);
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void execute(T sender, String[] args);
|
||||
|
||||
public String getCommand() {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
public String[] getArrayAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
private void register() {
|
||||
if (_commandMap != null) {
|
||||
setFields();
|
||||
_commandMap.register(command, this);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Field field = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||
field.setAccessible(true);
|
||||
_commandMap = (CommandMap) field.get(Bukkit.getServer());
|
||||
|
||||
setFields();
|
||||
|
||||
_commandMap.register(command, this);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void setFields() {
|
||||
if(this.aliases != null) setAliases(Arrays.asList(this.aliases));
|
||||
if(this.description != null) setDescription(this.description);
|
||||
if(this.permission != null) setPermission(this.permission);
|
||||
if(this.noPermissionMsg != null) setPermissionMessage(this.noPermissionMsg);
|
||||
}
|
||||
|
||||
private void getGenericClass() {
|
||||
if(this.parameterClass == null) {
|
||||
Type superClass = getClass().getGenericSuperclass();
|
||||
Type tType = ((ParameterizedType) superClass).getActualTypeArguments()[0];
|
||||
String className = tType.toString().split(" ")[1];
|
||||
try {
|
||||
this.parameterClass = (Class<T>) Class.forName(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package net.aminecraftdev.custombosses.utils.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 28-Apr-18
|
||||
*/
|
||||
public interface ISubCommandHandler {
|
||||
|
||||
void addSubCommand(SubCommand subCommand);
|
||||
|
||||
boolean handleSubCommand(CommandSender commandSender, String[] args);
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package net.aminecraftdev.custombosses.utils.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 28-Apr-18
|
||||
*/
|
||||
public abstract class SubCommand {
|
||||
|
||||
private List<String> aliases = new ArrayList<>();
|
||||
private String subCommand;
|
||||
|
||||
public SubCommand(String subCommand) {
|
||||
this.subCommand = subCommand;
|
||||
}
|
||||
|
||||
public SubCommand(String subCommand, String... subCommands) {
|
||||
this(subCommand);
|
||||
|
||||
this.aliases.addAll(Arrays.asList(subCommands));
|
||||
}
|
||||
|
||||
public String getSubCommand() {
|
||||
return this.subCommand;
|
||||
}
|
||||
|
||||
public List<String> getAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
public boolean isSubCommand(String input) {
|
||||
input = input.toLowerCase();
|
||||
|
||||
return (input.equals(this.subCommand) || this.aliases.contains(input));
|
||||
}
|
||||
|
||||
public abstract void execute(CommandSender sender, String[] args);
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package net.aminecraftdev.custombosses.utils.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 28-Apr-18
|
||||
*/
|
||||
public abstract class SubCommandService<T extends CommandSender> extends CommandService<T> implements ISubCommandHandler {
|
||||
|
||||
private List<SubCommand> subCommands = new ArrayList<>();
|
||||
|
||||
public SubCommandService(Class<? extends CommandService> cmd) {
|
||||
super(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSubCommand(SubCommand subCommand) {
|
||||
this.subCommands.add(subCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSubCommand(CommandSender commandSender, String[] args) {
|
||||
for(SubCommand subCommand : this.subCommands) {
|
||||
if(subCommand.isSubCommand(args[0])) {
|
||||
subCommand.execute(commandSender, args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.aminecraftdev.custombosses.utils.command.attributes;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Created by charl on 03-May-17.
|
||||
*/
|
||||
@Documented
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Alias {
|
||||
|
||||
String[] value();
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.aminecraftdev.custombosses.utils.command.attributes;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Created by charl on 03-May-17.
|
||||
*/
|
||||
@Documented
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Description {
|
||||
|
||||
String value();
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.aminecraftdev.custombosses.utils.command.attributes;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Created by LukeBingham on 03/04/2017.
|
||||
*/
|
||||
@Documented
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Name {
|
||||
|
||||
String value();
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package net.aminecraftdev.custombosses.utils.command.attributes;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author AMinecraftDev
|
||||
* @version 1.0.0
|
||||
* @since 08-Jun-17
|
||||
*/
|
||||
@Documented
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface NoPermission {
|
||||
|
||||
String value();
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.aminecraftdev.custombosses.utils.command.attributes;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Created by charl on 11-May-17.
|
||||
*/
|
||||
@Documented
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Permission {
|
||||
|
||||
String value();
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.aminecraftdev.custombosses.utils.command.attributes;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Created by LukeBingham on 03/04/2017.
|
||||
*/
|
||||
@Documented
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Suggest {
|
||||
|
||||
String value();
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package net.aminecraftdev.custombosses.utils.exceptions;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 18-Jul-18
|
||||
*/
|
||||
public class NotImplementedException extends Exception {
|
||||
|
||||
public NotImplementedException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
public NotImplementedException() {
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package net.aminecraftdev.custombosses.utils.itemstack;
|
||||
|
||||
import net.aminecraftdev.custombosses.utils.IConverter;
|
||||
import net.aminecraftdev.custombosses.utils.exceptions.NotImplementedException;
|
||||
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 18-Jul-18
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ItemStackHolderConverter implements IConverter<ItemStackHolder, ConfigurationSection> {
|
||||
|
||||
@Override
|
||||
public ItemStackHolder to(ConfigurationSection configurationSection) {
|
||||
if(configurationSection == null) return null;
|
||||
|
||||
Integer amount = (Integer) configurationSection.get("amount", null);
|
||||
String type = configurationSection.getString("type", null);
|
||||
Short durability = (Short) configurationSection.get("durability", null);
|
||||
String name = configurationSection.getString("name", null);
|
||||
List<String> lore = (List<String>) configurationSection.getList("lore", null);
|
||||
List<String> enchants = (List<String>) configurationSection.getList("enchants", null);
|
||||
String skullOwner = configurationSection.getString("skullOwner", null);
|
||||
Short spawnerId = (Short) configurationSection.get("spawnerId", null);
|
||||
Boolean isGlowing = (Boolean) configurationSection.get("isGlowing", null);
|
||||
|
||||
return new ItemStackHolder(amount, type, durability, name, lore, enchants, skullOwner, spawnerId, isGlowing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSection from(ItemStackHolder itemStackHolder) throws NotImplementedException {
|
||||
throw new NotImplementedException("An ItemStackHolder cannot be converted to a ConfigurationSection.");
|
||||
}
|
||||
}
|
@ -0,0 +1,292 @@
|
||||
package net.aminecraftdev.custombosses.utils.itemstack;
|
||||
|
||||
import net.aminecraftdev.custombosses.utils.NumberUtils;
|
||||
import net.aminecraftdev.custombosses.utils.factory.NbtFactory;
|
||||
import net.aminecraftdev.custombosses.utils.itemstack.enchants.GlowEnchant;
|
||||
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by charl on 28-Apr-17.
|
||||
*/
|
||||
public class ItemStackUtils {
|
||||
|
||||
public static ItemStack createItemStack(ItemStack itemStack, Map<String,String> replaceMap) {
|
||||
return createItemStack(itemStack, replaceMap, null);
|
||||
}
|
||||
|
||||
public static ItemStack createItemStack(ItemStack itemStack, Map<String,String> replaceMap, Map<String,Object> compoundData) {
|
||||
ItemStack cloneStack = itemStack.clone();
|
||||
ItemMeta itemMeta = cloneStack.getItemMeta();
|
||||
boolean hasName = cloneStack.getItemMeta().hasDisplayName();
|
||||
boolean hasLore = cloneStack.getItemMeta().hasLore();
|
||||
String name = "";
|
||||
List<String> newLore = new ArrayList<>();
|
||||
|
||||
if(hasName) name = cloneStack.getItemMeta().getDisplayName();
|
||||
|
||||
if(replaceMap != null && !replaceMap.isEmpty()) {
|
||||
if(hasName) {
|
||||
for(String s : replaceMap.keySet()) {
|
||||
name = name.replace(s, replaceMap.get(s));
|
||||
}
|
||||
|
||||
itemMeta.setDisplayName(name);
|
||||
}
|
||||
|
||||
if(hasLore) {
|
||||
for(String s : itemMeta.getLore()) {
|
||||
for(String z : replaceMap.keySet()) {
|
||||
if(s.contains(z)) s = s.replace(z, replaceMap.get(z));
|
||||
}
|
||||
|
||||
newLore.add(s);
|
||||
}
|
||||
|
||||
itemMeta.setLore(newLore);
|
||||
}
|
||||
}
|
||||
|
||||
cloneStack.setItemMeta(itemMeta);
|
||||
|
||||
if(compoundData == null || compoundData.isEmpty()) return cloneStack;
|
||||
|
||||
ItemStack craftStack = NbtFactory.getCraftItemStack(cloneStack);
|
||||
NbtFactory.NbtCompound compound = NbtFactory.fromItemTag(craftStack);
|
||||
|
||||
for(String s : compoundData.keySet()) {
|
||||
compound.put(s, compoundData.get(s));
|
||||
}
|
||||
|
||||
return craftStack;
|
||||
}
|
||||
|
||||
public static ItemStack createItemStack(ConfigurationSection configurationSection) {
|
||||
return createItemStack(configurationSection, 1, null);
|
||||
}
|
||||
|
||||
public static ItemStack createItemStack(ConfigurationSection configurationSection, int amount, Map<String, String> replacedMap) {
|
||||
String type = configurationSection.getString("type");
|
||||
String name = configurationSection.getString("name");
|
||||
List<String> lore = configurationSection.getStringList("lore");
|
||||
List<String> enchants = configurationSection.getStringList("enchants");
|
||||
short durability = (short) configurationSection.getInt("durability");
|
||||
String owner = configurationSection.getString("owner");
|
||||
Map<Enchantment, Integer> map = new HashMap<>();
|
||||
List<String> newLore = new ArrayList<>();
|
||||
Material mat = getType(type);
|
||||
short meta = 0;
|
||||
boolean addGlow = false;
|
||||
|
||||
if(type instanceof String) {
|
||||
String sType = (String) type;
|
||||
|
||||
if(sType.contains(":")) {
|
||||
String[] split = sType.split(":");
|
||||
|
||||
meta = Short.valueOf(split[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if((replacedMap != null) && (name != null)) {
|
||||
for(String z : replacedMap.keySet()) {
|
||||
if(!name.contains(z)) continue;
|
||||
|
||||
name = name.replace(z, replacedMap.get(z));
|
||||
}
|
||||
}
|
||||
|
||||
if(lore != null) {
|
||||
for(String z : lore) {
|
||||
String y = z;
|
||||
|
||||
if(replacedMap != null) {
|
||||
for(String x : replacedMap.keySet()) {
|
||||
if(!y.contains(x)) continue;
|
||||
|
||||
y = y.replace(x, replacedMap.get(x));
|
||||
}
|
||||
}
|
||||
|
||||
if(y.contains("\n")) {
|
||||
String[] split = y.split("\n");
|
||||
|
||||
for(String s2 : split) {
|
||||
newLore.add(ChatColor.translateAlternateColorCodes('&', s2));
|
||||
}
|
||||
} else {
|
||||
newLore.add(ChatColor.translateAlternateColorCodes('&', y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(enchants != null) {
|
||||
for(String s : enchants) {
|
||||
String[] spl = s.split(":");
|
||||
String ench = spl[0];
|
||||
|
||||
if(ench.equalsIgnoreCase("GLOW")) {
|
||||
addGlow = true;
|
||||
} else {
|
||||
int level = Integer.parseInt(spl[1]);
|
||||
|
||||
map.put(Enchantment.getByName(ench), level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack itemStack = new ItemStack(mat, amount, meta);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(!newLore.isEmpty()) {
|
||||
itemMeta.setLore(newLore);
|
||||
}
|
||||
if(name != null) {
|
||||
if(!name.equals("")) {
|
||||
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
}
|
||||
}
|
||||
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
|
||||
if(!map.isEmpty()) {
|
||||
itemStack.addUnsafeEnchantments(map);
|
||||
}
|
||||
if(configurationSection.contains("durability")) {
|
||||
short dura = itemStack.getType().getMaxDurability();
|
||||
dura -= (short) durability - 1;
|
||||
|
||||
itemStack.setDurability(dura);
|
||||
}
|
||||
|
||||
if(configurationSection.contains("owner") && itemStack.getType() == Material.SKULL_ITEM) {
|
||||
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
|
||||
|
||||
skullMeta.setOwner(owner);
|
||||
|
||||
itemStack.setItemMeta(skullMeta);
|
||||
}
|
||||
|
||||
return addGlow? addGlow(itemStack) : itemStack;
|
||||
}
|
||||
|
||||
public static Material getType(String string) {
|
||||
Material material = Material.getMaterial(string);
|
||||
|
||||
if(material == null) {
|
||||
if(NumberUtils.get().isInt(string)) {
|
||||
material = Material.getMaterial(Integer.valueOf(string));
|
||||
|
||||
if(material != null) return material;
|
||||
|
||||
return null;
|
||||
} else {
|
||||
String[] split = string.split(":");
|
||||
|
||||
material = Material.getMaterial(Integer.valueOf(split[0]));
|
||||
|
||||
if(material != null) return material;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
public static ItemStack addGlow(ItemStack itemStack) {
|
||||
return GlowEnchant.addGlow(itemStack);
|
||||
}
|
||||
|
||||
public static void giveItems(Player player, ItemStack... items) {
|
||||
giveItems(player, Arrays.asList(items));
|
||||
}
|
||||
|
||||
public static void giveItems(Player player, List<ItemStack> items) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
for(ItemStack itemStack : items) {
|
||||
int amount = itemStack.getAmount();
|
||||
|
||||
while(amount > 0) {
|
||||
int toGive = amount > 64? 64 : amount;
|
||||
|
||||
ItemStack stack = itemStack.clone();
|
||||
stack.setAmount(toGive);
|
||||
|
||||
if(inventory.firstEmpty() != -1) {
|
||||
inventory.addItem(stack);
|
||||
} else {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), stack);
|
||||
}
|
||||
|
||||
amount -= toGive;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void takeItems(Player player, Map<ItemStack, Integer> items) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
for(ItemStack itemStack : items.keySet()) {
|
||||
int toTake = items.get(itemStack);
|
||||
int i = 0;
|
||||
|
||||
while(toTake > 0 && i < inventory.getSize()) {
|
||||
if (inventory.getItem(i) != null && inventory.getItem(i).getType() == itemStack.getType() && (inventory.getItem(i).getData().getData() == itemStack.getData().getData() || itemStack.getData().getData() == -1)) {
|
||||
ItemStack target = inventory.getItem(i);
|
||||
if(target.getAmount() > toTake) {
|
||||
target.setAmount(target.getAmount()-toTake);
|
||||
inventory.setItem(i, target);
|
||||
break;
|
||||
} else if(target.getAmount() == toTake) {
|
||||
inventory.setItem(i, new ItemStack(Material.AIR));
|
||||
break;
|
||||
} else {
|
||||
toTake -= target.getAmount();
|
||||
inventory.setItem(i, new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int getAmount(Player player, ItemStack itemStack) {
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
int amountInInventory = 0;
|
||||
|
||||
for(int i = 0; i < playerInventory.getSize(); i++) {
|
||||
if (playerInventory.getItem(i) != null && playerInventory.getItem(i).getType() == itemStack.getType() && (playerInventory.getItem(i).getData().getData() == itemStack.getData().getData() || itemStack.getData().getData() == -1)) {
|
||||
amountInInventory += playerInventory.getItem(i).getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
return amountInInventory;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static ItemStackHolder getItemStackHolder(ConfigurationSection configurationSection) {
|
||||
Integer amount = (Integer) configurationSection.get("amount", null);
|
||||
String type = configurationSection.getString("type", null);
|
||||
Short durability = (Short) configurationSection.get("durability", null);
|
||||
String name = configurationSection.getString("name", null);
|
||||
List<String> lore = (List<String>) configurationSection.getList("lore", null);
|
||||
List<String> enchants = (List<String>) configurationSection.getList("enchants", null);
|
||||
String skullOwner = configurationSection.getString("skullOwner", null);
|
||||
Short spawnerId = (Short) configurationSection.get("spawnerId", null);
|
||||
Boolean isGlowing = (Boolean) configurationSection.get("isGlowing", null);
|
||||
|
||||
return new ItemStackHolder(amount, type, durability, name, lore, enchants, skullOwner, spawnerId, isGlowing);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package net.aminecraftdev.custombosses.utils.itemstack.enchants;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
/**
|
||||
* @author AMinecraftDev
|
||||
* @version 1.0.0
|
||||
* @since 08-Jun-17
|
||||
*/
|
||||
public class GlowEnchant {
|
||||
|
||||
public static ItemStack addGlow(ItemStack base) {
|
||||
base.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
|
||||
|
||||
ItemMeta itemMeta = base.getItemMeta();
|
||||
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
base.setItemMeta(itemMeta);
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,379 @@
|
||||
package net.aminecraftdev.custombosses.utils.panel;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.aminecraftdev.custombosses.utils.StringUtils;
|
||||
import net.aminecraftdev.custombosses.utils.panel.base.ClickAction;
|
||||
import net.aminecraftdev.custombosses.utils.panel.base.PageAction;
|
||||
import net.aminecraftdev.custombosses.utils.panel.base.PanelCloseAction;
|
||||
import net.aminecraftdev.custombosses.utils.panel.builder.PanelBuilderCounter;
|
||||
import net.aminecraftdev.custombosses.utils.panel.builder.PanelBuilderSettings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author AMinecraftDev
|
||||
* @version 2.0.0
|
||||
* @since 18-Jul-2018
|
||||
*/
|
||||
public class Panel implements Listener {
|
||||
|
||||
//--------------------------------------------------
|
||||
//
|
||||
// P A N E L S T A T I C F I E L D S
|
||||
//
|
||||
//--------------------------------------------------
|
||||
|
||||
@Getter private static final List<Panel> PANELS = new ArrayList<>();
|
||||
|
||||
private static JavaPlugin PLUGIN;
|
||||
|
||||
//--------------------------------------------------
|
||||
//
|
||||
// P A N E L F I E L D S
|
||||
//
|
||||
//--------------------------------------------------
|
||||
|
||||
private final Map<Integer, ClickAction> targettedSlotActions = new HashMap<>();
|
||||
private final List<ClickAction> allSlotActions = new ArrayList<>();
|
||||
|
||||
private final Map<UUID, Integer> currentPageContainer = new HashMap<>();
|
||||
private final Map<Integer, Integer> pageData = new HashMap<>();
|
||||
private final List<UUID> openedUsers = new ArrayList<>();
|
||||
|
||||
@Getter private boolean cancelClick = true, destroyWhenDone = true, cancelLowerClick = true;
|
||||
@Getter private PanelBuilderSettings panelBuilderSettings;
|
||||
@Getter private Sound clickSound = null;
|
||||
@Getter private Inventory inventory;
|
||||
@Getter private int viewers = 0;
|
||||
|
||||
private PageAction onPageChange = (player, currentPage, requestedPage) -> false;
|
||||
private PanelCloseAction panelClose = (p) -> {};
|
||||
|
||||
//--------------------------------------------------
|
||||
//
|
||||
// P A N E L C O N S T R U C T O R S
|
||||
//
|
||||
//--------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a Panel with the specified arguments
|
||||
*
|
||||
* @param title - Panel title
|
||||
* @param size - Panel size
|
||||
*/
|
||||
public Panel(String title, int size) {
|
||||
Bukkit.getPluginManager().registerEvents(this, PLUGIN);
|
||||
|
||||
if(size % 9 != 0 && size != 5) {
|
||||
throw new UnsupportedOperationException("Inventory size must be a multiple of 9 or 5");
|
||||
}
|
||||
|
||||
this.inventory = size % 9 == 0 ? Bukkit.createInventory(null, size, StringUtils.get().translateColor(title)) : Bukkit.createInventory(null, InventoryType.HOPPER, StringUtils.get().translateColor(title));
|
||||
PANELS.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Panel with the specified arguments
|
||||
*
|
||||
* @param inventory - Panel inventory
|
||||
*/
|
||||
public Panel(Inventory inventory) {
|
||||
this(inventory, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Panel with the specified arguments
|
||||
*
|
||||
* @param inventory - Panel inventory
|
||||
* @param pageData - Panel page data
|
||||
*/
|
||||
public Panel(Inventory inventory, Map<Integer, Integer> pageData, PanelBuilderSettings panelBuilderSettings) {
|
||||
Bukkit.getPluginManager().registerEvents(this, PLUGIN);
|
||||
|
||||
this.inventory = inventory;
|
||||
this.pageData.putAll(pageData);
|
||||
this.panelBuilderSettings = panelBuilderSettings;
|
||||
|
||||
PANELS.add(this);
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
//
|
||||
// P A N E L L I S T E N E R S
|
||||
//
|
||||
//--------------------------------------------------
|
||||
|
||||
@EventHandler
|
||||
protected void onClick(InventoryClickEvent event) {
|
||||
if(event.getInventory() == null || event.getCursor() == null || getInventory() == null) return;
|
||||
if(!getInventory().equals(event.getInventory())) return;
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
Inventory inventory = event.getInventory();
|
||||
|
||||
if((!isCancelClick()) && (event.getRawSlot() > inventory.getSize())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(getClickSound() != null) player.playSound(player.getLocation(), getClickSound(), 3F, 1F);
|
||||
if(isCancelClick()) event.setCancelled(true);
|
||||
if(getInventory().equals(inventory)) executeAction(event.getSlot(), event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
protected void onClose(InventoryCloseEvent event) {
|
||||
if(event.getInventory() == null || getInventory() == null) return;
|
||||
if(!getInventory().equals(event.getInventory())) return;
|
||||
|
||||
Player player = (Player) event.getPlayer();
|
||||
|
||||
this.panelClose.onClose(player);
|
||||
this.openedUsers.remove(player.getUniqueId());
|
||||
this.viewers--;
|
||||
|
||||
if(getViewers() <= 0 && isDestroyWhenDone()) destroy();
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
//
|
||||
// P A N E L E X E C U T E A C T I O N
|
||||
//
|
||||
//--------------------------------------------------
|
||||
|
||||
private void executeAction(int slot, InventoryClickEvent e) {
|
||||
Player clicker = (Player) e.getWhoClicked();
|
||||
|
||||
if(this.pageData.containsKey(slot)) {
|
||||
int currentPage = this.currentPageContainer.getOrDefault(clicker.getUniqueId(), 0);
|
||||
|
||||
if(this.pageData.get(slot) > 0) {
|
||||
if(this.onPageChange.onPageAction(clicker, currentPage, currentPage+1)) {
|
||||
this.currentPageContainer.put(clicker.getUniqueId(), currentPage+1);
|
||||
}
|
||||
} else {
|
||||
if(currentPage != 0) {
|
||||
if (this.onPageChange.onPageAction(clicker, currentPage, currentPage-1)) {
|
||||
this.currentPageContainer.put(clicker.getUniqueId(), currentPage - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.targettedSlotActions.containsKey(slot)) {
|
||||
this.targettedSlotActions.get(slot).onClick(e);
|
||||
}
|
||||
|
||||
if(!this.allSlotActions.isEmpty()) {
|
||||
for(ClickAction clickAction : this.allSlotActions) {
|
||||
clickAction.onClick(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
//
|
||||
// P A N E L S E T M E T H O D S
|
||||
//
|
||||
//--------------------------------------------------
|
||||
|
||||
/**
|
||||
* Used to set an action for when a player clicks
|
||||
* the panel.
|
||||
*
|
||||
* @param slot - the slot for the action to happen
|
||||
* @param clickAction - the action to happen
|
||||
* @return an instance of the Panel.
|
||||
*/
|
||||
public Panel setOnClick(int slot, ClickAction clickAction) {
|
||||
this.targettedSlotActions.put(slot, clickAction);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set an action for when a player clicks
|
||||
* on any slot in the panel.
|
||||
*
|
||||
* @param clickAction - the action to happen
|
||||
* @return an instance of the Panel.
|
||||
*/
|
||||
public Panel setOnClick(ClickAction clickAction) {
|
||||
this.allSlotActions.add(clickAction);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to add an item to the next open slot in
|
||||
* the panel.
|
||||
*
|
||||
* @param itemStack - the itemstack to add.
|
||||
* @return an instance of the Panel.
|
||||
*/
|
||||
public Panel addItem(ItemStack itemStack) {
|
||||
this.inventory.addItem(itemStack);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set an item to a specific slot in the
|
||||
* panel.
|
||||
*
|
||||
* @param slot - the slot for the item to be set to
|
||||
* @param item - the item to be set.
|
||||
* @return an instance of the Panel.
|
||||
*/
|
||||
public Panel setItem(int slot, ItemStack item){
|
||||
this.inventory.setItem(slot, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set an item to a specific slot in the
|
||||
* panel and for an action to also be set to that
|
||||
* specified slot.
|
||||
*
|
||||
* @param slot - the slot for the action and item to be set to
|
||||
* @param item - the item to be set
|
||||
* @param action - the action to be applied
|
||||
* @return an instance of the Panel.
|
||||
*/
|
||||
public Panel setItem(int slot, ItemStack item, ClickAction action) {
|
||||
this.inventory.setItem(slot, item);
|
||||
|
||||
return setOnClick(slot, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set the click sound for when a player
|
||||
* clicks the panel.
|
||||
*
|
||||
* @param clickSound - the sound to be played.
|
||||
* @return an instance of the Panel.
|
||||
*/
|
||||
public Panel setClickSound(Sound clickSound) {
|
||||
this.clickSound = clickSound;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to open the panel for the specified player.
|
||||
*
|
||||
* @param player - the player to be opened for.
|
||||
* @return an instance of the Panel.
|
||||
*/
|
||||
public Panel openFor(Player player) {
|
||||
player.openInventory(this.inventory);
|
||||
this.openedUsers.add(player.getUniqueId());
|
||||
viewers++;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set an action for when a player closes
|
||||
* the panel.
|
||||
*
|
||||
* @param panelClose - the action to happen on close.
|
||||
* @return an instance of the Panel.
|
||||
*/
|
||||
public Panel setOnClose(PanelCloseAction panelClose) {
|
||||
this.panelClose = panelClose;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set an action for when a player changes
|
||||
* the panel page.
|
||||
*
|
||||
* @param onPageChange - the action to occur.
|
||||
* @return an instance of the Panel.
|
||||
*/
|
||||
public Panel setOnPageChange(PageAction onPageChange) {
|
||||
this.onPageChange = onPageChange;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set if clicks are cancelled in the panel.
|
||||
*
|
||||
* @param cancelClick - boolean if clicks are cancelled.
|
||||
* @return an instance of the Panel.
|
||||
*/
|
||||
public Panel setCancelClick(boolean cancelClick) {
|
||||
this.cancelClick = cancelClick;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to specify if the panel is destroyed when the
|
||||
* last person closes it.
|
||||
*
|
||||
* @param destroyWhenDone - the boolean to set if the panel destroys on close.
|
||||
* @return an instance of the Panel.
|
||||
*/
|
||||
public Panel setDestroyWhenDone(boolean destroyWhenDone) {
|
||||
this.destroyWhenDone = destroyWhenDone;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set if the click is cancelled on the bottom
|
||||
* GUI.
|
||||
*
|
||||
* @param cancelClick - if the click is cancelled.
|
||||
* @return an instance of the Panel.
|
||||
*/
|
||||
public Panel setCancelLowerClick(boolean cancelClick) {
|
||||
this.cancelLowerClick = cancelClick;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to destroy a panel, no matter how many people
|
||||
* are in it or what's happening in it.
|
||||
*
|
||||
* ** ONLY USE THIS IF YOU KNOW WHAT YOU'RE DOING **
|
||||
*
|
||||
*/
|
||||
public void destroy() {
|
||||
this.currentPageContainer.clear();
|
||||
this.targettedSlotActions.clear();
|
||||
this.allSlotActions.clear();
|
||||
this.pageData.clear();
|
||||
this.inventory = null;
|
||||
|
||||
this.openedUsers.forEach(uuid -> {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
|
||||
if(player == null) return;
|
||||
|
||||
player.closeInventory();
|
||||
});
|
||||
|
||||
this.openedUsers.clear();
|
||||
|
||||
InventoryClickEvent.getHandlerList().unregister(this);
|
||||
InventoryCloseEvent.getHandlerList().unregister(this);
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
//
|
||||
// P A N E L S T A T I C M E T H O D
|
||||
//
|
||||
//--------------------------------------------------
|
||||
|
||||
public static void setPlugin(JavaPlugin javaPlugin) {
|
||||
PLUGIN = javaPlugin;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package net.aminecraftdev.custombosses.utils.panel.base;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
/**
|
||||
* @author Debugged
|
||||
* @version 1.0
|
||||
* @since 13-5-2017
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ClickAction {
|
||||
|
||||
/**
|
||||
* Called whenever the item that this
|
||||
* ClickAction is associated with is triggered
|
||||
*
|
||||
* @param e InventoryClickEvent
|
||||
*/
|
||||
void onClick(InventoryClickEvent e);
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.aminecraftdev.custombosses.utils.panel.base;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Debugged
|
||||
* @version 1.0
|
||||
* @since 13-5-2017
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PageAction {
|
||||
|
||||
boolean onPageAction(Player player, int currentPage, int requestedPage);
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package net.aminecraftdev.custombosses.utils.panel.base;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Debugged
|
||||
* @version 1.0
|
||||
* @since 13-5-2017
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PanelCloseAction {
|
||||
|
||||
/**
|
||||
* Called whenever a player closes the Panel
|
||||
* that this PanelCloseAction is associated with
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
void onClose(Player player);
|
||||
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
package net.aminecraftdev.custombosses.utils.panel.builder;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.aminecraftdev.custombosses.utils.NumberUtils;
|
||||
import net.aminecraftdev.custombosses.utils.StringUtils;
|
||||
import net.aminecraftdev.custombosses.utils.itemstack.ItemStackUtils;
|
||||
import net.aminecraftdev.custombosses.utils.panel.Panel;
|
||||
import net.aminecraftdev.custombosses.utils.panel.base.ClickAction;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author AMinecraftDev
|
||||
* @version 2.0.0
|
||||
* @since 18-Jul-2018
|
||||
*/
|
||||
public class PanelBuilder {
|
||||
|
||||
private final Map<String, String> replaceMap = new HashMap<>();
|
||||
private final Set<Integer> defaultSlots = new HashSet<>();
|
||||
private final ConfigurationSection configurationSection;
|
||||
private final PanelBuilderSettings panelBuilderSettings;
|
||||
|
||||
@Getter private final PanelBuilderCounter panelBuilderCounter;
|
||||
|
||||
private Inventory inventory;
|
||||
private int size = 0;
|
||||
|
||||
public PanelBuilder(ConfigurationSection configurationSection) {
|
||||
this(configurationSection, null);
|
||||
}
|
||||
|
||||
public PanelBuilder(ConfigurationSection configurationSection, Map<String, String> replaceMap) {
|
||||
this.panelBuilderSettings = new PanelBuilderSettings(configurationSection);
|
||||
this.panelBuilderCounter = new PanelBuilderCounter();
|
||||
this.configurationSection = configurationSection;
|
||||
|
||||
if(replaceMap != null) this.replaceMap.putAll(replaceMap);
|
||||
}
|
||||
|
||||
public PanelBuilder setSize(int size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isDefaultSlot(int slot) {
|
||||
return defaultSlots.contains(slot);
|
||||
}
|
||||
|
||||
public Panel getPanel() {
|
||||
build();
|
||||
|
||||
Panel panel = new Panel(this.inventory, this.panelBuilderCounter.getPageData(), this.panelBuilderSettings);
|
||||
|
||||
Map<String, ItemStack> itemStackMap = this.panelBuilderCounter.getItemStacks();
|
||||
Map<String, ClickAction> clickActionMap = this.panelBuilderCounter.getClickActions();
|
||||
|
||||
this.panelBuilderCounter.getSlotsWithCounter().forEach((identifier, slotsWith) -> {
|
||||
if(itemStackMap.containsKey(identifier)) {
|
||||
slotsWith.forEach(slot -> panel.setItem(slot, itemStackMap.get(identifier)));
|
||||
}
|
||||
if(clickActionMap.containsKey(identifier)) {
|
||||
slotsWith.forEach(slot -> panel.setOnClick(slot, clickActionMap.get(identifier)));
|
||||
}
|
||||
});
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private void build() {
|
||||
String name = configurationSection.contains("name")? StringUtils.get().translateColor(configurationSection.getString("name")) : "?!? naming convention error ?!?";
|
||||
int slots = this.size != 0? this.size : configurationSection.contains("slots")? configurationSection.getInt("slots") : 9;
|
||||
ConfigurationSection itemSection = configurationSection.contains("Items")? configurationSection.getConfigurationSection("Items") : null;
|
||||
|
||||
name = replace(name);
|
||||
this.inventory = Bukkit.createInventory(null, slots, name);
|
||||
|
||||
if(itemSection != null) {
|
||||
Map<String, Set<Integer>> slotsWith = this.panelBuilderCounter.getSlotsWithCounter();
|
||||
Map<String, Map<Integer, Object>> specialSlotsWith = this.panelBuilderCounter.getSpecialValuesCounter();
|
||||
|
||||
for(String s : itemSection.getKeys(false)) {
|
||||
int slot = NumberUtils.get().isInt(s)? Integer.valueOf(s) - 1 : 0;
|
||||
ConfigurationSection innerSection = itemSection.getConfigurationSection(s);
|
||||
|
||||
if(innerSection.contains("NextPage") && innerSection.getBoolean("NextPage")) this.panelBuilderCounter.addPageData(slot, 1);
|
||||
if(innerSection.contains("PreviousPage") && innerSection.getBoolean("PreviousPage")) this.panelBuilderCounter.addPageData(slot, -1);
|
||||
|
||||
for(String identifier : slotsWith.keySet()) {
|
||||
if(innerSection.contains(identifier) && innerSection.getBoolean(identifier)) {
|
||||
Set<Integer> current = slotsWith.get(identifier);
|
||||
|
||||
current.add(slot);
|
||||
this.panelBuilderCounter.getSlotsWithCounter().put(identifier, current);
|
||||
}
|
||||
}
|
||||
|
||||
for(String identifier : specialSlotsWith.keySet()) {
|
||||
if(innerSection.contains(identifier)) {
|
||||
Map<Integer, Object> current = specialSlotsWith.get(identifier);
|
||||
|
||||
current.put(slot, innerSection.get(identifier));
|
||||
this.panelBuilderCounter.getSpecialValuesCounter().put(identifier, current);
|
||||
}
|
||||
}
|
||||
|
||||
if(slot > inventory.getSize() - 1) continue;
|
||||
|
||||
this.defaultSlots.add(slot);
|
||||
|
||||
if(innerSection.contains("Item")) innerSection = innerSection.getConfigurationSection("Item");
|
||||
if(!innerSection.contains("type")) continue;
|
||||
|
||||
this.inventory.setItem(slot, ItemStackUtils.createItemStack(innerSection, 1, replaceMap));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String replace(String input) {
|
||||
for(Map.Entry<String, String> entry : replaceMap.entrySet()) {
|
||||
if(input.contains(entry.getKey())) {
|
||||
input = input.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package net.aminecraftdev.custombosses.utils.panel.builder;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.aminecraftdev.custombosses.utils.panel.base.ClickAction;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 18-Jul-18
|
||||
*/
|
||||
public class PanelBuilderCounter {
|
||||
|
||||
@Getter private final Map<String, Map<Integer, Object>> specialValuesCounter = new HashMap<>();
|
||||
@Getter private final Map<String, Set<Integer>> slotsWithCounter = new HashMap<>();
|
||||
@Getter private final Map<String, ClickAction> clickActions = new HashMap<>();
|
||||
@Getter private final Map<Integer, String> buttonCounters = new HashMap<>();
|
||||
@Getter private final Map<String, ItemStack> itemStacks = new HashMap<>();
|
||||
@Getter private final Map<Integer, Integer> pageData = new HashMap<>();
|
||||
|
||||
public PanelBuilderCounter addSpecialCounter(String identifier) {
|
||||
this.specialValuesCounter.put(identifier, new HashMap<>());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PanelBuilderCounter addSpecialCounter(String identifier, ClickAction clickAction) {
|
||||
this.specialValuesCounter.put(identifier, new HashMap<>());
|
||||
this.clickActions.put(identifier, clickAction);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PanelBuilderCounter addSlotCounter(String identifier) {
|
||||
this.slotsWithCounter.put(identifier, new HashSet<>());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PanelBuilderCounter addSlotCounter(String identifier, ClickAction clickAction) {
|
||||
this.slotsWithCounter.put(identifier, new HashSet<>());
|
||||
this.clickActions.put(identifier, clickAction);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PanelBuilderCounter addSlotCounter(String identifier, ItemStack itemStack) {
|
||||
this.slotsWithCounter.put(identifier, new HashSet<>());
|
||||
this.itemStacks.put(identifier, itemStack);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PanelBuilderCounter addSlotCounter(String identifier, ItemStack itemStack, ClickAction clickAction) {
|
||||
this.slotsWithCounter.put(identifier, new HashSet<>());
|
||||
this.itemStacks.put(identifier, itemStack);
|
||||
this.clickActions.put(identifier, clickAction);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PanelBuilderCounter addPageData(int slot, int pageMath) {
|
||||
this.pageData.put(slot, pageMath);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<Integer> getSlotsWith(String identifier) {
|
||||
return this.slotsWithCounter.getOrDefault(identifier, new HashSet<>());
|
||||
}
|
||||
|
||||
public Map<Integer, Object> getSpecialSlotsWith(String identifier) {
|
||||
return this.specialValuesCounter.getOrDefault(identifier, new HashMap<>());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package net.aminecraftdev.custombosses.utils.panel.builder;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.aminecraftdev.custombosses.utils.itemstack.ItemStackHolderConverter;
|
||||
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 18-Jul-18
|
||||
*/
|
||||
public class PanelBuilderSettings {
|
||||
|
||||
@Getter private boolean emptySpaceFiller, backButton, exitButton;
|
||||
@Getter private int fillTo, backButtonSlot, exitButtonSlot;
|
||||
@Getter private ItemStackHolder emptySpaceFillerItem;
|
||||
|
||||
public PanelBuilderSettings(ConfigurationSection configurationSection) {
|
||||
ItemStackHolderConverter itemStackHolderConverter = new ItemStackHolderConverter();
|
||||
|
||||
this.emptySpaceFiller = configurationSection.getBoolean("Settings.emptySpaceFiller", false);
|
||||
this.backButton = configurationSection.getBoolean("Settings.backButton", false);
|
||||
this.exitButton = configurationSection.getBoolean("Settings.exitButton", false);
|
||||
this.fillTo = configurationSection.getInt("Settings.fillTo", 0);
|
||||
this.backButtonSlot = configurationSection.getInt("Buttons.backButton", -1);
|
||||
this.exitButtonSlot = configurationSection.getInt("Buttons.exitButton", -1);
|
||||
this.emptySpaceFillerItem = itemStackHolderConverter.to(configurationSection.getConfigurationSection("EmptySpaceFiller"));
|
||||
}
|
||||
|
||||
}
|
2
pom.xml
2
pom.xml
@ -19,7 +19,7 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<plugin.version>3.0.0-SNAPSHOT-U18</plugin.version>
|
||||
<plugin.version>3.0.0-SNAPSHOT-U19</plugin.version>
|
||||
<plugin.name>CustomBosses</plugin.name>
|
||||
<plugin.main>net.aminecraftdev.custombosses.CustomBosses</plugin.main>
|
||||
<plugin.author>AMinecraftDev</plugin.author>
|
||||
|
Loading…
Reference in New Issue
Block a user