mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-28 05:25:21 +01:00
Fixes JavaDoc warnings. (#164)
@inheritDoc cannot be used on Constructors. Fixed some other warnings.
This commit is contained in:
parent
76fb30be36
commit
a50d00b2e7
@ -17,27 +17,27 @@ import world.bentobox.challenges.database.object.Challenge;
|
|||||||
public class ChallengeDataRequestHandler extends AddonRequestHandler
|
public class ChallengeDataRequestHandler extends AddonRequestHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor creates a new ChallengesDataRequestHandler instance.
|
* Constructor creates a new ChallengesDataRequestHandler instance.
|
||||||
*
|
*
|
||||||
* @param addon of type ChallengesAddon
|
* @param addon of type ChallengesAddon
|
||||||
*/
|
*/
|
||||||
public ChallengeDataRequestHandler(ChallengesAddon addon)
|
public ChallengeDataRequestHandler(ChallengesAddon addon)
|
||||||
{
|
{
|
||||||
super("challenge-data");
|
super("challenge-data");
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @param metaData Required meta data.
|
* @param metaData Required meta data.
|
||||||
* @return Map that returns information about challenges
|
* @return Map that returns information about challenges
|
||||||
* @see AddonRequestHandler#handle(Map<String, Object>)
|
* @see world.bentobox.bentobox.api.addons.request.AddonRequestHandler#handle(java.util.Map)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object handle(Map<String, Object> metaData)
|
public Object handle(Map<String, Object> metaData)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
What we need in the metaData:
|
What we need in the metaData:
|
||||||
0. "challenge-name" -> String
|
0. "challenge-name" -> String
|
||||||
What we will return:
|
What we will return:
|
||||||
@ -56,51 +56,51 @@ public class ChallengeDataRequestHandler extends AddonRequestHandler
|
|||||||
- maxTimes: Integer object that represents how many times challenge can be completed.
|
- maxTimes: Integer object that represents how many times challenge can be completed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (metaData == null ||
|
if (metaData == null ||
|
||||||
metaData.isEmpty() ||
|
metaData.isEmpty() ||
|
||||||
metaData.get("challenge-name") == null ||
|
metaData.get("challenge-name") == null ||
|
||||||
!(metaData.get("challenge-name") instanceof String))
|
!(metaData.get("challenge-name") instanceof String))
|
||||||
{
|
{
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
Challenge challenge = this.addon.getChallengesManager().getChallenge((String) metaData.get("challenge-name"));
|
Challenge challenge = this.addon.getChallengesManager().getChallenge((String) metaData.get("challenge-name"));
|
||||||
|
|
||||||
Map<String, Object> challengeDataMap;
|
Map<String, Object> challengeDataMap;
|
||||||
|
|
||||||
if (challenge == null)
|
if (challenge == null)
|
||||||
{
|
{
|
||||||
challengeDataMap = Collections.emptyMap();
|
challengeDataMap = Collections.emptyMap();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
challengeDataMap = new HashMap<>();
|
challengeDataMap = new HashMap<>();
|
||||||
|
|
||||||
challengeDataMap.put("uniqueId", challenge.getUniqueId());
|
challengeDataMap.put("uniqueId", challenge.getUniqueId());
|
||||||
challengeDataMap.put("name", challenge.getFriendlyName());
|
challengeDataMap.put("name", challenge.getFriendlyName());
|
||||||
challengeDataMap.put("icon", challenge.getIcon());
|
challengeDataMap.put("icon", challenge.getIcon());
|
||||||
challengeDataMap.put("levelId", challenge.getLevel());
|
challengeDataMap.put("levelId", challenge.getLevel());
|
||||||
challengeDataMap.put("order", challenge.getOrder());
|
challengeDataMap.put("order", challenge.getOrder());
|
||||||
challengeDataMap.put("deployed", challenge.isDeployed());
|
challengeDataMap.put("deployed", challenge.isDeployed());
|
||||||
challengeDataMap.put("description", challenge.getDescription());
|
challengeDataMap.put("description", challenge.getDescription());
|
||||||
challengeDataMap.put("type", challenge.getChallengeType().toString());
|
challengeDataMap.put("type", challenge.getChallengeType().toString());
|
||||||
|
|
||||||
challengeDataMap.put("repeatable", challenge.isRepeatable());
|
challengeDataMap.put("repeatable", challenge.isRepeatable());
|
||||||
challengeDataMap.put("maxTimes", challenge.isRepeatable() ? challenge.getMaxTimes() : 1);
|
challengeDataMap.put("maxTimes", challenge.isRepeatable() ? challenge.getMaxTimes() : 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return challengeDataMap;
|
return challengeDataMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variable stores challenges addon.
|
* Variable stores challenges addon.
|
||||||
*/
|
*/
|
||||||
private ChallengesAddon addon;
|
private ChallengesAddon addon;
|
||||||
}
|
}
|
||||||
|
@ -14,53 +14,53 @@ import world.bentobox.challenges.ChallengesAddon;
|
|||||||
*/
|
*/
|
||||||
public class ChallengeListRequestHandler extends AddonRequestHandler
|
public class ChallengeListRequestHandler extends AddonRequestHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor creates a new CompletedChallengesRequestHandler instance.
|
* Constructor creates a new CompletedChallengesRequestHandler instance.
|
||||||
*
|
*
|
||||||
* @param addon of type ChallengesAddon
|
* @param addon of type ChallengesAddon
|
||||||
*/
|
*/
|
||||||
public ChallengeListRequestHandler(ChallengesAddon addon)
|
public ChallengeListRequestHandler(ChallengesAddon addon)
|
||||||
{
|
{
|
||||||
super("challenge-list");
|
super("challenge-list");
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @param metaData Required meta data.
|
* @see world.bentobox.bentobox.api.addons.request.AddonRequestHandler#handle(java.util.Map)
|
||||||
* @return Set of strings that contains completed challenges.
|
* @param metaData Required meta data.
|
||||||
* @see AddonRequestHandler#handle(Map <String, Object>)
|
* @return Set of strings that contains completed challenges.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object handle(Map<String, Object> metaData)
|
public Object handle(Map<String, Object> metaData)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
What we need in the metaData:
|
What we need in the metaData:
|
||||||
0. "world-name" -> String
|
0. "world-name" -> String
|
||||||
What we will return:
|
What we will return:
|
||||||
- List of challenges in given world.
|
- List of challenges in given world.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (metaData == null ||
|
if (metaData == null ||
|
||||||
metaData.isEmpty() ||
|
metaData.isEmpty() ||
|
||||||
metaData.get("world-name") == null ||
|
metaData.get("world-name") == null ||
|
||||||
!(metaData.get("world-name") instanceof String) ||
|
!(metaData.get("world-name") instanceof String) ||
|
||||||
Bukkit.getWorld((String) metaData.get("world-name")) == null)
|
Bukkit.getWorld((String) metaData.get("world-name")) == null)
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.addon.getChallengesManager().getAllChallengesNames(Bukkit.getWorld((String) metaData.get("world-name")));
|
return this.addon.getChallengesManager().getAllChallengesNames(Bukkit.getWorld((String) metaData.get("world-name")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variable stores challenges addon.
|
* Variable stores challenges addon.
|
||||||
*/
|
*/
|
||||||
private ChallengesAddon addon;
|
private ChallengesAddon addon;
|
||||||
}
|
}
|
||||||
|
@ -17,27 +17,27 @@ import world.bentobox.challenges.ChallengesManager;
|
|||||||
public class CompletedChallengesRequestHandler extends AddonRequestHandler
|
public class CompletedChallengesRequestHandler extends AddonRequestHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor creates a new CompletedChallengesRequestHandler instance.
|
* Constructor creates a new CompletedChallengesRequestHandler instance.
|
||||||
*
|
*
|
||||||
* @param addon of type ChallengesAddon
|
* @param addon of type ChallengesAddon
|
||||||
*/
|
*/
|
||||||
public CompletedChallengesRequestHandler(ChallengesAddon addon)
|
public CompletedChallengesRequestHandler(ChallengesAddon addon)
|
||||||
{
|
{
|
||||||
super("completed-challenges");
|
super("completed-challenges");
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @param metaData Required meta data.
|
* @see world.bentobox.bentobox.api.addons.request.AddonRequestHandler#handle(java.util.Map)
|
||||||
* @return Set of strings that contains completed challenges.
|
* @param metaData Required meta data.
|
||||||
* @see AddonRequestHandler#handle(Map<String, Object>)
|
* @return Set of strings that contains completed challenges.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object handle(Map<String, Object> metaData)
|
public Object handle(Map<String, Object> metaData)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
What we need in the metaData:
|
What we need in the metaData:
|
||||||
0. "player" -> UUID
|
0. "player" -> UUID
|
||||||
1. "world-name" -> String
|
1. "world-name" -> String
|
||||||
@ -46,35 +46,35 @@ public class CompletedChallengesRequestHandler extends AddonRequestHandler
|
|||||||
- Set of completed challenges in given world (or empty list if user haven't completed any challenge)
|
- Set of completed challenges in given world (or empty list if user haven't completed any challenge)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (metaData == null ||
|
if (metaData == null ||
|
||||||
metaData.isEmpty() ||
|
metaData.isEmpty() ||
|
||||||
metaData.get("world-name") == null ||
|
metaData.get("world-name") == null ||
|
||||||
!(metaData.get("world-name") instanceof String) ||
|
!(metaData.get("world-name") instanceof String) ||
|
||||||
metaData.get("player") == null ||
|
metaData.get("player") == null ||
|
||||||
!(metaData.get("player") instanceof UUID) ||
|
!(metaData.get("player") instanceof UUID) ||
|
||||||
Bukkit.getWorld((String) metaData.get("world-name")) == null)
|
Bukkit.getWorld((String) metaData.get("world-name")) == null)
|
||||||
{
|
{
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
World world = Bukkit.getWorld((String) metaData.get("world-name"));
|
World world = Bukkit.getWorld((String) metaData.get("world-name"));
|
||||||
UUID player = (UUID) metaData.get("player");
|
UUID player = (UUID) metaData.get("player");
|
||||||
|
|
||||||
ChallengesManager manager = this.addon.getChallengesManager();
|
ChallengesManager manager = this.addon.getChallengesManager();
|
||||||
|
|
||||||
return manager.getAllChallengesNames(world).stream().
|
return manager.getAllChallengesNames(world).stream().
|
||||||
filter(challenge -> manager.isChallengeComplete(player, world, challenge)).
|
filter(challenge -> manager.isChallengeComplete(player, world, challenge)).
|
||||||
collect(Collectors.toSet());
|
collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variable stores challenges addon.
|
* Variable stores challenges addon.
|
||||||
*/
|
*/
|
||||||
private ChallengesAddon addon;
|
private ChallengesAddon addon;
|
||||||
}
|
}
|
||||||
|
@ -15,27 +15,27 @@ import world.bentobox.challenges.database.object.ChallengeLevel;
|
|||||||
*/
|
*/
|
||||||
public class LevelDataRequestHandler extends AddonRequestHandler
|
public class LevelDataRequestHandler extends AddonRequestHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor creates a new LevelDataRequestHandler instance.
|
* Constructor creates a new LevelDataRequestHandler instance.
|
||||||
*
|
*
|
||||||
* @param addon of type ChallengesAddon
|
* @param addon of type ChallengesAddon
|
||||||
*/
|
*/
|
||||||
public LevelDataRequestHandler(ChallengesAddon addon)
|
public LevelDataRequestHandler(ChallengesAddon addon)
|
||||||
{
|
{
|
||||||
super("level-data");
|
super("level-data");
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @param metaData Required meta data.
|
* @see world.bentobox.bentobox.api.addons.request.AddonRequestHandler#handle(java.util.Map)
|
||||||
* @return Map that returns information about level
|
* @param metaData Required meta data.
|
||||||
* @see AddonRequestHandler#handle(Map <String, Object>)
|
* @return Map that returns information about level
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object handle(Map<String, Object> metaData)
|
public Object handle(Map<String, Object> metaData)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
What we need in the metaData:
|
What we need in the metaData:
|
||||||
0. "level-name" -> String
|
0. "level-name" -> String
|
||||||
What we will return:
|
What we will return:
|
||||||
@ -52,47 +52,47 @@ public class LevelDataRequestHandler extends AddonRequestHandler
|
|||||||
- challenges: List of strings that represents challenges that is owned by given level.
|
- challenges: List of strings that represents challenges that is owned by given level.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (metaData == null ||
|
if (metaData == null ||
|
||||||
metaData.isEmpty() ||
|
metaData.isEmpty() ||
|
||||||
metaData.get("level-name") == null ||
|
metaData.get("level-name") == null ||
|
||||||
!(metaData.get("level-name") instanceof String))
|
!(metaData.get("level-name") instanceof String))
|
||||||
{
|
{
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ChallengeLevel level = this.addon.getChallengesManager().getLevel((String) metaData.get("level-name"));
|
ChallengeLevel level = this.addon.getChallengesManager().getLevel((String) metaData.get("level-name"));
|
||||||
|
|
||||||
Map<String, Object> levelDataMap;
|
Map<String, Object> levelDataMap;
|
||||||
|
|
||||||
if (level == null)
|
if (level == null)
|
||||||
{
|
{
|
||||||
levelDataMap = Collections.emptyMap();
|
levelDataMap = Collections.emptyMap();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
levelDataMap = new HashMap<>();
|
levelDataMap = new HashMap<>();
|
||||||
|
|
||||||
levelDataMap.put("uniqueId", level.getUniqueId());
|
levelDataMap.put("uniqueId", level.getUniqueId());
|
||||||
levelDataMap.put("name", level.getFriendlyName());
|
levelDataMap.put("name", level.getFriendlyName());
|
||||||
levelDataMap.put("icon", level.getIcon());
|
levelDataMap.put("icon", level.getIcon());
|
||||||
levelDataMap.put("order", level.getOrder());
|
levelDataMap.put("order", level.getOrder());
|
||||||
levelDataMap.put("message", level.getUnlockMessage());
|
levelDataMap.put("message", level.getUnlockMessage());
|
||||||
levelDataMap.put("world", level.getWorld());
|
levelDataMap.put("world", level.getWorld());
|
||||||
levelDataMap.put("challenges", level.getChallenges());
|
levelDataMap.put("challenges", level.getChallenges());
|
||||||
levelDataMap.put("waiveramount", level.getWaiverAmount());
|
levelDataMap.put("waiveramount", level.getWaiverAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
return levelDataMap;
|
return levelDataMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variable stores challenges addon.
|
* Variable stores challenges addon.
|
||||||
*/
|
*/
|
||||||
private ChallengesAddon addon;
|
private ChallengesAddon addon;
|
||||||
}
|
}
|
||||||
|
@ -15,53 +15,53 @@ import world.bentobox.challenges.ChallengesAddon;
|
|||||||
public class LevelListRequestHandler extends AddonRequestHandler
|
public class LevelListRequestHandler extends AddonRequestHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor creates a new CompletedChallengesRequestHandler instance.
|
* Constructor creates a new CompletedChallengesRequestHandler instance.
|
||||||
*
|
*
|
||||||
* @param addon of type ChallengesAddon
|
* @param addon of type ChallengesAddon
|
||||||
*/
|
*/
|
||||||
public LevelListRequestHandler(ChallengesAddon addon)
|
public LevelListRequestHandler(ChallengesAddon addon)
|
||||||
{
|
{
|
||||||
super("level-list");
|
super("level-list");
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @param metaData Required meta data.
|
* @see world.bentobox.bentobox.api.addons.request.AddonRequestHandler#handle(java.util.Map)
|
||||||
* @return List of strings that contains levels in given world
|
* @param metaData Required meta data.
|
||||||
* @see AddonRequestHandler#handle(Map <String, Object>)
|
* @return List of strings that contains levels in given world
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object handle(Map<String, Object> metaData)
|
public Object handle(Map<String, Object> metaData)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
What we need in the metaData:
|
What we need in the metaData:
|
||||||
0. "world-name" -> String
|
0. "world-name" -> String
|
||||||
What we will return:
|
What we will return:
|
||||||
- List of levels in given world.
|
- List of levels in given world.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (metaData == null ||
|
if (metaData == null ||
|
||||||
metaData.isEmpty() ||
|
metaData.isEmpty() ||
|
||||||
metaData.get("world-name") == null ||
|
metaData.get("world-name") == null ||
|
||||||
!(metaData.get("world-name") instanceof String) ||
|
!(metaData.get("world-name") instanceof String) ||
|
||||||
Bukkit.getWorld((String) metaData.get("world-name")) == null)
|
Bukkit.getWorld((String) metaData.get("world-name")) == null)
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.addon.getChallengesManager().getLevels(Bukkit.getWorld((String) metaData.get("world-name")));
|
return this.addon.getChallengesManager().getLevels(Bukkit.getWorld((String) metaData.get("world-name")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variable stores challenges addon.
|
* Variable stores challenges addon.
|
||||||
*/
|
*/
|
||||||
private ChallengesAddon addon;
|
private ChallengesAddon addon;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -22,117 +22,122 @@ import world.bentobox.challenges.utils.GuiUtils;
|
|||||||
*/
|
*/
|
||||||
public class GameModesGUI extends CommonGUI
|
public class GameModesGUI extends CommonGUI
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* @param adminMode - boolean that indicate if Gui is in admin mode.
|
||||||
* @param adminMode - boolean that indicate if Gui is in admin mode.
|
* @param gameModeAddons - List with GameModes where Challenges addon is integrated.
|
||||||
* @param gameModeAddons - List with GameModes where Challenges addon is integrated.
|
* @param addon Addon where panel operates.
|
||||||
*/
|
* @param world World from which panel was created.
|
||||||
public GameModesGUI(ChallengesAddon addon,
|
* @param user User who created panel.
|
||||||
World world,
|
* @param topLabel Command top label which creates panel (f.e. island or ai)
|
||||||
User user,
|
* @param permissionPrefix Command permission prefix (f.e. bskyblock.)
|
||||||
String topLabel,
|
|
||||||
String permissionPrefix,
|
*/
|
||||||
boolean adminMode,
|
public GameModesGUI(ChallengesAddon addon,
|
||||||
List<GameModeAddon> gameModeAddons)
|
World world,
|
||||||
{
|
User user,
|
||||||
super(addon, world, user, topLabel, permissionPrefix);
|
String topLabel,
|
||||||
this.adminMode = adminMode;
|
String permissionPrefix,
|
||||||
this.gameModeAddons = gameModeAddons;
|
boolean adminMode,
|
||||||
}
|
List<GameModeAddon> gameModeAddons)
|
||||||
|
{
|
||||||
|
super(addon, world, user, topLabel, permissionPrefix);
|
||||||
|
this.adminMode = adminMode;
|
||||||
|
this.gameModeAddons = gameModeAddons;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build()
|
public void build()
|
||||||
{
|
{
|
||||||
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).
|
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).
|
||||||
name("challenges.gui.title.game-modes");
|
name("challenges.gui.title.game-modes");
|
||||||
|
|
||||||
GuiUtils.fillBorder(panelBuilder, this.adminMode ?
|
GuiUtils.fillBorder(panelBuilder, this.adminMode ?
|
||||||
Material.BLACK_STAINED_GLASS_PANE :
|
Material.BLACK_STAINED_GLASS_PANE :
|
||||||
Material.BLUE_STAINED_GLASS_PANE);
|
Material.BLUE_STAINED_GLASS_PANE);
|
||||||
|
|
||||||
int elementIndex;
|
int elementIndex;
|
||||||
|
|
||||||
if (this.gameModeAddons.size() < 8)
|
if (this.gameModeAddons.size() < 8)
|
||||||
{
|
{
|
||||||
if (this.gameModeAddons.size() == 7)
|
if (this.gameModeAddons.size() == 7)
|
||||||
{
|
{
|
||||||
elementIndex = 19;
|
elementIndex = 19;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
elementIndex = 22 - this.gameModeAddons.size() / 2;
|
elementIndex = 22 - this.gameModeAddons.size() / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
elementIndex = 10;
|
elementIndex = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (GameModeAddon gameModeAddon : this.gameModeAddons)
|
for (GameModeAddon gameModeAddon : this.gameModeAddons)
|
||||||
{
|
{
|
||||||
if (!panelBuilder.slotOccupied(elementIndex))
|
if (!panelBuilder.slotOccupied(elementIndex))
|
||||||
{
|
{
|
||||||
panelBuilder.item(elementIndex++, this.createGameModeIcon(gameModeAddon));
|
panelBuilder.item(elementIndex++, this.createGameModeIcon(gameModeAddon));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Find first open slot
|
// Find first open slot
|
||||||
while (panelBuilder.slotOccupied(elementIndex))
|
while (panelBuilder.slotOccupied(elementIndex))
|
||||||
{
|
{
|
||||||
elementIndex++;
|
elementIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
panelBuilder.build();
|
panelBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates icon that will display given GameMode addon.
|
* This method creates icon that will display given GameMode addon.
|
||||||
* @param gameModeAddon GameMode addon.
|
* @param gameModeAddon GameMode addon.
|
||||||
* @return PanelItem that acts as icon for given GameMode.
|
* @return PanelItem that acts as icon for given GameMode.
|
||||||
*/
|
*/
|
||||||
private PanelItem createGameModeIcon(GameModeAddon gameModeAddon)
|
private PanelItem createGameModeIcon(GameModeAddon gameModeAddon)
|
||||||
{
|
{
|
||||||
return new PanelItemBuilder().
|
return new PanelItemBuilder().
|
||||||
name(gameModeAddon.getDescription().getName()).
|
name(gameModeAddon.getDescription().getName()).
|
||||||
description(gameModeAddon.getDescription().getDescription()).
|
description(gameModeAddon.getDescription().getDescription()).
|
||||||
icon(Material.PAPER).
|
icon(Material.PAPER).
|
||||||
clickHandler((panel, user, clickType, slot) -> {
|
clickHandler((panel, user, clickType, slot) -> {
|
||||||
Optional<CompositeCommand> command;
|
Optional<CompositeCommand> command;
|
||||||
|
|
||||||
if (this.adminMode)
|
if (this.adminMode)
|
||||||
{
|
{
|
||||||
command = gameModeAddon.getAdminCommand();
|
command = gameModeAddon.getAdminCommand();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
command = gameModeAddon.getPlayerCommand();
|
command = gameModeAddon.getPlayerCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
command.ifPresent(compositeCommand ->
|
command.ifPresent(compositeCommand ->
|
||||||
user.performCommand(compositeCommand.getTopLabel() + " challenges"));
|
user.performCommand(compositeCommand.getTopLabel() + " challenges"));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}).
|
}).
|
||||||
build();
|
build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List with game mode addons which must be showed in current GUI.
|
* List with game mode addons which must be showed in current GUI.
|
||||||
*/
|
*/
|
||||||
private List<GameModeAddon> gameModeAddons;
|
private List<GameModeAddon> gameModeAddons;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores if current GUI is in Admin Mode or not.
|
* Stores if current GUI is in Admin Mode or not.
|
||||||
*/
|
*/
|
||||||
private boolean adminMode;
|
private boolean adminMode;
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,11 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import net.wesjd.anvilgui.AnvilGUI;
|
import net.wesjd.anvilgui.AnvilGUI;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.util.Util;
|
|
||||||
import world.bentobox.challenges.ChallengesAddon;
|
import world.bentobox.challenges.ChallengesAddon;
|
||||||
import world.bentobox.challenges.panel.CommonGUI;
|
import world.bentobox.challenges.panel.CommonGUI;
|
||||||
import world.bentobox.challenges.panel.util.ConfirmationGUI;
|
import world.bentobox.challenges.panel.util.ConfirmationGUI;
|
||||||
@ -26,474 +22,478 @@ import world.bentobox.challenges.utils.Utils;
|
|||||||
*/
|
*/
|
||||||
public class AdminGUI extends CommonGUI
|
public class AdminGUI extends CommonGUI
|
||||||
{
|
{
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This boolean holds if import should overwrite existing challenges.
|
* This boolean holds if import should overwrite existing challenges.
|
||||||
*/
|
*/
|
||||||
private boolean overwriteMode;
|
private boolean overwriteMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This indicate if Reset Challenges must work as reset all.
|
* This indicate if Reset Challenges must work as reset all.
|
||||||
*/
|
*/
|
||||||
private boolean resetAllMode;
|
private boolean resetAllMode;
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Enums
|
// Section: Enums
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This enum contains all button variations. Just for cleaner code.
|
* This enum contains all button variations. Just for cleaner code.
|
||||||
*/
|
*/
|
||||||
private enum Button
|
private enum Button
|
||||||
{
|
{
|
||||||
COMPLETE_USER_CHALLENGES,
|
COMPLETE_USER_CHALLENGES,
|
||||||
RESET_USER_CHALLENGES,
|
RESET_USER_CHALLENGES,
|
||||||
ADD_CHALLENGE,
|
ADD_CHALLENGE,
|
||||||
ADD_LEVEL,
|
ADD_LEVEL,
|
||||||
EDIT_CHALLENGE,
|
EDIT_CHALLENGE,
|
||||||
EDIT_LEVEL,
|
EDIT_LEVEL,
|
||||||
DELETE_CHALLENGE,
|
DELETE_CHALLENGE,
|
||||||
DELETE_LEVEL,
|
DELETE_LEVEL,
|
||||||
IMPORT_CHALLENGES,
|
IMPORT_CHALLENGES,
|
||||||
EDIT_SETTINGS,
|
EDIT_SETTINGS,
|
||||||
DEFAULT_IMPORT_CHALLENGES,
|
DEFAULT_IMPORT_CHALLENGES,
|
||||||
DEFAULT_EXPORT_CHALLENGES,
|
DEFAULT_EXPORT_CHALLENGES,
|
||||||
COMPLETE_WIPE
|
COMPLETE_WIPE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Constructor
|
// Section: Constructor
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* @param addon Addon where panel operates.
|
||||||
* {@inheritDoc}
|
* @param world World from which panel was created.
|
||||||
*/
|
* @param user User who created panel.
|
||||||
public AdminGUI(ChallengesAddon addon,
|
* @param topLabel Command top label which creates panel (f.e. island or ai)
|
||||||
World world,
|
* @param permissionPrefix Command permission prefix (f.e. bskyblock.)
|
||||||
User user,
|
*/
|
||||||
String topLabel,
|
public AdminGUI(ChallengesAddon addon,
|
||||||
String permissionPrefix)
|
World world,
|
||||||
{
|
User user,
|
||||||
super(addon, world, user, topLabel, permissionPrefix);
|
String topLabel,
|
||||||
}
|
String permissionPrefix)
|
||||||
|
{
|
||||||
|
super(addon, world, user, topLabel, permissionPrefix);
|
||||||
// ---------------------------------------------------------------------
|
}
|
||||||
// Section: Methods
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Methods
|
||||||
/**
|
// ---------------------------------------------------------------------
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public void build()
|
/**
|
||||||
{
|
* {@inheritDoc}
|
||||||
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
|
*/
|
||||||
this.user.getTranslation("challenges.gui.title.admin.gui-title"));
|
@Override
|
||||||
|
public void build()
|
||||||
GuiUtils.fillBorder(panelBuilder);
|
{
|
||||||
|
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
|
||||||
panelBuilder.item(10, this.createButton(Button.COMPLETE_USER_CHALLENGES));
|
this.user.getTranslation("challenges.gui.title.admin.gui-title"));
|
||||||
panelBuilder.item(19, this.createButton(Button.RESET_USER_CHALLENGES));
|
|
||||||
|
GuiUtils.fillBorder(panelBuilder);
|
||||||
// Add Challenges
|
|
||||||
panelBuilder.item(12, this.createButton(Button.ADD_CHALLENGE));
|
panelBuilder.item(10, this.createButton(Button.COMPLETE_USER_CHALLENGES));
|
||||||
panelBuilder.item(13, this.createButton(Button.ADD_LEVEL));
|
panelBuilder.item(19, this.createButton(Button.RESET_USER_CHALLENGES));
|
||||||
|
|
||||||
// Edit Challenges
|
// Add Challenges
|
||||||
panelBuilder.item(21, this.createButton(Button.EDIT_CHALLENGE));
|
panelBuilder.item(12, this.createButton(Button.ADD_CHALLENGE));
|
||||||
panelBuilder.item(22, this.createButton(Button.EDIT_LEVEL));
|
panelBuilder.item(13, this.createButton(Button.ADD_LEVEL));
|
||||||
|
|
||||||
// Remove Challenges
|
// Edit Challenges
|
||||||
panelBuilder.item(30, this.createButton(Button.DELETE_CHALLENGE));
|
panelBuilder.item(21, this.createButton(Button.EDIT_CHALLENGE));
|
||||||
panelBuilder.item(31, this.createButton(Button.DELETE_LEVEL));
|
panelBuilder.item(22, this.createButton(Button.EDIT_LEVEL));
|
||||||
|
|
||||||
|
// Remove Challenges
|
||||||
// Import Challenges
|
panelBuilder.item(30, this.createButton(Button.DELETE_CHALLENGE));
|
||||||
panelBuilder.item(15, this.createButton(Button.IMPORT_CHALLENGES));
|
panelBuilder.item(31, this.createButton(Button.DELETE_LEVEL));
|
||||||
panelBuilder.item(24, this.createButton(Button.DEFAULT_IMPORT_CHALLENGES));
|
|
||||||
// Not added as I do not think admins should use it. It still will be able via command.
|
|
||||||
// panelBuilder.item(33, this.createButton(Button.DEFAULT_EXPORT_CHALLENGES));
|
// Import Challenges
|
||||||
|
panelBuilder.item(15, this.createButton(Button.IMPORT_CHALLENGES));
|
||||||
// Edit Addon Settings
|
panelBuilder.item(24, this.createButton(Button.DEFAULT_IMPORT_CHALLENGES));
|
||||||
panelBuilder.item(16, this.createButton(Button.EDIT_SETTINGS));
|
// Not added as I do not think admins should use it. It still will be able via command.
|
||||||
|
// panelBuilder.item(33, this.createButton(Button.DEFAULT_EXPORT_CHALLENGES));
|
||||||
// Button that deletes everything from challenges addon
|
|
||||||
panelBuilder.item(34, this.createButton(Button.COMPLETE_WIPE));
|
// Edit Addon Settings
|
||||||
|
panelBuilder.item(16, this.createButton(Button.EDIT_SETTINGS));
|
||||||
panelBuilder.item(44, this.returnButton);
|
|
||||||
|
// Button that deletes everything from challenges addon
|
||||||
panelBuilder.build();
|
panelBuilder.item(34, this.createButton(Button.COMPLETE_WIPE));
|
||||||
}
|
|
||||||
|
panelBuilder.item(44, this.returnButton);
|
||||||
|
|
||||||
/**
|
panelBuilder.build();
|
||||||
* This method is used to create PanelItem for each button type.
|
}
|
||||||
* @param button Button which must be created.
|
|
||||||
* @return PanelItem with necessary functionality.
|
|
||||||
*/
|
/**
|
||||||
private PanelItem createButton(Button button)
|
* This method is used to create PanelItem for each button type.
|
||||||
{
|
* @param button Button which must be created.
|
||||||
ItemStack icon;
|
* @return PanelItem with necessary functionality.
|
||||||
String name;
|
*/
|
||||||
String description;
|
private PanelItem createButton(Button button)
|
||||||
boolean glow;
|
{
|
||||||
PanelItem.ClickHandler clickHandler;
|
ItemStack icon;
|
||||||
|
String name;
|
||||||
String permissionSuffix;
|
String description;
|
||||||
|
boolean glow;
|
||||||
switch (button)
|
PanelItem.ClickHandler clickHandler;
|
||||||
{
|
|
||||||
case COMPLETE_USER_CHALLENGES:
|
String permissionSuffix;
|
||||||
permissionSuffix = COMPLETE;
|
|
||||||
|
switch (button)
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.complete");
|
{
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.complete");
|
case COMPLETE_USER_CHALLENGES:
|
||||||
icon = new ItemStack(Material.WRITTEN_BOOK);
|
permissionSuffix = COMPLETE;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
new ListUsersGUI(this.addon,
|
name = this.user.getTranslation("challenges.gui.buttons.admin.complete");
|
||||||
this.world,
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.complete");
|
||||||
this.user,
|
icon = new ItemStack(Material.WRITTEN_BOOK);
|
||||||
ListUsersGUI.Mode.COMPLETE,
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
this.topLabel,
|
new ListUsersGUI(this.addon,
|
||||||
this.permissionPrefix,
|
this.world,
|
||||||
this).build();
|
this.user,
|
||||||
|
ListUsersGUI.Mode.COMPLETE,
|
||||||
return true;
|
this.topLabel,
|
||||||
};
|
this.permissionPrefix,
|
||||||
glow = false;
|
this).build();
|
||||||
|
|
||||||
break;
|
return true;
|
||||||
case RESET_USER_CHALLENGES:
|
};
|
||||||
permissionSuffix = RESET;
|
glow = false;
|
||||||
|
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.reset");
|
break;
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.reset");
|
case RESET_USER_CHALLENGES:
|
||||||
icon = new ItemStack(Material.WRITABLE_BOOK);
|
permissionSuffix = RESET;
|
||||||
|
|
||||||
glow = this.resetAllMode;
|
name = this.user.getTranslation("challenges.gui.buttons.admin.reset");
|
||||||
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.reset");
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
icon = new ItemStack(Material.WRITABLE_BOOK);
|
||||||
if (clickType.isRightClick())
|
|
||||||
{
|
glow = this.resetAllMode;
|
||||||
this.resetAllMode = !this.resetAllMode;
|
|
||||||
this.build();
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
}
|
if (clickType.isRightClick())
|
||||||
else
|
{
|
||||||
{
|
this.resetAllMode = !this.resetAllMode;
|
||||||
new ListUsersGUI(this.addon,
|
this.build();
|
||||||
this.world,
|
}
|
||||||
this.user,
|
else
|
||||||
this.resetAllMode ? ListUsersGUI.Mode.RESET_ALL : ListUsersGUI.Mode.RESET,
|
{
|
||||||
this.topLabel,
|
new ListUsersGUI(this.addon,
|
||||||
this.permissionPrefix,
|
this.world,
|
||||||
this).build();
|
this.user,
|
||||||
}
|
this.resetAllMode ? ListUsersGUI.Mode.RESET_ALL : ListUsersGUI.Mode.RESET,
|
||||||
|
this.topLabel,
|
||||||
return true;
|
this.permissionPrefix,
|
||||||
};
|
this).build();
|
||||||
|
}
|
||||||
break;
|
|
||||||
case ADD_CHALLENGE:
|
return true;
|
||||||
permissionSuffix = ADD;
|
};
|
||||||
|
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.create-challenge");
|
break;
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.create-challenge");
|
case ADD_CHALLENGE:
|
||||||
icon = new ItemStack(Material.BOOK);
|
permissionSuffix = ADD;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
new AnvilGUI(this.addon.getPlugin(),
|
name = this.user.getTranslation("challenges.gui.buttons.admin.create-challenge");
|
||||||
this.user.getPlayer(),
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.create-challenge");
|
||||||
"unique_id",
|
icon = new ItemStack(Material.BOOK);
|
||||||
(player, reply) -> {
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
String newName = Utils.getGameMode(this.world) + "_" + reply;
|
new AnvilGUI(this.addon.getPlugin(),
|
||||||
|
this.user.getPlayer(),
|
||||||
if (!this.addon.getChallengesManager().containsChallenge(newName))
|
"unique_id",
|
||||||
{
|
(player, reply) -> {
|
||||||
new EditChallengeGUI(this.addon,
|
String newName = Utils.getGameMode(this.world) + "_" + reply;
|
||||||
this.world,
|
|
||||||
this.user,
|
if (!this.addon.getChallengesManager().containsChallenge(newName))
|
||||||
this.addon.getChallengesManager().createChallenge(newName),
|
{
|
||||||
this.topLabel,
|
new EditChallengeGUI(this.addon,
|
||||||
this.permissionPrefix,
|
this.world,
|
||||||
this).build();
|
this.user,
|
||||||
}
|
this.addon.getChallengesManager().createChallenge(newName),
|
||||||
else
|
this.topLabel,
|
||||||
{
|
this.permissionPrefix,
|
||||||
this.user.sendMessage("challenges.errors.unique-id", "[id]", reply);
|
this).build();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return reply;
|
{
|
||||||
});
|
this.user.sendMessage("challenges.errors.unique-id", "[id]", reply);
|
||||||
|
}
|
||||||
return true;
|
|
||||||
};
|
return reply;
|
||||||
glow = false;
|
});
|
||||||
|
|
||||||
break;
|
return true;
|
||||||
case ADD_LEVEL:
|
};
|
||||||
permissionSuffix = ADD;
|
glow = false;
|
||||||
|
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.create-level");
|
break;
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.create-level");
|
case ADD_LEVEL:
|
||||||
icon = new ItemStack(Material.BOOK);
|
permissionSuffix = ADD;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
new AnvilGUI(this.addon.getPlugin(),
|
name = this.user.getTranslation("challenges.gui.buttons.admin.create-level");
|
||||||
this.user.getPlayer(),
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.create-level");
|
||||||
"unique_id",
|
icon = new ItemStack(Material.BOOK);
|
||||||
(player, reply) -> {
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
String newName = Utils.getGameMode(this.world) + "_" + reply;
|
new AnvilGUI(this.addon.getPlugin(),
|
||||||
|
this.user.getPlayer(),
|
||||||
if (!this.addon.getChallengesManager().containsLevel(newName))
|
"unique_id",
|
||||||
{
|
(player, reply) -> {
|
||||||
new EditLevelGUI(this.addon,
|
String newName = Utils.getGameMode(this.world) + "_" + reply;
|
||||||
this.world,
|
|
||||||
this.user,
|
if (!this.addon.getChallengesManager().containsLevel(newName))
|
||||||
this.addon.getChallengesManager().createLevel(newName, this.world),
|
{
|
||||||
this.topLabel,
|
new EditLevelGUI(this.addon,
|
||||||
this.permissionPrefix,
|
this.world,
|
||||||
this).build();
|
this.user,
|
||||||
}
|
this.addon.getChallengesManager().createLevel(newName, this.world),
|
||||||
else
|
this.topLabel,
|
||||||
{
|
this.permissionPrefix,
|
||||||
this.user.sendMessage("challenges.errors.unique-id", "[id]", reply);
|
this).build();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return reply;
|
{
|
||||||
});
|
this.user.sendMessage("challenges.errors.unique-id", "[id]", reply);
|
||||||
|
}
|
||||||
return true;
|
|
||||||
};
|
return reply;
|
||||||
glow = false;
|
});
|
||||||
|
|
||||||
break;
|
return true;
|
||||||
case EDIT_CHALLENGE:
|
};
|
||||||
permissionSuffix = EDIT;
|
glow = false;
|
||||||
|
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.edit-challenge");
|
break;
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.edit-challenge");
|
case EDIT_CHALLENGE:
|
||||||
icon = new ItemStack(Material.ANVIL);
|
permissionSuffix = EDIT;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
new ListChallengesGUI(this.addon,
|
name = this.user.getTranslation("challenges.gui.buttons.admin.edit-challenge");
|
||||||
this.world,
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.edit-challenge");
|
||||||
this.user,
|
icon = new ItemStack(Material.ANVIL);
|
||||||
ListChallengesGUI.Mode.EDIT,
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
this.topLabel,
|
new ListChallengesGUI(this.addon,
|
||||||
this.permissionPrefix,
|
this.world,
|
||||||
this).build();
|
this.user,
|
||||||
|
ListChallengesGUI.Mode.EDIT,
|
||||||
return true;
|
this.topLabel,
|
||||||
};
|
this.permissionPrefix,
|
||||||
glow = false;
|
this).build();
|
||||||
|
|
||||||
break;
|
return true;
|
||||||
case EDIT_LEVEL:
|
};
|
||||||
{
|
glow = false;
|
||||||
permissionSuffix = EDIT;
|
|
||||||
|
break;
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.edit-level");
|
case EDIT_LEVEL:
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.edit-level");
|
{
|
||||||
icon = new ItemStack(Material.ANVIL);
|
permissionSuffix = EDIT;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
new ListLevelsGUI(this.addon,
|
name = this.user.getTranslation("challenges.gui.buttons.admin.edit-level");
|
||||||
this.world,
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.edit-level");
|
||||||
this.user,
|
icon = new ItemStack(Material.ANVIL);
|
||||||
ListLevelsGUI.Mode.EDIT,
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
this.topLabel,
|
new ListLevelsGUI(this.addon,
|
||||||
this.permissionPrefix,
|
this.world,
|
||||||
this).build();
|
this.user,
|
||||||
|
ListLevelsGUI.Mode.EDIT,
|
||||||
return true;
|
this.topLabel,
|
||||||
};
|
this.permissionPrefix,
|
||||||
glow = false;
|
this).build();
|
||||||
|
|
||||||
break;
|
return true;
|
||||||
}
|
};
|
||||||
case DELETE_CHALLENGE:
|
glow = false;
|
||||||
{
|
|
||||||
permissionSuffix = DELETE;
|
break;
|
||||||
|
}
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.delete-challenge");
|
case DELETE_CHALLENGE:
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.delete-challenge");
|
{
|
||||||
icon = new ItemStack(Material.LAVA_BUCKET);
|
permissionSuffix = DELETE;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
new ListChallengesGUI(this.addon,
|
name = this.user.getTranslation("challenges.gui.buttons.admin.delete-challenge");
|
||||||
this.world,
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.delete-challenge");
|
||||||
this.user,
|
icon = new ItemStack(Material.LAVA_BUCKET);
|
||||||
ListChallengesGUI.Mode.DELETE,
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
this.topLabel,
|
new ListChallengesGUI(this.addon,
|
||||||
this.permissionPrefix,
|
this.world,
|
||||||
this).build();
|
this.user,
|
||||||
|
ListChallengesGUI.Mode.DELETE,
|
||||||
return true;
|
this.topLabel,
|
||||||
};
|
this.permissionPrefix,
|
||||||
glow = false;
|
this).build();
|
||||||
|
|
||||||
break;
|
return true;
|
||||||
}
|
};
|
||||||
case DELETE_LEVEL:
|
glow = false;
|
||||||
{
|
|
||||||
permissionSuffix = DELETE;
|
break;
|
||||||
|
}
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.delete-level");
|
case DELETE_LEVEL:
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.delete-level");
|
{
|
||||||
icon = new ItemStack(Material.LAVA_BUCKET);
|
permissionSuffix = DELETE;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
new ListLevelsGUI(this.addon,
|
name = this.user.getTranslation("challenges.gui.buttons.admin.delete-level");
|
||||||
this.world,
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.delete-level");
|
||||||
this.user,
|
icon = new ItemStack(Material.LAVA_BUCKET);
|
||||||
ListLevelsGUI.Mode.DELETE,
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
this.topLabel,
|
new ListLevelsGUI(this.addon,
|
||||||
this.permissionPrefix,
|
this.world,
|
||||||
this).build();
|
this.user,
|
||||||
|
ListLevelsGUI.Mode.DELETE,
|
||||||
return true;
|
this.topLabel,
|
||||||
};
|
this.permissionPrefix,
|
||||||
glow = false;
|
this).build();
|
||||||
|
|
||||||
break;
|
return true;
|
||||||
}
|
};
|
||||||
case IMPORT_CHALLENGES:
|
glow = false;
|
||||||
{
|
|
||||||
permissionSuffix = IMPORT;
|
break;
|
||||||
|
}
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.import");
|
case IMPORT_CHALLENGES:
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.import");
|
{
|
||||||
icon = new ItemStack(Material.HOPPER);
|
permissionSuffix = IMPORT;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
if (clickType.isRightClick())
|
name = this.user.getTranslation("challenges.gui.buttons.admin.import");
|
||||||
{
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.import");
|
||||||
this.overwriteMode = !this.overwriteMode;
|
icon = new ItemStack(Material.HOPPER);
|
||||||
this.build();
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
}
|
if (clickType.isRightClick())
|
||||||
else
|
{
|
||||||
{
|
this.overwriteMode = !this.overwriteMode;
|
||||||
// Run import command.
|
this.build();
|
||||||
this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + IMPORT +
|
}
|
||||||
(this.overwriteMode ? " overwrite" : ""));
|
else
|
||||||
}
|
{
|
||||||
return true;
|
// Run import command.
|
||||||
};
|
this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + IMPORT +
|
||||||
glow = this.overwriteMode;
|
(this.overwriteMode ? " overwrite" : ""));
|
||||||
|
}
|
||||||
break;
|
return true;
|
||||||
}
|
};
|
||||||
case DEFAULT_IMPORT_CHALLENGES:
|
glow = this.overwriteMode;
|
||||||
{
|
|
||||||
permissionSuffix = DEFAULT;
|
break;
|
||||||
|
}
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.default-import");
|
case DEFAULT_IMPORT_CHALLENGES:
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.default-import");
|
{
|
||||||
icon = new ItemStack(Material.HOPPER);
|
permissionSuffix = DEFAULT;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
// Run import command.
|
name = this.user.getTranslation("challenges.gui.buttons.admin.default-import");
|
||||||
this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + DEFAULT + " " + IMPORT);
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.default-import");
|
||||||
|
icon = new ItemStack(Material.HOPPER);
|
||||||
return true;
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
};
|
// Run import command.
|
||||||
glow = false;
|
this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + DEFAULT + " " + IMPORT);
|
||||||
|
|
||||||
break;
|
return true;
|
||||||
}
|
};
|
||||||
case DEFAULT_EXPORT_CHALLENGES:
|
glow = false;
|
||||||
{
|
|
||||||
permissionSuffix = DEFAULT;
|
break;
|
||||||
|
}
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.default-export");
|
case DEFAULT_EXPORT_CHALLENGES:
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.default-export");
|
{
|
||||||
icon = new ItemStack(Material.HOPPER);
|
permissionSuffix = DEFAULT;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
if (clickType.isRightClick())
|
name = this.user.getTranslation("challenges.gui.buttons.admin.default-export");
|
||||||
{
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.default-export");
|
||||||
this.overwriteMode = !this.overwriteMode;
|
icon = new ItemStack(Material.HOPPER);
|
||||||
this.build();
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
}
|
if (clickType.isRightClick())
|
||||||
else
|
{
|
||||||
{
|
this.overwriteMode = !this.overwriteMode;
|
||||||
// Run import command.
|
this.build();
|
||||||
this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + DEFAULT + " " + GENERATE +
|
}
|
||||||
(this.overwriteMode ? " overwrite" : ""));
|
else
|
||||||
}
|
{
|
||||||
return true;
|
// Run import command.
|
||||||
};
|
this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + DEFAULT + " " + GENERATE +
|
||||||
glow = this.overwriteMode;
|
(this.overwriteMode ? " overwrite" : ""));
|
||||||
|
}
|
||||||
break;
|
return true;
|
||||||
}
|
};
|
||||||
case EDIT_SETTINGS:
|
glow = this.overwriteMode;
|
||||||
{
|
|
||||||
permissionSuffix = SETTINGS;
|
break;
|
||||||
|
}
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.settings");
|
case EDIT_SETTINGS:
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.settings");
|
{
|
||||||
icon = new ItemStack(Material.CRAFTING_TABLE);
|
permissionSuffix = SETTINGS;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
new EditSettingsGUI(this.addon,
|
name = this.user.getTranslation("challenges.gui.buttons.admin.settings");
|
||||||
this.world,
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.settings");
|
||||||
this.user,
|
icon = new ItemStack(Material.CRAFTING_TABLE);
|
||||||
this.topLabel,
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
this.permissionPrefix,
|
new EditSettingsGUI(this.addon,
|
||||||
this).build();
|
this.world,
|
||||||
|
this.user,
|
||||||
return true;
|
this.topLabel,
|
||||||
};
|
this.permissionPrefix,
|
||||||
glow = false;
|
this).build();
|
||||||
|
|
||||||
break;
|
return true;
|
||||||
}
|
};
|
||||||
case COMPLETE_WIPE:
|
glow = false;
|
||||||
{
|
|
||||||
permissionSuffix = WIPE;
|
break;
|
||||||
|
}
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.complete-wipe");
|
case COMPLETE_WIPE:
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.complete-wipe");
|
{
|
||||||
icon = new ItemStack(Material.TNT);
|
permissionSuffix = WIPE;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
new ConfirmationGUI(this.user, value -> {
|
name = this.user.getTranslation("challenges.gui.buttons.admin.complete-wipe");
|
||||||
if (value)
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.complete-wipe");
|
||||||
{
|
icon = new ItemStack(Material.TNT);
|
||||||
this.addon.getChallengesManager().wipeDatabase();
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
this.user.sendMessage("challenges.messages.admin.complete-wipe");
|
new ConfirmationGUI(this.user, value -> {
|
||||||
}
|
if (value)
|
||||||
|
{
|
||||||
this.build();
|
this.addon.getChallengesManager().wipeDatabase();
|
||||||
});
|
this.user.sendMessage("challenges.messages.admin.complete-wipe");
|
||||||
|
}
|
||||||
return true;
|
|
||||||
};
|
this.build();
|
||||||
glow = false;
|
});
|
||||||
|
|
||||||
break;
|
return true;
|
||||||
}
|
};
|
||||||
default:
|
glow = false;
|
||||||
// This should never happen.
|
|
||||||
return null;
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
// If user does not have permission to run command, then change icon and clickHandler.
|
// This should never happen.
|
||||||
final String actionPermission = this.permissionPrefix + ADMIN + "." + CHALLENGES + "." + permissionSuffix;
|
return null;
|
||||||
|
}
|
||||||
if (!this.user.hasPermission(actionPermission))
|
|
||||||
{
|
// If user does not have permission to run command, then change icon and clickHandler.
|
||||||
icon = new ItemStack(Material.BARRIER);
|
final String actionPermission = this.permissionPrefix + ADMIN + "." + CHALLENGES + "." + permissionSuffix;
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
this.user.sendMessage("general.errors.no-permission", "[permission]", actionPermission);
|
if (!this.user.hasPermission(actionPermission))
|
||||||
return true;
|
{
|
||||||
};
|
icon = new ItemStack(Material.BARRIER);
|
||||||
}
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
|
this.user.sendMessage("general.errors.no-permission", "[permission]", actionPermission);
|
||||||
return new PanelItemBuilder().
|
return true;
|
||||||
icon(icon).
|
};
|
||||||
name(name).
|
}
|
||||||
description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())).
|
|
||||||
glow(glow).
|
return new PanelItemBuilder().
|
||||||
clickHandler(clickHandler).
|
icon(icon).
|
||||||
build();
|
name(name).
|
||||||
}
|
description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())).
|
||||||
|
glow(glow).
|
||||||
|
clickHandler(clickHandler).
|
||||||
|
build();
|
||||||
|
}
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -23,176 +23,184 @@ import world.bentobox.challenges.utils.GuiUtils;
|
|||||||
*/
|
*/
|
||||||
public class ListChallengesGUI extends CommonGUI
|
public class ListChallengesGUI extends CommonGUI
|
||||||
{
|
{
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Constructor
|
// Section: Constructor
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* @param addon Addon where panel operates.
|
||||||
* @param mode - mode that indicate what should do icon clicking.
|
* @param world World from which panel was created.
|
||||||
*/
|
* @param user User who created panel.
|
||||||
public ListChallengesGUI(ChallengesAddon addon,
|
* @param topLabel Command top label which creates panel (f.e. island or ai)
|
||||||
World world,
|
* @param permissionPrefix Command permission prefix (f.e. bskyblock.)
|
||||||
User user,
|
* @param mode - mode that indicate what should do icon clicking.
|
||||||
Mode mode,
|
*/
|
||||||
String topLabel,
|
public ListChallengesGUI(ChallengesAddon addon,
|
||||||
String permissionPrefix)
|
World world,
|
||||||
{
|
User user,
|
||||||
this(addon, world, user, mode, topLabel, permissionPrefix, null);
|
Mode mode,
|
||||||
}
|
String topLabel,
|
||||||
|
String permissionPrefix)
|
||||||
|
{
|
||||||
|
this(addon, world, user, mode, topLabel, permissionPrefix, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* @param addon Addon where panel operates.
|
||||||
* @param mode - mode that indicate what should do icon clicking.
|
* @param world World from which panel was created.
|
||||||
*/
|
* @param user User who created panel.
|
||||||
public ListChallengesGUI(ChallengesAddon addon,
|
* @param topLabel Command top label which creates panel (f.e. island or ai)
|
||||||
World world,
|
* @param permissionPrefix Command permission prefix (f.e. bskyblock.)
|
||||||
User user,
|
* @param mode - mode that indicate what should do icon clicking.
|
||||||
Mode mode,
|
*/
|
||||||
String topLabel,
|
public ListChallengesGUI(ChallengesAddon addon,
|
||||||
String permissionPrefix,
|
World world,
|
||||||
CommonGUI parentGUI)
|
User user,
|
||||||
{
|
Mode mode,
|
||||||
super(addon, world, user, topLabel, permissionPrefix, parentGUI);
|
String topLabel,
|
||||||
this.currentMode = mode;
|
String permissionPrefix,
|
||||||
}
|
CommonGUI parentGUI)
|
||||||
|
{
|
||||||
|
super(addon, world, user, topLabel, permissionPrefix, parentGUI);
|
||||||
|
this.currentMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Methods
|
// Section: Methods
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void build()
|
public void build()
|
||||||
{
|
{
|
||||||
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
|
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
|
||||||
this.user.getTranslation("challenges.gui.title.admin.choose-challenge-title"));
|
this.user.getTranslation("challenges.gui.title.admin.choose-challenge-title"));
|
||||||
|
|
||||||
if (this.currentMode.equals(Mode.DELETE))
|
if (this.currentMode.equals(Mode.DELETE))
|
||||||
{
|
{
|
||||||
GuiUtils.fillBorder(panelBuilder, Material.RED_STAINED_GLASS_PANE);
|
GuiUtils.fillBorder(panelBuilder, Material.RED_STAINED_GLASS_PANE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GuiUtils.fillBorder(panelBuilder);
|
GuiUtils.fillBorder(panelBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Challenge> challengeList = this.addon.getChallengesManager().getAllChallenges(this.world);
|
List<Challenge> challengeList = this.addon.getChallengesManager().getAllChallenges(this.world);
|
||||||
|
|
||||||
final int MAX_ELEMENTS = 21;
|
final int MAX_ELEMENTS = 21;
|
||||||
|
|
||||||
if (this.pageIndex < 0)
|
if (this.pageIndex < 0)
|
||||||
{
|
{
|
||||||
this.pageIndex = challengeList.size() / MAX_ELEMENTS;
|
this.pageIndex = challengeList.size() / MAX_ELEMENTS;
|
||||||
}
|
}
|
||||||
else if (this.pageIndex > (challengeList.size() / MAX_ELEMENTS))
|
else if (this.pageIndex > (challengeList.size() / MAX_ELEMENTS))
|
||||||
{
|
{
|
||||||
this.pageIndex = 0;
|
this.pageIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int challengeIndex = MAX_ELEMENTS * this.pageIndex;
|
int challengeIndex = MAX_ELEMENTS * this.pageIndex;
|
||||||
|
|
||||||
// I want first row to be only for navigation and return button.
|
// I want first row to be only for navigation and return button.
|
||||||
int index = 10;
|
int index = 10;
|
||||||
|
|
||||||
while (challengeIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) &&
|
while (challengeIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) &&
|
||||||
challengeIndex < challengeList.size() &&
|
challengeIndex < challengeList.size() &&
|
||||||
index < 36)
|
index < 36)
|
||||||
{
|
{
|
||||||
if (!panelBuilder.slotOccupied(index))
|
if (!panelBuilder.slotOccupied(index))
|
||||||
{
|
{
|
||||||
panelBuilder.item(index, this.createChallengeIcon(challengeList.get(challengeIndex++)));
|
panelBuilder.item(index, this.createChallengeIcon(challengeList.get(challengeIndex++)));
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Navigation buttons only if necessary
|
// Navigation buttons only if necessary
|
||||||
if (challengeList.size() > MAX_ELEMENTS)
|
if (challengeList.size() > MAX_ELEMENTS)
|
||||||
{
|
{
|
||||||
panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS));
|
panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS));
|
||||||
panelBuilder.item(26, this.getButton(CommonButtons.NEXT));
|
panelBuilder.item(26, this.getButton(CommonButtons.NEXT));
|
||||||
}
|
}
|
||||||
|
|
||||||
panelBuilder.item(44, this.returnButton);
|
panelBuilder.item(44, this.returnButton);
|
||||||
|
|
||||||
panelBuilder.build();
|
panelBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates button for given challenge.
|
* This method creates button for given challenge.
|
||||||
* @param challenge Challenge which button must be created.
|
* @param challenge Challenge which button must be created.
|
||||||
* @return Challenge button.
|
* @return Challenge button.
|
||||||
*/
|
*/
|
||||||
private PanelItem createChallengeIcon(Challenge challenge)
|
private PanelItem createChallengeIcon(Challenge challenge)
|
||||||
{
|
{
|
||||||
PanelItemBuilder itemBuilder = new PanelItemBuilder().
|
PanelItemBuilder itemBuilder = new PanelItemBuilder().
|
||||||
name(ChatColor.translateAlternateColorCodes('&', challenge.getFriendlyName())).
|
name(ChatColor.translateAlternateColorCodes('&', challenge.getFriendlyName())).
|
||||||
description(GuiUtils.stringSplit(this.generateChallengeDescription(challenge, this.user.getPlayer()),
|
description(GuiUtils.stringSplit(this.generateChallengeDescription(challenge, this.user.getPlayer()),
|
||||||
this.addon.getChallengesSettings().getLoreLineLength())).
|
this.addon.getChallengesSettings().getLoreLineLength())).
|
||||||
icon(challenge.getIcon()).
|
icon(challenge.getIcon()).
|
||||||
glow(challenge.isDeployed());
|
glow(challenge.isDeployed());
|
||||||
|
|
||||||
if (this.currentMode.equals(Mode.EDIT))
|
if (this.currentMode.equals(Mode.EDIT))
|
||||||
{
|
{
|
||||||
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
|
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
|
||||||
new EditChallengeGUI(this.addon,
|
new EditChallengeGUI(this.addon,
|
||||||
this.world,
|
this.world,
|
||||||
this.user,
|
this.user,
|
||||||
challenge,
|
challenge,
|
||||||
this.topLabel,
|
this.topLabel,
|
||||||
this.permissionPrefix,
|
this.permissionPrefix,
|
||||||
this).build();
|
this).build();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (this.currentMode.equals(Mode.DELETE))
|
else if (this.currentMode.equals(Mode.DELETE))
|
||||||
{
|
{
|
||||||
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
|
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
|
||||||
new ConfirmationGUI(this.user, value -> {
|
new ConfirmationGUI(this.user, value -> {
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
this.addon.getChallengesManager().deleteChallenge(challenge);
|
this.addon.getChallengesManager().deleteChallenge(challenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.build();
|
this.build();
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemBuilder.build();
|
return itemBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Enums
|
// Section: Enums
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mode in which gui icons should processed.
|
* Mode in which gui icons should processed.
|
||||||
*/
|
*/
|
||||||
public enum Mode
|
public enum Mode
|
||||||
{
|
{
|
||||||
EDIT,
|
EDIT,
|
||||||
DELETE
|
DELETE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current mode in which icons will act.
|
* Current mode in which icons will act.
|
||||||
*/
|
*/
|
||||||
private Mode currentMode;
|
private Mode currentMode;
|
||||||
}
|
}
|
||||||
|
@ -23,178 +23,186 @@ import world.bentobox.challenges.utils.GuiUtils;
|
|||||||
*/
|
*/
|
||||||
public class ListLevelsGUI extends CommonGUI
|
public class ListLevelsGUI extends CommonGUI
|
||||||
{
|
{
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Constructor
|
// Section: Constructor
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* @param addon Addon where panel operates.
|
||||||
* @param mode - mode that indicate what should do icon clicking.
|
* @param world World from which panel was created.
|
||||||
*/
|
* @param user User who created panel.
|
||||||
public ListLevelsGUI(ChallengesAddon addon,
|
* @param topLabel Command top label which creates panel (f.e. island or ai)
|
||||||
World world,
|
* @param permissionPrefix Command permission prefix (f.e. bskyblock.)
|
||||||
User user,
|
* @param mode - mode that indicate what should do icon clicking.
|
||||||
Mode mode,
|
*/
|
||||||
String topLabel,
|
public ListLevelsGUI(ChallengesAddon addon,
|
||||||
String permissionPrefix)
|
World world,
|
||||||
{
|
User user,
|
||||||
this(addon, world, user, mode, topLabel, permissionPrefix, null);
|
Mode mode,
|
||||||
}
|
String topLabel,
|
||||||
|
String permissionPrefix)
|
||||||
|
{
|
||||||
|
this(addon, world, user, mode, topLabel, permissionPrefix, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* @param addon Addon where panel operates.
|
||||||
* @param mode - mode that indicate what should do icon clicking.
|
* @param world World from which panel was created.
|
||||||
*/
|
* @param user User who created panel.
|
||||||
public ListLevelsGUI(ChallengesAddon addon,
|
* @param topLabel Command top label which creates panel (f.e. island or ai)
|
||||||
World world,
|
* @param permissionPrefix Command permission prefix (f.e. bskyblock.)
|
||||||
User user,
|
* @param mode - mode that indicate what should do icon clicking.
|
||||||
Mode mode,
|
*/
|
||||||
String topLabel,
|
public ListLevelsGUI(ChallengesAddon addon,
|
||||||
String permissionPrefix,
|
World world,
|
||||||
CommonGUI parentGUI)
|
User user,
|
||||||
{
|
Mode mode,
|
||||||
super(addon, world, user, topLabel, permissionPrefix, parentGUI);
|
String topLabel,
|
||||||
this.currentMode = mode;
|
String permissionPrefix,
|
||||||
}
|
CommonGUI parentGUI)
|
||||||
|
{
|
||||||
|
super(addon, world, user, topLabel, permissionPrefix, parentGUI);
|
||||||
|
this.currentMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Methods
|
// Section: Methods
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void build()
|
public void build()
|
||||||
{
|
{
|
||||||
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
|
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
|
||||||
this.user.getTranslation("challenges.gui.title.admin.choose-level-title"));
|
this.user.getTranslation("challenges.gui.title.admin.choose-level-title"));
|
||||||
|
|
||||||
if (this.currentMode.equals(Mode.DELETE))
|
if (this.currentMode.equals(Mode.DELETE))
|
||||||
{
|
{
|
||||||
GuiUtils.fillBorder(panelBuilder, Material.RED_STAINED_GLASS_PANE);
|
GuiUtils.fillBorder(panelBuilder, Material.RED_STAINED_GLASS_PANE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GuiUtils.fillBorder(panelBuilder);
|
GuiUtils.fillBorder(panelBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ChallengeLevel> levelList = this.addon.getChallengesManager().getLevels(this.world);
|
List<ChallengeLevel> levelList = this.addon.getChallengesManager().getLevels(this.world);
|
||||||
|
|
||||||
final int MAX_ELEMENTS = 21;
|
final int MAX_ELEMENTS = 21;
|
||||||
|
|
||||||
if (this.pageIndex < 0)
|
if (this.pageIndex < 0)
|
||||||
{
|
{
|
||||||
this.pageIndex = levelList.size() / MAX_ELEMENTS;
|
this.pageIndex = levelList.size() / MAX_ELEMENTS;
|
||||||
}
|
}
|
||||||
else if (this.pageIndex > (levelList.size() / MAX_ELEMENTS))
|
else if (this.pageIndex > (levelList.size() / MAX_ELEMENTS))
|
||||||
{
|
{
|
||||||
this.pageIndex = 0;
|
this.pageIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int levelIndex = MAX_ELEMENTS * this.pageIndex;
|
int levelIndex = MAX_ELEMENTS * this.pageIndex;
|
||||||
|
|
||||||
// I want first row to be only for navigation and return button.
|
// I want first row to be only for navigation and return button.
|
||||||
int index = 10;
|
int index = 10;
|
||||||
|
|
||||||
while (levelIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) &&
|
while (levelIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) &&
|
||||||
levelIndex < levelList.size() &&
|
levelIndex < levelList.size() &&
|
||||||
index < 36)
|
index < 36)
|
||||||
{
|
{
|
||||||
if (!panelBuilder.slotOccupied(index))
|
if (!panelBuilder.slotOccupied(index))
|
||||||
{
|
{
|
||||||
panelBuilder.item(index, this.createLevelIcon(levelList.get(levelIndex++)));
|
panelBuilder.item(index, this.createLevelIcon(levelList.get(levelIndex++)));
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Navigation buttons only if necessary
|
// Navigation buttons only if necessary
|
||||||
if (levelList.size() > MAX_ELEMENTS)
|
if (levelList.size() > MAX_ELEMENTS)
|
||||||
{
|
{
|
||||||
panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS));
|
panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS));
|
||||||
panelBuilder.item(26, this.getButton(CommonButtons.NEXT));
|
panelBuilder.item(26, this.getButton(CommonButtons.NEXT));
|
||||||
}
|
}
|
||||||
|
|
||||||
panelBuilder.item(44, this.returnButton);
|
panelBuilder.item(44, this.returnButton);
|
||||||
|
|
||||||
panelBuilder.build();
|
panelBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates button for given level
|
* This method creates button for given level
|
||||||
* @param challengeLevel Level which button must be created.
|
* @param challengeLevel Level which button must be created.
|
||||||
* @return Level button.
|
* @return Level button.
|
||||||
*/
|
*/
|
||||||
private PanelItem createLevelIcon(ChallengeLevel challengeLevel)
|
private PanelItem createLevelIcon(ChallengeLevel challengeLevel)
|
||||||
{
|
{
|
||||||
PanelItemBuilder itemBuilder = new PanelItemBuilder().
|
PanelItemBuilder itemBuilder = new PanelItemBuilder().
|
||||||
name(ChatColor.translateAlternateColorCodes('&', challengeLevel.getFriendlyName())).
|
name(ChatColor.translateAlternateColorCodes('&', challengeLevel.getFriendlyName())).
|
||||||
description(GuiUtils.stringSplit(
|
description(GuiUtils.stringSplit(
|
||||||
this.generateLevelDescription(challengeLevel, this.user.getPlayer()),
|
this.generateLevelDescription(challengeLevel, this.user.getPlayer()),
|
||||||
this.addon.getChallengesSettings().getLoreLineLength())).
|
this.addon.getChallengesSettings().getLoreLineLength())).
|
||||||
icon(challengeLevel.getIcon()).
|
icon(challengeLevel.getIcon()).
|
||||||
glow(false);
|
glow(false);
|
||||||
|
|
||||||
if (this.currentMode.equals(Mode.EDIT))
|
if (this.currentMode.equals(Mode.EDIT))
|
||||||
{
|
{
|
||||||
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
|
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
|
||||||
new EditLevelGUI(this.addon,
|
new EditLevelGUI(this.addon,
|
||||||
this.world,
|
this.world,
|
||||||
this.user,
|
this.user,
|
||||||
challengeLevel,
|
challengeLevel,
|
||||||
this.topLabel,
|
this.topLabel,
|
||||||
this.permissionPrefix,
|
this.permissionPrefix,
|
||||||
this).build();
|
this).build();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (this.currentMode.equals(Mode.DELETE))
|
else if (this.currentMode.equals(Mode.DELETE))
|
||||||
{
|
{
|
||||||
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
|
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
|
||||||
new ConfirmationGUI(this.user, value -> {
|
new ConfirmationGUI(this.user, value -> {
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
this.addon.getChallengesManager().
|
this.addon.getChallengesManager().
|
||||||
deleteChallengeLevel(challengeLevel);
|
deleteChallengeLevel(challengeLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.build();
|
this.build();
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemBuilder.build();
|
return itemBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Enums
|
// Section: Enums
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mode in which gui icons should processed.
|
* Mode in which gui icons should processed.
|
||||||
*/
|
*/
|
||||||
public enum Mode
|
public enum Mode
|
||||||
{
|
{
|
||||||
EDIT,
|
EDIT,
|
||||||
DELETE
|
DELETE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current mode in which icons will act.
|
* Current mode in which icons will act.
|
||||||
*/
|
*/
|
||||||
private Mode currentMode;
|
private Mode currentMode;
|
||||||
}
|
}
|
||||||
|
@ -30,296 +30,304 @@ import world.bentobox.challenges.utils.GuiUtils;
|
|||||||
*/
|
*/
|
||||||
public class ListUsersGUI extends CommonGUI
|
public class ListUsersGUI extends CommonGUI
|
||||||
{
|
{
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List with players that should be in GUI.
|
* List with players that should be in GUI.
|
||||||
*/
|
*/
|
||||||
private List<Player> onlineUsers;
|
private List<Player> onlineUsers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current operation mode.
|
* Current operation mode.
|
||||||
*/
|
*/
|
||||||
private Mode operationMode;
|
private Mode operationMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current index of view mode
|
* Current index of view mode
|
||||||
*/
|
*/
|
||||||
private int modeIndex = 2;
|
private int modeIndex = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This allows to switch which users should be in the list.
|
* This allows to switch which users should be in the list.
|
||||||
*/
|
*/
|
||||||
private enum ViewMode
|
private enum ViewMode
|
||||||
{
|
{
|
||||||
ONLINE,
|
ONLINE,
|
||||||
WITH_ISLAND,
|
WITH_ISLAND,
|
||||||
IN_WORLD
|
IN_WORLD
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This allows to decide what User Icon should do.
|
* This allows to decide what User Icon should do.
|
||||||
*/
|
*/
|
||||||
public enum Mode
|
public enum Mode
|
||||||
{
|
{
|
||||||
COMPLETE,
|
COMPLETE,
|
||||||
RESET,
|
RESET,
|
||||||
RESET_ALL
|
RESET_ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Constructors
|
// Section: Constructors
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* @param addon Addon where panel operates.
|
||||||
* @param operationMode Indicate what should happen on player icon click.
|
* @param world World from which panel was created.
|
||||||
*/
|
* @param user User who created panel.
|
||||||
public ListUsersGUI(ChallengesAddon addon,
|
* @param topLabel Command top label which creates panel (f.e. island or ai)
|
||||||
World world,
|
* @param permissionPrefix Command permission prefix (f.e. bskyblock.)
|
||||||
User user,
|
* @param operationMode Indicate what should happen on player icon click.
|
||||||
Mode operationMode,
|
*/
|
||||||
String topLabel,
|
public ListUsersGUI(ChallengesAddon addon,
|
||||||
String permissionPrefix)
|
World world,
|
||||||
{
|
User user,
|
||||||
this(addon, world, user, operationMode, topLabel, permissionPrefix, null);
|
Mode operationMode,
|
||||||
}
|
String topLabel,
|
||||||
|
String permissionPrefix)
|
||||||
|
{
|
||||||
|
this(addon, world, user, operationMode, topLabel, permissionPrefix, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* @param addon Addon where panel operates.
|
||||||
* @param operationMode Indicate what should happen on player icon click.
|
* @param world World from which panel was created.
|
||||||
*/
|
* @param user User who created panel.
|
||||||
public ListUsersGUI(ChallengesAddon addon,
|
* @param topLabel Command top label which creates panel (f.e. island or ai)
|
||||||
World world,
|
* @param permissionPrefix Command permission prefix (f.e. bskyblock.)
|
||||||
User user,
|
* @param operationMode Indicate what should happen on player icon click.
|
||||||
Mode operationMode,
|
*/
|
||||||
String topLabel,
|
public ListUsersGUI(ChallengesAddon addon,
|
||||||
String permissionPrefix,
|
World world,
|
||||||
CommonGUI parentPanel)
|
User user,
|
||||||
{
|
Mode operationMode,
|
||||||
super(addon, world, user, topLabel, permissionPrefix, parentPanel);
|
String topLabel,
|
||||||
this.onlineUsers = this.collectUsers(ViewMode.IN_WORLD);
|
String permissionPrefix,
|
||||||
this.operationMode = operationMode;
|
CommonGUI parentPanel)
|
||||||
}
|
{
|
||||||
|
super(addon, world, user, topLabel, permissionPrefix, parentPanel);
|
||||||
|
this.onlineUsers = this.collectUsers(ViewMode.IN_WORLD);
|
||||||
|
this.operationMode = operationMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Methods
|
// Section: Methods
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build()
|
public void build()
|
||||||
{
|
{
|
||||||
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
|
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
|
||||||
this.user.getTranslation("challenges.gui.title.admin.choose-user-title"));
|
this.user.getTranslation("challenges.gui.title.admin.choose-user-title"));
|
||||||
|
|
||||||
GuiUtils.fillBorder(panelBuilder);
|
GuiUtils.fillBorder(panelBuilder);
|
||||||
|
|
||||||
final int MAX_ELEMENTS = 21;
|
final int MAX_ELEMENTS = 21;
|
||||||
|
|
||||||
if (this.pageIndex < 0)
|
if (this.pageIndex < 0)
|
||||||
{
|
{
|
||||||
this.pageIndex = this.onlineUsers.size() / MAX_ELEMENTS;
|
this.pageIndex = this.onlineUsers.size() / MAX_ELEMENTS;
|
||||||
}
|
}
|
||||||
else if (this.pageIndex > (this.onlineUsers.size() / MAX_ELEMENTS))
|
else if (this.pageIndex > (this.onlineUsers.size() / MAX_ELEMENTS))
|
||||||
{
|
{
|
||||||
this.pageIndex = 0;
|
this.pageIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int playerIndex = MAX_ELEMENTS * this.pageIndex;
|
int playerIndex = MAX_ELEMENTS * this.pageIndex;
|
||||||
|
|
||||||
// I want first row to be only for navigation and return button.
|
// I want first row to be only for navigation and return button.
|
||||||
int index = 10;
|
int index = 10;
|
||||||
|
|
||||||
while (playerIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) &&
|
while (playerIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) &&
|
||||||
playerIndex < this.onlineUsers.size() &&
|
playerIndex < this.onlineUsers.size() &&
|
||||||
index < 36)
|
index < 36)
|
||||||
{
|
{
|
||||||
if (!panelBuilder.slotOccupied(index))
|
if (!panelBuilder.slotOccupied(index))
|
||||||
{
|
{
|
||||||
panelBuilder.item(index, this.createPlayerIcon(this.onlineUsers.get(playerIndex++)));
|
panelBuilder.item(index, this.createPlayerIcon(this.onlineUsers.get(playerIndex++)));
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add button that allows to toogle different player lists.
|
// Add button that allows to toogle different player lists.
|
||||||
panelBuilder.item( 4, this.createToggleButton());
|
panelBuilder.item( 4, this.createToggleButton());
|
||||||
|
|
||||||
// Navigation buttons only if necessary
|
// Navigation buttons only if necessary
|
||||||
if (this.onlineUsers.size() > MAX_ELEMENTS)
|
if (this.onlineUsers.size() > MAX_ELEMENTS)
|
||||||
{
|
{
|
||||||
panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS));
|
panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS));
|
||||||
panelBuilder.item(26, this.getButton(CommonButtons.NEXT));
|
panelBuilder.item(26, this.getButton(CommonButtons.NEXT));
|
||||||
}
|
}
|
||||||
|
|
||||||
panelBuilder.item(44, this.returnButton);
|
panelBuilder.item(44, this.returnButton);
|
||||||
|
|
||||||
|
|
||||||
panelBuilder.build();
|
panelBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates button for given user. If user has island it will add valid click handler.
|
* This method creates button for given user. If user has island it will add valid click handler.
|
||||||
* @param player Player which button must be created.
|
* @param player Player which button must be created.
|
||||||
* @return Player button.
|
* @return Player button.
|
||||||
*/
|
*/
|
||||||
private PanelItem createPlayerIcon(Player player)
|
private PanelItem createPlayerIcon(Player player)
|
||||||
{
|
{
|
||||||
int lineLength = this.addon.getChallengesSettings().getLoreLineLength();
|
int lineLength = this.addon.getChallengesSettings().getLoreLineLength();
|
||||||
|
|
||||||
if (this.addon.getIslands().getIsland(this.world, player.getUniqueId()) != null)
|
if (this.addon.getIslands().getIsland(this.world, player.getUniqueId()) != null)
|
||||||
{
|
{
|
||||||
return new PanelItemBuilder().name(player.getName()).icon(player.getName()).clickHandler(
|
return new PanelItemBuilder().name(player.getName()).icon(player.getName()).clickHandler(
|
||||||
(panel, user1, clickType, slot) -> {
|
(panel, user1, clickType, slot) -> {
|
||||||
ChallengesManager manager = this.addon.getChallengesManager();
|
ChallengesManager manager = this.addon.getChallengesManager();
|
||||||
Map<Challenge, List<String>> challengeDescriptionMap;
|
Map<Challenge, List<String>> challengeDescriptionMap;
|
||||||
|
|
||||||
switch (this.operationMode)
|
switch (this.operationMode)
|
||||||
{
|
{
|
||||||
case COMPLETE:
|
case COMPLETE:
|
||||||
challengeDescriptionMap = new LinkedHashMap<>();
|
challengeDescriptionMap = new LinkedHashMap<>();
|
||||||
|
|
||||||
for (Challenge challenge : manager.getAllChallenges(this.world))
|
for (Challenge challenge : manager.getAllChallenges(this.world))
|
||||||
{
|
{
|
||||||
if (!manager.isChallengeComplete(player.getUniqueId(), this.world, challenge))
|
if (!manager.isChallengeComplete(player.getUniqueId(), this.world, challenge))
|
||||||
{
|
{
|
||||||
challengeDescriptionMap.put(challenge, this.generateChallengeDescription(challenge, player));
|
challengeDescriptionMap.put(challenge, this.generateChallengeDescription(challenge, player));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new SelectChallengeGUI(this.user, challengeDescriptionMap, lineLength, (status, valueSet) -> {
|
new SelectChallengeGUI(this.user, challengeDescriptionMap, lineLength, (status, valueSet) -> {
|
||||||
if (status)
|
if (status)
|
||||||
{
|
{
|
||||||
valueSet.forEach(challenge -> manager.setChallengeComplete(player.getUniqueId(), this.world, challenge, this.user.getUniqueId()));
|
valueSet.forEach(challenge -> manager.setChallengeComplete(player.getUniqueId(), this.world, challenge, this.user.getUniqueId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.build();
|
this.build();
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case RESET:
|
case RESET:
|
||||||
challengeDescriptionMap = new LinkedHashMap<>();
|
challengeDescriptionMap = new LinkedHashMap<>();
|
||||||
|
|
||||||
for (Challenge challenge : manager.getAllChallenges(this.world))
|
for (Challenge challenge : manager.getAllChallenges(this.world))
|
||||||
{
|
{
|
||||||
if (manager.isChallengeComplete(player.getUniqueId(), this.world, challenge))
|
if (manager.isChallengeComplete(player.getUniqueId(), this.world, challenge))
|
||||||
{
|
{
|
||||||
challengeDescriptionMap.put(challenge, this.generateChallengeDescription(challenge, player));
|
challengeDescriptionMap.put(challenge, this.generateChallengeDescription(challenge, player));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new SelectChallengeGUI(this.user, challengeDescriptionMap, lineLength, (status, valueSet) -> {
|
new SelectChallengeGUI(this.user, challengeDescriptionMap, lineLength, (status, valueSet) -> {
|
||||||
if (status)
|
if (status)
|
||||||
{
|
{
|
||||||
valueSet.forEach(challenge -> manager.resetChallenge(player.getUniqueId(), this.world, challenge, this.user.getUniqueId()));
|
valueSet.forEach(challenge -> manager.resetChallenge(player.getUniqueId(), this.world, challenge, this.user.getUniqueId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.build();
|
this.build();
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case RESET_ALL:
|
case RESET_ALL:
|
||||||
new ConfirmationGUI(this.user, status -> {
|
new ConfirmationGUI(this.user, status -> {
|
||||||
if (status)
|
if (status)
|
||||||
{
|
{
|
||||||
manager.resetAllChallenges(player.getUniqueId(), this.world, this.user.getUniqueId());
|
manager.resetAllChallenges(player.getUniqueId(), this.world, this.user.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.build();
|
this.build();
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}).build();
|
}).build();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new PanelItemBuilder().
|
return new PanelItemBuilder().
|
||||||
name(player.getName()).
|
name(player.getName()).
|
||||||
icon(Material.BARRIER).
|
icon(Material.BARRIER).
|
||||||
description(GuiUtils.stringSplit(this.user.getTranslation("general.errors.player-has-no-island"), lineLength)).
|
description(GuiUtils.stringSplit(this.user.getTranslation("general.errors.player-has-no-island"), lineLength)).
|
||||||
clickHandler((panel, user1, clickType, slot) -> false).
|
clickHandler((panel, user1, clickType, slot) -> false).
|
||||||
build();
|
build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method collects users based on view mode.
|
* This method collects users based on view mode.
|
||||||
* @param mode Given view mode.
|
* @param mode Given view mode.
|
||||||
* @return List with players in necessary view mode.
|
* @return List with players in necessary view mode.
|
||||||
*/
|
*/
|
||||||
private List<Player> collectUsers(ViewMode mode)
|
private List<Player> collectUsers(ViewMode mode)
|
||||||
{
|
{
|
||||||
if (mode.equals(ViewMode.ONLINE))
|
if (mode.equals(ViewMode.ONLINE))
|
||||||
{
|
{
|
||||||
return new ArrayList<>(Bukkit.getOnlinePlayers());
|
return new ArrayList<>(Bukkit.getOnlinePlayers());
|
||||||
}
|
}
|
||||||
else if (mode.equals(ViewMode.WITH_ISLAND))
|
else if (mode.equals(ViewMode.WITH_ISLAND))
|
||||||
{
|
{
|
||||||
return this.addon.getPlayers().getPlayers().stream().
|
return this.addon.getPlayers().getPlayers().stream().
|
||||||
filter(player -> this.addon.getIslands().getIsland(this.world, player.getPlayerUUID()) != null).
|
filter(player -> this.addon.getIslands().getIsland(this.world, player.getPlayerUUID()) != null).
|
||||||
map(Players::getPlayer).
|
map(Players::getPlayer).
|
||||||
collect(Collectors.toList());
|
collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new ArrayList<>(this.world.getPlayers());
|
return new ArrayList<>(this.world.getPlayers());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates Player List view Mode toggle button.
|
* This method creates Player List view Mode toggle button.
|
||||||
* @return Button that toggles through player view mode.
|
* @return Button that toggles through player view mode.
|
||||||
*/
|
*/
|
||||||
private PanelItem createToggleButton()
|
private PanelItem createToggleButton()
|
||||||
{
|
{
|
||||||
List<String> description = new ArrayList<>(ViewMode.values().length + 1);
|
List<String> description = new ArrayList<>(ViewMode.values().length + 1);
|
||||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.toggle-user-list"));
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.toggle-user-list"));
|
||||||
description.add((ViewMode.ONLINE == ViewMode.values()[this.modeIndex] ? "&2" : "&c") +
|
description.add((ViewMode.ONLINE == ViewMode.values()[this.modeIndex] ? "&2" : "&c") +
|
||||||
this.user.getTranslation("challenges.gui.descriptions.admin.mode-online"));
|
this.user.getTranslation("challenges.gui.descriptions.admin.mode-online"));
|
||||||
description.add((ViewMode.WITH_ISLAND == ViewMode.values()[this.modeIndex] ? "&2" : "&c") +
|
description.add((ViewMode.WITH_ISLAND == ViewMode.values()[this.modeIndex] ? "&2" : "&c") +
|
||||||
this.user.getTranslation("challenges.gui.descriptions.admin.mode-in-world"));
|
this.user.getTranslation("challenges.gui.descriptions.admin.mode-in-world"));
|
||||||
description.add((ViewMode.IN_WORLD == ViewMode.values()[this.modeIndex] ? "&2" : "&c") +
|
description.add((ViewMode.IN_WORLD == ViewMode.values()[this.modeIndex] ? "&2" : "&c") +
|
||||||
this.user.getTranslation("challenges.gui.descriptions.admin.mode-with-island"));
|
this.user.getTranslation("challenges.gui.descriptions.admin.mode-with-island"));
|
||||||
|
|
||||||
return new PanelItemBuilder().
|
return new PanelItemBuilder().
|
||||||
name(this.user.getTranslation("challenges.gui.buttons.admin.toggle-user-list")).
|
name(this.user.getTranslation("challenges.gui.buttons.admin.toggle-user-list")).
|
||||||
description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())).
|
description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())).
|
||||||
icon(Material.STONE_BUTTON).
|
icon(Material.STONE_BUTTON).
|
||||||
clickHandler(
|
clickHandler(
|
||||||
(panel, user1, clickType, slot) -> {
|
(panel, user1, clickType, slot) -> {
|
||||||
if (clickType.isRightClick())
|
if (clickType.isRightClick())
|
||||||
{
|
{
|
||||||
this.modeIndex--;
|
this.modeIndex--;
|
||||||
|
|
||||||
if (this.modeIndex < 0)
|
if (this.modeIndex < 0)
|
||||||
{
|
{
|
||||||
this.modeIndex = ViewMode.values().length - 1;
|
this.modeIndex = ViewMode.values().length - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.modeIndex++;
|
this.modeIndex++;
|
||||||
|
|
||||||
if (this.modeIndex >= ViewMode.values().length)
|
if (this.modeIndex >= ViewMode.values().length)
|
||||||
{
|
{
|
||||||
this.modeIndex = 0;
|
this.modeIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.onlineUsers = this.collectUsers(ViewMode.values()[this.modeIndex]);
|
this.onlineUsers = this.collectUsers(ViewMode.values()[this.modeIndex]);
|
||||||
this.pageIndex = 0;
|
this.pageIndex = 0;
|
||||||
this.build();
|
this.build();
|
||||||
return true;
|
return true;
|
||||||
}).build();
|
}).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user