Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
item cooldown support for 1.11.2+ (#90)
* Register itemcooldown command * Add itemcooldown command * Add item_cooldown tag * fix a derp
- Loading branch information
1 parent
2e3fcba
commit 3d68ac3
Showing
3 changed files
with
108 additions
and
0 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
66 changes: 66 additions & 0 deletions
66
plugin/src/main/java/net/aufdemrand/denizen/scripts/commands/player/ItemCooldownCommand.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,66 @@ | ||
package net.aufdemrand.denizen.scripts.commands.player; | ||
|
||
import net.aufdemrand.denizen.BukkitScriptEntryData; | ||
import net.aufdemrand.denizen.objects.dMaterial; | ||
import net.aufdemrand.denizen.objects.dPlayer; | ||
import net.aufdemrand.denizen.utilities.debugging.dB; | ||
import net.aufdemrand.denizencore.exceptions.CommandExecutionException; | ||
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException; | ||
import net.aufdemrand.denizencore.objects.Duration; | ||
import net.aufdemrand.denizencore.objects.aH; | ||
import net.aufdemrand.denizencore.objects.dList; | ||
import net.aufdemrand.denizencore.scripts.ScriptEntry; | ||
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class ItemCooldownCommand extends AbstractCommand { | ||
|
||
@Override | ||
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { | ||
|
||
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) { | ||
|
||
if (!scriptEntry.hasObject("materials") | ||
&& (arg.matchesArgumentType(dMaterial.class) | ||
|| arg.matchesArgumentType(dList.class))) { | ||
scriptEntry.addObject("materials", arg.asType(dList.class).filter(dMaterial.class)); | ||
} | ||
|
||
else if (!scriptEntry.hasObject("duration") | ||
&& arg.matchesPrefix("d", "duration") | ||
&& arg.matchesArgumentType(Duration.class)) { | ||
scriptEntry.addObject("duration", arg.asType(Duration.class)); | ||
} | ||
|
||
else { | ||
arg.reportUnhandled(); | ||
} | ||
} | ||
|
||
if (!scriptEntry.hasObject("materials")) { | ||
throw new InvalidArgumentsException("Missing materials argument!"); | ||
} | ||
|
||
scriptEntry.defaultObject("duration", new Duration(1)); | ||
} | ||
|
||
@Override | ||
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { | ||
|
||
ArrayList<dMaterial> materials = (ArrayList<dMaterial>) scriptEntry.getObject("materials"); | ||
Duration duration = scriptEntry.getdObject("duration"); | ||
dPlayer player = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(); | ||
|
||
if (player == null) { | ||
dB.echoError("Invalid linked player."); | ||
return; | ||
} | ||
|
||
dB.report(scriptEntry, getName(), aH.debugList("materials", materials) + duration.debug()); | ||
|
||
for (dMaterial mat : materials) { | ||
player.getPlayerEntity().setCooldown(mat.getMaterial(), duration.getTicksAsInt()); | ||
} | ||
} | ||
} |