Skip to content

Commit

Permalink
Merge pull request #903 from Morphan1/master
Browse files Browse the repository at this point in the history
Fix Some Denizen Things
  • Loading branch information
mcmonkey4eva committed Dec 29, 2014
2 parents 501e8e4 + ac05a64 commit 5993b02
Show file tree
Hide file tree
Showing 21 changed files with 317 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public DenizenCommandHandler(Denizen denizen) {
// denizen.basic # use the basics of the /denizen command
// denizen.notable # use the /notable command
// denizen.notable.basic # functionality within the /notable command, such as add or list
// denizen.flag # use the /flag command
// denizen.dscript # use the /dscript command
// denizen.ex # use the /ex command
// denizen.debug # use the /denizen debug command
Expand Down
37 changes: 17 additions & 20 deletions src/main/java/net/aufdemrand/denizen/objects/dInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -949,46 +949,43 @@ public dInventory remove(ItemStack[] items) {
* Denizen support for updatable quest journals
* and their like
*
* @param book The itemStack of the book
* @param title The title of the book
* @param author The author of the book
* @param quantity The number of books to remove
* @return The resulting dInventory
*
*/

public dInventory removeBook(ItemStack book) {
public dInventory removeBook(String title, String author, int quantity) {

if (inventory == null || book == null) return this;

// We have to manually keep track of the quantity
// we are removing, because we are not relying on
// Bukkit methods to find matching itemStacks
int qty = book.getAmount();

// Store the book's meta information in a variable
BookMeta bookMeta = (BookMeta) book.getItemMeta();
if (inventory == null || (title == null && author == null)) return this;

for (ItemStack invStack : inventory) {

if (qty == 0) break;
if (quantity == 0) break;

if (invStack != null && invStack.getItemMeta() instanceof BookMeta) {

BookMeta invMeta = (BookMeta) invStack.getItemMeta();

if (invMeta.getAuthor().equalsIgnoreCase(bookMeta.getAuthor())
&& invMeta.getTitle().equalsIgnoreCase(bookMeta.getTitle())) {
String invTitle = invMeta.getTitle();
String invAuthor = invMeta.getAuthor();

if ((invTitle == null && title != null) || (invAuthor == null && author != null))
continue;
else if (invTitle == null || invAuthor == null)
continue;

if (invAuthor.equalsIgnoreCase(author) && invTitle.equalsIgnoreCase(title)) {
// Make sure we don't remove more books than we
// need to
if (qty - invStack.getAmount() < 0) {

invStack.setAmount((qty - invStack.getAmount()) * -1);
if (quantity - invStack.getAmount() < 0) {
invStack.setAmount((quantity - invStack.getAmount()) * -1);
}
else {

inventory.removeItem(invStack);

// Update the quantity we still have to remove
qty = qty - invStack.getAmount();
quantity -= invStack.getAmount();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dItem.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.aufdemrand.denizen.objects;

import net.aufdemrand.denizen.objects.notable.*;
import net.aufdemrand.denizen.objects.notable.Note;
import net.aufdemrand.denizen.objects.properties.item.*;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.objects.properties.PropertyParser;
Expand All @@ -11,7 +10,8 @@
import net.aufdemrand.denizen.scripts.containers.core.ItemScriptHelper;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.*;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,8 @@ public static String getClassId(Class notable) {
else
return null;
}

public static Map<String, Class> getReverseClassIdMap() {
return reverse_objects;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public PropertyParser() {

// register core dInventory properties
registerProperty(InventoryHolder.class, dInventory.class); // Holder must be loaded first to initiate correctly
registerProperty(InventorySize.class, dInventory.class); // Same with size...(Too small for contents)
registerProperty(InventoryContents.class, dInventory.class);
registerProperty(InventorySize.class, dInventory.class);
registerProperty(InventoryTitle.class, dInventory.class);

// register core dItem properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.entity.RabbitType;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.DyeColor;
import org.bukkit.entity.*;

public class EntityColor implements Property {


public static boolean describes(dObject entity) {
return entity instanceof dEntity &&
(((dEntity) entity).getEntityType() == EntityType.SHEEP
|| ((dEntity) entity).getEntityType() == EntityType.HORSE
|| ((dEntity) entity).getEntityType() == EntityType.WOLF
|| ((dEntity) entity).getEntityType() == EntityType.OCELOT);
if (!(entity instanceof dEntity)) return false;
EntityType type = ((dEntity) entity).getEntityType();
return type == EntityType.SHEEP ||
type == EntityType.HORSE ||
type == EntityType.WOLF ||
type == EntityType.OCELOT ||
type == EntityType.RABBIT;
}

public static EntityColor getFrom(dObject entity) {
Expand All @@ -35,20 +39,25 @@ private EntityColor(dEntity entity) {
dEntity colored;

private String getColor() {
if (colored.getEntityType() == EntityType.HORSE)
EntityType type = colored.getEntityType();

if (type == EntityType.HORSE)
return ((Horse) colored.getBukkitEntity()).getColor().name() + "|" +
((Horse) colored.getBukkitEntity()).getStyle().name() + "|" +
((Horse) colored.getBukkitEntity()).getVariant().name();

else if (colored.getEntityType() == EntityType.SHEEP)
else if (type == EntityType.SHEEP)
return ((Sheep) colored.getBukkitEntity()).getColor().name();

else if (colored.getEntityType() == EntityType.WOLF)
else if (type == EntityType.WOLF)
return ((Wolf) colored.getBukkitEntity()).getCollarColor().name();

else if (colored.getEntityType() == EntityType.OCELOT)
else if (type == EntityType.OCELOT)
return ((Ocelot) colored.getBukkitEntity()).getCatType().name();

else if (type == EntityType.RABBIT)
return RabbitType.getRabbitType((Rabbit) colored.getBukkitEntity()).name();

else // Should never happen
return null;
}
Expand All @@ -59,7 +68,7 @@ else if (colored.getEntityType() == EntityType.OCELOT)

@Override
public String getPropertyString() {
return getColor().toLowerCase();
return CoreUtilities.toLowerCase(getColor());
}

@Override
Expand Down Expand Up @@ -88,6 +97,20 @@ public String getPropertyId() {
// DONKEY, MULE, SKELETON_HORSE, UNDEAD_HORSE, or HORSE.
// -->

// <--[language]
// @name Rabbit Types
// @group Properties
// @description
// Denizen includes its own user-friendly list of rabbit type names, instead
// of relying on Bukkit names which did not exist at the time of writing.
//
// Types currently available:
// BROWN, WHITE, BLACK, WHITE_SPLOTCHED, GOLD, SALT, KILLER.
//
// Note: The KILLER rabbit type is a hostile rabbit type. It will attempt to kill
// nearby players and wolves. Use at your own risk.
// -->


@Override
public String getAttribute(Attribute attribute) {
Expand All @@ -101,9 +124,10 @@ public String getAttribute(Attribute attribute) {
// @group properties
// @description
// If the entity can have a color, returns the entity's color.
// Currently, only Horse, Wolf, Ocelot, and Sheep type entities can have a color.
// Currently, only Horse, Wolf, Ocelot, Sheep, and Rabbit type entities can have a color.
// For horses, the output is COLOR|STYLE|VARIANT, see <@link language horse types>.
// For ocelots, the types are BLACK_CAT, RED_CAT, SIAMESE_CAT, or WILD_OCELOT.
// For rabbit types, see <@link language rabbit types>.
// -->
if (attribute.startsWith("color"))
return new Element(getColor().toLowerCase())
Expand All @@ -121,16 +145,19 @@ public void adjust(Mechanism mechanism) {
// @input Element
// @description
// Changes the entity's color.
// Currently, only Horse, Wolf, Ocelot, and Sheep type entities can have a color.
// Currently, only Horse, Wolf, Ocelot, Sheep, and Rabbit type entities can have a color.
// For horses, the input is COLOR|STYLE|VARIANT, see <@link language horse types>
// For ocelots, the types are BLACK_CAT, RED_CAT, SIAMESE_CAT, or WILD_OCELOT.
// For rabbit types, see <@link language rabbit types>.
// @tags
// <e@entity.color>
// <e@entity.is_colorable>
// -->

if (mechanism.matches("color")) {
if (colored.getEntityType() == EntityType.HORSE) {
EntityType type = colored.getEntityType();

if (type == EntityType.HORSE) {
dList horse_info = mechanism.getValue().asType(dList.class);
if (horse_info.size() > 0 && new Element(horse_info.get(0)).matchesEnum(Horse.Color.values()))
((Horse) colored.getBukkitEntity())
Expand All @@ -143,21 +170,26 @@ public void adjust(Mechanism mechanism) {
.setVariant(Horse.Variant.valueOf(horse_info.get(2).toUpperCase()));
}

else if (colored.getEntityType() == EntityType.SHEEP
else if (type == EntityType.SHEEP
&& mechanism.getValue().matchesEnum(DyeColor.values()))
((Sheep) colored.getBukkitEntity())
.setColor(DyeColor.valueOf(mechanism.getValue().asString().toUpperCase()));

else if (colored.getEntityType() == EntityType.WOLF
else if (type == EntityType.WOLF
&& mechanism.getValue().matchesEnum(DyeColor.values()))
((Wolf) colored.getBukkitEntity())
.setCollarColor(DyeColor.valueOf(mechanism.getValue().asString().toUpperCase()));

else if (colored.getEntityType() == EntityType.OCELOT
&& mechanism.getValue().matchesEnum(Ocelot.Type.values()))
else if (type == EntityType.OCELOT
&& mechanism.getValue().matchesEnum(Ocelot.Type.values()))
((Ocelot) colored.getBukkitEntity())
.setCatType(Ocelot.Type.valueOf(mechanism.getValue().asString().toUpperCase()));

else if (type == EntityType.RABBIT
&& mechanism.getValue().matchesEnum(RabbitType.values()))
RabbitType.setRabbitType((Rabbit) colored.getBukkitEntity(),
RabbitType.valueOf(mechanism.getValue().asString().toUpperCase()));

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name CopyBlock
// @Syntax copyblock [location:<location>] [to:<location>]
// @Syntax copyblock [<location>/<cuboid>] [to:<location>] (remove_original)
// @Required 1
// @Stable unstable
// @Short Copies a block to another location, keeping all metadata.
Expand All @@ -563,7 +563,7 @@ public void registerCoreMembers() {
// TODO: Document Command Details
// -->
registerCoreMember(CopyBlockCommand.class,
"COPYBLOCK", "copyblock [location:<location>] [to:<location>]", 1);
"COPYBLOCK", "copyblock [<location>/<cuboid>] [to:<location>] (remove_original)", 1);


// <--[command]
Expand Down Expand Up @@ -1960,7 +1960,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name Push
// @Syntax push [<entity>|...] (origin:<entity>/<location>) (destination:<location>) (speed:<#.#>) (duration:<duration>) (<script>) (force_along) (precision:<#>)
// @Syntax push [<entity>|...] (origin:<entity>/<location>) (destination:<location>) (speed:<#.#>) (duration:<duration>) (<script>) (force_along) (precision:<#>) (no_rotate) (no_damage)
// @Required 1
// @Stable stable
// @Short Pushes entities through the air in a straight line.
Expand All @@ -1980,7 +1980,7 @@ public void registerCoreMembers() {
//
// -->
registerCoreMember(PushCommand.class,
"PUSH", "push [<entity>|...] (origin:<entity>/<location>) (destination:<location>) (speed:<#.#>) (<duration>) (<script>) (force_along) (precision:<#>)", 1);
"PUSH", "push [<entity>|...] (origin:<entity>/<location>) (destination:<location>) (speed:<#.#>) (<duration>) (<script>) (force_along) (precision:<#>) (no_rotate) (no_damage)", 1);


// <--[command]
Expand Down Expand Up @@ -2449,7 +2449,7 @@ public void registerCoreMembers() {
// @Syntax sit (<location>)
// @Required 0
// @Stable unstable
// @Short Causes the NPC to sit.
// @Short Causes the NPC to sit. To make them stand, see <@link command Stand>.
// @Author Jeebiss, mcmonkey
// @Group npc
// @Description
Expand Down Expand Up @@ -2539,7 +2539,7 @@ public void registerCoreMembers() {
// @Syntax stand
// @Required 0
// @Stable unstable
// @Short Causes the NPC to stand.
// @Short Causes the NPC to stand. To make them sit, see <@link command Sit>.
// @Author Jeebiss
// @Group npc
// @Description
Expand Down Expand Up @@ -2612,7 +2612,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name Take
// @Syntax take [money/iteminhand/bydisplay:<name>/slot:<#>/<item>|...] (qty:<#>) (from:<inventory>)
// @Syntax take [money/iteminhand/bydisplay:<name>/bycover:<title>|<author>/slot:<#>/<item>|...] (qty:<#>) (from:<inventory>)
// @Required 1
// @Stable stable
// @Short Takes an item from the player.
Expand All @@ -2627,7 +2627,7 @@ public void registerCoreMembers() {
// TODO: Document Command Details
// -->
registerCoreMember(TakeCommand.class,
"TAKE", "take [money/iteminhand/bydisplay:<name>/slot:<#>/<item>|...] (qty:<#>) (from:<inventory>)", 1);
"TAKE", "take [money/iteminhand/bydisplay:<name>/bycover:<title>|<author>/slot:<#>/<item>|...] (qty:<#>) (from:<inventory>)", 1);

// <--[command]
// @Name Teleport
Expand Down

0 comments on commit 5993b02

Please sign in to comment.