Cancel restore session events if it's a premium player (Related #201)

This commit is contained in:
games647
2018-03-13 14:21:24 +01:00
parent b7c0fd549c
commit 5bcfdfeb32
6 changed files with 44 additions and 13 deletions

24
.gitignore vendored
View File

@ -1,26 +1,26 @@
# Eclipse stuff # Eclipse
/.classpath .classpath
/.project .project
/.settings .settings/
# NetBeans # NetBeans
*/nbproject nbproject/
nb-configuration.xml nb-configuration.xml
# maven # Maven
*/target target/
# vim # Vim
.*.sw[a-p] .*.sw[a-p]
# virtual machine crash logs, see https://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see https://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
# various other potential build files # various other potential build files
*/build/ build/
/bin bin/
/dist dist/
/manifest.mf manifest.mf
*.log *.log
# Mac filesystem dust # Mac filesystem dust

View File

@ -97,6 +97,7 @@
<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-->

View File

@ -1,10 +1,16 @@
package com.github.games647.fastlogin.bukkit.hooks; package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import fr.xephi.authme.api.v3.AuthMeApi; import fr.xephi.authme.api.v3.AuthMeApi;
import fr.xephi.authme.events.RestoreSessionEvent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
/** /**
* GitHub: https://github.com/Xephi/AuthMeReloaded/ * GitHub: https://github.com/Xephi/AuthMeReloaded/
@ -15,7 +21,24 @@ import org.bukkit.entity.Player;
* <p> * <p>
* Spigot: https://www.spigotmc.org/resources/authme-reloaded.6269/ * Spigot: https://www.spigotmc.org/resources/authme-reloaded.6269/
*/ */
public class AuthMeHook implements AuthPlugin<Player> { public class AuthMeHook implements AuthPlugin<Player>, Listener {
private final FastLoginBukkit plugin;
public AuthMeHook(FastLoginBukkit plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onSessionRestore(RestoreSessionEvent restoreSessionEvent) {
Player player = restoreSessionEvent.getPlayer();
String id = '/' + player.getAddress().getAddress().getHostAddress() + ':' + player.getAddress().getPort();
BukkitLoginSession session = plugin.getLoginSessions().get(id);
if (session != null && session.isVerified()) {
restoreSessionEvent.setCancelled(true);
}
}
@Override @Override
public boolean forceLogin(Player player) { public boolean forceLogin(Player player) {

View File

@ -49,6 +49,7 @@ public class JoinListener implements Listener {
public void onPlayerQuit(PlayerQuitEvent quitEvent) { public void onPlayerQuit(PlayerQuitEvent quitEvent) {
Player player = quitEvent.getPlayer(); Player player = quitEvent.getPlayer();
player.removeMetadata(plugin.getName(), plugin); player.removeMetadata(plugin.getName(), plugin);
plugin.getCore().getPendingConfirms().remove(player.getUniqueId()); plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
} }
} }

View File

@ -15,6 +15,7 @@ import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
public class DelayedAuthHook implements Runnable { public class DelayedAuthHook implements Runnable {
@ -53,6 +54,10 @@ public class DelayedAuthHook implements Runnable {
return false; return false;
} }
if (authPluginHook instanceof Listener) {
Bukkit.getPluginManager().registerEvents((Listener) authPluginHook, plugin);
}
if (plugin.getCore().getAuthPluginHook() == null) { if (plugin.getCore().getAuthPluginHook() == null) {
plugin.getLog().info("Hooking into auth plugin: {}", authPluginHook.getClass().getSimpleName()); plugin.getLog().info("Hooking into auth plugin: {}", authPluginHook.getClass().getSimpleName());
plugin.getCore().setAuthPluginHook(authPluginHook); plugin.getCore().setAuthPluginHook(authPluginHook);

View File

@ -71,6 +71,7 @@
<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-->