mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 02:37:34 +02:00
Simplify command handling
This commit is contained in:
@ -97,7 +97,6 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.games647</groupId>
|
<groupId>com.github.games647</groupId>
|
||||||
<artifactId>fastlogin.core</artifactId>
|
<artifactId>fastlogin.core</artifactId>
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--Server API-->
|
<!--Server API-->
|
||||||
|
@ -9,7 +9,6 @@ import com.github.games647.fastlogin.bukkit.listener.protocollib.SkinApplyListen
|
|||||||
import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener;
|
import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener;
|
||||||
import com.github.games647.fastlogin.bukkit.tasks.DelayedAuthHook;
|
import com.github.games647.fastlogin.bukkit.tasks.DelayedAuthHook;
|
||||||
import com.github.games647.fastlogin.core.CommonUtil;
|
import com.github.games647.fastlogin.core.CommonUtil;
|
||||||
import com.github.games647.fastlogin.core.messages.ChangePremiumMessage;
|
|
||||||
import com.github.games647.fastlogin.core.messages.ChannelMessage;
|
import com.github.games647.fastlogin.core.messages.ChannelMessage;
|
||||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||||
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
|
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
|
||||||
@ -17,7 +16,6 @@ import com.google.common.io.ByteArrayDataOutput;
|
|||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -114,23 +112,6 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
|
|||||||
return core;
|
return core;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendBungeeActivateMessage(CommandSender invoker, String target, boolean activate) {
|
|
||||||
if (invoker instanceof PluginMessageRecipient) {
|
|
||||||
ChannelMessage message = new ChangePremiumMessage(target, activate, true);
|
|
||||||
sendPluginMessage((PluginMessageRecipient) invoker, message);
|
|
||||||
} else {
|
|
||||||
Optional<? extends Player> optPlayer = getServer().getOnlinePlayers().stream().findFirst();
|
|
||||||
if (!optPlayer.isPresent()) {
|
|
||||||
logger.info("No player online to send a plugin message to the proxy");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player sender = optPlayer.get();
|
|
||||||
ChannelMessage message = new ChangePremiumMessage(target, activate, false);
|
|
||||||
sendPluginMessage(sender, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a thread-safe map about players which are connecting to the server are being checked to be premium (paid
|
* Gets a thread-safe map about players which are connecting to the server are being checked to be premium (paid
|
||||||
* account)
|
* account)
|
||||||
@ -141,7 +122,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
|
|||||||
return loginSession;
|
return loginSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBungeeCord() {
|
public boolean isBungeeEnabled() {
|
||||||
return bungeeCord;
|
return bungeeCord;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,47 +5,18 @@ import com.github.games647.fastlogin.core.StoredProfile;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class CrackedCommand implements CommandExecutor {
|
public class CrackedCommand extends ToggleCommand {
|
||||||
|
|
||||||
private final FastLoginBukkit plugin;
|
|
||||||
|
|
||||||
public CrackedCommand(FastLoginBukkit plugin) {
|
public CrackedCommand(FastLoginBukkit plugin) {
|
||||||
this.plugin = plugin;
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
if (!(sender instanceof Player)) {
|
onCrackedSelf(sender, command, args);
|
||||||
//console or command block
|
|
||||||
sender.sendMessage(plugin.getCore().getMessage("no-console"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plugin.isBungeeCord()) {
|
|
||||||
plugin.sendBungeeActivateMessage(sender, sender.getName(), false);
|
|
||||||
plugin.getCore().sendLocaleMessage("wait-on-proxy", sender);
|
|
||||||
} else {
|
|
||||||
//todo: load async if
|
|
||||||
StoredProfile profile = plugin.getCore().getStorage().loadProfile(sender.getName());
|
|
||||||
if (profile.isPremium()) {
|
|
||||||
plugin.getCore().sendLocaleMessage("remove-premium", sender);
|
|
||||||
|
|
||||||
profile.setPremium(false);
|
|
||||||
profile.setId(null);
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
plugin.getCore().getStorage().save(profile);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
plugin.getCore().sendLocaleMessage("not-premium", sender);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
onCrackedOther(sender, command, args);
|
onCrackedOther(sender, command, args);
|
||||||
}
|
}
|
||||||
@ -53,34 +24,65 @@ public class CrackedCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onCrackedOther(CommandSender sender, Command command, String[] args) {
|
private void onCrackedSelf(CommandSender sender, Command cmd, String[] args) {
|
||||||
if (!sender.hasPermission(command.getPermission() + ".other")) {
|
if (isConsole(sender)) {
|
||||||
plugin.getCore().sendLocaleMessage("no-permission", sender);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.isBungeeCord()) {
|
if (forwardCrackedCommand(sender, sender.getName())) {
|
||||||
plugin.sendBungeeActivateMessage(sender, args[0], false);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.isBungeeEnabled()) {
|
||||||
|
sendBungeeActivateMessage(sender, sender.getName(), false);
|
||||||
plugin.getCore().sendLocaleMessage("wait-on-proxy", sender);
|
plugin.getCore().sendLocaleMessage("wait-on-proxy", sender);
|
||||||
} else {
|
} else {
|
||||||
//todo: load async
|
//todo: load async if
|
||||||
StoredProfile profile = plugin.getCore().getStorage().loadProfile(args[0]);
|
StoredProfile profile = plugin.getCore().getStorage().loadProfile(sender.getName());
|
||||||
if (profile == null) {
|
if (profile.isPremium()) {
|
||||||
sender.sendMessage("Error occurred");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//existing player is already cracked
|
|
||||||
if (profile.isSaved() && !profile.isPremium()) {
|
|
||||||
plugin.getCore().sendLocaleMessage("not-premium-other", sender);
|
|
||||||
} else {
|
|
||||||
plugin.getCore().sendLocaleMessage("remove-premium", sender);
|
plugin.getCore().sendLocaleMessage("remove-premium", sender);
|
||||||
|
|
||||||
profile.setPremium(false);
|
profile.setPremium(false);
|
||||||
|
profile.setId(null);
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
plugin.getCore().getStorage().save(profile);
|
plugin.getCore().getStorage().save(profile);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
plugin.getCore().sendLocaleMessage("not-premium", sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onCrackedOther(CommandSender sender, Command command, String[] args) {
|
||||||
|
if (!hasOtherPermission(sender, command)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (forwardCrackedCommand(sender, args[0])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//todo: load async
|
||||||
|
StoredProfile profile = plugin.getCore().getStorage().loadProfile(args[0]);
|
||||||
|
if (profile == null) {
|
||||||
|
sender.sendMessage("Error occurred");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//existing player is already cracked
|
||||||
|
if (profile.isSaved() && !profile.isPremium()) {
|
||||||
|
plugin.getCore().sendLocaleMessage("not-premium-other", sender);
|
||||||
|
} else {
|
||||||
|
plugin.getCore().sendLocaleMessage("remove-premium", sender);
|
||||||
|
|
||||||
|
profile.setPremium(false);
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
plugin.getCore().getStorage().save(profile);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean forwardCrackedCommand(CommandSender sender, String target) {
|
||||||
|
return forwardBungeeCommand(sender, target, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -16,52 +15,16 @@ import org.bukkit.entity.Player;
|
|||||||
* the user has access to it's account. So we can make sure that not another
|
* the user has access to it's account. So we can make sure that not another
|
||||||
* person with a paid account and the same username can steal his account.
|
* person with a paid account and the same username can steal his account.
|
||||||
*/
|
*/
|
||||||
public class PremiumCommand implements CommandExecutor {
|
public class PremiumCommand extends ToggleCommand {
|
||||||
|
|
||||||
private final FastLoginBukkit plugin;
|
|
||||||
|
|
||||||
public PremiumCommand(FastLoginBukkit plugin) {
|
public PremiumCommand(FastLoginBukkit plugin) {
|
||||||
this.plugin = plugin;
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
if (!(sender instanceof Player)) {
|
onPremiumSelf(sender, command, args);
|
||||||
//console or command block
|
|
||||||
plugin.getCore().sendLocaleMessage("no-console", sender);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plugin.isBungeeCord()) {
|
|
||||||
plugin.sendBungeeActivateMessage(sender, sender.getName(), true);
|
|
||||||
plugin.getCore().sendLocaleMessage("wait-on-proxy", sender);
|
|
||||||
} else {
|
|
||||||
UUID id = ((Player) sender).getUniqueId();
|
|
||||||
if (plugin.getConfig().getBoolean("premium-warning")
|
|
||||||
&& !plugin.getCore().getPendingConfirms().contains(id)) {
|
|
||||||
sender.sendMessage(plugin.getCore().getMessage("premium-warning"));
|
|
||||||
plugin.getCore().getPendingConfirms().add(id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.getCore().getPendingConfirms().remove(id);
|
|
||||||
//todo: load async
|
|
||||||
StoredProfile profile = plugin.getCore().getStorage().loadProfile(sender.getName());
|
|
||||||
if (profile.isPremium()) {
|
|
||||||
plugin.getCore().sendLocaleMessage("already-exists", sender);
|
|
||||||
} else {
|
|
||||||
//todo: resolve uuid
|
|
||||||
profile.setPremium(true);
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
plugin.getCore().getStorage().save(profile);
|
|
||||||
});
|
|
||||||
|
|
||||||
plugin.getCore().sendLocaleMessage("add-premium", sender);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
onPremiumOther(sender, command, args);
|
onPremiumOther(sender, command, args);
|
||||||
}
|
}
|
||||||
@ -69,25 +32,27 @@ public class PremiumCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPremiumOther(CommandSender sender, Command command, String[] args) {
|
private void onPremiumSelf(CommandSender sender, Command cmd, String[] args) {
|
||||||
if (!sender.hasPermission(command.getPermission() + ".other")) {
|
if (isConsole(sender)) {
|
||||||
plugin.getCore().sendLocaleMessage("no-permission", sender);
|
return;
|
||||||
return ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.isBungeeCord()) {
|
if (forwardPremiumCommand(sender, sender.getName())) {
|
||||||
plugin.sendBungeeActivateMessage(sender, args[0], true);
|
return;
|
||||||
plugin.getCore().sendLocaleMessage("wait-on-proxy", sender);
|
}
|
||||||
} else {
|
|
||||||
//todo: load async
|
UUID id = ((Player) sender).getUniqueId();
|
||||||
StoredProfile profile = plugin.getCore().getStorage().loadProfile(args[0]);
|
if (plugin.getConfig().getBoolean("premium-warning") && !plugin.getCore().getPendingConfirms().contains(id)) {
|
||||||
if (profile == null) {
|
sender.sendMessage(plugin.getCore().getMessage("premium-warning"));
|
||||||
plugin.getCore().sendLocaleMessage("player-unknown", sender);
|
plugin.getCore().getPendingConfirms().add(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin.getCore().getPendingConfirms().remove(id);
|
||||||
|
//todo: load async
|
||||||
|
StoredProfile profile = plugin.getCore().getStorage().loadProfile(sender.getName());
|
||||||
if (profile.isPremium()) {
|
if (profile.isPremium()) {
|
||||||
plugin.getCore().sendLocaleMessage("already-exists-other", sender);
|
plugin.getCore().sendLocaleMessage("already-exists", sender);
|
||||||
} else {
|
} else {
|
||||||
//todo: resolve uuid
|
//todo: resolve uuid
|
||||||
profile.setPremium(true);
|
profile.setPremium(true);
|
||||||
@ -95,8 +60,40 @@ public class PremiumCommand implements CommandExecutor {
|
|||||||
plugin.getCore().getStorage().save(profile);
|
plugin.getCore().getStorage().save(profile);
|
||||||
});
|
});
|
||||||
|
|
||||||
plugin.getCore().sendLocaleMessage("add-premium-other", sender);
|
plugin.getCore().sendLocaleMessage("add-premium", sender);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onPremiumOther(CommandSender sender, Command command, String[] args) {
|
||||||
|
if (!hasOtherPermission(sender, command)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (forwardPremiumCommand(sender, args[0])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//todo: load async
|
||||||
|
StoredProfile profile = plugin.getCore().getStorage().loadProfile(args[0]);
|
||||||
|
if (profile == null) {
|
||||||
|
plugin.getCore().sendLocaleMessage("player-unknown", sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (profile.isPremium()) {
|
||||||
|
plugin.getCore().sendLocaleMessage("already-exists-other", sender);
|
||||||
|
} else {
|
||||||
|
//todo: resolve uuid
|
||||||
|
profile.setPremium(true);
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
plugin.getCore().getStorage().save(profile);
|
||||||
|
});
|
||||||
|
|
||||||
|
plugin.getCore().sendLocaleMessage("add-premium-other", sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean forwardPremiumCommand(CommandSender sender, String target) {
|
||||||
|
return forwardBungeeCommand(sender, target, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.github.games647.fastlogin.bukkit.commands;
|
||||||
|
|
||||||
|
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||||
|
import com.github.games647.fastlogin.core.messages.ChangePremiumMessage;
|
||||||
|
import com.github.games647.fastlogin.core.messages.ChannelMessage;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.messaging.PluginMessageRecipient;
|
||||||
|
|
||||||
|
public abstract class ToggleCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
protected final FastLoginBukkit plugin;
|
||||||
|
|
||||||
|
public ToggleCommand(FastLoginBukkit plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean hasOtherPermission(CommandSender sender, Command cmd) {
|
||||||
|
if (!sender.hasPermission(cmd.getPermission() + ".other")) {
|
||||||
|
plugin.getCore().sendLocaleMessage("no-permission", sender);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean forwardBungeeCommand(CommandSender sender, String target, boolean activate) {
|
||||||
|
if (plugin.isBungeeEnabled()) {
|
||||||
|
sendBungeeActivateMessage(sender, target, activate);
|
||||||
|
plugin.getCore().sendLocaleMessage("wait-on-proxy", sender);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isConsole(CommandSender sender) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//console or command block
|
||||||
|
sender.sendMessage(plugin.getCore().getMessage("no-console"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendBungeeActivateMessage(CommandSender invoker, String target, boolean activate) {
|
||||||
|
if (invoker instanceof PluginMessageRecipient) {
|
||||||
|
ChannelMessage message = new ChangePremiumMessage(target, activate, true);
|
||||||
|
plugin.sendPluginMessage((PluginMessageRecipient) invoker, message);
|
||||||
|
} else {
|
||||||
|
Optional<? extends Player> optPlayer = Bukkit.getServer().getOnlinePlayers().stream().findFirst();
|
||||||
|
if (!optPlayer.isPresent()) {
|
||||||
|
plugin.getLog().info("No player online to send a plugin message to the proxy");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player sender = optPlayer.get();
|
||||||
|
ChannelMessage message = new ChangePremiumMessage(target, activate, false);
|
||||||
|
plugin.sendPluginMessage(sender, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -63,9 +63,12 @@ public class BungeeListener implements PluginMessageListener {
|
|||||||
|
|
||||||
//check if the player is still online or disconnected
|
//check if the player is still online or disconnected
|
||||||
Player checkedPlayer = Bukkit.getPlayerExact(loginMessage.getPlayerName());
|
Player checkedPlayer = Bukkit.getPlayerExact(loginMessage.getPlayerName());
|
||||||
|
if (checkedPlayer == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//fail if target player is blacklisted because already authenticated or wrong bungeecord id
|
//fail if target player is blacklisted because already authenticated or wrong bungeecord id
|
||||||
if (checkedPlayer != null && !checkedPlayer.hasMetadata(plugin.getName())) {
|
if (checkedPlayer.hasMetadata(plugin.getName())) {
|
||||||
//fail if BungeeCord support is disabled (id = null)
|
//fail if BungeeCord support is disabled (id = null)
|
||||||
UUID sourceId = loginMessage.getProxyId();
|
UUID sourceId = loginMessage.getProxyId();
|
||||||
if (proxyIds.contains(sourceId)) {
|
if (proxyIds.contains(sourceId)) {
|
||||||
@ -73,6 +76,8 @@ public class BungeeListener implements PluginMessageListener {
|
|||||||
} else {
|
} else {
|
||||||
plugin.getLog().warn("Received proxy id: {} that doesn't exist in the proxy whitelist file", sourceId);
|
plugin.getLog().warn("Received proxy id: {} that doesn't exist in the proxy whitelist file", sourceId);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
plugin.getLog().warn("Received message {} from a blacklisted player {}", loginMessage, checkedPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public class JoinListener implements Listener {
|
|||||||
public void onPlayerJoin(PlayerJoinEvent joinEvent) {
|
public void onPlayerJoin(PlayerJoinEvent joinEvent) {
|
||||||
Player player = joinEvent.getPlayer();
|
Player player = joinEvent.getPlayer();
|
||||||
|
|
||||||
if (!plugin.isBungeeCord()) {
|
if (!plugin.isBungeeEnabled()) {
|
||||||
//Wait before auth plugin and we received a message from BungeeCord initializes the player
|
//Wait before auth plugin and we received a message from BungeeCord initializes the player
|
||||||
Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player);
|
Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player);
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, forceLoginTask, DELAY_LOGIN);
|
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, forceLoginTask, DELAY_LOGIN);
|
||||||
|
@ -27,7 +27,7 @@ public class DelayedAuthHook implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean hookFound = isHookFound();
|
boolean hookFound = isHookFound();
|
||||||
if (plugin.isBungeeCord()) {
|
if (plugin.isBungeeEnabled()) {
|
||||||
plugin.getLog().info("BungeeCord setting detected. No auth plugin is required");
|
plugin.getLog().info("BungeeCord setting detected. No auth plugin is required");
|
||||||
} else if (!hookFound) {
|
} else if (!hookFound) {
|
||||||
plugin.getLog().warn("No auth plugin were found by this plugin "
|
plugin.getLog().warn("No auth plugin were found by this plugin "
|
||||||
|
@ -2,7 +2,6 @@ package com.github.games647.fastlogin.bukkit.tasks;
|
|||||||
|
|
||||||
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
|
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
|
||||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||||
import com.github.games647.fastlogin.core.messages.ChannelMessage;
|
|
||||||
import com.github.games647.fastlogin.core.messages.SuccessMessage;
|
import com.github.games647.fastlogin.core.messages.SuccessMessage;
|
||||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||||
import com.github.games647.fastlogin.core.shared.ForceLoginManagement;
|
import com.github.games647.fastlogin.core.shared.ForceLoginManagement;
|
||||||
@ -38,9 +37,8 @@ public class ForceLoginTask extends ForceLoginManagement<Player, CommandSender,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onForceActionSuccess(LoginSession session) {
|
public void onForceActionSuccess(LoginSession session) {
|
||||||
if (core.getPlugin().isBungeeCord()) {
|
if (core.getPlugin().isBungeeEnabled()) {
|
||||||
ChannelMessage message = new SuccessMessage();
|
core.getPlugin().sendPluginMessage(player, new SuccessMessage());
|
||||||
core.getPlugin().sendPluginMessage(player, message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,6 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
<artifactId>fastlogin.core</artifactId>
|
<artifactId>fastlogin.core</artifactId>
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--BungeeCord with also the part outside the API-->
|
<!--BungeeCord with also the part outside the API-->
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.github.games647.fastlogin.bungee.listener;
|
package com.github.games647.fastlogin.bungee.listener;
|
||||||
|
|
||||||
import com.github.games647.craftapi.UUIDAdapter;
|
|
||||||
import com.github.games647.fastlogin.bungee.FastLoginBungee;
|
import com.github.games647.fastlogin.bungee.FastLoginBungee;
|
||||||
import com.github.games647.fastlogin.bungee.tasks.AsyncPremiumCheck;
|
import com.github.games647.fastlogin.bungee.tasks.AsyncPremiumCheck;
|
||||||
import com.github.games647.fastlogin.bungee.tasks.ForceLoginTask;
|
import com.github.games647.fastlogin.bungee.tasks.ForceLoginTask;
|
||||||
|
@ -39,14 +39,16 @@ public class MessageListener implements Listener {
|
|||||||
//moreover the client shouldn't be able fake a running premium check by sending the result message
|
//moreover the client shouldn't be able fake a running premium check by sending the result message
|
||||||
pluginMessageEvent.setCancelled(true);
|
pluginMessageEvent.setCancelled(true);
|
||||||
|
|
||||||
//check if the message is sent from the server
|
if (!(pluginMessageEvent.getSender() instanceof Server)) {
|
||||||
if (Server.class.isAssignableFrom(pluginMessageEvent.getSender().getClass())) {
|
//check if the message is sent from the server
|
||||||
//so that we can safely process this in the background
|
return;
|
||||||
byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length);
|
|
||||||
ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver();
|
|
||||||
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> readMessage(forPlayer, data));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//so that we can safely process this in the background
|
||||||
|
byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length);
|
||||||
|
ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver();
|
||||||
|
|
||||||
|
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> readMessage(forPlayer, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readMessage(ProxiedPlayer forPlayer, byte[] data) {
|
private void readMessage(ProxiedPlayer forPlayer, byte[] data) {
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.games647</groupId>
|
<groupId>com.github.games647</groupId>
|
||||||
<artifactId>craftapi</artifactId>
|
<artifactId>craftapi</artifactId>
|
||||||
<version>0.1</version>
|
<version>0.1.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- APIs we can use because they are available in all platforms (Spigot, Bungee, Cauldron) -->
|
<!-- APIs we can use because they are available in all platforms (Spigot, Bungee, Cauldron) -->
|
||||||
|
@ -49,4 +49,13 @@ public class ChangePremiumMessage implements ChannelMessage {
|
|||||||
output.writeUTF(playerName);
|
output.writeUTF(playerName);
|
||||||
output.writeBoolean(isSourceInvoker);
|
output.writeBoolean(isSourceInvoker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.getClass().getSimpleName() + '{' +
|
||||||
|
"playerName='" + playerName + '\'' +
|
||||||
|
", willEnable=" + willEnable +
|
||||||
|
", isSourceInvoker=" + isSourceInvoker +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,4 +19,9 @@ public class SuccessMessage implements ChannelMessage {
|
|||||||
public void writeTo(ByteArrayDataOutput output) {
|
public void writeTo(ByteArrayDataOutput output) {
|
||||||
//empty
|
//empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.getClass().getSimpleName() + "{}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user