save entry location in database
This commit is contained in:
parent
4b2203e5ae
commit
89de8b6ab5
@ -61,7 +61,11 @@ public final class PixelBlocks extends JavaPlugin {
|
|||||||
"locationWorldName CHAR(36), " +
|
"locationWorldName CHAR(36), " +
|
||||||
"locationX DOUBLE, " +
|
"locationX DOUBLE, " +
|
||||||
"locationY DOUBLE, " +
|
"locationY DOUBLE, " +
|
||||||
"locationZ DOUBLE" +
|
"locationZ DOUBLE, " +
|
||||||
|
"entryLocationWorldName CHAR(36), " +
|
||||||
|
"entryLocationX DOUBLE, " +
|
||||||
|
"entryLocationY DOUBLE, " +
|
||||||
|
"entryLocationZ DOUBLE" +
|
||||||
");";
|
");";
|
||||||
|
|
||||||
try (var conn = DriverManager.getConnection(url);
|
try (var conn = DriverManager.getConnection(url);
|
||||||
@ -75,7 +79,15 @@ public final class PixelBlocks extends JavaPlugin {
|
|||||||
Bukkit.getWorld(pixelBlocksResult.getString("locationWorldName")),
|
Bukkit.getWorld(pixelBlocksResult.getString("locationWorldName")),
|
||||||
pixelBlocksResult.getDouble("locationX"),
|
pixelBlocksResult.getDouble("locationX"),
|
||||||
pixelBlocksResult.getDouble("locationY"),
|
pixelBlocksResult.getDouble("locationY"),
|
||||||
pixelBlocksResult.getDouble("locationZ"));
|
pixelBlocksResult.getDouble("locationZ")
|
||||||
|
);
|
||||||
|
|
||||||
|
Location newEntryLocation = new Location(
|
||||||
|
Bukkit.getWorld(pixelBlocksResult.getString("entryLocationWorldName")),
|
||||||
|
pixelBlocksResult.getDouble("entryLocationX"),
|
||||||
|
pixelBlocksResult.getDouble("entryLocationY"),
|
||||||
|
pixelBlocksResult.getDouble("entryLocationZ")
|
||||||
|
);
|
||||||
|
|
||||||
entities.stream().filter(entity -> entity.getLocation().clone().add(0, PixelBlock.hitboxOffset, 0).toBlockLocation().equals(newPixelBlockLocation)).forEach(Entity::remove);
|
entities.stream().filter(entity -> entity.getLocation().clone().add(0, PixelBlock.hitboxOffset, 0).toBlockLocation().equals(newPixelBlockLocation)).forEach(Entity::remove);
|
||||||
|
|
||||||
@ -85,6 +97,7 @@ public final class PixelBlocks extends JavaPlugin {
|
|||||||
16,
|
16,
|
||||||
UUID.fromString(pixelBlocksResult.getString("uuid"))
|
UUID.fromString(pixelBlocksResult.getString("uuid"))
|
||||||
);
|
);
|
||||||
|
newPixelBlock.lastEntryLocation = newEntryLocation;
|
||||||
newPixelBlock.place(newPixelBlockLocation);
|
newPixelBlock.place(newPixelBlockLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,19 +16,19 @@ import java.util.*;
|
|||||||
import static eu.mhsl.minecraft.pixelblocks.PixelBlocks.plugin;
|
import static eu.mhsl.minecraft.pixelblocks.PixelBlocks.plugin;
|
||||||
|
|
||||||
public class PlayerInteractListener implements Listener {
|
public class PlayerInteractListener implements Listener {
|
||||||
@EventHandler
|
// @EventHandler
|
||||||
static void onPlayerInteract(PlayerInteractEvent event) {
|
// static void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null) {
|
// if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null) {
|
||||||
if(event.getClickedBlock().getType() == Material.GLASS) {
|
// if(event.getClickedBlock().getType() == Material.GLASS) {
|
||||||
// final WorldCreator worldCreator = new WorldCreator(plugin.getDataFolder().getPath()+"/"+event.getPlayer().getUniqueId());
|
//// final WorldCreator worldCreator = new WorldCreator(plugin.getDataFolder().getPath()+"/"+event.getPlayer().getUniqueId());
|
||||||
// worldCreator.type(WorldType.FLAT);
|
//// worldCreator.type(WorldType.FLAT);
|
||||||
//
|
////
|
||||||
// World newWorld = Bukkit.createWorld(worldCreator);
|
//// World newWorld = Bukkit.createWorld(worldCreator);
|
||||||
//
|
////
|
||||||
// event.getPlayer().teleport(newWorld.getSpawnLocation());
|
//// event.getPlayer().teleport(newWorld.getSpawnLocation());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
static void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
static void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||||
@ -47,6 +47,7 @@ public class PlayerInteractListener implements Listener {
|
|||||||
if(playerUID.equals(blockOwner)) {
|
if(playerUID.equals(blockOwner)) {
|
||||||
pixelBlock.lastEntryLocation = event.getPlayer().getLocation();
|
pixelBlock.lastEntryLocation = event.getPlayer().getLocation();
|
||||||
pixelBlock.lastEntryTime = System.currentTimeMillis();
|
pixelBlock.lastEntryTime = System.currentTimeMillis();
|
||||||
|
pixelBlock.saveToDB();
|
||||||
|
|
||||||
World blockWorld = Bukkit.getWorld(plugin.getDataFolder().getPath()+ "/" +pixelBlock.uuid);
|
World blockWorld = Bukkit.getWorld(plugin.getDataFolder().getPath()+ "/" +pixelBlock.uuid);
|
||||||
assert blockWorld != null;
|
assert blockWorld != null;
|
||||||
|
@ -136,16 +136,64 @@ public class PixelBlock {
|
|||||||
if(!uuids.contains(this.uuid)) {
|
if(!uuids.contains(this.uuid)) {
|
||||||
try (var conn = DriverManager.getConnection(url)) {
|
try (var conn = DriverManager.getConnection(url)) {
|
||||||
PreparedStatement prep = conn.prepareStatement(
|
PreparedStatement prep = conn.prepareStatement(
|
||||||
"INSERT INTO pixelblocks(uuid, owner, locationWorldName, locationX, locationY, locationZ)" +
|
"INSERT INTO pixelblocks(uuid, owner, " +
|
||||||
" VALUES(?, ?, ?, ?, ?, ?);"
|
"locationWorldName, locationX, locationY, locationZ, " +
|
||||||
|
"entryLocationWorldName, entryLocationX, entryLocationY, entryLocationZ) " +
|
||||||
|
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"
|
||||||
);
|
);
|
||||||
prep.setString(1, this.uuid.toString());
|
prep.setString(1, this.uuid.toString());
|
||||||
prep.setString(2, this.owner.toString());
|
prep.setString(2, this.owner.toString());
|
||||||
|
|
||||||
prep.setString(3, this.pixelBlockLocation.getWorld().getName());
|
prep.setString(3, this.pixelBlockLocation.getWorld().getName());
|
||||||
prep.setDouble(4, this.pixelBlockLocation.getX());
|
prep.setDouble(4, this.pixelBlockLocation.getX());
|
||||||
prep.setDouble(5, this.pixelBlockLocation.getY());
|
prep.setDouble(5, this.pixelBlockLocation.getY());
|
||||||
prep.setDouble(6, this.pixelBlockLocation.getZ());
|
prep.setDouble(6, this.pixelBlockLocation.getZ());
|
||||||
|
|
||||||
|
if(this.lastEntryLocation != null) {
|
||||||
|
prep.setString(7, this.lastEntryLocation.getWorld().getName());
|
||||||
|
prep.setDouble(8, this.lastEntryLocation.getX());
|
||||||
|
prep.setDouble(9, this.lastEntryLocation.getY());
|
||||||
|
prep.setDouble(10, this.lastEntryLocation.getZ());
|
||||||
|
} else {
|
||||||
|
prep.setString(7, Bukkit.getWorlds().getFirst().getName());
|
||||||
|
prep.setDouble(8, Bukkit.getWorlds().getFirst().getSpawnLocation().getX());
|
||||||
|
prep.setDouble(9, Bukkit.getWorlds().getFirst().getSpawnLocation().getY());
|
||||||
|
prep.setDouble(10, Bukkit.getWorlds().getFirst().getSpawnLocation().getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
prep.executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.err.println(e.getMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try (var conn = DriverManager.getConnection(url)) {
|
||||||
|
PreparedStatement prep = conn.prepareStatement(
|
||||||
|
"UPDATE pixelblocks " +
|
||||||
|
"SET owner=?, locationWorldName=?, locationX=?, locationY=?, locationZ=?," +
|
||||||
|
"entryLocationWorldName=?, entryLocationX=?, entryLocationY=?, entryLocationZ=? " +
|
||||||
|
"WHERE uuid=?;"
|
||||||
|
);
|
||||||
|
prep.setString(1, this.owner.toString());
|
||||||
|
|
||||||
|
prep.setString(2, this.pixelBlockLocation.getWorld().getName());
|
||||||
|
prep.setDouble(3, this.pixelBlockLocation.getX());
|
||||||
|
prep.setDouble(4, this.pixelBlockLocation.getY());
|
||||||
|
prep.setDouble(5, this.pixelBlockLocation.getZ());
|
||||||
|
|
||||||
|
if(this.lastEntryLocation != null) {
|
||||||
|
prep.setString(6, this.lastEntryLocation.getWorld().getName());
|
||||||
|
prep.setDouble(7, this.lastEntryLocation.getX());
|
||||||
|
prep.setDouble(8, this.lastEntryLocation.getY());
|
||||||
|
prep.setDouble(9, this.lastEntryLocation.getZ());
|
||||||
|
} else {
|
||||||
|
prep.setString(6, Bukkit.getWorlds().getFirst().getName());
|
||||||
|
prep.setDouble(7, Bukkit.getWorlds().getFirst().getSpawnLocation().getX());
|
||||||
|
prep.setDouble(8, Bukkit.getWorlds().getFirst().getSpawnLocation().getY());
|
||||||
|
prep.setDouble(9, Bukkit.getWorlds().getFirst().getSpawnLocation().getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
prep.setString(10, this.uuid.toString());
|
||||||
|
|
||||||
prep.executeUpdate();
|
prep.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getMessage());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user