Siege functionality fixed and now works.
This commit is contained in:
parent
6e707442cf
commit
6d9bb1c083
|
@ -2,6 +2,8 @@ package moe.oko.opennaw.command;
|
|||
|
||||
import moe.oko.opennaw.OpenNAW;
|
||||
import moe.oko.opennaw.util.CommandHelper;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
|
@ -25,7 +27,7 @@ public class CityCommand implements TabExecutor {
|
|||
switch (args[0]) {
|
||||
case "add": {
|
||||
var location = ((Player) sender).getLocation();
|
||||
OpenNAW.getInstance().getCityHandler().addCity(args[1], args[2], location);
|
||||
OpenNAW.getInstance().getCityHandler().addCity(args[1], args[2], new Location(location.getWorld() ,location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
sender.sendMessage("Created city " + args[1] + " at " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ());
|
||||
return true;
|
||||
}
|
||||
|
@ -41,6 +43,11 @@ public class CityCommand implements TabExecutor {
|
|||
sender.sendMessage(msg);
|
||||
return true;
|
||||
}
|
||||
case "debug": {
|
||||
var city = OpenNAW.getInstance().getCityHandler().fetchCityViaName(args[1]);
|
||||
OpenNAW.getInstance().getCityHandler().setCityOwner(city, OpenNAW.getInstance().getNationHandler().fetchNationViaName(args[2]));
|
||||
sender.sendMessage(ChatColor.GREEN + "Done!" + "Owner set to " + city.getOwner().getName() );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -48,7 +55,7 @@ public class CityCommand implements TabExecutor {
|
|||
@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 1 -> List.of("add", "list", "modify", "remove", "debug");
|
||||
case 2 -> OpenNAW.getInstance().getCityHandler().getCityList();
|
||||
default -> null;
|
||||
};
|
||||
|
|
|
@ -60,6 +60,7 @@ public class NationCommand implements TabExecutor {
|
|||
}
|
||||
|
||||
var group = OpenNAW.getInstance().getNationHandler().getNationGroup(args[1]);
|
||||
OpenNAW.getInstance().getNationHandler().getNationByName(args[1]).getPlayerMap().put(player.getUniqueId(), player);
|
||||
OpenNAW.getInstance().getGroupHandler().addPlayerToGroup(player, group);
|
||||
|
||||
sender.sendMessage("Added " + player.getName() + " to nation " + args[1]);
|
||||
|
|
|
@ -71,7 +71,7 @@ public class City {
|
|||
public void damage() {
|
||||
//Ran each time a city is damaged by a capture event
|
||||
//Makes an explosion of ash around a block
|
||||
point.getWorld().spawnParticle(Particle.ASH, point, 4000, .5, .5, .5);
|
||||
point.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, point, 1, .01, .01, .01);
|
||||
point.getWorld().playSound(point, Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F);
|
||||
health = (short) (health - OpenNAW.getInstance().getConfigHelper().cityDamageOnStrike());
|
||||
switch (health) {
|
||||
|
@ -85,6 +85,7 @@ public class City {
|
|||
player.sendMessage(ChatColor.BOLD + "" + ChatColor.RED + "THE CITY HAS FALLEN TO " + health + " HEALTH...");
|
||||
}
|
||||
}
|
||||
return;
|
||||
case 10:
|
||||
for(var player : Bukkit.getOnlinePlayers()) {
|
||||
if(player.getLocation().distance(point) < 100) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.bukkit.OfflinePlayer;
|
|||
import org.bukkit.Sound;
|
||||
|
||||
public class CityAttackAction extends Action{
|
||||
public static final long DELAY = 10000L;
|
||||
public static final long DELAY = 200L;
|
||||
|
||||
public OfflinePlayer player;
|
||||
|
||||
|
@ -25,12 +25,12 @@ public class CityAttackAction extends Action{
|
|||
}
|
||||
|
||||
public void initiation() {
|
||||
city.getPoint().getWorld().playSound(city.getPoint(), Sound.ENTITY_FIREWORK_ROCKET_BLAST, 1, 1);
|
||||
if(!city.underSiege()) {
|
||||
var nation = OpenNAW.getInstance().getNationHandler().getNationByPlayer(player.getUniqueId());
|
||||
//Initiate siege.
|
||||
city.startSiege(nation);
|
||||
}
|
||||
city.getPoint().getWorld().playSound(city.getPoint(), Sound.ENTITY_FIREWORK_ROCKET_BLAST, 1, 1);
|
||||
}
|
||||
|
||||
public void completion() {
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.bukkit.entity.Player;
|
|||
public class CityDefenseAction extends Action {
|
||||
|
||||
//60 seconds for defense action
|
||||
public static final long DELAY = 60000L;
|
||||
public static final long DELAY = 1200L;
|
||||
|
||||
public OfflinePlayer player;
|
||||
|
||||
|
|
|
@ -20,44 +20,57 @@ public class ActionLogger {
|
|||
public boolean tryAction(Action action) {
|
||||
if(action instanceof CityAttackAction) {
|
||||
//City attack logic
|
||||
if(enoughTimeElapsed(action.timeOfAction, CityAttackAction.DELAY)) {
|
||||
CityAttackAction CAA = (CityAttackAction) action;
|
||||
if (actionByUuid.containsKey(CAA.getPlayer().getUniqueId())) {
|
||||
actionByUuid.remove(CAA.getPlayer().getUniqueId());
|
||||
CAA.getPlayer().getPlayer().sendMessage(ChatColor.YELLOW + "Action switched.");
|
||||
Action storedAction = actionByUuid.get(CAA.getPlayer().getUniqueId());
|
||||
if(actionByUuid.get(CAA.getPlayer().getUniqueId()) instanceof CityAttackAction) {
|
||||
//Action is already running.
|
||||
return true;
|
||||
} else {
|
||||
actionByUuid.get(CAA.getPlayer().getUniqueId()).setCancelled(true); //Cancel prior action.
|
||||
actionByUuid.remove(CAA.getPlayer().getUniqueId());
|
||||
CAA.getPlayer().getPlayer().sendMessage(ChatColor.YELLOW + "Action switched.");
|
||||
}
|
||||
}
|
||||
actionByUuid.put(CAA.getPlayer().getUniqueId(), action);
|
||||
CAA.initiation(); //Code to run when action started.
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(OpenNAW.getInstance(), () -> {
|
||||
Bukkit.getScheduler().runTaskLater(OpenNAW.getInstance(), () -> {
|
||||
OpenNAW.getInstance().getLogger().info("Starting Callback...");
|
||||
var actionCallback = actionByUuid.get(CAA.getPlayer().getUniqueId());
|
||||
if (!actionCallback.isCancelled()) {
|
||||
OpenNAW.getInstance().getLogger().info("Callback not cancelled!");
|
||||
CAA.completion();
|
||||
}
|
||||
actionByUuid.remove(CAA.getPlayer().getUniqueId());
|
||||
}, CityAttackAction.DELAY);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else if(action instanceof CityDefenseAction) {
|
||||
if(enoughTimeElapsed(action.timeOfAction, CityDefenseAction.DELAY)) {
|
||||
CityDefenseAction CDA = (CityDefenseAction) action;
|
||||
if (actionByUuid.containsKey(CDA.getPlayer().getUniqueId())) {
|
||||
CAA.getPlayer().getPlayer().sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "You raise your sword...");
|
||||
return true;
|
||||
} else if(action instanceof CityDefenseAction) {
|
||||
CityDefenseAction CDA = (CityDefenseAction) action;
|
||||
if (actionByUuid.containsKey(CDA.getPlayer().getUniqueId())) {
|
||||
Action storedAction = actionByUuid.get(CDA.getPlayer().getUniqueId());
|
||||
if (actionByUuid.get(CDA.getPlayer().getUniqueId()) instanceof CityDefenseAction) {
|
||||
//Action is already running.
|
||||
return true;
|
||||
} else {
|
||||
actionByUuid.get(CDA.getPlayer().getUniqueId()).setCancelled(true); //Cancel prior action.
|
||||
actionByUuid.remove(CDA.getPlayer().getUniqueId());
|
||||
CDA.getPlayer().getPlayer().sendMessage(ChatColor.YELLOW + "Action switched.");
|
||||
}
|
||||
actionByUuid.put(CDA.getPlayer().getUniqueId(), action);
|
||||
CDA.initiation(); //Code to run when action started.
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(OpenNAW.getInstance(), () -> {
|
||||
var actionCallback = actionByUuid.get(CDA.getPlayer().getUniqueId());
|
||||
if (!actionCallback.isCancelled()) {
|
||||
CDA.completion();
|
||||
}
|
||||
actionByUuid.remove(CDA.getPlayer().getUniqueId());
|
||||
}, CityDefenseAction.DELAY);
|
||||
return true;
|
||||
}
|
||||
actionByUuid.put(CDA.getPlayer().getUniqueId(), action);
|
||||
CDA.initiation(); //Code to run when action started.
|
||||
Bukkit.getScheduler().runTaskLater(OpenNAW.getInstance(), () -> {
|
||||
var actionCallback = actionByUuid.get(CDA.getPlayer().getUniqueId());
|
||||
if (!actionCallback.isCancelled()) {
|
||||
CDA.completion();
|
||||
}
|
||||
actionByUuid.remove(CDA.getPlayer().getUniqueId());
|
||||
}, CityDefenseAction.DELAY);
|
||||
CDA.getPlayer().getPlayer().sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "You stand your ground...");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return false; //Null action?
|
||||
}
|
||||
|
||||
public void cancelDefenseActions(City city) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package moe.oko.opennaw.util;
|
||||
|
||||
import moe.oko.opennaw.OpenNAW;
|
||||
import moe.oko.opennaw.model.City;
|
||||
import moe.oko.opennaw.model.Nation;
|
||||
import org.bukkit.Location;
|
||||
|
@ -39,6 +40,15 @@ public class CityHandler {
|
|||
return null;
|
||||
}
|
||||
|
||||
public City fetchCityViaName(String name) {
|
||||
for(City cty : cities.values()) {
|
||||
if(cty.getName().equalsIgnoreCase(name)) {
|
||||
return cty;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> getCityList() {
|
||||
List<String> cityList = new ArrayList<String>();
|
||||
for (City city : cities.values()) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package moe.oko.opennaw.util;
|
||||
|
||||
import moe.oko.opennaw.OpenNAW;
|
||||
import moe.oko.opennaw.model.City;
|
||||
import moe.oko.opennaw.model.Nation;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -25,6 +27,8 @@ public class NationHandler {
|
|||
return nations.get(name).getGroup();
|
||||
}
|
||||
|
||||
public Nation getNationByName(String name) { return nations.get(name); }
|
||||
|
||||
public boolean isPlayerInNation(Player player, Nation nation) {
|
||||
return nation.getPlayerMap().containsKey(player.getUniqueId());
|
||||
}
|
||||
|
@ -38,6 +42,15 @@ public class NationHandler {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Nation fetchNationViaName(String name) {
|
||||
for(Nation cty : nations.values()) {
|
||||
if(cty.getName().equalsIgnoreCase(name)) {
|
||||
return cty;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> getNationList() {
|
||||
List<String> nationList = new ArrayList<String>();
|
||||
for (Nation nation : nations.values()) {
|
||||
|
|
Loading…
Reference in a new issue