Skip to content

Commit f937c50

Browse files
committed
More customization settings
1 parent cac616c commit f937c50

File tree

7 files changed

+70
-15
lines changed

7 files changed

+70
-15
lines changed

src/main/java/io/github/bilektugrul/simpleservertools/features/placeholders/PAPIPlaceholders.java

+21-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import io.github.bilektugrul.simpleservertools.SST;
44
import io.github.bilektugrul.simpleservertools.features.vanish.VanishManager;
5+
import io.github.bilektugrul.simpleservertools.users.User;
6+
import io.github.bilektugrul.simpleservertools.users.UserManager;
7+
import io.github.bilektugrul.simpleservertools.utils.Utils;
58
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
69
import org.bukkit.Bukkit;
710
import org.bukkit.entity.Player;
@@ -12,11 +15,13 @@ public class PAPIPlaceholders extends PlaceholderExpansion {
1215
private final SST plugin;
1316
private final CustomPlaceholderManager placeholderManager;
1417
private final VanishManager vanishManager;
18+
private final UserManager userManager;
1519

1620
public PAPIPlaceholders(SST plugin) {
1721
this.plugin = plugin;
1822
this.placeholderManager = plugin.getPlaceholderManager();
1923
this.vanishManager = plugin.getVanishManager();
24+
this.userManager = plugin.getUserManager();
2025
}
2126

2227
@Override
@@ -47,26 +52,38 @@ public boolean canRegister() {
4752
@Override
4853
public String onPlaceholderRequest(Player player, @NotNull String identifier) {
4954

50-
boolean playerRequired = (identifier.equals("safeonline"));
55+
boolean playerRequired = identifier.equals("safeonline");
56+
boolean userRequired = identifier.contains("status");
5157

5258
if (playerRequired) {
5359
if (player == null) return "";
5460
}
5561

5662
if (identifier.equals("safeonline")) {
63+
int size = Bukkit.getOnlinePlayers().size();
5764
if (!player.hasPermission("sst.staff")) {
58-
return String.valueOf(Bukkit.getOnlinePlayers().size() - vanishManager.getOnlineVanishedPlayers().size());
65+
return String.valueOf(size - vanishManager.getOnlineVanishedPlayers().size());
5966
} else {
60-
return String.valueOf(Bukkit.getOnlinePlayers().size());
67+
return String.valueOf(size);
6168
}
6269
}
6370

64-
if (identifier.equals("vanished")){
71+
if (identifier.equals("vanished")) {
6572
return String.valueOf(vanishManager.getOnlineVanishedPlayers().size());
73+
6674
} else if (identifier.contains("custom")) {
6775
String name = identifier.substring(identifier.indexOf("custom_") + 7);
6876
return placeholderManager.getPlaceholder(name).getValue();
77+
78+
} else if (userRequired) {
79+
User user = userManager.getUser(player);
80+
if (identifier.endsWith("msg")) {
81+
return Utils.getMessage("user-statuses.msg." + user.isAcceptingMsg());
82+
} else if (identifier.endsWith("tpa")){
83+
return Utils.getMessage("user-statuses.tpa." + user.isAcceptingTPA());
84+
}
6985
}
86+
7087
return null;
7188
}
7289

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.github.bilektugrul.simpleservertools.stuff;
2+
3+
public enum MessageType {
4+
5+
CHAT, TITLE, ACTIONBAR
6+
7+
}

src/main/java/io/github/bilektugrul/simpleservertools/stuff/teleporting/TeleportTask.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.github.bilektugrul.simpleservertools.SST;
44
import io.github.bilektugrul.simpleservertools.stuff.CancelMode;
5+
import io.github.bilektugrul.simpleservertools.stuff.MessageType;
56
import io.github.bilektugrul.simpleservertools.users.User;
67
import io.github.bilektugrul.simpleservertools.users.UserManager;
78
import io.github.bilektugrul.simpleservertools.users.UserState;
@@ -24,10 +25,10 @@ public class TeleportTask extends BukkitRunnable {
2425
private final boolean isStaff;
2526
private int time;
2627
private String teleportingMsg;
27-
private final String teleportingMode;
28+
private final MessageType teleportingMode;
2829
private String teleportingSub;
2930
private String teleportedMsg;
30-
private final String teleportedMode;
31+
private final MessageType teleportedMode;
3132
private String teleportedSub;
3233
private final Location firstLoc;
3334
private final Location finalLoc;
@@ -49,11 +50,11 @@ public TeleportTask(Player player, Location loc, TeleportMode teleportMode, Tele
4950
: settings.getTime();
5051

5152
teleportingMsg = Utils.getMessage("" + mode + ".teleporting.message", player);
52-
teleportingMode = Utils.getMessage("" + mode + ".teleporting.mode", player);
53+
teleportingMode = MessageType.valueOf(Utils.getMessage("" + mode + ".teleporting.mode", player));
5354
teleportingSub = "";
5455

5556
teleportedMsg = Utils.getMessage("" + mode + ".teleported.message", player);
56-
teleportedMode = Utils.getMessage("" + mode +".teleported.mode", player);
57+
teleportedMode = MessageType.valueOf(Utils.getMessage("" + mode +".teleported.mode", player));
5758
teleportedSub = "";
5859

5960
firstLoc = player.getLocation();
@@ -81,7 +82,7 @@ public TeleportTask(Player player, Location loc, TeleportMode teleportMode, Tele
8182
teleportingMsg = teleportingMsg.replace("%teleporting%", teleportingTo);
8283
}
8384

84-
if ((teleportingMode.equalsIgnoreCase("TITLE") && teleportingMsg.contains("\n"))) {
85+
if ((teleportingMode == MessageType.TITLE && teleportingMsg.contains("\n"))) {
8586
int index = teleportingMsg.indexOf("\n");
8687
try {
8788
teleportingSub = teleportingMsg.split("\n")[1];
@@ -90,7 +91,7 @@ public TeleportTask(Player player, Location loc, TeleportMode teleportMode, Tele
9091
}
9192
teleportingMsg = teleportingMsg.substring(0, index);
9293
}
93-
if (teleportedMode.equalsIgnoreCase("TITLE") && teleportedMsg.contains("\n")) {
94+
if (teleportedMode == MessageType.TITLE && teleportedMsg.contains("\n")) {
9495
int index = teleportedMsg.indexOf("\n");
9596
try {
9697
teleportedSub = teleportedMsg.split("\n")[1];

src/main/java/io/github/bilektugrul/simpleservertools/utils/Utils.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.github.bilektugrul.simpleservertools.SST;
44
import io.github.bilektugrul.simpleservertools.features.language.LanguageManager;
55
import io.github.bilektugrul.simpleservertools.features.placeholders.CustomPlaceholderManager;
6+
import io.github.bilektugrul.simpleservertools.stuff.MessageType;
67
import me.clip.placeholderapi.PlaceholderAPI;
78
import me.despical.commons.compat.Titles;
89
import net.md_5.bungee.api.ChatColor;
@@ -25,6 +26,10 @@ private Utils() {}
2526

2627
private static final boolean isPAPIEnabled = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
2728

29+
public static String getMessage(String string) {
30+
return getString(languageManager.getLanguage(), "messages." + string, null, false, false);
31+
}
32+
2833
public static String getMessage(String string, CommandSender from) {
2934
return getString(languageManager.getLanguage(), "messages." + string, from);
3035
}
@@ -49,6 +54,10 @@ public static String getString(FileConfiguration file, String string, CommandSen
4954
return replacePlaceholders(file.getString(string), from, replacePersonalPlaceholders);
5055
}
5156

57+
public static String getString(FileConfiguration file, String string, CommandSender from, boolean replacePersonalPlaceholders, boolean replacePAPI) {
58+
return replacePlaceholders(file.getString(string), from, replacePersonalPlaceholders);
59+
}
60+
5261
public static String replacePlaceholders(String msg, CommandSender from, boolean replacePersonalPlaceholders, boolean replacePAPI) {
5362
boolean isPlayer = from instanceof Player;
5463
msg = placeholderManager.replacePlaceholders(ChatColor.translateAlternateColorCodes('&', msg));
@@ -105,17 +114,17 @@ public static boolean isSameLoc(Location loc1, Location loc2) {
105114
return (loc1.getBlockX() == loc2.getBlockX()) && (loc1.getBlockY() == loc2.getBlockY()) && (loc1.getBlockZ() == loc2.getBlockZ());
106115
}
107116

108-
public static void sendMessage(Player p, String mode, String msg, String subtitle, String time) {
117+
public static void sendMessage(Player p, MessageType mode, String msg, String subtitle, String time) {
109118
msg = msg.replace("%time%", time);
110119
subtitle = subtitle.replace("%time%", time) ;
111120
switch (mode) {
112-
case "CHAT":
121+
case CHAT:
113122
p.sendMessage(msg);
114123
break;
115-
case "TITLE":
116-
Titles.sendTitle(p, msg, subtitle);
124+
case TITLE:
125+
Titles.sendTitle(p, getInt("titles.fade-in"), getInt("titles.stay"), getInt("titles-fade-out"), msg, subtitle);
117126
break;
118-
case "ACTIONBAR":
127+
case ACTIONBAR:
119128
ActionBar.sendActionBar(p, msg.replace('\n', ' '));
120129
break;
121130
}

src/main/resources/config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ auto-respawn:
4040
enabled: true # removes respawn screen
4141
permission-required: false # sst.autorespawn
4242

43+
titles: # Settings for title messages that are used in language files.
44+
fade-in: 0
45+
stay: 30
46+
fade-out: 0
47+
4348
warps:
4449
tab-complete: true # warp list will be sent to players when they click TAB. (they can not see warps with permissions if they don't have the permission.)
4550
teleport-time: 5 # in seconds

src/main/resources/language/messages_en.yml

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ messages:
1919
config-reloaded: '%prefix% &eEverything has been reloaded, %player%!'
2020
wrong-usage: '%prefix% &cWrong usage. /sst help'
2121

22+
user-statuses:
23+
tpa:
24+
true: ACCEPTS
25+
false: NOT ACCEPTS
26+
msg:
27+
true: ACCEPTS
28+
false: NOT ACCEPTS
29+
2230
vanish:
2331
activated: '%prefix% &eVanish mode: &bENABLED'
2432
disabled: '%prefix% &eVanish mode: &cDISABLED'

src/main/resources/language/messages_tr.yml

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ messages:
3333
config-reloaded: '%prefix% &eAyar dosyası başarıyla yenilendi %player%!'
3434
wrong-usage: '%prefix% &cHatalı kullanım. /sst help'
3535

36+
user-statuses:
37+
tpa:
38+
true: KABUL EDIYOR
39+
false: KABUL ETMIYOR
40+
msg:
41+
true: KABUL EDIYOR
42+
false: KABUL ETMIYOR
43+
3644
vanish:
3745
activated: '%prefix% &eVanish modu: &bAktif'
3846
disabled: '%prefix% &eVanish modu: &cKapalı'

0 commit comments

Comments
 (0)