From dca43b6c57d43166c291a39fde153ecf4120dc2d Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 3 Jul 2017 00:36:54 +0100 Subject: [PATCH] Separate Gem Hunters inventories by region --- .../gemhunters/persistence/PersistenceData.java | 10 +++++++++- .../persistence/PersistenceModule.java | 5 ++++- .../persistence/PersistenceRepository.java | 16 +++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java index fed987d21..3ab3ed48f 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java @@ -1,12 +1,14 @@ package mineplex.gemhunters.persistence; import mineplex.gemhunters.quest.QuestPlayerData; +import mineplex.serverdata.Region; import org.bukkit.Location; import org.bukkit.inventory.ItemStack; public class PersistenceData { + private final Region _region; private final int _gems; private final Location _location; private final QuestPlayerData _questData; @@ -19,8 +21,9 @@ public class PersistenceData private final long _saveTime; private final int _cashOutTime; - public PersistenceData(int gems, Location location, QuestPlayerData questData, int health, int maxHealth, int hunger, int slots, ItemStack[] items, ItemStack[] armour, long saveTime, int cashOutTime) + public PersistenceData(Region region, int gems, Location location, QuestPlayerData questData, int health, int maxHealth, int hunger, int slots, ItemStack[] items, ItemStack[] armour, long saveTime, int cashOutTime) { + _region = region; _gems = gems; _location = location; _questData = questData; @@ -34,6 +37,11 @@ public class PersistenceData _cashOutTime = cashOutTime; } + public Region getRegion() + { + return _region; + } + public int getGems() { return _gems; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java index 322f25d54..aeaf4da47 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import mineplex.core.common.util.UtilServer; +import mineplex.serverdata.Region; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -84,6 +86,7 @@ public class PersistenceModule extends MiniPlugin return; } + Region region = UtilServer.getRegion(); int gems = _economy.Get(player); Location location = player.getLocation(); QuestPlayerData quest = _quest.Get(player); @@ -106,7 +109,7 @@ public class PersistenceModule extends MiniPlugin cashOutTime = (int) rechargeData.GetRemaining(); } - PersistenceData data = new PersistenceData(gems, location, quest, health, maxHealth, hunger, slots, items, armour, saveTime, cashOutTime); + PersistenceData data = new PersistenceData(region, gems, location, quest, health, maxHealth, hunger, slots, items, armour, saveTime, cashOutTime); runAsync(() -> { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java index cab1e644a..3f6bcf360 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java @@ -2,7 +2,9 @@ package mineplex.gemhunters.persistence; import com.google.gson.Gson; import mineplex.core.account.CoreClient; +import mineplex.core.common.util.UtilServer; import mineplex.gemhunters.quest.QuestPlayerData; +import mineplex.serverdata.Region; import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.RepositoryBase; import mineplex.serverdata.database.column.ColumnInt; @@ -25,9 +27,9 @@ import java.util.function.Consumer; public class PersistenceRepository extends RepositoryBase { - private static final String GET_DATA = "SELECT * FROM gemHunters WHERE accountId=?;"; - private static final String INSERT_DATA = "INSERT INTO gemHunters VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; - private static final String UPDATE_DATA = "UPDATE gemHunters SET gems=?,health=?,maxHealth=?,hunger=?,x=?,y=?,z=?,yaw=?,pitch=?,quests=?,slots=?,items=?,armour=?,saveTime=?,cashOutTime=? WHERE accountId=?;"; + private static final String GET_DATA = "SELECT * FROM gemHunters WHERE accountId=? AND region=?;"; + private static final String INSERT_DATA = "INSERT INTO gemHunters VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; + private static final String UPDATE_DATA = "UPDATE gemHunters SET region=?,gems=?,health=?,maxHealth=?,hunger=?,x=?,y=?,z=?,yaw=?,pitch=?,quests=?,slots=?,items=?,armour=?,saveTime=?,cashOutTime=? WHERE accountId=?;"; private static final String DELETE_DATA = "DELETE FROM gemHunters WHERE accountId=?;"; private static final Gson GSON; private static final ItemStack AIR = new ItemStack(Material.AIR); @@ -49,6 +51,7 @@ public class PersistenceRepository extends RepositoryBase public void getPersistenceData(Consumer response, CoreClient client) { int accountId = client.getAccountId(); + Region region = UtilServer.getRegion(); executeQuery(GET_DATA, resultSet -> { @@ -111,16 +114,17 @@ public class PersistenceRepository extends RepositoryBase _exists.add(accountId); Location location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch); - PersistenceData data = new PersistenceData(gems, location, questData, health, maxHealth, hunger, slots, itemsList.toArray(new ItemStack[0]), armourList.toArray(new ItemStack[0]), saveTime.getTime(), cashOutTime); + PersistenceData data = new PersistenceData(region, gems, location, questData, health, maxHealth, hunger, slots, itemsList.toArray(new ItemStack[0]), armourList.toArray(new ItemStack[0]), saveTime.getTime(), cashOutTime); response.accept(data); } - }, new ColumnInt("accountId", accountId)); + }, new ColumnInt("accountId", accountId), new ColumnVarChar("region", 2, region.toString())); } public void savePersistence(CoreClient client, PersistenceData data) { int accountId = client.getAccountId(); + Region region = data.getRegion(); int gems = data.getGems(); int health = data.getHealth(); int maxHealth = data.getMaxHealth(); @@ -161,6 +165,7 @@ public class PersistenceRepository extends RepositoryBase if (exists(client)) { executeUpdate(UPDATE_DATA, + new ColumnVarChar("region", 2, region.toString()), new ColumnInt("gems", gems), new ColumnInt("health", health), new ColumnInt("maxHealth", maxHealth), @@ -183,6 +188,7 @@ public class PersistenceRepository extends RepositoryBase { executeInsert(INSERT_DATA, null, new ColumnInt("accountId", accountId), + new ColumnVarChar("region", 2, region.toString()), new ColumnInt("gems", gems), new ColumnInt("health", health), new ColumnInt("maxHealth", maxHealth),