Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ High performance Random Teleport plugin with 1v1 matchmaking, Redis cross-server
|---|---|
| `/rtp` | Opens solo teleport menu |
| `/rtp <world>` | Direct teleport to specified world |
| `/rtp cancel` | Cancel an active solo teleport countdown |
| `/rtp <player> <world>` | Admin: teleport another player (requires `lexonrtp.admin`) |
| `/rtpqueue` | Opens 1v1 matchmaking menu |
| `/rtpqueue <world>` | Join queue for specified world |
| `/rtpqueue leave` | Leave the queue |
| `/lexonrtp reload` | Admin: reload config & messages without restart (requires `lexonrtp.admin`) |

## Permissions

| Permission | Default | Description |
|---|---|---|
| `lexonrtp.use` | `true` | Use RTP commands |
| `lexonrtp.admin` | `op` | Reload plugin and RTP other players |
| `lexonrtp.cooldown.bypass` | `op` | Bypass cooldown |

## Installation
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/lexon/rtp/LexonRTP.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lexon.rtp;

import com.lexon.rtp.command.LexonRtpCommand;
import com.lexon.rtp.command.RtpCommand;
import com.lexon.rtp.command.RtpQueueCommand;
import com.lexon.rtp.config.ConfigManager;
Expand Down Expand Up @@ -42,6 +43,7 @@ public void onEnable() {
this.queueManager.start();
register("rtp", new RtpCommand(this));
register("rtpqueue", new RtpQueueCommand(this));
register("lexonrtp", new LexonRtpCommand(this));
getServer().getPluginManager().registerEvents(new MenuListener(this), this);
getServer().getPluginManager().registerEvents(new CrossServerListener(this), this);
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
Expand Down Expand Up @@ -100,4 +102,13 @@ public QueueManager queue() {
public RtpService rtpService() {
return rtpService;
}

public void reloadPlugin() {
configManager.load();
messageManager.load();
this.locationFinder = new LocationFinder(this);
queueManager.start();
redisManager.reload();
getLogger().info("LexonRTP reloaded.");
}
}
29 changes: 28 additions & 1 deletion src/main/java/com/lexon/rtp/RtpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.io.ByteStreams;
import com.lexon.rtp.config.WorldSettings;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;
Expand All @@ -16,23 +17,31 @@ public RtpService(LexonRTP plugin) {
}

public void request(Player player, String worldKey, boolean matchmaking) {
request(player, worldKey, matchmaking, null);
}

public void request(Player player, String worldKey, boolean matchmaking, CommandSender requester) {
WorldSettings target = plugin.config().getWorld(worldKey);
if (target == null) {
plugin.messages().send(player, "invalid-world");
feedback(requester, player, "invalid-world");
return;
}
if (!target.isEnabled()) {
plugin.messages().send(player, "world-disabled");
feedback(requester, player, "world-disabled");
return;
}
String targetServer = target.getTargetServer();
if (targetServer != null && !targetServer.isEmpty()) {
if (!plugin.redis().isConnected()) {
plugin.messages().send(player, "cross-server-unavailable");
feedback(requester, player, "cross-server-unavailable");
return;
}
plugin.redis().savePendingRtp(player.getUniqueId(), worldKey, matchmaking);
plugin.messages().send(player, "rtp-queued");
feedback(requester, player, "rtp-queued");
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(targetServer);
Expand All @@ -41,29 +50,37 @@ public void request(Player player, String worldKey, boolean matchmaking) {
}
if (Bukkit.getWorld(target.getWorldName()) == null) {
plugin.messages().send(player, "world-not-found");
feedback(requester, player, "world-not-found");
return;
}
if (matchmaking && !plugin.config().isQueueEnabled()) {
plugin.messages().send(player, "queue-disabled");
feedback(requester, player, "queue-disabled");
return;
}
if (plugin.queue().isQueued(player.getUniqueId())) {
sendQueueAlready(player);
feedback(requester, player, "queue-already",
"%queue%", String.valueOf(plugin.queue().positionOf(player.getUniqueId())));
return;
}
if (!player.hasPermission("lexonrtp.cooldown.bypass")) {
long remaining = plugin.redis().getRemaining(player.getUniqueId());
if (remaining > 0) {
plugin.messages().send(player, "cooldown-active", "%time%", String.valueOf(remaining));
feedback(requester, player, "cooldown-active", "%time%", String.valueOf(remaining));
return;
}
}
if (!plugin.queue().enqueue(player, target, matchmaking)) {
if (!plugin.queue().enqueue(player, target, matchmaking, requester)) {
sendQueueAlready(player);
feedback(requester, player, "queue-already",
"%queue%", String.valueOf(plugin.queue().positionOf(player.getUniqueId())));
return;
}
if (!matchmaking) {
plugin.messages().send(player, "rtp-queued");
feedback(requester, player, "rtp-queued");
return;
}
int count = plugin.queue().matchSize(target.getKey());
Expand All @@ -72,11 +89,21 @@ public void request(Player player, String worldKey, boolean matchmaking) {
"%count%", String.valueOf(count),
"%required%", String.valueOf(required),
"%queue%", String.valueOf(plugin.queue().positionOf(player.getUniqueId())));
feedback(requester, player, "queue-joined",
"%count%", String.valueOf(count),
"%required%", String.valueOf(required),
"%queue%", String.valueOf(plugin.queue().positionOf(player.getUniqueId())));
if (count < required && plugin.config().isAnnounceWaiting()) {
broadcastWaiting(player, count, required);
}
}

private void feedback(CommandSender requester, Player player, String path, String... replacements) {
if (requester != null && requester != player) {
plugin.messages().send(requester, path, replacements);
}
}

private void sendQueueAlready(Player player) {
plugin.messages().send(player, "queue-already",
"%queue%", String.valueOf(plugin.queue().positionOf(player.getUniqueId())));
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/lexon/rtp/command/BaseRtpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public abstract class BaseRtpCommand implements TabExecutor {
protected final LexonRTP plugin;
Expand All @@ -19,8 +20,7 @@ protected BaseRtpCommand(LexonRTP plugin) {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
plugin.messages().send(sender, "players-only");
return true;
return executeConsole(sender, args);
}
if (!player.hasPermission("lexonrtp.use")) {
plugin.messages().send(player, "no-permission");
Expand All @@ -31,6 +31,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

protected abstract boolean execute(Player player, String[] args);

protected boolean executeConsole(CommandSender sender, String[] args) {
plugin.messages().send(sender, "players-only");
return true;
}

protected List<String> worldKeys(String prefix) {
List<String> matches = new ArrayList<>();
for (String key : plugin.config().getWorlds().keySet()) {
Expand All @@ -43,6 +48,6 @@ protected List<String> worldKeys(String prefix) {

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return args.length == 1 ? worldKeys(args[0].toLowerCase()) : List.of();
return args.length == 1 ? worldKeys(args[0].toLowerCase(Locale.ROOT)) : List.of();
}
}
50 changes: 50 additions & 0 deletions src/main/java/com/lexon/rtp/command/LexonRtpCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.lexon.rtp.command;

import com.lexon.rtp.LexonRTP;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;

import java.util.List;
import java.util.Locale;

public final class LexonRtpCommand implements TabExecutor {
private final LexonRTP plugin;

public LexonRtpCommand(LexonRTP plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!sender.hasPermission("lexonrtp.admin")) {
plugin.messages().send(sender, "no-permission");
return true;
}
if (args.length == 0) {
plugin.messages().sendList(sender, "lexonrtp-help");
return true;
}
if (args[0].equalsIgnoreCase("reload")) {
plugin.reloadPlugin();
plugin.messages().send(sender, "reloaded");
return true;
}
plugin.messages().sendList(sender, "lexonrtp-help");
return true;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (!sender.hasPermission("lexonrtp.admin")) {
return List.of();
}
if (args.length == 1) {
String prefix = args[0].toLowerCase(Locale.ROOT);
if ("reload".startsWith(prefix)) {
return List.of("reload");
}
}
return List.of();
}
}
78 changes: 77 additions & 1 deletion src/main/java/com/lexon/rtp/command/RtpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

import com.lexon.rtp.LexonRTP;
import com.lexon.rtp.gui.RtpMenu;
import com.lexon.rtp.util.Text;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;
import java.util.Locale;

public final class RtpCommand extends BaseRtpCommand {
public RtpCommand(LexonRTP plugin) {
super(plugin);
Expand All @@ -15,7 +22,76 @@ protected boolean execute(Player player, String[] args) {
new RtpMenu(plugin).open(player);
return true;
}
plugin.rtpService().request(player, args[0].toLowerCase(), false);
if (args.length == 1 && args[0].equalsIgnoreCase("cancel")) {
if (plugin.queue().cancelSolo(player.getUniqueId())) {
Text.resetTitle(player);
plugin.messages().send(player, "rtp-cancelled");
} else {
plugin.messages().send(player, "rtp-cancel-none");
}
return true;
}
if (args.length > 2) {
plugin.messages().send(player, "rtp-usage");
return true;
}
if (args.length == 2) {
if (!player.hasPermission("lexonrtp.admin")) {
plugin.messages().send(player, "no-permission");
return true;
}
Player target = Bukkit.getPlayerExact(args[0]);
if (target == null) {
plugin.messages().send(player, "player-not-found");
return true;
}
plugin.rtpService().request(target, args[1].toLowerCase(Locale.ROOT), false, player);
return true;
}
plugin.rtpService().request(player, args[0].toLowerCase(Locale.ROOT), false);
return true;
}

@Override
protected boolean executeConsole(CommandSender sender, String[] args) {
if (args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("cancel"))) {
plugin.messages().send(sender, "rtp-usage");
return true;
}
if (args.length > 2) {
plugin.messages().send(sender, "rtp-usage");
return true;
}
if (args.length == 2) {
if (!sender.hasPermission("lexonrtp.admin")) {
plugin.messages().send(sender, "no-permission");
return true;
}
Player target = Bukkit.getPlayerExact(args[0]);
if (target == null) {
plugin.messages().send(sender, "player-not-found");
return true;
}
plugin.rtpService().request(target, args[1].toLowerCase(Locale.ROOT), false, sender);
return true;
}
plugin.messages().send(sender, "players-only");
return true;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (args.length == 1) {
String prefix = args[0].toLowerCase(Locale.ROOT);
List<String> matches = worldKeys(prefix);
if (!matches.contains("cancel") && "cancel".startsWith(prefix)) {
matches.add("cancel");
}
return matches;
}
if (args.length == 2 && sender.hasPermission("lexonrtp.admin")) {
return worldKeys(args[1].toLowerCase(Locale.ROOT));
}
return List.of();
}
}
7 changes: 4 additions & 3 deletions src/main/java/com/lexon/rtp/command/RtpQueueCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.entity.Player;

import java.util.List;
import java.util.Locale;

public final class RtpQueueCommand extends BaseRtpCommand {
public RtpQueueCommand(LexonRTP plugin) {
Expand All @@ -28,16 +29,16 @@ protected boolean execute(Player player, String[] args) {
}
return true;
}
plugin.rtpService().request(player, args[0].toLowerCase(), true);
plugin.rtpService().request(player, args[0].toLowerCase(Locale.ROOT), true);
return true;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (args.length == 1) {
String prefix = args[0].toLowerCase();
String prefix = args[0].toLowerCase(Locale.ROOT);
List<String> matches = worldKeys(prefix);
if ("leave".startsWith(prefix)) {
if (!matches.contains("leave") && "leave".startsWith(prefix)) {
matches.add("leave");
}
return matches;
Expand Down
Loading