Skip to content

Commit

Permalink
Add BukkitScriptEntryData
Browse files Browse the repository at this point in the history
Part of moving ScriptEntry to the core
  • Loading branch information
mcmonkey4eva committed Nov 5, 2014
1 parent 53e5257 commit bba8d04
Show file tree
Hide file tree
Showing 95 changed files with 470 additions and 358 deletions.
52 changes: 52 additions & 0 deletions src/main/java/net/aufdemrand/denizen/BukkitScriptEntryData.java
@@ -0,0 +1,52 @@
package net.aufdemrand.denizen;

import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;
import net.citizensnpcs.api.CitizensAPI;

public class BukkitScriptEntryData extends ScriptEntryData {
private dPlayer player;
private dNPC npc;

public BukkitScriptEntryData(dPlayer player, dNPC npc) {
this.player = player;
this.npc = npc;
}

public dPlayer getPlayer() {
return player;
}

public dNPC getNPC() {
return npc;
}

public boolean hasNPC() {
return npc != null;
}

public boolean hasPlayer() {
return player != null;
}

public void setPlayer(dPlayer player) {
if (player != null && player.isOnline() && Depends.citizens != null
&& CitizensAPI.getNPCRegistry().isNPC(player.getPlayerEntity())) {
dontFixMe = true;
setNPC(new dNPC(CitizensAPI.getNPCRegistry().getNPC(player.getPlayerEntity())));
}
else
this.player = player;
}

private boolean dontFixMe = false;

public void setNPC(dNPC npc) {
if (npc == null && dontFixMe) {
dontFixMe = false;
}
this.npc = npc;
}
}
Expand Up @@ -9,7 +9,6 @@
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;

