Skip to content

Commit

Permalink
made M->G and G->M message forwarding switchable
Browse files Browse the repository at this point in the history
  • Loading branch information
MCUmbrella committed Jun 25, 2022
1 parent 730909b commit 84d15a0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
14 changes: 10 additions & 4 deletions src/main/java/vip/floatationdevice/mgbridge/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ConfigManager
static String socksProxyHost = null; // socks proxy settings
static String socksProxyPort = null;
static String toGuildedMessageFormat = "<{PLAYER}> {MESSAGE}"; // messages sent to guilded
static String toMinecraftMessageFormat = "§e<§r<{PLAYER}§e> §r{MESSAGE}"; // messages sent to minecraft
static String toMinecraftMessageFormat = "§e<§r{PLAYER}§e> §r{MESSAGE}"; // messages sent to minecraft
static boolean loadConfig()
{
File cfgFile = new File(instance.getDataFolder(), "config.yml");
Expand All @@ -31,7 +31,7 @@ static boolean loadConfig()
if(!notSet(cfg.getString("socksProxy"))) // is socksProxy field set?
{
String[] socksProxy = cfg.getString("socksProxy").split(":");
if(cfg.getString("socksProxy").equals("default"))
if("default".equalsIgnoreCase(cfg.getString("socksProxy")))
{ // use proxy settings in JVM arguments
socksProxyHost = System.getProperty("socksProxyHost");
socksProxyPort = System.getProperty("socksProxyPort");
Expand All @@ -43,8 +43,14 @@ else if(socksProxy.length == 2 && socksProxy[0].length() > 0 && socksProxy[1].le
}
}
// set message formatter
toGuildedMessageFormat = cfg.getString("toGuildedMessageFormat", toGuildedMessageFormat);
toMinecraftMessageFormat = cfg.getString("toMinecraftMessageFormat", toMinecraftMessageFormat);
if("disabled".equalsIgnoreCase(cfg.getString("toGuildedMessageFormat")))
toGuildedMessageFormat = null;
else
toGuildedMessageFormat = cfg.getString("toGuildedMessageFormat", toGuildedMessageFormat);
if("disabled".equalsIgnoreCase(cfg.getString("toMinecraftMessageFormat")))
toMinecraftMessageFormat = null;
else
toMinecraftMessageFormat = cfg.getString("toMinecraftMessageFormat", toMinecraftMessageFormat);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public void onGuildedMessage(ChatMessageCreatedEvent event)
if(executor.getCommandName().equals(args[1]))
executor.execute(msg, subCommandArgs);
}
else // not a mgb command
{
if(!msg.getContent().startsWith("/") && bindMap.containsKey(msg.getCreatorId())) // guilded user bound?
else // not a mgb command. consider it as normal message
{ // check if G->M forwarding is enabled, the message is not a command, and the message is from a user who is bound to Minecraft
if(toMinecraftMessageFormat != null && !msg.getContent().startsWith("/") && bindMap.containsKey(msg.getCreatorId()))
Bukkit.broadcastMessage(toMinecraftMessageFormat.replace("{PLAYER}", getPlayerName(bindMap.get(msg.getCreatorId()))).replace("{MESSAGE}", msg.getContent()));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/vip/floatationdevice/mgbridge/MGBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ public void onDisable()
@EventHandler(priority = EventPriority.MONITOR)
public void onChat(AsyncPlayerChatEvent event)
{
if(event.isCancelled()) return; // don't forward cancelled events
String message = event.getMessage();
if(!message.startsWith("/"))
if(toGuildedMessageFormat != null && !message.startsWith("/")) // check if M->G forwarding is enabled and the message is not a command
sendGuildedMessage(toGuildedMessageFormat.replace("{PLAYER}", event.getPlayer().getName()).replace("{MESSAGE}", message), null, null, null);
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ channel:
forwardJoinLeaveEvents: true
# Socks proxy address. Enter an address (e.g. "127.0.0.1:1080") to use a proxy, enter "default" to use the default proxy, or leave blank to not use a proxy.
socksProxy:
# The format of the messages from Minecraft to Guilded. You can use the following variables: {PLAYER}, {MESSAGE}
# The format of the chat messages from Minecraft to Guilded. You can use the following variables: {PLAYER}, {MESSAGE}
# You can disable forwarding messages from Minecraft to Guilded by setting this to "disabled"
toGuildedMessageFormat: "<{PLAYER}> {MESSAGE}"
# The format of the messages sent from Guilded server to Minecraft. You can use the following variables: {PLAYER}, {MESSAGE}
toMinecraftMessageFormat: "§e<§r<{PLAYER}§e> §r{MESSAGE}"
# The format of the chat messages sent from Guilded server to Minecraft. You can use the following variables: {PLAYER}, {MESSAGE}
# You can disable forwarding messages from Guilded to Minecraft by setting this to "disabled"
toMinecraftMessageFormat: "§e<§r{PLAYER}§e> §r{MESSAGE}"
# Print the response after forwarding a message to Guilded
debug: false

0 comments on commit 84d15a0

Please sign in to comment.