This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Cmd_Wt.java
106 lines (97 loc) · 4.68 KB
/
Cmd_Wt.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* jaoLicense
*
* Copyright (c) 2022 jao Minecraft Server
*
* The following license applies to this project: jaoLicense
*
* Japanese: https://github.com/jaoafa/jao-Minecraft-Server/blob/master/jaoLICENSE.md
* English: https://github.com/jaoafa/jao-Minecraft-Server/blob/master/jaoLICENSE-en.md
*/
package com.jaoafa.mymaid4.command;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.bukkit.parsers.PlayerArgument;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.meta.CommandMeta;
import com.jaoafa.mymaid4.lib.CommandPremise;
import com.jaoafa.mymaid4.lib.MyMaidCommand;
import com.jaoafa.mymaid4.lib.MyMaidData;
import com.jaoafa.mymaid4.lib.MyMaidLibrary;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Map;
public class Cmd_Wt extends MyMaidLibrary implements CommandPremise {
@Override
public MyMaidCommand.Detail details() {
return new MyMaidCommand.Detail(
"wt",
"他ワールドにテレポートします。"
);
}
@Override
public MyMaidCommand.Cmd register(cloud.commandframework.Command.Builder<CommandSender> builder) {
return new MyMaidCommand.Cmd(
builder
.meta(CommandMeta.DESCRIPTION, "指定したワールドにテレポートします。")
.senderType(Player.class)
.argument(StringArgument
.<CommandSender>newBuilder("worldName")
.withSuggestionsProvider(MyMaidLibrary::suggestWorldNames), ArgumentDescription.of("ワールド名もしくはワールド番号"))
.handler(this::worldTeleport)
.build(),
builder
.meta(CommandMeta.DESCRIPTION, "指定したプレイヤーを指定したワールドにテレポートさせます。")
.argument(StringArgument
.<CommandSender>newBuilder("worldName")
.withSuggestionsProvider(MyMaidLibrary::suggestWorldNames), ArgumentDescription.of("ワールド名もしくはワールド番号"))
.argument(PlayerArgument.of("player"), ArgumentDescription.of("テレポートさせるプレイヤー"))
.handler(this::worldTeleportPlayer)
.build()
);
}
void worldTeleport(CommandContext<CommandSender> context) {
Player player = (Player) context.getSender();
String worldName = context.get("worldName");
Map<String, String> worlds = MyMaidData.getAliasWorlds();
World world = Bukkit.getWorld(worlds.getOrDefault(worldName, worldName));
if (world == null) {
SendMessage(player, details(), String.format("「%s」ワールドの取得に失敗しました。", worlds.getOrDefault(worldName, worldName)));
return;
}
Location loc = new Location(world, 0, 0, 0, 0, 0);
int y = getGroundPos(loc);
loc = new Location(world, 0, y, 0, 0, 0);
loc.add(0.5f, 0f, 0.5f);
player.teleport(loc);
SendMessage(player, details(), String.format("「%s」ワールドにテレポートしました。", world.getName()));
}
void worldTeleportPlayer(CommandContext<CommandSender> context) {
Player player = context.getOrDefault("player", null);
if (player == null) {
return;
}
CommandSender sender = context.getSender();
if (sender instanceof Player && !isAMR((Player) sender)) {
SendMessage(player, details(), "あなたは他人をテレポートさせることはできません");
return;
}
String worldName = context.get("worldName");
Map<String, String> worlds = MyMaidData.getAliasWorlds();
World world = Bukkit.getWorld(worlds.getOrDefault(worldName, worldName));
if (world == null) {
SendMessage(player, details(), String.format("「%s」ワールドの取得に失敗しました。", worlds.getOrDefault(worldName, worldName)));
return;
}
Location loc = new Location(world, 0, 0, 0, 0, 0);
int y = getGroundPos(loc);
loc = new Location(world, 0, y, 0, 0, 0);
loc.add(0.5f, 0f, 0.5f);
player.teleport(loc);
SendMessage(player, details(), String.format("「%s」ワールドにテレポートしました。", world.getName()));
SendMessage(sender, details(), String.format("プレイヤー「%s」を「%s」ワールドにテレポートさせました。", player, world.getName()));
}
}