More renaming and DI framework.

This commit is contained in:
Aust1n46 2021-12-25 19:41:17 -06:00
parent fb7fb52ce5
commit d6350e6feb
79 changed files with 920 additions and 985 deletions

View File

@ -1,5 +1,8 @@
#Sun Nov 28 17:16:27 CST 2021
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.source=1.8
eclipse.preferences.version=1
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

View File

@ -249,15 +249,15 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>3.12.4</version>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -3,7 +3,11 @@ package venture.Aust1n46.chat;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import venture.Aust1n46.chat.initiators.application.VentureChat;
@Singleton
public class Logger {
private static final String LOG_PREFIX = "[VentureChat] ";

View File

@ -6,6 +6,7 @@ import com.google.inject.Inject;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -1,8 +1,8 @@
package venture.Aust1n46.chat;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import venture.Aust1n46.chat.initiators.application.VentureChat;
public class VentureChatPluginModule extends AbstractModule {
private final VentureChat plugin;
@ -11,10 +11,6 @@ public class VentureChatPluginModule extends AbstractModule {
this.plugin = plugin;
}
public Injector createInjector() {
return Guice.createInjector(this);
}
@Override
protected void configure() {
this.bind(VentureChat.class).toInstance(plugin);

View File

@ -1,4 +1,4 @@
package mineverse.Aust1n46.chat.api.events;
package venture.Aust1n46.chat.api.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;

View File

@ -1,4 +1,4 @@
package mineverse.Aust1n46.chat.api.events;
package venture.Aust1n46.chat.api.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;

View File

@ -1,4 +1,4 @@
package mineverse.Aust1n46.chat.api.events;
package venture.Aust1n46.chat.api.events;
import java.util.Set;
@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
@ -17,6 +16,8 @@ import venture.Aust1n46.chat.model.VentureChatPlayer;
* @author Aust1n46
*/
public class VentureChatEvent extends Event {
private static final boolean ASYNC = true;
private static final HandlerList handlers = new HandlerList();
private final VentureChatPlayer mcp;
private final String username;
@ -31,7 +32,7 @@ public class VentureChatEvent extends Event {
private final boolean bungee;
public VentureChatEvent(VentureChatPlayer mcp, String username, String playerPrimaryGroup, ChatChannel channel, Set<Player> recipients, int recipientCount, String format, String chat, String globalJSON, int hash, boolean bungee) {
super(VentureChat.ASYNC);
super(ASYNC);
this.mcp = mcp;
this.username = username;
this.playerPrimaryGroup = playerPrimaryGroup;

View File

@ -20,16 +20,17 @@ import com.google.inject.Inject;
import com.google.inject.Singleton;
import me.clip.placeholderapi.PlaceholderAPI;
import mineverse.Aust1n46.chat.api.events.VentureChatEvent;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.api.events.VentureChatEvent;
import venture.Aust1n46.chat.controllers.commands.MuteContainer;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatDatabaseService;
import venture.Aust1n46.chat.service.VentureChatFormatService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
@Singleton
public class PluginMessageController {
@ -43,6 +44,8 @@ public class PluginMessageController {
private VentureChatFormatService formatService;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
public void sendPluginMessage(ByteArrayOutputStream byteOutStream) {
if(playerApiService.getOnlineMineverseChatPlayers().size() > 0) {
@ -68,6 +71,15 @@ public class PluginMessageController {
}
}
public void synchronizeWithDelay(final VentureChatPlayer vcp, final boolean changes) {
final long delayInTicks = 20L;
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
public void run() {
synchronize(vcp, false);
}
}, delayInTicks);
}
public void synchronize(VentureChatPlayer mcp, boolean changes) {
// System.out.println("Sync started...");
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
@ -82,7 +94,7 @@ public class PluginMessageController {
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
if(!mcp.isOnline() || mcp.hasPlayed()) {
if(!mcp.isOnline() || mcp.isHasPlayed()) {
return;
}
synchronize(mcp, false);
@ -95,14 +107,14 @@ public class PluginMessageController {
// out.writeUTF("Channels");
int channelCount = 0;
for(String c : mcp.getListening()) {
ChatChannel channel = ChatChannel.getChannel(c);
ChatChannel channel = configService.getChannel(c);
if(channel.getBungee()) {
channelCount++;
}
}
out.write(channelCount);
for(String c : mcp.getListening()) {
ChatChannel channel = ChatChannel.getChannel(c);
ChatChannel channel = configService.getChannel(c);
if(channel.getBungee()) {
out.writeUTF(channel.getName());
}
@ -110,7 +122,7 @@ public class PluginMessageController {
// out.writeUTF("Mutes");
int muteCount = 0;
for(MuteContainer mute : mcp.getMutes()) {
ChatChannel channel = ChatChannel.getChannel(mute.getChannel());
ChatChannel channel = configService.getChannel(mute.getChannel());
if(channel.getBungee()) {
muteCount++;
}
@ -118,7 +130,7 @@ public class PluginMessageController {
// System.out.println(muteCount + " mutes");
out.write(muteCount);
for(MuteContainer mute : mcp.getMutes()) {
ChatChannel channel = ChatChannel.getChannel(mute.getChannel());
ChatChannel channel = configService.getChannel(mute.getChannel());
if(channel.getBungee()) {
out.writeUTF(channel.getName());
out.writeLong(mute.getDuration());
@ -170,10 +182,10 @@ public class PluginMessageController {
String globalJSON = msgin.readUTF();
String primaryGroup = msgin.readUTF();
if(!ChatChannel.isChannel(chatchannel)) {
if(!configService.isChannel(chatchannel)) {
return;
}
ChatChannel chatChannelObject = ChatChannel.getChannel(chatchannel);
ChatChannel chatChannelObject = configService.getChannel(chatchannel);
if(!chatChannelObject.getBungee()) {
return;
@ -181,7 +193,7 @@ public class PluginMessageController {
Set<Player> recipients = new HashSet<Player>();
for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if(p.isListening(chatChannelObject.getName())) {
if(configService.isListening(p, chatChannelObject.getName())) {
recipients.add(p.getPlayer());
}
}
@ -203,7 +215,7 @@ public class PluginMessageController {
}
for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if(p.isListening(chatChannelObject.getName())) {
if(configService.isListening(p, chatChannelObject.getName())) {
if(!p.isBungeeToggle() && playerApiService.getOnlineMineverseChatPlayer(senderName) == null) {
continue;
}
@ -225,10 +237,10 @@ public class PluginMessageController {
if(subchannel.equals("DiscordSRV")) {
String chatChannel = msgin.readUTF();
String message = msgin.readUTF();
if(!ChatChannel.isChannel(chatChannel)) {
if(!configService.isChannel(chatChannel)) {
return;
}
ChatChannel chatChannelObj = ChatChannel.getChannel(chatChannel);
ChatChannel chatChannelObj = configService.getChannel(chatChannel);
if(!chatChannelObj.getBungee()) {
return;
}
@ -237,7 +249,7 @@ public class PluginMessageController {
int hash = (message.replaceAll("([<5B>]([a-z0-9]))", "")).hashCode();
for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if(p.isListening(chatChannelObj.getName())) {
if(configService.isListening(p, chatChannelObj.getName())) {
String finalJSON = formatService.formatModerationGUI(json, p.getPlayer(), "Discord", chatChannelObj.getName(), hash);
PacketContainer packet = formatService.createPacketPlayOutChat(finalJSON);
formatService.sendPacketPlayOutChat(p.getPlayer(), packet);
@ -258,9 +270,9 @@ public class PluginMessageController {
String sender = msgin.readUTF();
String chatchannel = msgin.readUTF();
List<String> listening = new ArrayList<String>();
if(ChatChannel.isChannel(chatchannel)) {
if(configService.isChannel(chatchannel)) {
for(VentureChatPlayer mcp : playerApiService.getOnlineMineverseChatPlayers()) {
if(mcp.isListening(chatchannel)) {
if(configService.isListening(mcp, chatchannel)) {
String entry = "&f" + mcp.getName();
if(mcp.isMuted(chatchannel)) {
entry = "&c" + mcp.getName();
@ -284,7 +296,7 @@ public class PluginMessageController {
String sender = msgin.readUTF();
String stringchannel = msgin.readUTF();
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(UUID.fromString(sender));
ChatChannel chatchannel = ChatChannel.getChannel(stringchannel);
ChatChannel chatchannel = configService.getChannel(stringchannel);
String playerList = "";
int size = msgin.readInt();
for(int a = 0; a < size; a++) {
@ -309,12 +321,12 @@ public class PluginMessageController {
}
String uuid = msgin.readUTF();
VentureChatPlayer p = playerApiService.getOnlineMineverseChatPlayer(UUID.fromString(uuid));
if(p == null || p.hasPlayed()) {
if(p == null || p.isHasPlayed()) {
return;
}
for(Object ch : p.getListening().toArray()) {
String c = ch.toString();
ChatChannel cha = ChatChannel.getChannel(c);
ChatChannel cha = configService.getChannel(c);
if(cha.getBungee()) {
p.removeListening(c);
}
@ -322,14 +334,14 @@ public class PluginMessageController {
int size = msgin.read();
for(int a = 0; a < size; a++) {
String ch = msgin.readUTF();
if(ChatChannel.isChannel(ch)) {
ChatChannel cha = ChatChannel.getChannel(ch);
if(configService.isChannel(ch)) {
ChatChannel cha = configService.getChannel(ch);
if(!cha.hasPermission() || p.getPlayer().hasPermission(cha.getPermission())) {
p.addListening(ch);
}
}
}
p.getMutes().removeIf(mute -> ChatChannel.getChannel(mute.getChannel()).getBungee());
p.getMutes().removeIf(mute -> configService.getChannel(mute.getChannel()).getBungee());
int sizeB = msgin.read();
// System.out.println(sizeB + " mute size");
for(int b = 0; b < sizeB; b++) {
@ -337,7 +349,7 @@ public class PluginMessageController {
long muteTime = msgin.readLong();
String muteReason = msgin.readUTF();
// System.out.println(ch);
if(ChatChannel.isChannel(ch)) {
if(configService.isChannel(ch)) {
p.addMute(ch, muteTime, muteReason);
}
}
@ -355,10 +367,10 @@ public class PluginMessageController {
// System.out.println(i);
p.addIgnore(UUID.fromString(i));
}
if(!p.hasPlayed()) {
if(!p.isHasPlayed()) {
boolean isThereABungeeChannel = false;
for(ChatChannel ch : ChatChannel.getAutojoinList()) {
if((!ch.hasPermission() || p.getPlayer().hasPermission(ch.getPermission())) && !p.isListening(ch.getName())) {
for(ChatChannel ch : configService.getAutojoinList()) {
if((!ch.hasPermission() || p.getPlayer().hasPermission(ch.getPermission())) && !configService.isListening(p, ch.getName())) {
p.addListening(ch.getName());
if(ch.getBungee()) {
isThereABungeeChannel = true;
@ -445,10 +457,10 @@ public class PluginMessageController {
sendPluginMessage(stream);
return;
}
if(!ChatChannel.isChannel(channelName)) {
if(!configService.isChannel(channelName)) {
return;
}
ChatChannel chatChannelObj = ChatChannel.getChannel(channelName);
ChatChannel chatChannelObj = configService.getChannel(channelName);
if (playerToMuteMCP.isMuted(chatChannelObj.getName())) {
out.writeUTF("Mute");
out.writeUTF("AlreadyMuted");
@ -516,10 +528,10 @@ public class PluginMessageController {
String channelName = msgin.readUTF();
long time = msgin.readLong();
String reason = msgin.readUTF();
if(!ChatChannel.isChannel(channelName)) {
if(!configService.isChannel(channelName)) {
return;
}
ChatChannel chatChannelObj = ChatChannel.getChannel(channelName);
ChatChannel chatChannelObj = configService.getChannel(channelName);
if(time > 0) {
String timeString = FormatUtils.parseTimeStringFromMillis(time);
if(reason.isEmpty()) {
@ -617,10 +629,10 @@ public class PluginMessageController {
String senderIdentifier = msgin.readUTF();
String playerToMute = msgin.readUTF();
String channelName = msgin.readUTF();
if(!ChatChannel.isChannel(channelName)) {
if(!configService.isChannel(channelName)) {
return;
}
ChatChannel chatChannelObj = ChatChannel.getChannel(channelName);
ChatChannel chatChannelObj = configService.getChannel(channelName);
if(senderIdentifier.equals("VentureChat:Console")) {
Bukkit.getConsoleSender().sendMessage(LocalizedMessage.PLAYER_ALREADY_MUTED.toString()
.replace("{player}", playerToMute).replace("{channel_color}", chatChannelObj.getColor())
@ -654,10 +666,10 @@ public class PluginMessageController {
sendPluginMessage(stream);
return;
}
if(!ChatChannel.isChannel(channelName)) {
if(!configService.isChannel(channelName)) {
return;
}
ChatChannel chatChannelObj = ChatChannel.getChannel(channelName);
ChatChannel chatChannelObj = configService.getChannel(channelName);
if (!playerToUnmuteMCP.isMuted(chatChannelObj.getName())) {
out.writeUTF("Unmute");
out.writeUTF("NotMuted");
@ -686,10 +698,10 @@ public class PluginMessageController {
String senderIdentifier = msgin.readUTF();
String playerToUnmute = msgin.readUTF();
String channelName = msgin.readUTF();
if(!ChatChannel.isChannel(channelName)) {
if(!configService.isChannel(channelName)) {
return;
}
ChatChannel chatChannelObj = ChatChannel.getChannel(channelName);
ChatChannel chatChannelObj = configService.getChannel(channelName);
if(senderIdentifier.equals("VentureChat:Console")) {
Bukkit.getConsoleSender().sendMessage(LocalizedMessage.UNMUTE_PLAYER_SENDER.toString()
.replace("{player}", playerToUnmute)
@ -724,10 +736,10 @@ public class PluginMessageController {
String senderIdentifier = msgin.readUTF();
String playerToUnmute = msgin.readUTF();
String channelName = msgin.readUTF();
if(!ChatChannel.isChannel(channelName)) {
if(!configService.isChannel(channelName)) {
return;
}
ChatChannel chatChannelObj = ChatChannel.getChannel(channelName);
ChatChannel chatChannelObj = configService.getChannel(channelName);
if(senderIdentifier.equals("VentureChat:Console")) {
Bukkit.getConsoleSender().sendMessage(LocalizedMessage.PLAYER_NOT_MUTED.toString()
.replace("{player}", playerToUnmute).replace("{channel_color}", chatChannelObj.getColor())
@ -782,11 +794,11 @@ public class PluginMessageController {
return;
}
p.getPlayer().sendMessage(FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(p.getPlayer(), send.replaceAll("receiver_", ""))) + msg);
if(p.hasNotifications()) {
if(p.isNotifications()) {
formatService.playMessageSound(p);
}
if(playerApiService.getMineverseChatPlayer(sender) == null) {
VentureChatPlayer senderMCP = new VentureChatPlayer(sender, sName);
VentureChatPlayer senderMCP = new VentureChatPlayer(sender, sName, configService.getDefaultChannel());
playerApiService.addMineverseChatPlayerToMap(senderMCP);
playerApiService.addNameToMap(senderMCP);
}
@ -832,7 +844,7 @@ public class PluginMessageController {
VentureChatPlayer senderMCP = playerApiService.getOnlineMineverseChatPlayer(senderUUID);
String echo = msgin.readUTF();
if(playerApiService.getMineverseChatPlayer(receiverUUID) == null) {
VentureChatPlayer receiverMCP = new VentureChatPlayer(receiverUUID, receiverName);
VentureChatPlayer receiverMCP = new VentureChatPlayer(receiverUUID, receiverName, configService.getDefaultChannel());
playerApiService.addMineverseChatPlayerToMap(receiverMCP);
playerApiService.addNameToMap(receiverMCP);
}

View File

@ -13,12 +13,12 @@ import java.util.UUID;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.proxy.VentureChatProxySource;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import venture.Aust1n46.chat.controllers.commands.MuteContainer;
import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer;
import venture.Aust1n46.chat.proxy.VentureChatProxySource;
import venture.Aust1n46.chat.service.UUIDService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -21,13 +21,14 @@ import org.bukkit.configuration.file.YamlConfiguration;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.controllers.commands.MuteContainer;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.UUIDService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
/**
* Class for reading and writing player data.
@ -42,6 +43,8 @@ public class VentureChatSpigotFlatFileController {
private UUIDService uuidService;
@Inject
private VentureChatPlayerApiService ventureChatApi;
@Inject
private ConfigService configService;
private String playerDataDirectoryPath;
@ -67,7 +70,7 @@ public class VentureChatSpigotFlatFileController {
}
String name = playerData.getConfigurationSection("players." + uuid).getString("name");
String currentChannelName = playerData.getConfigurationSection("players." + uuid).getString("current");
ChatChannel currentChannel = ChatChannel.isChannel(currentChannelName) ? ChatChannel.getChannel(currentChannelName) : ChatChannel.getDefaultChannel();
ChatChannel currentChannel = configService.isChannel(currentChannelName) ? configService.getChannel(currentChannelName) : configService.getDefaultChannel();
Set<UUID> ignores = new HashSet<UUID>();
StringTokenizer i = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("ignores"), ",");
while (i.hasMoreTokens()) {
@ -77,7 +80,7 @@ public class VentureChatSpigotFlatFileController {
StringTokenizer l = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("listen"), ",");
while (l.hasMoreTokens()) {
String channel = l.nextToken();
if (ChatChannel.isChannel(channel)) {
if (configService.isChannel(channel)) {
listening.add(channel);
}
}
@ -85,7 +88,7 @@ public class VentureChatSpigotFlatFileController {
StringTokenizer m = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("mutes"), ",");
while (m.hasMoreTokens()) {
String[] parts = m.nextToken().split(":");
if (ChatChannel.isChannel(parts[0])) {
if (configService.isChannel(parts[0])) {
if (parts[1].equals("null")) {
Bukkit.getConsoleSender().sendMessage("[VentureChat] Null Mute Time: " + parts[0] + " " + name);
continue;
@ -161,7 +164,7 @@ public class VentureChatSpigotFlatFileController {
}
String name = playerDataFileYamlConfiguration.getString("name");
String currentChannelName = playerDataFileYamlConfiguration.getString("current");
ChatChannel currentChannel = ChatChannel.isChannel(currentChannelName) ? ChatChannel.getChannel(currentChannelName) : ChatChannel.getDefaultChannel();
ChatChannel currentChannel = configService.isChannel(currentChannelName) ? configService.getChannel(currentChannelName) : configService.getDefaultChannel();
Set<UUID> ignores = new HashSet<UUID>();
StringTokenizer i = new StringTokenizer(playerDataFileYamlConfiguration.getString("ignores"), ",");
while (i.hasMoreTokens()) {
@ -171,7 +174,7 @@ public class VentureChatSpigotFlatFileController {
StringTokenizer l = new StringTokenizer(playerDataFileYamlConfiguration.getString("listen"), ",");
while (l.hasMoreTokens()) {
String channel = l.nextToken();
if (ChatChannel.isChannel(channel)) {
if (configService.isChannel(channel)) {
listening.add(channel);
}
}
@ -211,7 +214,7 @@ public class VentureChatSpigotFlatFileController {
}
public void savePlayerData(VentureChatPlayer mcp) {
if (mcp == null || uuidService.shouldSkipOfflineUUID(mcp.getUuid()) || (!mcp.isOnline() && !mcp.wasModified())) {
if (mcp == null || uuidService.shouldSkipOfflineUUID(mcp.getUuid()) || (!mcp.isOnline() && !mcp.isModified())) {
return;
}
try {
@ -230,7 +233,7 @@ public class VentureChatSpigotFlatFileController {
playerDataFileYamlConfiguration.set("ignores", ignores);
String listening = "";
for (String channel : mcp.getListening()) {
ChatChannel c = ChatChannel.getChannel(channel);
ChatChannel c = configService.getChannel(channel);
listening += c.getName() + ",";
}
String blockedCommands = "";
@ -253,7 +256,7 @@ public class VentureChatSpigotFlatFileController {
playerDataFileYamlConfiguration.set("host", mcp.isHost());
playerDataFileYamlConfiguration.set("party", mcp.hasParty() ? mcp.getParty().toString() : "");
playerDataFileYamlConfiguration.set("filter", mcp.isFilter());
playerDataFileYamlConfiguration.set("notifications", mcp.hasNotifications());
playerDataFileYamlConfiguration.set("notifications", mcp.isNotifications());
playerDataFileYamlConfiguration.set("spy", mcp.isSpy());
playerDataFileYamlConfiguration.set("commandspy", mcp.hasCommandSpy());
playerDataFileYamlConfiguration.set("rangedspy", mcp.getRangedSpy());

View File

@ -6,11 +6,11 @@ import org.bukkit.configuration.ConfigurationSection;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatFormatService;
import venture.Aust1n46.chat.utilities.FormatUtils;
public class Broadcast implements VentureCommand {
@Inject

View File

@ -6,8 +6,8 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -7,12 +7,13 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import mineverse.Aust1n46.chat.api.events.ChannelJoinEvent;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.api.events.ChannelJoinEvent;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
@Singleton
@ -21,6 +22,8 @@ public class Channel implements VentureCommand {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -30,12 +33,12 @@ public class Channel implements VentureCommand {
}
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender);
if (args.length > 0) {
if (!ChatChannel.isChannel(args[0])) {
if (!configService.isChannel(args[0])) {
mcp.getPlayer().sendMessage(LocalizedMessage.INVALID_CHANNEL.toString()
.replace("{args}", args[0]));
return;
}
ChatChannel channel = ChatChannel.getChannel(args[0]);
ChatChannel channel = configService.getChannel(args[0]);
ChannelJoinEvent channelJoinEvent = new ChannelJoinEvent(mcp.getPlayer(), channel, LocalizedMessage.SET_CHANNEL.toString()
.replace("{channel_color}", channel.getColor() + "")
.replace("{channel_name}", channel.getName()));

View File

@ -3,11 +3,16 @@ package venture.Aust1n46.chat.controllers.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import com.google.inject.Inject;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.utilities.FormatUtils;
public class Channelinfo implements VentureCommand {
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -16,7 +21,7 @@ public class Channelinfo implements VentureCommand {
sender.sendMessage(ChatColor.RED + "Invalid command: /channelinfo [channel]");
return;
}
ChatChannel chname = ChatChannel.getChannel(args[0]);
ChatChannel chname = configService.getChannel(args[0]);
if (chname == null) {
sender.sendMessage(ChatColor.RED + "Invalid channel: " + args[0]);
return;

View File

@ -10,11 +10,14 @@ import com.google.inject.Inject;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
public class Chatinfo implements VentureCommand {
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -31,11 +34,11 @@ public class Chatinfo implements VentureCommand {
if (args.length < 1) {
mcp.getPlayer().sendMessage(ChatColor.GOLD + "Player: " + ChatColor.GREEN + mcp.getName());
for (String c : mcp.getListening()) {
ChatChannel channel = ChatChannel.getChannel(c);
ChatChannel channel = configService.getChannel(c);
listen += channel.getColor() + channel.getName() + " ";
}
for (MuteContainer muteContainer : mcp.getMutes()) {
ChatChannel channel = ChatChannel.getChannel(muteContainer.getChannel());
ChatChannel channel = configService.getChannel(muteContainer.getChannel());
mute += channel.getColor() + channel.getName() + " ";
}
for (String bc : mcp.getBlockedCommands()) {
@ -86,11 +89,11 @@ public class Chatinfo implements VentureCommand {
}
sender.sendMessage(ChatColor.GOLD + "Player: " + ChatColor.GREEN + p.getName());
for (String c : p.getListening()) {
ChatChannel channel = ChatChannel.getChannel(c);
ChatChannel channel = configService.getChannel(c);
listen += channel.getColor() + channel.getName() + " ";
}
for (MuteContainer muteContainer : p.getMutes()) {
ChatChannel channel = ChatChannel.getChannel(muteContainer.getChannel());
ChatChannel channel = configService.getChannel(muteContainer.getChannel());
mute += channel.getColor() + channel.getName() + " ";
}
for (String bc : p.getBlockedCommands()) {

View File

@ -8,13 +8,15 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.controllers.VentureChatSpigotFlatFileController;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.JsonFormat;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
public class Chatreload implements VentureCommand {
@Inject
@ -23,6 +25,8 @@ public class Chatreload implements VentureCommand {
private VentureChatSpigotFlatFileController spigotFlatFileController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -33,7 +37,7 @@ public class Chatreload implements VentureCommand {
playerApiService.clearOnlineMineverseChatPlayerMap();
plugin.reloadConfig();
plugin.initializeConfigReaders();
configService.postConstruct();
spigotFlatFileController.loadLegacyPlayerData();
spigotFlatFileController.loadPlayerData();
@ -44,11 +48,20 @@ public class Chatreload implements VentureCommand {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - There could be an issue with your player data saving."));
String name = p.getName();
UUID uuid = p.getUniqueId();
mcp = new VentureChatPlayer(uuid, name);
mcp = new VentureChatPlayer(uuid, name, configService.getDefaultChannel());
}
mcp.setOnline(true);
mcp.setPlayer(plugin.getServer().getPlayer(mcp.getUuid()));
mcp.setHasPlayed(false);
mcp.setJsonFormat();
String jsonFormat = mcp.getJsonFormat();
for(JsonFormat j : configService.getJsonFormats()) {
if(mcp.getPlayer().hasPermission("venturechat.json." + j.getName())) {
if(configService.getJsonFormat(mcp.getJsonFormat()).getPriority() > j.getPriority()) {
jsonFormat = j.getName();
}
}
}
mcp.setJsonFormat(jsonFormat);
playerApiService.addMineverseChatOnlinePlayerToMap(mcp);
playerApiService.addNameToMap(mcp);
}

View File

@ -2,16 +2,21 @@ package venture.Aust1n46.chat.controllers.commands;
import org.bukkit.command.CommandSender;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import com.google.inject.Inject;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
public class Chlist implements VentureCommand {
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
sender.sendMessage(LocalizedMessage.CHANNEL_LIST_HEADER.toString());
for (ChatChannel chname : ChatChannel.getChatChannels()) {
for (ChatChannel chname : configService.getChatChannels()) {
if (chname.hasPermission()) {
if (sender.hasPermission(chname.getPermission())) {
sender.sendMessage(LocalizedMessage.CHANNEL_LIST_WITH_PERMISSIONS.toString()

View File

@ -1,6 +1,6 @@
package venture.Aust1n46.chat.controllers.commands;
import static venture.Aust1n46.chat.VentureChat.LINE_LENGTH;
import static venture.Aust1n46.chat.utilities.FormatUtils.LINE_LENGTH;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
@ -16,12 +16,13 @@ import com.massivecraft.factions.entity.MPlayer;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.object.Resident;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
public class Chwho implements VentureCommand {
@ -31,13 +32,15 @@ public class Chwho implements VentureCommand {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
String playerlist = "";
if (sender.hasPermission("venturechat.chwho")) {
if (args.length > 0) {
ChatChannel channel = ChatChannel.getChannel(args[0]);
ChatChannel channel = configService.getChannel(args[0]);
if (channel != null) {
if (channel.hasPermission()) {
if (!sender.hasPermission(channel.getPermission())) {

View File

@ -4,8 +4,8 @@ import org.bukkit.command.CommandSender;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.InternalMessage;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.localization.InternalMessage;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -6,8 +6,8 @@ import org.bukkit.command.CommandSender;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -13,13 +13,13 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.service.VentureChatFormatService;
public class Edit implements VentureCommand {

View File

@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -4,7 +4,7 @@ import org.bukkit.command.CommandSender;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -4,7 +4,7 @@ import org.bukkit.command.CommandSender;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -16,9 +16,9 @@ import org.bukkit.util.StringUtil;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -5,11 +5,12 @@ import org.bukkit.command.CommandSender;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
public class Kickchannel implements VentureCommand {
@ -17,6 +18,8 @@ public class Kickchannel implements VentureCommand {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -33,7 +36,7 @@ public class Kickchannel implements VentureCommand {
.replace("{args}", args[0]));
return;
}
ChatChannel channel = ChatChannel.getChannel(args[1]);
ChatChannel channel = configService.getChannel(args[1]);
if (channel == null) {
sender.sendMessage(LocalizedMessage.INVALID_CHANNEL.toString()
.replace("{args}", args[1]));
@ -53,16 +56,16 @@ public class Kickchannel implements VentureCommand {
}
boolean isThereABungeeChannel = channel.getBungee();
if (player.getListening().size() == 0) {
player.addListening(ChatChannel.getDefaultChannel().getName());
player.setCurrentChannel(ChatChannel.getDefaultChannel());
if (ChatChannel.getDefaultChannel().getBungee()) {
player.addListening(configService.getDefaultChannel().getName());
player.setCurrentChannel(configService.getDefaultChannel());
if (configService.getDefaultChannel().getBungee()) {
isThereABungeeChannel = true;
}
if (player.isOnline()) {
player.getPlayer().sendMessage(LocalizedMessage.MUST_LISTEN_ONE_CHANNEL.toString());
player.getPlayer().sendMessage(LocalizedMessage.SET_CHANNEL.toString()
.replace("{channel_color}", ChatColor.valueOf(ChatChannel.getDefaultColor().toUpperCase()) + "")
.replace("{channel_name}", ChatChannel.getDefaultChannel().getName()));
.replace("{channel_color}", ChatColor.valueOf(configService.getDefaultColor().toUpperCase()) + "")
.replace("{channel_name}", configService.getDefaultChannel().getName()));
} else
player.setModified(true);
}

View File

@ -5,11 +5,12 @@ import org.bukkit.command.CommandSender;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
public class Kickchannelall implements VentureCommand {
@ -17,6 +18,8 @@ public class Kickchannelall implements VentureCommand {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -35,8 +38,8 @@ public class Kickchannelall implements VentureCommand {
}
boolean isThereABungeeChannel = false;
for (String channel : player.getListening()) {
if (ChatChannel.isChannel(channel)) {
ChatChannel chatChannelObj = ChatChannel.getChannel(channel);
if (configService.isChannel(channel)) {
ChatChannel chatChannelObj = configService.getChannel(channel);
if (chatChannelObj.getBungee()) {
isThereABungeeChannel = true;
}
@ -45,9 +48,9 @@ public class Kickchannelall implements VentureCommand {
player.clearListening();
sender.sendMessage(LocalizedMessage.KICK_CHANNEL_ALL_SENDER.toString()
.replace("{player}", player.getName()));
player.addListening(ChatChannel.getDefaultChannel().getName());
player.setCurrentChannel(ChatChannel.getDefaultChannel());
if (ChatChannel.getDefaultChannel().getBungee()) {
player.addListening(configService.getDefaultChannel().getName());
player.setCurrentChannel(configService.getDefaultChannel());
if (configService.getDefaultChannel().getBungee()) {
isThereABungeeChannel = true;
}
if (isThereABungeeChannel) {
@ -57,8 +60,8 @@ public class Kickchannelall implements VentureCommand {
player.getPlayer().sendMessage(LocalizedMessage.KICK_CHANNEL_ALL_PLAYER.toString());
player.getPlayer().sendMessage(LocalizedMessage.MUST_LISTEN_ONE_CHANNEL.toString());
player.getPlayer().sendMessage(LocalizedMessage.SET_CHANNEL.toString()
.replace("{channel_color}", ChatColor.valueOf(ChatChannel.getDefaultColor().toUpperCase()) + "")
.replace("{channel_name}", ChatChannel.getDefaultChannel().getName()));
.replace("{channel_color}", ChatColor.valueOf(configService.getDefaultColor().toUpperCase()) + "")
.replace("{channel_name}", configService.getDefaultChannel().getName()));
} else {
player.setModified(true);
}

View File

@ -7,11 +7,12 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
public class Leave implements VentureCommand {
@ -19,6 +20,8 @@ public class Leave implements VentureCommand {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -28,7 +31,7 @@ public class Leave implements VentureCommand {
}
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender);
if (args.length > 0) {
ChatChannel channel = ChatChannel.getChannel(args[0]);
ChatChannel channel = configService.getChannel(args[0]);
if (channel == null) {
mcp.getPlayer().sendMessage(LocalizedMessage.INVALID_CHANNEL.toString()
.replace("{args}", args[0]));
@ -40,15 +43,15 @@ public class Leave implements VentureCommand {
.replace("{channel_name}", channel.getName()));
boolean isThereABungeeChannel = channel.getBungee();
if (mcp.getListening().size() == 0) {
mcp.addListening(ChatChannel.getDefaultChannel().getName());
mcp.setCurrentChannel(ChatChannel.getDefaultChannel());
if (ChatChannel.getDefaultChannel().getBungee()) {
mcp.addListening(configService.getDefaultChannel().getName());
mcp.setCurrentChannel(configService.getDefaultChannel());
if (configService.getDefaultChannel().getBungee()) {
isThereABungeeChannel = true;
}
mcp.getPlayer().sendMessage(LocalizedMessage.MUST_LISTEN_ONE_CHANNEL.toString());
mcp.getPlayer().sendMessage(LocalizedMessage.SET_CHANNEL.toString()
.replace("{channel_color}", ChatColor.valueOf(ChatChannel.getDefaultColor().toUpperCase()) + "")
.replace("{channel_name}", ChatChannel.getDefaultChannel().getName()));
.replace("{channel_color}", ChatColor.valueOf(configService.getDefaultColor().toUpperCase()) + "")
.replace("{channel_name}", configService.getDefaultChannel().getName()));
}
if (isThereABungeeChannel) {
pluginMessageController.synchronize(mcp, true);

View File

@ -6,11 +6,12 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
public class Listen implements VentureCommand {
@ -18,6 +19,8 @@ public class Listen implements VentureCommand {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -27,7 +30,7 @@ public class Listen implements VentureCommand {
}
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender);
if (args.length > 0) {
ChatChannel channel = ChatChannel.getChannel(args[0]);
ChatChannel channel = configService.getChannel(args[0]);
if (channel == null) {
mcp.getPlayer().sendMessage(LocalizedMessage.INVALID_CHANNEL.toString()
.replace("{args}", args[0]));

View File

@ -5,10 +5,10 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.service.VentureChatFormatService;
public class Me implements VentureCommand {

View File

@ -15,12 +15,12 @@ import org.bukkit.util.StringUtil;
import com.google.inject.Inject;
import me.clip.placeholderapi.PlaceholderAPI;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.service.VentureChatFormatService;
public class MessageCommandExecutor implements TabExecutor {
@ -109,7 +109,7 @@ public class MessageCommandExecutor implements TabExecutor {
mcp.setReplyPlayer(player.getUuid());
player.getPlayer().sendMessage(send);
mcp.getPlayer().sendMessage(echo);
if (player.hasNotifications()) {
if (player.isNotifications()) {
formatService.playMessageSound(player);
}
if (!mcp.getPlayer().hasPermission("venturechat.spy.override")) {

View File

@ -6,8 +6,8 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -15,13 +15,14 @@ import org.bukkit.util.StringUtil;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
public class Mute implements VentureCommand {
private static final List<String> COMMON_MUTE_TIMES = Collections.unmodifiableList(Arrays.asList(new String[]{"12h", "15m", "1d", "1h", "1m", "30s"}));
@ -30,6 +31,8 @@ public class Mute implements VentureCommand {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -39,8 +42,8 @@ public class Mute implements VentureCommand {
.replace("{args}", "[channel] [player] {time} {reason}"));
return;
}
if (ChatChannel.isChannel(args[0])) {
ChatChannel channel = ChatChannel.getChannel(args[0]);
if (configService.isChannel(args[0])) {
ChatChannel channel = configService.getChannel(args[0]);
if (channel.isMutable()) {
long datetime = System.currentTimeMillis();
long time = 0;
@ -167,13 +170,13 @@ public class Mute implements VentureCommand {
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
List<String> completions = new ArrayList<>();
if (args.length == 1) {
StringUtil.copyPartialMatches(args[0], ChatChannel.getChatChannels().stream().map(ChatChannel::getName).collect(Collectors.toList()), completions);
StringUtil.copyPartialMatches(args[0], configService.getChatChannels().stream().map(ChatChannel::getName).collect(Collectors.toList()), completions);
Collections.sort(completions);
return completions;
}
if (args.length == 2) {
if (ChatChannel.isChannel(args[0])) {
ChatChannel chatChannelObj = ChatChannel.getChannel(args[0]);
if (configService.isChannel(args[0])) {
ChatChannel chatChannelObj = configService.getChannel(args[0]);
if (chatChannelObj.getBungee()) {
StringUtil.copyPartialMatches(args[1], playerApiService.getNetworkPlayerNames(), completions);
Collections.sort(completions);

View File

@ -4,19 +4,22 @@ import org.bukkit.command.CommandSender;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
public class Muteall implements VentureCommand {
@Inject
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -43,7 +46,7 @@ public class Muteall implements VentureCommand {
}
if (reason.isEmpty()) {
boolean bungee = false;
for (ChatChannel channel : ChatChannel.getChatChannels()) {
for (ChatChannel channel : configService.getChatChannels()) {
if (channel.isMutable()) {
player.addMute(channel.getName());
if (channel.getBungee()) {
@ -63,7 +66,7 @@ public class Muteall implements VentureCommand {
return;
} else {
boolean bungee = false;
for (ChatChannel channel : ChatChannel.getChatChannels()) {
for (ChatChannel channel : configService.getChatChannels()) {
if (channel.isMutable()) {
player.addMute(channel.getName(), reason);
if (channel.getBungee()) {

View File

@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
@ -23,7 +23,7 @@ public class Notifications implements VentureCommand {
}
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender);
if (!mcp.hasNotifications()) {
if (!mcp.isNotifications()) {
mcp.setNotifications(true);
mcp.getPlayer().sendMessage(LocalizedMessage.NOTIFICATIONS_ON.toString());
return;

View File

@ -1,6 +1,6 @@
package venture.Aust1n46.chat.controllers.commands;
import static venture.Aust1n46.chat.VentureChat.LINE_LENGTH;
import static venture.Aust1n46.chat.utilities.FormatUtils.LINE_LENGTH;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -8,12 +8,12 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.service.VentureChatFormatService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
public class Party implements VentureCommand {
@Inject

View File

@ -1,6 +1,6 @@
package venture.Aust1n46.chat.controllers.commands;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -16,16 +16,16 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatFormatService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
public class Removemessage implements VentureCommand {
@Inject
@ -36,6 +36,8 @@ public class Removemessage implements VentureCommand {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
private PacketContainer emptyLinePacketContainer;
private WrappedChatComponent messageDeletedComponentPlayer;
@ -62,7 +64,7 @@ public class Removemessage implements VentureCommand {
sender.sendMessage(LocalizedMessage.INVALID_HASH.toString());
return;
}
if (args.length > 1 && ChatChannel.isChannel(args[1]) && ChatChannel.getChannel(args[1]).getBungee()) {
if (args.length > 1 && configService.isChannel(args[1]) && configService.getChannel(args[1]).getBungee()) {
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOutStream);
try {

View File

@ -9,13 +9,13 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import me.clip.placeholderapi.PlaceholderAPI;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.service.VentureChatFormatService;
public class Reply implements VentureCommand {
@ -101,7 +101,7 @@ public class Reply implements VentureCommand {
}
player.getPlayer().sendMessage(send);
mcp.getPlayer().sendMessage(echo);
if (player.hasNotifications()) {
if (player.isNotifications()) {
formatService.playMessageSound(player);
}
player.setReplyPlayer(mcp.getUuid());

View File

@ -4,11 +4,12 @@ import org.bukkit.command.CommandSender;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
public class Setchannel implements VentureCommand {
@ -16,6 +17,8 @@ public class Setchannel implements VentureCommand {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -32,7 +35,7 @@ public class Setchannel implements VentureCommand {
.replace("{args}", args[0]));
return;
}
ChatChannel channel = ChatChannel.getChannel(args[1]);
ChatChannel channel = configService.getChannel(args[1]);
if (channel == null) {
sender.sendMessage(LocalizedMessage.INVALID_CHANNEL.toString()
.replace("{args}", args[1]));

View File

@ -4,11 +4,12 @@ import org.bukkit.command.CommandSender;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
public class Setchannelall implements VentureCommand {
@ -16,6 +17,8 @@ public class Setchannelall implements VentureCommand {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -33,7 +36,7 @@ public class Setchannelall implements VentureCommand {
return;
}
boolean isThereABungeeChannel = false;
for (ChatChannel channel : ChatChannel.getChatChannels()) {
for (ChatChannel channel : configService.getChatChannels()) {
if (channel.hasPermission()) {
if (!player.isOnline()) {
sender.sendMessage(LocalizedMessage.PLAYER_OFFLINE_NO_PERMISSIONS_CHECK.toString());

View File

@ -6,8 +6,8 @@ import org.bukkit.entity.Player;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;

View File

@ -14,11 +14,12 @@ import org.bukkit.util.StringUtil;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
public class Unmute implements VentureCommand {
@ -26,6 +27,8 @@ public class Unmute implements VentureCommand {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -35,8 +38,8 @@ public class Unmute implements VentureCommand {
.replace("{args}", "[channel] [player]"));
return;
}
if (ChatChannel.isChannel(args[0])) {
ChatChannel channel = ChatChannel.getChannel(args[0]);
if (configService.isChannel(args[0])) {
ChatChannel channel = configService.getChannel(args[0]);
if (channel.getBungee()) {
sendBungeeCordUnmute(sender, args[1], channel);
return;
@ -77,13 +80,13 @@ public class Unmute implements VentureCommand {
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
List<String> completions = new ArrayList<>();
if (args.length == 1) {
StringUtil.copyPartialMatches(args[0], ChatChannel.getChatChannels().stream().map(ChatChannel::getName).collect(Collectors.toList()), completions);
StringUtil.copyPartialMatches(args[0], configService.getChatChannels().stream().map(ChatChannel::getName).collect(Collectors.toList()), completions);
Collections.sort(completions);
return completions;
}
if (args.length == 2) {
if (ChatChannel.isChannel(args[0])) {
ChatChannel chatChannelObj = ChatChannel.getChannel(args[0]);
if (configService.isChannel(args[0])) {
ChatChannel chatChannelObj = configService.getChannel(args[0]);
if (chatChannelObj.getBungee()) {
StringUtil.copyPartialMatches(args[1], playerApiService.getNetworkPlayerNames(), completions);
Collections.sort(completions);

View File

@ -4,11 +4,12 @@ import org.bukkit.command.CommandSender;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
public class Unmuteall implements VentureCommand {
@ -16,6 +17,8 @@ public class Unmuteall implements VentureCommand {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -33,7 +36,7 @@ public class Unmuteall implements VentureCommand {
return;
}
boolean bungee = false;
for (ChatChannel channel : ChatChannel.getChatChannels()) {
for (ChatChannel channel : configService.getChatChannels()) {
player.removeMute(channel.getName());
if (channel.getBungee()) {
bungee = true;

View File

@ -16,21 +16,24 @@ import org.bukkit.inventory.meta.SkullMeta;
import com.google.inject.Inject;
import me.clip.placeholderapi.PlaceholderAPI;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import mineverse.Aust1n46.chat.versions.VersionHandler;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.GuiSlot;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.VentureCommand;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.utilities.VersionHandler;
public class VentureChatGui implements VentureCommand {
@Inject
private VentureChat plugin;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Override
public void execute(CommandSender sender, String command, String[] args) {
@ -52,8 +55,8 @@ public class VentureChatGui implements VentureCommand {
.replace("{args}", args[0]));
return;
}
if (ChatChannel.isChannel(args[1])) {
ChatChannel channel = ChatChannel.getChannel(args[1]);
if (configService.isChannel(args[1])) {
ChatChannel channel = configService.getChannel(args[1]);
final int hash;
try {
hash = Integer.parseInt(args[2]);
@ -108,7 +111,7 @@ public class VentureChatGui implements VentureCommand {
skull.setDurability((short) 3);
inv.setItem(0, skull);
for (GuiSlot g : GuiSlot.getGuiSlots()) {
for (GuiSlot g : configService.getGuiSlots()) {
if (!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) {
if (this.checkSlot(g.getSlot())) {
plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&cGUI: " + g.getName() + " has invalid slot: " + g.getSlot() + "!"));
@ -165,7 +168,7 @@ public class VentureChatGui implements VentureCommand {
skull.setDurability((short) 3);
inv.setItem(0, skull);
for (GuiSlot g : GuiSlot.getGuiSlots()) {
for (GuiSlot g : configService.getGuiSlots()) {
if (!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) {
if (this.checkSlot(g.getSlot())) {
plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&cGUI: " + g.getName() + " has invalid slot: " + g.getSlot() + "!"));

View File

@ -1,7 +1,7 @@
package venture.Aust1n46.chat.controllers.commands;
import mineverse.Aust1n46.chat.localization.InternalMessage;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.InternalMessage;
//import net.md_5.bungee.api.chat.ClickEvent;
//import net.md_5.bungee.api.chat.ComponentBuilder;
//import net.md_5.bungee.api.chat.HoverEvent;

View File

@ -1,4 +1,4 @@
package venture.Aust1n46.chat;
package venture.Aust1n46.chat.initiators.application;
import java.io.File;
@ -11,13 +11,14 @@ import org.bukkit.plugin.messaging.PluginMessageListener;
import org.bukkit.scheduler.BukkitScheduler;
import com.comphenix.protocol.ProtocolLibrary;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Singleton;
import mineverse.Aust1n46.chat.localization.Localization;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission;
import venture.Aust1n46.chat.VentureChatPlaceholders;
import venture.Aust1n46.chat.VentureChatPluginModule;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.controllers.VentureChatSpigotFlatFileController;
import venture.Aust1n46.chat.initiators.listeners.ChatListener;
@ -27,13 +28,9 @@ import venture.Aust1n46.chat.initiators.listeners.PacketListener;
import venture.Aust1n46.chat.initiators.listeners.SignListener;
import venture.Aust1n46.chat.initiators.listeners.VentureCommandExecutor;
import venture.Aust1n46.chat.initiators.schedulers.UnmuteScheduler;
import venture.Aust1n46.chat.model.Alias;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.GuiSlot;
import venture.Aust1n46.chat.model.JsonFormat;
import venture.Aust1n46.chat.service.VentureChatDatabaseService;
import venture.Aust1n46.chat.service.VentureChatFormatService;
import venture.Aust1n46.chat.localization.Localization;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
/**
* VentureChat Minecraft plugin for servers running Spigot or Paper software.
@ -42,10 +39,6 @@ import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
*/
@Singleton
public class VentureChat extends JavaPlugin implements PluginMessageListener {
public static final boolean ASYNC = true;
public static final boolean SYNC = false;
public static final int LINE_LENGTH = 40;
@Inject
private LoginListener loginListener;
@Inject
@ -55,59 +48,52 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener {
@Inject
private CommandListener commandListener;
@Inject
private VentureCommandExecutor commandExecutor;
@Inject
private PacketListener packetListener;
@Inject
private VentureChatPlaceholders ventureChatPlaceholders;
@Inject
private VentureChatFormatService formatter;
@Inject
private VentureChatDatabaseService databaseService;
@Inject
private VentureChatSpigotFlatFileController spigotFlatFileService;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private UnmuteScheduler unmuteScheduler;
@Inject
private PluginMessageController pluginMessageController;
private Permission permission = null;
@Override
public void onEnable() {
VentureChatPluginModule pluginModule = new VentureChatPluginModule(this);
pluginModule.createInjector().injectMembers(this);
final VentureChatPluginModule pluginModule = new VentureChatPluginModule(this);
final Injector injector = Guice.createInjector(pluginModule);
injector.injectMembers(this);
injector.injectMembers(new VentureCommandExecutor());
injector.injectMembers(new UnmuteScheduler());
try {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Initializing..."));
if(!getDataFolder().exists()) {
if (!getDataFolder().exists()) {
getDataFolder().mkdirs();
}
File file = new File(getDataFolder(), "config.yml");
if(!file.exists()) {
if (!file.exists()) {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Config not found! Generating file."));
saveDefaultConfig();
}
else {
} else {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Config found! Loading file."));
}
saveResource("example_config_always_up_to_date!.yml", true);
}
catch(Exception ex) {
} catch (Exception ex) {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - &cCould not load configuration! Something unexpected went wrong!"));
}
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Checking for Vault..."));
if(!setupPermissions() || !setupChat()) {
if (!setupPermissions()) {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - &cCould not find Vault and/or a Vault compatible permissions plugin!"));
Bukkit.getPluginManager().disablePlugin(this);
}
initializeConfigReaders();
Localization.initialize(this);
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Loading player data"));
spigotFlatFileService.loadLegacyPlayerData();
@ -115,24 +101,23 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener {
registerListeners();
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Registering Listeners"));
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Attaching to Executors"));
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Establishing BungeeCord"));
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Registering BungeeCord channels"));
Bukkit.getMessenger().registerOutgoingPluginChannel(this, PluginMessageController.PLUGIN_MESSAGING_CHANNEL);
Bukkit.getMessenger().registerIncomingPluginChannel(this, PluginMessageController.PLUGIN_MESSAGING_CHANNEL, this);
PluginManager pluginManager = getServer().getPluginManager();
if(pluginManager.isPluginEnabled("Towny")) {
if (pluginManager.isPluginEnabled("Towny")) {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Enabling Towny Formatting"));
}
if(pluginManager.isPluginEnabled("Jobs")) {
if (pluginManager.isPluginEnabled("Jobs")) {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Enabling Jobs Formatting"));
}
if(pluginManager.isPluginEnabled("Factions")) {
String version = pluginManager.getPlugin("Factions").getDescription().getVersion();
if (pluginManager.isPluginEnabled("Factions")) {
final String version = pluginManager.getPlugin("Factions").getDescription().getVersion();
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Enabling Factions Formatting version " + version));
}
if(pluginManager.isPluginEnabled("PlaceholderAPI")) {
if (pluginManager.isPluginEnabled("PlaceholderAPI")) {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Enabling PlaceholderAPI Hook"));
}
@ -143,11 +128,6 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Enabled Successfully"));
}
@Override
public void onLoad() {
//new DebugLoggingProvider().enableDebugLogging();
}
@Override
public void onDisable() {
spigotFlatFileService.savePlayerData();
@ -164,11 +144,11 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener {
@Override
public void run() {
spigotFlatFileService.savePlayerData();
if(getConfig().getString("loglevel", "info").equals("debug")) {
if (getConfig().getString("loglevel", "info").equals("debug")) {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Saving Player Data"));
}
}
}, 0L, getConfig().getInt("saveinterval") * 1200); //one minute * save interval
}, 0L, getConfig().getInt("saveinterval") * 1200); // one minute * save interval
}
private void registerListeners() {
@ -182,27 +162,10 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener {
private boolean setupPermissions() {
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
if(permissionProvider != null) {
if (permissionProvider != null) {
permission = permissionProvider.getProvider();
}
return(permission != null);
}
private boolean setupChat() {
RegisteredServiceProvider<Chat> chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class);
Chat chat = null;
if(chatProvider != null) {
chat = chatProvider.getProvider();
}
return(chat != null);
}
public void initializeConfigReaders() {
Localization.initialize(this);
Alias.initialize(this);
JsonFormat.initialize(this);
GuiSlot.initialize(this);
ChatChannel.initialize(this, formatter, false);
return (permission != null);
}
public Permission getVaultPermission() {

View File

@ -22,18 +22,19 @@ import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.object.Resident;
import me.clip.placeholderapi.PlaceholderAPI;
import mineverse.Aust1n46.chat.api.events.VentureChatEvent;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import net.essentialsx.api.v2.services.discord.DiscordService;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.api.events.VentureChatEvent;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.controllers.commands.MuteContainer;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatDatabaseService;
import venture.Aust1n46.chat.service.VentureChatFormatService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
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.
@Singleton
@ -49,6 +50,8 @@ public class ChatListener implements Listener {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
// this event isn't always asynchronous even though the event's name starts with "Async"
// blame md_5 for that one
@ -151,7 +154,7 @@ public class ChatListener implements Listener {
}
tp.getPlayer().sendMessage(send);
mcp.getPlayer().sendMessage(echo);
if(tp.hasNotifications()) {
if(tp.isNotifications()) {
formatService.playMessageSound(tp);
}
mcp.setReplyPlayer(tp.getUuid());
@ -256,7 +259,7 @@ public class ChatListener implements Listener {
mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_PERMISSION.toString());
mcp.setQuickChat(false);
mcp.removeListening(eventChannel.getName());
mcp.setCurrentChannel(ChatChannel.getDefaultChannel());
mcp.setCurrentChannel(configService.getDefaultChannel());
return;
}
if(eventChannel.hasSpeakPermission() && !mcp.getPlayer().hasPermission(eventChannel.getSpeakPermission())) {
@ -364,7 +367,7 @@ public class ChatListener implements Listener {
PluginManager pluginManager = plugin.getServer().getPluginManager();
for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if(p.getPlayer() != mcp.getPlayer()) {
if(!p.isListening(eventChannel.getName())) {
if(!configService.isListening(p, eventChannel.getName())) {
recipients.remove(p.getPlayer());
recipientCount--;
continue;
@ -560,9 +563,10 @@ public class ChatListener implements Listener {
if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
System.out.println(out.size() + " bytes size with json");
}
out.writeUTF(plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer()));
// look into not sending this
out.writeUTF(mcp.getPlayer().getDisplayName());
out.writeUTF(plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer())); // look into not sending this
@SuppressWarnings("deprecation") // Paper Deprecated
final String displayName = mcp.getPlayer().getDisplayName();
out.writeUTF(displayName);
pluginMessageController.sendPluginMessage(byteOutStream);
out.close();
}

View File

@ -23,16 +23,17 @@ import com.google.inject.Inject;
import com.google.inject.Singleton;
import me.clip.placeholderapi.PlaceholderAPI;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import mineverse.Aust1n46.chat.versions.VersionHandler;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.Alias;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.GuiSlot;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.utilities.VersionHandler;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatDatabaseService;
import venture.Aust1n46.chat.service.VentureChatFormatService;
@ -50,6 +51,8 @@ public class CommandListener implements CommandExecutor, Listener {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) throws FileNotFoundException {
@ -94,7 +97,7 @@ public class CommandListener implements CommandExecutor, Listener {
databaseService.writeVentureChat(mcp.getUuid().toString(), mcp.getName(), "Local", "Command_Component", event.getMessage().replace("'", "''"), "Command");
}
for(Alias a : Alias.getAliases()) {
for(Alias a : configService.getAliases()) {
if(message.toLowerCase().substring(1).split(" ")[0].equals(a.getName().toLowerCase())) {
for(String s : a.getComponents()) {
if(!mcp.getPlayer().hasPermission(a.getPermission()) && a.hasPermission()) {
@ -145,8 +148,8 @@ public class CommandListener implements CommandExecutor, Listener {
}
}
if(!ChatChannel.areAliasesRegisteredAsCommands()) {
for(ChatChannel channel : ChatChannel.getChatChannels()) {
if(!configService.areAliasesRegisteredAsCommands()) {
for(ChatChannel channel : configService.getChatChannels()) {
if(!channel.hasPermission() || mcp.getPlayer().hasPermission(channel.getPermission())) {
if(message.equals("/" + channel.getAlias())) {
mcp.getPlayer().sendMessage(LocalizedMessage.SET_CHANNEL.toString()
@ -217,7 +220,7 @@ public class CommandListener implements CommandExecutor, Listener {
return true;
}
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender);
for(ChatChannel channel : ChatChannel.getChatChannels()) {
for(ChatChannel channel : configService.getChatChannels()) {
if(command.getName().toLowerCase().equals(channel.getAlias())) {
if(args.length == 0) {
mcp.getPlayer().sendMessage(ChatColor.RED + "Invalid command: /" + channel.getAlias() + " message");
@ -253,7 +256,7 @@ public class CommandListener implements CommandExecutor, Listener {
VentureChatPlayer target = playerApiService.getMineverseChatPlayer(playerName);
ItemStack skull = e.getInventory().getItem(0);
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
ChatChannel channel = ChatChannel.getChannel(ChatColor.stripColor(skullMeta.getLore().get(0)).replace("Channel: ", ""));
ChatChannel channel = configService.getChannel(ChatColor.stripColor(skullMeta.getLore().get(0)).replace("Channel: ", ""));
int hash = Integer.parseInt(ChatColor.stripColor(skullMeta.getLore().get(1).replace("Hash: ", "")));
if(VersionHandler.is1_7()) {
if(item.getType() == Material.BEDROCK) {
@ -265,7 +268,7 @@ public class CommandListener implements CommandExecutor, Listener {
mcp.getPlayer().closeInventory();
}
}
for(GuiSlot g : GuiSlot.getGuiSlots()) {
for(GuiSlot g : configService.getGuiSlots()) {
if(g.getIcon() == item.getType() && g.getDurability() == item.getDurability() && g.getSlot() == e.getSlot()) {
String command = g.getCommand().replace("{channel}", channel.getName()).replace("{hash}", hash + "");
if(target != null) {

View File

@ -12,15 +12,17 @@ import org.bukkit.event.player.PlayerQuitEvent;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.Logger;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.controllers.VentureChatSpigotFlatFileController;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.JsonFormat;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.UUIDService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
/**
* Manages player login and logout events.
@ -40,6 +42,8 @@ public class LoginListener implements Listener {
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Inject
private Logger log;
@EventHandler(priority = EventPriority.LOW)
@ -56,57 +60,54 @@ public class LoginListener implements Listener {
}
}
void handleNameChange(VentureChatPlayer mcp, Player eventPlayerInstance) {
plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Detected Name Change. Old Name:&c " + mcp.getName() + " &eNew Name:&c " + eventPlayerInstance.getName()));
private void handleNameChange(VentureChatPlayer mcp, Player eventPlayerInstance) {
plugin.getServer().getConsoleSender().sendMessage(
FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Detected Name Change. Old Name:&c " + mcp.getName() + " &eNew Name:&c " + eventPlayerInstance.getName()));
playerApiService.removeNameFromMap(mcp.getName());
mcp.setName(eventPlayerInstance.getName());
playerApiService.addNameToMap(mcp);
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(PlayerJoinEvent event) throws Exception {
public void onPlayerJoin(PlayerJoinEvent event) {
VentureChatPlayer mcp = playerApiService.getMineverseChatPlayer(event.getPlayer());
Player player = event.getPlayer();
String name = player.getName();
if(mcp == null) {
if (mcp == null) {
UUID uuid = player.getUniqueId();
mcp = new VentureChatPlayer(uuid, name);
mcp = new VentureChatPlayer(uuid, name, configService.getDefaultChannel());
playerApiService.addMineverseChatPlayerToMap(mcp);
playerApiService.addNameToMap(mcp);
}
uuidService.checkOfflineUUIDWarning(mcp.getUuid());
//check for name change
if(!mcp.getName().equals(name)) {
// check for name change
if (!mcp.getName().equals(name)) {
handleNameChange(mcp, event.getPlayer());
}
mcp.setOnline(true);
mcp.setPlayer(player);
mcp.setHasPlayed(false);
playerApiService.addMineverseChatOnlinePlayerToMap(mcp);
mcp.setJsonFormat();
for(ChatChannel ch : ChatChannel.getAutojoinList()) {
if(ch.hasPermission()) {
if(mcp.getPlayer().hasPermission(ch.getPermission())) {
String jsonFormat = mcp.getJsonFormat();
for (JsonFormat j : configService.getJsonFormats()) {
if (mcp.getPlayer().hasPermission("venturechat.json." + j.getName())) {
if (configService.getJsonFormat(mcp.getJsonFormat()).getPriority() > j.getPriority()) {
jsonFormat = j.getName();
}
}
}
mcp.setJsonFormat(jsonFormat);
for (ChatChannel ch : configService.getAutojoinList()) {
if (ch.hasPermission()) {
if (mcp.getPlayer().hasPermission(ch.getPermission())) {
mcp.addListening(ch.getName());
}
} else {
mcp.addListening(ch.getName());
}
}
else {
mcp.addListening(ch.getName());
}
}
try {
if(plugin.getServer().spigot().getConfig().getBoolean("settings.bungeecord") || plugin.getServer().spigot().getPaperConfig().getBoolean("settings.velocity-support.enabled")) {
long delayInTicks = 20L;
final VentureChatPlayer sync = mcp;
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
public void run() {
pluginMessageController.synchronize(sync, false);
}
}, delayInTicks);
}
}
catch(NoSuchMethodError exception) { // Thrown if server isn't Paper.
// Do nothing
if (configService.isProxyEnabled()) {
pluginMessageController.synchronizeWithDelay(mcp, false);
}
}
}

View File

@ -9,11 +9,11 @@ import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import mineverse.Aust1n46.chat.versions.VersionHandler;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.model.ChatMessage;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.VersionHandler;
import venture.Aust1n46.chat.service.VentureChatFormatService;
//This class listens for chat packets and intercepts them before they are sent to the Player.

View File

@ -8,9 +8,9 @@ import org.bukkit.event.block.SignChangeEvent;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
//This class listens for text being added to signs, and it formats them to allow colors and formatting.
@Singleton

View File

@ -12,7 +12,6 @@ import org.bukkit.command.TabExecutor;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.controllers.commands.Broadcast;
import venture.Aust1n46.chat.controllers.commands.BungeeToggle;
import venture.Aust1n46.chat.controllers.commands.Channel;
@ -50,6 +49,7 @@ import venture.Aust1n46.chat.controllers.commands.Unmute;
import venture.Aust1n46.chat.controllers.commands.Unmuteall;
import venture.Aust1n46.chat.controllers.commands.VentureChatGui;
import venture.Aust1n46.chat.controllers.commands.Venturechat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.model.VentureCommand;
/**
@ -181,11 +181,12 @@ public class VentureCommandExecutor implements TabExecutor {
commands.put("venturechatgui", ventureChatGui);
commands.put("messagetoggle", messageToggle);
commands.put("bungeetoggle", bungeeToggle);
for(String command : commands.keySet()) {
for (String command : commands.keySet()) {
registerCommand(command, this);
}
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
if (plugin.isEnabled()) {
commands.put("reply", reply);
commands.put("r", reply);
registerCommand("reply", this);
@ -206,11 +207,12 @@ public class VentureCommandExecutor implements TabExecutor {
registerCommand("whisper", messageCommandExecutor);
registerCommand("ignore", ignoreCommandExecutor);
}
}, 0);
}
private void registerCommand(String command, CommandExecutor commandExecutor) {
if(plugin.getCommand(command) != null) {
if (plugin.getCommand(command) != null) {
plugin.getCommand(command).setExecutor(commandExecutor);
}
}

View File

@ -7,14 +7,15 @@ import org.bukkit.scheduler.BukkitScheduler;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.controllers.commands.MuteContainer;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
public class UnmuteScheduler {
@Inject
@ -23,6 +24,8 @@ public class UnmuteScheduler {
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@Inject
public void postConstruct() {
@ -35,8 +38,8 @@ public class UnmuteScheduler {
Iterator<MuteContainer> iterator = p.getMutes().iterator();
while (iterator.hasNext()) {
MuteContainer mute = iterator.next();
if(ChatChannel.isChannel(mute.getChannel())) {
ChatChannel channel = ChatChannel.getChannel(mute.getChannel());
if(configService.isChannel(mute.getChannel())) {
ChatChannel channel = configService.getChannel(mute.getChannel());
long timemark = mute.getDuration();
if (timemark == 0) {
continue;

View File

@ -1,6 +1,6 @@
package mineverse.Aust1n46.chat.localization;
package venture.Aust1n46.chat.localization;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.utilities.FormatUtils;
/**
* Messages internal to the plugin

View File

@ -1,4 +1,4 @@
package mineverse.Aust1n46.chat.localization;
package venture.Aust1n46.chat.localization;
import java.io.File;
@ -6,8 +6,8 @@ import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.utilities.FormatUtils;
//This class is used to create objects of localization for different languages.
public class Localization {

View File

@ -1,6 +1,6 @@
package mineverse.Aust1n46.chat.localization;
package venture.Aust1n46.chat.localization;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.utilities.FormatUtils;
/**
* Messages configurable in Messages.yml file.

View File

@ -1,15 +1,11 @@
package venture.Aust1n46.chat.model;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.configuration.ConfigurationSection;
import venture.Aust1n46.chat.VentureChat;
import lombok.Getter;
@Getter
public class Alias {
private static List<Alias> aliases;
private String name;
private int arguments;
private List<String> components;
@ -22,38 +18,6 @@ public class Alias {
this.permission = "venturechat." + permission;
}
public static void initialize(VentureChat plugin) {
aliases = new ArrayList<Alias>();
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("alias");
for (String key : cs.getKeys(false)) {
String name = key;
int arguments = cs.getInt(key + ".arguments", 0);
List<String> components = cs.getStringList(key + ".components");
String permissions = cs.getString(key + ".permissions", "None");
aliases.add(new Alias(name, arguments, components, permissions));
}
}
public static List<Alias> getAliases() {
return aliases;
}
public String getName() {
return name;
}
public int getArguments() {
return arguments;
}
public List<String> getComponents() {
return components;
}
public String getPermission() {
return permission;
}
public boolean hasPermission() {
return !permission.equalsIgnoreCase("venturechat.none");
}

View File

@ -1,18 +1,9 @@
package venture.Aust1n46.chat.model;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.service.VentureChatFormatService;
import venture.Aust1n46.chat.utilities.FormatUtils;
/**
* Chat channel object pojo. Class also contains static initialization methods
@ -24,11 +15,6 @@ public class ChatChannel {
private static final String PERMISSION_PREFIX = "venturechat.";
private static final String NO_PERMISSIONS = "venturechat.none";
private static boolean aliasesRegisteredAsCommands;
private static ChatChannel defaultChatChannel;
private static String defaultColor;
private static HashMap<String, ChatChannel> chatChannels;
private String name;
private String permission;
private String speakPermission;
@ -45,117 +31,6 @@ public class ChatChannel {
private int cooldown;
private String prefix;
/**
* Read chat channels from config file and initialize channel array.
*/
public static void initialize(final VentureChat plugin, final VentureChatFormatService formatter, final boolean aliasesRegisteredAsCommands) {
chatChannels = new HashMap<String, ChatChannel>();
ChatChannel.aliasesRegisteredAsCommands = aliasesRegisteredAsCommands;
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("channels");
for (String key : cs.getKeys(false)) {
String color = cs.getString(key + ".color", "white");
String chatColor = cs.getString(key + ".chatcolor", "white");
String name = key;
String permission = cs.getString(key + ".permissions", "None");
String speakPermission = cs.getString(key + ".speak_permissions", "None");
boolean mutable = cs.getBoolean(key + ".mutable", false);
boolean filter = cs.getBoolean(key + ".filter", true);
boolean bungee = cs.getBoolean(key + ".bungeecord", false);
String format = cs.getString(key + ".format", "Default");
boolean defaultChannel = cs.getBoolean(key + ".default", false);
String alias = cs.getString(key + ".alias", "None");
double distance = cs.getDouble(key + ".distance", (double) 0);
int cooldown = cs.getInt(key + ".cooldown", 0);
boolean autojoin = cs.getBoolean(key + ".autojoin", false);
String prefix = cs.getString(key + ".channel_prefix");
ChatChannel chatChannel = new ChatChannel(name, color, chatColor, permission, speakPermission, mutable,
filter, defaultChannel, alias, distance, autojoin, bungee, cooldown, prefix, format);
chatChannels.put(name.toLowerCase(), chatChannel);
chatChannels.put(alias.toLowerCase(), chatChannel);
if (defaultChannel) {
defaultChatChannel = chatChannel;
defaultColor = color;
}
}
// Error handling for missing default channel in the config.
if(defaultChatChannel == null) {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - &cNo default channel found!"));
defaultChatChannel = new ChatChannel("MissingDefault", "red", "red", "None", "None", false,
true, true, "md", 0, true, false, 0, "&f[&cMissingDefault&f]", "{venturechat_channel_prefix} {vault_prefix}{player_displayname}&c:");
defaultColor = defaultChatChannel.getColor();
chatChannels.put("missingdefault", defaultChatChannel);
chatChannels.put("md", defaultChatChannel);
}
}
public static boolean areAliasesRegisteredAsCommands() {
return aliasesRegisteredAsCommands;
}
/**
* Get list of chat channels.
*
* @return {@link Collection}&lt{@link ChatChannel}&gt
*/
public static Collection<ChatChannel> getChatChannels() {
return new HashSet<ChatChannel>(chatChannels.values());
}
/**
* Get a chat channel by name.
*
* @param channelName
* name of channel to get.
* @return {@link ChatChannel}
*/
public static ChatChannel getChannel(String channelName) {
return chatChannels.get(channelName.toLowerCase());
}
/**
* Checks if the chat channel exists.
*
* @param channelName
* name of channel to check.
* @return true if channel exists, false otherwise.
*/
public static boolean isChannel(String channelName) {
return getChannel(channelName) != null;
}
/**
* Get default chat channel color.
*
* @return {@link String}
*/
public static String getDefaultColor() {
return defaultColor;
}
/**
* Get default chat channel.
*
* @return {@link ChatChannel}
*/
public static ChatChannel getDefaultChannel() {
return defaultChatChannel;
}
/**
* Get list of chat channels with autojoin set to true.
*
* @return {@link List}&lt{@link ChatChannel}&gt
*/
public static List<ChatChannel> getAutojoinList() {
List<ChatChannel> joinlist = new ArrayList<ChatChannel>();
for (ChatChannel c : chatChannels.values()) {
if (c.getAutojoin()) {
joinlist.add(c);
}
}
return joinlist;
}
/**
* Parameterized constructor a {@link ChatChannel}.
*

View File

@ -2,8 +2,9 @@ package venture.Aust1n46.chat.model;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
//This class is used to create ChatMessage objects, which are used to store information about previous text components
//that were sent to the player. This is a main component in making the message remover work.
import lombok.Data;
@Data
public class ChatMessage {
private WrappedChatComponent component;
private String message;
@ -16,28 +17,4 @@ public class ChatMessage {
this.coloredMessage = coloredMessage;
this.hash = hash;
}
public WrappedChatComponent getComponent() {
return this.component;
}
public void setComponent(WrappedChatComponent component) {
this.component = component;
}
public String getMessage() {
return this.message;
}
public String getColoredMessage() {
return this.coloredMessage;
}
public int getHash() {
return this.hash;
}
public void setHash(int hash) {
this.hash = hash;
}
}

View File

@ -1,16 +1,11 @@
package venture.Aust1n46.chat.model;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import venture.Aust1n46.chat.VentureChat;
import lombok.Getter;
@Getter
public class GuiSlot {
private static List<GuiSlot> guiSlots;
private String text;
private String command;
private String permission;
@ -29,53 +24,6 @@ public class GuiSlot {
this.slot = slot;
}
public static void initialize(final VentureChat plugin) {
guiSlots = new ArrayList<GuiSlot>();
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("venturegui");
for (String key : cs.getKeys(false)) {
String name = key;
String icon = cs.getString(key + ".icon");
int durability = cs.getInt(key + ".durability");
String text = cs.getString(key + ".text");
String permission = cs.getString(key + ".permission");
String command = cs.getString(key + ".command");
int slot = cs.getInt(key + ".slot");
guiSlots.add(new GuiSlot(name, icon, durability, text, permission, command, slot));
}
}
public static List<GuiSlot> getGuiSlots() {
return guiSlots;
}
public String getText() {
return text;
}
public String getCommand() {
return command;
}
public String getPermission() {
return permission;
}
public Material getIcon() {
return icon;
}
public int getDurability() {
return durability;
}
public String getName() {
return name;
}
public int getSlot() {
return slot;
}
public boolean hasPermission() {
return !permission.equalsIgnoreCase("venturechat.none");
}

View File

@ -2,6 +2,9 @@ package venture.Aust1n46.chat.model;
import java.util.List;
import lombok.Getter;
@Getter
public class JsonAttribute {
private String name;
private List<String> hoverText;
@ -14,20 +17,4 @@ public class JsonAttribute {
this.clickAction = clickAction;
this.clickText = clickText;
}
public String getName() {
return name;
}
public List<String> getHoverText() {
return hoverText;
}
public String getClickAction() {
return clickAction;
}
public String getClickText() {
return clickText;
}
}

View File

@ -1,17 +1,11 @@
package venture.Aust1n46.chat.model;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import org.bukkit.configuration.ConfigurationSection;
import venture.Aust1n46.chat.VentureChat;
import lombok.Getter;
@Getter
public class JsonFormat {
private static HashMap<String, JsonFormat> jsonFormats;
private List<JsonAttribute> jsonAttributes;
private int priority;
private String name;
@ -21,43 +15,4 @@ public class JsonFormat {
this.priority = priority;
this.jsonAttributes = jsonAttributes;
}
public static void initialize(final VentureChat plugin) {
jsonFormats = new HashMap<String, JsonFormat>();
ConfigurationSection jsonFormatSection = plugin.getConfig().getConfigurationSection("jsonformatting");
for (String jsonFormat : jsonFormatSection.getKeys(false)) {
int priority = jsonFormatSection.getInt(jsonFormat + ".priority", 0);
List<JsonAttribute> jsonAttributes = new ArrayList<>();
ConfigurationSection jsonAttributeSection = jsonFormatSection.getConfigurationSection(jsonFormat + ".json_attributes");
if (jsonAttributeSection != null) {
for (String attribute : jsonAttributeSection.getKeys(false)) {
List<String> hoverText = jsonAttributeSection.getStringList(attribute + ".hover_text");
String clickAction = jsonAttributeSection.getString(attribute + ".click_action", "");
String clickText = jsonAttributeSection.getString(attribute + ".click_text", "");
jsonAttributes.add(new JsonAttribute(attribute, hoverText, clickAction, clickText));
}
}
jsonFormats.put(jsonFormat.toLowerCase(), new JsonFormat(jsonFormat, priority, jsonAttributes));
}
}
public static Collection<JsonFormat> getJsonFormats() {
return jsonFormats.values();
}
public static JsonFormat getJsonFormat(String name) {
return jsonFormats.get(name.toLowerCase());
}
public String getName() {
return name;
}
public int getPriority() {
return priority;
}
public List<JsonAttribute> getJsonAttributes() {
return jsonAttributes;
}
}

View File

@ -8,7 +8,6 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import lombok.AccessLevel;
@ -56,11 +55,6 @@ public class VentureChatPlayer {
private boolean messageToggle;
private boolean bungeeToggle;
@Deprecated
public VentureChatPlayer(UUID uuid, String name, ChatChannel currentChannel, Set<UUID> ignores, Set<String> listening, HashMap<String, MuteContainer> mutes, Set<String> blockedCommands, boolean host, UUID party, boolean filter, boolean notifications, String nickname, String jsonFormat, boolean spy, boolean commandSpy, boolean rangedSpy, boolean messageToggle, boolean bungeeToggle) {
this(uuid, name, currentChannel, ignores, listening, mutes, blockedCommands, host, party, filter, notifications, jsonFormat, spy, commandSpy, rangedSpy, messageToggle, bungeeToggle);
}
public VentureChatPlayer(UUID uuid, String name, ChatChannel currentChannel, Set<UUID> ignores, Set<String> listening, HashMap<String, MuteContainer> mutes, Set<String> blockedCommands, boolean host, UUID party, boolean filter, boolean notifications, String jsonFormat, boolean spy, boolean commandSpy, boolean rangedSpy, boolean messageToggle, boolean bungeeToggle) {
this.uuid = uuid;
this.name = name;
@ -93,10 +87,10 @@ public class VentureChatPlayer {
this.bungeeToggle = bungeeToggle;
}
public VentureChatPlayer(UUID uuid, String name) {
public VentureChatPlayer(UUID uuid, String name, ChatChannel currentChannel) {
this.uuid = uuid;
this.name = name;
this.currentChannel = ChatChannel.getDefaultChannel();
this.currentChannel = currentChannel;
this.ignores = new HashSet<UUID>();
this.listening = new HashSet<String>();
listening.add(currentChannel.getName());
@ -152,26 +146,8 @@ public class VentureChatPlayer {
this.ignores.remove(ignore);
}
public Set<String> getListening() {
return this.listening;
}
public boolean isListening(String channel) {
if(this.isOnline()) {
if(ChatChannel.isChannel(channel)) {
ChatChannel chatChannel = ChatChannel.getChannel(channel);
if(chatChannel.hasPermission()) {
if(!this.getPlayer().hasPermission(chatChannel.getPermission())) {
if(this.getCurrentChannel().equals(chatChannel)) {
this.setCurrentChannel(ChatChannel.getDefaultChannel());
}
this.removeListening(channel);
return false;
}
}
}
}
return this.listening.contains(channel);
return listening.contains(channel);
}
public boolean addListening(String channel) {
@ -234,10 +210,6 @@ public class VentureChatPlayer {
return channel != null ? this.mutes.containsKey(channel) : false;
}
public Set<String> getBlockedCommands() {
return this.blockedCommands;
}
public void addBlockedCommand(String command) {
this.blockedCommands.add(command);
}
@ -254,28 +226,10 @@ public class VentureChatPlayer {
return this.party != null;
}
public void setOnline(boolean online) {
this.online = online;
if(this.online) {
this.player = Bukkit.getPlayer(name);
}
else {
this.player = null;
}
}
public Player getPlayer() {
return this.online ? this.player : null;
}
public UUID getConversation() {
return this.conversation;
}
public void setConversation(UUID conversation) {
this.conversation = conversation;
}
public boolean hasConversation() {
return this.conversation != null;
}
@ -290,10 +244,6 @@ public class VentureChatPlayer {
return this.spy;
}
public void setSpy(boolean spy) {
this.spy = spy;
}
public boolean hasCommandSpy() {
if(this.isOnline()) {
if(!this.getPlayer().hasPermission("venturechat.commandspy")) {
@ -304,22 +254,6 @@ public class VentureChatPlayer {
return this.commandSpy;
}
public void setCommandSpy(boolean commandSpy) {
this.commandSpy = commandSpy;
}
public boolean isQuickChat() {
return this.quickChat;
}
public void setQuickChat(boolean quickChat) {
this.quickChat = quickChat;
}
public ChatChannel getQuickChannel() {
return this.quickChannel;
}
public boolean setQuickChannel(ChatChannel channel) {
if(channel != null) {
this.quickChannel = channel;
@ -328,39 +262,10 @@ public class VentureChatPlayer {
return false;
}
@Deprecated
/**
* Not needed and never resets to it's original null value after being set once.
* @return
*/
public boolean hasQuickChannel() {
return this.quickChannel != null;
}
public UUID getReplyPlayer() {
return this.replyPlayer;
}
public void setReplyPlayer(UUID replyPlayer) {
this.replyPlayer = replyPlayer;
}
public boolean hasReplyPlayer() {
return this.replyPlayer != null;
}
public boolean isPartyChat() {
return this.partyChat;
}
public void setPartyChat(boolean partyChat) {
this.partyChat = partyChat;
}
public HashMap<ChatChannel, Long> getCooldowns() {
return this.cooldowns;
}
public boolean addCooldown(ChatChannel channel, long time) {
if(channel != null && time > 0) {
cooldowns.put(channel, time);
@ -381,10 +286,6 @@ public class VentureChatPlayer {
return channel != null && this.cooldowns != null ? this.cooldowns.containsKey(channel) : false;
}
public HashMap<ChatChannel, List<Long>> getSpam() {
return this.spam;
}
public boolean hasSpam(ChatChannel channel) {
return channel != null && this.spam != null ? this.spam.containsKey(channel) : false;
}
@ -397,18 +298,6 @@ public class VentureChatPlayer {
return false;
}
public void setModified(boolean modified) {
this.modified = modified;
}
public boolean wasModified() {
return this.modified;
}
public List<ChatMessage> getMessages() {
return this.messages;
}
public void addMessage(ChatMessage message) {
if(this.messages.size() >= 100) {
this.messages.remove(0);
@ -419,19 +308,4 @@ public class VentureChatPlayer {
public void clearMessages() {
this.messages.clear();
}
public String getJsonFormat() {
return this.jsonFormat;
}
public void setJsonFormat() {
this.jsonFormat = "Default";
for(JsonFormat j : JsonFormat.getJsonFormats()) {
if(this.getPlayer().hasPermission("venturechat.json." + j.getName())) {
if(JsonFormat.getJsonFormat(this.getJsonFormat()).getPriority() > j.getPriority()) {
this.jsonFormat = j.getName();
}
}
}
}
}

View File

@ -1,4 +1,4 @@
package mineverse.Aust1n46.chat.proxy;
package venture.Aust1n46.chat.proxy;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
@ -9,7 +9,6 @@ import java.util.stream.Collectors;
import com.google.inject.Inject;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.config.ServerInfo;
@ -27,6 +26,7 @@ import net.md_5.bungee.config.YamlConfiguration;
import net.md_5.bungee.event.EventHandler;
import venture.Aust1n46.chat.controllers.VentureChatProxyFlatFileController;
import venture.Aust1n46.chat.service.UUIDService;
import venture.Aust1n46.chat.utilities.FormatUtils;
/**
* VentureChat Minecraft plugin for BungeeCord.

View File

@ -1,4 +1,4 @@
package mineverse.Aust1n46.chat.proxy;
package venture.Aust1n46.chat.proxy;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

View File

@ -1,4 +1,4 @@
package mineverse.Aust1n46.chat.proxy;
package venture.Aust1n46.chat.proxy;
public class VentureChatProxyServer {
private String name;

View File

@ -1,4 +1,4 @@
package mineverse.Aust1n46.chat.proxy;
package venture.Aust1n46.chat.proxy;
import java.util.List;

View File

@ -1,4 +1,4 @@
package mineverse.Aust1n46.chat.proxy;
package venture.Aust1n46.chat.proxy;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
@ -29,11 +29,11 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import venture.Aust1n46.chat.controllers.VentureChatProxyFlatFileController;
import venture.Aust1n46.chat.utilities.FormatUtils;
/**
* VentureChat Minecraft plugin for Velocity.

View File

@ -0,0 +1,225 @@
package venture.Aust1n46.chat.service;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.model.Alias;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.GuiSlot;
import venture.Aust1n46.chat.model.JsonAttribute;
import venture.Aust1n46.chat.model.JsonFormat;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.utilities.FormatUtils;
@Singleton
public class ConfigService {
@Inject
private VentureChat plugin;
private final HashMap<String, ChatChannel> chatChannels = new HashMap<String, ChatChannel>();
private final HashMap<String, JsonFormat> jsonFormats = new HashMap<String, JsonFormat>();
private final List<Alias> aliases = new ArrayList<>();
private final List<GuiSlot> guiSlots = new ArrayList<>();
private boolean aliasesRegisteredAsCommands;
private ChatChannel defaultChatChannel;
private String defaultColor;
@Inject
public void postConstruct() {
aliasesRegisteredAsCommands = true;
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("channels");
for (String key : cs.getKeys(false)) {
String color = cs.getString(key + ".color", "white");
String chatColor = cs.getString(key + ".chatcolor", "white");
String name = key;
String permission = cs.getString(key + ".permissions", "None");
String speakPermission = cs.getString(key + ".speak_permissions", "None");
boolean mutable = cs.getBoolean(key + ".mutable", false);
boolean filter = cs.getBoolean(key + ".filter", true);
boolean bungee = cs.getBoolean(key + ".bungeecord", false);
String format = cs.getString(key + ".format", "Default");
boolean defaultChannel = cs.getBoolean(key + ".default", false);
String alias = cs.getString(key + ".alias", "None");
double distance = cs.getDouble(key + ".distance", (double) 0);
int cooldown = cs.getInt(key + ".cooldown", 0);
boolean autojoin = cs.getBoolean(key + ".autojoin", false);
String prefix = cs.getString(key + ".channel_prefix");
ChatChannel chatChannel = new ChatChannel(name, color, chatColor, permission, speakPermission, mutable, filter, defaultChannel, alias, distance, autojoin, bungee,
cooldown, prefix, format);
chatChannels.put(name.toLowerCase(), chatChannel);
chatChannels.put(alias.toLowerCase(), chatChannel);
if (defaultChannel) {
defaultChatChannel = chatChannel;
defaultColor = color;
}
}
// Error handling for missing default channel in the config.
if (defaultChatChannel == null) {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - &cNo default channel found!"));
defaultChatChannel = new ChatChannel("MissingDefault", "red", "red", "None", "None", false, true, true, "md", 0, true, false, 0, "&f[&cMissingDefault&f]",
"{venturechat_channel_prefix} {vault_prefix}{player_displayname}&c:");
defaultColor = defaultChatChannel.getColor();
chatChannels.put("missingdefault", defaultChatChannel);
chatChannels.put("md", defaultChatChannel);
}
jsonFormats.clear();
ConfigurationSection jsonFormatSection = plugin.getConfig().getConfigurationSection("jsonformatting");
for (String jsonFormat : jsonFormatSection.getKeys(false)) {
int priority = jsonFormatSection.getInt(jsonFormat + ".priority", 0);
List<JsonAttribute> jsonAttributes = new ArrayList<>();
ConfigurationSection jsonAttributeSection = jsonFormatSection.getConfigurationSection(jsonFormat + ".json_attributes");
if (jsonAttributeSection != null) {
for (String attribute : jsonAttributeSection.getKeys(false)) {
List<String> hoverText = jsonAttributeSection.getStringList(attribute + ".hover_text");
String clickAction = jsonAttributeSection.getString(attribute + ".click_action", "");
String clickText = jsonAttributeSection.getString(attribute + ".click_text", "");
jsonAttributes.add(new JsonAttribute(attribute, hoverText, clickAction, clickText));
}
}
jsonFormats.put(jsonFormat.toLowerCase(), new JsonFormat(jsonFormat, priority, jsonAttributes));
}
aliases.clear();
ConfigurationSection configurationSection = plugin.getConfig().getConfigurationSection("alias");
for (String key : configurationSection.getKeys(false)) {
String name = key;
int arguments = configurationSection.getInt(key + ".arguments", 0);
List<String> components = configurationSection.getStringList(key + ".components");
String permissions = configurationSection.getString(key + ".permissions", "None");
aliases.add(new Alias(name, arguments, components, permissions));
}
guiSlots.clear();
cs = plugin.getConfig().getConfigurationSection("venturegui");
for (String key : cs.getKeys(false)) {
String name = key;
String icon = cs.getString(key + ".icon");
int durability = cs.getInt(key + ".durability");
String text = cs.getString(key + ".text");
String permission = cs.getString(key + ".permission");
String command = cs.getString(key + ".command");
int slot = cs.getInt(key + ".slot");
guiSlots.add(new GuiSlot(name, icon, durability, text, permission, command, slot));
}
}
public boolean areAliasesRegisteredAsCommands() {
return aliasesRegisteredAsCommands;
}
/**
* Get list of chat channels.
*
* @return {@link Collection}&lt{@link ChatChannel}&gt
*/
public Collection<ChatChannel> getChatChannels() {
return new HashSet<ChatChannel>(chatChannels.values());
}
/**
* Get a chat channel by name.
*
* @param channelName name of channel to get.
* @return {@link ChatChannel}
*/
public ChatChannel getChannel(String channelName) {
return chatChannels.get(channelName.toLowerCase());
}
/**
* Checks if the chat channel exists.
*
* @param channelName name of channel to check.
* @return true if channel exists, false otherwise.
*/
public boolean isChannel(String channelName) {
return getChannel(channelName) != null;
}
public boolean isListening(VentureChatPlayer ventureChatPlayer, String channel) {
if (ventureChatPlayer.isOnline()) {
if (isChannel(channel)) {
ChatChannel chatChannel = getChannel(channel);
if (chatChannel.hasPermission()) {
if (!ventureChatPlayer.getPlayer().hasPermission(chatChannel.getPermission())) {
if (ventureChatPlayer.getCurrentChannel().equals(chatChannel)) {
ventureChatPlayer.setCurrentChannel(getDefaultChannel());
}
ventureChatPlayer.removeListening(channel);
return false;
}
}
}
}
return ventureChatPlayer.isListening(channel);
}
/**
* Get default chat channel color.
*
* @return {@link String}
*/
public String getDefaultColor() {
return defaultColor;
}
/**
* Get default chat channel.
*
* @return {@link ChatChannel}
*/
public ChatChannel getDefaultChannel() {
return defaultChatChannel;
}
/**
* Get list of chat channels with autojoin set to true.
*
* @return {@link List}&lt{@link ChatChannel}&gt
*/
public List<ChatChannel> getAutojoinList() {
List<ChatChannel> joinlist = new ArrayList<ChatChannel>();
for (ChatChannel c : chatChannels.values()) {
if (c.getAutojoin()) {
joinlist.add(c);
}
}
return joinlist;
}
public Collection<JsonFormat> getJsonFormats() {
return jsonFormats.values();
}
public JsonFormat getJsonFormat(String name) {
return jsonFormats.get(name.toLowerCase());
}
public List<Alias> getAliases() {
return aliases;
}
public List<GuiSlot> getGuiSlots() {
return guiSlots;
}
public boolean isProxyEnabled() {
try {
return plugin.getServer().spigot().getConfig().getBoolean("settings.bungeecord")
|| plugin.getServer().spigot().getPaperConfig().getBoolean("settings.velocity-support.enabled");
} catch (NoSuchMethodError exception) { // Thrown if server isn't Paper.
return false;
}
}
}

View File

@ -7,9 +7,9 @@ import org.bukkit.Bukkit;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import mineverse.Aust1n46.chat.proxy.VentureChatProxySource;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.proxy.VentureChatProxySource;
import venture.Aust1n46.chat.utilities.FormatUtils;
@Singleton
public class UUIDService {

View File

@ -14,8 +14,8 @@ import com.google.inject.Singleton;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.utilities.FormatUtils;
/**
* Initializes and handles writing to the chat logging database.

View File

@ -1,10 +1,10 @@
package venture.Aust1n46.chat.service;
import static mineverse.Aust1n46.chat.utilities.FormatUtils.BUKKIT_COLOR_CODE_PREFIX;
import static mineverse.Aust1n46.chat.utilities.FormatUtils.BUKKIT_COLOR_CODE_PREFIX_CHAR;
import static mineverse.Aust1n46.chat.utilities.FormatUtils.BUKKIT_HEX_COLOR_CODE_PREFIX;
import static mineverse.Aust1n46.chat.utilities.FormatUtils.DEFAULT_COLOR_CODE;
import static mineverse.Aust1n46.chat.utilities.FormatUtils.HEX_COLOR_CODE_PREFIX;
import static venture.Aust1n46.chat.utilities.FormatUtils.BUKKIT_COLOR_CODE_PREFIX;
import static venture.Aust1n46.chat.utilities.FormatUtils.BUKKIT_COLOR_CODE_PREFIX_CHAR;
import static venture.Aust1n46.chat.utilities.FormatUtils.BUKKIT_HEX_COLOR_CODE_PREFIX;
import static venture.Aust1n46.chat.utilities.FormatUtils.DEFAULT_COLOR_CODE;
import static venture.Aust1n46.chat.utilities.FormatUtils.HEX_COLOR_CODE_PREFIX;
import java.util.ArrayList;
import java.util.Arrays;
@ -28,12 +28,12 @@ import com.google.inject.Inject;
import com.google.inject.Singleton;
import me.clip.placeholderapi.PlaceholderAPI;
import mineverse.Aust1n46.chat.utilities.FormatUtils;
import mineverse.Aust1n46.chat.versions.VersionHandler;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.model.JsonAttribute;
import venture.Aust1n46.chat.model.JsonFormat;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.utilities.VersionHandler;
/**
* Class containing chat formatting methods.
@ -50,6 +50,8 @@ public class VentureChatFormatService {
private VentureChat plugin;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
/**
* Converts a message to Minecraft JSON formatting while applying the
@ -61,7 +63,7 @@ public class VentureChatFormatService {
* @return {@link String}
*/
public String convertToJson(VentureChatPlayer sender, String format, String chat) {
JsonFormat JSONformat = JsonFormat.getJsonFormat(sender.getJsonFormat());
JsonFormat JSONformat = configService.getJsonFormat(sender.getJsonFormat());
String f = escapeJsonChars(format);
String c = escapeJsonChars(chat);
String json = "[\"\",{\"text\":\"\",\"extra\":[";
@ -105,7 +107,8 @@ public class VentureChatFormatService {
indexStart = matcher.start();
indexEnd = matcher.end();
placeholder = remaining.substring(indexStart, indexEnd);
formattedPlaceholder = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), placeholder));
formattedPlaceholder = FormatUtils
.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), placeholder));
temp += convertToJsonColors(lastCode + remaining.substring(0, indexStart)) + ",";
lastCode = getLastCode(lastCode + remaining.substring(0, indexStart));
String action = "";
@ -121,9 +124,9 @@ public class VentureChatFormatService {
}
}
}
if(!hover.isEmpty()) {
hover = FormatUtils.FormatStringAll(
PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1)));
if (!hover.isEmpty()) {
hover = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(),
hover.substring(0, hover.length() - 1)));
}
temp += convertToJsonColors(lastCode + formattedPlaceholder,
",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text
@ -416,8 +419,7 @@ public class VentureChatFormatService {
",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/vchatgui " + sender + " " + channelName
+ " " + hash
+ "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":["
+ convertToJsonColors(
FormatUtils.FormatStringAll(plugin.getConfig().getString("guitext")))
+ convertToJsonColors(FormatUtils.FormatStringAll(plugin.getConfig().getString("guitext")))
+ "]}}")
+ "]";
}
@ -459,17 +461,50 @@ public class VentureChatFormatService {
splitComponents(finalList, o, c);
for (Object component : finalList) {
try {
if (VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10()
|| VersionHandler.is1_11() || VersionHandler.is1_12() || VersionHandler.is1_13()
|| VersionHandler.is1_14() || VersionHandler.is1_15() || VersionHandler.is1_16()
|| VersionHandler.is1_17()) {
String text = (String) component.getClass().getMethod("getText").invoke(component);
Object chatModifier = component.getClass().getMethod("getChatModifier").invoke(component);
String color = chatModifier.getClass().getMethod("getColor").invoke(chatModifier).toString();
Object color = chatModifier.getClass().getMethod("getColor").invoke(chatModifier);
String colorString = "white";
if (color != null) {
colorString = color.getClass().getMethod("b").invoke(color).toString();
}
boolean bold = (boolean) chatModifier.getClass().getMethod("isBold").invoke(chatModifier);
boolean strikethrough = (boolean) chatModifier.getClass().getMethod("isStrikethrough").invoke(chatModifier);
boolean strikethrough = (boolean) chatModifier.getClass().getMethod("isStrikethrough")
.invoke(chatModifier);
boolean italic = (boolean) chatModifier.getClass().getMethod("isItalic").invoke(chatModifier);
boolean underlined = (boolean) chatModifier.getClass().getMethod("isUnderlined").invoke(chatModifier);
boolean obfuscated = (boolean) chatModifier.getClass().getMethod("isRandom").invoke(chatModifier);
boolean underlined = (boolean) chatModifier.getClass().getMethod("isUnderlined")
.invoke(chatModifier);
boolean obfuscated = (boolean) chatModifier.getClass().getMethod("isRandom")
.invoke(chatModifier);
JSONObject jsonObject = new JSONObject();
jsonObject.put("text", text);
jsonObject.put("color", color);
jsonObject.put("color", colorString);
jsonObject.put("bold", bold);
jsonObject.put("strikethrough", strikethrough);
jsonObject.put("italic", italic);
jsonObject.put("underlined", underlined);
jsonObject.put("obfuscated", obfuscated);
stringbuilder.append(jsonObject.toJSONString() + ",");
} else {
String text = (String) component.getClass().getMethod("getString").invoke(component);
Object chatModifier = component.getClass().getMethod("c").invoke(component);
Object color = chatModifier.getClass().getMethod("a").invoke(chatModifier);
String colorString = "white";
if (color != null) {
colorString = color.getClass().getMethod("b").invoke(color).toString();
}
boolean bold = (boolean) chatModifier.getClass().getMethod("b").invoke(chatModifier);
boolean italic = (boolean) chatModifier.getClass().getMethod("c").invoke(chatModifier);
boolean strikethrough = (boolean) chatModifier.getClass().getMethod("d").invoke(chatModifier);
boolean underlined = (boolean) chatModifier.getClass().getMethod("e").invoke(chatModifier);
boolean obfuscated = (boolean) chatModifier.getClass().getMethod("f").invoke(chatModifier);
JSONObject jsonObject = new JSONObject();
jsonObject.put("text", text);
jsonObject.put("color", colorString);
jsonObject.put("bold", bold);
jsonObject.put("strikethrough", strikethrough);
jsonObject.put("italic", italic);
@ -477,7 +512,7 @@ public class VentureChatFormatService {
jsonObject.put("obfuscated", obfuscated);
stringbuilder.append(jsonObject.toJSONString() + ",");
}
catch(Exception e) {
} catch (Exception e) {
return "\"extra\":[{\"text\":\"Something went wrong. Could not access color.\",\"color\":\"red\"}]";
}
}
@ -485,7 +520,7 @@ public class VentureChatFormatService {
e.printStackTrace();
}
String coloredText = stringbuilder.toString();
if(coloredText.endsWith(",")) {
if (coloredText.endsWith(",")) {
coloredText = coloredText.substring(0, coloredText.length() - 1);
}
coloredText += "]";
@ -500,29 +535,22 @@ public class VentureChatFormatService {
for (Object component : finalList) {
if (VersionHandler.is1_7()) {
stringbuilder.append((String) component.getClass().getMethod("e").invoke(component));
} else {
} else if (VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10()
|| VersionHandler.is1_11() || VersionHandler.is1_12() || VersionHandler.is1_13()
|| VersionHandler.is1_14() || VersionHandler.is1_15() || VersionHandler.is1_16()
|| VersionHandler.is1_17()) {
stringbuilder.append((String) component.getClass().getMethod("getText").invoke(component));
} else {
stringbuilder.append((String) component.getClass().getMethod("getString").invoke(component));
}
}
} catch (Exception e) {
e.printStackTrace();
}
// if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
// System.out.println("my string");
// System.out.println("my string");
// System.out.println("my string");
// System.out.println("my string");
// System.out.println("my string");
// System.out.println(stringbuilder.toString());
// }
return stringbuilder.toString();
}
private void splitComponents(List<Object> finalList, Object o, Class<?> c) throws Exception {
// for(Method m : c.getMethods()) {
// System.out.println(m.getName());
// }
if (VersionHandler.is1_7() || VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10()
|| VersionHandler.is1_11() || VersionHandler.is1_12() || VersionHandler.is1_13()
|| (VersionHandler.is1_14() && !VersionHandler.is1_14_4())) {
@ -535,7 +563,8 @@ public class VentureChatFormatService {
finalList.add(component);
}
}
} else {
} else if (VersionHandler.is1_14_4() || VersionHandler.is1_15() || VersionHandler.is1_16()
|| VersionHandler.is1_17()) {
ArrayList<?> list = (ArrayList<?>) c.getMethod("getSiblings").invoke(o, new Object[0]);
for (Object component : list) {
ArrayList<?> innerList = (ArrayList<?>) c.getMethod("getSiblings").invoke(component, new Object[0]);
@ -545,6 +574,16 @@ public class VentureChatFormatService {
finalList.add(component);
}
}
} else {
ArrayList<?> list = (ArrayList<?>) c.getMethod("b").invoke(o, new Object[0]);
for (Object component : list) {
ArrayList<?> innerList = (ArrayList<?>) c.getMethod("b").invoke(component, new Object[0]);
if (innerList.size() > 0) {
splitComponents(finalList, component, c);
} else {
finalList.add(component);
}
}
}
}
@ -573,7 +612,7 @@ public class VentureChatFormatService {
}
public void broadcastToServer(String message) {
for(VentureChatPlayer mcp : playerApiService.getOnlineMineverseChatPlayers()) {
for (VentureChatPlayer mcp : playerApiService.getOnlineMineverseChatPlayers()) {
mcp.getPlayer().sendMessage(message);
}
}
@ -581,25 +620,26 @@ public class VentureChatFormatService {
public void playMessageSound(VentureChatPlayer mcp) {
Player player = mcp.getPlayer();
String soundName = plugin.getConfig().getString("message_sound", DEFAULT_MESSAGE_SOUND);
if(!soundName.equalsIgnoreCase("None")) {
if (!soundName.equalsIgnoreCase("None")) {
Sound messageSound = getSound(soundName);
player.playSound(player.getLocation(), messageSound, 1, 0);
}
}
private Sound getSound(String soundName) {
if(Arrays.asList(Sound.values()).stream().map(Sound::toString).collect(Collectors.toList()).contains(soundName)) {
if (Arrays.asList(Sound.values()).stream().map(Sound::toString).collect(Collectors.toList())
.contains(soundName)) {
return Sound.valueOf(soundName);
}
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Message sound invalid!"));
Bukkit.getConsoleSender()
.sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Message sound invalid!"));
return getDefaultMessageSound();
}
private Sound getDefaultMessageSound() {
if(VersionHandler.is1_7() || VersionHandler.is1_8()) {
if (VersionHandler.is1_7() || VersionHandler.is1_8()) {
return Sound.valueOf(DEFAULT_LEGACY_MESSAGE_SOUND);
}
else {
} else {
return Sound.valueOf(DEFAULT_MESSAGE_SOUND);
}
}

View File

@ -8,8 +8,8 @@ import java.util.UUID;
import org.bukkit.entity.Player;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer;
import venture.Aust1n46.chat.model.VentureChatPlayer;
/**
* API class for looking up wrapped {@link VentureChatPlayer} objects from
@ -17,7 +17,7 @@ import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer;
*
* @author Aust1n46
*/
public final class VentureChatPlayerApiService {
public class VentureChatPlayerApiService {
private static HashMap<UUID, VentureChatPlayer> playerMap = new HashMap<UUID, VentureChatPlayer>();
private static HashMap<String, UUID> namesMap = new HashMap<String, UUID>();
private static HashMap<UUID, VentureChatPlayer> onlinePlayerMap = new HashMap<UUID, VentureChatPlayer>();
@ -102,7 +102,7 @@ public final class VentureChatPlayerApiService {
* @param player {@link Player} object.
* @return {@link VentureChatPlayer}
*/
public VentureChatPlayer getOnlineMineverseChatPlayer(Player player) {
public VentureChatPlayer getOnlineMineverseChatPlayer(final Player player) {
return getOnlineMineverseChatPlayer(player.getUniqueId());
}
@ -132,7 +132,6 @@ public final class VentureChatPlayerApiService {
public List<String> getNetworkPlayerNames() {
return networkPlayerNames;
}
@ -149,11 +148,6 @@ public final class VentureChatPlayerApiService {
proxyPlayerMap.put(smcp.getUUID(), smcp);
}
// @Deprecated
// public static void clearBungeePlayerMap() {
// clearProxyPlayerMap();
// }
public void clearProxyPlayerMap() {
proxyPlayerMap.clear();
}

View File

@ -1,11 +1,11 @@
package mineverse.Aust1n46.chat.utilities;
package venture.Aust1n46.chat.utilities;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.localization.LocalizedMessage;
public class FormatUtils {
public static final char BUKKIT_COLOR_CODE_PREFIX_CHAR = '\u00A7';
@ -19,6 +19,8 @@ public class FormatUtils {
public static final long MILLISECONDS_PER_MINUTE = 60000;
public static final long MILLISECONDS_PER_SECOND = 1000;
public static final int LINE_LENGTH = 40;
private static final Pattern LEGACY_CHAT_COLOR_DIGITS_PATTERN = Pattern.compile("&([0-9])");
private static final Pattern LEGACY_CHAT_COLOR_PATTERN = Pattern.compile(
"(?<!(&x(&[a-fA-F0-9]){5}))(?<!(&x(&[a-fA-F0-9]){4}))(?<!(&x(&[a-fA-F0-9]){3}))(?<!(&x(&[a-fA-F0-9]){2}))(?<!(&x(&[a-fA-F0-9]){1}))(?<!(&x))(&)([0-9a-fA-F])");

View File

@ -1,4 +1,4 @@
package mineverse.Aust1n46.chat.versions;
package venture.Aust1n46.chat.utilities;
import org.bukkit.Bukkit;

View File

@ -1,24 +1,28 @@
package venture.Aust1n46.chat.initiators.listeners;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.Mockito.when;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import venture.Aust1n46.chat.Logger;
import venture.Aust1n46.chat.VentureChat;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.controllers.VentureChatSpigotFlatFileController;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.UUIDService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class LoginListenerTest {
@Mock
private VentureChat plugin;
@ -31,6 +35,8 @@ public class LoginListenerTest {
@Mock
private VentureChatPlayerApiService playerApiService;
@Mock
private ConfigService configService;
@Mock
private Logger log;
@InjectMocks
private LoginListener loginListener;
@ -38,9 +44,13 @@ public class LoginListenerTest {
@Mock
private PlayerQuitEvent mockPlayerQuitEvent;
@Mock
private PlayerJoinEvent mockPlayerJoinEvent;
@Mock
private Player mockPlayer;
@Mock
private VentureChatPlayer mockVentureChatPlayer;
@Mock
private ChatChannel mockDefaultChannel;
@Test
public void testPlayerQuit() {
@ -50,7 +60,28 @@ public class LoginListenerTest {
}
@Test
public void testPlayerJoin_successful() {
public void testPlayerQuit_playerNull() {
when(mockPlayerQuitEvent.getPlayer()).thenReturn(mockPlayer);
when(playerApiService.getOnlineMineverseChatPlayer(mockPlayer)).thenReturn(null);
loginListener.onPlayerQuit(mockPlayerQuitEvent);
assertDoesNotThrow(() -> loginListener.onPlayerQuit(mockPlayerQuitEvent));
}
@Test
public void testPlayerJoin_existingPlayer_NoProxy() {
when(mockPlayerJoinEvent.getPlayer()).thenReturn(mockPlayer);
when(configService.getDefaultChannel()).thenReturn(mockDefaultChannel);
when(mockPlayer.getName()).thenReturn("Aust1n46");
when(configService.isProxyEnabled()).thenReturn(false);
loginListener.onPlayerJoin(mockPlayerJoinEvent);
}
@Test
public void testPlayerJoin_existingPlayer_Proxy() {
when(mockPlayerJoinEvent.getPlayer()).thenReturn(mockPlayer);
when(configService.getDefaultChannel()).thenReturn(mockDefaultChannel);
when(mockPlayer.getName()).thenReturn("Aust1n46");
when(configService.isProxyEnabled()).thenReturn(true);
loginListener.onPlayerJoin(mockPlayerJoinEvent);
}
}