Skip to content

Commit

Permalink
1.2.0 Reload command
Browse files Browse the repository at this point in the history
# Feautres:
- Added reload for admins (**crosschat.reload**)
- Added configuration for communication channel used by the plugins (**in the config.yml**).
# Code:
 - ## Added command manager on BungeePlugin:
    1. Added class **Command Manager** which will manage subcommands for the plugin.
    2. Added absctract class **SubCommand** as a template for subcommands.
    3. Added **reload** subcommand which reload the plugin config (bungee only for now)
  • Loading branch information
mataai authored Nov 4, 2020
2 parents cce7e5a + 2d3a877 commit 9494e4c
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CrossChat/
updatenotes.md
2 changes: 1 addition & 1 deletion Bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.mateimartin</groupId>
<artifactId>CrossChatBungee</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>

<repositories>
<repository>
Expand Down
42 changes: 13 additions & 29 deletions Bungee/src/main/java/ca/matai/crosschat/CrossChatBungee.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ca.matai.crosschat;

import ca.matai.crosschat.commands.CommandManager;
import ca.matai.crosschat.listeners.MessageListener;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.plugin.Plugin;
Expand All @@ -26,33 +27,34 @@ public void onEnable() {
configuration = getConfig();
} catch (Exception e) {
getProxy().getLogger().log(Level.SEVERE,
ChatColor.BLUE+"[CrossChat]"+ChatColor.RED+" Configuration file could not be loaded, using default config.");
ChatColor.AQUA+"[CrossChat]"+ChatColor.RED+" Configuration file could not be loaded, using default config.");
}

getProxy().registerChannel( "message:sent" );
getProxy().registerChannel( getConfigurationValue("communicationChannel"));
getProxy().getPluginManager().registerListener(this,new MessageListener());

this.getProxy().getPluginManager().registerCommand(this,new CommandManager());
}

