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