mirror of
https://github.com/trainerlord/WorldSystem.git
synced 2025-02-07 23:51:28 +01:00
Fixed #23
This commit is contained in:
parent
1f02b57adb
commit
0358a634b2
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.butzlabben.world</groupId>
|
<groupId>de.butzlabben.world</groupId>
|
||||||
<artifactId>WorldSystem</artifactId>
|
<artifactId>WorldSystem</artifactId>
|
||||||
<version>2.4.4.2</version>
|
<version>2.4.5</version>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.build.number>-</project.build.number>
|
<project.build.number>-</project.build.number>
|
||||||
|
@ -5,6 +5,7 @@ import de.butzlabben.world.command.*;
|
|||||||
import de.butzlabben.world.config.*;
|
import de.butzlabben.world.config.*;
|
||||||
import de.butzlabben.world.listener.*;
|
import de.butzlabben.world.listener.*;
|
||||||
import de.butzlabben.world.util.PapiExtension;
|
import de.butzlabben.world.util.PapiExtension;
|
||||||
|
import de.butzlabben.world.util.database.DatabaseRepository;
|
||||||
import de.butzlabben.world.wrapper.AsyncCreatorAdapter;
|
import de.butzlabben.world.wrapper.AsyncCreatorAdapter;
|
||||||
import de.butzlabben.world.wrapper.CreatorAdapter;
|
import de.butzlabben.world.wrapper.CreatorAdapter;
|
||||||
import de.butzlabben.world.wrapper.SystemWorld;
|
import de.butzlabben.world.wrapper.SystemWorld;
|
||||||
@ -83,6 +84,9 @@ public class WorldSystem extends JavaPlugin {
|
|||||||
framework.registerCommands(new WorldAdministrateCommand());
|
framework.registerCommands(new WorldAdministrateCommand());
|
||||||
|
|
||||||
|
|
||||||
|
// Establish database connection
|
||||||
|
DatabaseRepository.getInstance().getUtil().connect();
|
||||||
|
|
||||||
System.setProperty("bstats.relocatecheck", "false");
|
System.setProperty("bstats.relocatecheck", "false");
|
||||||
Metrics m = new Metrics(this);
|
Metrics m = new Metrics(this);
|
||||||
m.addCustomChart(new Metrics.SingleLineChart("worlds", DependenceConfig::getHighestID));
|
m.addCustomChart(new Metrics.SingleLineChart("worlds", DependenceConfig::getHighestID));
|
||||||
@ -126,6 +130,9 @@ public class WorldSystem extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close database connection
|
||||||
|
DatabaseRepository.getInstance().getUtil().close();
|
||||||
|
|
||||||
Bukkit.getConsoleSender()
|
Bukkit.getConsoleSender()
|
||||||
.sendMessage(PluginConfig.getPrefix() + "Succesfully disabled WorldSystem v" + version);
|
.sendMessage(PluginConfig.getPrefix() + "Succesfully disabled WorldSystem v" + version);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ public class PluginConfig {
|
|||||||
&& (cfg.isDouble("spawn.spawnpoint.yaw") || cfg.isInt("spawn.spawnpoint.yaw"))
|
&& (cfg.isDouble("spawn.spawnpoint.yaw") || cfg.isInt("spawn.spawnpoint.yaw"))
|
||||||
&& (cfg.isDouble("spawn.spawnpoint.pitch") || cfg.isInt("spawn.spawnpoint.pitch")) &&
|
&& (cfg.isDouble("spawn.spawnpoint.pitch") || cfg.isInt("spawn.spawnpoint.pitch")) &&
|
||||||
|
|
||||||
cfg.isBoolean("worldspawn.use")
|
cfg.isBoolean("worldspawn.use") && cfg.isBoolean("worldspawn.use_last_location")
|
||||||
&& (cfg.isDouble("worldspawn.spawnpoint.x") || cfg.isInt("worldspawn.spawnpoint.x"))
|
&& (cfg.isDouble("worldspawn.spawnpoint.x") || cfg.isInt("worldspawn.spawnpoint.x"))
|
||||||
&& (cfg.isDouble("worldspawn.spawnpoint.y") || cfg.isInt("worldspawn.spawnpoint.y"))
|
&& (cfg.isDouble("worldspawn.spawnpoint.y") || cfg.isInt("worldspawn.spawnpoint.y"))
|
||||||
&& (cfg.isDouble("worldspawn.spawnpoint.z") || cfg.isInt("worldspawn.spawnpoint.z"))
|
&& (cfg.isDouble("worldspawn.spawnpoint.z") || cfg.isInt("worldspawn.spawnpoint.z"))
|
||||||
@ -249,7 +249,11 @@ public class PluginConfig {
|
|||||||
return creator;
|
return creator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTablename() {
|
public static boolean useLastLocation() {
|
||||||
|
return getConfig().getBoolean("worldspawn.use_last_location");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTableName() {
|
||||||
return getConfig().getString("database.table_name");
|
return getConfig().getString("database.table_name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package de.butzlabben.world.listener;
|
|||||||
import de.butzlabben.world.config.MessageConfig;
|
import de.butzlabben.world.config.MessageConfig;
|
||||||
import de.butzlabben.world.config.PluginConfig;
|
import de.butzlabben.world.config.PluginConfig;
|
||||||
import de.butzlabben.world.config.WorldConfig;
|
import de.butzlabben.world.config.WorldConfig;
|
||||||
|
import de.butzlabben.world.util.PlayerPositions;
|
||||||
import de.butzlabben.world.wrapper.SystemWorld;
|
import de.butzlabben.world.wrapper.SystemWorld;
|
||||||
import de.butzlabben.world.wrapper.WorldPlayer;
|
import de.butzlabben.world.wrapper.WorldPlayer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -60,6 +61,11 @@ public class CommandListener implements Listener {
|
|||||||
|
|
||||||
// Fix for #18
|
// Fix for #18
|
||||||
if (from != to || WorldConfig.exists(from.getName())) {
|
if (from != to || WorldConfig.exists(from.getName())) {
|
||||||
|
// Save location for #23
|
||||||
|
if(WorldConfig.exists(from.getName())) {
|
||||||
|
WorldConfig config = WorldConfig.getWorldConfig(from.getName());
|
||||||
|
PlayerPositions.getInstance().savePlayerLocation(p, config);
|
||||||
|
}
|
||||||
GameMode gameMode = PluginConfig.getSpawnGamemode();
|
GameMode gameMode = PluginConfig.getSpawnGamemode();
|
||||||
if (WorldConfig.exists(to.getName())) {
|
if (WorldConfig.exists(to.getName())) {
|
||||||
if (PluginConfig.isSurvival()) {
|
if (PluginConfig.isSurvival()) {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package de.butzlabben.world.listener;
|
package de.butzlabben.world.listener;
|
||||||
|
|
||||||
|
import de.butzlabben.world.config.WorldConfig;
|
||||||
|
import de.butzlabben.world.util.PlayerPositions;
|
||||||
|
import de.butzlabben.world.wrapper.WorldPlayer;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -33,6 +36,12 @@ public class PlayerListener implements Listener {
|
|||||||
public void onLeave(PlayerQuitEvent e) {
|
public void onLeave(PlayerQuitEvent e) {
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
World w = p.getWorld();
|
World w = p.getWorld();
|
||||||
|
WorldPlayer player = new WorldPlayer(p);
|
||||||
|
// Save last location for #23
|
||||||
|
if (player.isOnSystemWorld()) {
|
||||||
|
WorldConfig config = WorldConfig.getWorldConfig(player.getWorldname());
|
||||||
|
PlayerPositions.getInstance().savePlayerLocation(p, config);
|
||||||
|
}
|
||||||
SystemWorld.tryUnloadLater(w);
|
SystemWorld.tryUnloadLater(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
107
src/main/java/de/butzlabben/world/util/PlayerPositions.java
Normal file
107
src/main/java/de/butzlabben/world/util/PlayerPositions.java
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
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.DatabaseRepository;
|
||||||
|
import de.butzlabben.world.util.database.DatabaseUtil;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public class PlayerPositions {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static PlayerPositions instance = new PlayerPositions();
|
||||||
|
|
||||||
|
private DatabaseUtil util = DatabaseRepository.getInstance().getUtil();
|
||||||
|
|
||||||
|
public Location injectLocation(Player player, WorldConfig config, Location location) {
|
||||||
|
if (!PluginConfig.useLastLocation())
|
||||||
|
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.getTableName();
|
||||||
|
|
||||||
|
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 void savePlayerLocation(Player player, WorldConfig config) {
|
||||||
|
if (!PluginConfig.useLastLocation())
|
||||||
|
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.getTableName();
|
||||||
|
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 checkTables() {
|
||||||
|
String tableName = PluginConfig.getTableName();
|
||||||
|
try {
|
||||||
|
PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + tableName +
|
||||||
|
" ( `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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PlayerPositions() {
|
||||||
|
checkTables();
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,4 @@
|
|||||||
package de.butzlabben.world.util;
|
package de.butzlabben.world.util.database;
|
||||||
|
|
||||||
import de.butzlabben.world.config.PluginConfig;
|
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package de.butzlabben.world.util;
|
package de.butzlabben.world.util.database;
|
||||||
|
|
||||||
import de.butzlabben.world.config.PluginConfig;
|
import de.butzlabben.world.config.PluginConfig;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
@ -1,4 +1,4 @@
|
|||||||
package de.butzlabben.world.util;
|
package de.butzlabben.world.util.database;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
@ -1,4 +1,4 @@
|
|||||||
package de.butzlabben.world.util;
|
package de.butzlabben.world.util.database;
|
||||||
|
|
||||||
import de.butzlabben.world.config.PluginConfig;
|
import de.butzlabben.world.config.PluginConfig;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package de.butzlabben.world.util;
|
package de.butzlabben.world.util.database;
|
||||||
|
|
||||||
import de.butzlabben.world.config.PluginConfig;
|
import de.butzlabben.world.config.PluginConfig;
|
||||||
|
|
@ -6,6 +6,7 @@ import de.butzlabben.world.config.*;
|
|||||||
import de.butzlabben.world.event.WorldCreateEvent;
|
import de.butzlabben.world.event.WorldCreateEvent;
|
||||||
import de.butzlabben.world.event.WorldLoadEvent;
|
import de.butzlabben.world.event.WorldLoadEvent;
|
||||||
import de.butzlabben.world.event.WorldUnloadEvent;
|
import de.butzlabben.world.event.WorldUnloadEvent;
|
||||||
|
import de.butzlabben.world.util.PlayerPositions;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -370,6 +371,7 @@ public class SystemWorld {
|
|||||||
public void teleportToWorldSpawn(Player p) {
|
public void teleportToWorldSpawn(Player p) {
|
||||||
Preconditions.checkNotNull(p, "player must not be null");
|
Preconditions.checkNotNull(p, "player must not be null");
|
||||||
Preconditions.checkArgument(p.isOnline(), "player must be online");
|
Preconditions.checkArgument(p.isOnline(), "player must be online");
|
||||||
|
PlayerPositions positions = PlayerPositions.getInstance();
|
||||||
|
|
||||||
if (creating) {
|
if (creating) {
|
||||||
p.sendMessage(MessageConfig.getWorldStillCreating());
|
p.sendMessage(MessageConfig.getWorldStillCreating());
|
||||||
@ -383,12 +385,12 @@ public class SystemWorld {
|
|||||||
|
|
||||||
WorldConfig config = WorldConfig.getWorldConfig(worldname);
|
WorldConfig config = WorldConfig.getWorldConfig(worldname);
|
||||||
if (config.getHome() != null) {
|
if (config.getHome() != null) {
|
||||||
p.teleport(config.getHome());
|
p.teleport(positions.injectLocation(p, config, config.getHome()));
|
||||||
} else {
|
} else {
|
||||||
if (PluginConfig.useWorldSpawn()) {
|
if (PluginConfig.useWorldSpawn()) {
|
||||||
p.teleport(PluginConfig.getWorldSpawn(w));
|
p.teleport(positions.injectLocation(p, config, PluginConfig.getWorldSpawn(w)));
|
||||||
} else {
|
} else {
|
||||||
p.teleport(w.getSpawnLocation());
|
p.teleport(positions.injectLocation(p, config, w.getSpawnLocation()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (PluginConfig.isSurvival()) {
|
if (PluginConfig.isSurvival()) {
|
||||||
|
@ -122,6 +122,7 @@ spawn:
|
|||||||
|
|
||||||
# Location where you spawn when you join a world
|
# Location where you spawn when you join a world
|
||||||
worldspawn:
|
worldspawn:
|
||||||
|
use_last_location: true
|
||||||
use: false
|
use: false
|
||||||
spawnpoint:
|
spawnpoint:
|
||||||
x: 0
|
x: 0
|
||||||
|
Loading…
Reference in New Issue
Block a user