diff --git a/src/main/java/us/camin/regions/CityRegionCommand.java b/src/main/java/us/camin/regions/CityRegionCommand.java
new file mode 100644
index 0000000..8611d15
--- /dev/null
+++ b/src/main/java/us/camin/regions/CityRegionCommand.java
@@ -0,0 +1,54 @@
+package us.camin.regions;
+
+/**
+ * This file is part of Regions
+ *
+ * Regions is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Regions is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Regions. If not, see .
+ *
+ */
+
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.Command;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
+
+public class CityRegionCommand implements CommandExecutor {
+
+ Plugin m_plugin;
+
+ public CityRegionCommand(Plugin p) {
+ m_plugin = p;
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
+ if (!(sender instanceof Player)) {
+ sender.sendMessage("Region command is only available to players.");
+ return true;
+ }
+ Player p = (Player)sender;
+ Region city = m_plugin.regionManager().cityRegion(p.getLocation().getWorld().getName());
+ Region nearest = m_plugin.regionManager().nearestRegion(p.getLocation());
+ if (city != null) {
+ if (p.getLocation().distance(nearest.teleportLocation()) <= 5) {
+ p.teleport(city.teleportLocation(), TeleportCause.COMMAND);
+ } else {
+ sender.sendMessage("You must be within 5 blocks of a region center.");
+ }
+ } else {
+ sender.sendMessage("There is no city region defined.");
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/us/camin/regions/HomeRegionCommand.java b/src/main/java/us/camin/regions/HomeRegionCommand.java
new file mode 100644
index 0000000..30c5d5f
--- /dev/null
+++ b/src/main/java/us/camin/regions/HomeRegionCommand.java
@@ -0,0 +1,55 @@
+package us.camin.regions;
+
+/**
+ * This file is part of Regions
+ *
+ * Regions is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Regions is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Regions. If not, see .
+ *
+ */
+
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.Command;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
+
+public class HomeRegionCommand implements CommandExecutor {
+
+ Plugin m_plugin;
+
+ public HomeRegionCommand(Plugin p) {
+ m_plugin = p;
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
+ if (!(sender instanceof Player)) {
+ sender.sendMessage("Region command is only available to players.");
+ return true;
+ }
+ Player p = (Player)sender;
+ Region home = m_plugin.regionManager().homeRegion(p.getName());
+ Region nearest = m_plugin.regionManager().nearestRegion(p.getLocation());
+
+ if (home != null) {
+ if (p.getLocation().distance(nearest.teleportLocation()) <= 5) {
+ p.teleport(home.teleportLocation(), TeleportCause.COMMAND);
+ } else {
+ sender.sendMessage("You must be within 5 blocks of a region center.");
+ }
+ } else {
+ sender.sendMessage("You have no home region.");
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/us/camin/regions/MoveinRegionCommand.java b/src/main/java/us/camin/regions/MoveinRegionCommand.java
new file mode 100644
index 0000000..88c16a9
--- /dev/null
+++ b/src/main/java/us/camin/regions/MoveinRegionCommand.java
@@ -0,0 +1,50 @@
+package us.camin.regions;
+
+/**
+ * This file is part of Regions
+ *
+ * Regions is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Regions is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Regions. If not, see .
+ *
+ */
+
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.Command;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
+
+public class MoveinRegionCommand implements CommandExecutor {
+
+ Plugin m_plugin;
+
+ public MoveinRegionCommand(Plugin p) {
+ m_plugin = p;
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
+ if (!(sender instanceof Player)) {
+ sender.sendMessage("Region command is only available to players.");
+ return true;
+ }
+ Player p = (Player)sender;
+ Region nearest = m_plugin.regionManager().nearestRegion(p.getLocation());
+ if (nearest != null) {
+ m_plugin.regionManager().setHomeRegion(p.getName(), nearest);
+ sender.sendMessage("Your home region has been set to "+nearest.name());
+ } else {
+ sender.sendMessage("There are no regions in this world.");
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/us/camin/regions/Plugin.java b/src/main/java/us/camin/regions/Plugin.java
index 8c33c9c..a357dff 100644
--- a/src/main/java/us/camin/regions/Plugin.java
+++ b/src/main/java/us/camin/regions/Plugin.java
@@ -22,6 +22,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Location;
import org.bukkit.plugin.PluginManager;
import org.bukkit.World;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
import org.bukkit.command.CommandExecutor;
import org.bukkit.configuration.ConfigurationSection;
import org.dynmap.markers.MarkerAPI;
@@ -50,13 +52,20 @@ public class Plugin extends JavaPlugin {
CommandExecutor regionCommand = new RegionCommand(this);
getCommand("region").setExecutor(regionCommand);
+ getCommand("cityregion").setExecutor(new CityRegionCommand(this));
+ getCommand("homeregion").setExecutor(new HomeRegionCommand(this));
+ getCommand("movein").setExecutor(new MoveinRegionCommand(this));
org.bukkit.plugin.Plugin mapPlugin = getServer().getPluginManager().getPlugin("dynmap");
if (mapPlugin instanceof DynmapCommonAPI) {
DynmapCommonAPI mapAPI = (DynmapCommonAPI)mapPlugin;
MarkerAPI markerAPI = mapAPI.getMarkerAPI();
- RegionEventHandler regionHandler = new RegionEventHandler(markerAPI);
- getServer().getPluginManager().registerEvents(regionHandler, this);
+ if (markerAPI != null) {
+ RegionEventHandler regionHandler = new RegionEventHandler(markerAPI);
+ getServer().getPluginManager().registerEvents(regionHandler, this);
+ } else {
+ log.info("[Regions] Dynmap marker API not found. Disabling map support.");
+ }
} else {
log.info("[Regions] Dynmap not found. Disabling map support.");
}
@@ -79,13 +88,13 @@ public class Plugin extends JavaPlugin {
public void loadRegions() {
reloadConfig();
- ConfigurationSection section = getConfig().getConfigurationSection("regions");
+ ConfigurationSection section = getConfig().getConfigurationSection("worlds");
if (section != null)
m_regions.loadRegions(section, getServer());
}
public void saveRegions() {
- m_regions.saveRegions(getConfig().createSection("regions"));
+ m_regions.saveRegions(getConfig().createSection("worlds"));
saveConfig();
}
@@ -93,4 +102,20 @@ public class Plugin extends JavaPlugin {
saveRegions();
log.info("[Regions] Plugin disabled");
}
+
+ public void regenRegionPost(Region r) {
+ World world = r.location().getWorld();
+ Location center = world.getHighestBlockAt(r.location()).getLocation();
+ for(int x = center.getBlockX()-1;x <= center.getBlockX()+1;x++) {
+ for(int z = center.getBlockZ()-1;z <= center.getBlockZ()+1;z++) {
+ Block b = world.getBlockAt(x, center.getBlockY()-1, z);
+ b.setType(Material.COBBLESTONE);
+ }
+ }
+
+ for(int y = center.getBlockY()-2;y < center.getBlockY()+2;y++) {
+ Block b = world.getBlockAt(center.getBlockX(), y, center.getBlockZ());
+ b.setType(Material.GLOWSTONE);
+ }
+ }
}
diff --git a/src/main/java/us/camin/regions/Region.java b/src/main/java/us/camin/regions/Region.java
index b3dee74..2d34420 100644
--- a/src/main/java/us/camin/regions/Region.java
+++ b/src/main/java/us/camin/regions/Region.java
@@ -33,6 +33,10 @@ public class Region {
return m_location;
}
+ public Location teleportLocation() {
+ return m_location.getWorld().getHighestBlockAt(m_location).getLocation();
+ }
+
public String name() {
return m_name;
}
diff --git a/src/main/java/us/camin/regions/RegionCommand.java b/src/main/java/us/camin/regions/RegionCommand.java
index 778cd56..b8ca434 100644
--- a/src/main/java/us/camin/regions/RegionCommand.java
+++ b/src/main/java/us/camin/regions/RegionCommand.java
@@ -56,6 +56,8 @@ public class RegionCommand implements CommandExecutor {
regionName.append(split[split.length-1]);
Region r = new Region(regionName.toString(), p.getLocation());
m_plugin.regionManager().addRegion(r);
+ m_plugin.regenRegionPost(r);
+ p.teleport(r.teleportLocation());
} else if (subCommand.equals("remove") && p.hasPermission("regions.remove")) {
Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
if (r == null) {
@@ -63,8 +65,20 @@ public class RegionCommand implements CommandExecutor {
return true;
}
m_plugin.regionManager().removeRegion(r);
+ } else if (subCommand.equals("city") && p.hasPermission("regions.setCity")) {
+ Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
+ if (r == null) {
+ p.sendMessage("There are no regions in this world.");
+ return true;
+ }
+ m_plugin.regionManager().setCityRegion(p.getLocation().getWorld().getName(), r);
+ p.sendMessage("City region set to "+r.name());
+ } else if (subCommand.equals("regen") && p.hasPermission("regions.create")) {
+ Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
+ m_plugin.regenRegionPost(r);
+ p.sendMessage("Region post regenerated.");
} else {
- p.sendMessage("Unknown operation. Options are create and remove.");
+ p.sendMessage("Unknown operation. Options are create, remove, city.");
}
return true;
}
diff --git a/src/main/java/us/camin/regions/RegionManager.java b/src/main/java/us/camin/regions/RegionManager.java
index 92262fb..3ee3ed2 100644
--- a/src/main/java/us/camin/regions/RegionManager.java
+++ b/src/main/java/us/camin/regions/RegionManager.java
@@ -38,20 +38,33 @@ import java.util.Set;
public class RegionManager {
Logger log = Logger.getLogger("Regions.RegionManager");
private Map> m_regions;
+ private Map m_cityRegions;
+ private Map m_homeRegions;
private PluginManager m_pm;
public RegionManager(PluginManager pm) {
m_pm = pm;
- m_regions = new HashMap>();
+ clear();
}
public void clear() {
m_regions = new HashMap>();
+ m_cityRegions = new HashMap();
+ m_homeRegions = new HashMap();
}
public void renameWorld(String oldName, String newName) {
log.fine("Renaming "+oldName+" to "+newName);
m_regions.put(newName, m_regions.remove(oldName));
+ m_cityRegions.put(newName, m_cityRegions.remove(oldName));
+ }
+
+ public Region cityRegion(String worldName) {
+ return m_cityRegions.get(worldName);
+ }
+
+ public void setCityRegion(String worldName, Region region) {
+ m_cityRegions.put(worldName, region);
}
public boolean addRegion(Region r) {
@@ -118,31 +131,61 @@ public class RegionManager {
public void saveRegions(ConfigurationSection section) {
for(String worldName : m_regions.keySet()) {
ConfigurationSection worldSection = section.createSection(worldName);
+ Region cityRegion = cityRegion(worldName);
+ if (cityRegion != null)
+ worldSection.set("city", cityRegion.name());
+ ConfigurationSection worldRegionSection = worldSection.createSection("regions");
for(Region r : regionsForWorld(worldName)) {
- ConfigurationSection regionSection = worldSection.createSection(r.name());
+ ConfigurationSection regionSection = worldRegionSection.createSection(r.name());
regionSection.set("x", r.location().getBlockX());
regionSection.set("z", r.location().getBlockZ());
+ ArrayList homePlayers = new ArrayList();
+ for(String player : m_homeRegions.keySet()) {
+ if (m_homeRegions.get(player) == r) {
+ homePlayers.add(player);
+ }
+ }
+ regionSection.set("players", homePlayers);
}
}
}
+ public Region homeRegion(String playerName) {
+ return m_homeRegions.get(playerName);
+ }
+
+ public void setHomeRegion(String player, Region r) {
+ m_homeRegions.put(player, r);
+ }
+
public void loadRegions(ConfigurationSection section, Server server) {
Set worldNames = section.getKeys(false);
for(String worldName : worldNames) {
ConfigurationSection worldSection = section.getConfigurationSection(worldName);
- Set regionNames = worldSection.getKeys(false);
+ String cityName = worldSection.getString("city");
+ ConfigurationSection worldRegionSection = worldSection.getConfigurationSection("regions");
+ Set regionNames = worldRegionSection.getKeys(false);
World world = server.getWorld(worldName);
if (world == null) {
log.warning("Could not find world: "+worldName);
continue;
}
for(String regionName : regionNames) {
- ConfigurationSection regionSection = worldSection.getConfigurationSection(regionName);
+ ConfigurationSection regionSection = worldRegionSection.getConfigurationSection(regionName);
int x = regionSection.getInt("x");
int z = regionSection.getInt("z");
Location loc = new Location(world, x, 64, z);
Region r = new Region(regionName, loc);
addRegion(r);
+
+ if (regionName.equals(cityName)) {
+ m_cityRegions.put(worldName, r);
+ }
+
+ List regionPlayers = regionSection.getStringList("players");
+ for(String player : regionPlayers) {
+ m_homeRegions.put(player, r);
+ }
}
}
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 6d82376..0ed16d0 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -8,6 +8,15 @@ commands:
region:
description: Interface to the region system
usage: / [args...]
+ movein:
+ description: "Sets your home region."
+ usage: /
+ cityregion:
+ description: "Teleports you to the world's city region."
+ usage: /
+ homeregion:
+ description: "Teleports you to your home region."
+ usage: /
permissions:
regions.*:
default: op
@@ -15,9 +24,13 @@ permissions:
children:
regions.create: true
regions.remove: true
+ regions.city: true
regions.create:
default: op
description: Create a region
regions.remove:
default: op
description: Remove a region
+ regions.city:
+ default: op
+ description: Defines the city region