Skip to content

Commit

Permalink
dObject work
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Jun 13, 2013
1 parent 37593c9 commit 26c12ac
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 131 deletions.
@@ -1,7 +1,7 @@
package net.aufdemrand.denizen.interfaces;

/**
* Container interface for instances loaded into a DenizenRegistry.
* Container interface for instances loaded into a dRegistry.
*
* @author Jeremy Schroeder
*
Expand Down
@@ -1,6 +1,6 @@
package net.aufdemrand.denizen.interfaces;

public interface ExternalDenizenClass {
public interface dExternal {

/**
* Called by the RuntimeCompiler after an 'External Dependency' is compiled and loaded.
Expand Down
Expand Up @@ -10,7 +10,7 @@
*
*/

public interface DenizenRegistry {
public interface dRegistry {

/**
* Called by an AbstractInstance to get added to the registry.
Expand Down
Expand Up @@ -3,7 +3,7 @@
import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.events.ListenerCancelEvent;
import net.aufdemrand.denizen.events.ListenerFinishEvent;
import net.aufdemrand.denizen.interfaces.DenizenRegistry;
import net.aufdemrand.denizen.interfaces.dRegistry;
import net.aufdemrand.denizen.interfaces.RegistrationableInstance;
import net.aufdemrand.denizen.listeners.core.*;
import net.aufdemrand.denizen.objects.dNPC;
Expand All @@ -14,8 +14,6 @@
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.citizensnpcs.api.CitizensAPI;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
Expand All @@ -26,7 +24,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class ListenerRegistry implements DenizenRegistry, Listener {
public class ListenerRegistry implements dRegistry, Listener {

private Map<String, Map<String, AbstractListener>> listeners = new ConcurrentHashMap<String, Map<String, AbstractListener>>();
private Map<String, AbstractListenerType> types = new ConcurrentHashMap<String, AbstractListenerType>();
Expand Down
@@ -1,7 +1,7 @@
package net.aufdemrand.denizen.npc.activities;

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.interfaces.DenizenRegistry;
import net.aufdemrand.denizen.interfaces.dRegistry;
import net.aufdemrand.denizen.interfaces.RegistrationableInstance;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.npc.activities.core.TaskActivity;
Expand All @@ -13,7 +13,7 @@
import java.util.Map;
import java.util.logging.Level;

public class ActivityRegistry implements DenizenRegistry {
public class ActivityRegistry implements dRegistry {

public final Denizen denizen;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/npc/dNPCRegistry.java
Expand Up @@ -96,7 +96,7 @@ public Set<dNPC> getSpawnedNPCs() {
while (it.hasNext()) {
Map.Entry<Integer, dNPC> npc = it.next();
if (npc.getValue().getCitizen() == null) {
dB.log(ChatColor.RED + "Removed NPC from DenizenRegistry.");
dB.log(ChatColor.RED + "Removed NPC from dRegistry.");
try { denizenNPCs.remove(npc.getKey()); } catch (Exception e) { dB.echoDebug("Report this error to aufdemrand! Err: posconcurrency1"); }
}
else if (npc.getValue().isSpawned())
Expand Down
32 changes: 28 additions & 4 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -364,10 +364,29 @@ public String getAttribute(Attribute attribute) {
return "null";
}

if (attribute.startsWith("name"))
return new Element(entity.getCustomName()).getAttribute(attribute.fulfill(1));

if (attribute.startsWith("type")) {

if (attribute.startsWith("custom_name")) {
if (entity.getCustomName() == null) return "null";
return new Element(entity.getCustomName()).getAttribute(attribute.fulfill(2));
}

if (attribute.startsWith("name")) {
if (CitizensAPI.getNPCRegistry().isNPC(entity))
return new Element(CitizensAPI.getNPCRegistry().getNPC(entity).getName())
.getAttribute(attribute.fulfill(1));
if (entity instanceof Player)
return new Element(((Player) entity).getName())
.getAttribute(attribute.fulfill(1));
return new Element(entity.getType().getName())
.getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("entity_type"))
return new Element(entity.getType().getName())
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("custom_id")) {
if (CustomNBT.hasCustomNBT(getBukkitEntity(), "denizen-script-id"))
return new dScript(CustomNBT.getCustomNBT(getBukkitEntity(), "denizen-script-id"))
.getAttribute(attribute.fulfill(1));
Expand Down Expand Up @@ -415,6 +434,10 @@ else if ((float) entity.getHealth() / maxHealth < 1)
.getAttribute(attribute.fulfill(2));
}

if (attribute.startsWith("health.max"))
return new Element(String.valueOf(entity.getMaxHealth()))
.getAttribute(attribute.fulfill(2));

if (attribute.startsWith("health"))
return new Element(String.valueOf(entity.getHealth()))
.getAttribute(attribute.fulfill(1));
Expand Down Expand Up @@ -464,7 +487,8 @@ else if ((float) entity.getHealth() / maxHealth < 1)
}

if (attribute.startsWith("world")) {
// Add world dScriptArg
return new dWorld(entity.getWorld())
.getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("prefix"))
Expand Down
89 changes: 1 addition & 88 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -272,17 +272,6 @@ public String getAttribute(Attribute attribute) {
if (attribute.startsWith("name"))
return new Element(player_name).getAttribute(attribute.fulfill(1));

if (attribute.startsWith("location.cursor_on")) {
int range = attribute.getIntContext(2);
if (range < 1) range = 50;
return new dLocation(getPlayerEntity().getTargetBlock(null, range).getLocation())
.getAttribute(attribute.fulfill(2));
}

if (attribute.startsWith("location.standing_on"))
return new dLocation(getPlayerEntity().getLocation().add(0, -1, 0))
.getAttribute(attribute.fulfill(2));

if (attribute.startsWith("location.compass_target"))
return new dLocation(getPlayerEntity().getCompassTarget())
.getAttribute(attribute.fulfill(2));
Expand All @@ -291,34 +280,6 @@ public String getAttribute(Attribute attribute) {
return new dLocation(getPlayerEntity().getLocation())
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("health.formatted")) {
int maxHealth = getPlayerEntity().getMaxHealth();
if (attribute.hasContext(2))
maxHealth = attribute.getIntContext(2);
if ((float) getPlayerEntity().getHealth() / maxHealth < .10)
return new Element("dying").getAttribute(attribute.fulfill(2));
else if ((float) getPlayerEntity().getHealth() / maxHealth < .40)
return new Element("seriously wounded").getAttribute(attribute.fulfill(2));
else if ((float) getPlayerEntity().getHealth() / maxHealth < .75)
return new Element("injured").getAttribute(attribute.fulfill(2));
else if ((float) getPlayerEntity().getHealth() / maxHealth < 1)
return new Element("scraped").getAttribute(attribute.fulfill(2));

else return new Element("healthy").getAttribute(attribute.fulfill(2));
}

if (attribute.startsWith("health.percentage")) {
int maxHealth = getPlayerEntity().getMaxHealth();
if (attribute.hasContext(2))
maxHealth = attribute.getIntContext(2);
return new Element(String.valueOf(((float) getPlayerEntity().getHealth() / maxHealth) * 100))
.getAttribute(attribute.fulfill(2));
}

if (attribute.startsWith("health"))
return new Element(String.valueOf(getPlayerEntity().getHealth()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("food_level.formatted")) {
int maxHunger = getPlayerEntity().getMaxHealth();
if (attribute.hasContext(2))
Expand Down Expand Up @@ -395,10 +356,6 @@ else if ((float) getPlayerEntity().getFoodLevel() / maxHunger < 1)
return new Element(String.valueOf(getPlayerEntity().isSprinting()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("is_inside_vehicle"))
return new Element(String.valueOf(getPlayerEntity().isInsideVehicle()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("gamemode.id"))
return new Element(String.valueOf(getPlayerEntity().getGameMode().getValue()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -411,22 +368,6 @@ else if ((float) getPlayerEntity().getFoodLevel() / maxHunger < 1)
return new dItem(getPlayerEntity().getItemOnCursor())
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("killer"))
return new dPlayer(getPlayerEntity().getKiller())
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("last_damage_cause"))
return new Element(String.valueOf(getPlayerEntity().getLastDamageCause().getCause().toString()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("last_damage"))
return new Element(String.valueOf(getPlayerEntity().getLastDamage()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("time_lived"))
return new Duration(getPlayerEntity().getTicksLived() / 20)
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("allowed_flight"))
return new Element(String.valueOf(getPlayerEntity().getAllowFlight()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -435,22 +376,6 @@ else if ((float) getPlayerEntity().getFoodLevel() / maxHunger < 1)
return new Element(String.valueOf(getPlayerEntity().getAddress().getHostName()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("can_pickup_items"))
return new Element(String.valueOf(getPlayerEntity().getCanPickupItems()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("entity_id"))
return new Element(String.valueOf(getPlayerEntity().getEntityId()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("fall_distance"))
return new Element(String.valueOf(getPlayerEntity().getFallDistance()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("uuid"))
return new Element(String.valueOf(getPlayerEntity().getUniqueId().toString()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("time_asleep"))
return new Duration(getPlayerEntity().getSleepTicks() / 20)
.getAttribute(attribute.fulfill(1));
Expand All @@ -463,18 +388,6 @@ else if ((float) getPlayerEntity().getFoodLevel() / maxHunger < 1)
return new Element(String.valueOf(getPlayerEntity().getPlayerTimeOffset()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("has_effect")) {
// Add later
}

if (attribute.startsWith("equipment")) {
// Add later
}

if (attribute.startsWith("world")) {
// Add world dScriptArg
}

if (attribute.startsWith("prefix"))
return new Element(prefix)
.getAttribute(attribute.fulfill(1));
Expand All @@ -495,7 +408,7 @@ else if ((float) getPlayerEntity().getFoodLevel() / maxHunger < 1)
.getAttribute(attribute.fulfill(1));
}

return new Element(identify()).getAttribute(attribute.fulfill(0));
return new dEntity(getPlayerEntity()).getAttribute(attribute.fulfill(0));
}

}
35 changes: 18 additions & 17 deletions src/main/java/net/aufdemrand/denizen/objects/dWorld.java
Expand Up @@ -110,23 +110,24 @@ public String getAttribute(Attribute attribute) {

if (attribute == null) return null;

// getWorld().canGenerateStructures())
// .getAttribute(attribute.fulfill(1));
//
// getWorld().getName())
// .getAttribute(attribute.fulfill(1));
//
// getWorld().getAllowAnimals())
// .getAttribute(attribute.fulfill(1));
//
// getWorld().getAllowMonsters())
// .getAttribute(attribute.fulfill(1));
//
// getWorld().getAmbientSpawnLimit())
// .getAttribute(attribute.fulfill(1));
//
// getWorld().getAnimalSpawnLimit())
// .getAttribute(attribute.fulfill(1));
if (attribute.startsWith("can_generate_structures"))
return new Element(String.valueOf(getWorld().canGenerateStructures()))
.getAttribute(attribute.fulfill(1));

getWorld().getName())
.getAttribute(attribute.fulfill(1));

getWorld().getAllowAnimals())
.getAttribute(attribute.fulfill(1));

getWorld().getAllowMonsters())
.getAttribute(attribute.fulfill(1));

getWorld().getAmbientSpawnLimit())
.getAttribute(attribute.fulfill(1));

getWorld().getAnimalSpawnLimit())
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("highest_block")) {
// TODO: finish
Expand Down
Expand Up @@ -4,7 +4,7 @@
import java.util.Map;

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.interfaces.DenizenRegistry;
import net.aufdemrand.denizen.interfaces.dRegistry;
import net.aufdemrand.denizen.interfaces.RegistrationableInstance;
import net.aufdemrand.denizen.scripts.commands.core.*;
import net.aufdemrand.denizen.scripts.commands.item.*;
Expand All @@ -17,7 +17,7 @@
import net.aufdemrand.denizen.scripts.commands.world.*;
import net.aufdemrand.denizen.utilities.debugging.dB;

public class CommandRegistry implements DenizenRegistry {
public class CommandRegistry implements dRegistry {

public Denizen denizen;

Expand Down
@@ -1,15 +1,15 @@
package net.aufdemrand.denizen.scripts.requirements;

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.interfaces.DenizenRegistry;
import net.aufdemrand.denizen.interfaces.dRegistry;
import net.aufdemrand.denizen.interfaces.RegistrationableInstance;
import net.aufdemrand.denizen.scripts.requirements.core.*;
import net.aufdemrand.denizen.utilities.debugging.dB;

import java.util.HashMap;
import java.util.Map;

public class RequirementRegistry implements DenizenRegistry {
public class RequirementRegistry implements dRegistry {

public Denizen denizen;

Expand Down
@@ -1,8 +1,6 @@
package net.aufdemrand.denizen.scripts.triggers;

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.Settings;
import net.aufdemrand.denizen.interfaces.DenizenRegistry;
import net.aufdemrand.denizen.interfaces.dRegistry;
import net.aufdemrand.denizen.interfaces.RegistrationableInstance;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.triggers.core.ChatTrigger;
Expand All @@ -11,13 +9,12 @@
import net.aufdemrand.denizen.scripts.triggers.core.ProximityTrigger;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.entity.Player;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TriggerRegistry implements DenizenRegistry {
public class TriggerRegistry implements dRegistry {

////////
// Registry
Expand Down
Expand Up @@ -8,7 +8,7 @@
import java.util.List;

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.interfaces.ExternalDenizenClass;
import net.aufdemrand.denizen.interfaces.dExternal;
import net.aufdemrand.denizen.utilities.debugging.dB;

import org.abstractmeta.toolbox.compilation.compiler.JavaSourceCompiler;
Expand Down Expand Up @@ -59,8 +59,8 @@ public void loader() {
try {
compilationUnit.addJavaSource(fileName.replace(".java", ""), readFile(f.getAbsolutePath()));
ClassLoader classLoader = javaSourceCompiler.compile(compilationUnit);
Class<ExternalDenizenClass> load = (Class<ExternalDenizenClass>) classLoader.loadClass(fileName.replace(".java", ""));
ExternalDenizenClass loadedClass = load.newInstance();
Class<dExternal> load = (Class<dExternal>) classLoader.loadClass(fileName.replace(".java", ""));
dExternal loadedClass = load.newInstance();
loadedClass.load();
} catch (Exception e) {
if (e instanceof IllegalStateException)
Expand Down

0 comments on commit 26c12ac

Please sign in to comment.