Skip to content

Commit

Permalink
Merge pull request #21 from SawFowl/dev
Browse files Browse the repository at this point in the history
Update 2.8.1
  • Loading branch information
SawFowl authored May 25, 2022
2 parents 7ba2196 + ec91941 commit 07f8488
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 50 deletions.
13 changes: 7 additions & 6 deletions src/main/java/sawfowl/commandsyncclient/sponge/CSC.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private String[] loadConfig() {
remove = Boolean.valueOf(data[6]);
loc = new Locale(this, String.valueOf(data[7]));
loc.init();
logger.info(loc.getString("ConfigLoaded"));
logger.info(loc.getString("ConfigLoaded", true));
} catch(IOException e) {
e.printStackTrace();
}
Expand All @@ -148,8 +148,8 @@ private void workData() throws IOException {
boolean remove = this.remove;
if (remove == true) {
if(data.delete()){
logger.info(loc.getString("DataRemoved"));
} else logger.warn(loc.getString("DataRemoveNotFound"));
logger.info(loc.getString("DataRemoved", true));
} else logger.warn(loc.getString("DataRemoveNotFound", true));
} else {
loadData();
}
Expand All @@ -164,7 +164,7 @@ public void saveData() {
}
ps.println("qc:" + String.valueOf(qc));
ps.close();
logger.info(loc.getString("DataSaved"));
logger.info(loc.getString("DataSaved", true));
}catch(IOException e){
e.printStackTrace();
}
Expand All @@ -185,15 +185,16 @@ private void loadData() {
}
l = br.readLine();
}
logger.info(loc.getString("DataLoaded"));
logger.info(loc.getString("DataLoaded", true));
} finally {
br.close();
}
} else {
logger.warn(loc.getString("DataNotfound"));
logger.warn(loc.getString("DataNotfound", true));
}
} catch(IOException e) {
e.printStackTrace();
}
}

}
18 changes: 9 additions & 9 deletions src/main/java/sawfowl/commandsyncclient/sponge/ClientThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void run() {
out.println("heartbeat");
if(out.checkError()) {
connected = false;
plugin.getLogger().warn(plugin.getLocale().getString("ConnectLost"));
plugin.getLogger().warn(plugin.getLocale().getString("ConnectLost", true));
} else {
try {
Integer size = plugin.oq.size();
Expand All @@ -55,18 +55,18 @@ public void run() {
count++;
String output = plugin.oq.get(i);
out.println(output);
plugin.getLogger().info(plugin.getLocale().getString("SentOutput", socket.getInetAddress().getHostName(), String.valueOf(socket.getPort()), output));
plugin.getLogger().info(plugin.getLocale().getString("SentOutput", true, socket.getInetAddress().getHostName(), String.valueOf(socket.getPort()), output));
}
plugin.qc = count;
}
while(in.ready()) {
String input = in.readLine();
if(!input.equals("heartbeat")) {
plugin.getLogger().info(plugin.getLocale().getString("ReceivedInput", socket.getInetAddress().getHostName(), String.valueOf(socket.getPort()), input));
plugin.getLogger().info(plugin.getLocale().getString("ReceivedInput", true, socket.getInetAddress().getHostName(), String.valueOf(socket.getPort()), input));
String[] data = input.split(plugin.spacer);
if(data[0].equals("console")) {
String command = data[2].replaceAll("\\+", " ");
plugin.getLogger().info(plugin.getLocale().getString("RanCommand", command));
plugin.getLogger().info(plugin.getLocale().getString("RanCommand", true, command));
Sponge.server().scheduler().executor(plugin.getContainer()).execute(() -> {
try {
Sponge.server().commandManager().process(Sponge.systemSubject(), command);
Expand Down Expand Up @@ -106,26 +106,26 @@ public void connect(Boolean sleep) {
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.println(name);
if(in.readLine().equals("n")) {
plugin.getLogger().error(plugin.getLocale().getString("NameError", name));
plugin.getLogger().error(plugin.getLocale().getString("NameError", true, name));
socket.close();
return;
}
out.println(pass);
if(in.readLine().equals("n")) {
plugin.getLogger().error(plugin.getLocale().getString("InvalidPassword"));
plugin.getLogger().error(plugin.getLocale().getString("InvalidPassword", true));
socket.close();
return;
}
out.println(version);
if(in.readLine().equals("n")) {
plugin.getLogger().error(plugin.getLocale().getString("VersionError", version, in.readLine()));
plugin.getLogger().error(plugin.getLocale().getString("VersionError", true, version, in.readLine()));
socket.close();
return;
}
connected = true;
plugin.getLogger().info((plugin.getLocale().getString("ConnectInfo", ip.getHostName(), String.valueOf(port), name)));
plugin.getLogger().info((plugin.getLocale().getString("ConnectInfo", true, ip.getHostName(), String.valueOf(port), name)));
} catch(IOException e) {
plugin.getLogger().error(plugin.getLocale().getString("NoConnect"));
plugin.getLogger().error(plugin.getLocale().getString("NoConnect", true));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ public CommandResult process(CommandCause cause, Mutable arguments) throws Comma
String[] args = Stream.of(arguments.input().split(" ")).filter(string -> (!string.equals(""))).toArray(String[]::new);
if(args.length >= 0) {
if(args.length <= 2) {
cause.audience().sendMessage(plugin.getLocale().getString("HelpAuthors"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpAuthors"));
if(args.length >= 1) {
if(args[0].equalsIgnoreCase("console")){
cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands9", "sync"));
cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands8", "sync"));
cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands7", "sync"));
cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands6", "sync"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands9", "sync"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands8", "sync"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands7", "sync"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands6", "sync"));
} else if(args[0].equalsIgnoreCase("player")) {
cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands5", "sync"));
cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands4", "sync"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands5", "sync"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands4", "sync"));
} else {
cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands10", "sync"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands10", "sync"));
}
} else {
cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands3", "sync"));
cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands2", "sync"));
cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands1"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands3", "sync"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands2", "sync"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands1"));
}
cause.audience().sendMessage(plugin.getLocale().getString("HelpLink"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpLink"));
} else if(args.length >= 3) {
if(args[0].equalsIgnoreCase("console") || args[0].equalsIgnoreCase("player")) {
String[] newArgs = new String[3];
Expand All @@ -73,7 +73,7 @@ public CommandResult process(CommandCause cause, Mutable arguments) throws Comma
makeData(newArgs, true, cause);
}
} else {
cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands9"));
cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands9"));
}
}
}
Expand Down Expand Up @@ -115,20 +115,20 @@ public Component usage(CommandCause cause) {

private void makeData(String[] args, Boolean single, CommandCause cause) {
String data;
Component message;
String message;
if(args[0].equalsIgnoreCase("console")) {
if(args[1].equalsIgnoreCase("all")) {
message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), serialize(plugin.getLocale().getString("SyncConsoleAll")));
message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), plugin.getLocale().getString("SyncConsoleAll"));
} else {
message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), serialize(plugin.getLocale().getString("SyncConsole", args[1])));
message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), plugin.getLocale().getString("SyncConsole", args[1]));
}
} else if(args[0].equalsIgnoreCase("bungee") || args[0].equalsIgnoreCase("proxy")) {
message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), serialize(plugin.getLocale().getString("SyncConsole", args[1])));
message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), plugin.getLocale().getString("SyncConsole", args[1]));
} else {
if(args[1].equalsIgnoreCase("all")) {
message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), serialize(plugin.getLocale().getString("SyncPlayerAll")));
message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), plugin.getLocale().getString("SyncPlayerAll"));
} else {
message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), serialize(plugin.getLocale().getString("SyncPlayer", args[1])));
message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), plugin.getLocale().getString("SyncPlayer", args[1]));
}
}
if(single) {
Expand All @@ -137,11 +137,11 @@ private void makeData(String[] args, Boolean single, CommandCause cause) {
data = args[0].toLowerCase() + plugin.spacer + args[1].toLowerCase() + plugin.spacer + args[2];
}
plugin.oq.add(data);
cause.audience().sendMessage(message);
cause.audience().sendMessage(deserialize(message));
}

