Implemented CityCommand
This commit is contained in:
parent
6e3f2af410
commit
fcd087391d
|
@ -2,6 +2,7 @@ package moe.oko.opennaw;
|
||||||
|
|
||||||
import moe.oko.opennaw.command.NationCommand;
|
import moe.oko.opennaw.command.NationCommand;
|
||||||
import moe.oko.opennaw.util.ChatHandler;
|
import moe.oko.opennaw.util.ChatHandler;
|
||||||
|
import moe.oko.opennaw.util.CityHandler;
|
||||||
import moe.oko.opennaw.util.GroupHandler;
|
import moe.oko.opennaw.util.GroupHandler;
|
||||||
import moe.oko.opennaw.util.NationHandler;
|
import moe.oko.opennaw.util.NationHandler;
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
|
@ -13,6 +14,7 @@ public final class OpenNAW extends JavaPlugin {
|
||||||
|
|
||||||
public static OpenNAW instance;
|
public static OpenNAW instance;
|
||||||
public NationHandler nationHandler;
|
public NationHandler nationHandler;
|
||||||
|
public CityHandler cityHandler;
|
||||||
public GroupHandler groupHandler;
|
public GroupHandler groupHandler;
|
||||||
private LuckPerms luckPerms;
|
private LuckPerms luckPerms;
|
||||||
|
|
||||||
|
@ -23,6 +25,7 @@ public final class OpenNAW extends JavaPlugin {
|
||||||
public NationHandler getNationHandler() {
|
public NationHandler getNationHandler() {
|
||||||
return nationHandler;
|
return nationHandler;
|
||||||
}
|
}
|
||||||
|
public CityHandler getCityHandler(){ return cityHandler; }
|
||||||
public GroupHandler getGroupHandler() { return groupHandler; }
|
public GroupHandler getGroupHandler() { return groupHandler; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
54
src/main/java/moe/oko/opennaw/command/CityCommand.java
Normal file
54
src/main/java/moe/oko/opennaw/command/CityCommand.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package moe.oko.opennaw.command;
|
||||||
|
|
||||||
|
import moe.oko.opennaw.OpenNAW;
|
||||||
|
import moe.oko.opennaw.util.CommandHelper;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CityCommand implements TabExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage(CommandHelper.NOT_PLAYER);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length < 1) { return false; }
|
||||||
|
|
||||||
|
var cityList = OpenNAW.getInstance().getCityHandler().getCityList();
|
||||||
|
|
||||||
|
switch (args[0]) {
|
||||||
|
case "add": {
|
||||||
|
var location = ((Player) sender).getLocation();
|
||||||
|
OpenNAW.getInstance().getCityHandler().addCity(args[1], args[2], location);
|
||||||
|
sender.sendMessage("Created city " + args[1] + " at " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ());
|
||||||
|
}
|
||||||
|
case "remove": {
|
||||||
|
OpenNAW.getInstance().getCityHandler().removeCity(args[1]);
|
||||||
|
sender.sendMessage("Removed city " + args[1]);
|
||||||
|
}
|
||||||
|
case "list": {
|
||||||
|
final var msg = cityList.size() == 0
|
||||||
|
? "There are no cities"
|
||||||
|
: "There are " + cityList.size() + " cities: " + cityList;
|
||||||
|
sender.sendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||||
|
return switch (args.length) {
|
||||||
|
case 1 -> List.of("add", "list", "modify", "remove");
|
||||||
|
case 2 -> OpenNAW.getInstance().getCityHandler().getCityList();
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,4 +16,32 @@ public class City {
|
||||||
this.point = location;
|
this.point = location;
|
||||||
this.health = 500;
|
this.health = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResource() {
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Nation getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwner(Nation nation) {
|
||||||
|
this.owner = nation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getPoint() {
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getHealth() {
|
||||||
|
return health;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void damage(short damage) {
|
||||||
|
this.health -= damage;
|
||||||
|
}
|
||||||
}
|
}
|
31
src/main/java/moe/oko/opennaw/util/CityHandler.java
Normal file
31
src/main/java/moe/oko/opennaw/util/CityHandler.java
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package moe.oko.opennaw.util;
|
||||||
|
|
||||||
|
import moe.oko.opennaw.model.City;
|
||||||
|
import moe.oko.opennaw.model.Nation;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CityHandler {
|
||||||
|
private HashMap<String, City> cities = new HashMap<>();
|
||||||
|
|
||||||
|
public void addCity(String name, String resource, Location location) {
|
||||||
|
cities.put(name, new City(name, resource, location));
|
||||||
|
location.getBlock().setType(Material.SPONGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeCity(String name) { cities.remove(name);}
|
||||||
|
|
||||||
|
public void setCityOwner(City city, Nation nation) { cities.get(city.getName()).setOwner(nation); }
|
||||||
|
|
||||||
|
public List<String> getCityList() {
|
||||||
|
List<String> cityList = new ArrayList<String>();
|
||||||
|
for (City city : cities.values()) {
|
||||||
|
cityList.add(city.getName());
|
||||||
|
}
|
||||||
|
return cityList;
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,16 +11,16 @@ public class NationHandler {
|
||||||
|
|
||||||
private HashMap<String, Nation> nations = new HashMap<>();
|
private HashMap<String, Nation> nations = new HashMap<>();
|
||||||
|
|
||||||
public void addNation(String nation, Group group) {
|
public void addNation(String name, Group group) {
|
||||||
nations.put(nation, new Nation(nation, group));
|
nations.put(name, new Nation(name, group));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Nation removeNation(String name) {
|
public void removeNation(String name) {
|
||||||
return nations.remove(name);
|
nations.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Group getNationGroup(String nation) {
|
public Group getNationGroup(String name) {
|
||||||
return nations.get(nation).getGroup();
|
return nations.get(name).getGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getNationList() {
|
public List<String> getNationList() {
|
||||||
|
|
Loading…
Reference in a new issue