#421 Create SpawnLoader

- Non-static service class which handles the spawnpoints used in AuthMe
This commit is contained in:
ljacqu
2016-03-12 10:27:15 +01:00
parent 8b27444a49
commit 8293766f98
18 changed files with 464 additions and 274 deletions
@@ -1,9 +1,7 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.settings.Spawn;
import org.bukkit.entity.Player;
import java.util.List;
@@ -12,16 +10,10 @@ public class FirstSpawnCommand extends PlayerCommand {
@Override
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
// Make sure the command executor is a player
try {
if (Spawn.getInstance().getFirstSpawn() != null) {
player.teleport(Spawn.getInstance().getFirstSpawn());
} else {
player.sendMessage("[AuthMe] First spawn has failed, please try to define the first spawn");
}
} catch (NullPointerException ex) {
// TODO ljacqu 20151119: Catching NullPointerException is never a good idea. Find what can cause one instead
ConsoleLogger.showError(ex.getMessage());
if (commandService.getSpawnLoader().getFirstSpawn() != null) {
player.teleport(commandService.getSpawnLoader().getFirstSpawn());
} else {
player.sendMessage("[AuthMe] First spawn has failed, please try to define the first spawn");
}
}
}
@@ -1,9 +1,7 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.settings.Spawn;
import org.bukkit.entity.Player;
import java.util.List;
@@ -12,14 +10,10 @@ public class SetFirstSpawnCommand extends PlayerCommand {
@Override
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
try {
if (Spawn.getInstance().setFirstSpawn(player.getLocation())) {
player.sendMessage("[AuthMe] Correctly defined new first spawn point");
} else {
player.sendMessage("[AuthMe] SetFirstSpawn has failed, please retry");
}
} catch (NullPointerException ex) {
ConsoleLogger.showError(ex.getMessage());
if (commandService.getSpawnLoader().setFirstSpawn(player.getLocation())) {
player.sendMessage("[AuthMe] Correctly defined new first spawn point");
} else {
player.sendMessage("[AuthMe] SetFirstSpawn has failed, please retry");
}
}
}
@@ -1,9 +1,7 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.settings.Spawn;
import org.bukkit.entity.Player;
import java.util.List;
@@ -12,14 +10,10 @@ public class SetSpawnCommand extends PlayerCommand {
@Override
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
try {
if (Spawn.getInstance().setSpawn(player.getLocation())) {
player.sendMessage("[AuthMe] Correctly defined new spawn point");
} else {
player.sendMessage("[AuthMe] SetSpawn has failed, please retry");
}
} catch (NullPointerException ex) {
ConsoleLogger.showError(ex.getMessage());
if (commandService.getSpawnLoader().setSpawn(player.getLocation())) {
player.sendMessage("[AuthMe] Correctly defined new spawn point");
} else {
player.sendMessage("[AuthMe] SetSpawn has failed, please retry");
}
}
}
@@ -1,9 +1,7 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.settings.Spawn;
import org.bukkit.entity.Player;
import java.util.List;
@@ -12,14 +10,10 @@ public class SpawnCommand extends PlayerCommand {
@Override
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
try {
if (Spawn.getInstance().getSpawn() != null) {
player.teleport(Spawn.getInstance().getSpawn());
} else {
player.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
}
} catch (NullPointerException ex) {
ConsoleLogger.showError(ex.getMessage());
if (commandService.getSpawnLoader().getSpawn() != null) {
player.teleport(commandService.getSpawnLoader().getSpawn());
} else {
player.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
}
}
}