Skip to content

Commit

Permalink
Merge pull request #19 from Mineaurion/feature-reload.command
Browse files Browse the repository at this point in the history
Feature reload.command
  • Loading branch information
Yann151924 authored Mar 1, 2023
2 parents 7c9929c + f94ad70 commit 7e4dc66
Show file tree
Hide file tree
Showing 44 changed files with 641 additions and 677 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ subprojects {
api 'com.google.code.gson:gson:2.8.5'
api 'com.rabbitmq:amqp-client:5.14.2'
compileOnly 'net.luckperms:api:5.4'
compileOnly 'org.apache.logging.log4j:log4j-api:2.19.0'
}

compileJava.options.encoding = 'UTF-8'
Expand Down
103 changes: 35 additions & 68 deletions bukkit/src/main/java/com/mineaurion/aurionchat/bukkit/AurionChat.java
Original file line number Diff line number Diff line change
@@ -1,97 +1,64 @@
package com.mineaurion.aurionchat.bukkit;

import com.mineaurion.aurionchat.bukkit.channel.ChatService;
import com.mineaurion.aurionchat.bukkit.command.ChatCommand;
import com.mineaurion.aurionchat.bukkit.listeners.ChatListener;
import com.mineaurion.aurionchat.bukkit.listeners.CommandListener;
import com.mineaurion.aurionchat.bukkit.listeners.LoginListener;
import com.mineaurion.aurionchat.common.LuckPermsUtils;
import net.luckperms.api.LuckPerms;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import com.mineaurion.aurionchat.common.AbstractAurionChat;
import com.mineaurion.aurionchat.common.logger.JavaPluginLogger;
import com.mineaurion.aurionchat.common.logger.PluginLogger;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeoutException;
public class AurionChat extends AbstractAurionChat<AurionChatPlayer> {

public static final String ID = "aurionchat";

public class AurionChat extends JavaPlugin {
public static Config config;
public static Map<UUID, AurionChatPlayer> aurionChatPlayers = new HashMap<>();
public static LuckPermsUtils luckPermsUtils = null;
public static Utils utils = new Utils();
public ChatService getChatService() {
return chatService;
}

public void setChatService(ChatService chatService) {
this.chatService = chatService;
}
private ChatService chatService;
public final JavaPlugin plugin;

public boolean isErrorRabbitmq() {
return errorRabbitmq;
public AurionChat(JavaPlugin plugin){
this.plugin = plugin;
}

public void setErrorRabbitmq(boolean errorRabbitmq) {
this.errorRabbitmq = errorRabbitmq;
public void onEnable(){
getlogger().info("AurionChat Initializing");
config = new Config(this.plugin);
this.enable(
config.rabbitmq.uri,
config.rabbitmq.serverName,
config.options.spy,
config.options.autoMessage,
true
);
}

private boolean errorRabbitmq = false;
public void onDisable() {
this.disable();
}


@Override
public void onEnable(){
sendConsoleMessage("&8[&eAurionChat&8]&e - Initializing...");
sendConsoleMessage("&8[&eAurionChat&8]&e - Checking for Vault...");
RegisteredServiceProvider<LuckPerms> luckPermsprovider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
if(luckPermsprovider != null) {
luckPermsUtils = new LuckPermsUtils(luckPermsprovider.getProvider());
}
config = new Config(this);
sendConsoleMessage("&8[&eAurionChat&8]&e - Config Loaded.");
sendConsoleMessage("&8[&eAurionChat&8]&e - Connecting to RabbitMQ");

try {
this.setChatService(new ChatService(config.rabbitmq.uri, config.rabbitmq.serverName));
} catch (IOException | TimeoutException e){
Bukkit.getPluginManager().disablePlugin(this);
this.setErrorRabbitmq(true);
sendConsoleMessage("&8[&eAurionChat&8]&e - &ccan't connect to rabbitmq, disabling.");
getLogger().warning(e.getMessage());
}
sendConsoleMessage("&8[&eAurionChat&8]&e - Registering Listeners");
setupListener(this);
this.getCommand("chat").setExecutor(new ChatCommand());
protected void registerPlatformListeners() {
PluginManager pluginManager = this.plugin.getServer().getPluginManager();
pluginManager.registerEvents(new LoginListener(this), this.plugin);
pluginManager.registerEvents(new CommandListener(this), this.plugin);
pluginManager.registerEvents(new ChatListener(this), this.plugin);
}

private void setupListener(AurionChat plugin){
PluginManager pluginManager = getServer().getPluginManager();
pluginManager.registerEvents(new LoginListener(), this);
pluginManager.registerEvents(new ChatListener(plugin), this);
pluginManager.registerEvents(new CommandListener(plugin), this);
@Override
protected void registerCommands() {
this.plugin.getCommand("chat").setExecutor(new ChatCommand(this));
}

@Override
public void onDisable() {
if(!this.isErrorRabbitmq()){
try{
if(this.getChatService() != null){
this.getChatService().close();
}
}
catch(IOException|TimeoutException e){
sendConsoleMessage("&8[&eAurionChat&8]&e - Error when communication closed");
sendConsoleMessage(e.getMessage());
}
}
protected void disablePlugin() {
this.plugin.getServer().getPluginManager().disablePlugin(this.plugin);
}

public void sendConsoleMessage(String message){
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', message));
@Override
public PluginLogger getlogger() {
return new JavaPluginLogger(this.plugin.getServer().getLogger());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mineaurion.aurionchat.common.config.Channel;
import org.bukkit.Sound;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -14,7 +15,7 @@ public class Config {
public Options options = new Options();
public Map<String, Channel> channels = new HashMap<>();

public Config(AurionChat plugin){
public Config(JavaPlugin plugin){
plugin.getConfig().options().copyDefaults(true);
plugin.saveDefaultConfig();
config = plugin.getConfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mineaurion.aurionchat.bukkit;

import org.bukkit.plugin.java.JavaPlugin;

public class PluginLoader extends JavaPlugin {

private final AurionChat plugin;

public PluginLoader(){
this.plugin = new AurionChat(this);
}

@Override
public void onEnable(){
this.plugin.onEnable();
}

@Override
public void onDisable(){
this.plugin.onDisable();
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class ChatCommand extends ChatCommandCommon<AurionChatPlayer> implements CommandExecutor {
public ChatCommand() {
public class ChatCommand extends ChatCommandCommon implements CommandExecutor {

private final AurionChat aurionChat;

public ChatCommand(AurionChat aurionChat) {
super(AurionChat.config.channels.keySet());
this.aurionChat = aurionChat;
}

@Override
Expand All @@ -20,7 +24,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if(!(sender instanceof Player)){
return false;
}
AurionChatPlayer aurionChatPlayer = AurionChat.aurionChatPlayers.get(Bukkit.getPlayer(sender.getName()).getUniqueId());
AurionChatPlayer aurionChatPlayer = this.aurionChat.getAurionChatPlayers().get(Bukkit.getPlayer(sender.getName()).getUniqueId());
String command = args.length < 1 ? "DEFAULT" : args[0];
String channel = (args.length == 2) ? args[1] : "";

Expand All @@ -38,6 +42,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return false;
}
}

return false;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.mineaurion.aurionchat.bukkit.AurionChat;
import com.mineaurion.aurionchat.bukkit.AurionChatPlayer;
import com.mineaurion.aurionchat.common.ChatService;
import com.mineaurion.aurionchat.common.Utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -12,10 +14,11 @@
import java.io.IOException;

public class ChatListener implements Listener {
private final AurionChat plugin;

public ChatListener(AurionChat plugin){
this.plugin = plugin;
private final AurionChat aurionChat;

public ChatListener(AurionChat aurionChat){
this.aurionChat = aurionChat;
}

@EventHandler(priority = EventPriority.HIGHEST)
Expand All @@ -26,13 +29,13 @@ public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event){
event.setCancelled(true);
return;
}
AurionChatPlayer aurionChatPlayer = AurionChat.aurionChatPlayers.get(player.getUniqueId());
AurionChatPlayer aurionChatPlayer = this.aurionChat.getAurionChatPlayers().get(player.getUniqueId());

String currentChannel = aurionChatPlayer.getCurrentChannel();
String messageFormat = AurionChat.utils.processMessage(AurionChat.config.channels.get(currentChannel).format, event.getMessage(), aurionChatPlayer);
String messageFormat = Utils.processMessage(AurionChat.config.channels.get(currentChannel).format, event.getMessage(), aurionChatPlayer);

try{
this.plugin.getChatService().send(currentChannel,messageFormat);
ChatService.getInstance().send(currentChannel,messageFormat);
}
catch(IOException e){
Bukkit.getConsoleSender().sendMessage(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import com.mineaurion.aurionchat.bukkit.AurionChat;
import com.mineaurion.aurionchat.bukkit.AurionChatPlayer;
import com.mineaurion.aurionchat.bukkit.Config;
import com.mineaurion.aurionchat.bukkit.Utils;
import com.mineaurion.aurionchat.bukkit.channel.ChatService;
import com.mineaurion.aurionchat.common.listeners.CommandListenerCommon;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Bukkit;
Expand All @@ -15,12 +12,13 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class CommandListener extends CommandListenerCommon<AurionChatPlayer, Utils, ChatService> implements CommandExecutor, Listener {
private final Config config;
public class CommandListener extends CommandListenerCommon<AurionChatPlayer> implements CommandExecutor, Listener {

public CommandListener(AurionChat plugin){
super(AurionChat.utils, plugin.getChatService());
this.config = AurionChat.config;
private final AurionChat aurionChat;


public CommandListener(AurionChat aurionChat){
this.aurionChat = aurionChat;
}

@EventHandler
Expand All @@ -30,8 +28,8 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){
String message = String.join(" ", (String[]) ArrayUtils.removeElement(fullCommand, "/" + command));

AurionChat.config.getChannelByNameOrAlias(command).ifPresent(channelName -> {
AurionChatPlayer aurionChatPlayer = AurionChat.aurionChatPlayers.get(event.getPlayer().getUniqueId());
this.onCommand(aurionChatPlayer, message, channelName, config.channels.get(channelName).format);
AurionChatPlayer aurionChatPlayer = this.aurionChat.getAurionChatPlayers().get(event.getPlayer().getUniqueId());
this.onCommand(aurionChatPlayer, message, channelName, AurionChat.config.channels.get(channelName).format);
event.setCancelled(true);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,15 @@
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;

import java.util.Map;
import java.util.UUID;

public class LoginListener extends LoginListenerCommon<AurionChatPlayer> implements Listener {

private static final Map<UUID, AurionChatPlayer> aurionChatPlayers = AurionChat.aurionChatPlayers;

public LoginListener() {
super(aurionChatPlayers);
public LoginListener(AurionChat aurionChat){
super(aurionChat.getAurionChatPlayers());
}

@EventHandler(priority = EventPriority.LOW)
public void onPlayerKick(PlayerKickEvent event){
this.playerLeaving(event.getPlayer().getUniqueId());
playerLeaving(event.getPlayer().getUniqueId());
}

@EventHandler(priority = EventPriority.LOW)
Expand Down
5 changes: 4 additions & 1 deletion bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Aurionchat
version: ${version}
main: com.mineaurion.aurionchat.bukkit.AurionChat
main: com.mineaurion.aurionchat.bukkit.PluginLoader
authors: [Yann151924]
website: https://mineaurion.com
depend:
Expand All @@ -14,4 +14,7 @@ permissions:
aurionchat.chat.colors:
default: false
description: Chat color
aurionchat.reload:
default: false
description: Relaod connection

Loading

0 comments on commit 7e4dc66

Please sign in to comment.