Add InviteRequest.java
This commit is contained in:
parent
144383769c
commit
adacce0677
|
|
@ -22,10 +22,10 @@ public class IslandCommand extends PlayerSubCommand {
|
|||
registerSubCommand(new IslandLeave(plugin));
|
||||
registerSubCommand(new IslandLevel(plugin)); // TODO -- Add IslandLevelCommand
|
||||
// registerSubCommand(new IslandTop(plugin)); // TODO -- Add IslandTopCommand
|
||||
registerSubCommand(new IslandInvite(plugin)); // TODO -- Add IslandInviteCommand
|
||||
registerSubCommand(new IslandInvite(plugin));
|
||||
registerSubCommand(new IslandKick(plugin)); // TODO -- Add IslandKickCommand
|
||||
registerSubCommand(new IslandSetOwner(plugin)); // TODO -- Add some more output
|
||||
registerSubCommand(new IslandVisit(plugin)); // TODO -- Add some more output
|
||||
registerSubCommand(new IslandVisit(plugin));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ 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.VisitRequest;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
|
|
@ -16,7 +19,7 @@ public class IslandVisit extends PlayerSubCommand {
|
|||
super(plugin, "visit");
|
||||
}
|
||||
|
||||
// TODO -- finish IslandVisitCommand and Request
|
||||
// TODO -- ad
|
||||
@Override
|
||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||
MessageConfiguration.Commands.Island.Visit visit = plugin.messagesConfiguration().get().commands().island().visit();
|
||||
|
|
@ -26,30 +29,32 @@ public class IslandVisit extends PlayerSubCommand {
|
|||
}
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (player == target) {
|
||||
// can't visit self
|
||||
player.sendRichMessage(visit.visitSelf());
|
||||
return true;
|
||||
}
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.unparsed("target", args[0])
|
||||
);
|
||||
if (target == null) {
|
||||
// target offline
|
||||
player.sendRichMessage(visit.targetOffline(), placeholders);
|
||||
return true;
|
||||
}
|
||||
IslandPlayer islandPlayer1 = IslandPlayer.getIslandPlayer(target.getUniqueId());
|
||||
if (islandPlayer1.islandId() == 0) {
|
||||
// target does not have an island
|
||||
player.sendRichMessage(visit.targetHasNoIsland(), placeholders);
|
||||
return true;
|
||||
}
|
||||
Island island = Island.getIsland(islandPlayer1.islandUUID());
|
||||
if (island == null) {
|
||||
// failed to load island
|
||||
return true;
|
||||
}
|
||||
if (island.visitNeedsRequest()) {
|
||||
// send request
|
||||
islandPlayer1.request(new VisitRequest(plugin, player, target));
|
||||
return true;
|
||||
}
|
||||
World islandWorld = plugin.worldGenerator().loadIslandWorld(island.worldName());
|
||||
if (islandWorld == null) {
|
||||
// could not load world
|
||||
player.sendRichMessage("<red>Could not load this world. Contact an administrator!");
|
||||
return true;
|
||||
}
|
||||
player.teleportAsync(islandWorld.getSpawnLocation());
|
||||
|
|
|
|||
|
|
@ -128,7 +128,9 @@ public class MessageConfiguration implements Configuration {
|
|||
Visit visit = new Visit();
|
||||
@ConfigSerializable @Getter
|
||||
public static class Visit {
|
||||
|
||||
String visitSelf = "<red>You can not visit your own island.";
|
||||
String targetOffline = "<red><target> not found, is the player online?";
|
||||
String targetHasNoIsland = "<red><target> does not have an island.";
|
||||
}
|
||||
|
||||
Go go = new Go();
|
||||
|
|
@ -159,6 +161,7 @@ public class MessageConfiguration implements Configuration {
|
|||
public static class Requests {
|
||||
String timedOut = "Your request has timed out!";
|
||||
String noPendingRequests = "You have no pending requests, have they been timed out?";
|
||||
String playerOffline = "This request has denied because both players are no longer online.";
|
||||
|
||||
private Invite invite = new Invite();
|
||||
|
||||
|
|
@ -168,7 +171,6 @@ public class MessageConfiguration implements Configuration {
|
|||
String islandInviteReceived = "<requester> has requested you to join their island.<newline>Type <yellow>/island accept</yellow> to accept or <yellow>/island deny</yellow> to deny.";
|
||||
String accept = "<target> has accepted <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.";
|
||||
}
|
||||
|
||||
private Restart restart = new Restart();
|
||||
|
|
@ -188,6 +190,18 @@ public class MessageConfiguration implements Configuration {
|
|||
String accept = "You have left your island.";
|
||||
String denied = "You have cancelled your request.";
|
||||
}
|
||||
|
||||
private Visit visit = new Visit();
|
||||
|
||||
@ConfigSerializable @Getter
|
||||
public static class Visit {
|
||||
String created = "<requester> has requested to teleport to your island. Type <yellow>/island accept</yellow> or <yellow>/island deny</yellow> to confirm.";
|
||||
String send = "You have send a request to visit <target>'s island.";
|
||||
String targetAccept = "you have accepted <requester>'s island visit request.";
|
||||
String requesterAccept = "<target> has accepted your island visit request.";
|
||||
String targetDenied = "you have denied <requester>'s island visit request.";
|
||||
String requesterDenied = "<target> has denied your island visit request.";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ public class InviteRequest extends Request {
|
|||
public void accept() {
|
||||
if (!target().isOnline() || !requester().isOnline()) {
|
||||
if (target().isOnline())
|
||||
target().sendRichMessage(requests().invite().playerOffline());
|
||||
target().sendRichMessage(requests().playerOffline());
|
||||
|
||||
if (requester().isOnline())
|
||||
requester().sendRichMessage(requests().invite().playerOffline());
|
||||
requester().sendRichMessage(requests().playerOffline());
|
||||
|
||||
cancel();
|
||||
return;
|
||||
|
|
@ -38,10 +38,10 @@ public class InviteRequest extends Request {
|
|||
public void deny() {
|
||||
if (!target().isOnline() || !requester().isOnline()) {
|
||||
if (target().isOnline())
|
||||
target().sendRichMessage(requests().invite().playerOffline());
|
||||
target().sendRichMessage(requests().playerOffline());
|
||||
|
||||
if (requester().isOnline())
|
||||
requester().sendRichMessage(requests().invite().playerOffline());
|
||||
requester().sendRichMessage(requests().playerOffline());
|
||||
|
||||
cancel();
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
package com.alttd.cometskyblock.request;
|
||||
|
||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class VisitRequest extends Request {
|
||||
|
||||
public VisitRequest(CometSkyBlockPlugin plugin, Player requester, Player target) {
|
||||
super(plugin, requester, target);
|
||||
|
||||
target.sendRichMessage(requests().visit().created(), placeholders());
|
||||
requester.sendRichMessage(requests().visit().send(), placeholders());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept() {
|
||||
if (!target().isOnline() || !requester().isOnline()) {
|
||||
if (target().isOnline())
|
||||
target().sendRichMessage(requests().playerOffline());
|
||||
|
||||
if (requester().isOnline())
|
||||
requester().sendRichMessage(requests().playerOffline());
|
||||
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
target().sendRichMessage(requests().visit().targetAccept(), placeholders());
|
||||
requester().sendRichMessage(requests().visit().requesterAccept(), placeholders());
|
||||
super.accept();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deny() {
|
||||
if (!target().isOnline() || !requester().isOnline()) {
|
||||
if (target().isOnline())
|
||||
target().sendRichMessage(requests().playerOffline());
|
||||
|
||||
if (requester().isOnline())
|
||||
requester().sendRichMessage(requests().playerOffline());
|
||||
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
target().sendRichMessage(requests().visit().targetDenied(), placeholders());
|
||||
requester().sendRichMessage(requests().visit().requesterDenied(), placeholders());
|
||||
super.deny();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user