Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/aufdemrand/Denizen
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 18, 2014
2 parents f62939f + a7557c8 commit acbf273
Show file tree
Hide file tree
Showing 34 changed files with 712 additions and 153 deletions.
3 changes: 2 additions & 1 deletion src/main/java/net/aufdemrand/denizen/Denizen.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ public void onEnable() {

// Register Core Members in the Denizen Registries
try {
getTriggerRegistry().registerCoreMembers();
if (Depends.citizens != null)
getTriggerRegistry().registerCoreMembers();
getRequirementRegistry().registerCoreMembers();
getListenerRegistry().registerCoreMembers();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

import net.aufdemrand.denizen.events.EventManager;
import net.aufdemrand.denizen.events.SmartEvent;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.objects.dMaterial;
import net.aufdemrand.denizen.objects.dObject;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.Utilities;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
Expand Down Expand Up @@ -118,7 +117,7 @@ public void run() {
if (now != null && now.getType() == item.getType()
&& now.getDurability() == item.getDurability()
&& (before == null || before.getType() == Material.AIR)) {
if (playerEquipsArmorEvent(player, item)) {
if (playerEquipsArmorEvent(player, item, "DISPENSER")) {
location.getWorld().dropItemNaturally(location, item).setVelocity(velocity);
armor_contents[i] = null;
player.getInventory().setArmorContents(armor_contents);
Expand All @@ -143,13 +142,13 @@ public void inventoryClick(InventoryClickEvent event) {
if (event.getSlotType() == InventoryType.SlotType.ARMOR) {
if (item != null && item.getType() != Material.AIR
&& (cursor == null || cursor.getType() == Material.AIR || isArmor(cursor))) {
if (playerUnequipsArmorEvent(player, item)) {
if (playerUnequipsArmorEvent(player, item, "INVENTORY")) {
event.setCancelled(true);
return;
}
}
if (cursor != null && cursor.getType() != Material.AIR && isArmor(cursor)) {
if (playerEquipsArmorEvent(player, cursor)) {
if (playerEquipsArmorEvent(player, cursor, "INVENTORY")) {
event.setCancelled(true);
return;
}
Expand All @@ -158,7 +157,7 @@ public void inventoryClick(InventoryClickEvent event) {
else if (event.getClick().isShiftClick() && item != null && isArmor(item)) {
ItemStack currentItem = player.getInventory().getArmorContents()[getArmorTypeNumber(item)];
if (currentItem == null || currentItem.getType() == Material.AIR) {
if (playerEquipsArmorEvent(player, item)) {
if (playerEquipsArmorEvent(player, item, "INVENTORY")) {
event.setCancelled(true);
return;
}
Expand All @@ -180,7 +179,7 @@ public void inventoryDrag(InventoryDragEvent event) {
if (slots.contains(slot) && (slot-5 == getArmorTypeNumber(item))) {
ItemStack before = inventory.getItem(slot);
if (before == null || before.getType() == Material.AIR) {
if (playerEquipsArmorEvent(player, item)) {
if (playerEquipsArmorEvent(player, item, "INVENTORY")) {
event.setCancelled(true);
return;
}
Expand All @@ -201,14 +200,41 @@ public void playerInteract(PlayerInteractEvent event) {
ItemStack currentItem = event.getPlayer().getInventory().getArmorContents()[getArmorTypeNumber(item)];
if (currentItem == null || currentItem.getType() == Material.AIR) {
Player player = event.getPlayer();
if (playerEquipsArmorEvent(player, item)) {
if (playerEquipsArmorEvent(player, item, "INTERACT")) {
event.setCancelled(true);
return;
}
}
}
}

@EventHandler
public void entityDamage(EntityDamageEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof Player))
return;
final Player player = (Player) entity;
final ItemStack[] oldArmor = player.getInventory().getArmorContents();
new BukkitRunnable() {
@Override
public void run() {
ItemStack[] newArmor = player.getInventory().getArmorContents();
for (int i = 0; i < 4; i++) {
ItemStack o = oldArmor[i];
ItemStack n = newArmor[i];
if (o != null) {
if (n == null || !n.equals(o)) {
if (playerUnequipsArmorEvent(player, o, "BREAK")) {
newArmor[i] = o;
}
}
}
player.getInventory().setArmorContents(newArmor);
}
}
}.runTaskLater(DenizenAPI.getCurrentInstance(), 1);
}

private boolean isArmor(ItemStack itemStack) {
int id = itemStack.getTypeId();
return id >= 298 && id <= 317;
Expand Down Expand Up @@ -291,25 +317,27 @@ private boolean isInteractive(Material material) {

// <--[event]
// @Events
// player equips armor
// player equips <item>
// player equips [helmet/chestplate/leggings/boots]
// player (un)equips armor
// player (un)equips <item>
// player (un)equips [helmet/chestplate/leggings/boots]
//
// @Regex on player equips (m@|i@)?\w+
// @Regex on player (un)equips (m@|i@)?\w+
//
// @Triggers when a player equips armor.
// @Triggers when a player (un)equips armor.
// @Context
// <context.armor> returns the dItem that was equipped.
// <context.armor> returns the dItem that was (un)equipped.
// <context.reason> returns the reason that the armor was (un)equipped. Can be "INVENTORY", "INTERACT", "DISPENSER", or "BREAK".
//
// @Determine
// "CANCELLED" to stop the armor from being equipped.
// "CANCELLED" to stop the armor from being (un)equipped.
// -->
private boolean playerEquipsArmorEvent(final Player player, final ItemStack item) {
private boolean playerEquipsArmorEvent(final Player player, final ItemStack item, String reason) {

dItem armor = new dItem(item);

Map<String, dObject> context = new HashMap<String, dObject>();
context.put("armor", armor);
context.put("reason", new Element(reason));

String determination = EventManager.doEvents(Arrays.asList
("player equips armor",
Expand All @@ -332,27 +360,13 @@ public void run() {

}

// <--[event]
// @Events
// player unequips armor
// player unequips <item>
// player unequips [helmet/chestplate/leggings/boots]
//
// @Regex on player unequips (m@|i@)?\w+
//
// @Triggers when a player unequips armor.
// @Context
// <context.armor> returns the dItem that was unequipped.
//
// @Determine
// "CANCELLED" to stop the armor from being unequipped.
// -->
private boolean playerUnequipsArmorEvent(final Player player, final ItemStack item) {
private boolean playerUnequipsArmorEvent(final Player player, final ItemStack item, String reason) {

dItem armor = new dItem(item);

Map<String, dObject> context = new HashMap<String, dObject>();
context.put("armor", armor);
context.put("reason", new Element(reason));

String determination = EventManager.doEvents(Arrays.asList
("player unequips armor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ else if (arg.matchesPrefix("mobnames, mn")) {
dB.echoError("Missing TYPE argument! Valid: NPC, ENTITY, PLAYER, GROUP");
cancel();
}
else if (type == KillType.NPC && Depends.citizens == null) {
dB.echoError("Invalid TYPE argument 'NPC': Citizens2 is not enabled.");
cancel();
}

// At this point, constructed() is called.
}
Expand Down Expand Up @@ -267,7 +271,7 @@ else if (type == KillType.NPC) {
else if (type == KillType.PLAYER) {
// Check to make sure entity is a Player, and not a NPC
if (event.getEntityType() != EntityType.PLAYER) return;
if (CitizensAPI.getNPCRegistry().isNPC(event.getEntity())) return;
if (Depends.citizens != null && CitizensAPI.getNPCRegistry().isNPC(event.getEntity())) return;

// Get player killed
dPlayer player = dPlayer.mirrorBukkitPlayer((Player) event.getEntity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void standInternal() {
}

/**
* Makes the NPC sit a the specified location
* Makes the NPC sit at the specified location
*
* @param location where to sit
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void toSleep() {
}

/**
* Makes the NPC sleep a the specified location
* Makes the NPC sleep at the specified location
*
* @param location where to sleep at
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/Duration.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ else if (attribute.startsWith("second"))
// @attribute <d@duration.type>
// @returns Element
// @description
// Always returns 'Duration' for Duration objects. All objects fetchable by the Object Fetcher will return a the
// Always returns 'Duration' for Duration objects. All objects fetchable by the Object Fetcher will return the
// type of object that is fulfilling this attribute.
// -->
if (attribute.startsWith("type")) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
// @attribute <el@element.type>
// @returns Element
// @description
// Always returns 'Element' for Element objects. All objects fetchable by the Object Fetcher will return a the
// Always returns 'Element' for Element objects. All objects fetchable by the Object Fetcher will return the
// type of object that is fulfilling this attribute.
// -->
if (attribute.startsWith("type")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static <T extends dObject> T getObjectFrom(Class<T> dClass, String value)
return getObjectFrom(dClass, value, null, null);
}

public static List<String> SeparateProperties(String input) {
public static List<String> separateProperties(String input) {
if (input.indexOf('[') == -1 || input.lastIndexOf(']') != input.length() - 1)
return null;
ArrayList<String> output = new ArrayList<String>();
Expand Down Expand Up @@ -155,7 +155,7 @@ else if (input.charAt(i) == ']' && brackets > 0) {

public static <T extends dObject> T getObjectFrom(Class<T> dClass, String value, dPlayer player, dNPC npc) {
try {
List<String> matches = SeparateProperties(value);
List<String> matches = separateProperties(value);
boolean matched = matches != null && Adjustable.class.isAssignableFrom(dClass);
T gotten = (T) ((dClass.equals(dItem.class)) ? dItem.valueOf(matched ? matches.get(0): value, player, npc):
valueof.get(dClass).invoke(null, matched ? matches.get(0): value));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public String getAttribute(Attribute attribute) {
// @attribute <ch@chunk.type>
// @returns Element
// @description
// Always returns 'Chunk' for dChunk objects. All objects fetchable by the Object Fetcher will return a the
// Always returns 'Chunk' for dChunk objects. All objects fetchable by the Object Fetcher will return the
// type of object that is fulfilling this attribute.
// -->
if (attribute.startsWith("type")) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public String getAttribute(Attribute attribute) {
// @attribute <co@color.type>
// @returns Element
// @description
// Always returns 'Color' for dColor objects. All objects fetchable by the Object Fetcher will return a the
// Always returns 'Color' for dColor objects. All objects fetchable by the Object Fetcher will return the
// type of object that is fulfilling this attribute.
// -->
if (attribute.startsWith("type")) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/aufdemrand/denizen/objects/dCuboid.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.aufdemrand.denizen.utilities.blocks.SafeBlock;
import net.aufdemrand.denizen.utilities.debugging.dB;

import net.aufdemrand.denizen.utilities.depends.Depends;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -902,7 +903,7 @@ public String getAttribute(Attribute attribute) {
// @description
// Gets a list of all NPCs currently within the dCuboid.
// -->
if (attribute.startsWith("list_npcs")) {
if (attribute.startsWith("list_npcs") && Depends.citizens != null) {
ArrayList<dNPC> npcs = new ArrayList<dNPC>();
for (NPC npc : CitizensAPI.getNPCRegistry()) {
dNPC dnpc = dNPC.mirrorCitizensNPC(npc);
Expand Down Expand Up @@ -953,7 +954,7 @@ public String getAttribute(Attribute attribute) {
ArrayList<dEntity> entities = new ArrayList<dEntity>();
for (Entity ent : getWorld().getLivingEntities()) {
if (ent.isValid() && isInsideCuboid(ent.getLocation())
&& !CitizensAPI.getNPCRegistry().isNPC(ent))
&& (Depends.citizens == null || !CitizensAPI.getNPCRegistry().isNPC(ent)))
entities.add(new dEntity(ent));
}
return new dList(entities).getAttribute(attribute.fulfill(1));
Expand Down Expand Up @@ -1039,7 +1040,7 @@ public String getAttribute(Attribute attribute) {
// @attribute <cu@cuboid.type>
// @returns Element
// @description
// Always returns 'Cuboid' for dCuboid objects. All objects fetchable by the Object Fetcher will return a the
// Always returns 'Cuboid' for dCuboid objects. All objects fetchable by the Object Fetcher will return the
// type of object that is fulfilling this attribute.
// -->
if (attribute.startsWith("type")) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ public String getAttribute(Attribute attribute) {
// @attribute <e@entity.type>
// @returns Element
// @description
// Always returns 'Entity' for dEntity objects. All objects fetchable by the Object Fetcher will return a the
// Always returns 'Entity' for dEntity objects. All objects fetchable by the Object Fetcher will return the
// type of object that is fulfilling this attribute.
// -->
if (attribute.startsWith("type")) {
Expand Down

0 comments on commit acbf273

Please sign in to comment.