Skip to content

Commit

Permalink
Implement ability to import/generate default.json file.
Browse files Browse the repository at this point in the history
Remove old unnecessary methods.

Improve default.json challenges.
  • Loading branch information
BONNe committed May 1, 2019
1 parent 0418e64 commit 93da0c7
Show file tree
Hide file tree
Showing 6 changed files with 3,174 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ private List<ItemStack> parseItems(String reqList) {
* @param world Target world.
* @return <code>true</code> if everything was successful, otherwise <code>false</code>.
*/
@SuppressWarnings("unused")
private boolean loadDefaultChallenges(User user, World world)
public boolean loadDefaultChallenges(User user, World world)
{
ChallengesManager manager = this.addon.getChallengesManager();

Expand Down Expand Up @@ -299,13 +298,45 @@ private boolean loadDefaultChallenges(User user, World world)
/**
* Create method that can generate default challenge file from existing challenges in given world.
* This method will create default.json file in Challenges folder.
* @param user User who calls this method.
* @param world from which challenges must be stored.
* @param overwrite indicates if existing default.json file can be overwritten.
* @return <code>true</code> if everything was successful, otherwise <code>false</code>
*/
@SuppressWarnings("unused")
private void generateDefaultChallengeFile(World world)
public boolean generateDefaultChallengeFile(User user, World world, boolean overwrite)
{
File defaultFile = new File(this.addon.getDataFolder(), "default.json");

if (defaultFile.exists())
{
if (overwrite)
{
if (user.isPlayer())
{
user.sendMessage("challenges.messages.defaults-file-overwrite");
}
else
{
this.addon.logWarning("challenges.messages.defaults-file-overwrite");
}

defaultFile.delete();
}
else
{
if (user.isPlayer())
{
user.sendMessage("challenges.errors.defaults-file-exist");
}
else
{
this.addon.logWarning("challenges.errors.defaults-file-exist");
}

return false;
}
}

try
{
if (defaultFile.createNewFile())
Expand Down Expand Up @@ -358,9 +389,28 @@ private void generateDefaultChallengeFile(World world)
}
catch (IOException e)
{
this.addon.logError("Could not save json file: " + e.getMessage());
}
}
if (user.isPlayer())
{
user.sendMessage("challenges.errors.defaults-file-error");
}

this.addon.logError("Could not save json file: " + e.getMessage());
return false;
}
finally
{
if (user.isPlayer())
{
user.sendMessage("challenges.messages.defaults-file-completed", "[world]", world.getName());
}
else
{
this.addon.logWarning("challenges.messages.defaults-file-completed");
}
}

return true;
}


// ---------------------------------------------------------------------
Expand Down Expand Up @@ -392,7 +442,7 @@ private final class DefaultJSONHandler
builder.disableHtmlEscaping();

this.addon = addon;
this.gson = builder.create();
this.gson = builder.setPrettyPrinting().create();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,44 @@
import world.bentobox.challenges.panel.admin.AdminGUI;


public class Challenges extends CompositeCommand {
public class Challenges extends CompositeCommand
{

/**
* Admin command for challenges
*
* @param parent
*/
public Challenges(ChallengesAddon addon, CompositeCommand parent) {
public Challenges(ChallengesAddon addon, CompositeCommand parent)
{
super(addon, parent, "challenges");
}


@Override
public void setup() {
public void setup()
{
this.setPermission("admin.challenges");
this.setParametersHelp("challenges.commands.admin.main.parameters");
this.setDescription("challenges.commands.admin.main.description");

// Register sub commands
new ImportCommand(getAddon(), this);
// new CompleteChallenge(getAddon(), this);
new ReloadChallenges(getAddon(), this);
new ResetChallenge(getAddon(), this);
//new ShowChallenges(getAddon(), this);
//new CreateChallenge(getAddon(), this);

// This method reloads challenges addon
new ReloadChallenges(getAddon(), this);
// Import ASkyBlock Challenges
new ImportCommand(getAddon(), this);
// Defaults processing command
new DefaultsCommand(this.getAddon(), this);
}


@Override
public boolean execute(User user, String label, List<String> args) {
public boolean execute(User user, String label, List<String> args)
{
// Open up the admin challenges GUI
if (user.isPlayer()) {
if (user.isPlayer())
{
new AdminGUI((ChallengesAddon) this.getAddon(),
this.getWorld(),
user,
Expand All @@ -47,5 +56,4 @@ public boolean execute(User user, String label, List<String> args) {
}
return false;
}

}

This file was deleted.

0 comments on commit 93da0c7

Please sign in to comment.