mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-03 22:15:24 +00:00
feat: TownMetaController
- WIP commit for custom spawn points
This commit is contained in:
1 file changed
+40
@@ -0,0 +1,40 @@
|
|||||||
|
package com.github.alathra.AlathranWars.data;
|
||||||
|
|
||||||
|
import com.github.alathra.AlathranWars.AlathranWars;
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.metadata.LocationDataField;
|
||||||
|
import com.palmergames.bukkit.towny.utils.MetaDataUtil;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class TownMetaController {
|
||||||
|
private AlathranWars plugin;
|
||||||
|
private static LocationDataField defendersSpawn = new LocationDataField("alathranwars_defendersSpawn");
|
||||||
|
|
||||||
|
TownMetaController(AlathranWars plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasDefendersSpawn(Town town) {
|
||||||
|
return town.hasMeta(defendersSpawn.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Location getDefendersSpawn(Town town) {
|
||||||
|
if (hasDefendersSpawn(town)) {
|
||||||
|
return MetaDataUtil.getLocation(town, defendersSpawn);
|
||||||
|
} else {
|
||||||
|
Location location = town.getSpawnOrNull();
|
||||||
|
|
||||||
|
setDefendersSpawn(town, location);
|
||||||
|
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setDefendersSpawn(Town town, Location location) {
|
||||||
|
if (hasDefendersSpawn(town)) {
|
||||||
|
MetaDataUtil.setLocation(town, defendersSpawn, location, true);
|
||||||
|
} else {
|
||||||
|
town.addMetaData(new LocationDataField(defendersSpawn.getKey(), location));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user