Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Subcommand;
import de.butzlabben.missilewars.Logger;
import de.butzlabben.missilewars.configuration.Config;
import de.butzlabben.missilewars.configuration.Messages;
import de.butzlabben.missilewars.game.Game;
Expand Down Expand Up @@ -240,7 +241,12 @@ public class SpawnpointSetup extends BaseCommand {
public void set(CommandSender sender, String[] args) {
if (!senderIsPlayer(sender)) return;
if (!isValidGame(args)) return;


if (!game.isInLobbyArea(player.getLocation())) {
Logger.WARN.log("The new 'spawnpoint' of the lobby '" + game.getLobby().getName()
+ "' is currently not located within the lobby area. This can lead to undesired behavior of MissileWars.");
}

game.getLobby().setSpawnPoint(player.getLocation());
game.getLobby().updateConfig();
player.sendMessage(Messages.getPrefix() + "§fSet new 'spawnPoint' to " + player.getLocation() + ".");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,13 @@ public class Arena implements Cloneable {
@SerializedName("shield") private ShieldConfiguration shieldConfiguration = new ShieldConfiguration();
@Setter @SerializedName("area") private AreaConfiguration areaConfig = new AreaConfiguration(-30, 0, -72, 30, 256, 72);

@SerializedName("spectator_spawn")
@Setter
@Setter @SerializedName("spectator_spawn")
private Location spectatorSpawn = new Location(null, 0, 100, 0, 90, 0);

@SerializedName("team1_spawn")
@Setter
@Setter @SerializedName("team1_spawn")
private Location team1Spawn = new Location(null, 0.5, 100, 45.5, 180, 0);

@SerializedName("team2_spawn")
@Setter
@Setter @SerializedName("team2_spawn")
private Location team2Spawn = new Location(null, 0.5, 100, -45.5, 0, 0);

// These values are only set after the Config has been read.
Expand All @@ -92,6 +89,12 @@ public Arena clone() {
}

public void updateConfig() {

// Prevent the (temporary) arena world from being saved as well.
spectatorSpawn.setWorld(null);
team1Spawn.setWorld(null);
team2Spawn.setWorld(null);

try {
Serializer.serialize(file, this);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public GameArea(World world, AreaConfiguration areaConfig) {
* according to the current values. The assigned MIN and MAX
* information can be used to later compare the GameArea more
* easily with current live positions/areas. In addition, the
* area direction is calculated afterwards.
* area direction is calculated afterward.
*/
private void initialize() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ public class LocationTypeAdapter extends TypeAdapter<Location> {

private final boolean serializeWorld;

/**
* This is the serializer for Bukkit Location objects.
*
* @param serializeWorld "true" if the world should also be serialized. Otherwise, it will not be saved.
*/
public LocationTypeAdapter(boolean serializeWorld) {
this.serializeWorld = serializeWorld;
}

public LocationTypeAdapter() {
this(false);
}

@Override
public void write(JsonWriter out, Location value) throws IOException {
out.beginObject();
if (serializeWorld && value.getWorld() != null) {
if (serializeWorld && isValidWorld(value.getWorld())) {
out.name("world").value(value.getWorld().getName());
}
out.name("x").value(value.getX());
Expand All @@ -64,8 +65,8 @@ public Location read(JsonReader in) throws IOException {
if (!serializeWorld) break;
String worldName = in.nextString();
World world = Bukkit.getWorld(worldName);
if (world == null) {
Logger.WARN.log("Could not find world \"" + worldName + "\" which is specified at one missilewars sign");
if (!isValidWorld(world)) {
Logger.WARN.log("Could not find world \"" + worldName + "\" which is specified at one MissileWars sign");
}
location.setWorld(world);
break;
Expand All @@ -90,4 +91,14 @@ public Location read(JsonReader in) throws IOException {
in.endObject();
return location;
}

/**
* This method checks whether the world exists on the server.
*
* @param world the target Bukkit world
* @return "true", if it exists
*/
private boolean isValidWorld(World world) {
return (world != null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Serializer {

static {
gson = new GsonBuilder()
.registerTypeAdapter(Location.class, new LocationTypeAdapter())
.registerTypeAdapter(Location.class, new LocationTypeAdapter(true))
// .registerTypeAdapter(EntityType.class, new EntityTypeTypeAdapter())
.setPrettyPrinting()
.create();
Expand Down