mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-05-23 02:19:05 +00:00
Separate proxy architecture.
This commit is contained in:
parent
4e9d70adfb
commit
d7a55622be
2
.settings/.gitignore
vendored
2
.settings/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
/org.eclipse.core.resources.prefs
|
|
||||||
/org.eclipse.m2e.core.prefs
|
|
@ -1,8 +1,5 @@
|
|||||||
eclipse.preferences.version=1
|
#Sat Jan 15 01:48:59 CST 2022
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
|
||||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
|
||||||
org.eclipse.jdt.core.compiler.release=disabled
|
|
||||||
org.eclipse.jdt.core.compiler.source=1.8
|
org.eclipse.jdt.core.compiler.source=1.8
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
|
6
pom.xml
6
pom.xml
@ -260,5 +260,11 @@
|
|||||||
<version>4.2.0</version>
|
<version>4.2.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-junit-jupiter</artifactId>
|
||||||
|
<version>4.2.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package venture.Aust1n46.chat;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
|
||||||
|
import venture.Aust1n46.chat.proxy.VentureChatBungee;
|
||||||
|
|
||||||
|
public class VentureChatBungeePluginModule extends AbstractModule {
|
||||||
|
private final VentureChatBungee plugin;
|
||||||
|
|
||||||
|
public VentureChatBungeePluginModule(final VentureChatBungee plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
this.bind(VentureChatBungee.class).toInstance(plugin);
|
||||||
|
}
|
||||||
|
}
|
@ -19,8 +19,8 @@ import net.md_5.bungee.config.YamlConfiguration;
|
|||||||
import venture.Aust1n46.chat.controllers.commands.MuteContainer;
|
import venture.Aust1n46.chat.controllers.commands.MuteContainer;
|
||||||
import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer;
|
import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer;
|
||||||
import venture.Aust1n46.chat.proxy.VentureChatProxySource;
|
import venture.Aust1n46.chat.proxy.VentureChatProxySource;
|
||||||
import venture.Aust1n46.chat.service.UUIDService;
|
import venture.Aust1n46.chat.service.proxy.ProxyUuidService;
|
||||||
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
|
import venture.Aust1n46.chat.service.proxy.VentureChatProxyPlayerApiService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for reading and writing proxy player data.
|
* Class for reading and writing proxy player data.
|
||||||
@ -29,9 +29,9 @@ import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
|
|||||||
*/
|
*/
|
||||||
public class VentureChatProxyFlatFileController {
|
public class VentureChatProxyFlatFileController {
|
||||||
@Inject
|
@Inject
|
||||||
private UUIDService uuidService;
|
private ProxyUuidService uuidService;
|
||||||
@Inject
|
@Inject
|
||||||
private VentureChatPlayerApiService playerApiService;
|
private VentureChatProxyPlayerApiService playerApiService;
|
||||||
|
|
||||||
public void loadLegacyBungeePlayerData(File dataFolder, VentureChatProxySource source) {
|
public void loadLegacyBungeePlayerData(File dataFolder, VentureChatProxySource source) {
|
||||||
File sync = new File(dataFolder, "BungeePlayers.yml");
|
File sync = new File(dataFolder, "BungeePlayers.yml");
|
||||||
|
@ -17,7 +17,8 @@ public class Me implements VentureCommand {
|
|||||||
@Inject
|
@Inject
|
||||||
private VentureChatPlayerApiService playerApiService;
|
private VentureChatPlayerApiService playerApiService;
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
public void execute(CommandSender sender, String command, String[] args) {
|
public void execute(CommandSender sender, String command, String[] args) {
|
||||||
if (sender.hasPermission("venturechat.me")) {
|
if (sender.hasPermission("venturechat.me")) {
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
|
@ -37,6 +37,7 @@ import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
|
|||||||
import venture.Aust1n46.chat.utilities.FormatUtils;
|
import venture.Aust1n46.chat.utilities.FormatUtils;
|
||||||
|
|
||||||
//This class listens to chat through the chat event and handles the bulk of the chat channels and formatting.
|
//This class listens to chat through the chat event and handles the bulk of the chat channels and formatting.
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ChatListener implements Listener {
|
public class ChatListener implements Listener {
|
||||||
private final boolean essentialsDiscordHook = Bukkit.getPluginManager().isPluginEnabled("EssentialsDiscord");
|
private final boolean essentialsDiscordHook = Bukkit.getPluginManager().isPluginEnabled("EssentialsDiscord");
|
||||||
@ -54,8 +55,7 @@ public class ChatListener implements Listener {
|
|||||||
private ConfigService configService;
|
private ConfigService configService;
|
||||||
|
|
||||||
// this event isn't always asynchronous even though the event's name starts with "Async"
|
// this event isn't always asynchronous even though the event's name starts with "Async"
|
||||||
// blame md_5 for that one
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
|
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@ -564,7 +564,6 @@ public class ChatListener implements Listener {
|
|||||||
System.out.println(out.size() + " bytes size with json");
|
System.out.println(out.size() + " bytes size with json");
|
||||||
}
|
}
|
||||||
out.writeUTF(plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer())); // look into not sending this
|
out.writeUTF(plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer())); // look into not sending this
|
||||||
@SuppressWarnings("deprecation") // Paper Deprecated
|
|
||||||
final String displayName = mcp.getPlayer().getDisplayName();
|
final String displayName = mcp.getPlayer().getDisplayName();
|
||||||
out.writeUTF(displayName);
|
out.writeUTF(displayName);
|
||||||
pluginMessageController.sendPluginMessage(byteOutStream);
|
pluginMessageController.sendPluginMessage(byteOutStream);
|
||||||
|
@ -246,11 +246,14 @@ public class CommandListener implements CommandExecutor, Listener {
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void InventoryClick(InventoryClickEvent e) {
|
public void InventoryClick(InventoryClickEvent e) {
|
||||||
ItemStack item = e.getCurrentItem();
|
if(!e.getView().getTitle().contains("VentureChat")) {
|
||||||
if(item == null || !e.getView().getTitle().contains("VentureChat")) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
ItemStack item = e.getCurrentItem();
|
||||||
|
if (item == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) e.getWhoClicked());
|
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) e.getWhoClicked());
|
||||||
String playerName = e.getView().getTitle().replace(" GUI", "").replace("VentureChat: ", "");
|
String playerName = e.getView().getTitle().replace(" GUI", "").replace("VentureChat: ", "");
|
||||||
VentureChatPlayer target = playerApiService.getMineverseChatPlayer(playerName);
|
VentureChatPlayer target = playerApiService.getMineverseChatPlayer(playerName);
|
||||||
|
@ -18,6 +18,7 @@ public class SignListener implements Listener {
|
|||||||
@Inject
|
@Inject
|
||||||
private VentureChatPlayerApiService playerApiService;
|
private VentureChatPlayerApiService playerApiService;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onSignChange(SignChangeEvent event) {
|
public void onSignChange(SignChangeEvent event) {
|
||||||
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(event.getPlayer());
|
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(event.getPlayer());
|
||||||
|
@ -7,7 +7,9 @@ import java.nio.file.Files;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
@ -24,8 +26,9 @@ import net.md_5.bungee.config.Configuration;
|
|||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
import venture.Aust1n46.chat.VentureChatBungeePluginModule;
|
||||||
import venture.Aust1n46.chat.controllers.VentureChatProxyFlatFileController;
|
import venture.Aust1n46.chat.controllers.VentureChatProxyFlatFileController;
|
||||||
import venture.Aust1n46.chat.service.UUIDService;
|
import venture.Aust1n46.chat.service.proxy.ProxyUuidService;
|
||||||
import venture.Aust1n46.chat.utilities.FormatUtils;
|
import venture.Aust1n46.chat.utilities.FormatUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,34 +39,37 @@ import venture.Aust1n46.chat.utilities.FormatUtils;
|
|||||||
public class VentureChatBungee extends Plugin implements Listener, VentureChatProxySource {
|
public class VentureChatBungee extends Plugin implements Listener, VentureChatProxySource {
|
||||||
private static Configuration bungeeConfig;
|
private static Configuration bungeeConfig;
|
||||||
private File bungeePlayerDataDirectory;
|
private File bungeePlayerDataDirectory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ProxyUuidService uuidService;
|
||||||
@Inject
|
@Inject
|
||||||
private UUIDService uuidService;
|
|
||||||
@Inject
|
|
||||||
private VentureChatProxyFlatFileController proxyFlatFileController;
|
private VentureChatProxyFlatFileController proxyFlatFileController;
|
||||||
@Inject
|
@Inject
|
||||||
private VentureChatProxy proxy;
|
private VentureChatProxy proxy;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
if(!getDataFolder().exists()) {
|
final VentureChatBungeePluginModule pluginModule = new VentureChatBungeePluginModule(this);
|
||||||
|
final Injector injector = Guice.createInjector(pluginModule);
|
||||||
|
injector.injectMembers(this);
|
||||||
|
|
||||||
|
if (!getDataFolder().exists()) {
|
||||||
getDataFolder().mkdir();
|
getDataFolder().mkdir();
|
||||||
}
|
}
|
||||||
File config = new File(getDataFolder(), "bungeeconfig.yml");
|
File config = new File(getDataFolder(), "bungeeconfig.yml");
|
||||||
try {
|
try {
|
||||||
if(!config.exists()) {
|
if (!config.exists()) {
|
||||||
Files.copy(getResourceAsStream("bungeeconfig.yml"), config.toPath());
|
Files.copy(getResourceAsStream("bungeeconfig.yml"), config.toPath());
|
||||||
}
|
}
|
||||||
bungeeConfig = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "bungeeconfig.yml"));
|
bungeeConfig = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "bungeeconfig.yml"));
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
bungeePlayerDataDirectory = new File(getDataFolder().getAbsolutePath() + "/PlayerData");
|
bungeePlayerDataDirectory = new File(getDataFolder().getAbsolutePath() + "/PlayerData");
|
||||||
proxyFlatFileController.loadLegacyBungeePlayerData(bungeePlayerDataDirectory, this);
|
proxyFlatFileController.loadLegacyBungeePlayerData(bungeePlayerDataDirectory, this);
|
||||||
proxyFlatFileController.loadProxyPlayerData(bungeePlayerDataDirectory, this);
|
proxyFlatFileController.loadProxyPlayerData(bungeePlayerDataDirectory, this);
|
||||||
|
|
||||||
this.getProxy().registerChannel(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING);
|
this.getProxy().registerChannel(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING);
|
||||||
this.getProxy().getPluginManager().registerListener(this, this);
|
this.getProxy().getPluginManager().registerListener(this, this);
|
||||||
}
|
}
|
||||||
@ -72,49 +78,48 @@ public class VentureChatBungee extends Plugin implements Listener, VentureChatPr
|
|||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
proxyFlatFileController.saveProxyPlayerData(bungeePlayerDataDirectory, this);
|
proxyFlatFileController.saveProxyPlayerData(bungeePlayerDataDirectory, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(ServerSwitchEvent event) {
|
public void onPlayerJoin(ServerSwitchEvent event) {
|
||||||
updatePlayerNames();
|
updatePlayerNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLeave(ServerDisconnectEvent event) {
|
public void onPlayerLeave(ServerDisconnectEvent event) {
|
||||||
updatePlayerNames();
|
updatePlayerNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoinNetwork(PostLoginEvent event) {
|
public void onPlayerJoinNetwork(PostLoginEvent event) {
|
||||||
uuidService.checkOfflineUUIDWarningProxy(event.getPlayer().getUniqueId(), this);
|
uuidService.checkOfflineUUIDWarningProxy(event.getPlayer().getUniqueId(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePlayerNames() {
|
private void updatePlayerNames() {
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
|
||||||
DataOutputStream out = new DataOutputStream(outstream);
|
DataOutputStream out = new DataOutputStream(outstream);
|
||||||
out.writeUTF("PlayerNames");
|
out.writeUTF("PlayerNames");
|
||||||
out.writeInt(getProxy().getPlayers().size());
|
out.writeInt(getProxy().getPlayers().size());
|
||||||
for(ProxiedPlayer pp : getProxy().getPlayers()) {
|
for (ProxiedPlayer pp : getProxy().getPlayers()) {
|
||||||
out.writeUTF(pp.getName());
|
out.writeUTF(pp.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
for(String send : getProxy().getServers().keySet()) {
|
for (String send : getProxy().getServers().keySet()) {
|
||||||
if(getProxy().getServers().get(send).getPlayers().size() > 0) {
|
if (getProxy().getServers().get(send).getPlayers().size() > 0) {
|
||||||
getProxy().getServers().get(send).sendData(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING, outstream.toByteArray());
|
getProxy().getServers().get(send).sendData(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING, outstream.toByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPluginMessage(PluginMessageEvent event) {
|
public void onPluginMessage(PluginMessageEvent event) {
|
||||||
if(!event.getTag().equals(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING) && !event.getTag().contains("viaversion:")) {
|
if (!event.getTag().equals(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING) && !event.getTag().contains("viaversion:")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!(event.getSender() instanceof Server)) {
|
if (!(event.getSender() instanceof Server)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String serverName = ((Server) event.getSender()).getInfo().getName();
|
String serverName = ((Server) event.getSender()).getInfo().getName();
|
||||||
@ -128,7 +133,8 @@ public class VentureChatBungee extends Plugin implements Listener, VentureChatPr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<VentureChatProxyServer> getServers() {
|
public List<VentureChatProxyServer> getServers() {
|
||||||
return getProxy().getServers().values().stream().map(bungeeServer -> new VentureChatProxyServer(bungeeServer.getName(), bungeeServer.getPlayers().isEmpty())).collect(Collectors.toList());
|
return getProxy().getServers().values().stream().map(bungeeServer -> new VentureChatProxyServer(bungeeServer.getName(), bungeeServer.getPlayers().isEmpty()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -12,7 +12,7 @@ import com.google.inject.Inject;
|
|||||||
import venture.Aust1n46.chat.controllers.commands.MuteContainer;
|
import venture.Aust1n46.chat.controllers.commands.MuteContainer;
|
||||||
import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer;
|
import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer;
|
||||||
import venture.Aust1n46.chat.model.TemporaryDataInstance;
|
import venture.Aust1n46.chat.model.TemporaryDataInstance;
|
||||||
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
|
import venture.Aust1n46.chat.service.proxy.VentureChatProxyPlayerApiService;
|
||||||
|
|
||||||
public class VentureChatProxy {
|
public class VentureChatProxy {
|
||||||
public static String PLUGIN_MESSAGING_CHANNEL_NAMESPACE = "venturechat";
|
public static String PLUGIN_MESSAGING_CHANNEL_NAMESPACE = "venturechat";
|
||||||
@ -20,7 +20,7 @@ public class VentureChatProxy {
|
|||||||
public static String PLUGIN_MESSAGING_CHANNEL_STRING = "venturechat:data";
|
public static String PLUGIN_MESSAGING_CHANNEL_STRING = "venturechat:data";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private VentureChatPlayerApiService playerApiService;
|
private VentureChatProxyPlayerApiService playerApiService;
|
||||||
|
|
||||||
public void onPluginMessage(byte[] data, String serverName, VentureChatProxySource source) {
|
public void onPluginMessage(byte[] data, String serverName, VentureChatProxySource source) {
|
||||||
ByteArrayInputStream instream = new ByteArrayInputStream(data);
|
ByteArrayInputStream instream = new ByteArrayInputStream(data);
|
||||||
|
@ -8,55 +8,31 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import venture.Aust1n46.chat.initiators.application.VentureChat;
|
import venture.Aust1n46.chat.initiators.application.VentureChat;
|
||||||
import venture.Aust1n46.chat.proxy.VentureChatProxySource;
|
|
||||||
import venture.Aust1n46.chat.utilities.FormatUtils;
|
import venture.Aust1n46.chat.utilities.FormatUtils;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class UUIDService {
|
public class UUIDService {
|
||||||
@Inject
|
@Inject
|
||||||
private VentureChat plugin;
|
private VentureChat plugin;
|
||||||
|
|
||||||
/**
|
public boolean shouldSkipOfflineUUID(UUID uuid) {
|
||||||
* Returns whether the passed UUID is a v3 UUID. Offline UUIDs are v3, online are v4.
|
return (FormatUtils.uuidIsOffline(uuid) && !plugin.getConfig().getBoolean("offline_server_acknowledgement", false));
|
||||||
*
|
}
|
||||||
* @param uuid the UUID to check
|
|
||||||
* @return whether the UUID is a v3 UUID & thus is offline
|
public void checkOfflineUUIDWarning(UUID uuid) {
|
||||||
*/
|
if (shouldSkipOfflineUUID(uuid)) {
|
||||||
public boolean uuidIsOffline(UUID uuid) {
|
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Detected Offline UUID!"));
|
||||||
return uuid.version() == 3;
|
Bukkit.getConsoleSender()
|
||||||
}
|
.sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - If you are using BungeeCord, make sure you have properly setup IP Forwarding."));
|
||||||
|
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/"));
|
||||||
public boolean shouldSkipOfflineUUID(UUID uuid) {
|
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - You can access this wiki page from the log file or just Google it."));
|
||||||
return (uuidIsOffline(uuid) && !plugin.getConfig().getBoolean("offline_server_acknowledgement", false));
|
Bukkit.getConsoleSender().sendMessage(FormatUtils
|
||||||
}
|
.FormatStringAll("&8[&eVentureChat&8]&c - If you're running a \"cracked\" server, player data might not be stored properly, and thus, you are on your own."));
|
||||||
|
Bukkit.getConsoleSender().sendMessage(FormatUtils
|
||||||
public boolean shouldSkipOfflineUUIDProxy(UUID uuid, VentureChatProxySource source) {
|
.FormatStringAll("&8[&eVentureChat&8]&c - If you run your server in offline mode, you will probably lose your player data when switching to online mode!"));
|
||||||
return (uuidIsOffline(uuid) && !source.isOfflineServerAcknowledgementSet());
|
Bukkit.getConsoleSender().sendMessage(FormatUtils
|
||||||
}
|
.FormatStringAll("&8[&eVentureChat&8]&c - No player data will be saved in offline mode unless you set the \"cracked\" server acknowledgement in the config!"));
|
||||||
|
return;
|
||||||
public void checkOfflineUUIDWarning(UUID uuid) {
|
|
||||||
if(shouldSkipOfflineUUID(uuid)) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Detected Offline UUID!"));
|
|
||||||
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - If you are using BungeeCord, make sure you have properly setup IP Forwarding."));
|
|
||||||
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/"));
|
|
||||||
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - You can access this wiki page from the log file or just Google it."));
|
|
||||||
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - If you're running a \"cracked\" server, player data might not be stored properly, and thus, you are on your own."));
|
|
||||||
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - If you run your server in offline mode, you will probably lose your player data when switching to online mode!"));
|
|
||||||
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - No player data will be saved in offline mode unless you set the \"cracked\" server acknowledgement in the config!"));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkOfflineUUIDWarningProxy(UUID uuid, VentureChatProxySource source) {
|
|
||||||
if(shouldSkipOfflineUUIDProxy(uuid, source)) {
|
|
||||||
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Detected Offline UUID!");
|
|
||||||
source.sendConsoleMessage("&8[&eVentureChat&8]&c - If you are using BungeeCord, make sure you have properly setup IP Forwarding.");
|
|
||||||
source.sendConsoleMessage("&8[&eVentureChat&8]&c - https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/");
|
|
||||||
source.sendConsoleMessage("&8[&eVentureChat&8]&c - You can access this wiki page from the log file or just Google it.");
|
|
||||||
source.sendConsoleMessage("&8[&eVentureChat&8]&c - If you're running a \"cracked\" server, player data might not be stored properly, and thus, you are on your own.");
|
|
||||||
source.sendConsoleMessage("&8[&eVentureChat&8]&c - If you run your server in offline mode, you will probably lose your player data when switching to online mode!");
|
|
||||||
source.sendConsoleMessage("&8[&eVentureChat&8]&c - No player data will be saved in offline mode unless you set the \"cracked\" server acknowledgement in the config!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,8 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import venture.Aust1n46.chat.model.VentureChatPlayer;
|
import venture.Aust1n46.chat.model.VentureChatPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,152 +18,125 @@ import venture.Aust1n46.chat.model.VentureChatPlayer;
|
|||||||
*
|
*
|
||||||
* @author Aust1n46
|
* @author Aust1n46
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class VentureChatPlayerApiService {
|
public class VentureChatPlayerApiService {
|
||||||
private static HashMap<UUID, VentureChatPlayer> playerMap = new HashMap<UUID, VentureChatPlayer>();
|
private final HashMap<UUID, VentureChatPlayer> playerMap = new HashMap<>();
|
||||||
private static HashMap<String, UUID> namesMap = new HashMap<String, UUID>();
|
private final HashMap<String, UUID> namesMap = new HashMap<>();
|
||||||
private static HashMap<UUID, VentureChatPlayer> onlinePlayerMap = new HashMap<UUID, VentureChatPlayer>();
|
private final HashMap<UUID, VentureChatPlayer> onlinePlayerMap = new HashMap<>();
|
||||||
|
private final List<String> networkPlayerNames = new ArrayList<>();
|
||||||
private static List<String> networkPlayerNames = new ArrayList<String>();
|
|
||||||
private static HashMap<UUID, SynchronizedVentureChatPlayer> proxyPlayerMap = new HashMap<UUID, SynchronizedVentureChatPlayer>();
|
|
||||||
|
|
||||||
public void addNameToMap(VentureChatPlayer mcp) {
|
|
||||||
namesMap.put(mcp.getName(), mcp.getUuid());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeNameFromMap(String name) {
|
public void addNameToMap(VentureChatPlayer mcp) {
|
||||||
namesMap.remove(name);
|
namesMap.put(mcp.getName(), mcp.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearNameMap() {
|
public void removeNameFromMap(String name) {
|
||||||
namesMap.clear();
|
namesMap.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMineverseChatPlayerToMap(VentureChatPlayer mcp) {
|
public void clearNameMap() {
|
||||||
playerMap.put(mcp.getUuid(), mcp);
|
namesMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearMineverseChatPlayerMap() {
|
public void addMineverseChatPlayerToMap(VentureChatPlayer mcp) {
|
||||||
playerMap.clear();
|
playerMap.put(mcp.getUuid(), mcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<VentureChatPlayer> getMineverseChatPlayers() {
|
public void clearMineverseChatPlayerMap() {
|
||||||
return playerMap.values();
|
playerMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMineverseChatOnlinePlayerToMap(VentureChatPlayer mcp) {
|
public Collection<VentureChatPlayer> getMineverseChatPlayers() {
|
||||||
onlinePlayerMap.put(mcp.getUuid(), mcp);
|
return playerMap.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMineverseChatOnlinePlayerToMap(VentureChatPlayer mcp) {
|
public void addMineverseChatOnlinePlayerToMap(VentureChatPlayer mcp) {
|
||||||
onlinePlayerMap.remove(mcp.getUuid());
|
onlinePlayerMap.put(mcp.getUuid(), mcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearOnlineMineverseChatPlayerMap() {
|
public void removeMineverseChatOnlinePlayerToMap(VentureChatPlayer mcp) {
|
||||||
onlinePlayerMap.clear();
|
onlinePlayerMap.remove(mcp.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<VentureChatPlayer> getOnlineMineverseChatPlayers() {
|
public void clearOnlineMineverseChatPlayerMap() {
|
||||||
return onlinePlayerMap.values();
|
onlinePlayerMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Collection<VentureChatPlayer> getOnlineMineverseChatPlayers() {
|
||||||
* Get a MineverseChatPlayer wrapper from a Bukkit Player instance.
|
return onlinePlayerMap.values();
|
||||||
*
|
}
|
||||||
* @param player {@link Player} object.
|
|
||||||
* @return {@link VentureChatPlayer}
|
|
||||||
*/
|
|
||||||
public VentureChatPlayer getMineverseChatPlayer(Player player) {
|
|
||||||
return getMineverseChatPlayer(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a MineverseChatPlayer wrapper from a UUID.
|
* Get a MineverseChatPlayer wrapper from a Bukkit Player instance.
|
||||||
*
|
*
|
||||||
* @param uuid {@link UUID}.
|
* @param player {@link Player} object.
|
||||||
* @return {@link VentureChatPlayer}
|
* @return {@link VentureChatPlayer}
|
||||||
*/
|
*/
|
||||||
public VentureChatPlayer getMineverseChatPlayer(UUID uuid) {
|
public VentureChatPlayer getMineverseChatPlayer(Player player) {
|
||||||
return playerMap.get(uuid);
|
return getMineverseChatPlayer(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a MineverseChatPlayer wrapper from a user name.
|
* Get a MineverseChatPlayer wrapper from a UUID.
|
||||||
*
|
*
|
||||||
* @param name {@link String}.
|
* @param uuid {@link UUID}.
|
||||||
* @return {@link VentureChatPlayer}
|
* @return {@link VentureChatPlayer}
|
||||||
*/
|
*/
|
||||||
public VentureChatPlayer getMineverseChatPlayer(String name) {
|
public VentureChatPlayer getMineverseChatPlayer(UUID uuid) {
|
||||||
return getMineverseChatPlayer(namesMap.get(name));
|
return playerMap.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a MineverseChatPlayer wrapper from a Bukkit Player instance. Only checks
|
* Get a MineverseChatPlayer wrapper from a user name.
|
||||||
* current online players. Much more efficient!
|
*
|
||||||
*
|
* @param name {@link String}.
|
||||||
* @param player {@link Player} object.
|
* @return {@link VentureChatPlayer}
|
||||||
* @return {@link VentureChatPlayer}
|
*/
|
||||||
*/
|
public VentureChatPlayer getMineverseChatPlayer(String name) {
|
||||||
public VentureChatPlayer getOnlineMineverseChatPlayer(final Player player) {
|
return getMineverseChatPlayer(namesMap.get(name));
|
||||||
return getOnlineMineverseChatPlayer(player.getUniqueId());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a MineverseChatPlayer wrapper from a UUID. Only checks current online
|
* Get a MineverseChatPlayer wrapper from a Bukkit Player instance. Only checks
|
||||||
* players. Much more efficient!
|
* current online players. Much more efficient!
|
||||||
*
|
*
|
||||||
* @param uuid {@link UUID}.
|
* @param player {@link Player} object.
|
||||||
* @return {@link VentureChatPlayer}
|
* @return {@link VentureChatPlayer}
|
||||||
*/
|
*/
|
||||||
public VentureChatPlayer getOnlineMineverseChatPlayer(UUID uuid) {
|
public VentureChatPlayer getOnlineMineverseChatPlayer(final Player player) {
|
||||||
return onlinePlayerMap.get(uuid);
|
return getOnlineMineverseChatPlayer(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a MineverseChatPlayer wrapper from a user name. Only checks current
|
* Get a MineverseChatPlayer wrapper from a UUID. Only checks current online
|
||||||
* online players. Much more efficient!
|
* players. Much more efficient!
|
||||||
*
|
*
|
||||||
* @param name {@link String}.
|
* @param uuid {@link UUID}.
|
||||||
* @return {@link VentureChatPlayer}
|
* @return {@link VentureChatPlayer}
|
||||||
*/
|
*/
|
||||||
public VentureChatPlayer getOnlineMineverseChatPlayer(String name) {
|
public VentureChatPlayer getOnlineMineverseChatPlayer(UUID uuid) {
|
||||||
return getOnlineMineverseChatPlayer(namesMap.get(name));
|
return onlinePlayerMap.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<String> getNetworkPlayerNames() {
|
/**
|
||||||
return networkPlayerNames;
|
* Get a MineverseChatPlayer wrapper from a user name. Only checks current
|
||||||
}
|
* online players. Much more efficient!
|
||||||
|
*
|
||||||
|
* @param name {@link String}.
|
||||||
|
* @return {@link VentureChatPlayer}
|
||||||
|
*/
|
||||||
|
public VentureChatPlayer getOnlineMineverseChatPlayer(String name) {
|
||||||
|
return getOnlineMineverseChatPlayer(namesMap.get(name));
|
||||||
|
}
|
||||||
|
|
||||||
public void clearNetworkPlayerNames() {
|
public List<String> getNetworkPlayerNames() {
|
||||||
networkPlayerNames.clear();
|
return networkPlayerNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNetworkPlayerName(String name) {
|
public void clearNetworkPlayerNames() {
|
||||||
networkPlayerNames.add(name);
|
networkPlayerNames.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSynchronizedMineverseChatPlayerToMap(SynchronizedVentureChatPlayer smcp) {
|
public void addNetworkPlayerName(String name) {
|
||||||
proxyPlayerMap.put(smcp.getUUID(), smcp);
|
networkPlayerNames.add(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearProxyPlayerMap() {
|
|
||||||
proxyPlayerMap.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<SynchronizedVentureChatPlayer> getSynchronizedMineverseChatPlayers() {
|
|
||||||
return proxyPlayerMap.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a SynchronizedMineverseChatPlayer from a UUID.
|
|
||||||
*
|
|
||||||
* @param uuid {@link UUID}
|
|
||||||
* @return {@link SynchronizedVentureChatPlayer}
|
|
||||||
*/
|
|
||||||
public SynchronizedVentureChatPlayer getSynchronizedMineverseChatPlayer(UUID uuid) {
|
|
||||||
return proxyPlayerMap.get(uuid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package venture.Aust1n46.chat.service.proxy;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
import venture.Aust1n46.chat.proxy.VentureChatProxySource;
|
||||||
|
import venture.Aust1n46.chat.utilities.FormatUtils;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class ProxyUuidService {
|
||||||
|
|
||||||
|
public boolean shouldSkipOfflineUUIDProxy(UUID uuid, VentureChatProxySource source) {
|
||||||
|
return (FormatUtils.uuidIsOffline(uuid) && !source.isOfflineServerAcknowledgementSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkOfflineUUIDWarningProxy(UUID uuid, VentureChatProxySource source) {
|
||||||
|
if (shouldSkipOfflineUUIDProxy(uuid, source)) {
|
||||||
|
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Detected Offline UUID!");
|
||||||
|
source.sendConsoleMessage("&8[&eVentureChat&8]&c - If you are using BungeeCord, make sure you have properly setup IP Forwarding.");
|
||||||
|
source.sendConsoleMessage("&8[&eVentureChat&8]&c - https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/");
|
||||||
|
source.sendConsoleMessage("&8[&eVentureChat&8]&c - You can access this wiki page from the log file or just Google it.");
|
||||||
|
source.sendConsoleMessage("&8[&eVentureChat&8]&c - If you're running a \"cracked\" server, player data might not be stored properly, and thus, you are on your own.");
|
||||||
|
source.sendConsoleMessage("&8[&eVentureChat&8]&c - If you run your server in offline mode, you will probably lose your player data when switching to online mode!");
|
||||||
|
source.sendConsoleMessage("&8[&eVentureChat&8]&c - No player data will be saved in offline mode unless you set the \"cracked\" server acknowledgement in the config!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package venture.Aust1n46.chat.service.proxy;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class VentureChatProxyPlayerApiService {
|
||||||
|
private final HashMap<UUID, SynchronizedVentureChatPlayer> proxyPlayerMap = new HashMap<>();
|
||||||
|
|
||||||
|
public void addSynchronizedMineverseChatPlayerToMap(SynchronizedVentureChatPlayer smcp) {
|
||||||
|
proxyPlayerMap.put(smcp.getUUID(), smcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearProxyPlayerMap() {
|
||||||
|
proxyPlayerMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<SynchronizedVentureChatPlayer> getSynchronizedMineverseChatPlayers() {
|
||||||
|
return proxyPlayerMap.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a SynchronizedMineverseChatPlayer from a UUID.
|
||||||
|
*
|
||||||
|
* @param uuid {@link UUID}
|
||||||
|
* @return {@link SynchronizedVentureChatPlayer}
|
||||||
|
*/
|
||||||
|
public SynchronizedVentureChatPlayer getSynchronizedMineverseChatPlayer(UUID uuid) {
|
||||||
|
return proxyPlayerMap.get(uuid);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package venture.Aust1n46.chat.utilities;
|
package venture.Aust1n46.chat.utilities;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -300,4 +301,15 @@ public class FormatUtils {
|
|||||||
public static String stripColor(String message) {
|
public static String stripColor(String message) {
|
||||||
return message.replaceAll("(\u00A7([a-z0-9]))", "");
|
return message.replaceAll("(\u00A7([a-z0-9]))", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the passed UUID is a v3 UUID. Offline UUIDs are v3, online
|
||||||
|
* are v4.
|
||||||
|
*
|
||||||
|
* @param uuid the UUID to check
|
||||||
|
* @return whether the UUID is a v3 UUID & thus is offline
|
||||||
|
*/
|
||||||
|
public static boolean uuidIsOffline(UUID uuid) {
|
||||||
|
return uuid.version() == 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
name: VentureChat
|
name: VentureChat
|
||||||
main: mineverse.Aust1n46.chat.proxy.VentureChatBungee
|
main: venture.Aust1n46.chat.proxy.VentureChatBungee
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
author: Aust1n46
|
author: Aust1n46
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: VentureChat
|
name: VentureChat
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
main: venture.Aust1n46.chat.VentureChat
|
main: venture.Aust1n46.chat.initiators.application.VentureChat
|
||||||
depend: [Vault, ProtocolLib, PlaceholderAPI]
|
depend: [Vault, ProtocolLib, PlaceholderAPI]
|
||||||
softdepend: [Towny, Factions, EssentialsDiscord]
|
softdepend: [Towny, Factions, EssentialsDiscord]
|
||||||
author: Aust1n46
|
author: Aust1n46
|
||||||
|
Loading…
x
Reference in New Issue
Block a user