mirror of
https://github.com/songoda/EpicFurnaces.git
synced 2024-11-27 12:25:52 +01:00
Database update to the new system
This commit is contained in:
parent
1f75b99a3d
commit
2033f30cd0
4
pom.xml
4
pom.xml
@ -4,9 +4,9 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.songoda</groupId>
|
||||
<groupId>com.craftaro</groupId>
|
||||
<artifactId>EpicFurnaces</artifactId>
|
||||
<version>4.10.0-SNAPSHOT</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
|
||||
<name>EpicFurnaces</name>
|
||||
<description>EpicFurnaces allows you to upgrade basic Minecraft features to make the game way more entertaining</description>
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.songoda.epicfurnaces;
|
||||
package com.craftaro.epicfurnaces;
|
||||
|
||||
import com.craftaro.core.SongodaCore;
|
||||
import com.craftaro.core.SongodaPlugin;
|
||||
import com.craftaro.core.commands.CommandManager;
|
||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import com.craftaro.core.database.DataMigrationManager;
|
||||
import com.craftaro.core.database.Data;
|
||||
import com.craftaro.core.database.DatabaseConnector;
|
||||
import com.craftaro.core.database.MySQLConnector;
|
||||
import com.craftaro.core.database.SQLiteConnector;
|
||||
@ -16,33 +16,34 @@ import com.craftaro.core.hooks.ProtectionManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.songoda.epicfurnaces.boost.BoostData;
|
||||
import com.songoda.epicfurnaces.boost.BoostManager;
|
||||
import com.songoda.epicfurnaces.commands.CommandBoost;
|
||||
import com.songoda.epicfurnaces.commands.CommandGive;
|
||||
import com.songoda.epicfurnaces.commands.CommandReload;
|
||||
import com.songoda.epicfurnaces.commands.CommandRemote;
|
||||
import com.songoda.epicfurnaces.commands.CommandSettings;
|
||||
import com.songoda.epicfurnaces.compatibility.FabledSkyBlockLoader;
|
||||
import com.songoda.epicfurnaces.database.DataManager;
|
||||
import com.songoda.epicfurnaces.database.migrations._1_InitialMigration;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.epicfurnaces.furnace.FurnaceBuilder;
|
||||
import com.songoda.epicfurnaces.furnace.FurnaceManager;
|
||||
import com.songoda.epicfurnaces.furnace.levels.LevelManager;
|
||||
import com.songoda.epicfurnaces.handlers.BlacklistHandler;
|
||||
import com.songoda.epicfurnaces.listeners.BlockListeners;
|
||||
import com.songoda.epicfurnaces.listeners.EntityListeners;
|
||||
import com.songoda.epicfurnaces.listeners.FurnaceListeners;
|
||||
import com.songoda.epicfurnaces.listeners.InteractListeners;
|
||||
import com.songoda.epicfurnaces.listeners.InventoryListeners;
|
||||
import com.songoda.epicfurnaces.settings.Settings;
|
||||
import com.songoda.epicfurnaces.storage.Storage;
|
||||
import com.songoda.epicfurnaces.storage.StorageRow;
|
||||
import com.songoda.epicfurnaces.storage.types.StorageYaml;
|
||||
import com.songoda.epicfurnaces.tasks.FurnaceTask;
|
||||
import com.songoda.epicfurnaces.tasks.HologramTask;
|
||||
import com.songoda.epicfurnaces.utils.Methods;
|
||||
import com.craftaro.epicfurnaces.commands.CommandBoost;
|
||||
import com.craftaro.epicfurnaces.commands.CommandGive;
|
||||
import com.craftaro.epicfurnaces.commands.CommandReload;
|
||||
import com.craftaro.epicfurnaces.commands.CommandRemote;
|
||||
import com.craftaro.epicfurnaces.commands.CommandSettings;
|
||||
import com.craftaro.epicfurnaces.compatibility.FabledSkyBlockLoader;
|
||||
import com.craftaro.epicfurnaces.database.DataHelper;
|
||||
import com.craftaro.epicfurnaces.database.DataManager;
|
||||
import com.craftaro.epicfurnaces.furnace.FurnaceBuilder;
|
||||
import com.craftaro.epicfurnaces.furnace.FurnaceManager;
|
||||
import com.craftaro.epicfurnaces.furnace.levels.LevelManager;
|
||||
import com.craftaro.epicfurnaces.handlers.BlacklistHandler;
|
||||
import com.craftaro.epicfurnaces.listeners.BlockListeners;
|
||||
import com.craftaro.epicfurnaces.listeners.EntityListeners;
|
||||
import com.craftaro.epicfurnaces.listeners.FurnaceListeners;
|
||||
import com.craftaro.epicfurnaces.listeners.InventoryListeners;
|
||||
import com.craftaro.epicfurnaces.settings.Settings;
|
||||
import com.craftaro.epicfurnaces.storage.Storage;
|
||||
import com.craftaro.epicfurnaces.storage.StorageRow;
|
||||
import com.craftaro.epicfurnaces.storage.types.StorageYaml;
|
||||
import com.craftaro.epicfurnaces.boost.BoostData;
|
||||
import com.craftaro.epicfurnaces.boost.BoostManager;
|
||||
import com.craftaro.epicfurnaces.database.migrations._1_InitialMigration;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epicfurnaces.listeners.InteractListeners;
|
||||
import com.craftaro.epicfurnaces.tasks.FurnaceTask;
|
||||
import com.craftaro.epicfurnaces.tasks.HologramTask;
|
||||
import com.craftaro.epicfurnaces.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -60,9 +61,11 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -77,9 +80,8 @@ public class EpicFurnaces extends SongodaPlugin {
|
||||
private CommandManager commandManager;
|
||||
|
||||
private BlacklistHandler blacklistHandler;
|
||||
private DataHelper dataHelper;
|
||||
|
||||
private DatabaseConnector databaseConnector;
|
||||
private DataManager dataManager;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getPlugin(Class)} instead
|
||||
@ -95,9 +97,7 @@ public class EpicFurnaces extends SongodaPlugin {
|
||||
|
||||
@Override
|
||||
public void onPluginDisable() {
|
||||
shutdownDataManager(this.dataManager);
|
||||
this.databaseConnector.closeConnection();
|
||||
|
||||
this.dataManager.shutdown();
|
||||
HologramManager.removeAllHolograms();
|
||||
}
|
||||
|
||||
@ -144,32 +144,8 @@ public class EpicFurnaces extends SongodaPlugin {
|
||||
this.boostManager = new BoostManager(this);
|
||||
this.blacklistHandler = new BlacklistHandler(this);
|
||||
|
||||
// Database stuff.
|
||||
try {
|
||||
if (Settings.MYSQL_ENABLED.getBoolean()) {
|
||||
String hostname = Settings.MYSQL_HOSTNAME.getString();
|
||||
int port = Settings.MYSQL_PORT.getInt();
|
||||
String database = Settings.MYSQL_DATABASE.getString();
|
||||
String username = Settings.MYSQL_USERNAME.getString();
|
||||
String password = Settings.MYSQL_PASSWORD.getString();
|
||||
boolean useSSL = Settings.MYSQL_USE_SSL.getBoolean();
|
||||
int poolSize = Settings.MYSQL_POOL_SIZE.getInt();
|
||||
|
||||
this.databaseConnector = new MySQLConnector(this, hostname, port, database, username, password, useSSL, poolSize);
|
||||
this.getLogger().info("Data handler connected using MySQL.");
|
||||
} else {
|
||||
this.databaseConnector = new SQLiteConnector(this);
|
||||
this.getLogger().info("Data handler connected using SQLite.");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
this.getLogger().severe("Fatal error trying to connect to database. Please make sure all your connection settings are correct and try again. Plugin has been disabled.");
|
||||
this.emergencyStop();
|
||||
}
|
||||
|
||||
this.dataManager = new DataManager(this.databaseConnector, this);
|
||||
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager,
|
||||
new _1_InitialMigration(this));
|
||||
dataMigrationManager.runMigrations();
|
||||
dataHelper = new DataHelper(this);
|
||||
initDatabase(Collections.singletonList(new _1_InitialMigration()));
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
||||
// Legacy data! Yay!
|
||||
@ -226,7 +202,8 @@ public class EpicFurnaces extends SongodaPlugin {
|
||||
.setAccessList(usableList)
|
||||
.setPlacedBy(placedBy).build());
|
||||
}
|
||||
this.dataManager.createFurnaces(furnaces);
|
||||
Set<Data> data = new HashSet<>(furnaces);
|
||||
this.dataManager.saveBatch(data);
|
||||
}
|
||||
|
||||
// Adding in Boosts
|
||||
@ -236,7 +213,7 @@ public class EpicFurnaces extends SongodaPlugin {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.dataManager.createBoost(new BoostData(
|
||||
this.dataManager.save(new BoostData(
|
||||
row.get("amount").asInt(),
|
||||
Long.parseLong(row.getKey()),
|
||||
UUID.fromString(row.get("uuid").asString())));
|
||||
@ -246,14 +223,14 @@ public class EpicFurnaces extends SongodaPlugin {
|
||||
}
|
||||
|
||||
final boolean finalConverted = converted;
|
||||
this.dataManager.runAsync(() -> {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
||||
if (finalConverted) {
|
||||
Bukkit.getConsoleSender().sendMessage("[" + getDescription().getName() + "] " + ChatColor.GREEN + "Conversion complete :)");
|
||||
}
|
||||
|
||||
this.dataManager.getFurnaces((furnaces) -> {
|
||||
this.furnaceManager.addFurnaces(furnaces.values());
|
||||
this.dataManager.getBoosts((boosts) -> this.boostManager.addBoosts(boosts));
|
||||
this.dataManager.loadBatch(Furnace.class, "active_furnaces").forEach((furnace) -> {
|
||||
this.furnaceManager.addFurnace((Furnace) furnace);
|
||||
this.boostManager.addBoosts(this.dataManager.loadBatch(BoostData.class, "boosts"));
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -506,11 +483,7 @@ public class EpicFurnaces extends SongodaPlugin {
|
||||
return this.levelManager;
|
||||
}
|
||||
|
||||
public DatabaseConnector getDatabaseConnector() {
|
||||
return this.databaseConnector;
|
||||
}
|
||||
|
||||
public DataManager getDataManager() {
|
||||
return this.dataManager;
|
||||
public DataHelper getDataHelper() {
|
||||
return this.dataHelper;
|
||||
}
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
package com.songoda.epicfurnaces.boost;
|
||||
package com.craftaro.epicfurnaces.boost;
|
||||
|
||||
import com.craftaro.core.database.Data;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BoostData {
|
||||
public class BoostData implements Data {
|
||||
private final int multiplier;
|
||||
private final long endTime;
|
||||
private final UUID player;
|
||||
@ -45,4 +49,28 @@ public class BoostData {
|
||||
return this.multiplier == other.multiplier && this.endTime == other.endTime
|
||||
&& Objects.equals(this.player, other.player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("player", this.player);
|
||||
map.put("multiplier", this.multiplier);
|
||||
map.put("endTime", this.endTime);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Data deserialize(Map<String, Object> map) {
|
||||
return new BoostData((int) map.get("multiplier"), (long) map.get("endTime"), UUID.fromString((String) map.get("player")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableName() {
|
||||
return "boosted_players";
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfurnaces.boost;
|
||||
package com.craftaro.epicfurnaces.boost;
|
||||
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@ -42,7 +42,7 @@ public class BoostManager {
|
||||
if (boostData.getPlayer().toString().equals(player.toString())) {
|
||||
if (System.currentTimeMillis() >= boostData.getEndTime()) {
|
||||
removeBoostFromPlayer(boostData);
|
||||
this.plugin.getDataManager().deleteBoost(boostData);
|
||||
this.plugin.getDataManager().delete(boostData);
|
||||
}
|
||||
return boostData;
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package com.songoda.epicfurnaces.commands;
|
||||
package com.craftaro.epicfurnaces.commands;
|
||||
|
||||
import com.craftaro.core.commands.AbstractCommand;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.core.utils.TimeUtils;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.boost.BoostData;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.boost.BoostData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -49,7 +49,7 @@ public class CommandBoost extends AbstractCommand {
|
||||
|
||||
BoostData boostData = new BoostData(Integer.parseInt(args[1]), duration == 0L ? Long.MAX_VALUE : System.currentTimeMillis() + duration, player.getUniqueId());
|
||||
this.instance.getBoostManager().addBoostToPlayer(boostData);
|
||||
this.instance.getDataManager().createBoost(boostData);
|
||||
this.instance.getDataManager().save(boostData);
|
||||
this.instance.getLocale().newMessage("&7Successfully boosted &6" + Bukkit.getPlayer(args[0]).getName()
|
||||
+ "'s &7furnace reward amounts &6" + args[1] + "x" + (duration == 0L ? "" : (" for " + TimeUtils.makeReadable(duration))) + "&7.").sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.epicfurnaces.commands;
|
||||
package com.craftaro.epicfurnaces.commands;
|
||||
|
||||
import com.craftaro.core.commands.AbstractCommand;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.furnace.levels.Level;
|
||||
import com.craftaro.epicfurnaces.furnace.levels.Level;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.epicfurnaces.commands;
|
||||
package com.craftaro.epicfurnaces.commands;
|
||||
|
||||
import com.craftaro.core.commands.AbstractCommand;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
@ -1,9 +1,9 @@
|
||||
package com.songoda.epicfurnaces.commands;
|
||||
package com.craftaro.epicfurnaces.commands;
|
||||
|
||||
import com.craftaro.core.commands.AbstractCommand;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.epicfurnaces.settings.Settings;
|
||||
import com.craftaro.epicfurnaces.settings.Settings;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
@ -1,9 +1,9 @@
|
||||
package com.songoda.epicfurnaces.commands;
|
||||
package com.craftaro.epicfurnaces.commands;
|
||||
|
||||
import com.craftaro.core.commands.AbstractCommand;
|
||||
import com.craftaro.core.configuration.editor.PluginConfigGui;
|
||||
import com.craftaro.core.gui.GuiManager;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -0,0 +1,12 @@
|
||||
package com.craftaro.epicfurnaces.compatibility;
|
||||
|
||||
|
||||
import com.craftaro.skyblock.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.skyblock.permission.BasicPermission;
|
||||
import com.craftaro.skyblock.permission.PermissionType;
|
||||
|
||||
public class EpicFurnacesPermission extends BasicPermission {
|
||||
public EpicFurnacesPermission() {
|
||||
super("EpicFurnaces", XMaterial.FIRE_CHARGE, PermissionType.GENERIC);
|
||||
}
|
||||
}
|
@ -1,14 +1,15 @@
|
||||
package com.songoda.epicfurnaces.compatibility;
|
||||
package com.craftaro.epicfurnaces.compatibility;
|
||||
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.permission.BasicPermission;
|
||||
|
||||
import com.craftaro.skyblock.SkyBlock;
|
||||
import com.craftaro.skyblock.permission.BasicPermission;
|
||||
|
||||
public class FabledSkyBlockLoader {
|
||||
public FabledSkyBlockLoader() {
|
||||
SkyBlock.getInstance().getPermissionManager().registerPermission(new EpicFurnacesPermission());
|
||||
|
||||
try {
|
||||
SkyBlock.getInstance().getPermissionManager().registerPermission((BasicPermission) Class.forName("com.songoda.epicfurnaces.compatibility.EpicFurnacesPermission").getDeclaredConstructor().newInstance());
|
||||
SkyBlock.getInstance().getPermissionManager().registerPermission((BasicPermission) Class.forName("com.craftaro.epicfurnaces.compatibility.EpicFurnacesPermission").getDeclaredConstructor().newInstance());
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
157
src/main/java/com/craftaro/epicfurnaces/database/DataHelper.java
Normal file
157
src/main/java/com/craftaro/epicfurnaces/database/DataHelper.java
Normal file
@ -0,0 +1,157 @@
|
||||
package com.craftaro.epicfurnaces.database;
|
||||
|
||||
import com.craftaro.core.database.Data;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.third_party.org.jooq.impl.DSL;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DataHelper {
|
||||
|
||||
private final EpicFurnaces plugin;
|
||||
private final Set<Furnace> furnaceUpdateQueue = new HashSet<>();
|
||||
|
||||
public DataHelper(EpicFurnaces plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, this::bulkUpdateFurnaceQueue, 20 * 60 * 3, 20 * 60 * 3);
|
||||
}
|
||||
|
||||
public void bulkUpdateFurnaceQueue() {
|
||||
synchronized (this.furnaceUpdateQueue) {
|
||||
updateFurnaces(new LinkedHashSet<>(this.furnaceUpdateQueue));
|
||||
this.furnaceUpdateQueue.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void queueFurnaceForUpdate(Furnace furnace) {
|
||||
synchronized (this.furnaceUpdateQueue) {
|
||||
this.furnaceUpdateQueue.add(furnace);
|
||||
}
|
||||
}
|
||||
|
||||
public void dequeueFurnaceForUpdate(Furnace furnace) {
|
||||
synchronized (this.furnaceUpdateQueue) {
|
||||
this.furnaceUpdateQueue.remove(furnace);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateFurnaces(Collection<Furnace> furnaces) {
|
||||
Set<Data> data = new HashSet<>(furnaces);
|
||||
plugin.getDataManager().saveBatch(data);
|
||||
}
|
||||
|
||||
|
||||
public void updateLevelupItems(Furnace furnace, XMaterial material, int amount) {
|
||||
String tablePrefix = plugin.getDataManager().getTablePrefix();
|
||||
plugin.getDataManager().getDatabaseConnector().connectDSL(dslContext -> {
|
||||
dslContext.deleteFrom(DSL.table(tablePrefix + "to_level_new"))
|
||||
.where(DSL.field("furnace_id").eq(furnace.getId()))
|
||||
.and(DSL.field("item").eq(material.name()))
|
||||
.execute();
|
||||
|
||||
dslContext.insertInto(DSL.table(tablePrefix + "to_level_new"))
|
||||
.columns(DSL.field("furnace_id"), DSL.field("item"), DSL.field("amount"))
|
||||
.values(furnace.getId(), material.name(), amount)
|
||||
.execute();
|
||||
});
|
||||
}
|
||||
|
||||
// public void createAccessPlayer(Furnace furnace, UUID uuid) {
|
||||
// this.runAsync(() -> {
|
||||
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
// String createAccessPlayer = "INSERT INTO " + this.getTablePrefix() + "access_list (furnace_id, uuid) VALUES (?, ?)";
|
||||
// PreparedStatement statement = connection.prepareStatement(createAccessPlayer);
|
||||
// statement.setInt(1, furnace.getId());
|
||||
// statement.setString(2, uuid.toString());
|
||||
// statement.executeUpdate();
|
||||
// } catch (Exception ex) {
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// // These will be used in the future when the access list gets revamped.
|
||||
// // Probably by me since I already have a custom version in my server.
|
||||
// public void deleteAccessPlayer(Furnace furnace, UUID uuid) {
|
||||
// this.runAsync(() -> {
|
||||
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
// String deleteAccessPlayer = "DELETE FROM " + this.getTablePrefix() + "access_list WHERE furnace_id = ? AND uuid = ?";
|
||||
// PreparedStatement statement = connection.prepareStatement(deleteAccessPlayer);
|
||||
// statement.setInt(1, furnace.getId());
|
||||
// statement.setString(2, uuid.toString());
|
||||
// statement.executeUpdate();
|
||||
// } catch (Exception ex) {
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// public void updateAccessPlayers(Furnace furnace) {
|
||||
// this.runAsync(() -> {
|
||||
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
// String deletePlayers = "DELETE FROM " + this.getTablePrefix() + "access_list WHERE furnace_id = ?";
|
||||
// try (PreparedStatement statement = connection.prepareStatement(deletePlayers)) {
|
||||
// statement.setInt(1, furnace.getId());
|
||||
// statement.executeUpdate();
|
||||
// }
|
||||
//
|
||||
// String createAccessPlayer = "INSERT INTO " + this.getTablePrefix() + "access_list (furnace_id, uuid) VALUES (?, ?)";
|
||||
// try (PreparedStatement statement = connection.prepareStatement(createAccessPlayer)) {
|
||||
// for (UUID uuid : furnace.getAccessList()) {
|
||||
// statement.setInt(1, furnace.getId());
|
||||
// statement.setString(2, uuid.toString());
|
||||
// statement.addBatch();
|
||||
// }
|
||||
// statement.executeBatch();
|
||||
// }
|
||||
// } catch (Exception ex) {
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
public void createAccessPlayer(Furnace furnace, UUID uuid) {
|
||||
String tablePrefix = plugin.getDataManager().getTablePrefix();
|
||||
plugin.getDataManager().getDatabaseConnector().connectDSL(dslContext -> {
|
||||
dslContext.insertInto(DSL.table(tablePrefix + "access_list"))
|
||||
.columns(DSL.field("furnace_id"), DSL.field("uuid"))
|
||||
.values(furnace.getId(), uuid.toString())
|
||||
.execute();
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteAccessPlayer(Furnace furnace, UUID uuid) {
|
||||
String tablePrefix = plugin.getDataManager().getTablePrefix();
|
||||
plugin.getDataManager().getDatabaseConnector().connectDSL(dslContext -> {
|
||||
dslContext.deleteFrom(DSL.table(tablePrefix + "access_list"))
|
||||
.where(DSL.field("furnace_id").eq(furnace.getId()))
|
||||
.and(DSL.field("uuid").eq(uuid.toString()))
|
||||
.execute();
|
||||
});
|
||||
}
|
||||
|
||||
public void updateAccessPlayers(Furnace furnace) {
|
||||
String tablePrefix = plugin.getDataManager().getTablePrefix();
|
||||
plugin.getDataManager().getDatabaseConnector().connectDSL(dslContext -> {
|
||||
dslContext.deleteFrom(DSL.table(tablePrefix + "access_list"))
|
||||
.where(DSL.field("furnace_id").eq(furnace.getId()))
|
||||
.execute();
|
||||
|
||||
for (UUID uuid : furnace.getAccessList()) {
|
||||
dslContext.insertInto(DSL.table(tablePrefix + "access_list"))
|
||||
.columns(DSL.field("furnace_id"), DSL.field("uuid"))
|
||||
.values(furnace.getId(), uuid.toString())
|
||||
.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
package com.craftaro.epicfurnaces.database;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||
import com.craftaro.core.database.DatabaseConnector;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.epicfurnaces.furnace.FurnaceBuilder;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.boost.BoostData;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class DataManager {
|
||||
|
||||
|
||||
public DataManager(DatabaseConnector connector, Plugin plugin) {
|
||||
//super(connector, plugin);
|
||||
|
||||
// Updating furnaces every 3 minutes should be plenty I believe
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// public void getFurnaces(Consumer<Map<Integer, Furnace>> callback) {
|
||||
// this.runAsync(() -> {
|
||||
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
// Map<Integer, Furnace> furnaces = new HashMap<>();
|
||||
//
|
||||
// try (Statement statement = connection.createStatement()) {
|
||||
// String selectFurnaces = "SELECT * FROM " + this.getTablePrefix() + "active_furnaces";
|
||||
// ResultSet result = statement.executeQuery(selectFurnaces);
|
||||
// while (result.next()) {
|
||||
// World world = Bukkit.getWorld(result.getString("world"));
|
||||
//
|
||||
// if (world == null) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// int id = result.getInt("id");
|
||||
// int level = result.getInt("level");
|
||||
// int uses = result.getInt("uses");
|
||||
//
|
||||
// String placedByStr = result.getString("placed_by");
|
||||
// UUID placedBy = placedByStr == null ? null : UUID.fromString(result.getString("placed_by"));
|
||||
//
|
||||
// String nickname = result.getString("nickname");
|
||||
//
|
||||
// int x = result.getInt("x");
|
||||
// int y = result.getInt("y");
|
||||
// int z = result.getInt("z");
|
||||
// Location location = new Location(world, x, y, z);
|
||||
//
|
||||
// Furnace furnace = new FurnaceBuilder(location)
|
||||
// .setId(id)
|
||||
// .setLevel(EpicFurnaces.getInstance().getLevelManager().getLevel(level))
|
||||
// .setUses(uses)
|
||||
// .setPlacedBy(placedBy)
|
||||
// .setNickname(nickname)
|
||||
// .build();
|
||||
//
|
||||
// furnaces.put(id, furnace);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// try (Statement statement = connection.createStatement()) {
|
||||
// String selectAccessList = "SELECT * FROM " + this.getTablePrefix() + "access_list";
|
||||
// ResultSet result = statement.executeQuery(selectAccessList);
|
||||
// while (result.next()) {
|
||||
// int id = result.getInt("furnace_id");
|
||||
// UUID uuid = UUID.fromString(result.getString("uuid"));
|
||||
//
|
||||
// Furnace furnace = furnaces.get(id);
|
||||
// if (furnace == null) {
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// furnace.addToAccessList(uuid);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// try (Statement statement = connection.createStatement()) {
|
||||
// String selectLevelupItems = "SELECT * FROM " + this.getTablePrefix() + "to_level_new";
|
||||
// ResultSet result = statement.executeQuery(selectLevelupItems);
|
||||
// while (result.next()) {
|
||||
// int id = result.getInt("furnace_id");
|
||||
// XMaterial material = CompatibleMaterial.getMaterial(result.getString("item")).get();
|
||||
// int amount = result.getInt("amount");
|
||||
//
|
||||
// Furnace furnace = furnaces.get(id);
|
||||
// if (furnace == null) {
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// furnace.addToLevel(material, amount);
|
||||
// }
|
||||
// }
|
||||
// this.sync(() -> callback.accept(furnaces));
|
||||
// } catch (Exception ex) {
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
}
|
@ -1,29 +1,26 @@
|
||||
package com.songoda.epicfurnaces.database.migrations;
|
||||
package com.craftaro.epicfurnaces.database.migrations;
|
||||
|
||||
import com.craftaro.core.database.DataMigration;
|
||||
import com.craftaro.core.database.MySQLConnector;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class _1_InitialMigration extends DataMigration {
|
||||
private final EpicFurnaces plugin;
|
||||
|
||||
public _1_InitialMigration(EpicFurnaces plugin) {
|
||||
public _1_InitialMigration() {
|
||||
super(1);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(Connection connection, String tablePrefix) throws SQLException {
|
||||
String autoIncrement = this.plugin.getDatabaseConnector() instanceof MySQLConnector ? " AUTO_INCREMENT" : "";
|
||||
|
||||
// Create furnaces table.
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.execute("CREATE TABLE " + tablePrefix + "active_furnaces (" +
|
||||
"id INTEGER PRIMARY KEY" + autoIncrement + ", " +
|
||||
"id INTEGER PRIMARY KEY AUTO_INCREMENT, " +
|
||||
"level INTEGER NOT NULL, " +
|
||||
"uses INTEGER NOT NULL," +
|
||||
"placed_by VARCHAR(36), " +
|
@ -1,20 +1,22 @@
|
||||
package com.songoda.epicfurnaces.furnace;
|
||||
package com.craftaro.epicfurnaces.furnace;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.database.Data;
|
||||
import com.craftaro.core.database.SerializedLocation;
|
||||
import com.craftaro.core.gui.GuiManager;
|
||||
import com.craftaro.core.hooks.EconomyManager;
|
||||
import com.craftaro.core.hooks.ProtectionManager;
|
||||
import com.craftaro.core.math.MathUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XSound;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.boost.BoostData;
|
||||
import com.songoda.epicfurnaces.furnace.levels.Level;
|
||||
import com.songoda.epicfurnaces.gui.GUIOverview;
|
||||
import com.songoda.epicfurnaces.settings.Settings;
|
||||
import com.songoda.epicfurnaces.utils.CostType;
|
||||
import com.songoda.epicfurnaces.utils.Methods;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.furnace.levels.Level;
|
||||
import com.craftaro.epicfurnaces.settings.Settings;
|
||||
import com.craftaro.epicfurnaces.boost.BoostData;
|
||||
import com.craftaro.epicfurnaces.gui.GUIOverview;
|
||||
import com.craftaro.epicfurnaces.utils.CostType;
|
||||
import com.craftaro.epicfurnaces.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -32,11 +34,12 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Furnace {
|
||||
public class Furnace implements Data {
|
||||
private final EpicFurnaces plugin = EpicFurnaces.getPlugin(EpicFurnaces.class);
|
||||
|
||||
private final String hologramId = UUID.randomUUID().toString();
|
||||
@ -56,8 +59,25 @@ public class Furnace {
|
||||
private final List<Location> radiusFuelshare = new ArrayList<>();
|
||||
private final List<UUID> accessList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructor for database use.
|
||||
*/
|
||||
public Furnace() {
|
||||
this.location = null;
|
||||
}
|
||||
|
||||
public Furnace(Location location) {
|
||||
this.location = location;
|
||||
this.id = this.plugin.getDataManager().getNextId("active_furnaces");
|
||||
}
|
||||
|
||||
public Furnace(Map<String, Object> map) {
|
||||
this.id = (int) map.get("id");
|
||||
this.level = this.plugin.getLevelManager().getLevel((int) map.get("level"));
|
||||
this.uses = (int) map.get("uses");
|
||||
this.placedBy = map.get("placed_by") == null ? null : UUID.fromString((String) map.get("placed_by"));
|
||||
this.nickname = (String) map.get("nickname");
|
||||
this.location = SerializedLocation.of(map);
|
||||
}
|
||||
|
||||
public void overview(GuiManager guiManager, Player player) {
|
||||
@ -84,14 +104,14 @@ public class Furnace {
|
||||
}
|
||||
|
||||
this.uses++;
|
||||
this.plugin.getDataManager().queueFurnaceForUpdate(this);
|
||||
this.plugin.getDataHelper().queueFurnaceForUpdate(this);
|
||||
|
||||
XMaterial material = CompatibleMaterial.getMaterial(event.getResult().getType()).get();
|
||||
int needed = -1;
|
||||
|
||||
if (this.level.getMaterials().containsKey(material)) {
|
||||
int amount = addToLevel(material, 1);
|
||||
this.plugin.getDataManager().updateLevelupItems(this, material, amount);
|
||||
this.plugin.getDataHelper().updateLevelupItems(this, material, amount);
|
||||
needed = this.level.getMaterials().get(material) - getToLevel(material);
|
||||
}
|
||||
|
||||
@ -184,7 +204,7 @@ public class Furnace {
|
||||
private void upgradeFinal(Player player) {
|
||||
levelUp();
|
||||
syncName();
|
||||
this.plugin.getDataManager().queueFurnaceForUpdate(this);
|
||||
this.plugin.getDataHelper().queueFurnaceForUpdate(this);
|
||||
if (this.plugin.getLevelManager().getHighestLevel() != this.level) {
|
||||
this.plugin.getLocale().getMessage("event.upgrade.success")
|
||||
.processPlaceholder("level", this.level.getLevel()).sendPrefixedMessage(player);
|
||||
@ -408,8 +428,26 @@ public class Furnace {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("id", this.id);
|
||||
map.put("level", this.level.getLevel());
|
||||
map.put("uses", this.uses);
|
||||
map.put("placed_by", this.placedBy == null ? null : this.placedBy.toString());
|
||||
map.put("nickname", this.nickname);
|
||||
map.putAll(SerializedLocation.of(this.location));
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Data deserialize(Map<String, Object> map) {
|
||||
return new Furnace(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableName() {
|
||||
return "active_furnaces";
|
||||
}
|
||||
|
||||
public void dropItems() {
|
@ -1,8 +1,7 @@
|
||||
package com.songoda.epicfurnaces.furnace;
|
||||
package com.craftaro.epicfurnaces.furnace;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.songoda.epicfurnaces.furnace.levels.Level;
|
||||
import com.craftaro.epicfurnaces.furnace.levels.Level;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.List;
|
||||
@ -52,11 +51,6 @@ public class FurnaceBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public FurnaceBuilder setId(int id) {
|
||||
this.furnace.setId(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Furnace build() {
|
||||
return this.furnace;
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package com.songoda.epicfurnaces.furnace;
|
||||
package com.craftaro.epicfurnaces.furnace;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import com.songoda.epicfurnaces.settings.Settings;
|
||||
import com.songoda.epicfurnaces.utils.GameArea;
|
||||
import com.craftaro.epicfurnaces.settings.Settings;
|
||||
import com.craftaro.epicfurnaces.utils.GameArea;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.epicfurnaces.furnace.levels;
|
||||
package com.craftaro.epicfurnaces.furnace.levels;
|
||||
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
@ -1,6 +1,5 @@
|
||||
package com.songoda.epicfurnaces.furnace.levels;
|
||||
package com.craftaro.epicfurnaces.furnace.levels;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
|
||||
import java.util.Collections;
|
@ -1,4 +1,4 @@
|
||||
package com.songoda.epicfurnaces.gui;
|
||||
package com.craftaro.epicfurnaces.gui;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||
import com.craftaro.core.gui.CustomizableGui;
|
||||
@ -8,13 +8,13 @@ import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.core.utils.TimeUtils;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.boost.BoostData;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.epicfurnaces.furnace.levels.Level;
|
||||
import com.songoda.epicfurnaces.settings.Settings;
|
||||
import com.songoda.epicfurnaces.utils.CostType;
|
||||
import com.songoda.epicfurnaces.utils.Methods;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.boost.BoostData;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epicfurnaces.furnace.levels.Level;
|
||||
import com.craftaro.epicfurnaces.settings.Settings;
|
||||
import com.craftaro.epicfurnaces.utils.CostType;
|
||||
import com.craftaro.epicfurnaces.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -151,7 +151,7 @@ public class GUIOverview extends CustomizableGui {
|
||||
}
|
||||
}
|
||||
|
||||
this.plugin.getDataManager().queueFurnaceForUpdate(this.furnace);
|
||||
this.plugin.getDataHelper().queueFurnaceForUpdate(this.furnace);
|
||||
this.furnace.setNickname(promptEvent.getMessage());
|
||||
this.plugin.getLocale().getMessage("event.remote.nicknamesuccess").sendPrefixedMessage(this.player);
|
||||
}).setOnClose(() -> this.guiManager.showGUI(this.player, new GUIOverview(this.plugin, this.furnace, this.player)));
|
@ -1,4 +1,4 @@
|
||||
package com.songoda.epicfurnaces.gui;
|
||||
package com.craftaro.epicfurnaces.gui;
|
||||
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.gui.CustomizableGui;
|
||||
@ -6,10 +6,10 @@ import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.input.ChatPrompt;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.epicfurnaces.settings.Settings;
|
||||
import com.songoda.epicfurnaces.utils.Methods;
|
||||
import com.craftaro.epicfurnaces.settings.Settings;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epicfurnaces.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -76,7 +76,7 @@ public class GUIRemoteAccess extends CustomizableGui {
|
||||
}
|
||||
|
||||
this.furnace.addToAccessList(toAdd);
|
||||
this.plugin.getDataManager().createAccessPlayer(this.furnace, toAdd.getUniqueId());
|
||||
this.plugin.getDataHelper().createAccessPlayer(this.furnace, toAdd.getUniqueId());
|
||||
this.plugin.getLocale().getMessage("event.remote.playeradded").sendPrefixedMessage(this.player);
|
||||
}).setOnClose(() -> this.guiManager.showGUI(this.player, new GUIRemoteAccess(this.plugin, this.furnace, this.player)));
|
||||
});
|
||||
@ -104,7 +104,7 @@ public class GUIRemoteAccess extends CustomizableGui {
|
||||
|
||||
setButton(num, itemStack, event -> {
|
||||
this.furnace.removeFromAccessList(entry);
|
||||
this.plugin.getDataManager().deleteAccessPlayer(this.furnace, entry);
|
||||
this.plugin.getDataHelper().deleteAccessPlayer(this.furnace, entry);
|
||||
this.guiManager.showGUI(this.player, new GUIRemoteAccess(this.plugin, this.furnace, this.player));
|
||||
});
|
||||
num++;
|
@ -1,4 +1,4 @@
|
||||
package com.songoda.epicfurnaces.handlers;
|
||||
package com.craftaro.epicfurnaces.handlers;
|
||||
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import org.bukkit.World;
|
@ -1,11 +1,11 @@
|
||||
package com.songoda.epicfurnaces.listeners;
|
||||
package com.craftaro.epicfurnaces.listeners;
|
||||
|
||||
import com.craftaro.core.utils.PlayerUtils;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.epicfurnaces.furnace.FurnaceBuilder;
|
||||
import com.songoda.epicfurnaces.settings.Settings;
|
||||
import com.songoda.epicfurnaces.utils.GameArea;
|
||||
import com.craftaro.epicfurnaces.furnace.FurnaceBuilder;
|
||||
import com.craftaro.epicfurnaces.settings.Settings;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epicfurnaces.utils.GameArea;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -92,7 +92,7 @@ public class BlockListeners implements Listener {
|
||||
.setPlacedBy(event.getPlayer().getUniqueId()).build()
|
||||
: new FurnaceBuilder(location).setPlacedBy(event.getPlayer().getUniqueId()).build();
|
||||
|
||||
this.plugin.getDataManager().createFurnace(furnace);
|
||||
this.plugin.getDataManager().save(furnace);
|
||||
this.plugin.getFurnaceManager().addFurnace(furnace);
|
||||
|
||||
this.plugin.updateHolograms(Collections.singleton(furnace));
|
||||
@ -132,6 +132,6 @@ public class BlockListeners implements Listener {
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), item);
|
||||
}
|
||||
this.plugin.getFurnaceManager().removeFurnace(block.getLocation());
|
||||
this.plugin.getDataManager().deleteFurnace(furnace);
|
||||
this.plugin.getDataManager().delete(furnace);
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.epicfurnaces.listeners;
|
||||
package com.craftaro.epicfurnaces.listeners;
|
||||
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.epicfurnaces.furnace.FurnaceManager;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epicfurnaces.furnace.FurnaceManager;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -27,7 +27,7 @@ public class EntityListeners implements Listener {
|
||||
}
|
||||
|
||||
this.furnaceManager.removeFurnace(block.getLocation());
|
||||
this.plugin.getDataManager().deleteFurnace(furnace);
|
||||
this.plugin.getDataManager().delete(furnace);
|
||||
this.plugin.clearHologram(furnace);
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.epicfurnaces.listeners;
|
||||
package com.craftaro.epicfurnaces.listeners;
|
||||
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.epicfurnaces.furnace.levels.Level;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epicfurnaces.furnace.levels.Level;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
@ -1,13 +1,13 @@
|
||||
package com.songoda.epicfurnaces.listeners;
|
||||
package com.craftaro.epicfurnaces.listeners;
|
||||
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epichoppers.EpicHoppersApi;
|
||||
import com.craftaro.epichoppers.player.PlayerData;
|
||||
import com.craftaro.epichoppers.player.SyncType;
|
||||
import com.craftaro.core.compatibility.CompatibleHand;
|
||||
import com.craftaro.core.gui.GuiManager;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.craftaro.skyblock.SkyBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.epicfurnaces.listeners;
|
||||
package com.craftaro.epicfurnaces.listeners;
|
||||
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
@ -1,11 +1,11 @@
|
||||
package com.songoda.epicfurnaces.settings;
|
||||
package com.craftaro.epicfurnaces.settings;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import com.craftaro.core.configuration.ConfigSetting;
|
||||
import com.craftaro.core.hooks.EconomyManager;
|
||||
import com.craftaro.core.hooks.HologramManager;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
|
||||
public class Settings {
|
||||
static final Config CONFIG = EpicFurnaces.getPlugin(EpicFurnaces.class).getCoreConfig();
|
@ -1,11 +1,11 @@
|
||||
package com.songoda.epicfurnaces.storage;
|
||||
package com.craftaro.epicfurnaces.storage;
|
||||
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.boost.BoostData;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.epicfurnaces.utils.Methods;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.boost.BoostData;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epicfurnaces.utils.Methods;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfurnaces.storage;
|
||||
package com.craftaro.epicfurnaces.storage;
|
||||
|
||||
import com.songoda.epicfurnaces.utils.Methods;
|
||||
import com.craftaro.epicfurnaces.utils.Methods;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.ArrayList;
|
@ -1,4 +1,4 @@
|
||||
package com.songoda.epicfurnaces.storage;
|
||||
package com.craftaro.epicfurnaces.storage;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
@ -1,9 +1,9 @@
|
||||
package com.songoda.epicfurnaces.storage.types;
|
||||
package com.craftaro.epicfurnaces.storage.types;
|
||||
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.storage.Storage;
|
||||
import com.songoda.epicfurnaces.storage.StorageItem;
|
||||
import com.songoda.epicfurnaces.storage.StorageRow;
|
||||
import com.craftaro.epicfurnaces.storage.StorageItem;
|
||||
import com.craftaro.epicfurnaces.storage.StorageRow;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.storage.Storage;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.songoda.epicfurnaces.tasks;
|
||||
package com.craftaro.epicfurnaces.tasks;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.epicfurnaces.settings.Settings;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epicfurnaces.settings.Settings;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.epicfurnaces.tasks;
|
||||
package com.craftaro.epicfurnaces.tasks;
|
||||
|
||||
import com.craftaro.core.hooks.HologramManager;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class HologramTask extends BukkitRunnable {
|
@ -1,4 +1,4 @@
|
||||
package com.songoda.epicfurnaces.utils;
|
||||
package com.craftaro.epicfurnaces.utils;
|
||||
|
||||
/**
|
||||
* Represents a cost type when making a purchase from EpicFurnaces
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfurnaces.utils;
|
||||
package com.craftaro.epicfurnaces.utils;
|
||||
|
||||
import com.songoda.epicfurnaces.settings.Settings;
|
||||
import com.craftaro.epicfurnaces.settings.Settings;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.epicfurnaces.utils;
|
||||
package com.craftaro.epicfurnaces.utils;
|
||||
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
@ -1,11 +0,0 @@
|
||||
package com.songoda.epicfurnaces.compatibility;
|
||||
|
||||
import com.songoda.skyblock.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.skyblock.permission.BasicPermission;
|
||||
import com.songoda.skyblock.permission.PermissionType;
|
||||
|
||||
public class EpicFurnacesPermission extends BasicPermission {
|
||||
public EpicFurnacesPermission() {
|
||||
super("EpicFurnaces", CompatibleMaterial.FIRE_CHARGE, PermissionType.GENERIC);
|
||||
}
|
||||
}
|
@ -1,377 +0,0 @@
|
||||
package com.songoda.epicfurnaces.database;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||
import com.craftaro.core.database.DataManagerAbstract;
|
||||
import com.craftaro.core.database.DatabaseConnector;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.boost.BoostData;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.epicfurnaces.furnace.FurnaceBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class DataManager extends DataManagerAbstract {
|
||||
private final Set<Furnace> furnaceUpdateQueue = new HashSet<>();
|
||||
|
||||
public DataManager(DatabaseConnector connector, Plugin plugin) {
|
||||
super(connector, plugin);
|
||||
|
||||
// Updating furnaces every 3 minutes should be plenty I believe
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, this::bulkUpdateFurnaceQueue, 20 * 60 * 3, 20 * 60 * 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdownTaskQueue() {
|
||||
bulkUpdateFurnaceQueue();
|
||||
|
||||
super.shutdownTaskQueue();
|
||||
}
|
||||
|
||||
public void queueFurnaceForUpdate(Furnace furnace) {
|
||||
synchronized (this.furnaceUpdateQueue) {
|
||||
this.furnaceUpdateQueue.add(furnace);
|
||||
}
|
||||
}
|
||||
|
||||
public void dequeueFurnaceForUpdate(Furnace furnace) {
|
||||
synchronized (this.furnaceUpdateQueue) {
|
||||
this.furnaceUpdateQueue.remove(furnace);
|
||||
}
|
||||
}
|
||||
|
||||
public void bulkUpdateFurnaceQueue() {
|
||||
synchronized (this.furnaceUpdateQueue) {
|
||||
updateFurnaces(new LinkedHashSet<>(this.furnaceUpdateQueue));
|
||||
this.furnaceUpdateQueue.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void createBoost(BoostData boostData) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String createBoostedPlayer = "INSERT INTO " + this.getTablePrefix() + "boosted_players (player, multiplier, end_time) VALUES (?, ?, ?)";
|
||||
PreparedStatement statement = connection.prepareStatement(createBoostedPlayer);
|
||||
statement.setString(1, boostData.getPlayer().toString());
|
||||
statement.setInt(2, boostData.getMultiplier());
|
||||
statement.setLong(3, boostData.getEndTime());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getBoosts(Consumer<List<BoostData>> callback) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
List<BoostData> boosts = new ArrayList<>();
|
||||
|
||||
Statement statement = connection.createStatement();
|
||||
String selectBoostedPlayers = "SELECT * FROM " + this.getTablePrefix() + "boosted_players";
|
||||
ResultSet result = statement.executeQuery(selectBoostedPlayers);
|
||||
while (result.next()) {
|
||||
UUID player = UUID.fromString(result.getString("player"));
|
||||
int multiplier = result.getInt("multiplier");
|
||||
long endTime = result.getLong("end_time");
|
||||
boosts.add(new BoostData(multiplier, endTime, player));
|
||||
}
|
||||
|
||||
this.sync(() -> callback.accept(boosts));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteBoost(BoostData boostData) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String deleteBoost = "DELETE FROM " + this.getTablePrefix() + "boosted_players WHERE end_time = ?";
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(deleteBoost);
|
||||
statement.setLong(1, boostData.getEndTime());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void createFurnaces(List<Furnace> furnaces) {
|
||||
for (Furnace furnace : furnaces) {
|
||||
createFurnace(furnace);
|
||||
}
|
||||
}
|
||||
|
||||
public void createFurnace(Furnace furnace) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String createFurnace = "INSERT INTO " + this.getTablePrefix() + "active_furnaces (level, uses, nickname, placed_by, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(createFurnace)) {
|
||||
statement.setInt(1, furnace.getLevel().getLevel());
|
||||
statement.setInt(2, furnace.getUses());
|
||||
statement.setString(3, furnace.getNickname());
|
||||
statement.setString(4,
|
||||
furnace.getPlacedBy() == null ? null : furnace.getPlacedBy().toString());
|
||||
|
||||
statement.setString(5, furnace.getLocation().getWorld().getName());
|
||||
statement.setInt(6, furnace.getLocation().getBlockX());
|
||||
statement.setInt(7, furnace.getLocation().getBlockY());
|
||||
statement.setInt(8, furnace.getLocation().getBlockZ());
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
int furnaceId = this.lastInsertedId(connection, "active_furnaces");
|
||||
furnace.setId(furnaceId);
|
||||
|
||||
String createAccessList = "INSERT INTO " + this.getTablePrefix() + "access_list (furnace_id, uuid) VALUES (?, ?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(createAccessList)) {
|
||||
for (UUID uuid : furnace.getAccessList()) {
|
||||
statement.setInt(1, furnace.getId());
|
||||
statement.setString(2, uuid.toString());
|
||||
statement.addBatch();
|
||||
}
|
||||
statement.executeBatch();
|
||||
}
|
||||
|
||||
String createNewLevel = "INSERT INTO " + this.getTablePrefix() + "to_level_new (furnace_id, item, amount) VALUES (?, ?, ?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(createNewLevel)) {
|
||||
for (Map.Entry<XMaterial, Integer> entry : furnace.getToLevel().entrySet()) {
|
||||
statement.setInt(1, furnace.getId());
|
||||
statement.setString(2, entry.getKey().name());
|
||||
statement.setInt(3, entry.getValue());
|
||||
statement.addBatch();
|
||||
}
|
||||
statement.executeBatch();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateFurnaces(Collection<Furnace> furnaces) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String updateFurnace = "UPDATE " + this.getTablePrefix() + "active_furnaces SET level =?, nickname =?, uses =? WHERE id =?;";
|
||||
PreparedStatement statement = connection.prepareStatement(updateFurnace);
|
||||
for (Furnace furnace : furnaces) {
|
||||
statement.setInt(1, furnace.getLevel().getLevel());
|
||||
statement.setString(2, furnace.getNickname());
|
||||
statement.setInt(3, furnace.getUses());
|
||||
statement.setInt(4, furnace.getId());
|
||||
|
||||
statement.addBatch();
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteFurnace(Furnace furnace) {
|
||||
dequeueFurnaceForUpdate(furnace);
|
||||
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String deleteFurnace = "DELETE FROM " + this.getTablePrefix() + "active_furnaces WHERE id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteFurnace)) {
|
||||
statement.setInt(1, furnace.getId());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
String deleteAccessList = "DELETE FROM " + this.getTablePrefix() + "access_list WHERE furnace_id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteAccessList)) {
|
||||
statement.setInt(1, furnace.getId());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
String deleteLevelupItems = "DELETE FROM " + this.getTablePrefix() + "to_level_new WHERE furnace_id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteLevelupItems)) {
|
||||
statement.setInt(1, furnace.getId());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void createAccessPlayer(Furnace furnace, UUID uuid) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String createAccessPlayer = "INSERT INTO " + this.getTablePrefix() + "access_list (furnace_id, uuid) VALUES (?, ?)";
|
||||
PreparedStatement statement = connection.prepareStatement(createAccessPlayer);
|
||||
statement.setInt(1, furnace.getId());
|
||||
statement.setString(2, uuid.toString());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// These will be used in the future when the access list gets revamped.
|
||||
// Probably by me since I already have a custom version in my server.
|
||||
public void deleteAccessPlayer(Furnace furnace, UUID uuid) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String deleteAccessPlayer = "DELETE FROM " + this.getTablePrefix() + "access_list WHERE furnace_id = ? AND uuid = ?";
|
||||
PreparedStatement statement = connection.prepareStatement(deleteAccessPlayer);
|
||||
statement.setInt(1, furnace.getId());
|
||||
statement.setString(2, uuid.toString());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateAccessPlayers(Furnace furnace) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String deletePlayers = "DELETE FROM " + this.getTablePrefix() + "access_list WHERE furnace_id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deletePlayers)) {
|
||||
statement.setInt(1, furnace.getId());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
String createAccessPlayer = "INSERT INTO " + this.getTablePrefix() + "access_list (furnace_id, uuid) VALUES (?, ?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(createAccessPlayer)) {
|
||||
for (UUID uuid : furnace.getAccessList()) {
|
||||
statement.setInt(1, furnace.getId());
|
||||
statement.setString(2, uuid.toString());
|
||||
statement.addBatch();
|
||||
}
|
||||
statement.executeBatch();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateLevelupItems(Furnace furnace, XMaterial material, int amount) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String deleteLevelupItem = "DELETE FROM " + this.getTablePrefix() + "to_level_new WHERE furnace_id = ? AND item = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteLevelupItem)) {
|
||||
statement.setInt(1, furnace.getId());
|
||||
statement.setString(2, material.name());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
String createLevelupItem = "INSERT INTO " + this.getTablePrefix() + "to_level_new (furnace_id, item, amount) VALUES (?, ?, ?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(createLevelupItem)) {
|
||||
statement.setInt(1, furnace.getId());
|
||||
statement.setString(2, material.name());
|
||||
statement.setInt(3, amount);
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getFurnaces(Consumer<Map<Integer, Furnace>> callback) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
Map<Integer, Furnace> furnaces = new HashMap<>();
|
||||
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
String selectFurnaces = "SELECT * FROM " + this.getTablePrefix() + "active_furnaces";
|
||||
ResultSet result = statement.executeQuery(selectFurnaces);
|
||||
while (result.next()) {
|
||||
World world = Bukkit.getWorld(result.getString("world"));
|
||||
|
||||
if (world == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int id = result.getInt("id");
|
||||
int level = result.getInt("level");
|
||||
int uses = result.getInt("uses");
|
||||
|
||||
String placedByStr = result.getString("placed_by");
|
||||
UUID placedBy = placedByStr == null ? null : UUID.fromString(result.getString("placed_by"));
|
||||
|
||||
String nickname = result.getString("nickname");
|
||||
|
||||
int x = result.getInt("x");
|
||||
int y = result.getInt("y");
|
||||
int z = result.getInt("z");
|
||||
Location location = new Location(world, x, y, z);
|
||||
|
||||
Furnace furnace = new FurnaceBuilder(location)
|
||||
.setId(id)
|
||||
.setLevel(EpicFurnaces.getInstance().getLevelManager().getLevel(level))
|
||||
.setUses(uses)
|
||||
.setPlacedBy(placedBy)
|
||||
.setNickname(nickname)
|
||||
.build();
|
||||
|
||||
furnaces.put(id, furnace);
|
||||
}
|
||||
}
|
||||
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
String selectAccessList = "SELECT * FROM " + this.getTablePrefix() + "access_list";
|
||||
ResultSet result = statement.executeQuery(selectAccessList);
|
||||
while (result.next()) {
|
||||
int id = result.getInt("furnace_id");
|
||||
UUID uuid = UUID.fromString(result.getString("uuid"));
|
||||
|
||||
Furnace furnace = furnaces.get(id);
|
||||
if (furnace == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
furnace.addToAccessList(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
String selectLevelupItems = "SELECT * FROM " + this.getTablePrefix() + "to_level_new";
|
||||
ResultSet result = statement.executeQuery(selectLevelupItems);
|
||||
while (result.next()) {
|
||||
int id = result.getInt("furnace_id");
|
||||
XMaterial material = CompatibleMaterial.getMaterial(result.getString("item")).get();
|
||||
int amount = result.getInt("amount");
|
||||
|
||||
Furnace furnace = furnaces.get(id);
|
||||
if (furnace == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
furnace.addToLevel(material, amount);
|
||||
}
|
||||
}
|
||||
this.sync(() -> callback.accept(furnaces));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user