- T2CodeLib 15.9 is required!
- Strings and lists can now be used for the message
Examples:
String:
message: 'test
List:
message:
  - test 1
  - test 2
This commit is contained in:
JaTiTV 2023-08-04 16:36:29 +02:00
parent b9d20ffb06
commit ea4fb0b88d
5 changed files with 41 additions and 12 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId>
<artifactId>AutomatedMessages</artifactId>
<version>1.1</version>
<version>1.2</version>
<!--version>VERSION_snapshot-0</version-->
<!--version>VERSION_beta-0</version-->
<!--version>VERSION_dev-0</version-->
@ -27,8 +27,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
<plugin>
@ -84,7 +84,8 @@
<dependency>
<groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId>
<version>15.3</version>
<version>15.9</version>
<classifier>dev-2</classifier>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->

View File

@ -8,7 +8,7 @@ public class Util {
private static String infoText = "";
@Getter
private static String requiredT2CodeLibVersion = "15.3";
private static String requiredT2CodeLibVersion = "15.9";
@Getter
private static String prefix = "<dark_gray>[<dark_red>T2C</dark_red>-<color:#5cff5c>Automated</color><color:#69d2ff>Messages</color>]</dark_gray>";

View File

@ -9,6 +9,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.HashMap;
import java.util.Objects;
public class MessagesSelect {
@ -47,7 +48,7 @@ public class MessagesSelect {
for (Messages value : Messages.values()) {
Boolean enable = yamlConfiguration.getBoolean(value.msgEnablePath);
String message = yamlConfiguration.getString(value.msgMsgPath);
Object message = yamlConfiguration.get(value.msgMsgPath);
Boolean soundEnable = yamlConfiguration.getBoolean(value.soundEnablePath);
Sound sound;

View File

@ -7,17 +7,44 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.*;
public class SendMessage {
public static void send(Message message) {
String timeStamp = new SimpleDateFormat(Config.timeFormat.valueString).format(Calendar.getInstance().getTime());
if (Config.sendConsole.valueBoolean) T2Csend.console(message.message.replace("[time]", timeStamp).replace("[prefix]",Config.prefix.valueString));
if (Config.sendConsole.valueBoolean) {
T2Csend.console(replace(message.message, Map.entry("[time]", timeStamp), Map.entry("[prefix]", Config.prefix.valueString)));
}
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.hasPermission(message.permission) || !message.permissionNeededToSeeMessage) {
T2Csend.player(player, message.message.replace("[time]", timeStamp).replace("[prefix]",Config.prefix.valueString).replace("[player]",player.getName()));
T2Csend.player(player, replace(message.message, Map.entry("[time]", timeStamp), Map.entry("[prefix]", Config.prefix.valueString), Map.entry("[player]", player.getName())));
player.playSound(player.getLocation(), message.sound, 3, 1);
}
}
}
@SafeVarargs
private static Object replace(Object object, Map.Entry<String, String>... map) {
Object o = null;
if (object instanceof List) {
ArrayList<String> res = (ArrayList<String>) object;
ArrayList<String> out = new ArrayList<>();
for (String s : res) {
String re = s;
for (Map.Entry<String, String> placeholder : map) {
re = re.replace(placeholder.getKey(), placeholder.getValue());
}
out.add(re);
}
o = out;
}
if (object instanceof String) {
String res = (String) object;
for (Map.Entry<String, String> placeholder : map) {
res = res.replace(placeholder.getKey(), placeholder.getValue());
}
o = res;
}
return o;
}
}

View File

@ -9,7 +9,7 @@ public class Message {
public String key;
public Boolean enable;
public String message;
public Object message;
public Boolean soundEnable;
public Sound sound;
@ -25,7 +25,7 @@ public class Message {
public Message(String key,
Boolean enable,
String message,
Object message,
Boolean soundEnable,
Sound sound,
Boolean permissionNeededToSeeMessage,