Skip to content

Commit

Permalink
Add ability to set prefix for redis channels
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCodez committed Feb 24, 2024
1 parent 770e3e8 commit c442cd1
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions VotingPlugin/Resources/BungeeSettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Redis:
Port: 6379
Username: ''
Password: ''
# Set a prefix from an entire proxy network if using mutli-proxy setup below
Prefix: ''

# Enables more debug messages for communication between servers
# Use /votingpluginbungee status for testing communication
Expand Down
2 changes: 2 additions & 0 deletions VotingPlugin/Resources/bungeeconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Redis:
Port: 6379
Username: ''
Password: ''
# Set a prefix from an entire proxy network if using mutli-proxy setup below
Prefix: ''

# If false, votes will be checked if user is a valid player that has joined to server
# Works for PLUGINMESSAGING and SOCKETS methods only
Expand Down
8 changes: 5 additions & 3 deletions VotingPlugin/src/com/bencodez/votingplugin/BungeeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ public void sendMessage(String subChannel, String... messageData) {
ArrayList<String> list = new ArrayList<String>();
list.add(subChannel);
list.addAll(ArrayUtils.getInstance().convert(messageData));
redisHandler.sendMessage("VotingPlugin", ArrayUtils.getInstance().convert(list));
redisHandler.sendMessage(plugin.getBungeeSettings().getRedisPrefix() + "VotingPlugin",
ArrayUtils.getInstance().convert(list));
}
}
};
Expand Down Expand Up @@ -626,8 +627,9 @@ public void debug(String message) {
@Override
public void run() {
if (plugin.isEnabled()) {
redisHandler.loadListener(new RedisListener(redisHandler,
"VotingPlugin_" + plugin.getBungeeSettings().getServer()));
redisHandler.loadListener(
new RedisListener(redisHandler, plugin.getBungeeSettings().getRedisPrefix()
+ "VotingPlugin_" + plugin.getBungeeSettings().getServer()));
}
}
});
Expand Down
4 changes: 4 additions & 0 deletions VotingPlugin/src/com/bencodez/votingplugin/bungee/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public String getRedisUsername() {
return getData().getString("Redis.Username", "");
}

public String getRedisPrefix() {
return getData().getString("Redis.Prefix", "");
}

public String getRedisPassword() {
return getData().getString("Redis.Password", "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,8 @@ public void debug(String message) {

@Override
public void run() {
redisHandler.loadListener(new RedisListener(redisHandler, "VotingPlugin"));
redisHandler.loadListener(
new RedisListener(redisHandler, getConfig().getRedisPrefix() + "VotingPlugin"));
}
});

Expand Down Expand Up @@ -1255,7 +1256,8 @@ public void sendRedisMessageServer(String server, String channel, String... mess
ArrayList<String> list = new ArrayList<String>();
list.add(channel);
list.addAll(ArrayUtils.getInstance().convert(messageData));
redisHandler.sendMessage("VotingPlugin_" + server, ArrayUtils.getInstance().convert(list));
redisHandler.sendMessage(getConfig().getRedisPrefix() + "VotingPlugin_" + server,
ArrayUtils.getInstance().convert(list));
}

public void sendPluginMessageServer(String server, String channel, String... messageData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public int getRedisPort() {
public String getRedisUsername() {
return getString(getNode("Redis", "Username"), "");
}

public String getRedisPrefix() {
return getString(getNode("Redis", "Prefix"), "");
}

public String getRedisPassword() {
return getString(getNode("Redis", "Password"), "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,8 @@ public void debug(String message) {
};

server.getScheduler().buildTask(this, () -> {
redisHandler.loadListener(new RedisListener(redisHandler, "VotingPlugin"));
redisHandler.loadListener(
new RedisListener(redisHandler, getConfig().getRedisPrefix() + "VotingPlugin"));
}).schedule();

}
Expand Down Expand Up @@ -1304,7 +1305,8 @@ public void sendRedisMessageServer(RegisteredServer s, String channel, String...
ArrayList<String> list = new ArrayList<String>();
list.add(channel);
list.addAll(ArrayUtils.getInstance().convert(messageData));
redisHandler.sendMessage("VotingPlugin_" + s.getServerInfo().getName(), ArrayUtils.getInstance().convert(list));
redisHandler.sendMessage(getConfig().getRedisPrefix() + "VotingPlugin_" + s.getServerInfo().getName(),
ArrayUtils.getInstance().convert(list));
}

public void sendPluginMessageServer(RegisteredServer s, String channel, String... messageData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class BungeeSettings extends YMLFile {
@Getter
private String RedisUsername = "";

@ConfigDataString(path = "Redis.Prefix")
@Getter
private String RedisPrefix = "";

@ConfigDataString(path = "Redis.Password")
@Getter
private String RedisPassword = "";
Expand Down

0 comments on commit c442cd1

Please sign in to comment.