import java.util.Arrays;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/net/aufdemrand/denizen/npc/speech/DenizenChat.java
@@ -1,5 +1,6 @@
package net.aufdemrand.denizen.npc.speech;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.Settings;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.scripts.ScriptEntry;
Expand Down Expand Up @@ -51,14 +52,14 @@ public void talk(SpeechContext speechContext) {

// Chat to the world using Denizen chat settings
if (!context.hasRecipients()) {
String text = TagManager.tag(entry.getPlayer(), entry.getNPC(), Settings.chatNoTargetFormat(), false, entry);
String text = TagManager.tag(((BukkitScriptEntryData)entry.entryData).getPlayer(), ((BukkitScriptEntryData)entry.entryData).getNPC(), Settings.chatNoTargetFormat(), false, entry);
talkToBystanders(talker, text, context);
}

// Single recipient
else if (context.size() <= 1) {
// Send chat to target
String text = TagManager.tag(entry.getPlayer(), entry.getNPC(), Settings.chatToTargetFormat(), false, entry);
String text = TagManager.tag(((BukkitScriptEntryData)entry.entryData).getPlayer(), ((BukkitScriptEntryData)entry.entryData).getNPC(), Settings.chatToTargetFormat(), false, entry);
for (Talkable entity : context) {
entity.talkTo(context, text, this);
}
Expand All @@ -68,7 +69,7 @@ else if (context.size() <= 1) {
if (queue.hasDefinition("target"))
defTarget = queue.getDefinition("target");
queue.addDefinition("target", new dEntity(context.iterator().next().getEntity()).identify());
String bystanderText = TagManager.tag(entry.getPlayer(), entry.getNPC(),
String bystanderText = TagManager.tag(((BukkitScriptEntryData)entry.entryData).getPlayer(), ((BukkitScriptEntryData)entry.entryData).getNPC(),
Settings.chatWithTargetToBystandersFormat(), false, entry);
talkToBystanders(talker, bystanderText, context);
if (defTarget != null)
Expand All @@ -79,7 +80,7 @@ else if (context.size() <= 1) {
// Multiple recipients
else {
// Send chat to targets
String text = TagManager.tag(entry.getPlayer(), entry.getNPC(), Settings.chatToTargetFormat(), false, entry);
String text = TagManager.tag(((BukkitScriptEntryData)entry.entryData).getPlayer(), ((BukkitScriptEntryData)entry.entryData).getNPC(), Settings.chatToTargetFormat(), false, entry);
for (Talkable entity : context) {
entity.talkTo(context, text, this);
}
Expand All @@ -98,14 +99,14 @@ else if (context.size() <= 1) {
parsed.append(format[i]).append(new dEntity(iter.next().getEntity()).getName());
i++;
}
String targets = TagManager.tag(entry.getPlayer(), entry.getNPC(), parsed.toString(), false, entry);
String targets = TagManager.tag(((BukkitScriptEntryData)entry.entryData).getPlayer(), ((BukkitScriptEntryData)entry.entryData).getNPC(), parsed.toString(), false, entry);

String defTargets = null;
if (queue.hasDefinition("targets"))
defTargets = queue.getDefinition("targets");
queue.addDefinition("targets", targets);

String bystanderText = TagManager.tag(entry.getPlayer(), entry.getNPC(),
String bystanderText = TagManager.tag(((BukkitScriptEntryData)entry.entryData).getPlayer(), ((BukkitScriptEntryData)entry.entryData).getNPC(),
Settings.chatWithTargetsToBystandersFormat(), false, entry);
talkToBystanders(talker, bystanderText, context);

Expand Down
Expand Up @@ -5,13 +5,11 @@
import net.aufdemrand.denizen.utilities.entity.CraftFakeArrow;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.util.PlayerAnimation;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/aufdemrand/denizen/objects/dList.java
@@ -1,5 +1,6 @@
package net.aufdemrand.denizen.objects;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.flags.FlagManager;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.objects.properties.PropertyParser;
Expand Down Expand Up @@ -246,8 +247,8 @@ public <T extends dObject> List<T> filter(Class<T> dClass, ScriptEntry entry) {
if (ObjectFetcher.checkMatch(dClass, element)) {

T object = ObjectFetcher.getObjectFrom(dClass, element,
(entry != null ? entry.getPlayer(): null),
(entry != null ? entry.getNPC(): null));
(entry != null ? ((BukkitScriptEntryData)entry.entryData).getPlayer(): null),
(entry != null ? ((BukkitScriptEntryData)entry.entryData).getNPC(): null));

// Only add the object if it is not null, thus filtering useless
// list items
Expand Down Expand Up @@ -967,7 +968,7 @@ public int compare(String o1, String o2) {
Collections.sort(list, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
List<ScriptEntry> entries = script.getBaseEntries(entry.getPlayer(), entry.getNPC());
List<ScriptEntry> entries = script.getBaseEntries(((BukkitScriptEntryData)entry.entryData).getPlayer(), ((BukkitScriptEntryData)entry.entryData).getNPC());
if (entries.isEmpty()) {
return 0;
}
Expand Down
Expand Up @@ -24,7 +24,6 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.block.Skull;

import java.util.*;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dNPC.java
Expand Up @@ -34,7 +34,6 @@
import net.citizensnpcs.util.Pose;

import net.minecraft.server.v1_7_R4.EntityLiving;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftLivingEntity;
Expand Down
Expand Up @@ -6,11 +6,9 @@
import net.aufdemrand.denizen.objects.dObject;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.tags.Attribute;
import org.bukkit.Rotation;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.Villager;

public class EntityRotation implements Property {

Expand Down
45 changes: 18 additions & 27 deletions src/main/java/net/aufdemrand/denizen/scripts/ScriptEntry.java
Expand Up @@ -2,6 +2,7 @@

import java.util.*;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.exceptions.ScriptEntryCreationException;
import net.aufdemrand.denizen.objects.Element;
Expand All @@ -12,14 +13,13 @@
import net.aufdemrand.denizen.objects.dScript;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.scripts.commands.BracedCommand;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;
import net.aufdemrand.denizencore.scripts.commands.Holdable;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.scripts.queues.ScriptQueue;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizencore.utilities.debugging.Debuggable;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.citizensnpcs.api.CitizensAPI;


/**
Expand All @@ -45,8 +45,7 @@ public class ScriptEntry implements Cloneable, Debuggable {
private boolean waitfor = false;

// 'Attached' core context
private dPlayer player = null;
private dNPC npc = null;
public ScriptEntryData entryData;
private dScript script = null;
private ScriptQueue queue = null;

Expand All @@ -69,6 +68,7 @@ public void setBracedSet(LinkedHashMap<String, ArrayList<ScriptEntry>> set) {
public ScriptEntry clone() throws CloneNotSupportedException {
ScriptEntry se = (ScriptEntry) super.clone();
se.objects = new HashMap<String, Object>();
se.entryData = (ScriptEntryData)entryData.clone();
return se;
}

Expand Down Expand Up @@ -258,8 +258,8 @@ public void setData(Object result) {
}

public void copyFrom(ScriptEntry entry) {
setPlayer(entry.getPlayer());
setNPC(entry.getNPC());
setPlayer(((BukkitScriptEntryData)entry.entryData).getPlayer());
setNPC(((BukkitScriptEntryData)entry.entryData).getNPC());
setSendingQueue(entry.getResidingQueue());
}

Expand Down Expand Up @@ -325,46 +325,37 @@ public boolean hasObject(String key) {
*
* @return the NPC linked to this script entry
*/
@Deprecated
public dNPC getNPC() {
return npc;
return ((BukkitScriptEntryData)entryData).getNPC();
}


@Deprecated
public boolean hasNPC() {
return (npc != null);
return ((BukkitScriptEntryData)entryData).hasNPC();
}


private boolean dontFixMe = false;

@Deprecated
public ScriptEntry setNPC(dNPC dNPC) {
if (dNPC == null && dontFixMe) {
dontFixMe = false;
return this;
}
this.npc = dNPC;
((BukkitScriptEntryData)entryData).setNPC(dNPC);
return this;
}


@Deprecated
public dPlayer getPlayer() {
return player;
return ((BukkitScriptEntryData)entryData).getPlayer();
}


@Deprecated
public boolean hasPlayer() {
return (player != null);
return ((BukkitScriptEntryData)entryData).hasPlayer();
}


@Deprecated
public ScriptEntry setPlayer(dPlayer player) {
if (player != null && player.isOnline() && Depends.citizens != null
&& CitizensAPI.getNPCRegistry().isNPC(player.getPlayerEntity())) {
dontFixMe = true;
this.npc = new dNPC(CitizensAPI.getNPCRegistry().getNPC(player.getPlayerEntity()));
}
else
this.player = player;
((BukkitScriptEntryData)entryData).setPlayer(player);
return this;
}

Expand Down
Expand Up @@ -7,7 +7,6 @@
import net.aufdemrand.denizencore.DenizenCore;
import net.aufdemrand.denizencore.scripts.ScriptHelper;
import net.aufdemrand.denizencore.utilities.YamlConfiguration;
import org.bukkit.configuration.file.FileConfiguration;

import java.util.*;

Expand Down
Expand Up @@ -15,9 +15,9 @@ public abstract class AbstractCommand extends BaseAbstractCommand {
* should be iterated through and checked before continuing to execute(). Note that
* PLAYER:player_name and NPCID:# arguments are parsed automatically by the Executer
* and should not be handled by this Command otherwise. Their output is stored in the
* attached {@link ScriptEntry} and can be retrieved with scriptEntry.getPlayer(),
* attached {@link ScriptEntry} and can be retrieved with ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(),
* scriptEntry.getOfflinePlayer() (if the player specified is not online), and
* scriptEntry.getNPC(). Remember that any of these have a possibility of being null
* ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(). Remember that any of these have a possibility of being null
* and should be handled accordingly if required by this Command.
*
* @param scriptEntry
Expand Down
Expand Up @@ -2,6 +2,7 @@

import java.util.*;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizencore.exceptions.ScriptEntryCreationException;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.scripts.ScriptEntry;
Expand Down Expand Up @@ -31,7 +32,7 @@ public static LinkedHashMap<String, ArrayList<ScriptEntry>> getBracedCommands(Sc
for (Map.Entry<String, ArrayList<ScriptEntry>> entry: entryBracedSet.entrySet()) {
ArrayList array = new ArrayList(entry.getValue().size());
for (ScriptEntry sEntry: entry.getValue()) {
array.add(sEntry.clone().setPlayer(scriptEntry.getPlayer()).setNPC(scriptEntry.getNPC()));
array.add(sEntry.clone().setPlayer(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer()).setNPC(((BukkitScriptEntryData)scriptEntry.entryData).getNPC()));
}
bracedSections.put(entry.getKey(), array);
}
Expand Down Expand Up @@ -120,8 +121,8 @@ else if (arg.matches("}")) {
bracesSection.add(new ScriptEntry(cmd,
args,
scriptEntry.getScript() != null ? scriptEntry.getScript().getContainer() : null));
bracesSection.get(bracesSection.size() - 1).setPlayer(scriptEntry.getPlayer());
bracesSection.get(bracesSection.size() - 1).setNPC(scriptEntry.getNPC());
bracesSection.get(bracesSection.size() - 1).setPlayer(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer());
bracesSection.get(bracesSection.size() - 1).setNPC(((BukkitScriptEntryData)scriptEntry.entryData).getNPC());
if (hyperdebug) dB.echoDebug(scriptEntry, "Command added: " + cmd + ", with " + String.valueOf(args.length) + " arguments");
} catch (ScriptEntryCreationException e) {
if (hyperdebug) dB.echoError(scriptEntry.getResidingQueue(), e.getMessage());
Expand Down

0 comments on commit bba8d04

Please sign in to comment.