add base for IslandRestart.java
This commit is contained in:
parent
ebf2894ccf
commit
f4bf8e8964
|
|
@ -4,7 +4,10 @@ import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||||
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
||||||
import com.alttd.cometskyblock.commands.SubCommand;
|
import com.alttd.cometskyblock.commands.SubCommand;
|
||||||
import com.alttd.cometskyblock.configuration.MessageConfiguration;
|
import com.alttd.cometskyblock.configuration.MessageConfiguration;
|
||||||
|
import com.alttd.cometskyblock.island.Island;
|
||||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||||
|
import com.alttd.cometskyblock.request.InviteRequest;
|
||||||
|
import com.alttd.cometskyblock.request.RestartRequest;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -14,16 +17,23 @@ public class IslandRestart extends PlayerSubCommand {
|
||||||
public IslandRestart(CometSkyBlockPlugin plugin) {
|
public IslandRestart(CometSkyBlockPlugin plugin) {
|
||||||
super(plugin, "restart");
|
super(plugin, "restart");
|
||||||
registerSubCommand(new IslandRestartConfirm(plugin));
|
registerSubCommand(new IslandRestartConfirm(plugin));
|
||||||
|
registerSubCommand(new IslandRestartDeny(plugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO -- IslandRestartCommand, add a one day delay on trying to reset again!
|
// TODO -- IslandRestartCommand, add a one day delay on trying to reset again!
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||||
|
MessageConfiguration.Commands.Island.Restart restart = plugin.messagesConfiguration().get().commands().island().restart();
|
||||||
if (!islandPlayer.islandOwner()) {
|
if (!islandPlayer.islandOwner()) {
|
||||||
// You must be the islandOwner to do this command.
|
player.sendRichMessage(restart.notIslandOwner());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// create new Island request and wait for x time to do /island restart confirm
|
Island island = Island.getIsland(islandPlayer.islandUUID());
|
||||||
|
if (island == null) {
|
||||||
|
// could not load island
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
island.request(new RestartRequest(plugin, player, player));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@ package com.alttd.cometskyblock.commands.island;
|
||||||
|
|
||||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||||
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
||||||
|
import com.alttd.cometskyblock.configuration.MessageConfiguration;
|
||||||
import com.alttd.cometskyblock.island.Island;
|
import com.alttd.cometskyblock.island.Island;
|
||||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||||
|
import com.alttd.cometskyblock.request.Request;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
@ -12,38 +14,29 @@ import org.bukkit.entity.Player;
|
||||||
public class IslandRestartConfirm extends PlayerSubCommand {
|
public class IslandRestartConfirm extends PlayerSubCommand {
|
||||||
|
|
||||||
public IslandRestartConfirm(CometSkyBlockPlugin plugin) {
|
public IslandRestartConfirm(CometSkyBlockPlugin plugin) {
|
||||||
super(plugin, "restart");
|
super(plugin, "confirm");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO -- IslandRestartCommand, add a one day delay on trying to reset again!
|
// TODO -- IslandRestartCommand, add a one day delay on trying to reset again!
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||||
|
MessageConfiguration.Commands.Island.Restart restart = plugin.messagesConfiguration().get().commands().island().restart();
|
||||||
if (!islandPlayer.islandOwner()) {
|
if (!islandPlayer.islandOwner()) {
|
||||||
// You must be the islandOwner to do this command.
|
player.sendRichMessage(restart.notIslandOwner());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// check if they have an island request, if not run create request code and ask to rerun command
|
|
||||||
|
|
||||||
// Teleport everyone on the island to spawnworld
|
|
||||||
Island island = Island.getIsland(islandPlayer.islandUUID());
|
Island island = Island.getIsland(islandPlayer.islandUUID());
|
||||||
if (island == null) {
|
if (island == null) {
|
||||||
// could not load island
|
// could not load island
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
World islandWorld = plugin.worldGenerator().loadIslandWorld(island.worldName());
|
// check if they have an island request, if not run create request code and ask to rerun command
|
||||||
if (islandWorld == null) {
|
Request request = island.request();
|
||||||
// could not load world
|
if (request == null) {
|
||||||
|
player.sendRichMessage(plugin.messagesConfiguration().get().requests().noPendingRequests());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
World world = Bukkit.getWorlds().get(0);
|
request.accept();
|
||||||
Location spawnLocation = world.getSpawnLocation();
|
|
||||||
for (Player target : islandWorld.getPlayers()) {
|
|
||||||
target.teleport(spawnLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
// teleport owner to the new island and give new starter gear
|
|
||||||
|
|
||||||
// send message to all online members that a new island has been created
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.alttd.cometskyblock.commands.island;
|
||||||
|
|
||||||
|
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||||
|
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
||||||
|
import com.alttd.cometskyblock.configuration.MessageConfiguration;
|
||||||
|
import com.alttd.cometskyblock.island.Island;
|
||||||
|
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||||
|
import com.alttd.cometskyblock.request.Request;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class IslandRestartDeny extends PlayerSubCommand {
|
||||||
|
|
||||||
|
public IslandRestartDeny(CometSkyBlockPlugin plugin) {
|
||||||
|
super(plugin, "deny");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||||
|
MessageConfiguration.Commands.Island.Restart restart = plugin.messagesConfiguration().get().commands().island().restart();
|
||||||
|
if (!islandPlayer.islandOwner()) {
|
||||||
|
player.sendRichMessage(restart.notIslandOwner());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Island island = Island.getIsland(islandPlayer.islandUUID());
|
||||||
|
if (island == null) {
|
||||||
|
// could not load island
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// check if they have an island request, if not run create request code and ask to rerun command
|
||||||
|
Request request = island.request();
|
||||||
|
if (request == null) {
|
||||||
|
player.sendRichMessage(plugin.messagesConfiguration().get().requests().noPendingRequests());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
request.deny();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -49,7 +49,7 @@ public class MessageConfiguration implements Configuration {
|
||||||
Restart restart = new Restart();
|
Restart restart = new Restart();
|
||||||
@ConfigSerializable @Getter
|
@ConfigSerializable @Getter
|
||||||
public static class Restart {
|
public static class Restart {
|
||||||
|
String notIslandOwner = "<red>You must be the island owner to do this.";
|
||||||
}
|
}
|
||||||
|
|
||||||
Accept accept = new Accept();
|
Accept accept = new Accept();
|
||||||
|
|
@ -159,6 +159,14 @@ public class MessageConfiguration implements Configuration {
|
||||||
String denied = "<target> has denied <requester>'s island invite.";
|
String denied = "<target> has denied <requester>'s island invite.";
|
||||||
String playerOffline = "This request has denied because both players are no longer online.";
|
String playerOffline = "This request has denied because both players are no longer online.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Restart restart = new Restart();
|
||||||
|
|
||||||
|
@ConfigSerializable @Getter
|
||||||
|
public static class Restart {
|
||||||
|
String created = "Island restart request created type <yellow>/island restart confirm</yellow> or <yellow>/island restart deny</yellow>.<newline><red>This action can not be reversed!";
|
||||||
|
String cancelled = "You have cancelled your island restart request!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package com.alttd.cometskyblock.island;
|
package com.alttd.cometskyblock.island;
|
||||||
|
|
||||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||||
|
import com.alttd.cometskyblock.request.Request;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -36,6 +38,7 @@ public class Island extends YamlConfiguration {
|
||||||
private final File file;
|
private final File file;
|
||||||
private final Object saveLock = new Object();
|
private final Object saveLock = new Object();
|
||||||
@Getter private final UUID islandUUID;
|
@Getter private final UUID islandUUID;
|
||||||
|
@Getter @Setter private Request request;
|
||||||
|
|
||||||
private Island(UUID uuid) {
|
private Island(UUID uuid) {
|
||||||
super();
|
super();
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public abstract class Request {
|
public abstract class Request {
|
||||||
|
|
||||||
private final CometSkyBlockPlugin plugin;
|
protected final CometSkyBlockPlugin plugin;
|
||||||
@Getter private final Player requester;
|
@Getter private final Player requester;
|
||||||
@Getter private final Player target;
|
@Getter private final Player target;
|
||||||
private final RequestTimeout timeoutTask;
|
private final RequestTimeout timeoutTask;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ public class RequestTimeout extends BukkitRunnable {
|
||||||
);
|
);
|
||||||
var messagesConfig = CometSkyBlockPlugin.instance().messagesConfiguration().get().requests();
|
var messagesConfig = CometSkyBlockPlugin.instance().messagesConfiguration().get().requests();
|
||||||
request.requester().sendRichMessage(messagesConfig.timedOut(), placeholders);
|
request.requester().sendRichMessage(messagesConfig.timedOut(), placeholders);
|
||||||
request.target().sendRichMessage(messagesConfig.timedOut(), placeholders);
|
if (request.requester() != request.target())
|
||||||
|
request.target().sendRichMessage(messagesConfig.timedOut(), placeholders);
|
||||||
|
|
||||||
request.cancel();
|
request.cancel();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
package com.alttd.cometskyblock.request;
|
package com.alttd.cometskyblock.request;
|
||||||
|
|
||||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||||
|
import com.alttd.cometskyblock.island.Island;
|
||||||
|
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class RestartRequest extends Request {
|
public class RestartRequest extends Request {
|
||||||
|
|
@ -8,40 +13,39 @@ public class RestartRequest extends Request {
|
||||||
public RestartRequest(CometSkyBlockPlugin plugin, Player requester, Player target) {
|
public RestartRequest(CometSkyBlockPlugin plugin, Player requester, Player target) {
|
||||||
super(plugin, requester, target);
|
super(plugin, requester, target);
|
||||||
|
|
||||||
requester.sendRichMessage(requests().restart().islandInviteSend(), placeholders());
|
requester.sendRichMessage(requests().restart().created(), placeholders());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept() {
|
public void accept() {
|
||||||
if (!target().isOnline() || !requester().isOnline()) {
|
IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(requester().getUniqueId());
|
||||||
if (target().isOnline())
|
// Teleport everyone on the island to spawnworld
|
||||||
target().sendRichMessage(requests().invite().playerOffline());
|
Island island = Island.getIsland(islandPlayer.islandUUID());
|
||||||
|
if (island == null) {
|
||||||
if (requester().isOnline())
|
// could not load island
|
||||||
requester().sendRichMessage(requests().invite().playerOffline());
|
|
||||||
|
|
||||||
cancel();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
target().sendRichMessage(requests().invite().accept(), placeholders());
|
World islandWorld = plugin.worldGenerator().loadIslandWorld(island.worldName());
|
||||||
requester().sendRichMessage(requests().invite().accept(), placeholders());
|
if (islandWorld == null) {
|
||||||
|
// could not load world
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
World world = Bukkit.getWorlds().get(0);
|
||||||
|
Location spawnLocation = world.getSpawnLocation();
|
||||||
|
for (Player target : islandWorld.getPlayers()) {
|
||||||
|
target.teleport(spawnLocation);
|
||||||
|
}
|
||||||
|
// TODO - run code to generate a new world and update the id for all members!
|
||||||
super.accept();
|
super.accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deny() {
|
public void deny() {
|
||||||
if (!target().isOnline() || !requester().isOnline()) {
|
if (!requester().isOnline()) {
|
||||||
if (target().isOnline())
|
|
||||||
target().sendRichMessage(requests().invite().playerOffline());
|
|
||||||
|
|
||||||
if (requester().isOnline())
|
|
||||||
requester().sendRichMessage(requests().invite().playerOffline());
|
|
||||||
|
|
||||||
cancel();
|
cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
target().sendRichMessage(requests().invite().denied(), placeholders());
|
requester().sendRichMessage(requests().restart().cancelled(), placeholders());
|
||||||
requester().sendRichMessage(requests().invite().denied(), placeholders());
|
|
||||||
super.deny();
|
super.deny();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user