Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move some dScript code to a property
So the file can be moved to the core
- Loading branch information
1 parent
e949577
commit e501a53
Showing
3 changed files
with
133 additions
and
78 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
121 changes: 121 additions & 0 deletions
121
src/main/java/net/aufdemrand/denizen/objects/properties/bukkit/BukkitScriptProperties.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,121 @@ | ||
package net.aufdemrand.denizen.objects.properties.bukkit; | ||
|
||
import net.aufdemrand.denizen.objects.*; | ||
import net.aufdemrand.denizen.objects.properties.Property; | ||
import net.aufdemrand.denizen.scripts.commands.core.CooldownCommand; | ||
import net.aufdemrand.denizen.scripts.containers.core.InteractScriptContainer; | ||
import net.aufdemrand.denizen.scripts.containers.core.InteractScriptHelper; | ||
import net.aufdemrand.denizen.tags.Attribute; | ||
import net.aufdemrand.denizen.tags.core.EscapeTags; | ||
import net.aufdemrand.denizen.utilities.debugging.dB; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.meta.BookMeta; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class BukkitScriptProperties implements Property { | ||
|
||
public static boolean describes(dObject script) { | ||
return script instanceof dScript; | ||
} | ||
|
||
public static BukkitScriptProperties getFrom(dObject script) { | ||
if (!describes(script)) return null; | ||
else return new BukkitScriptProperties((dScript)script); | ||
} | ||
|
||
|
||
private BukkitScriptProperties(dScript script) { | ||
this.script = script; | ||
} | ||
|
||
dScript script; | ||
|
||
@Override | ||
public String getAttribute(Attribute attribute) { | ||
|
||
if (attribute == null) return "null"; | ||
|
||
// <--[tag] | ||
// @attribute <s@script.cooled_down[<player>]> | ||
// @returns Element(Boolean) | ||
// @description | ||
// Returns whether the script is currently cooled down for the player. Any global | ||
// cooldown present on the script will also be taken into account. Not specifying a player will result in | ||
// using the attached player available in the script entry. Not having a valid player will result in 'null'. | ||
// --> | ||
if (attribute.startsWith("cooled_down")) { | ||
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1)) | ||
: attribute.getScriptEntry().getPlayer()); | ||
if (player != null && player.isValid()) | ||
return new Element(CooldownCommand.checkCooldown(player, script.getContainer().getName())) | ||
.getAttribute(attribute.fulfill(1)); | ||
else return "null"; | ||
} | ||
|
||
// <--[tag] | ||
// @attribute <s@script.requirements[<player>].check[<path>]> | ||
// @returns Element | ||
// @description | ||
// Returns whether the player specified (defaults to current) has the requirement. | ||
// Must be an INTERACT script. | ||
// --> | ||
if (attribute.startsWith("requirements.check")) { | ||
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1)) | ||
: attribute.getScriptEntry().getPlayer()); | ||
if (attribute.hasContext(2)) | ||
return new Element(((InteractScriptContainer)script.getContainer()).checkRequirements(player, | ||
attribute.getScriptEntry().getNPC(), | ||
attribute.getContext(2))) | ||
.getAttribute(attribute.fulfill(2)); | ||
} | ||
|
||
// <--[tag] | ||
// @attribute <s@script.cooldown[<player>]> | ||
// @returns Duration | ||
// @description | ||
// Returns the time left for the player to cooldown for the script. | ||
// --> | ||
if (attribute.startsWith("cooldown")) { | ||
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1)) | ||
: attribute.getScriptEntry().getPlayer()); | ||
return CooldownCommand.getCooldownDuration(player, script.getName()) | ||
.getAttribute(attribute.fulfill(1)); | ||
|
||
} | ||
|
||
|
||
// <--[tag] | ||
// @attribute <s@script.step[<player>]> | ||
// @returns Element | ||
// @description | ||
// Returns the name of a script step that the player is currently on. | ||
// Must be an INTERACT script. | ||
// --> | ||
if (attribute.startsWith("step")) { | ||
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1)) | ||
: attribute.getScriptEntry().getPlayer()); | ||
|
||
if (player != null && player.isValid()) | ||
return new Element(InteractScriptHelper.getCurrentStep(player, script.getContainer().getName())) | ||
.getAttribute(attribute.fulfill(1)); | ||
} | ||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public String getPropertyString() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "BukkitScriptProperties"; | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
// None | ||
} | ||
} |