A silly little update by a silly little developer

This commit is contained in:
Anya 2022-04-22 18:09:49 -07:00
parent fcd087391d
commit 81ac63c998
9 changed files with 104 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package moe.oko.opennaw;
import moe.oko.opennaw.command.CityCommand;
import moe.oko.opennaw.command.NationCommand;
import moe.oko.opennaw.util.ChatHandler;
import moe.oko.opennaw.util.CityHandler;
@ -34,12 +35,14 @@ public final class OpenNAW extends JavaPlugin {
instance = this;
this.luckPerms = getServer().getServicesManager().load(LuckPerms.class);
nationHandler = new NationHandler();
cityHandler = new CityHandler();
groupHandler = new GroupHandler(this.luckPerms);
info("OpenNAW is enabled!");
// Register Commands & Events
this.getCommand("nation").setExecutor(new NationCommand());
this.getCommand("city").setExecutor(new CityCommand());
getServer().getPluginManager().registerEvents(new ChatHandler(), this);
}

View File

@ -27,19 +27,21 @@ public class CityCommand implements TabExecutor {
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());
return true;
}
case "remove": {
OpenNAW.getInstance().getCityHandler().removeCity(args[1]);
sender.sendMessage("Removed city " + args[1]);
return true;
}
case "list": {
final var msg = cityList.size() == 0
? "There are no cities"
: "There are " + cityList.size() + " cities: " + cityList;
sender.sendMessage(msg);
return true;
}
}
return true;
}

View File

@ -5,6 +5,7 @@ import org.bukkit.Location;
public class City {
private String name;
private String resource;
private CityState state;
private Nation owner;
private Location point;
private short health;
@ -13,8 +14,9 @@ public class City {
this.name = name;
this.resource = resource;
this.owner = null;
this.state = CityState.NORMAL;
this.point = location;
this.health = 500;
this.health = 300;
}
public String getName() {

View File

@ -0,0 +1,8 @@
package moe.oko.opennaw.model;
public enum CityState {
NORMAL,
SIEGE
}

View File

@ -0,0 +1,17 @@
package moe.oko.opennaw.model.action;
public abstract class Action {
public long timeOfAction;
public boolean cancelled;
public long timeOfAction() {
return timeOfAction;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -0,0 +1,22 @@
package moe.oko.opennaw.model.action;
import moe.oko.opennaw.model.City;
import org.bukkit.OfflinePlayer;
public class CityAttackAction extends Action{
public static final long DELAY = 10000L;
public OfflinePlayer player;
public OfflinePlayer getPlayer() {
return player;
}
public CityAttackAction(OfflinePlayer player, City city) {
this.timeOfAction = System.currentTimeMillis();
this.player = player;
}
public void completion() {
}
}

View File

@ -0,0 +1,43 @@
package moe.oko.opennaw.util;
import moe.oko.opennaw.OpenNAW;
import moe.oko.opennaw.model.action.Action;
import moe.oko.opennaw.model.action.CityAttackAction;
import org.bukkit.Bukkit;
import java.util.HashMap;
import java.util.UUID;
public class ActionLogger {
HashMap<UUID, Action> actionByUuid = new HashMap<>();
public 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());
}
actionByUuid.put(CAA.getPlayer().getUniqueId(), action);
Bukkit.getScheduler().scheduleSyncDelayedTask(OpenNAW.getInstance(), () -> {
var actionCallback = actionByUuid.get(CAA.getPlayer().getUniqueId());
if (!actionCallback.isCancelled()) {
CAA.completion();
}
actionByUuid.remove(CAA.getPlayer().getUniqueId());
}, CityAttackAction.DELAY);
return true;
}
return false;
}
return false;
}
private boolean enoughTimeElapsed(long timestamp, long delay) {
return (System.currentTimeMillis() - timestamp) > delay;
}
}

View File

@ -0,0 +1,2 @@
# OpenNAW Configuration

View File

@ -10,3 +10,6 @@ commands:
nation:
description: Manages nations
usage: /<command>
city:
description: Manages cities
usage: /<command>