Skip to content
Browse files

Implemented /getspawn, and an option for TweakWorld, to keep the spaw…

…n chunks active.
  • Loading branch information...
1 parent 0a9127f commit a57fc81fb0a053ad6f38f06ad06f0d4c4eb22775 @GuntherDW committed
View
3 plugin.yml
@@ -130,6 +130,9 @@ commands:
spawn:
description: Sends you to the spawn of the world you're in
usage: /<command>
+ getspawn:
+ description: Gets the spawn location for the world
+ usage: /<command>
setspawn:
description: Sets the spawn of the current world
usage: /<command>
View
1 src/com/guntherdw/bukkit/tweakcraft/Commands/CommandHandler.java
@@ -98,6 +98,7 @@ public CommandHandler(TweakcraftUtils instance) {
commandMap.put("whois", new CommandWhois());
commandMap.put("donotmount", new CommandDoNotMount());
commandMap.put("eject", new CommandEject());
+ commandMap.put("getspawn", new CommandGetSpawn());
/**
* Chat commands
View
77 src/com/guntherdw/bukkit/tweakcraft/Commands/General/CommandGetSpawn.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2011 GuntherDW
+ *
+ * This program 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 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.guntherdw.bukkit.tweakcraft.Commands.General;
+
+import com.guntherdw.bukkit.tweakcraft.Commands.iCommand;
+import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandSenderException;
+import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandUsageException;
+import com.guntherdw.bukkit.tweakcraft.Exceptions.PermissionsException;
+import com.guntherdw.bukkit.tweakcraft.Tools.ArgumentParser;
+import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+/**
+ * @author GuntherDW
+ */
+public class CommandGetSpawn implements iCommand {
+ @Override
+ public boolean executeCommand(CommandSender sender, String command, String[] realargs, TweakcraftUtils plugin)
+ throws PermissionsException, CommandSenderException, CommandUsageException {
+
+ if(sender instanceof Player)
+ if(!plugin.check((Player)sender, getPermissionSuffix()))
+ throw new PermissionsException(command);
+
+ ArgumentParser ap = new ArgumentParser(realargs);
+ String world = ap.getString("w", null);
+ String[] args = ap.getNormalArgs();
+ float x,y,z;
+
+
+ World w = null;
+
+ if(world!=null)
+ w = plugin.getServer().getWorld(world);
+ else {
+ if(sender instanceof Player)
+ w = ((Player)sender).getWorld();
+ }
+
+ if(w==null)
+ throw new CommandUsageException("I didn't get a good world to fetch?");
+
+ sender.sendMessage(ChatColor.YELLOW + "Spawn position for "+w.getName());
+ Location spawn = w.getSpawnLocation();
+ x = Math.round((float) spawn.getX());
+ y = Math.round((float) spawn.getY());
+ z = Math.round((float) spawn.getZ());
+ sender.sendMessage(ChatColor.YELLOW+ "X:"+x+" Y:"+y+" Z:"+z);
+
+ return true;
+ }
+
+ @Override
+ public String getPermissionSuffix() {
+ return "getspawn";
+ }
+}
View
10 src/com/guntherdw/bukkit/tweakcraft/Worlds/TweakWorld.java
@@ -37,6 +37,7 @@
private boolean allowanimals = true;
private boolean tooldurability = true;
private boolean netherenabled = false;
+ private boolean keepspawnactive = false;
private String worldName = "";
private org.bukkit.World.Environment environment;
private WorldManager wm;
@@ -173,6 +174,15 @@ public IWorld getWorld() {
public org.bukkit.World.Environment getEnvironment() {
return environment;
}
+
+ public void setSpawnChunksActive(boolean state) {
+ this.world.setKeepSpawnInMemory(state);
+ this.keepspawnactive = state;
+ }
+
+ public boolean getSpawnChunksActive() {
+ return this.keepspawnactive;
+ }
public org.bukkit.World getBukkitWorld() {
return world;
View
7 src/com/guntherdw/bukkit/tweakcraft/Worlds/WorldManager.java
@@ -58,7 +58,9 @@ public void setupWorlds() {
// catch a /reload!
// IWorld iw = new TweakWorld(this, world.getName(), world.getEnvironment(), world.getPVP(), world.getAllowMonsters(), world.getAllowMonsters(), defaultviewdistance, worldInfDura, true);
if(!extraworlds.contains(world.getName())) {
- worlds.put(world.getName(), new TweakWorld(this, world.getName(), world.getEnvironment(), world.getPVP(), world.getAllowMonsters(), world.getAllowMonsters(), defaultviewdistance, worldInfDura, true));
+ TweakWorld tw = new TweakWorld(this, world.getName(), world.getEnvironment(), world.getPVP(), world.getAllowMonsters(), world.getAllowMonsters(), defaultviewdistance, worldInfDura, true);
+ tw.setSpawnChunksActive(world.getKeepSpawnInMemory());
+ worlds.put(world.getName(), tw);
}
if (world.getEnvironment() == Environment.NETHER)
netherWorldOnline = true;
@@ -86,9 +88,11 @@ public void setupWorlds() {
boolean animals = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".animals", true);
boolean durability = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".durability", true);
boolean addnether = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".addnether", false);
+ boolean spawnchunksactive = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".spawnchunksactive", false);
int viewdistance = plugin.getConfiguration().getInt("worlds.extraworlds." + node + ".viewdistance", defaultviewdistance);
+
Environment wenv = null;
if(env==null || env=="") {
plugin.getLogger().info("[TweakcraftUtils] World "+node+" does not have a valid environment definition, using \"normal\"");
@@ -112,6 +116,7 @@ public void setupWorlds() {
plugin.getLogger().info("[TweakcraftUtils] World "+node+" Tool Durability : "+(durability?"enabled":"disabled"));
TweakWorld tw = new TweakWorld(this, node, wenv, pvp, monsters, animals, viewdistance, durability, enabled);
if(addnether) tw.addNether();
+ tw.setSpawnChunksActive(spawnchunksactive);
worlds.put(node, tw);
} else {

0 comments on commit a57fc81

Please sign in to comment.
Something went wrong with that request. Please try again.