Skip to content

Commit

Permalink
minor cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 24, 2019
1 parent e95d980 commit c0ecb9d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 113 deletions.
Expand Up @@ -18,7 +18,7 @@ public class PlayerCompletesAdvancementScriptEvent extends BukkitScriptEvent imp
// @Events
// player completes advancement
//
// @Regex ^on player completes advancement?$
// @Regex ^on player completes advancement$
//
// @Triggers when a player has completed all criteria in an advancement.
//
Expand Down
Expand Up @@ -8,12 +8,9 @@
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.objects.Argument;
import com.denizenscript.denizencore.objects.TagRunnable;
import com.denizenscript.denizencore.objects.core.ScriptTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.tags.ReplaceableTagEvent;
import com.denizenscript.denizencore.tags.TagManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand All @@ -22,72 +19,6 @@

public class ScribeCommand extends AbstractCommand {

/*
* <b>dScript Usage:</b><br>
* <pre>Scribe [SCRIPT:book_script] (GIVE|{DROP}|EQUIP) (LOCATION:x,y,z,world) (ITEM:ITEMSTACK.name)</pre>
*
* <ol><tt>Arguments: [] - Required () - Optional {} - Default</ol></tt>
*
* <ol><tt>[SCRIPT:book_script]</tt><br>
* The name of the 'Book Script'. See below for format.</ol>
*
* <ol><tt>[GIVE|{DROP}|EQUIP]</tt><br>
* What to do with the book after it is written. If not specified, it will default
* to dropping the book near the NPC. Note: When using BOOK with an 'ITEMSTACK.name',
* no default action is set allowing other commands to modify the book.</ol>
*
* <ol><tt>(LOCATION:x,y,z,world)</tt><br>
* When using DROP, a location may be specified. Default location, if unspecified,
* is the attached NPC.</ol>
*
* <ol><tt>(ITEM:ITEMSTACK.name)</tt><br>
* Allows the use of a specific BOOK created with a 'saved ITEMSTACK' from the NEW
* command. If not specified, a new book will be used.</ol>
*
*
* <br><b>Sample Book Script:</b><br>
* <ol><pre>
* "Cosmos Book":<br>
* Type: Book<br>
* Title: Cosmos, a Personal Voyage<br>
* Author: Carl Sagan<br>
* Text:<br>
* - Every one of us is, in the cosmic perspective, precious. If a human disagrees with<br>
* you, let him live. In a hundred billion galaxies, you will not find another<br>
* - The nitrogen in our DNA, the calcium in our teeth, the iron in our blood, the <br>
* carbon in our apple pies were made in the interiors of collapsing stars. We are <br>
* made of starstuff.<br>
* </pre></ol>
*
* <p>Note: ScribeCommand also implements a replaceable tag for &#60;P>, which creates a new
* paragraph in a written book's text.</p>
*
* <br><b>Example Usage:</b><br>
* <ol><tt>
* - SCRIBE SCRIPT:Cosmos DROP<br>
* - SCRIBE ITEM:ITEMSTACK.ImportantBook 'SCRIPT:Spellbook of Haste'<br>
* </ol></tt>
*
* <br><b>Extended Usage:</b><br>
* <ol><tt>
* Script: <br>
* - ENGAGE NOW DURATION:10 <br>
* - LOOKCLOSE TOGGLE:TRUE DURATION:10 <br>
* - CHAT 'Use this book with care, as it is very powerful and could cause great harm<br>
* if put into the wrong hands!' <br>
* - WAIT 2 <br>
* - ^ANIMATE ANIMATION:ARM_SWING <br>
* - ^NEW ITEMSTACK ITEM:book ID:&#60;PLAYER.NAME>s_enchanted_spellbook<br>
* - ^SCRIBE ITEM:ITEMSTACK.&#60;PLAYER.NAME>s_enchanted_spellbook SCRIPT:silk_touch_description <br>
* - ^ENCHANT ITEM:ITEMSTACK.&#60;PLAYER.NAME>s_enchanted_spellbook ENCHANTMENT:SILKTOUCH<br>
* - ^LORE ADD ITEM:ITEMSTACK.&#60;PLAYER.NAME>s_enchanted_spellbook 'A spell of Silk-touch, level 1'<br>
* - DROP ITEM:ITEMSTACK.&#60;PLAYER.NAME>s_enchanted_spellbook<br>
* - NARRATE '&#60;NPC.NAME> drops an old book.' <br>
* </ol></tt>
*
*/
// TODO: Combine the above outdated information with the new meta tags below

// <--[command]
// @Name Scribe
// @Syntax scribe [<script>] (<item>/give/equip/{drop <location>})
Expand All @@ -109,29 +40,19 @@ public class ScribeCommand extends AbstractCommand {
//
// @Usage
// Gives the book "Cosmos Book" to the player
// - scribe "Cosmos Book" give
// - scribe "Cosmos_Book" give
//
// @Usage
// Drops the "Cosmos Book" at the players location
// - scribe "Cosmos Book" drop <player.location>
// - scribe "Cosmos_Book" drop <player.location>
//
// @Usage
// Puts the "Cosmos Book" in the players hand
// - scribe "Cosmos Book" equip
// - scribe "Cosmos_Book" equip
// -->

private enum BookAction {GIVE, DROP, EQUIP, NONE}

@Override
public void onEnable() {
TagManager.registerTagHandler(new TagRunnable.RootForm() {
@Override
public void run(ReplaceableTagEvent event) {
paragraph(event);
}
}, "p", "n");
}

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

Expand Down Expand Up @@ -248,31 +169,4 @@ private void equipBook(Player player, ItemStack book) {
private void dropBook(Location location, ItemStack book) {
location.getWorld().dropItem(location, book);
}

/**
* Catches a replaceable tag event for '<P>' and replaces it with
* a book-friendly 'newline'.
*
* @param e ReplaceableTagEvent
*/
public void paragraph(ReplaceableTagEvent e) {
// <--[tag]
// @attribute <p>
// @returns ElementTag
// @description
// Returns a paragraph, for use in books.
// -->
if (e.matches("p")) {
e.setReplaced("\n \u00A7r \n");
// <--[tag]
// @attribute <n>
// @returns ElementTag
// @description
// Returns a newline symbol, for use in books.
// -->
}
else if (e.matches("n")) {
e.setReplaced("\n");
}
}
}
Expand Up @@ -19,7 +19,7 @@ public void run(ReplaceableTagEvent event) {
}
}, "&auml", "&Auml", "&ouml", "&Ouml", "&uuml", "&Uuml", "&nl", "&amp", "&cm", "&ss", "&sq", "&sp", "&nbsp",
"&dq", "&co", "&sc", "&rb", "&lb", "&rc", "&lc", "&ns", "&pc", "&pipe",
"&ds", "&lt", "&gt", "&bs", "&at", "&dot", "&hrt", "&chr");
"&ds", "&lt", "&gt", "&bs", "&at", "&dot", "&hrt", "&chr", "p", "n");
for (ChatColor color : ChatColor.values()) {
final String nameVal = CoreUtilities.toLowerCase(color.name());
final String codeVal = "&" + String.valueOf(color.getChar());
Expand Down Expand Up @@ -573,9 +573,28 @@ else if (lower.equals("&bs")) {
// @description
// Returns the Unicode character specified. e.g. <&chr[2665]> returns a heart.
// -->
if (attribute.startsWith("&chr") && attribute.hasContext(1)) {
event.setReplaced(String.valueOf((char) Integer.parseInt(attribute.getContext(1), 16)));
else if (attribute.startsWith("&chr") && attribute.hasContext(1)) {
event.setReplaced(new ElementTag(String.valueOf((char) Integer.parseInt(attribute.getContext(1), 16))).getAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <p>
// @returns ElementTag
// @description
// Returns a paragraph, for use in books.
// -->
else if (attribute.startsWith("p")) {
event.setReplaced(new ElementTag("\n " + ChatColor.RESET + " \n").getAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <n>
// @returns ElementTag
// @description
// Returns a newline symbol, for use in books.
// -->
else if (attribute.startsWith("n")) {
event.setReplaced(new ElementTag("\n").getAttribute(attribute.fulfill(1)));
}
}
}

0 comments on commit c0ecb9d

Please sign in to comment.