This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Methods.java
143 lines (110 loc) · 5.46 KB
/
Methods.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package me.h1dd3nxn1nja.chatmanager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import me.h1dd3nxn1nja.chatmanager.support.PluginSupport;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import me.clip.placeholderapi.PlaceholderAPI;
import me.h1dd3nxn1nja.chatmanager.commands.CommandMuteChat;
import me.h1dd3nxn1nja.chatmanager.listeners.ListenerCaps;
import net.md_5.bungee.api.ChatColor;
public class Methods {
private static final ChatManager plugin = ChatManager.getPlugin();
private static final SettingsManager settingsManager = plugin.getSettingsManager();
public static HashMap<Player, Player> cm_replied = new HashMap<Player, Player>();
public static HashMap<Player, String> cm_previousMessages = new HashMap<>();
public static HashMap<Player, String> cm_previousCommand = new HashMap<>();
public static HashMap<Player, Integer> cm_chatCooldown = new HashMap<>();
public static HashMap<Player, BukkitRunnable> cm_cooldownTask = new HashMap<>();
public static HashMap<Player, Integer> cm_commandCooldown = new HashMap<>();
public static HashSet<UUID> cm_pwcGlobal = new HashSet<>();
public static HashSet<UUID> cm_toggleChat = new HashSet<>();
public static HashSet<UUID> cm_toggleMentions = new HashSet<>();
public static HashSet<UUID> cm_localChat = new HashSet<>();
public static HashSet<UUID> cm_globalChat = new HashSet<>();
public static HashSet<UUID> cm_worldChat = new HashSet<>();
public static HashSet<UUID> cm_spyChat = new HashSet<>();
public static ArrayList<UUID> cm_antiBot = new ArrayList<>();
public static ArrayList<UUID> cm_commandSpy = new ArrayList<>();
public static ArrayList<UUID> cm_socialSpy = new ArrayList<>();
public static ArrayList<UUID> cm_staffChat = new ArrayList<>();
public static ArrayList<UUID> cm_togglePM = new ArrayList<>();
private static final char COLOR_CHAR = ChatColor.COLOR_CHAR;
public static String color(String message) {
String format = settingsManager.getConfig().getString("Hex_Color_Format");
Pattern hex = Pattern.compile(format + "([A-Fa-f0-9]{6})");
Matcher matcher = hex.matcher(message);
StringBuilder buffer = new StringBuilder(message.length() + 4 * 8);
while (matcher.find()) {
String group = matcher.group(1);
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5)
);
}
return ChatColor.translateAlternateColorCodes('&', message);
}
public static String color(Player player, String message) {
String format = settingsManager.getConfig().getString("Hex_Color_Format");
Pattern hex = Pattern.compile(format + "([A-Fa-f0-9]{6})");
Matcher matcher = hex.matcher(message);
StringBuilder buffer = new StringBuilder(message.length() + 4 * 8);
while (matcher.find()) {
String group = matcher.group(1);
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5)
);
}
return PluginSupport.PLACEHOLDERAPI.isPluginEnabled() ? ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, matcher.appendTail(buffer).toString())) : color(message);
}
public static String getPrefix() {
return color(settingsManager.getMessages().getString("Message.Prefix"));
}
public static String noPermission() {
return color(settingsManager.getMessages().getString("Message.No_Permission").replace("{Prefix}", getPrefix()));
}
public static boolean getMuted() {
return CommandMuteChat.muted;
}
public boolean isUppercase(String string) {
return ListenerCaps.upperCase.contains(string);
}
public static void tellConsole(String message, boolean prefix) {
if (prefix) {
sendMessage(plugin.getServer().getConsoleSender(), message, true);
return;
}
sendMessage(plugin.getServer().getConsoleSender(), message, false);
}
public static boolean inRange(Player player, Player receiver, int radius) {
if (receiver.getLocation().getWorld().equals(player.getLocation().getWorld())) {
return receiver.getLocation().distanceSquared(player.getLocation()) <= radius * radius;
}
return false;
}
public static boolean inWorld(Player player, Player receiver) {
return receiver.getLocation().getWorld().equals(player.getLocation().getWorld());
}
public static void sendMessage(CommandSender commandSender, String message, boolean prefixToggle) {
if (message == null || message.isEmpty()) return;
String prefix = getPrefix();
if (commandSender instanceof Player player) {
if (!prefix.isEmpty() && prefixToggle) player.sendMessage(color(message.replace("{Prefix}", prefix))); else player.sendMessage(color(message));
return;
}
if (!prefix.isEmpty() && prefixToggle) commandSender.sendMessage(color(message.replace("{Prefix}", prefix))); else commandSender.sendMessage(color(message));
}
public static void broadcast(String message) {
if (message == null || message.isEmpty()) return;
String prefix = getPrefix();
if (!prefix.isEmpty()) plugin.getServer().broadcastMessage(color(message.replace("{Prefix}", prefix))); else plugin.getServer().broadcastMessage(color(message));
}
}