mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-10-31 07:39:42 +01:00
create teleportTospawn method in Utils class
This commit is contained in:
parent
6d46827936
commit
872856e729
@ -1,14 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
@ -21,6 +12,14 @@ import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class UnregisterCommand extends ExecutableCommand {
|
||||
|
||||
@ -30,7 +29,6 @@ public class UnregisterCommand extends ExecutableCommand {
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
@ -62,33 +60,25 @@ public class UnregisterCommand extends ExecutableCommand {
|
||||
Player target = Bukkit.getPlayer(playerNameLowerCase);
|
||||
PlayerCache.getInstance().removePlayer(playerNameLowerCase);
|
||||
Utils.setGroup(target, Utils.GroupType.UNREGISTERED);
|
||||
if (target != null) {
|
||||
if (target.isOnline()) {
|
||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
||||
Location spawn = plugin.getSpawnLocation(target);
|
||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(target, target.getLocation(), spawn, false);
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
target.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
LimboCache.getInstance().addLimboPlayer(target);
|
||||
int delay = Settings.getRegistrationTimeout * 20;
|
||||
int interval = Settings.getWarnMessageInterval;
|
||||
BukkitScheduler scheduler = sender.getServer().getScheduler();
|
||||
if (delay != 0) {
|
||||
BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), delay);
|
||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTaskId(id);
|
||||
}
|
||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(scheduler.runTaskAsynchronously(plugin, new MessageTask(plugin, playerNameLowerCase, m.send("reg_msg"), interval)));
|
||||
if (Settings.applyBlindEffect)
|
||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
||||
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
||||
target.setWalkSpeed(0.0f);
|
||||
target.setFlySpeed(0.0f);
|
||||
}
|
||||
m.send(target, "unregistered");
|
||||
if (target != null && target.isOnline()) {
|
||||
Utils.teleportToSpawn(target);
|
||||
LimboCache.getInstance().addLimboPlayer(target);
|
||||
int delay = Settings.getRegistrationTimeout * 20;
|
||||
int interval = Settings.getWarnMessageInterval;
|
||||
BukkitScheduler scheduler = sender.getServer().getScheduler();
|
||||
if (delay != 0) {
|
||||
BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), delay);
|
||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTaskId(id);
|
||||
}
|
||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(scheduler.runTaskAsynchronously(plugin, new MessageTask(plugin, playerNameLowerCase, m.send("reg_msg"), interval)));
|
||||
if (Settings.applyBlindEffect)
|
||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
||||
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
||||
target.setWalkSpeed(0.0f);
|
||||
target.setFlySpeed(0.0f);
|
||||
}
|
||||
m.send(target, "unregistered");
|
||||
|
||||
}
|
||||
|
||||
// Show a status message
|
||||
|
@ -1,23 +1,5 @@
|
||||
package fr.xephi.authme.commands;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
@ -32,6 +14,23 @@ import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import fr.xephi.authme.util.Utils.GroupType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class AdminCommand implements CommandExecutor {
|
||||
|
||||
@ -274,7 +273,7 @@ public class AdminCommand implements CommandExecutor {
|
||||
}
|
||||
plugin.database.setUnlogged(name);
|
||||
if (Bukkit.getPlayerExact(realName) != null)
|
||||
Bukkit.getPlayerExact(realName).kickPlayer("An admin just registered you, please log again");
|
||||
Bukkit.getPlayerExact(realName).kickPlayer("An admin just registered you, please log again");
|
||||
m.send(sender, "registered");
|
||||
ConsoleLogger.info(name + " registered");
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
@ -472,33 +471,32 @@ public class AdminCommand implements CommandExecutor {
|
||||
Player target = Bukkit.getPlayer(name);
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
Utils.setGroup(target, GroupType.UNREGISTERED);
|
||||
if (target != null) {
|
||||
if (target.isOnline()) {
|
||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
||||
Location spawn = plugin.getSpawnLocation(target);
|
||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(target, target.getLocation(), spawn, false);
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
target.teleport(tpEvent.getTo());
|
||||
}
|
||||
if (target != null && target.isOnline()) {
|
||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
||||
Location spawn = plugin.getSpawnLocation(target);
|
||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(target, target.getLocation(), spawn, false);
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
target.teleport(tpEvent.getTo());
|
||||
}
|
||||
LimboCache.getInstance().addLimboPlayer(target);
|
||||
int delay = Settings.getRegistrationTimeout * 20;
|
||||
int interval = Settings.getWarnMessageInterval;
|
||||
BukkitScheduler sched = sender.getServer().getScheduler();
|
||||
if (delay != 0) {
|
||||
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, target), delay);
|
||||
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
||||
}
|
||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("reg_msg"), interval)));
|
||||
if (Settings.applyBlindEffect)
|
||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
||||
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
||||
target.setWalkSpeed(0.0f);
|
||||
target.setFlySpeed(0.0f);
|
||||
}
|
||||
m.send(target, "unregistered");
|
||||
}
|
||||
LimboCache.getInstance().addLimboPlayer(target);
|
||||
int delay = Settings.getRegistrationTimeout * 20;
|
||||
int interval = Settings.getWarnMessageInterval;
|
||||
BukkitScheduler sched = sender.getServer().getScheduler();
|
||||
if (delay != 0) {
|
||||
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, target), delay);
|
||||
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
||||
}
|
||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("reg_msg"), interval)));
|
||||
if (Settings.applyBlindEffect)
|
||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
||||
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
||||
target.setWalkSpeed(0.0f);
|
||||
target.setFlySpeed(0.0f);
|
||||
}
|
||||
m.send(target, "unregistered");
|
||||
|
||||
}
|
||||
m.send(sender, "unregistered");
|
||||
ConsoleLogger.info(args[1] + " unregistered");
|
||||
|
@ -55,22 +55,12 @@ public class AsyncronousLogout {
|
||||
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
||||
Location spawnLoc = plugin.getSpawnLocation(p);
|
||||
final AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(p, spawnLoc);
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
if (tpEvent.getTo() != null)
|
||||
p.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Utils.teleportToSpawn(p);
|
||||
}
|
||||
});
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name))
|
||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||
LimboCache.getInstance().addLimboPlayer(player);
|
||||
|
@ -48,17 +48,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
|
||||
}
|
||||
|
||||
protected void forceLogin(Player player) {
|
||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
||||
Location spawnLoc = plugin.getSpawnLocation(player);
|
||||
AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, spawnLoc);
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) {
|
||||
tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load();
|
||||
}
|
||||
player.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
Utils.teleportToSpawn(player);
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name))
|
||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||
LimboCache.getInstance().addLimboPlayer(player);
|
||||
@ -81,14 +71,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
|
||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
|
||||
if (limbo != null) {
|
||||
player.setGameMode(limbo.getGameMode());
|
||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
||||
Location loca = plugin.getSpawnLocation(player);
|
||||
RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca);
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled() && tpEvent.getTo() != null) {
|
||||
player.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
Utils.teleportToSpawn(player);
|
||||
|
||||
if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
|
||||
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
|
||||
|
@ -55,15 +55,7 @@ public class AsyncronousUnregister {
|
||||
return;
|
||||
}
|
||||
if (Settings.isForcedRegistrationEnabled) {
|
||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
||||
Location spawn = plugin.getSpawnLocation(player);
|
||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false);
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
player.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
|
||||
Utils.teleportToSpawn(player);
|
||||
player.saveData();
|
||||
PlayerCache.getInstance().removePlayer(player.getName().toLowerCase());
|
||||
if (!Settings.getRegisteredGroup.isEmpty())
|
||||
@ -98,22 +90,11 @@ public class AsyncronousUnregister {
|
||||
}
|
||||
m.send(player, "unregistered");
|
||||
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
||||
Location spawn = plugin.getSpawnLocation(player);
|
||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false);
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) {
|
||||
tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load();
|
||||
}
|
||||
player.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
return;
|
||||
Utils.teleportToSpawn(player);
|
||||
} else {
|
||||
m.send(player, "wrong_pwd");
|
||||
}
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
} catch (NoSuchAlgorithmException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import fr.xephi.authme.events.SpawnTeleportEvent;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -297,4 +299,15 @@ public class Utils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void teleportToSpawn(Player player) {
|
||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
||||
Location spawn = plugin.getSpawnLocation(player);
|
||||
AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, spawn);
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
player.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user