Revert "Made it possible to save/load shops"
This reverts commit 91c0c2ecd1.
This commit is contained in:
parent
91c0c2ecd1
commit
7fb6325285
|
|
@ -1,9 +1,7 @@
|
|||
package com.alttd.playershops;
|
||||
|
||||
import com.alttd.playershops.config.Config;
|
||||
import com.alttd.playershops.config.DatabaseConfig;
|
||||
import com.alttd.playershops.config.MessageConfig;
|
||||
import com.alttd.playershops.database.Database;
|
||||
import com.alttd.playershops.handler.ShopHandler;
|
||||
import com.alttd.playershops.listener.PlayerListener;
|
||||
import com.alttd.playershops.listener.ShopListener;
|
||||
|
|
@ -38,8 +36,6 @@ public class PlayerShops extends JavaPlugin {
|
|||
registerListeners();
|
||||
registerCommands();
|
||||
|
||||
Database.getDatabase(); //Start database
|
||||
|
||||
shopHandler = new ShopHandler(instance);
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +76,6 @@ public class PlayerShops extends JavaPlugin {
|
|||
public void reloadConfigs() {
|
||||
Config.reload();
|
||||
MessageConfig.reload();
|
||||
DatabaseConfig.reload();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class DatabaseConfig extends AbstractConfiguration {
|
|||
public static String DRIVER = "mysql";
|
||||
public static String IP = "localhost";
|
||||
public static String PORT = "3306";
|
||||
public static String DATABASE_NAME = "playershops";
|
||||
public static String DATABASE_NAME = "AltitudeQuests";
|
||||
public static String USERNAME = "root";
|
||||
public static String PASSWORD = "root";
|
||||
|
||||
|
|
|
|||
|
|
@ -148,66 +148,4 @@ public class ShopQueries {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static int saveShopWithoutId(AbstractShop shop) {
|
||||
String sql = "INSERT INTO shops " +
|
||||
"(owner_name, owner_uuid, shop_type, server, container_location, sign_location, " +
|
||||
"price, amount, balance, item_one, item_two, last_transaction)" +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" +
|
||||
"ON DUPLICATE KEY UPDATE owner_name = ?, owner_uuid = ?, shop_type = ?, server = ?, " +
|
||||
"container_location = ?, sign_location = ?, price = ?, amount = ?, balance = ?, " +
|
||||
"item_one = ?, item_two = ?, last_transaction = ?";
|
||||
try {
|
||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||
|
||||
statement.setString(2, shop.getOwnerName());
|
||||
statement.setString(3, shop.getOwnerUUID().toString());
|
||||
statement.setString(4, shop.getServer());
|
||||
statement.setString(5, shop.getType().toString());
|
||||
statement.setString(6, locationToString(shop.getContainerLocation()));
|
||||
statement.setString(7, locationToString(shop.getSignLocation()));
|
||||
statement.setDouble(8, shop.getPrice());
|
||||
statement.setInt(9, shop.getAmount());
|
||||
statement.setDouble(10, shop.getBalance());
|
||||
statement.setBytes(11, shop.getItemStack().serializeAsBytes());
|
||||
statement.setBytes(12, shop.getSecondaryItem().serializeAsBytes());
|
||||
statement.setLong(13, shop.getLastTransaction());
|
||||
//repeat everything except id for update
|
||||
statement.setString(14, shop.getOwnerName());
|
||||
statement.setString(15, shop.getOwnerUUID().toString());
|
||||
statement.setString(16, shop.getServer());
|
||||
statement.setString(17, shop.getType().toString());
|
||||
statement.setString(18, locationToString(shop.getContainerLocation()));
|
||||
statement.setString(19, locationToString(shop.getSignLocation()));
|
||||
statement.setDouble(20, shop.getPrice());
|
||||
statement.setInt(21, shop.getAmount());
|
||||
statement.setDouble(22, shop.getBalance());
|
||||
statement.setBytes(23, shop.getItemStack().serializeAsBytes());
|
||||
statement.setBytes(24, shop.getSecondaryItem().serializeAsBytes());
|
||||
statement.setLong(25, shop.getLastTransaction());
|
||||
|
||||
if (statement.executeUpdate() != 1) {
|
||||
//TODO error
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return loadShopWithoutId(shop);
|
||||
}
|
||||
|
||||
private static int loadShopWithoutId(AbstractShop shop) {
|
||||
String sql = "SELECT FROM shops WHERE server = ? AND container_location = ?";
|
||||
try {
|
||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||
statement.setString(1, shop.getServer());
|
||||
statement.setString(2, locationToString(shop.getContainerLocation()));
|
||||
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next())
|
||||
return resultSet.getInt("id");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,9 @@ package com.alttd.playershops.handler;
|
|||
|
||||
import com.alttd.playershops.PlayerShops;
|
||||
import com.alttd.playershops.config.Config;
|
||||
import com.alttd.playershops.database.ShopQueries;
|
||||
import com.alttd.playershops.events.PlayerCreateShopEvent;
|
||||
import com.alttd.playershops.shop.AbstractShop;
|
||||
import com.alttd.playershops.shop.ShopType;
|
||||
import com.alttd.playershops.utils.Logger;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import lombok.Getter;
|
||||
|
|
@ -16,7 +14,6 @@ import org.bukkit.Tag;
|
|||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
|
@ -37,13 +34,6 @@ public class ShopHandler {
|
|||
shopBuildLimits = new Object2IntOpenHashMap<>();
|
||||
shopBuildLimits.defaultReturnValue(Config.shopLimit);
|
||||
shopMaterials = new ArrayList<>(); // TODO move into parent method where materials are loaded in.
|
||||
loadShops();
|
||||
}
|
||||
|
||||
private void loadShops() {
|
||||
for (AbstractShop shop : ShopQueries.loadShops()) {
|
||||
shopLocation.put(shop.getContainerLocation(), shop);
|
||||
}
|
||||
}
|
||||
|
||||
public AbstractShop getShop(Location location) {
|
||||
|
|
@ -117,19 +107,6 @@ public class ShopHandler {
|
|||
if(playerCreateShopEvent.isCancelled())
|
||||
return null;
|
||||
|
||||
shopLocation.put(shop.getContainerLocation(), shop);
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int id = ShopQueries.saveShopWithoutId(shop);
|
||||
if (id == -1)
|
||||
Logger.warn("Tried to save a shop without id but couldn't get an id back [" + shop + "]");
|
||||
else
|
||||
shop.setId(id);
|
||||
}
|
||||
}.runTaskAsynchronously(PlayerShops.getInstance());
|
||||
|
||||
return shop;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ import java.util.UUID;
|
|||
|
||||
public abstract class AbstractShop {
|
||||
|
||||
@Getter @Setter
|
||||
private int id = -1;
|
||||
@Getter
|
||||
private int id;
|
||||
private String ownerName;
|
||||
@Getter
|
||||
private UUID ownerUUID;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user