Skip to content

Commit

Permalink
Fix CommandExecuter error, change some things in Entity events
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Aug 17, 2013
1 parent 8410fdd commit 12a9ada
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
Expand Up @@ -106,24 +106,26 @@ public boolean execute(ScriptEntry scriptEntry) {
m.appendTail(sb);
arg = aH.Argument.valueOf(sb.toString());

dPlayer player = scriptEntry.getPlayer();
dNPC npc = scriptEntry.getNPC();

// Fill player/off-line player
if (arg.matchesPrefix("player")) {
dB.echoDebug("...replacing the linked player.");
String value = TagManager.tag(scriptEntry.getPlayer(), scriptEntry.getNPC(), arg.getValue(), false);
if (!dPlayer.valueOf(arg.getValue()).isValid()) {
dB.echoError(arg.getValue() + " is an invalid player!");
String value = TagManager.tag(player, npc, arg.getValue(), false);
if (!player.isValid()) {
dB.echoError(value + " is an invalid player!");
return false;
}
scriptEntry.setPlayer(dPlayer.valueOf(value));
scriptEntry.setPlayer(player);
}

// Fill NPCID/NPC argument
else if (arg.matchesPrefix("npc, npcid")) {
dB.echoDebug("...replacing the linked NPC.");
String value = TagManager.tag(scriptEntry.getPlayer(), scriptEntry.getNPC(), arg.getValue(), false);
if (!dNPC.valueOf(arg.getValue()).isValid()) {
dB.echoError(arg.getValue() + " is an invalid NPC!");
String value = TagManager.tag(player, npc, arg.getValue(), false);
if (!npc.isValid()) {
dB.echoError(value + " is an invalid NPC!");
return false;
}
scriptEntry.setNPC(dNPC.valueOf(value));
Expand Down
Expand Up @@ -138,7 +138,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
+ (index > 0 ? aH.debugObj("Index", String.valueOf(index)) : "")
+ aH.debugUniqueObj("Action/Value", action.toString(), (value != null ? value : "null"))
+ (duration.getSeconds() > 0 ? duration.debug() : "")
+ aH.debugObj("Target", (target != null ? (target.isNPC() ? target.getNPC() : target.isPlayer() ? target.getPlayer() : target.getType()) : "Server")));
+ aH.debugObj("Target", (target != null ? (target.isNPC() ? target.getNPC().getId() : target.isPlayer() ? target.getPlayer().getName() : target.getType()) : "Server")));

Flag flag = null;

Expand Down
Expand Up @@ -524,26 +524,25 @@ public void entityDamage(EntityDamageEvent event) {

Map<String, Object> context = new HashMap<String, Object>();
boolean isFatal = false;
Entity entity = event.getEntity();
String entityType = entity.getType().name();
dEntity entity = new dEntity(event.getEntity());
String entityType = entity.getType();
String cause = event.getCause().name();

String determination;

Player player = null;
dPlayer player = null;
dNPC npc = null;

if (CitizensAPI.getNPCRegistry().isNPC(entity)) {
npc = DenizenAPI.getDenizenNPC(CitizensAPI.getNPCRegistry().getNPC(entity));
context.put("entity", npc);
if (entity.isNPC()) {
context.put("entity", new dNPC(entity.getNPC()));
entityType = "npc";
}
else if (entity instanceof Player) {
player = (Player) entity;
context.put("entity", new dPlayer((Player) entity));
else if (entity.isPlayer()) {
player = new dPlayer(entity.getPlayer());
context.put("entity", new dPlayer(entity.getPlayer()));
}
else {
context.put("entity", new dEntity(entity));
context.put("entity", entity);
}

context.put("damage", new Element(event.getDamage()));
Expand Down Expand Up @@ -576,30 +575,29 @@ else if (entity instanceof Player) {
// like "player damages player" from the one we have for
// "player damaged by player"

Player subPlayer = null;
dPlayer subPlayer = null;
dNPC subNPC = null;

Entity damager = subEvent.getDamager();
String damagerType = damager.getType().name();
dEntity damager = new dEntity(subEvent.getDamager());
String damagerType = damager.getType();

if (CitizensAPI.getNPCRegistry().isNPC(damager)) {
subNPC = DenizenAPI.getDenizenNPC(CitizensAPI.getNPCRegistry().getNPC(entity));
context.put("damager", DenizenAPI.getDenizenNPC
(CitizensAPI.getNPCRegistry().getNPC(damager)));
if (damager.isNPC()) {
subNPC = new dNPC(entity.getNPC());
context.put("damager", new dNPC(damager.getNPC()));
damagerType = "npc";

// If we had no NPC in our regular context, use this one
if (npc == null) npc = subNPC;
}
else if (damager instanceof Player) {
subPlayer = (Player) damager;
else if (damager.isPlayer()) {
subPlayer = new dPlayer(damager.getPlayer());
context.put("damager", new dPlayer((Player) damager));

// If we had no player in our regular context, use this one
if (player == null) player = subPlayer;
}
else {
context.put("damager", new dEntity(damager));
context.put("damager", damager);

if (damager instanceof Projectile) {
if (((Projectile) damager).getShooter() != null)
Expand Down Expand Up @@ -636,7 +634,7 @@ else if (damager instanceof Player) {
subEvents.add(damagerType + " kills " + entityType);
}

determination = doEvents(subEvents, subNPC, subPlayer, context);
determination = doEvents(subEvents, subNPC, subPlayer.getPlayerEntity(), context);

if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
Expand All @@ -647,7 +645,7 @@ else if (Argument.valueOf(determination)
}
}

determination = doEvents(events, npc, player, context);
determination = doEvents(events, npc, player.getPlayerEntity(), context);

if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
Expand Down

0 comments on commit 12a9ada

Please sign in to comment.