Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add <cu@cuboid.has_town> and <cu@cuboid.list_towns>
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/main/java/net/gnomeffinway/depenizen/extensions/towny/TownyCuboidExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package net.gnomeffinway.depenizen.extensions.towny; | ||
|
||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; | ||
import com.palmergames.bukkit.towny.object.TownyUniverse; | ||
import net.aufdemrand.denizen.objects.dCuboid; | ||
import net.aufdemrand.denizencore.objects.Element; | ||
import net.aufdemrand.denizencore.objects.dList; | ||
import net.aufdemrand.denizencore.objects.dObject; | ||
import net.aufdemrand.denizencore.tags.Attribute; | ||
import net.gnomeffinway.depenizen.extensions.dObjectExtension; | ||
import net.gnomeffinway.depenizen.objects.dTown; | ||
import org.bukkit.Location; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TownyCuboidExtension extends dObjectExtension { | ||
|
||
public static boolean describes(dObject cuboid) { | ||
return cuboid instanceof dCuboid; | ||
} | ||
|
||
public static TownyCuboidExtension getFrom(dObject cuboid) { | ||
if (!describes(cuboid)) return null; | ||
else return new TownyCuboidExtension((dCuboid) cuboid); | ||
} | ||
|
||
private TownyCuboidExtension(dCuboid cuboid) { | ||
this.cuboid = cuboid; | ||
} | ||
|
||
dCuboid cuboid = null; | ||
|
||
@Override | ||
public String getAttribute(Attribute attribute) { | ||
|
||
// <--[tag] | ||
// @attribute <cu@cuboid.has_town> | ||
// @returns Element(Boolean) | ||
// @description | ||
// Returns whether the cuboid contains any town at all. | ||
// @plugin Depenizen, Towny | ||
// --> | ||
if (attribute.startsWith("has_town")) { | ||
for (Location location : cuboid.getBlockLocations()) { | ||
if (TownyUniverse.getTownName(location) != null) | ||
return new Element(true).getAttribute(attribute.fulfill(1)); | ||
} | ||
return new Element(false).getAttribute(attribute.fulfill(1)); | ||
} | ||
|
||
// <--[tag] | ||
// @attribute <cu@cuboid.list_towns> | ||
// @returns dList(dTown) | ||
// @description | ||
// Returns all the towns within the cuboid. | ||
// @plugin Depenizen, Towny | ||
// --> | ||
if (attribute.startsWith("list_towns")) { | ||
dList list = new dList(); | ||
List<String> towns = new ArrayList<String>(); | ||
try { | ||
for (Location location : cuboid.getBlockLocations()) { | ||
String townName = TownyUniverse.getTownName(location); | ||
if (townName != null && !towns.contains(townName)) { | ||
list.add(new dTown(TownyUniverse.getTownBlock(location).getTown()).identify()); | ||
towns.add(townName); | ||
} | ||
} | ||
} catch (NotRegisteredException e) {} | ||
return list.getAttribute(attribute.fulfill(1)); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8bc5563
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely there's a better way to accomplish this. This'll lag into hell with a large cuboid.
8bc5563
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... Could loop through each town and then check if the locations are in that town but..
I don't think that'd make a difference
Just try not to use huge cuboids 😛
8bc5563
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about loop through each town and do an AABB intersection test?
8bc5563
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's an easy way to get the max or minimum points of a town
8bc5563
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since when does
easy
limit you?8bc5563
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like Towny internals just loops through the blocks in every town to check things like this @_@