Skip to content

Commit

Permalink
flaggable notes (inventory/cuboid/ellipsoid/polygon)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 8, 2021
1 parent 7c759fc commit 18b952e
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 18 deletions.
Expand Up @@ -3,6 +3,9 @@
import com.denizenscript.denizen.objects.notable.NotableManager;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.depends.Depends;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
import com.denizenscript.denizencore.flags.FlaggableObject;
import com.denizenscript.denizencore.flags.SavableMapFlagTracker;
import com.denizenscript.denizencore.objects.*;
import com.denizenscript.denizen.utilities.Settings;
import com.denizenscript.denizencore.objects.core.ElementTag;
Expand All @@ -20,14 +23,16 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.List;

public class CuboidTag implements ObjectTag, Cloneable, Notable, Adjustable, AreaContainmentObject {
public class CuboidTag implements ObjectTag, Cloneable, Notable, Adjustable, AreaContainmentObject, FlaggableObject {

// <--[language]
// @name CuboidTag Objects
Expand Down Expand Up @@ -59,6 +64,7 @@ public CuboidTag clone() {
cuboid = new CuboidTag();
}
cuboid.noteName = null;
cuboid.flagTracker = null;
cuboid.pairs = new ArrayList<>(pairs.size());
for (LocationPair pair : pairs) {
cuboid.pairs.add(new LocationPair(pair.low.clone(), pair.high.clone()));
Expand Down Expand Up @@ -302,6 +308,8 @@ public void regenerate(LocationTag point_1, LocationTag point_2) {

public String noteName = null;

public AbstractFlagTracker flagTracker = null;

/**
* Construct the cuboid without adding pairs
* ONLY use this if addPair will be called immediately after!
Expand Down Expand Up @@ -632,20 +640,25 @@ public boolean isUnique() {

@Override
@Note("Cuboids")
public String getSaveObject() {
return identifyFull().substring(3);
public Object getSaveObject() {
ConfigurationSection section = new YamlConfiguration();
section.set("object", identifyFull());
section.set("flags", flagTracker.toString());
return section;
}

@Override
public void makeUnique(String id) {
CuboidTag toNote = clone();
toNote.noteName = id;
toNote.flagTracker = new SavableMapFlagTracker();
NotableManager.saveAs(toNote, id);
}

@Override
public void forget() {
noteName = null;
flagTracker = null;
NotableManager.remove(this);
}

Expand Down Expand Up @@ -711,12 +724,34 @@ public String toString() {
return identify();
}

@Override
public AbstractFlagTracker getFlagTracker() {
return flagTracker;
}

@Override
public void reapplyTracker(AbstractFlagTracker tracker) {
if (noteName != null) {
this.flagTracker = tracker;
}
}

@Override
public String getReasonNotFlaggable() {
if (noteName == null) {
return "the area is not noted - only noted areas can hold flags";
}
return "unknown reason - something went wrong";
}

/////////////////////
// ObjectTag Tag Management
/////////////////////

public static void registerTags() {

AbstractFlagTracker.registerFlagHandlers(tagProcessor);

// <--[tag]
// @attribute <CuboidTag.random>
// @returns LocationTag
Expand Down
Expand Up @@ -3,6 +3,9 @@
import com.denizenscript.denizen.objects.notable.NotableManager;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.depends.Depends;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
import com.denizenscript.denizencore.flags.FlaggableObject;
import com.denizenscript.denizencore.flags.SavableMapFlagTracker;
import com.denizenscript.denizencore.objects.*;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.ListTag;
Expand All @@ -17,14 +20,16 @@
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.List;

public class EllipsoidTag implements ObjectTag, Notable, Cloneable, AreaContainmentObject {
public class EllipsoidTag implements ObjectTag, Notable, Cloneable, AreaContainmentObject, FlaggableObject {

// <--[language]
// @name EllipsoidTag Objects
Expand Down Expand Up @@ -112,14 +117,14 @@ public static boolean matches(String arg) {
}
@Override
public EllipsoidTag clone() {
if (noteName != null) {
return this;
}
return new EllipsoidTag(center.clone(), size.clone());
}

@Override
public ObjectTag duplicate() {
if (noteName != null) {
return this;
}
return clone();
}

Expand All @@ -142,6 +147,8 @@ public EllipsoidTag(LocationTag center, LocationTag size) {

public String noteName = null;

public AbstractFlagTracker flagTracker = null;

public ListTag getBlocks(Attribute attribute) {
return getBlocks(null, attribute);
}
Expand Down Expand Up @@ -274,20 +281,25 @@ public boolean isUnique() {
@Override
@Note("Ellipsoids")
public Object getSaveObject() {
return identifyFull().substring(10);
ConfigurationSection section = new YamlConfiguration();
section.set("object", identifyFull());
section.set("flags", flagTracker.toString());
return section;
}

@Override
public void makeUnique(String id) {
EllipsoidTag toNote = clone();
toNote.noteName = id;
toNote.flagTracker = new SavableMapFlagTracker();
NotableManager.saveAs(toNote, id);
}

@Override
public void forget() {
NotableManager.remove(this);
noteName = null;
flagTracker = null;
}
@Override
public int hashCode() {
Expand Down Expand Up @@ -359,8 +371,30 @@ public ObjectTag setPrefix(String prefix) {
return this;
}

@Override
public AbstractFlagTracker getFlagTracker() {
return flagTracker;
}

@Override
public void reapplyTracker(AbstractFlagTracker tracker) {
if (noteName != null) {
this.flagTracker = tracker;
}
}

@Override
public String getReasonNotFlaggable() {
if (noteName == null) {
return "the area is not noted - only noted areas can hold flags";
}
return "unknown reason - something went wrong";
}

public static void registerTags() {

AbstractFlagTracker.registerFlagHandlers(tagProcessor);

// <--[tag]
// @attribute <EllipsoidTag.random>
// @returns LocationTag
Expand Down
Expand Up @@ -9,6 +9,9 @@
import com.denizenscript.denizen.utilities.inventory.RecipeHelper;
import com.denizenscript.denizen.utilities.inventory.SlotHelper;
import com.denizenscript.denizen.utilities.nbt.CustomNBT;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
import com.denizenscript.denizencore.flags.FlaggableObject;
import com.denizenscript.denizencore.flags.SavableMapFlagTracker;
import com.denizenscript.denizencore.objects.*;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.abstracts.ImprovedOfflinePlayer;
Expand All @@ -34,6 +37,8 @@
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.block.DoubleChest;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
Expand All @@ -43,7 +48,7 @@

import java.util.*;

public class InventoryTag implements ObjectTag, Notable, Adjustable {
public class InventoryTag implements ObjectTag, Notable, Adjustable, FlaggableObject {

// <--[language]
// @name InventoryTag Objects
Expand Down Expand Up @@ -122,11 +127,16 @@ public boolean isUnique() {

public boolean isSaving = false;

public AbstractFlagTracker flagTracker = null;

@Note("Inventories")
public String getSaveObject() {
public Object getSaveObject() {
isSaving = true;
try {
return "in@" + idType + PropertyParser.getPropertiesString(this);
ConfigurationSection section = new YamlConfiguration();
section.set("object", "in@" + idType + PropertyParser.getPropertiesString(this));
section.set("flags", flagTracker.toString());
return section;
}
finally {
isSaving = false;
Expand Down Expand Up @@ -160,14 +170,36 @@ public void makeUnique(String id) {
idType = "generic";
idHolder = new ElementTag(CoreUtilities.toLowerCase(getInventoryType().name()));
}
flagTracker = new SavableMapFlagTracker();
NotableManager.saveAs(this, id);
}

public void forget() {
flagTracker = null;
NotableManager.remove(this);
InventoryScriptHelper.notedInventories.remove(inventory);
}

@Override
public AbstractFlagTracker getFlagTracker() {
return flagTracker;
}

@Override
public void reapplyTracker(AbstractFlagTracker tracker) {
if (NotableManager.getSavedId(this) != null) {
this.flagTracker = tracker;
}
}

@Override
public String getReasonNotFlaggable() {
if (NotableManager.getSavedId(this) == null) {
return "the inventory is not noted - only noted inventories can hold flags";
}
return "unknown reason - something went wrong";
}

public static InventoryTag valueOf(String string, PlayerTag player, NPCTag npc, boolean silent) {
return valueOf(string, new BukkitTagContext(player, npc, null, !silent, null));
}
Expand Down Expand Up @@ -1081,6 +1113,8 @@ public String toString() {

public static void registerTags() {

AbstractFlagTracker.registerFlagHandlers(tagProcessor);

// <--[tag]
// @attribute <InventoryTag.empty_slots>
// @returns ElementTag(Number)
Expand Down

0 comments on commit 18b952e

Please sign in to comment.