Add ability to set spawns with yaw and pitch

This commit is contained in:
kaenganxt
2014-12-17 17:14:24 +01:00
parent 32f6cfdcbf
commit a7e0838cac
6 changed files with 60 additions and 21 deletions

View File

@@ -7,9 +7,12 @@ import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.material.MaterialData;
@@ -255,4 +258,21 @@ public class Core {
Errors.reportException(ex);
}
}
public static Location getServerSpawn() {
FileConfiguration c = getMainClass().getConfig();
Location loc = null;
World w = Bukkit.getWorld(c.getString("spawn.world"));
if (w != null) {
loc = new Location(Bukkit.getWorld(c.getString("spawn.world")), c.getDouble("spawn.X"), c.getDouble("spawn.Y"), c.getDouble("spawn.Z"), (float) c.getDouble("spawn.yaw"), (float) c.getDouble("spawn.pitch"));
}
if (loc == null) {
loc = Bukkit.getWorlds().get(0).getSpawnLocation();
}
return loc;
}
public static void toSpawn(Player P) {
P.teleport(getServerSpawn());
}
}

View File

@@ -37,6 +37,7 @@ import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@@ -46,21 +47,28 @@ import org.bukkit.util.Vector;
public class Setup {
public static void setupConfig() {
Core.getMainClass().getConfig().addDefault("no-damage", false);
Core.getMainClass().getConfig().addDefault("no-void-death", false);
Core.getMainClass().getConfig().addDefault("no-change-blocks", false);
Core.getMainClass().getConfig().addDefault("is-main-lobby", false);
Core.getMainClass().getConfig().addDefault("no-hunger", false);
Core.getMainClass().getConfig().addDefault("no-rain", false);
Core.getMainClass().getConfig().addDefault("enable-leaves-decay", true);
Core.getMainClass().getConfig().addDefault("server-name", "none");
Core.getMainClass().getConfig().addDefault("allow-stairs-sit", false);
Core.getMainClass().getConfig().addDefault("disable-mushroom-spread", false);
Core.getMainClass().getConfig().addDefault("on-join-to-spawn", false);
Core.getMainClass().getConfig().addDefault("golf", false);
Core.getMainClass().getConfig().addDefault("realtime-day", false);
Core.getMainClass().getConfig().options().copyDefaults(true);
Core.getMainClass().getConfig().options().header("Config File of the Anura Core-Plugin:");
FileConfiguration c = Core.getMainClass().getConfig();
c.addDefault("no-damage", false);
c.addDefault("no-void-death", false);
c.addDefault("no-change-blocks", false);
c.addDefault("is-main-lobby", false);
c.addDefault("no-hunger", false);
c.addDefault("no-rain", false);
c.addDefault("enable-leaves-decay", true);
c.addDefault("server-name", "none");
c.addDefault("allow-stairs-sit", false);
c.addDefault("disable-mushroom-spread", false);
c.addDefault("on-join-to-spawn", false);
c.addDefault("golf", false);
c.addDefault("realtime-day", false);
c.addDefault("spawn.world", "none");
c.addDefault("spawn.X", 0);
c.addDefault("spawn.Y", 0);
c.addDefault("spawn.Z", 0);
c.addDefault("spawn.yaw", 0d);
c.addDefault("spawn.pitch", 0d);
c.options().copyDefaults(true);
c.options().header("Config File of the Anura Core-Plugin:");
}
public static void setupEvents() {

View File

@@ -11,6 +11,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
@@ -76,6 +77,14 @@ public class AdminCommands implements CommandExecutor {
if (P != null && P.hasPermission("core.commands.setspawn")) {
Location l = P.getLocation();
l.getWorld().setSpawnLocation((int) l.getX(), (int) l.getY(), (int) l.getZ());
FileConfiguration c = Core.getMainClass().getConfig();
c.set("spawn.X", l.getX());
c.set("spawn.Y", l.getY());
c.set("spawn.Z", l.getZ());
c.set("spawn.yaw", (double)l.getYaw());
c.set("spawn.pitch", (double)l.getPitch());
c.set("spawn.world", l.getWorld().getName());
Core.getMainClass().saveConfig();
Core.statusMsg(P, "spawn_set", true);
return true;
}

View File

@@ -191,7 +191,7 @@ public class PlayerCommands implements CommandExecutor {
Core.statusMsg(sender, "only_player_cmd", false);
return true;
}
P.teleport(P.getLocation().getWorld().getSpawnLocation());
Core.toSpawn(P);
Core.statusMsg(P, "spawn_tp_done", true);
return true;
} else if (cmd.getName().equalsIgnoreCase("warp")) {

View File

@@ -81,7 +81,7 @@ public class PlayerInteract implements Listener {
}
}
} else if (rs.getString("type").equalsIgnoreCase("spawn")) {
P.teleport(loc.getWorld().getSpawnLocation());
Core.toSpawn(P);
} else if (rs.getString("type").equalsIgnoreCase("server")) {
String targetServer = rs.getString("value");
ByteArrayOutputStream b = new ByteArrayOutputStream();

View File

@@ -6,6 +6,7 @@ import de.anura.core.AnuraCore;
import de.anura.core.Teleports;
import java.sql.ResultSet;
import java.util.UUID;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -21,11 +22,12 @@ public class PlayerJoin implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
try {
FileConfiguration c = plugin.getConfig();
UUID uuid = event.getPlayer().getUniqueId();
ResultSet rs;
rs = AnuraCore.getSql().querySelect("SELECT name FROM players WHERE uuid LIKE '" + uuid.toString() + "'");
if (rs == null) {
if (plugin.getConfig().getBoolean("is-main-lobby")) {
if (c.getBoolean("is-main-lobby")) {
event.getPlayer().kickPlayer("Please try again");
} else {
Core.kickToLobby(event.getPlayer());
@@ -46,14 +48,14 @@ public class PlayerJoin implements Listener {
plugin.joinTime.put(event.getPlayer(), (int) (System.currentTimeMillis() / 1000));
plugin.aimTheWaterWins.put(event.getPlayer(), 0);
Core.getLevel().loadLevel(event.getPlayer());
if (plugin.getConfig().getBoolean("on-join-to-spawn")) {
event.getPlayer().teleport(event.getPlayer().getWorld().getSpawnLocation());
}
String name = event.getPlayer().getName();
if (Teleports.queuedLocs.containsKey(name)) {
event.getPlayer().teleport(Teleports.queuedLocs.get(name));
Teleports.queuedLocs.remove(name);
} else if (c.getBoolean("on-join-to-spawn")) {
Core.toSpawn(event.getPlayer());
}
} catch(Throwable e) {
Errors.reportException(e);
}