فهرست منبع

Merge pull request #99 from daniel-naegele/fix/lobby-area-on-spawn

fix: create lobby area around spawn point
Daniel 2 سال پیش
والد
کامیت
95f4139cc1

+ 1 - 1
missilewars-plugin/src/main/java/de/butzlabben/missilewars/configuration/Lobby.java

@@ -60,7 +60,7 @@ public class Lobby {
     @SerializedName("team2_color") private String team2Color = "&a";
     @Setter @SerializedName("spawn_point") private Location spawnPoint = getBukkitDefaultWorld().getSpawnLocation();
     @Setter @SerializedName("after_game_spawn") private Location afterGameSpawn = getBukkitDefaultWorld().getSpawnLocation();
-    @Setter @SerializedName("area") private AreaConfiguration areaConfig = new AreaConfiguration(-30, 0, -30, 30, 256, 30);
+    @Setter @SerializedName("area") private AreaConfiguration areaConfig = AreaConfiguration.aroundLocation(getBukkitDefaultWorld().getSpawnLocation(), 30);
     @SerializedName("map_choose_procedure") private MapChooseProcedure mapChooseProcedure = MapChooseProcedure.FIRST;
     @SerializedName("possible_arenas") private List<String> possibleArenas = new ArrayList<>() {{
         add("arena0");

+ 20 - 0
missilewars-plugin/src/main/java/de/butzlabben/missilewars/configuration/arena/AreaConfiguration.java

@@ -24,6 +24,7 @@ import java.util.Map;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
 import lombok.ToString;
+import org.bukkit.Location;
 import org.bukkit.configuration.serialization.ConfigurationSerializable;
 import org.jetbrains.annotations.NotNull;
 
@@ -39,6 +40,25 @@ public class AreaConfiguration implements ConfigurationSerializable {
     @SerializedName("max_y") private int maxY;
     @SerializedName("max_z") private int maxZ;
 
+    /**
+     * Creates a quadratic area around the given location with the specified margin.
+     * The height will go from 0 to 256.
+     *
+     * @param location the location to put the area around.
+     * @param margin   the distance between the border of the area and the location.
+     *
+     * @return an area configuration around the location
+     */
+    public static AreaConfiguration aroundLocation(Location location, int margin) {
+        return new AreaConfiguration(location.getBlockX() - margin,
+                0,
+                location.getBlockZ() - margin,
+                location.getBlockX() + margin,
+                256,
+                location.getBlockZ() + margin
+        );
+    }
+
     /**
      * This method is used to save the config entries in the config file.
      */