mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-09 04:02:10 +01:00
Some fixes!
Thanks to Koolaid5000 for the forcesinglesession fix idea! 👍
This commit is contained in:
parent
835e935886
commit
8c8f84ae4a
@ -15,14 +15,17 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerBedEnterEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
@ -397,6 +400,61 @@ public class AuthMePlayerListener implements Listener {
|
||||
}, 300);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
final PlayerJoinEvent event = e;
|
||||
|
||||
if (event.getPlayer() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Shedule login task so works after the prelogin
|
||||
// (Fix found by Koolaid5000)
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
Player player = event.getPlayer();
|
||||
String name = player.getName().toLowerCase();
|
||||
|
||||
plugin.management.performJoin(player);
|
||||
|
||||
// Remove the join message while the player isn't logging in
|
||||
if ((Settings.enableProtection || Settings.delayJoinMessage) && name != null && event.getJoinMessage() != null) {
|
||||
joinMessage.put(name, event.getJoinMessage());
|
||||
event.setJoinMessage(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPreLogin(AsyncPlayerPreLoginEvent event){
|
||||
final String name = event.getName().toLowerCase();
|
||||
final Player player = Bukkit.getServer().getPlayer(name);
|
||||
|
||||
// Check if forceSingleSession is set to true, so kick player that has
|
||||
// joined with same nick of online player
|
||||
if (plugin.dataManager.isOnline(player, name) && Settings.isForceSingleSessionEnabled) {
|
||||
event.setKickMessage(m.send("same_nick")[0]);
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name))
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
|
||||
if (limbo != null && PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
|
||||
Utils.getInstance().addNormal(player, limbo.getGroup());
|
||||
LimboCache.getInstance().deleteLimboPlayer(player.getName().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
@ -445,27 +503,6 @@ public class AuthMePlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
// Check if forceSingleSession is set to true, so kick player that has
|
||||
// joined with same nick of online player
|
||||
if (plugin.dataManager.isOnline(player, name) && Settings.isForceSingleSessionEnabled) {
|
||||
event.setKickMessage(m.send("same_nick")[0]);
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name))
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
|
||||
if (player != null && limbo != null && PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
|
||||
Utils.getInstance().addNormal(player, limbo.getGroup());
|
||||
LimboCache.getInstance().deleteLimboPlayer(player.getName().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.database.isAuthAvailable(name) && plugin.database.getType() != DataSource.DataSourceType.FILE) {
|
||||
PlayerAuth auth = plugin.database.getAuth(name);
|
||||
if (auth.getRealName() != null && !auth.getRealName().isEmpty() && !auth.getRealName().equalsIgnoreCase("Player") && !auth.getRealName().equals(player.getName())) {
|
||||
@ -564,23 +601,6 @@ public class AuthMePlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (event.getPlayer() == null) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
String name = player.getName().toLowerCase();
|
||||
|
||||
plugin.management.performJoin(player);
|
||||
|
||||
// Remove the join message while the player isn't logging in
|
||||
if ((Settings.enableProtection || Settings.delayJoinMessage) && name != null && event.getJoinMessage() != null) {
|
||||
joinMessage.put(name, event.getJoinMessage());
|
||||
event.setJoinMessage(null);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (event.getPlayer() == null) {
|
||||
@ -736,6 +756,35 @@ public class AuthMePlayerListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void playerHitPlayerEvent(EntityDamageByEntityEvent event) {
|
||||
Entity damager = event.getDamager();
|
||||
if (!(damager instanceof Player)){
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) damager;
|
||||
String name = player.getName().toLowerCase();
|
||||
|
||||
if (Utils.getInstance().isUnrestricted(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getCitizensCommunicator().isNPC(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.database.isAuthAvailable(name) && !Settings.isForcedRegistrationEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (event.getPlayer() == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user