Fixed NPE
This commit is contained in:
parent
64b8fbbe4d
commit
9627dead9f
5
pom.xml
5
pom.xml
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.butzlabben.world</groupId>
|
||||
<artifactId>WorldSystem</artifactId>
|
||||
<version>2.4.8.2</version>
|
||||
<version>2.4.9</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -24,6 +24,7 @@
|
|||
</reporting>
|
||||
|
||||
<build>
|
||||
<finalName>WorldSystem.jar</finalName>
|
||||
<defaultGoal>package</defaultGoal>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
|
@ -129,7 +130,7 @@
|
|||
<dependency>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>authlib</artifactId>
|
||||
<version>1.5.21</version>
|
||||
<version>1.5.25</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -4,8 +4,15 @@ import de.butzlabben.world.autoupdater.AutoUpdater;
|
|||
import de.butzlabben.world.command.WSCommand;
|
||||
import de.butzlabben.world.command.WorldAdministrateCommand;
|
||||
import de.butzlabben.world.command.WorldSettingsCommands;
|
||||
import de.butzlabben.world.config.*;
|
||||
import de.butzlabben.world.listener.*;
|
||||
import de.butzlabben.world.config.DependenceConfig;
|
||||
import de.butzlabben.world.config.GuiConfig;
|
||||
import de.butzlabben.world.config.MessageConfig;
|
||||
import de.butzlabben.world.config.PluginConfig;
|
||||
import de.butzlabben.world.config.SettingsConfig;
|
||||
import de.butzlabben.world.listener.BlockListener;
|
||||
import de.butzlabben.world.listener.CommandListener;
|
||||
import de.butzlabben.world.listener.PlayerListener;
|
||||
import de.butzlabben.world.listener.WorldEditListener;
|
||||
import de.butzlabben.world.util.PapiExtension;
|
||||
import de.butzlabben.world.util.PlayerPositions;
|
||||
import de.butzlabben.world.util.VersionUtil;
|
||||
|
@ -13,6 +20,8 @@ import de.butzlabben.world.util.database.DatabaseProvider;
|
|||
import de.butzlabben.world.wrapper.AsyncCreatorAdapter;
|
||||
import de.butzlabben.world.wrapper.CreatorAdapter;
|
||||
import de.butzlabben.world.wrapper.SystemWorld;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import net.myplayplanet.commandframework.CommandFramework;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -21,9 +30,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Butzlabben
|
||||
* @author Jubeki
|
||||
|
@ -114,7 +120,6 @@ public class WorldSystem extends JavaPlugin {
|
|||
PluginManager pm = Bukkit.getPluginManager();
|
||||
pm.registerEvents(new PlayerListener(), this);
|
||||
pm.registerEvents(new BlockListener(), this);
|
||||
pm.registerEvents(new PlayerDeathListener(), this);
|
||||
pm.registerEvents(new CommandListener(), this);
|
||||
if (pm.getPlugin("WorldEdit") != null)
|
||||
pm.registerEvents(new WorldEditListener(), this);
|
||||
|
|
|
@ -4,16 +4,20 @@ import com.google.common.collect.Sets;
|
|||
import com.mojang.authlib.GameProfile;
|
||||
import de.butzlabben.world.GameProfileBuilder;
|
||||
import de.butzlabben.world.wrapper.WorldTemplate;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class represents a worldconfig.yml file Here you can edit and read all
|
||||
* things Get an instance via WorldConfig.getWorldConfig()
|
||||
|
@ -55,7 +59,7 @@ public class WorldConfig {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns wether a worldconfig exists for this worldname
|
||||
* Returns whether a worldconfig exists for this worldname
|
||||
*
|
||||
* @param worldname name of the world
|
||||
* @return Whether this world has a worldconfig
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
package de.butzlabben.world.listener;
|
||||
|
||||
import de.butzlabben.world.config.PluginConfig;
|
||||
import de.butzlabben.world.config.WorldConfig;
|
||||
import de.butzlabben.world.wrapper.WorldPlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerDeathListener implements Listener {
|
||||
|
||||
private final HashMap<UUID, World> deathLocations = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onDie(PlayerDeathEvent e) {
|
||||
Player p = e.getEntity();
|
||||
WorldPlayer wp = new WorldPlayer(p, p.getWorld().getName());
|
||||
if (wp.isOnSystemWorld()) {
|
||||
deathLocations.put(p.getUniqueId(), p.getLocation().getWorld());
|
||||
} else {
|
||||
p.setGameMode(PluginConfig.getSpawnGamemode());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRespawn(PlayerRespawnEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
if (deathLocations.containsKey(p.getUniqueId())) {
|
||||
World world = deathLocations.remove(p.getUniqueId());
|
||||
|
||||
WorldConfig config = WorldConfig.getWorldConfig(world.getName());
|
||||
|
||||
if (config.getHome() != null) {
|
||||
e.setRespawnLocation(config.getHome());
|
||||
} else {
|
||||
if (PluginConfig.useWorldSpawn()) {
|
||||
e.setRespawnLocation(PluginConfig.getWorldSpawn(world));
|
||||
} else {
|
||||
e.setRespawnLocation(world.getSpawnLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,16 +6,22 @@ import de.butzlabben.world.config.WorldConfig;
|
|||
import de.butzlabben.world.util.PlayerPositions;
|
||||
import de.butzlabben.world.wrapper.SystemWorld;
|
||||
import de.butzlabben.world.wrapper.WorldPlayer;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
private final HashMap<UUID, World> deathLocations = new HashMap<>();
|
||||
|
||||
//#17
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
|
@ -43,4 +49,36 @@ public class PlayerListener implements Listener {
|
|||
}
|
||||
SystemWorld.tryUnloadLater(w);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDie(PlayerDeathEvent e) {
|
||||
Player p = e.getEntity();
|
||||
WorldPlayer wp = new WorldPlayer(p, p.getWorld().getName());
|
||||
if (wp.isOnSystemWorld()) {
|
||||
deathLocations.put(p.getUniqueId(), p.getLocation().getWorld());
|
||||
} else {
|
||||
p.setGameMode(PluginConfig.getSpawnGamemode());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRespawn(PlayerRespawnEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
if (deathLocations.containsKey(p.getUniqueId())) {
|
||||
World world = deathLocations.remove(p.getUniqueId());
|
||||
|
||||
WorldConfig config = WorldConfig.getWorldConfig(world.getName());
|
||||
|
||||
if (config.getHome() != null) {
|
||||
e.setRespawnLocation(config.getHome());
|
||||
} else {
|
||||
if (PluginConfig.useWorldSpawn()) {
|
||||
e.setRespawnLocation(PluginConfig.getWorldSpawn(world));
|
||||
} else {
|
||||
e.setRespawnLocation(world.getSpawnLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,219 +1,218 @@
|
|||
package de.butzlabben.world.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import de.butzlabben.world.config.PluginConfig;
|
||||
import de.butzlabben.world.config.WorldConfig;
|
||||
import de.butzlabben.world.util.database.DatabaseProvider;
|
||||
import de.butzlabben.world.util.database.DatabaseUtil;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
/*
|
||||
Class for implementing #23
|
||||
*/
|
||||
public class PlayerPositions {
|
||||
|
||||
@Getter
|
||||
private static PlayerPositions instance = new PlayerPositions();
|
||||
|
||||
private final DatabaseUtil util = DatabaseProvider.getInstance().getUtil();
|
||||
|
||||
|
||||
private PlayerPositions() {
|
||||
checkTables();
|
||||
}
|
||||
|
||||
public Location injectWorldsLocation(Player player, WorldConfig config, Location location) {
|
||||
if (!PluginConfig.useWorldSpawnLastLocation())
|
||||
return location;
|
||||
if (!util.isConnectionAvailable())
|
||||
return location;
|
||||
|
||||
Preconditions.checkNotNull(player);
|
||||
Preconditions.checkNotNull(config);
|
||||
Preconditions.checkNotNull(location);
|
||||
UUID uuid = player.getUniqueId();
|
||||
int id = config.getId();
|
||||
UUID owner = config.getOwner();
|
||||
String tableName = PluginConfig.getWorldsTableName();
|
||||
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("SELECT * FROM " + tableName + " WHERE player=? AND id=? AND owner=?");
|
||||
|
||||
ps.setString(1, uuid.toString());
|
||||
ps.setInt(2, id);
|
||||
ps.setString(3, owner.toString());
|
||||
ResultSet rs = util.executeQuery(ps);
|
||||
if (!rs.next())
|
||||
return location;
|
||||
|
||||
double x = rs.getDouble("x");
|
||||
double y = rs.getDouble("y");
|
||||
double z = rs.getDouble("z");
|
||||
|
||||
location.setX(x);
|
||||
location.setY(y);
|
||||
location.setZ(z);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
public Location injectPlayersLocation(Player player, Location location) {
|
||||
if (!PluginConfig.useSpawnLastLocation())
|
||||
return location;
|
||||
if (!util.isConnectionAvailable())
|
||||
return location;
|
||||
if (player == null)
|
||||
return location;
|
||||
Preconditions.checkNotNull(location);
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
String tableName = PluginConfig.getPlayersTableName();
|
||||
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("SELECT * FROM " + tableName + " WHERE player=?");
|
||||
|
||||
ps.setString(1, uuid.toString());
|
||||
ResultSet rs = util.executeQuery(ps);
|
||||
if (!rs.next())
|
||||
return location;
|
||||
|
||||
double x = rs.getDouble("x");
|
||||
double y = rs.getDouble("y");
|
||||
double z = rs.getDouble("z");
|
||||
|
||||
location.setX(x);
|
||||
location.setY(y);
|
||||
location.setZ(z);
|
||||
|
||||
String locWorldName = location.getWorld().getName();
|
||||
if (!locWorldName.equals(rs.getString("world"))) {
|
||||
World world = Bukkit.getWorld(rs.getString("world"));
|
||||
if (world != null) {
|
||||
location.setWorld(world);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
public void savePlayerLocation(Player player) {
|
||||
if (!PluginConfig.useSpawnLastLocation())
|
||||
return;
|
||||
if (!util.isConnectionAvailable())
|
||||
return;
|
||||
|
||||
Preconditions.checkNotNull(player);
|
||||
|
||||
String playersTableName = PluginConfig.getPlayersTableName();
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
Location location = player.getLocation();
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("REPLACE INTO " + playersTableName +
|
||||
" (player, world, x, y, z) VALUES (?, ?, ?, ?, ?)");
|
||||
|
||||
ps.setString(1, uuid.toString());
|
||||
ps.setString(2, location.getWorld().getName());
|
||||
|
||||
ps.setDouble(3, location.getX());
|
||||
ps.setDouble(4, location.getY());
|
||||
ps.setDouble(5, location.getZ());
|
||||
|
||||
util.executeUpdate(ps);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveWorldsPlayerLocation(Player player, WorldConfig config) {
|
||||
if (!PluginConfig.useWorldSpawnLastLocation())
|
||||
return;
|
||||
if (!util.isConnectionAvailable())
|
||||
return;
|
||||
|
||||
Preconditions.checkNotNull(player);
|
||||
Preconditions.checkNotNull(config);
|
||||
UUID uuid = player.getUniqueId();
|
||||
int id = config.getId();
|
||||
UUID owner = config.getOwner();
|
||||
Location location = player.getLocation();
|
||||
String tableName = PluginConfig.getWorldsTableName();
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("REPLACE INTO " + tableName +
|
||||
" (player, id, owner, x, y, z) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
|
||||
ps.setString(1, uuid.toString());
|
||||
ps.setInt(2, id);
|
||||
ps.setString(3, owner.toString());
|
||||
ps.setDouble(4, location.getX());
|
||||
ps.setDouble(5, location.getY());
|
||||
ps.setDouble(6, location.getZ());
|
||||
|
||||
util.executeUpdate(ps);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deletePositions(WorldConfig config) {
|
||||
Preconditions.checkNotNull(config);
|
||||
if (!util.isConnectionAvailable())
|
||||
return;
|
||||
|
||||
String tableName = PluginConfig.getWorldsTableName();
|
||||
|
||||
int id = config.getId();
|
||||
UUID owner = config.getOwner();
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("DELETE FROM " + tableName +
|
||||
" WHERE id=? AND owner=?");
|
||||
|
||||
ps.setInt(1, id);
|
||||
ps.setString(2, owner.toString());
|
||||
|
||||
util.executeUpdate(ps);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void checkTables() {
|
||||
if (!util.isConnectionAvailable())
|
||||
return;
|
||||
|
||||
String worldsTableName = PluginConfig.getWorldsTableName();
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + worldsTableName +
|
||||
" ( `player` VARCHAR(36) NOT NULL , `id` INT NOT NULL , `owner` VARCHAR(36) NOT NULL , " +
|
||||
"`x` DOUBLE NOT NULL , `y` DOUBLE NOT NULL , `z` DOUBLE NOT NULL , PRIMARY KEY (`player`, `id`, `owner`))");
|
||||
|
||||
util.executeUpdate(ps);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String playersTableName = PluginConfig.getPlayersTableName();
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + playersTableName +
|
||||
"( `player` VARCHAR(36) NOT NULL , `world` TEXT NOT NULL , " +
|
||||
"`x` DOUBLE NOT NULL , `y` DOUBLE NOT NULL , `z` DOUBLE NOT NULL , PRIMARY KEY (`player`))");
|
||||
|
||||
util.executeUpdate(ps);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.butzlabben.world.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import de.butzlabben.world.config.PluginConfig;
|
||||
import de.butzlabben.world.config.WorldConfig;
|
||||
import de.butzlabben.world.util.database.DatabaseProvider;
|
||||
import de.butzlabben.world.util.database.DatabaseUtil;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/*
|
||||
Class for implementing #23
|
||||
*/
|
||||
public class PlayerPositions {
|
||||
|
||||
@Getter
|
||||
private static PlayerPositions instance = new PlayerPositions();
|
||||
|
||||
private final DatabaseUtil util = DatabaseProvider.getInstance().getUtil();
|
||||
|
||||
|
||||
private PlayerPositions() {
|
||||
checkTables();
|
||||
}
|
||||
|
||||
public Location injectWorldsLocation(Player player, WorldConfig config, Location location) {
|
||||
if (!PluginConfig.useWorldSpawnLastLocation())
|
||||
return location;
|
||||
if (!util.isConnectionAvailable())
|
||||
return location;
|
||||
|
||||
Preconditions.checkNotNull(player);
|
||||
Preconditions.checkNotNull(config);
|
||||
Preconditions.checkNotNull(location);
|
||||
UUID uuid = player.getUniqueId();
|
||||
int id = config.getId();
|
||||
UUID owner = config.getOwner();
|
||||
String tableName = PluginConfig.getWorldsTableName();
|
||||
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("SELECT * FROM " + tableName + " WHERE player=? AND id=? AND owner=?");
|
||||
|
||||
ps.setString(1, uuid.toString());
|
||||
ps.setInt(2, id);
|
||||
ps.setString(3, owner.toString());
|
||||
ResultSet rs = util.executeQuery(ps);
|
||||
if (!rs.next())
|
||||
return location;
|
||||
|
||||
double x = rs.getDouble("x");
|
||||
double y = rs.getDouble("y");
|
||||
double z = rs.getDouble("z");
|
||||
|
||||
location.setX(x);
|
||||
location.setY(y);
|
||||
location.setZ(z);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
public Location injectPlayersLocation(Player player, Location location) {
|
||||
if (!PluginConfig.useSpawnLastLocation())
|
||||
return location;
|
||||
if (!util.isConnectionAvailable())
|
||||
return location;
|
||||
if (player == null)
|
||||
return location;
|
||||
Preconditions.checkNotNull(location);
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
String tableName = PluginConfig.getPlayersTableName();
|
||||
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("SELECT * FROM " + tableName + " WHERE player=?");
|
||||
|
||||
ps.setString(1, uuid.toString());
|
||||
ResultSet rs = util.executeQuery(ps);
|
||||
if (!rs.next())
|
||||
return location;
|
||||
|
||||
double x = rs.getDouble("x");
|
||||
double y = rs.getDouble("y");
|
||||
double z = rs.getDouble("z");
|
||||
|
||||
location.setX(x);
|
||||
location.setY(y);
|
||||
location.setZ(z);
|
||||
|
||||
World locationWorld = location.getWorld();
|
||||
if (locationWorld == null || !locationWorld.getName().equals(rs.getString("world"))) {
|
||||
World world = Bukkit.getWorld(rs.getString("world"));
|
||||
if (world != null) {
|
||||
location.setWorld(world);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
public void savePlayerLocation(Player player) {
|
||||
if (!PluginConfig.useSpawnLastLocation())
|
||||
return;
|
||||
if (!util.isConnectionAvailable())
|
||||
return;
|
||||
|
||||
Preconditions.checkNotNull(player);
|
||||
|
||||
String playersTableName = PluginConfig.getPlayersTableName();
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
Location location = player.getLocation();
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("REPLACE INTO " + playersTableName +
|
||||
" (player, world, x, y, z) VALUES (?, ?, ?, ?, ?)");
|
||||
|
||||
ps.setString(1, uuid.toString());
|
||||
ps.setString(2, location.getWorld().getName());
|
||||
|
||||
ps.setDouble(3, location.getX());
|
||||
ps.setDouble(4, location.getY());
|
||||
ps.setDouble(5, location.getZ());
|
||||
|
||||
util.executeUpdate(ps);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveWorldsPlayerLocation(Player player, WorldConfig config) {
|
||||
if (!PluginConfig.useWorldSpawnLastLocation())
|
||||
return;
|
||||
if (!util.isConnectionAvailable())
|
||||
return;
|
||||
|
||||
Preconditions.checkNotNull(player);
|
||||
Preconditions.checkNotNull(config);
|
||||
UUID uuid = player.getUniqueId();
|
||||
int id = config.getId();
|
||||
UUID owner = config.getOwner();
|
||||
Location location = player.getLocation();
|
||||
String tableName = PluginConfig.getWorldsTableName();
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("REPLACE INTO " + tableName +
|
||||
" (player, id, owner, x, y, z) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
|
||||
ps.setString(1, uuid.toString());
|
||||
ps.setInt(2, id);
|
||||
ps.setString(3, owner.toString());
|
||||
ps.setDouble(4, location.getX());
|
||||
ps.setDouble(5, location.getY());
|
||||
ps.setDouble(6, location.getZ());
|
||||
|
||||
util.executeUpdate(ps);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deletePositions(WorldConfig config) {
|
||||
Preconditions.checkNotNull(config);
|
||||
if (!util.isConnectionAvailable())
|
||||
return;
|
||||
|
||||
String tableName = PluginConfig.getWorldsTableName();
|
||||
|
||||
int id = config.getId();
|
||||
UUID owner = config.getOwner();
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("DELETE FROM " + tableName +
|
||||
" WHERE id=? AND owner=?");
|
||||
|
||||
ps.setInt(1, id);
|
||||
ps.setString(2, owner.toString());
|
||||
|
||||
util.executeUpdate(ps);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void checkTables() {
|
||||
if (!util.isConnectionAvailable())
|
||||
return;
|
||||
|
||||
String worldsTableName = PluginConfig.getWorldsTableName();
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + worldsTableName +
|
||||
" ( `player` VARCHAR(36) NOT NULL , `id` INT NOT NULL , `owner` VARCHAR(36) NOT NULL , " +
|
||||
"`x` DOUBLE NOT NULL , `y` DOUBLE NOT NULL , `z` DOUBLE NOT NULL , PRIMARY KEY (`player`, `id`, `owner`))");
|
||||
|
||||
util.executeUpdate(ps);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String playersTableName = PluginConfig.getPlayersTableName();
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + playersTableName +
|
||||
"( `player` VARCHAR(36) NOT NULL , `world` TEXT NOT NULL , " +
|
||||
"`x` DOUBLE NOT NULL , `y` DOUBLE NOT NULL , `z` DOUBLE NOT NULL , PRIMARY KEY (`player`))");
|
||||
|
||||
util.executeUpdate(ps);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue