A silly little update by a silly little developer
This commit is contained in:
parent
fcd087391d
commit
81ac63c998
|
@ -1,5 +1,6 @@
|
||||||
package moe.oko.opennaw;
|
package moe.oko.opennaw;
|
||||||
|
|
||||||
|
import moe.oko.opennaw.command.CityCommand;
|
||||||
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.CityHandler;
|
||||||
|
@ -34,12 +35,14 @@ public final class OpenNAW extends JavaPlugin {
|
||||||
instance = this;
|
instance = this;
|
||||||
this.luckPerms = getServer().getServicesManager().load(LuckPerms.class);
|
this.luckPerms = getServer().getServicesManager().load(LuckPerms.class);
|
||||||
nationHandler = new NationHandler();
|
nationHandler = new NationHandler();
|
||||||
|
cityHandler = new CityHandler();
|
||||||
groupHandler = new GroupHandler(this.luckPerms);
|
groupHandler = new GroupHandler(this.luckPerms);
|
||||||
|
|
||||||
info("OpenNAW is enabled!");
|
info("OpenNAW is enabled!");
|
||||||
|
|
||||||
// Register Commands & Events
|
// Register Commands & Events
|
||||||
this.getCommand("nation").setExecutor(new NationCommand());
|
this.getCommand("nation").setExecutor(new NationCommand());
|
||||||
|
this.getCommand("city").setExecutor(new CityCommand());
|
||||||
getServer().getPluginManager().registerEvents(new ChatHandler(), this);
|
getServer().getPluginManager().registerEvents(new ChatHandler(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,19 +27,21 @@ public class CityCommand implements TabExecutor {
|
||||||
var location = ((Player) sender).getLocation();
|
var location = ((Player) sender).getLocation();
|
||||||
OpenNAW.getInstance().getCityHandler().addCity(args[1], args[2], location);
|
OpenNAW.getInstance().getCityHandler().addCity(args[1], args[2], location);
|
||||||
sender.sendMessage("Created city " + args[1] + " at " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ());
|
sender.sendMessage("Created city " + args[1] + " at " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
case "remove": {
|
case "remove": {
|
||||||
OpenNAW.getInstance().getCityHandler().removeCity(args[1]);
|
OpenNAW.getInstance().getCityHandler().removeCity(args[1]);
|
||||||
sender.sendMessage("Removed city " + args[1]);
|
sender.sendMessage("Removed city " + args[1]);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
case "list": {
|
case "list": {
|
||||||
final var msg = cityList.size() == 0
|
final var msg = cityList.size() == 0
|
||||||
? "There are no cities"
|
? "There are no cities"
|
||||||
: "There are " + cityList.size() + " cities: " + cityList;
|
: "There are " + cityList.size() + " cities: " + cityList;
|
||||||
sender.sendMessage(msg);
|
sender.sendMessage(msg);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import org.bukkit.Location;
|
||||||
public class City {
|
public class City {
|
||||||
private String name;
|
private String name;
|
||||||
private String resource;
|
private String resource;
|
||||||
|
private CityState state;
|
||||||
private Nation owner;
|
private Nation owner;
|
||||||
private Location point;
|
private Location point;
|
||||||
private short health;
|
private short health;
|
||||||
|
@ -13,8 +14,9 @@ public class City {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.resource = resource;
|
this.resource = resource;
|
||||||
this.owner = null;
|
this.owner = null;
|
||||||
|
this.state = CityState.NORMAL;
|
||||||
this.point = location;
|
this.point = location;
|
||||||
this.health = 500;
|
this.health = 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package moe.oko.opennaw.model;
|
||||||
|
|
||||||
|
public enum CityState {
|
||||||
|
|
||||||
|
NORMAL,
|
||||||
|
|
||||||
|
SIEGE
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
# OpenNAW Configuration
|
||||||
|
|
|
@ -10,3 +10,6 @@ commands:
|
||||||
nation:
|
nation:
|
||||||
description: Manages nations
|
description: Manages nations
|
||||||
usage: /<command>
|
usage: /<command>
|
||||||
|
city:
|
||||||
|
description: Manages cities
|
||||||
|
usage: /<command>
|
||||||
|
|
Loading…
Reference in New Issue