Skip to content

Commit

Permalink
towny plot_names, balance mech
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 21, 2021
1 parent 56bb83c commit 9655327
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -12,7 +12,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<craftbukkit.version>1.16.4-R0.1-SNAPSHOT</craftbukkit.version>
<craftbukkit.version>1.16.5-R0.1-SNAPSHOT</craftbukkit.version>
<citizens.version>2.0.27-SNAPSHOT</citizens.version>
<denizen.version>1.1.9-SNAPSHOT</denizen.version>
<BUILD_NUMBER>Unknown</BUILD_NUMBER>
Expand Down
@@ -1,26 +1,22 @@
package com.denizenscript.depenizen.bukkit.objects.towny;

import com.denizenscript.denizencore.objects.*;
import com.denizenscript.depenizen.bukkit.objects.factions.NationTag;
import com.palmergames.bukkit.towny.exceptions.EconomyException;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.palmergames.bukkit.towny.object.WorldCoord;
import com.palmergames.bukkit.towny.object.*;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.Fetchable;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.Location;

public class TownTag implements ObjectTag {
public class TownTag implements ObjectTag, Adjustable {

// <--[language]
// @name TownTag Objects
Expand Down Expand Up @@ -172,6 +168,7 @@ public String getAttribute(Attribute attribute) {
// @attribute <TownTag.balance>
// @returns ElementTag(Decimal)
// @plugin Depenizen, Towny
// @mechanism TownTag.balance
// @description
// Returns the current money balance of the town.
// -->
Expand Down Expand Up @@ -417,6 +414,21 @@ else if (attribute.startsWith("has_taxpercent")) {
return new ElementTag(town.isTaxPercentage()).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <TownTag.plot_names>
// @returns ListTag
// @plugin Depenizen, Towny
// @description
// Returns a list of the names of town plots.
// -->
else if (attribute.startsWith("plot_names")) {
ListTag output = new ListTag();
for (PlotGroup group : town.getPlotObjectGroups()) {
output.add(group.getName());
}
return output.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <TownTag.plottax>
// @returns ElementTag(Decimal)
Expand All @@ -442,4 +454,36 @@ else if (attribute.startsWith("plotprice")) {
return new ElementTag(identify()).getAttribute(attribute);

}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object TownTag
// @name balance
// @input ElementTag(Decimal)|ElementTag
// @description
// Sets the money balance of a town, with a reason for the change.
// @tags
// <TownTag.balance>
// -->
if (mechanism.matches("balance")) {
ListTag input = mechanism.valueAsType(ListTag.class);
if (input.size() != 2 || !ArgumentHelper.matchesDouble(input.get(0))) {
mechanism.echoError("Invalid balance mech input.");
return;
}
try {
town.getAccount().setBalance(new ElementTag(input.get(0)).asDouble(), input.get(1));
}
catch (EconomyException ex) {
Debug.echoError(ex);
}
}
}

@Override
public void applyProperty(Mechanism mechanism) {
Debug.echoError("Cannot apply properties to a Towny town!");
}
}

0 comments on commit 9655327

Please sign in to comment.