/**
* Retrieves the config object, if it dosent exist generates it.
* @return Return the Configuration object generated from the config file in your plugins folder.
* @throws IOException Error thrown if config.yml could not be read.
*/
private Configuration getConfig() throws IOException {
private static Configuration getConfig() throws IOException {
Configuration configuration;
if (!getDataFolder().exists()){
getDataFolder().mkdir();
File file = new File(getDataFolder(), "config.yml");
if (! instance.getDataFolder().exists()){
instance.getDataFolder().mkdir();
File file = new File(instance.getDataFolder(), "config.yml");
if (!file.exists()) {
try (InputStream in = getResourceAsStream("config.yml")) {
try (InputStream in = instance.getResourceAsStream("config.yml")) {
Files.copy(in, file.toPath());
} catch (Exception e) {
getProxy().getLogger().log(Level.SEVERE,
instance.getProxy().getLogger().log(Level.SEVERE,
ChatColor.RED+"[CrossChat]"+"getConfig readfile");
}
}
}
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(instance.getDataFolder(), "config.yml"));
return configuration;
}

Expand All @@ -74,24 +76,6 @@ private void FixConfig(){
e.printStackTrace();
}

// if (getDefaultConfig().getKeys() == configuration.getKeys()){ //Keys are the same but content might be empty.
// boolean diff = false;
// for (String key : input.getKeys()){
// if (input.get(key) == null || !input.get(key).equals("")) {
// input.set(key, getDefaultConfig().get(key));
// diff = true;
// }
// }
// try {
// ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, new File(getDataFolder(), "config.yml"));
// } catch (Exception e) {
// getProxy().getLogger().log(Level.WARNING,
// ChatColor.BLUE+"[CrossChat]"+ChatColor.RED+" Configuration file could not be saved after Configuration Validation.");
// getProxy().getLogger().log(Level.CONFIG,e.getMessage());
// }
// }
// return input;

}

/**
Expand All @@ -117,9 +101,9 @@ private static Configuration getDefaultConfig(){
Configuration configuration = new Configuration();

configuration.set("separator"," → ");
configuration.set("communicationChannel","crosschat:message");

return configuration;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.PluginManager;
import net.md_5.bungee.event.EventHandler;

public class MessageListener implements Listener {
Expand All @@ -16,12 +15,13 @@ public class MessageListener implements Listener {

@EventHandler
public void PluginMessageListener(PluginMessageEvent event){
if (event.getTag().equalsIgnoreCase("message:sent")){

if (event.getTag().equalsIgnoreCase(CrossChatBungee.instance.getConfigurationValue("communicationChannel"))){
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
String playername = in.readUTF();
String chatmessage = in.readUTF();

ProxyServer.getInstance().broadcast(new TextComponent(playername + CrossChatBungee.instance.getConfigurationValue("separator") + chatmessage));

}
}

Expand Down
11 changes: 10 additions & 1 deletion Bungee/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
separator: ""
separator: ""



#=================================================================================
# Advanced Section. Don't touch this if you don't know what you are doing.
# Trust me you might end up without chat or other functions on all your servers.
#=================================================================================

communicationChannel: "crosschat:message"
2 changes: 1 addition & 1 deletion Bungee/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CrossChat
version: 1.1.0
version: 1.2.0
description: Receiver plugin to chat across multiple Bungee/Waterfall servers.


Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ Project Code and feature/issues can be found on the GitHub repo ([Right Here!](h

## RoadMap:
1. ~~Add configuration for symbol between username and chat message.~~
2. Admins can toggle global chat.
2. Admins can toggle global chat.
3. Add option to display server user is chating from.
2 changes: 1 addition & 1 deletion Spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.matai</groupId>
<artifactId>CrossChatSpigot</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public List<SubCommand> getSubCommands() {
}

public void helpMessage(Player p) {
p.sendMessage(ChatColor.YELLOW + " [" + ChatColor.AQUA + "@Player" + ChatColor.YELLOW + "]");
p.sendMessage(ChatColor.AQUA+"[CrossChat]");
p.sendMessage(ChatColor.AQUA + "Version: " + JavaPlugin.getPlugin(CrossChatSpigot.class).getDescription().getVersion());
p.sendMessage(ChatColor.AQUA + "Available commands: ");
getSubCommands().forEach(x -> p.sendMessage(ChatColor.AQUA + x.getSyntax()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public abstract class SubCommand {

public Boolean permissionCheck(Player p){
if(!p.hasPermission(getPermission())){
p.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "CrossChat" + ChatColor.YELLOW + "]" + ChatColor.RED + "You do not have the permission to use this command!");
p.sendMessage(ChatColor.AQUA+"[CrossChat]" + ChatColor.RED + "You do not have the permission to use this command!");
return false;
}
return true;
Expand Down
20 changes: 14 additions & 6 deletions Spigot/src/main/java/ca/matai/CrossChat/CrossChatSpigot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,35 @@

import ca.matai.CrossChat.listeners.ChatListener;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.Configuration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.IOException;
import java.util.logging.Level;


public class CrossChatSpigot extends JavaPlugin implements Listener {


@Override
public void onEnable() {
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "message:sent");
this.saveDefaultConfig();

this.getServer().getMessenger().registerOutgoingPluginChannel(this, this.getConfig().getString("communicationChannel"));

Bukkit.getServer().getPluginManager().registerEvents(this, this);
}
@Override
public void onDisable() {
}



@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) {
public void onPlayerChat(AsyncPlayerChatEvent event) throws IOException {
ChatListener info = new ChatListener(event.getPlayer().getDisplayName(),event.getMessage());
event.getPlayer().sendPluginMessage(JavaPlugin.getPlugin(CrossChatSpigot.class),"message:sent",info.getPluginMessage());
event.getPlayer().sendPluginMessage(JavaPlugin.getPlugin(CrossChatSpigot.class),this.getConfig().getString("communicationChannel"),info.getPluginMessage());
event.setCancelled(true);
}

Expand Down
11 changes: 11 additions & 0 deletions Spigot/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
settingplaceholder: "Hello World!"




#=================================================================================
# Advanced Section. Don't touch this if you don't know what you are doing.
# Trust me you might end up without chat or other functions on all your servers.
#=================================================================================

communicationChannel: "crosschat:message"
2 changes: 1 addition & 1 deletion Spigot/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CrossChat
version: 1.1.0
version: 1.2.0
description: Sender plugin to chat across multiple Bungee/Waterfall servers.

author: _Matai_
Expand Down

0 comments on commit 9494e4c

Please sign in to comment.