Move GH quit NPCs to redis; use region when saving GH data
This commit is contained in:
parent
ed3455db68
commit
c341671ffc
@ -101,7 +101,7 @@ public class QuitNPCModule extends MiniPlugin
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String npcServer = _repo.loadNpcServer(event.getUniqueId()).get();
|
String npcServer = _repo.loadNpcServer(event.getUniqueId()).join();
|
||||||
if (npcServer == null || npcServer.isEmpty())
|
if (npcServer == null || npcServer.isEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -1,69 +1,33 @@
|
|||||||
package mineplex.gemhunters.death.quitnpc;
|
package mineplex.gemhunters.death.quitnpc;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
import mineplex.serverdata.database.DBPool;
|
import mineplex.serverdata.Region;
|
||||||
import mineplex.serverdata.database.RepositoryBase;
|
import mineplex.serverdata.redis.RedisRepository;
|
||||||
import mineplex.serverdata.database.column.ColumnVarChar;
|
|
||||||
|
|
||||||
public class QuitNPCRepository extends RepositoryBase
|
public class QuitNPCRepository extends RedisRepository
|
||||||
{
|
{
|
||||||
private static final String GET_DATA = "SELECT serverName FROM gemHuntersQuitNpcs WHERE uuid=?;";
|
private static final String REDIS_KEY_PREFIX = "GemHuntersNPC.";
|
||||||
private static final String INSERT_DATA = "INSERT INTO gemHuntersQuitNpcs (uuid, serverName) VALUES (?, ?);";
|
|
||||||
private static final String DELETE_DATA = "DELETE FROM gemHuntersQuitNpcs WHERE uuid=?;";
|
|
||||||
|
|
||||||
public QuitNPCRepository()
|
public QuitNPCRepository()
|
||||||
{
|
{
|
||||||
super(DBPool.getAccount());
|
super(Region.ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<String> loadNpcServer(UUID uuid)
|
public CompletableFuture<String> loadNpcServer(UUID uuid)
|
||||||
{
|
{
|
||||||
return CompletableFuture.supplyAsync(() ->
|
return CompletableFuture.supplyAsync(() -> getResource(false).get(getKey(REDIS_KEY_PREFIX + uuid.toString())));
|
||||||
{
|
|
||||||
try (Connection conn = getConnection())
|
|
||||||
{
|
|
||||||
PreparedStatement stmt = conn.prepareStatement(GET_DATA);
|
|
||||||
stmt.setString(1, uuid.toString());
|
|
||||||
|
|
||||||
String serverName = null;
|
|
||||||
|
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
|
||||||
if (resultSet.next())
|
|
||||||
{
|
|
||||||
serverName = resultSet.getString("serverName");
|
|
||||||
}
|
|
||||||
|
|
||||||
return serverName;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteNpc(UUID uuid)
|
public void deleteNpc(UUID uuid)
|
||||||
{
|
{
|
||||||
final String uuidStr = uuid.toString();
|
UtilServer.runAsync(() -> getResource(true).del(getKey(REDIS_KEY_PREFIX + uuid.toString())));
|
||||||
UtilServer.runAsync(() ->
|
|
||||||
{
|
|
||||||
executeUpdate(DELETE_DATA, new ColumnVarChar("uuid", uuidStr.length(), uuidStr));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertNpc(UUID uuid, String serverName)
|
public void insertNpc(UUID uuid, String serverName)
|
||||||
{
|
{
|
||||||
final String uuidStr = uuid.toString();
|
UtilServer.runAsync(() -> getResource(true).setex(REDIS_KEY_PREFIX + uuid.toString(), 60, serverName));
|
||||||
UtilServer.runAsync(() ->
|
|
||||||
{
|
|
||||||
executeInsert(INSERT_DATA, null, new ColumnVarChar("uuid", uuidStr.length(), uuidStr), new ColumnVarChar("serverName", serverName.length(), serverName));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,21 @@
|
|||||||
package mineplex.gemhunters.persistence;
|
package mineplex.gemhunters.persistence;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
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.core.common.util.UtilServer;
|
||||||
import mineplex.gemhunters.quest.QuestPlayerData;
|
import mineplex.gemhunters.quest.QuestPlayerData;
|
||||||
@ -10,26 +25,13 @@ import mineplex.serverdata.database.RepositoryBase;
|
|||||||
import mineplex.serverdata.database.column.ColumnInt;
|
import mineplex.serverdata.database.column.ColumnInt;
|
||||||
import mineplex.serverdata.database.column.ColumnTimestamp;
|
import mineplex.serverdata.database.column.ColumnTimestamp;
|
||||||
import mineplex.serverdata.database.column.ColumnVarChar;
|
import mineplex.serverdata.database.column.ColumnVarChar;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
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=? AND region=?;";
|
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 (accountId, region, gems, health, maxHealth, hunger, x, y, z, yaw, pitch, quests, slots, items, armour, saveTime, cashOutTime) 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 gems=?,health=?,maxHealth=?,hunger=?,x=?,y=?,z=?,yaw=?,pitch=?,quests=?,slots=?,items=?,armour=?,saveTime=?,cashOutTime=? WHERE accountId=? AND region=?;";
|
||||||
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);
|
||||||
@ -180,7 +182,8 @@ public class PersistenceRepository extends RepositoryBase
|
|||||||
new ColumnVarChar("armour", 1000, GSON.toJson(armourMap)),
|
new ColumnVarChar("armour", 1000, GSON.toJson(armourMap)),
|
||||||
new ColumnTimestamp("saveTime", saveTime),
|
new ColumnTimestamp("saveTime", saveTime),
|
||||||
new ColumnInt("cashOutTime", cashOutTime),
|
new ColumnInt("cashOutTime", cashOutTime),
|
||||||
new ColumnInt("accountId", accountId)
|
new ColumnInt("accountId", accountId),
|
||||||
|
new ColumnVarChar("region", 2, region.toString())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user