mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-25 01:57:48 +01:00
Fix 1.7 and 1.8 compatibility
This commit is contained in:
parent
d9399568a3
commit
843baa8e4a
@ -43,7 +43,6 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -80,8 +79,7 @@ public class PlayerListener implements Listener {
|
||||
@Inject
|
||||
private JoinMessageService joinMessageService;
|
||||
|
||||
private boolean isAsyncPlayerPreLoginEventCalled = false;
|
||||
private boolean isPlayerSpawnLocationEventCalled = false;
|
||||
private static boolean IS_ASYNC_PLAYER_PRE_LOGIN_EVENT_CALLED = false;
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
@ -189,26 +187,11 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
// Note: the following event is called since MC1.9, in older versions we have to fallback on the PlayerJoinEvent
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerSpawn(PlayerSpawnLocationEvent event) {
|
||||
isPlayerSpawnLocationEventCalled = true;
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
management.performJoin(player, event.getSpawnLocation());
|
||||
|
||||
Location customSpawnLocation = teleportationService.prepareOnJoinSpawnLocation(player);
|
||||
if (customSpawnLocation != null) {
|
||||
event.setSpawnLocation(customSpawnLocation);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (!isPlayerSpawnLocationEventCalled) {
|
||||
if (!PlayerListener19.isIsPlayerSpawnLocationEventCalled()) {
|
||||
teleportationService.teleportOnJoin(player);
|
||||
management.performJoin(player, player.getLocation());
|
||||
}
|
||||
@ -239,7 +222,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onAsyncPlayerPreLoginEvent(AsyncPlayerPreLoginEvent event) {
|
||||
isAsyncPlayerPreLoginEventCalled = true;
|
||||
IS_ASYNC_PLAYER_PRE_LOGIN_EVENT_CALLED = true;
|
||||
|
||||
final String name = event.getName();
|
||||
|
||||
@ -274,7 +257,7 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAsyncPlayerPreLoginEventCalled) {
|
||||
if (!IS_ASYNC_PLAYER_PRE_LOGIN_EVENT_CALLED) {
|
||||
try {
|
||||
runOnJoinChecks(name, event.getAddress().getHostAddress());
|
||||
} catch (FailedVerificationException e) {
|
||||
|
@ -2,19 +2,50 @@ package fr.xephi.authme.listener;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.service.TeleportationService;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
|
||||
|
||||
/**
|
||||
* Listener of player events for events introduced in Minecraft 1.9.
|
||||
*/
|
||||
public class PlayerListener19 implements Listener {
|
||||
|
||||
@Inject
|
||||
private Management management;
|
||||
|
||||
@Inject
|
||||
private TeleportationService teleportationService;
|
||||
|
||||
@Inject
|
||||
private ListenerService listenerService;
|
||||
|
||||
private static boolean IS_PLAYER_SPAWN_LOCATION_EVENT_CALLED = false;
|
||||
|
||||
public static boolean isIsPlayerSpawnLocationEventCalled() {
|
||||
return IS_PLAYER_SPAWN_LOCATION_EVENT_CALLED;
|
||||
}
|
||||
|
||||
// Note: the following event is called since MC1.9, in older versions we have to fallback on the PlayerJoinEvent
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerSpawn(PlayerSpawnLocationEvent event) {
|
||||
PlayerListener19.IS_PLAYER_SPAWN_LOCATION_EVENT_CALLED = true;
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
management.performJoin(player, event.getSpawnLocation());
|
||||
|
||||
Location customSpawnLocation = teleportationService.prepareOnJoinSpawnLocation(player);
|
||||
if (customSpawnLocation != null) {
|
||||
event.setSpawnLocation(customSpawnLocation);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||
if (listenerService.shouldCancelEvent(event)) {
|
||||
|
@ -32,7 +32,7 @@ public final class ListenerConsistencyTest {
|
||||
"PlayerListener#onPlayerQuit", "ServerListener#onPluginDisable",
|
||||
"ServerListener#onServerPing", "ServerListener#onPluginEnable",
|
||||
"PlayerListener#onJoinMessage", "PlayerListener#onAsyncPlayerPreLoginEvent",
|
||||
"PlayerListener#onPlayerSpawn");
|
||||
"PlayerListener19#onPlayerSpawn");
|
||||
|
||||
@BeforeClass
|
||||
public static void collectListenerClasses() {
|
||||
@ -120,7 +120,9 @@ public final class ListenerConsistencyTest {
|
||||
// Exclude any methods with "$" in it: jacoco creates a "$jacocoInit" method we want to ignore, and
|
||||
// methods like "access$000" are created by the compiler when a private member is being accessed by an inner
|
||||
// class, which is not of interest for us
|
||||
if (Modifier.isPrivate(method.getModifiers()) || method.getName().contains("$")) {
|
||||
// Also exclude getters
|
||||
String methodName = method.getName();
|
||||
if (Modifier.isPrivate(method.getModifiers()) || methodName.contains("$") || methodName.startsWith("get") || methodName.startsWith("is")) {
|
||||
return false;
|
||||
}
|
||||
// Skip reload() method (implementation of Reloadable interface)
|
||||
|
Loading…
Reference in New Issue
Block a user