-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1f08845
Showing
16 changed files
with
764 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target | ||
*.iml | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.alerium</groupId> | ||
<artifactId>Chocolate</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>8</source> | ||
<target>8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<createDependencyReducedPom>false</createDependencyReducedPom> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>velocity</id> | ||
<url>https://repo.velocitypowered.com/snapshots/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.velocitypowered</groupId> | ||
<artifactId>velocity-api</artifactId> | ||
<version>1.0.8-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.12</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>redis.clients</groupId> | ||
<artifactId>jedis</artifactId> | ||
<version>3.2.0</version> | ||
<type>jar</type> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>me.minidigger</groupId> | ||
<artifactId>minimessage-text</artifactId> | ||
<version>2.0.4</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.6</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package io.alerium.chocolate; | ||
|
||
import com.velocitypowered.api.event.Subscribe; | ||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; | ||
import com.velocitypowered.api.plugin.Plugin; | ||
import com.velocitypowered.api.plugin.annotation.DataDirectory; | ||
import com.velocitypowered.api.proxy.ProxyServer; | ||
import io.alerium.chocolate.commands.*; | ||
import io.alerium.chocolate.listeners.PlayerListener; | ||
import io.alerium.chocolate.redis.CacheManager; | ||
import io.alerium.chocolate.redis.RedisManager; | ||
import io.alerium.chocolate.utils.Config; | ||
import lombok.Getter; | ||
|
||
import javax.inject.Inject; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
@Plugin(id = "chocolate", name = "Chocolate", version = "1.0.0", authors = {"xQuickGlare"}) | ||
public class ChocolatePlugin { | ||
|
||
@Getter private final Logger logger; | ||
@Getter private final ProxyServer server; | ||
@Getter private final Path folderPath; | ||
|
||
@Getter private Config config; | ||
|
||
@Getter private RedisManager redisManager; | ||
@Getter private CacheManager cacheManager; | ||
|
||
@Inject | ||
public ChocolatePlugin(Logger logger, ProxyServer server, @DataDirectory Path folderPath) { | ||
this.logger = logger; | ||
this.server = server; | ||
this.folderPath = folderPath; | ||
} | ||
|
||
@Subscribe | ||
public void onProxyInitialize(ProxyInitializeEvent event) { | ||
if (!registerConfigs()) | ||
return; | ||
|
||
registerInstances(); | ||
registerListeners(); | ||
registerCommands(); | ||
} | ||
|
||
private boolean registerConfigs() { | ||
try { | ||
config = new Config(this, folderPath, "config"); | ||
return true; | ||
} catch (IOException e) { | ||
logger.log(Level.SEVERE, "An error occurred while loading config", e); | ||
return false; | ||
} | ||
} | ||
|
||
private void registerInstances() { | ||
redisManager = new RedisManager(this); | ||
redisManager.enable(); | ||
|
||
cacheManager = new CacheManager(this); | ||
} | ||
|
||
private void registerListeners() { | ||
server.getEventManager().register(new PlayerListener(this), this); | ||
} | ||
|
||
private void registerCommands() { | ||
server.getCommandManager().register(new FindCommand(this), "find"); | ||
server.getCommandManager().register(new GListCommand(this), "glist"); | ||
server.getCommandManager().register(new IPCommand(this), "ip"); | ||
server.getCommandManager().register(new LastSeenCommand(this), "lastseen"); | ||
server.getCommandManager().register(new ServerIDCommand(this), "serverid"); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/io/alerium/chocolate/commands/FindCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.alerium.chocolate.commands; | ||
|
||
import com.velocitypowered.api.command.Command; | ||
import com.velocitypowered.api.command.CommandSource; | ||
import io.alerium.chocolate.ChocolatePlugin; | ||
import io.alerium.chocolate.objects.PlayerData; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class FindCommand implements Command { | ||
|
||
private final ChocolatePlugin plugin; | ||
|
||
@Override | ||
public void execute(CommandSource source, String[] args) { | ||
if (args.length == 0) { | ||
source.sendMessage(plugin.getConfig().getMessage("find_usage")); | ||
return; | ||
} | ||
|
||
PlayerData data = plugin.getCacheManager().getPlayerData(args[0]); | ||
if (data == null) { | ||
source.sendMessage(plugin.getConfig().getMessage("find_player_not_found")); | ||
return; | ||
} | ||
|
||
if (data.getServer() == null) { | ||
source.sendMessage(plugin.getConfig().getMessage("find_player_not_found")); | ||
return; | ||
} | ||
|
||
source.sendMessage(plugin.getConfig().getMessage("find_found", "server", data.getServer(), "proxy", data.getProxy())); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/io/alerium/chocolate/commands/GListCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.alerium.chocolate.commands; | ||
|
||
import com.velocitypowered.api.command.Command; | ||
import com.velocitypowered.api.command.CommandSource; | ||
import io.alerium.chocolate.ChocolatePlugin; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.Set; | ||
|
||
@RequiredArgsConstructor | ||
public class GListCommand implements Command { | ||
|
||
private final ChocolatePlugin plugin; | ||
|
||
@Override | ||
public void execute(CommandSource source, String[] args) { | ||
if (args.length == 0) { | ||
source.sendMessage(plugin.getConfig().getMessage("glist_global", "players", Integer.toString(plugin.getRedisManager().getOnlinePlayers()))); | ||
return; | ||
} | ||
|
||
String proxy = args[0]; | ||
Set<String> players = plugin.getCacheManager().getOnlinePlayers(proxy); | ||
if (players == null) { | ||
source.sendMessage(plugin.getConfig().getMessage("glist_no_proxy")); | ||
return; | ||
} | ||
|
||
source.sendMessage(plugin.getConfig().getMessage("glist_proxy", "proxy", proxy, "players", Integer.toString(players.size()))); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/io/alerium/chocolate/commands/IPCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.alerium.chocolate.commands; | ||
|
||
import com.velocitypowered.api.command.Command; | ||
import com.velocitypowered.api.command.CommandSource; | ||
import io.alerium.chocolate.ChocolatePlugin; | ||
import io.alerium.chocolate.objects.PlayerData; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class IPCommand implements Command { | ||
|
||
private final ChocolatePlugin plugin; | ||
|
||
@Override | ||
public void execute(CommandSource source, String[] args) { | ||
if (args.length == 0) { | ||
source.sendMessage(plugin.getConfig().getMessage("ip_usage")); | ||
return; | ||
} | ||
|
||
PlayerData data = plugin.getCacheManager().getPlayerData(args[0]); | ||
if (data == null) { | ||
source.sendMessage(plugin.getConfig().getMessage("ip_player_not_found")); | ||
return; | ||
} | ||
|
||
if (data.getIp() == null) { | ||
source.sendMessage(plugin.getConfig().getMessage("ip_player_not_online")); | ||
return; | ||
} | ||
|
||
source.sendMessage(plugin.getConfig().getMessage("ip_data", "ip", data.getIp())); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/io/alerium/chocolate/commands/LastSeenCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.alerium.chocolate.commands; | ||
|
||
import com.velocitypowered.api.command.Command; | ||
import com.velocitypowered.api.command.CommandSource; | ||
import io.alerium.chocolate.ChocolatePlugin; | ||
import io.alerium.chocolate.objects.PlayerData; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
@RequiredArgsConstructor | ||
public class LastSeenCommand implements Command { | ||
|
||
private final ChocolatePlugin plugin; | ||
|
||
@Override | ||
public void execute(CommandSource source, String[] args) { | ||
if (args.length == 0) { | ||
source.sendMessage(plugin.getConfig().getMessage("last_seen_usage")); | ||
return; | ||
} | ||
|
||
PlayerData data = plugin.getCacheManager().getPlayerData(args[0]); | ||
if (data == null) { | ||
source.sendMessage(plugin.getConfig().getMessage("last_seen_player_not_found")); | ||
return; | ||
} | ||
|
||
if (data.getLastOnline() == 0) { | ||
source.sendMessage(plugin.getConfig().getMessage("last_seen_already_online")); | ||
return; | ||
} | ||
|
||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | ||
Date date = new Date(data.getLastOnline()); | ||
source.sendMessage(plugin.getConfig().getMessage("last_seen_time", "time", format.format(date))); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/io/alerium/chocolate/commands/ServerIDCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.alerium.chocolate.commands; | ||
|
||
import com.velocitypowered.api.command.Command; | ||
import com.velocitypowered.api.command.CommandSource; | ||
import io.alerium.chocolate.ChocolatePlugin; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class ServerIDCommand implements Command { | ||
|
||
private final ChocolatePlugin plugin; | ||
|
||
@Override | ||
public void execute(CommandSource source, String[] strings) { | ||
source.sendMessage(plugin.getConfig().getMessage("server_id", "proxy", plugin.getRedisManager().getProxyName())); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/io/alerium/chocolate/events/PubSubEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.alerium.chocolate.events; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor @Getter | ||
public class PubSubEvent { | ||
|
||
private final String channel; | ||
private final String message; | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/io/alerium/chocolate/listeners/PlayerListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.alerium.chocolate.listeners; | ||
|
||
import com.velocitypowered.api.event.Subscribe; | ||
import com.velocitypowered.api.event.connection.DisconnectEvent; | ||
import com.velocitypowered.api.event.connection.PostLoginEvent; | ||
import com.velocitypowered.api.event.player.ServerConnectedEvent; | ||
import com.velocitypowered.api.event.proxy.ProxyPingEvent; | ||
import com.velocitypowered.api.proxy.Player; | ||
import com.velocitypowered.api.proxy.server.ServerPing; | ||
import io.alerium.chocolate.ChocolatePlugin; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class PlayerListener { | ||
|
||
private final ChocolatePlugin plugin; | ||
|
||
@Subscribe | ||
public void onPlayerJoin(PostLoginEvent event) { | ||
Player player = event.getPlayer(); | ||
plugin.getRedisManager().createPlayer(player.getUniqueId(), player.getUsername(), player.getRemoteAddress().getAddress().getHostAddress()); | ||
} | ||
|
||
@Subscribe | ||
public void onServerConnected(ServerConnectedEvent event) { | ||
Player player = event.getPlayer(); | ||
plugin.getRedisManager().setPlayerServer(player.getUniqueId(), event.getServer().getServerInfo().getName()); | ||
} | ||
|
||
@Subscribe | ||
public void onPlayerQuit(DisconnectEvent event) { | ||
Player player = event.getPlayer(); | ||
plugin.getRedisManager().cleanPlayer(player.getUniqueId()); | ||
} | ||
|
||
@Subscribe | ||
public void onProxyPing(ProxyPingEvent event) { | ||
ServerPing ping = event.getPing(); | ||
|
||
ping.asBuilder().onlinePlayers(plugin.getRedisManager().getOnlinePlayers()); | ||
} | ||
|
||
} |
Oops, something went wrong.