Skip to content

Commit

Permalink
Add WorldEdit support (currently, only <p@player.selected_region>)
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Jun 20, 2014
1 parent ca7cb3e commit bfb540f
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 35 deletions.
79 changes: 48 additions & 31 deletions src/main/java/net/gnomeffinway/depenizen/Depenizen.java
@@ -1,23 +1,23 @@
package net.gnomeffinway.depenizen;

import com.gmail.nossr50.mcMMO;
import com.herocraftonline.heroes.Heroes;
import com.massivecraft.factions.Factions;
import com.palmergames.bukkit.towny.Towny;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.vexsoftware.votifier.Votifier;
import me.limebyte.battlenight.core.BattleNight;
import me.zford.jobs.bukkit.JobsPlugin;
import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.gnomeffinway.depenizen.support.*;
import net.slipcor.pvparena.PVPArena;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.DynmapAPI;

import com.gmail.nossr50.mcMMO;
import com.herocraftonline.heroes.Heroes;
import com.massivecraft.factions.Factions;
import com.palmergames.bukkit.towny.Towny;
import com.vexsoftware.votifier.Votifier;

public class Depenizen extends JavaPlugin {

public static mcMMO mcmmo;
Expand All @@ -31,6 +31,7 @@ public class Depenizen extends JavaPlugin {
public static PVPArena pvparena;
public static Heroes heroes;
public static DynmapAPI dynmap;
public static WorldEditPlugin worldedit;

public McMMOSupport mcmmoSupport;
public BattleNightSupport battlenightSupport;
Expand All @@ -42,12 +43,11 @@ public class Depenizen extends JavaPlugin {
public PVPArenaSupport pvparenaSupport;
public HeroesSupport heroesSupport;
public DynmapSupport dynmapSupport;
public WorldEditSupport worldeditSupport;

@Override
public void onEnable() {
checkPlugins();

getLogger().info("Finished loading " + getDescription().getFullName());
}

@Override
Expand All @@ -59,7 +59,7 @@ public void onDisable() {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("depenizen")) {
sender.sendMessage(ChatColor.UNDERLINE + "Depenizen");
sender.sendMessage(ChatColor.GRAY + "Developers: " + ChatColor.AQUA + "Morphan1" + ChatColor.GRAY + ", " + ChatColor.GREEN + "Jeebiss" + ChatColor.GRAY + " and GnomeffinWay");
sender.sendMessage(ChatColor.GRAY + "Developers: " + ChatColor.AQUA + "Morphan1" + ChatColor.GRAY + ", " + ChatColor.GREEN + "Jeebiss" + ChatColor.GRAY + ", and GnomeffinWay");
sender.sendMessage(ChatColor.GRAY + "Current version: "+ ChatColor.GOLD + this.getDescription().getVersion());
return true;
}
Expand All @@ -78,86 +78,103 @@ public void checkPlugins() {
pvparena = (PVPArena) getServer().getPluginManager().getPlugin("pvparena");
dynmap = (DynmapAPI) getServer().getPluginManager().getPlugin("dynmap");
heroes = (Heroes) getServer().getPluginManager().getPlugin("heroes");
worldedit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("worldedit");

if (denizen != null) {
getServer().getLogger().info("[Depenizen] Denizen hooked");
dB.log("Denizen hooked");
} else {
getServer().getLogger().severe("[Depenizen] Denizen not found, disabling");
this.getPluginLoader().disablePlugin(this);
getPluginLoader().disablePlugin(this);
return;
}

if (mcmmo != null) {
getServer().getLogger().info("[Depenizen] mcMMO hooked, enabling add-ons.");
dB.log("mcMMO hooked, enabling add-ons.");
mcmmoSupport = new McMMOSupport(this);
mcmmoSupport.register();
} else {
getServer().getLogger().info("[Depenizen] mcMMO not found, add-ons will not enable.");
dB.log("mcMMO not found, add-ons will not enable.");
}

if (towny != null) {
getServer().getLogger().info("[Depenizen] Towny hooked, enabling add-ons.");
dB.log("Towny hooked, enabling add-ons.");
townySupport = new TownySupport(this);
townySupport.register();
} else {
getServer().getLogger().info("[Depenizen] Towny not found, add-ons. will not add-ons.");
dB.log("Towny not found, add-ons. will not add-ons.");
}

if (factions != null) {
getServer().getLogger().info("[Depenizen] Factions hooked, enabling add-ons.");
dB.log("Factions hooked, enabling add-ons.");
factionsSupport = new FactionsSupport(this);
factionsSupport.register();
} else {
getServer().getLogger().info("[Depenizen] Factions not found, add-ons will not enable.");
dB.log("Factions not found, add-ons will not enable.");
}

if (battlenight != null) {
getServer().getLogger().info("[Depenizen] BattleNight hooked, enabling add-ons.");
dB.log("BattleNight hooked, enabling add-ons.");
battlenightSupport = new BattleNightSupport(this);
battlenightSupport.register();
} else {
getServer().getLogger().info("[Depenizen] BattleNight not found, add-ons will not enable.");
dB.log("BattleNight not found, add-ons will not enable.");
}

if (votifier != null) {
getServer().getLogger().info("[Depenizen] Votifier hooked, enabling add-ons.");
dB.log("Votifier hooked, enabling add-ons.");
votifierSupport = new VotifierSupport(this);
votifierSupport.register();
} else {
getServer().getLogger().info("[Depenizen] Votifier not found, add-ons will not enable.");
dB.log("Votifier not found, add-ons will not enable.");
}

if (bungeefier != null) {
getServer().getLogger().info("[Depenizen] Bungeefier hooked, enabling add-ons.");
dB.log("Bungeefier hooked, enabling add-ons.");
bungeefierSupport = new VotifierSupport(this);
bungeefierSupport.register();
} else {
getServer().getLogger().info("[Depenizen] Bungeefier not found, add-ons will not enable.");
dB.log("Bungeefier not found, add-ons will not enable.");
}

if (jobs != null) {
getServer().getLogger().info("[Depenizen] Jobs hooked, enabling add-ons.");
dB.log("Jobs hooked, enabling add-ons.");
jobsSupport = new JobsSupport(this);
jobsSupport.register();
} else {
getServer().getLogger().info("[Depenizen] Jobs not found, add-ons will not enable.");
dB.log("Jobs not found, add-ons will not enable.");
}

if (pvparena != null) {
getServer().getLogger().info("[Depenizen] PvP Arena hooked, enabling add-ons.");
dB.log("PvP Arena hooked, enabling add-ons.");
pvparenaSupport = new PVPArenaSupport(this);
pvparenaSupport.register();
} else {
getServer().getLogger().info("[Depenizen] PvP Arena not found, add-ons will not enable.");
dB.log("PvP Arena not found, add-ons will not enable.");
}

if (heroes != null) {
getServer().getLogger().info("[Depenizen] Heroes hooked, enabling add-ons.");
dB.log("Heroes hooked, enabling add-ons.");
heroesSupport = new HeroesSupport(this);
heroesSupport.register();
} else {
getServer().getLogger().info("[Depenizen] Heroes not found, add-ons will not enable.");
dB.log("Heroes not found, add-ons will not enable.");
}

if (dynmap != null) {
getServer().getLogger().info("[Depenizen] Dynmap hooked, enabling add-ons.");
dB.log("Dynmap hooked, enabling add-ons.");
dynmapSupport = new DynmapSupport(this);
dynmapSupport.register();
} else {
dB.log("Dynmap not found, add-ons will not enable.");
}

if (worldedit != null) {
dB.log("WorldEdit hooked, enabling add-ons.");
worldeditSupport = new WorldEditSupport(this);
worldeditSupport.register();
} else {
dB.log("WorldEdit not found, add-ons will not enable.");
}
}

}
Expand Up @@ -14,6 +14,7 @@ public class BattleNightCommands extends AbstractCommand {
// <--[command]
// @Name BN
// @Syntax bn [add/kick/start/end]
// @Group Depenizen
// @Plugin BattleNight
// @Required 1
// @Stable stable
Expand Down
Expand Up @@ -24,6 +24,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
// <--[command]
// @Name Jobs
// @Syntax jobs [promote/demote/join/quit] [<job>] (<#>)
// @Group Depenizen
// @Plugin Jobs
// @Required 2
// @Stable untested
Expand Down
Expand Up @@ -25,6 +25,7 @@ public class McMMOCommands extends AbstractCommand {
// <--[command]
// @Name mcMMO
// @Syntax mcmmo [add/remove/set] [levels/xp/xprate/vampirism/hardcore/leader] (skill:<skill>) (state:{toggle}/true/false) (qty:<#>) (party:<party>)
// @Group Depenizen
// @Plugin mcMMO
// @Required 1
// @Stable untested
Expand Down
Expand Up @@ -128,7 +128,7 @@ else if (attribute.startsWith("home")) {
return new dLocation(faction.getHome().asBukkitLocation())
.getAttribute(attribute.fulfill(1));
else
return new Element("null").getAttribute(attribute.fulfill(1));
return Element.NULL.getAttribute(attribute.fulfill(1));
}

// <--[tag]
Expand Down Expand Up @@ -237,7 +237,7 @@ else if (attribute.startsWith("relation")) {
return new Element(faction.getRelationTo(to.getFaction()).toString())
.getAttribute(attribute.fulfill(1));
else
return new Element("null").getAttribute(attribute.fulfill(1));
return Element.NULL.getAttribute(attribute.fulfill(1));
}

// <--[tag]
Expand Down
@@ -0,0 +1,20 @@
package net.gnomeffinway.depenizen.support;

import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.gnomeffinway.depenizen.Depenizen;
import net.gnomeffinway.depenizen.tags.worldedit.WorldEditPlayerTags;

public class WorldEditSupport {

public Depenizen depenizen;

public WorldEditSupport(Depenizen depenizen) {
this.depenizen = depenizen;
}

public void register() {
DenizenAPI.getCurrentInstance().getPropertyParser().registerProperty(WorldEditPlayerTags.class, dPlayer.class);
}

}
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.entity.Player;

public class BNPlayerTags implements Property {

public static boolean describes(dObject pl) {
return pl instanceof dPlayer
&& ((dPlayer) pl).isOnline();
Expand Down Expand Up @@ -90,4 +91,5 @@ else if (attribute.startsWith("team")) {
@Override
public void adjust(Mechanism mechanism) {
}

}
Expand Up @@ -11,6 +11,7 @@
import net.gnomeffinway.depenizen.objects.dTown;

public class TownyLocationTags implements Property {

public static boolean describes(dObject loc) {
return loc instanceof dLocation;
}
Expand Down Expand Up @@ -72,4 +73,5 @@ public String getAttribute(Attribute attribute) {
@Override
public void adjust(Mechanism mechanism) {
}

}
Expand Up @@ -12,6 +12,7 @@
import net.gnomeffinway.depenizen.objects.dTown;

public class TownyPlayerTags implements Property {

public static boolean describes(dObject pl) {
return pl instanceof dPlayer;
}
Expand Down Expand Up @@ -90,4 +91,5 @@ public String getAttribute(Attribute attribute) {
@Override
public void adjust(Mechanism mechanism) {
}

}
@@ -0,0 +1,71 @@
package net.gnomeffinway.depenizen.tags.worldedit;

import com.sk89q.worldedit.bukkit.selections.Selection;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.tags.Attribute;
import net.gnomeffinway.depenizen.Depenizen;
import org.bukkit.entity.Player;

public class WorldEditPlayerTags implements Property {

public static boolean describes(dObject pl) {
return pl instanceof dPlayer
&& ((dPlayer) pl).isOnline();
}

public static WorldEditPlayerTags getFrom(dObject pl) {
if (!describes(pl)) return null;
else return new WorldEditPlayerTags((dPlayer) pl);
}


///////////////////
// Instance Fields and Methods
/////////////

private WorldEditPlayerTags(dPlayer pl) {
player = pl.getPlayerEntity();
}

Player player = null;

/////////
// Property Methods
///////

@Override
public String getPropertyString() {
return null;
}

@Override
public String getPropertyId() {
return "WorldEditPlayerTags";
}

@Override
public String getAttribute(Attribute attribute) {

// <--[tag]
// @attribute <p@player.selected_region>
// @returns dCuboid
// @description
// Returns the player's current region selection, as a dCuboid.
// @Plugin WorldEdit
// -->
if (attribute.startsWith("selected_region")) {
Selection selection = Depenizen.worldedit.getSelection(player);
if (selection != null)
return new dCuboid(selection.getMinimumPoint(), selection.getMaximumPoint()).getAttribute(attribute.fulfill(1));
else
return Element.NULL.getAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {
}
}
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Expand Up @@ -3,11 +3,11 @@ author: GnomeffinWay
version: ${project.version} (build ${BUILD_NUMBER})
main: net.gnomeffinway.depenizen.Depenizen
depend: [Denizen, Citizens]
softdepend: [mcMMO, BattleNight, Towny, Factions, Votifier, Bungeefier, Jobs, Heroes, pvparena]
softdepend: [mcMMO, BattleNight, Towny, Factions, Votifier, Bungeefier, Jobs, Heroes, pvparena, Dynmap, WorldEdit]

commands:
depenizen:
description: Prints out the current Depenizen version.
usage: /depenizen

permissions:
permissions: []

0 comments on commit bfb540f

Please sign in to comment.