🚧 Create move command

This commit is contained in:
Maxlego08 2024-02-22 16:33:19 +01:00
parent e576ef829d
commit 5489150d3b
8 changed files with 144 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import fr.maxlego08.koth.api.KothStatus;
import fr.maxlego08.koth.api.KothTeam;
import fr.maxlego08.koth.api.KothType;
import fr.maxlego08.koth.api.events.KothCreateEvent;
import fr.maxlego08.koth.api.events.KothMoveEvent;
import fr.maxlego08.koth.hook.TeamPlugin;
import fr.maxlego08.koth.hook.teams.NoneHook;
import fr.maxlego08.koth.loader.KothLoader;
@ -188,4 +189,27 @@ public class KothManager extends ZUtils implements Savable {
Koth koth = optional.get();
koth.stop(sender);
}
public void moveKoth(Player player, Location maxLocation, Location minLocation, String name) {
Optional<Koth> optional = getKoth(name);
if (!optional.isPresent()) {
message(player, Message.DOESNT_EXIST, "%name%", name);
return;
}
Koth koth = optional.get();
KothMoveEvent event = new KothMoveEvent(koth, maxLocation, minLocation);
event.call();
if (event.isCancelled()) return;
Optional<Selection> optionalSelection = getSelection(player.getUniqueId());
optionalSelection.ifPresent(Selection::clear);
koth.move(minLocation, maxLocation);
message(player, Message.MOVE_SUCCESS, "%name%", name);
this.saveKoth(koth);
}
}

View File

@ -0,0 +1,59 @@
package fr.maxlego08.koth.api.events;
import fr.maxlego08.koth.api.Koth;
import org.bukkit.Location;
public class KothMoveEvent extends CancelledKothEvent {
private final Koth koth;
private Location newMaxLocation;
private Location newMinLocation;
/**
* @param koth
* @param newMaxLocation
* @param newMinLocation
*/
public KothMoveEvent(Koth koth, Location newMaxLocation, Location newMinLocation) {
super();
this.koth = koth;
this.newMaxLocation = newMaxLocation;
this.newMinLocation = newMinLocation;
}
/**
* @return the koth
*/
public Koth getKoth() {
return koth;
}
/**
* @return the newMaxLocation
*/
public Location getNewMaxLocation() {
return newMaxLocation;
}
/**
* @param newMaxLocation the newMaxLocation to set
*/
public void setNewMaxLocation(Location newMaxLocation) {
this.newMaxLocation = newMaxLocation;
}
/**
* @return the newMinLocation
*/
public Location getNewMinLocation() {
return newMinLocation;
}
/**
* @param newMinLocation the newMinLocation to set
*/
public void setNewMinLocation(Location newMinLocation) {
this.newMinLocation = newMinLocation;
}
}

View File

@ -16,6 +16,7 @@ public class CommandKoth extends VCommand {
this.addSubCommand(new CommandKothNow(plugin));
this.addSubCommand(new CommandKothSpawn(plugin));
this.addSubCommand(new CommandKothStop(plugin));
this.addSubCommand(new CommandKothMove(plugin));
}
@Override

View File

@ -0,0 +1,54 @@
package fr.maxlego08.koth.command.commands;
import fr.maxlego08.koth.KothPlugin;
import fr.maxlego08.koth.Selection;
import fr.maxlego08.koth.command.VCommand;
import fr.maxlego08.koth.zcore.enums.Message;
import fr.maxlego08.koth.zcore.enums.Permission;
import fr.maxlego08.koth.zcore.utils.commands.CommandType;
import org.bukkit.Location;
import java.util.Optional;
public class CommandKothMove extends VCommand {
public CommandKothMove(KothPlugin plugin) {
super(plugin);
this.setPermission(Permission.ZKOTH_MOVE);
this.addSubCommand("move");
this.setDescription(Message.DESCRIPTION_MOVE);
this.addRequireArg("name", (a,b) -> plugin.getKothManager().getNameKoths());
}
@Override
protected CommandType perform(KothPlugin plugin) {
String name = argAsString(0);
Optional<Selection> optional = this.manager.getSelection(this.player.getUniqueId());
if (!optional.isPresent()) {
message(this.sender, Message.CREATE_ERROR_SELECTION);
return CommandType.DEFAULT;
}
Selection selection = optional.get();
if (!selection.isValid()) {
message(this.sender, Message.CREATE_ERROR_SELECTION);
return CommandType.DEFAULT;
}
if (!selection.isCorrect()) {
message(this.sender, Message.CREATE_ERROR_SIZE);
return CommandType.DEFAULT;
}
Location minLocation = selection.getRightLocation();
Location maxLocation = selection.getLeftLocation();
this.manager.moveKoth(this.player, maxLocation, minLocation, name);
return CommandType.SUCCESS;
}
}

View File

@ -47,6 +47,7 @@ public enum Message {
DESCRIPTION_NOW("Spawn a koth without cooldown"),
DESCRIPTION_SPAWN("Spawn a koth with cooldown"),
DESCRIPTION_STOP("Stop a koth"),
DESCRIPTION_MOVE("Move a koth"),
DESCRIPTION_AXE("Getting the selection axe"),
DESCRIPTION_CREATE("Create new koth"),
@ -120,6 +121,8 @@ public enum Message {
EVENT_TIMER(MessageType.ACTION, "§fAnother §b%captureFormat% §fbefore §d%playerName% §fwins the koth §n%name%§e. §8(§7%centerX%, %centerY%, %centerZ%§8)"),
EVENT_EVERYSECONDS(MessageType.ACTION, "§d%playerName% §7- §8[§f%classicProgress%§8] §7- §b%classicPercent%§f%"),
MOVE_SUCCESS("§7You have just moved the koth §f%name%§7."),
;

View File

@ -6,7 +6,7 @@ public enum Permission {
ZKOTH_RELOAD,
ZKOTH_NOW,
ZKOTH_AXE,
ZKOTH_CREATE, ZKOTH_SPAWN, ZKOTH_STOP;
ZKOTH_CREATE, ZKOTH_SPAWN, ZKOTH_STOP, ZKOTH_MOVE;
private String permission;

View File

@ -15,6 +15,7 @@
# /zkoth now <koth name> - zkoth.now - Spawn a koth without cooldown
# /zkoth spawn <koth name> - zkoth.spawn - Spawn a koth
# /zkoth stop <koth name> - zkoth.stop - Stop a koth
# /zkoth move <koth name> - zkoth.stop - Move a koth
#
# Placeholders:
#

View File

@ -28,6 +28,7 @@ enableLooseCapMessage: true
startCommands: []
# Available placeholders:
# You can use these placeholders for scoreboards and messages.
# - %online-player% - Allows to run the order to all online players of the team
# - %name% - Koth name
# - %world% - World name