private String serialize(Component component) {
return LegacyComponentSerializer.legacyAmpersand().serialize(component);
private Component deserialize(String string) {
return LegacyComponentSerializer.legacyAmpersand().deserialize(string);
}

}
71 changes: 62 additions & 9 deletions src/main/java/sawfowl/commandsyncclient/sponge/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Properties;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;

/**
Expand Down Expand Up @@ -74,8 +75,8 @@ public void init() throws IOException {
* @param key - message key
* @return message, otherwise null
*/
public Component getString(final String key) {
return getString(key, false, "");
public Component getComponent(final String key) {
return getComponent(key, false, "");
}

/**
Expand All @@ -87,7 +88,20 @@ public Component getString(final String key) {
* @param args - arguments of the message. Only String format.
* @return message, otherwise null
*/
public Component getString(final String key, final String... args) {
public Component getComponent(final String key, final String... args) {
return this.getComponent(key, false, args);
}

/**
* Receiving a message with arguments from the configuration <br>
* Example message: "There is {0} players: {1}." <br>
* Example call: getString("key", "2", "You, Me");
*
* @param key - message key
* @param args - arguments of the message. Only String format.
* @return message, otherwise null
*/
public String getString(final String key, final String... args) {
return this.getString(key, false, args);
}

Expand All @@ -100,8 +114,48 @@ public Component getString(final String key, final String... args) {
* @param removeColors if true, then the colors will be removed
* @return message, otherwise null
*/
public Component getString(final String key, final boolean removeColors) {
return this.getString(key, removeColors, "");
public Component getComponent(final String key, final boolean removeColors) {
return this.getComponent(key, removeColors, "");
}

/**
* Receiving a message from a configuration with the ability to filter color <br>
* Example message: "\u00a76There is so many players." <br>
* Example call: getString("key", false);
*
* @param key - message key
* @param removeColors if true, then the colors will be removed
* @return message, otherwise null
*/
public String getString(final String key, final boolean removeColors) {
return getString(key, removeColors, "");
}

/**
* Receiving a message with arguments from a configuration with the ability to filter the color <br>
* Example message: "\u00a76There is \u00a7c{0} \u00a76players:\u00a7c {1}." <br>
* Example call: getString("key", false, "2", "You, Me"); <br>
*
* @param key - message key
* @param removeColors - if true, then the colors will be removed
* @param args - arguments of the message. Only String format.
* @return message, otherwise null
*/
public String getString(final String key, final boolean removeColors, final String... args) {
String out = this.locale.getProperty(key);
if (out == null) {
return LegacyComponentSerializer.legacyAmpersand().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize("&4Key \"" + key + "\" not found!&r"));
}
MessageFormat mf = this.messageCache.get(out);
if (mf == null) {
mf = new MessageFormat(out);
this.messageCache.put(out, mf);
}
out = mf.format(args);
if (removeColors) {
return LegacyComponentSerializer.legacyAmpersand().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(out).style(Style.style().build()).style(Style.style().build()));
}
return out;
}

/**
Expand All @@ -114,7 +168,7 @@ public Component getString(final String key, final boolean removeColors) {
* @param args - arguments of the message. Only String format.
* @return message, otherwise null
*/
public Component getString(final String key, final boolean removeColors, final String... args) {
public Component getComponent(final String key, final boolean removeColors, final String... args) {
String out = this.locale.getProperty(key);
if (out == null) {
return LegacyComponentSerializer.legacyAmpersand().deserialize("&4Key \"" + key + "\" not found!&r");
Expand All @@ -125,11 +179,10 @@ public Component getString(final String key, final boolean removeColors, final S
this.messageCache.put(out, mf);
}
out = mf.format(args);
Component component = LegacyComponentSerializer.legacyAmpersand().deserialize(out);
if (removeColors) {
component.decorations().clear();
return LegacyComponentSerializer.legacyAmpersand().deserialize(out).style(Style.style().build()).style(Style.style().build());
}
return component;
return LegacyComponentSerializer.legacyAmpersand().deserialize(out);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class PluginInfo {

public static final String NAME = "CommandSync";

public static final String VERSION = "2.8.0";
public static final String VERSION = "2.8.1";

public static final String DESCRIPTION = "Synchronize commands across servers.";

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/sponge_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"license": "GNU",
"global": {
"version": "2.8.0-API8",
"version": "2.8.1-API8",
"links": {
"homepage": "https://ore.spongepowered.org/Semenkovsky_Ivan/CommandSync",
"source": "https://github.com/SawFowl/CommandSync",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CommandSync
main: sawfowl.commandsyncserver.bungee.CSS
version: 2.8.0
version: 2.8.1
author: YoFuzzy3
description: Synchronize commands across servers.
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CommandSync
main: sawfowl.commandsyncclient.bukkit.CSC
version: 2.8.0
version: 2.8.1
author: YoFuzzy3
description: Synchronize commands across servers.

Expand Down

0 comments on commit 07f8488

Please sign in to comment.