Separate Gem Hunters inventories by region

This commit is contained in:
Sam 2017-07-03 00:36:54 +01:00
parent 5a4fab5fc0
commit dca43b6c57
3 changed files with 24 additions and 7 deletions

View File

@ -1,12 +1,14 @@
package mineplex.gemhunters.persistence; package mineplex.gemhunters.persistence;
import mineplex.gemhunters.quest.QuestPlayerData; import mineplex.gemhunters.quest.QuestPlayerData;
import mineplex.serverdata.Region;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class PersistenceData public class PersistenceData
{ {
private final Region _region;
private final int _gems; private final int _gems;
private final Location _location; private final Location _location;
private final QuestPlayerData _questData; private final QuestPlayerData _questData;
@ -19,8 +21,9 @@ public class PersistenceData
private final long _saveTime; private final long _saveTime;
private final int _cashOutTime; 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; _gems = gems;
_location = location; _location = location;
_questData = questData; _questData = questData;
@ -34,6 +37,11 @@ public class PersistenceData
_cashOutTime = cashOutTime; _cashOutTime = cashOutTime;
} }
public Region getRegion()
{
return _region;
}
public int getGems() public int getGems()
{ {
return _gems; return _gems;

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import mineplex.core.common.util.UtilServer;
import mineplex.serverdata.Region;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -84,6 +86,7 @@ public class PersistenceModule extends MiniPlugin
return; return;
} }
Region region = UtilServer.getRegion();
int gems = _economy.Get(player); int gems = _economy.Get(player);
Location location = player.getLocation(); Location location = player.getLocation();
QuestPlayerData quest = _quest.Get(player); QuestPlayerData quest = _quest.Get(player);
@ -106,7 +109,7 @@ public class PersistenceModule extends MiniPlugin
cashOutTime = (int) rechargeData.GetRemaining(); 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(() -> runAsync(() ->
{ {

View File

@ -2,7 +2,9 @@ package mineplex.gemhunters.persistence;
import com.google.gson.Gson; import com.google.gson.Gson;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.common.util.UtilServer;
import mineplex.gemhunters.quest.QuestPlayerData; import mineplex.gemhunters.quest.QuestPlayerData;
import mineplex.serverdata.Region;
import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase; import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt; import mineplex.serverdata.database.column.ColumnInt;
@ -25,9 +27,9 @@ import java.util.function.Consumer;
public class PersistenceRepository extends RepositoryBase public class PersistenceRepository extends RepositoryBase
{ {
private static final String GET_DATA = "SELECT * FROM gemHunters 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 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 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 String DELETE_DATA = "DELETE FROM gemHunters WHERE accountId=?;";
private static final Gson GSON; private static final Gson GSON;
private static final ItemStack AIR = new ItemStack(Material.AIR); private static final ItemStack AIR = new ItemStack(Material.AIR);
@ -49,6 +51,7 @@ public class PersistenceRepository extends RepositoryBase
public void getPersistenceData(Consumer<PersistenceData> response, CoreClient client) public void getPersistenceData(Consumer<PersistenceData> response, CoreClient client)
{ {
int accountId = client.getAccountId(); int accountId = client.getAccountId();
Region region = UtilServer.getRegion();
executeQuery(GET_DATA, resultSet -> executeQuery(GET_DATA, resultSet ->
{ {
@ -111,16 +114,17 @@ public class PersistenceRepository extends RepositoryBase
_exists.add(accountId); _exists.add(accountId);
Location location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch); 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); response.accept(data);
} }
}, new ColumnInt("accountId", accountId)); }, new ColumnInt("accountId", accountId), new ColumnVarChar("region", 2, region.toString()));
} }
public void savePersistence(CoreClient client, PersistenceData data) public void savePersistence(CoreClient client, PersistenceData data)
{ {
int accountId = client.getAccountId(); int accountId = client.getAccountId();
Region region = data.getRegion();
int gems = data.getGems(); int gems = data.getGems();
int health = data.getHealth(); int health = data.getHealth();
int maxHealth = data.getMaxHealth(); int maxHealth = data.getMaxHealth();
@ -161,6 +165,7 @@ public class PersistenceRepository extends RepositoryBase
if (exists(client)) if (exists(client))
{ {
executeUpdate(UPDATE_DATA, executeUpdate(UPDATE_DATA,
new ColumnVarChar("region", 2, region.toString()),
new ColumnInt("gems", gems), new ColumnInt("gems", gems),
new ColumnInt("health", health), new ColumnInt("health", health),
new ColumnInt("maxHealth", maxHealth), new ColumnInt("maxHealth", maxHealth),
@ -183,6 +188,7 @@ public class PersistenceRepository extends RepositoryBase
{ {
executeInsert(INSERT_DATA, null, executeInsert(INSERT_DATA, null,
new ColumnInt("accountId", accountId), new ColumnInt("accountId", accountId),
new ColumnVarChar("region", 2, region.toString()),
new ColumnInt("gems", gems), new ColumnInt("gems", gems),
new ColumnInt("health", health), new ColumnInt("health", health),
new ColumnInt("maxHealth", maxHealth), new ColumnInt("maxHealth", maxHealth),