-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for taking items even if challenge incomplete
#27 Also added admin challenge reset command.
- Loading branch information
1 parent
e5e0227
commit ac80a7e
Showing
8 changed files
with
209 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/bentobox/addon/challenges/commands/admin/ResetChallenge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package bentobox.addon.challenges.commands.admin; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import bentobox.addon.challenges.ChallengesAddon; | ||
import bentobox.addon.challenges.ChallengesManager; | ||
import world.bentobox.bentobox.api.addons.Addon; | ||
import world.bentobox.bentobox.api.commands.CompositeCommand; | ||
import world.bentobox.bentobox.api.localization.TextVariables; | ||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.bentobox.util.Util; | ||
|
||
public class ResetChallenge extends CompositeCommand { | ||
|
||
private ChallengesManager manager; | ||
|
||
/** | ||
* Admin command to complete user challenges | ||
* @param parent | ||
*/ | ||
public ResetChallenge(Addon addon, CompositeCommand parent) { | ||
super(addon, parent, "reset"); | ||
} | ||
|
||
@Override | ||
public void setup() { | ||
this.setPermission("admin.challenges"); | ||
this.setParametersHelp("challenges.admin.reset.parameters"); | ||
this.setDescription("challenges.admin.reset.description"); | ||
manager = ((ChallengesAddon)getAddon()).getChallengesManager(); | ||
} | ||
|
||
@Override | ||
public boolean execute(User user, String label, List<String> args) { | ||
if (args.size() != 2) { | ||
// Show help | ||
showHelp(this, user); | ||
return false; | ||
} | ||
// Get target player | ||
UUID targetUUID = getPlayers().getUUID(args.get(0)); | ||
if (targetUUID == null) { | ||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0)); | ||
return false; | ||
} | ||
if (!getPlugin().getIslands().hasIsland(getWorld(), targetUUID)) { | ||
user.sendMessage("general.errors.player-has-no-island"); | ||
return false; | ||
} | ||
// Check for valid challenge name | ||
if (!manager.isChallenge(getWorld(), args.get(1))) { | ||
user.sendMessage("challenges.admin.complete.unknown-challenge"); | ||
return false; | ||
} | ||
// Complete challenge | ||
User target = User.getInstance(targetUUID); | ||
manager.setResetChallenge(target, args.get(1), getWorld()); | ||
user.sendMessage("general.success"); | ||
return true; | ||
} | ||
|
||
@Override | ||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) { | ||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : ""; | ||
if (args.size() == 3) { | ||
// Online players | ||
return Optional.of(Util.tabLimit(new ArrayList<>(Util.getOnlinePlayerList(user)), lastArg)); | ||
} else if (args.size() == 4) { | ||
// Challenges in this world | ||
return Optional.of(Util.tabLimit(manager.getAllChallengesList(getWorld()), lastArg)); | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters