Skip to content

Commit

Permalink
strongly deprecate 'fail' and 'finish' commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 18, 2019
1 parent 53e4dd1 commit 86614c0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 187 deletions.
14 changes: 6 additions & 8 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -1787,24 +1787,22 @@ else if (isOnline()) {
// @attribute <p@player.has_finished[<script>]>
// @returns Element(Boolean)
// @description
// Returns whether the player has finished the specified script.
// Returns whether the player has finished the specified script. DEPRECATED: Use flags instead!
// -->
if (attribute.startsWith("has_finished")) {
dScript script = dScript.valueOf(attribute.getContext(1));
return new Element(script != null && FinishCommand.getScriptCompletes(getName(), script.getName()) > 0)
.getAttribute(attribute.fulfill(1));
FinishCommand.class.toString(); // TODO: Remove references to FINISH command.
dB.echoError("The 'FINISH' command is deprecated. Use flags instead!");
}

// <--[tag]
// @attribute <p@player.has_failed[<script>]>
// @returns Element(Boolean)
// @description
// Returns whether the player has failed the specified script.
// Returns whether the player has failed the specified script. DEPRECATED: Use flags instead!
// -->
if (attribute.startsWith("has_failed")) {
dScript script = dScript.valueOf(attribute.getContext(1));
return new Element(script != null && FailCommand.getScriptFails(getName(), script.getName()) > 0)
.getAttribute(attribute.fulfill(1));
FailCommand.class.toString(); // TODO: Remove references to FAIL command.
dB.echoError("The 'FAIL' command is deprecated. Use flags instead!");
}

/////////////////////
Expand Down
@@ -1,112 +1,20 @@
package net.aufdemrand.denizen.scripts.commands.core;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.events.bukkit.ScriptFailEvent;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.dScript;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import org.bukkit.Bukkit;

/**
* Sets a Script as 'FAILED'. Scripts can be failed multiple times and Denizen will keep track
* of the total amount. This can also be checked against with the SCRIPT requirement.
*
* @author aufdemrand
*/

// TODO: Remove entirely!
public class FailCommand extends AbstractCommand {

/* FAIL ('SCRIPT:[Script Name]') (PLAYER:[Player Name])
/* Arguments: [] - Required, () - Optional
* ('SCRIPT:[Script Name]') Changes the script from the triggering script to the one specified.
* Defaults to the script that the Script Entry was sent from.
* (PLAYER:[Player Name]) Changes the Player affected.
* Defaults to the Player who triggered the script.
*
* Example Usage:
* FAIL PLAYER:aufdemrand
* FAIL 'SCRIPT:A different script'
*/

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

// Parse the arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (arg.matchesArgumentType(dScript.class)) {
scriptEntry.addObject("script", arg.asType(dScript.class));
}
else if (arg.matchesArgumentType(dPlayer.class)) {
scriptEntry.addObject("player", arg.asType(dPlayer.class));
}
else {
arg.reportUnhandled();
}
}

// Check for required args
scriptEntry.defaultObject("player", ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer());
scriptEntry.defaultObject("script", scriptEntry.getScript());
}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Grab objects from scriptEntry
dScript script = (dScript) scriptEntry.getObject("script");
dPlayer player = (dPlayer) scriptEntry.getObject("player");

// Report to dB
if (scriptEntry.dbCallShouldDebug()) {
dB.report(scriptEntry, getName(),
player.debug() + script.debug());
}

dB.echoError(scriptEntry.getResidingQueue(), "The Fail command is outdated, use flags intead!");

failScript(player.getName(), script.getName());
}

public static void resetFails(String playerName, String scriptName) {
scriptName = scriptName.toUpperCase();
DenizenAPI._saves().set("Players." + playerName + "." + scriptName + "." + "Failed", null);
}

/**
* Increases a scripts 'failed' counter for a specified Player.
*
* @param playerName name of the Player
* @param scriptName name of the Script
*/
public static void failScript(String playerName, String scriptName) {
scriptName = scriptName.toUpperCase();
int fails = DenizenAPI._saves().getInt("Players." + playerName + "." + scriptName + "." + "Failed", 0);

// Increase fails by one and set.
fails++;
DenizenAPI._saves().set("Players." + playerName + "." + scriptName + "." + "Failed", fails);

// Call ScriptFailEvent
ScriptFailEvent event = new ScriptFailEvent(playerName, scriptName, fails);
Bukkit.getServer().getPluginManager().callEvent(event);
}

/**
* Gets the number of times a Player has 'failed' a script.
*
* @param playerName name of the Player
* @param scriptName name of the Script
* @return number of times the Player has failed the specified script
*/
public static int getScriptFails(String playerName, String scriptName) {
return DenizenAPI.getCurrentInstance().getSaves()
.getInt("Players." + playerName + "." + scriptName.toUpperCase() + "." + "Failed", 0);
dB.echoError("The 'FAIL' command is deprecated. Use flags instead!");
}
}
@@ -1,102 +1,21 @@
package net.aufdemrand.denizen.scripts.commands.core;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.events.bukkit.ScriptFinishEvent;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.dScript;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import org.bukkit.Bukkit;

/**
* Sets a Script as 'FINISHED'. Scripts can be finished multiple times and Denizen will keep track
* of the total amount. This can also be checked with the SCRIPT requirement or an IF command.
*
* @author Jeremy Schroeder
*/

// TODO: Remove entirely!
public class FinishCommand extends AbstractCommand {

/* FINISH ('SCRIPT:[Script Name]') (PLAYER:[Player Name])
/* Arguments: [] - Required, () - Optional
* ('SCRIPT:[Script Name]') Changes the script from the triggering script to the one specified.
* Defaults to the script that the Script Entry was sent from.
* (PLAYER:[Player Name]) Changes the Player affected.
* Defaults to the Player who triggered the script.
*
* Example Usage:
* FINISH PLAYER:aufdemrand
* FINISH 'SCRIPT:A different script'
*/

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

// Parse the arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (arg.matchesArgumentType(dScript.class)) {
scriptEntry.addObject("script", arg.asType(dScript.class));
}
else if (arg.matchesArgumentType(dPlayer.class)) {
scriptEntry.addObject("player", arg.asType(dPlayer.class));
}
else {
arg.reportUnhandled();
}
}

// Check for required args
scriptEntry.defaultObject("player", ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer());
scriptEntry.defaultObject("script", scriptEntry.getScript());
}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Grab objects from scriptEntry
dScript script = (dScript) scriptEntry.getObject("script");
dPlayer player = (dPlayer) scriptEntry.getObject("player");

// Report to dB
if (scriptEntry.dbCallShouldDebug()) {
dB.report(scriptEntry, getName(),
player.debug() + script.debug());
}

dB.echoError(scriptEntry.getResidingQueue(), "Finish is outdated, use flags instead!");

finishScript(player.getName(), script.getName());
}

public static void resetFinishes(String playerName, String scriptName) {
scriptName = scriptName.toUpperCase();
DenizenAPI._saves().set("Players." + playerName + "." + scriptName + "." + "Completed", null);
}

// TODO: Why is this a boolean?
public static boolean finishScript(String playerName, String scriptName) {
scriptName = scriptName.toUpperCase();
int finishes = DenizenAPI._saves().getInt("Players." + playerName + "." + scriptName + "." + "Completed", 0);

// Increase finishes by one and save.
finishes++;
DenizenAPI._saves().set("Players." + playerName + "." + scriptName + "." + "Completed", finishes);

// Call ScriptFinishEvent
ScriptFinishEvent event = new ScriptFinishEvent(playerName, scriptName, finishes);
Bukkit.getServer().getPluginManager().callEvent(event);

return true;
}

public static int getScriptCompletes(String playerName, String scriptName) {
return DenizenAPI.getCurrentInstance().getSaves().getInt("Players." + playerName + "." + scriptName.toUpperCase() + "." + "Completed", 0);
dB.echoError("The 'FINISH' command is deprecated. Use flags instead!");
}
}

Expand Down
Expand Up @@ -101,11 +101,13 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

switch (type) {
case FAIL:
FailCommand.resetFails(resettable.getName(), script.getName());
FailCommand.class.toString(); // TODO: Remove references to FAIL command.
dB.echoError("The 'FAIL' command is deprecated. Use flags instead!");
return;

case FINISH:
FinishCommand.resetFinishes(resettable.getName(), script.getName());
FinishCommand.class.toString(); // TODO: Remove references to FINISH command.
dB.echoError("The 'FINISH' command is deprecated. Use flags instead!");
return;

case PLAYER_COOLDOWN:
Expand Down

0 comments on commit 86614c0

Please sign in to comment.