Skip to content

Commit 461573b

Browse files
ZP4RKERZP4RKER
authored andcommitted
Completed for first test
1 parent 55a6906 commit 461573b

2 files changed

Lines changed: 52 additions & 16 deletions

File tree

src/main/java/com/perceivedev/clicktpa/ClickableTPA.java

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.bukkit.Bukkit;
44
import org.bukkit.ChatColor;
5+
import org.bukkit.entity.Player;
56
import org.bukkit.event.EventHandler;
67
import org.bukkit.event.Listener;
78
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
@@ -27,25 +28,60 @@ public void onCommandRun(PlayerCommandPreprocessEvent event) {
2728
// Has player as argument
2829
if (Bukkit.getPlayer(command.split(" ")[1]) != null) {
2930
// Valid player (and online)
30-
String acceptText = getConfig().getString("message.accept");
31-
String denyText = getConfig().getString("message.deny");
32-
boolean useDisplayName = getConfig().getBoolean("message.use-display-name");
33-
String[] firstLine = getConfig().getString("message.line-1").split(" ");
34-
JSONMessage message;
35-
for (int i = 0; i < firstLine.length; i++) {
36-
if (i == 0) {
37-
message = JSONMessage.create();
38-
if (firstLine[i].contains("&")) {
39-
int index = firstLine[i].indexOf("&");
40-
ChatColor colour = ChatColor.getByChar(firstLine[i].substring(index, index + 1));
41-
// Add text to JSONMessage instance
42-
}
43-
}
44-
}
31+
sendMessages(Bukkit.getPlayer(command.split(" ")[1]));
4532
}
4633
}
4734
}
4835
}
4936
}
37+
38+
private JSONMessage getFirstLine(Player player) {
39+
boolean useDisplayName = getConfig().getBoolean("message.use-display-name");
40+
JSONMessage message = JSONMessage.create();
41+
if (getConfig().getString("message.line-1") != "") {
42+
String[] words = getConfig().getString("message.line-1").split(" ");
43+
for (int i = 0; i < words.length; i++) {
44+
String word = trans(words[i].replace("%player%", useDisplayName ? player.getDisplayName() : player.getName()));
45+
if (word.equalsIgnoreCase("%accept%")) {
46+
message.then(word).runCommand("tpaccept");
47+
} else if (word.equalsIgnoreCase("%deny%")) {
48+
message.then(word).runCommand("tpdeny");
49+
} else {
50+
message.then(word);
51+
}
52+
message.then(" ");
53+
}
54+
}
55+
return message;
56+
}
57+
58+
private JSONMessage getSecondLine(Player player) {
59+
boolean useDisplayName = getConfig().getBoolean("message.use-display-name");
60+
JSONMessage message = JSONMessage.create();
61+
if (getConfig().getString("message.line-2") != "") {
62+
String[] words = getConfig().getString("message.line-2").split(" ");
63+
for (int i = 0; i < words.length; i++) {
64+
String word = trans(words[i].replace("%player%", useDisplayName ? player.getDisplayName() : player.getName()));
65+
if (word.equalsIgnoreCase("%accept%")) {
66+
message.then(word).runCommand("tpaccept");
67+
} else if (word.equalsIgnoreCase("%deny%")) {
68+
message.then(word).runCommand("tpdeny");
69+
} else {
70+
message.then(word);
71+
}
72+
message.then(" ");
73+
}
74+
}
75+
return message;
76+
}
77+
78+
private void sendMessages(Player player) {
79+
getFirstLine(player).send(player);
80+
getSecondLine(player).send(player);
81+
}
82+
83+
private String trans(String string) {
84+
return ChatColor.translateAlternateColorCodes('&', string);
85+
}
5086

5187
}

src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tpa-command-permission: "essentials.tpa" # The permission for running the tpa co
44
# %accept% = The clickable text to accept the request
55
# %deny% = The clickable text to deny the request
66
message:
7-
line-1: "&2%sender% &6has requested to teleport to you!" # Line one of the message to send to the player
7+
line-1: "&2%player% &6has requested to teleport to you!" # Line one of the message to send to the player
88
line-2: "&6Click %accept% or %deny%" # Line two of the message to send to the player (Leave empty for no second line, i.e "")
99
accept: "&2Accept" # The text of the %accept% placeholder
1010
deny: "&cDeny" # The text of the %deny% placeholder

0 commit comments

Comments
 (0)