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.SubCommand;
|
||||
import com.alttd.cometskyblock.configuration.MessageConfiguration;
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||
import com.alttd.cometskyblock.request.InviteRequest;
|
||||
import com.alttd.cometskyblock.request.RestartRequest;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -14,16 +17,23 @@ public class IslandRestart extends PlayerSubCommand {
|
|||
public IslandRestart(CometSkyBlockPlugin plugin) {
|
||||
super(plugin, "restart");
|
||||
registerSubCommand(new IslandRestartConfirm(plugin));
|
||||
registerSubCommand(new IslandRestartDeny(plugin));
|
||||
}
|
||||
|
||||
// TODO -- IslandRestartCommand, add a one day delay on trying to reset again!
|
||||
@Override
|
||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||
MessageConfiguration.Commands.Island.Restart restart = plugin.messagesConfiguration().get().commands().island().restart();
|
||||
if (!islandPlayer.islandOwner()) {
|
||||
// You must be the islandOwner to do this command.
|
||||
player.sendRichMessage(restart.notIslandOwner());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ 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.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
|
@ -12,38 +14,29 @@ import org.bukkit.entity.Player;
|
|||
public class IslandRestartConfirm extends PlayerSubCommand {
|
||||
|
||||
public IslandRestartConfirm(CometSkyBlockPlugin plugin) {
|
||||
super(plugin, "restart");
|
||||
super(plugin, "confirm");
|
||||
}
|
||||
|
||||
// TODO -- IslandRestartCommand, add a one day delay on trying to reset again!
|
||||
@Override
|
||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||
MessageConfiguration.Commands.Island.Restart restart = plugin.messagesConfiguration().get().commands().island().restart();
|
||||
if (!islandPlayer.islandOwner()) {
|
||||
// You must be the islandOwner to do this command.
|
||||
player.sendRichMessage(restart.notIslandOwner());
|
||||
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());
|
||||
if (island == null) {
|
||||
// could not load island
|
||||
return true;
|
||||
}
|
||||
World islandWorld = plugin.worldGenerator().loadIslandWorld(island.worldName());
|
||||
if (islandWorld == null) {
|
||||
// could not load world
|
||||
// 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;
|
||||
}
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
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
|
||||
request.accept();
|
||||
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();
|
||||
@ConfigSerializable @Getter
|
||||
public static class Restart {
|
||||
|
||||
String notIslandOwner = "<red>You must be the island owner to do this.";
|
||||
}
|
||||
|
||||
Accept accept = new Accept();
|
||||
|
|
@ -159,6 +159,14 @@ public class MessageConfiguration implements Configuration {
|
|||
String denied = "<target> has denied <requester>'s island invite.";
|
||||
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;
|
||||
|
||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.request.Request;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -36,6 +38,7 @@ public class Island extends YamlConfiguration {
|
|||
private final File file;
|
||||
private final Object saveLock = new Object();
|
||||
@Getter private final UUID islandUUID;
|
||||
@Getter @Setter private Request request;
|
||||
|
||||
private Island(UUID uuid) {
|
||||
super();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import org.bukkit.entity.Player;
|
|||
|
||||
public abstract class Request {
|
||||
|
||||
private final CometSkyBlockPlugin plugin;
|
||||
protected final CometSkyBlockPlugin plugin;
|
||||
@Getter private final Player requester;
|
||||
@Getter private final Player target;
|
||||
private final RequestTimeout timeoutTask;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ public class RequestTimeout extends BukkitRunnable {
|
|||
);
|
||||
var messagesConfig = CometSkyBlockPlugin.instance().messagesConfiguration().get().requests();
|
||||
request.requester().sendRichMessage(messagesConfig.timedOut(), placeholders);
|
||||
if (request.requester() != request.target())
|
||||
request.target().sendRichMessage(messagesConfig.timedOut(), placeholders);
|
||||
|
||||
request.cancel();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
package com.alttd.cometskyblock.request;
|
||||
|
||||
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;
|
||||
|
||||
public class RestartRequest extends Request {
|
||||
|
|
@ -8,40 +13,39 @@ public class RestartRequest extends Request {
|
|||
public RestartRequest(CometSkyBlockPlugin plugin, Player requester, Player target) {
|
||||
super(plugin, requester, target);
|
||||
|
||||
requester.sendRichMessage(requests().restart().islandInviteSend(), placeholders());
|
||||
requester.sendRichMessage(requests().restart().created(), placeholders());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept() {
|
||||
if (!target().isOnline() || !requester().isOnline()) {
|
||||
if (target().isOnline())
|
||||
target().sendRichMessage(requests().invite().playerOffline());
|
||||
|
||||
if (requester().isOnline())
|
||||
requester().sendRichMessage(requests().invite().playerOffline());
|
||||
|
||||
cancel();
|
||||
IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(requester().getUniqueId());
|
||||
// Teleport everyone on the island to spawnworld
|
||||
Island island = Island.getIsland(islandPlayer.islandUUID());
|
||||
if (island == null) {
|
||||
// could not load island
|
||||
return;
|
||||
}
|
||||
target().sendRichMessage(requests().invite().accept(), placeholders());
|
||||
requester().sendRichMessage(requests().invite().accept(), placeholders());
|
||||
World islandWorld = plugin.worldGenerator().loadIslandWorld(island.worldName());
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deny() {
|
||||
if (!target().isOnline() || !requester().isOnline()) {
|
||||
if (target().isOnline())
|
||||
target().sendRichMessage(requests().invite().playerOffline());
|
||||
|
||||
if (requester().isOnline())
|
||||
requester().sendRichMessage(requests().invite().playerOffline());
|
||||
|
||||
if (!requester().isOnline()) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
target().sendRichMessage(requests().invite().denied(), placeholders());
|
||||
requester().sendRichMessage(requests().invite().denied(), placeholders());
|
||||
requester().sendRichMessage(requests().restart().cancelled(), placeholders());
|
||||
super.deny();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user