mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-24 11:15:19 +01:00
commit
13982011c7
@ -743,25 +743,9 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
|
||||
// Return the spawn location of a player
|
||||
@Deprecated
|
||||
public Location getSpawnLocation(Player player) {
|
||||
World world = player.getWorld();
|
||||
String[] spawnPriority = Settings.spawnPriority.split(",");
|
||||
Location spawnLoc = world.getSpawnLocation();
|
||||
for (int i = spawnPriority.length - 1; i >= 0; i--) {
|
||||
String s = spawnPriority[i];
|
||||
if (s.equalsIgnoreCase("default") && getDefaultSpawn(world) != null)
|
||||
spawnLoc = getDefaultSpawn(world);
|
||||
if (s.equalsIgnoreCase("multiverse") && getMultiverseSpawn(world) != null)
|
||||
spawnLoc = getMultiverseSpawn(world);
|
||||
if (s.equalsIgnoreCase("essentials") && getEssentialsSpawn() != null)
|
||||
spawnLoc = getEssentialsSpawn();
|
||||
if (s.equalsIgnoreCase("authme") && getAuthMeSpawn(player) != null)
|
||||
spawnLoc = getAuthMeSpawn(player);
|
||||
}
|
||||
if (spawnLoc == null) {
|
||||
spawnLoc = world.getSpawnLocation();
|
||||
}
|
||||
return spawnLoc;
|
||||
return Spawn.getInstance().getSpawnLocation(player);
|
||||
}
|
||||
|
||||
// Return the default spawn point of a world
|
||||
|
@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
@ -20,6 +21,7 @@ public class ReloadCommand implements ExecutableCommand {
|
||||
try {
|
||||
commandService.getSettings().reload();
|
||||
commandService.reloadMessages(commandService.getSettings().getMessagesFile());
|
||||
Spawn.reload();
|
||||
// TODO #432: We should not reload only certain plugin entities but actually reinitialize all elements,
|
||||
// i.e. here in the future we might not have setupDatabase() but Authme.onEnable(), maybe after
|
||||
// a call to some destructor method
|
||||
|
@ -5,6 +5,7 @@ import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.settings.domain.Property;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
@ -176,7 +177,7 @@ public final class Settings {
|
||||
emailRegistration = configFile.getBoolean("settings.registration.enableEmailRegistrationSystem", false);
|
||||
saltLength = configFile.getInt("settings.security.doubleMD5SaltLength", 8);
|
||||
getmaxRegPerEmail = configFile.getInt("Email.maxRegPerEmail", 1);
|
||||
multiverse = configFile.getBoolean("Hooks.multiverse", true);
|
||||
multiverse = load(HooksSettings.MULTIVERSE);
|
||||
bungee = configFile.getBoolean("Hooks.bungeecord", false);
|
||||
getForcedWorlds = configFile.getStringList("settings.restrictions.ForceSpawnOnTheseWorlds");
|
||||
banUnsafeIp = configFile.getBoolean("settings.restrictions.banUnsafedIP", false);
|
||||
@ -213,7 +214,7 @@ public final class Settings {
|
||||
broadcastWelcomeMessage = configFile.getBoolean("settings.broadcastWelcomeMessage", false);
|
||||
forceRegKick = configFile.getBoolean("settings.registration.forceKickAfterRegister", false);
|
||||
forceRegLogin = configFile.getBoolean("settings.registration.forceLoginAfterRegister", false);
|
||||
spawnPriority = configFile.getString("settings.restrictions.spawnPriority", "authme,essentials,multiverse,default");
|
||||
spawnPriority = load(RestrictionSettings.SPAWN_PRIORITY);
|
||||
getMaxLoginPerIp = configFile.getInt("settings.restrictions.maxLoginPerIp", 0);
|
||||
getMaxJoinPerIp = configFile.getInt("settings.restrictions.maxJoinPerIp", 0);
|
||||
checkVeryGames = configFile.getBoolean("VeryGames.enableIpCheck", false);
|
||||
|
@ -1,7 +1,14 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@ -12,13 +19,17 @@ import java.io.File;
|
||||
public class Spawn extends CustomConfiguration {
|
||||
|
||||
private static Spawn spawn;
|
||||
private static String[] spawnPriority;
|
||||
|
||||
public Spawn() {
|
||||
super(new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "spawn.yml"));
|
||||
spawn = this;
|
||||
load();
|
||||
save();
|
||||
saveDefault();
|
||||
private Spawn() {
|
||||
super(new File(Settings.PLUGIN_FOLDER, "spawn.yml"));
|
||||
reload();
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
getInstance().load();
|
||||
getInstance().save();
|
||||
spawnPriority = Settings.spawnPriority.split(",");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -33,111 +44,108 @@ public class Spawn extends CustomConfiguration {
|
||||
return spawn;
|
||||
}
|
||||
|
||||
private void saveDefault() {
|
||||
if (!contains("spawn")) {
|
||||
set("spawn.world", "");
|
||||
set("spawn.x", "");
|
||||
set("spawn.y", "");
|
||||
set("spawn.z", "");
|
||||
set("spawn.yaw", "");
|
||||
set("spawn.pitch", "");
|
||||
save();
|
||||
}
|
||||
if (!contains("firstspawn")) {
|
||||
set("firstspawn.world", "");
|
||||
set("firstspawn.x", "");
|
||||
set("firstspawn.y", "");
|
||||
set("firstspawn.z", "");
|
||||
set("firstspawn.yaw", "");
|
||||
set("firstspawn.pitch", "");
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setSpawn.
|
||||
*
|
||||
* @param location Location
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean setSpawn(Location location) {
|
||||
try {
|
||||
set("spawn.world", location.getWorld().getName());
|
||||
set("spawn.x", location.getX());
|
||||
set("spawn.y", location.getY());
|
||||
set("spawn.z", location.getZ());
|
||||
set("spawn.yaw", location.getYaw());
|
||||
set("spawn.pitch", location.getPitch());
|
||||
save();
|
||||
return true;
|
||||
} catch (NullPointerException npe) {
|
||||
if (location == null || location.getWorld() == null) {
|
||||
return false;
|
||||
}
|
||||
set("spawn.world", location.getWorld().getName());
|
||||
set("spawn.x", location.getX());
|
||||
set("spawn.y", location.getY());
|
||||
set("spawn.z", location.getZ());
|
||||
set("spawn.yaw", location.getYaw());
|
||||
set("spawn.pitch", location.getPitch());
|
||||
save();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setFirstSpawn.
|
||||
*
|
||||
* @param location Location
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean setFirstSpawn(Location location) {
|
||||
try {
|
||||
set("firstspawn.world", location.getWorld().getName());
|
||||
set("firstspawn.x", location.getX());
|
||||
set("firstspawn.y", location.getY());
|
||||
set("firstspawn.z", location.getZ());
|
||||
set("firstspawn.yaw", location.getYaw());
|
||||
set("firstspawn.pitch", location.getPitch());
|
||||
save();
|
||||
return true;
|
||||
} catch (NullPointerException npe) {
|
||||
if (location == null || location.getWorld() == null) {
|
||||
return false;
|
||||
}
|
||||
set("firstspawn.world", location.getWorld().getName());
|
||||
set("firstspawn.x", location.getX());
|
||||
set("firstspawn.y", location.getY());
|
||||
set("firstspawn.z", location.getZ());
|
||||
set("firstspawn.yaw", location.getYaw());
|
||||
set("firstspawn.pitch", location.getPitch());
|
||||
save();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getLocation.
|
||||
*
|
||||
* @return Location
|
||||
*/
|
||||
@Deprecated
|
||||
public Location getLocation() {
|
||||
return getSpawn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getSpawn.
|
||||
*
|
||||
* @return Location
|
||||
*/
|
||||
public Location getSpawn() {
|
||||
try {
|
||||
if (this.getString("spawn.world").isEmpty() || this.getString("spawn.world").equals(""))
|
||||
String worldName = getString("spawn.world");
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (StringUtils.isEmpty(worldName) || world == null) {
|
||||
return null;
|
||||
Location location = new Location(Bukkit.getWorld(this.getString("spawn.world")), this.getDouble("spawn.x"), this.getDouble("spawn.y"), this.getDouble("spawn.z"), Float.parseFloat(this.getString("spawn.yaw")), Float.parseFloat(this.getString("spawn.pitch")));
|
||||
return location;
|
||||
} catch (NullPointerException | NumberFormatException npe) {
|
||||
}
|
||||
return new Location(world, getDouble("spawn.x"), getDouble("spawn.y"), getDouble("spawn.z"),
|
||||
Float.parseFloat(getString("spawn.yaw")), Float.parseFloat(getString("spawn.pitch")));
|
||||
} catch (NumberFormatException e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getFirstSpawn.
|
||||
*
|
||||
* @return Location
|
||||
*/
|
||||
public Location getFirstSpawn() {
|
||||
try {
|
||||
if (this.getString("firstspawn.world").isEmpty() || this.getString("firstspawn.world").equals(""))
|
||||
String worldName;
|
||||
World world;
|
||||
if (StringUtils.isEmpty(worldName = getString("firstspawn.world")) ||
|
||||
(world = Bukkit.getWorld(worldName)) == null) {
|
||||
return null;
|
||||
Location location = new Location(Bukkit.getWorld(this.getString("firstspawn.world")), this.getDouble("firstspawn.x"), this.getDouble("firstspawn.y"), this.getDouble("firstspawn.z"), Float.parseFloat(this.getString("firstspawn.yaw")), Float.parseFloat(this.getString("firstspawn.pitch")));
|
||||
return location;
|
||||
} catch (NullPointerException | NumberFormatException npe) {
|
||||
}
|
||||
return new Location(world, getDouble("firstspawn.x"), getDouble("firstspawn.y"), getDouble("firstspawn.z"),
|
||||
Float.parseFloat(getString("firstspawn.yaw")), Float.parseFloat(getString("firstspawn.pitch")));
|
||||
} catch (NumberFormatException e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the spawn location of a player
|
||||
public Location getSpawnLocation(Player player) {
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
if (plugin == null || player == null || player.getWorld() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
World world = player.getWorld();
|
||||
Location spawnLoc = null;
|
||||
for (String priority : spawnPriority) {
|
||||
switch (priority.toLowerCase()) {
|
||||
case "default":
|
||||
if (world.getSpawnLocation() != null) {
|
||||
spawnLoc = world.getSpawnLocation();
|
||||
}
|
||||
break;
|
||||
case "multiverse":
|
||||
if (Settings.multiverse && plugin.multiverse != null) {
|
||||
MVWorldManager manager = plugin.multiverse.getMVWorldManager();
|
||||
if (manager.isMVWorld(world)) {
|
||||
spawnLoc = manager.getMVWorld(world).getSpawnLocation();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "essentials":
|
||||
spawnLoc = plugin.essentialsSpawn;
|
||||
break;
|
||||
case "authme":
|
||||
String playerNameLower = player.getName().toLowerCase();
|
||||
if (PlayerCache.getInstance().isAuthenticated(playerNameLower)) {
|
||||
spawnLoc = getSpawn();
|
||||
} else if ((getFirstSpawn() != null) && (!player.hasPlayedBefore() ||
|
||||
(!plugin.getDataSource().isAuthAvailable(playerNameLower)))) {
|
||||
spawnLoc = getFirstSpawn();
|
||||
} else {
|
||||
spawnLoc = getSpawn();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (spawnLoc != null) {
|
||||
return spawnLoc;
|
||||
}
|
||||
}
|
||||
return world.getSpawnLocation(); // return default location
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user