9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-28 19:39:06 +00:00

1.3.0-beta-2

This commit is contained in:
Xiao-MoMi
2023-03-05 00:45:11 +08:00
parent 1b1cf93b2a
commit 413b8cf6df
17 changed files with 357 additions and 159 deletions

View File

@@ -35,7 +35,7 @@ public class OpenBagCommand extends AbstractSubCommand {
return true;
}
viewer.closeInventory();
CustomFishing.getInstance().getBagDataManager().openFishingBag(viewer, viewer);
CustomFishing.getInstance().getBagDataManager().openFishingBag(viewer, viewer, false);
}
return true;
}

View File

@@ -52,9 +52,9 @@ public class OpenCommand extends AbstractSubCommand {
return true;
}
player.closeInventory();
CustomFishing.getInstance().getBagDataManager().openFishingBag(player, player);
CustomFishing.getInstance().getBagDataManager().openFishingBag(player, player, false);
}
if (args.size() == 1) {
if (args.size() >= 1) {
if (!sender.hasPermission("customfishing.admin")) {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.noPerm);
return true;
@@ -65,7 +65,7 @@ public class OpenCommand extends AbstractSubCommand {
return true;
}
player.closeInventory();
CustomFishing.getInstance().getBagDataManager().openFishingBag(player, offlinePlayer);
CustomFishing.getInstance().getBagDataManager().openFishingBag(player, offlinePlayer, args.size() >= 2 && args.get(1).equals("--force"));
}
return true;
}

View File

@@ -29,8 +29,8 @@ public interface DataStorageInterface {
void initialize();
void disable();
Inventory loadBagData(OfflinePlayer player);
void saveBagData(PlayerBagData playerBagData);
void loadSellCache(Player player);
void saveSellCache(UUID uuid, PlayerSellData playerSellData);
Inventory loadBagData(OfflinePlayer player, boolean force);
void saveBagData(PlayerBagData playerBagData, boolean unlock);
PlayerSellData loadSellData(Player player, boolean force);
void saveSellData(UUID uuid, PlayerSellData playerSellData, boolean unlock);
}

View File

@@ -52,7 +52,7 @@ public class FileStorageImpl implements DataStorageInterface {
}
@Override
public Inventory loadBagData(OfflinePlayer player) {
public Inventory loadBagData(OfflinePlayer player, boolean force) {
YamlConfiguration config = ConfigUtil.readData(new File(plugin.getDataFolder(), "fishingbag_data" + File.separator + player.getUniqueId() + ".yml"));
String contents = config.getString("contents");
int size = config.getInt("size", 9);
@@ -63,7 +63,7 @@ public class FileStorageImpl implements DataStorageInterface {
}
@Override
public void saveBagData(PlayerBagData playerBagData) {
public void saveBagData(PlayerBagData playerBagData, boolean unlock) {
YamlConfiguration data = new YamlConfiguration();
Inventory inventory = playerBagData.getInventory();
String contents = InventoryUtil.toBase64(inventory.getContents());
@@ -78,16 +78,16 @@ public class FileStorageImpl implements DataStorageInterface {
}
@Override
public void loadSellCache(Player player) {
public PlayerSellData loadSellData(Player player, boolean force) {
UUID uuid = player.getUniqueId();
YamlConfiguration data = ConfigUtil.readData(new File(plugin.getDataFolder(), "sell-data" + File.separator + uuid + ".yml"));
int date = data.getInt("date");
double money = data.getDouble("earnings");
plugin.getSellManager().loadPlayerToCache(player.getUniqueId(), date, money);
return new PlayerSellData(money, date);
}
@Override
public void saveSellCache(UUID uuid, PlayerSellData playerSellData) {
public void saveSellData(UUID uuid, PlayerSellData playerSellData, boolean unlock) {
YamlConfiguration data = new YamlConfiguration();
data.set("date", playerSellData.getDate());
data.set("earnings", playerSellData.getMoney());

View File

@@ -49,7 +49,7 @@ public class MySQLStorageImpl implements DataStorageInterface {
public void initialize() {
sqlConnection.createNewHikariConfiguration();
createTableIfNotExist(sqlConnection.getTablePrefix() + "_fishingbag", SqlConstants.SQL_CREATE_BAG_TABLE);
createTableIfNotExist(sqlConnection.getTablePrefix() + "_sellcache", SqlConstants.SQL_CREATE_SELL_TABLE);
createTableIfNotExist(sqlConnection.getTablePrefix() + "_selldata", SqlConstants.SQL_CREATE_SELL_TABLE);
}
@Override
@@ -58,21 +58,29 @@ public class MySQLStorageImpl implements DataStorageInterface {
}
@Override
public Inventory loadBagData(OfflinePlayer player) {
public Inventory loadBagData(OfflinePlayer player, boolean force) {
Inventory inventory = null;
String sql = String.format(SqlConstants.SQL_SELECT_BAG_BY_UUID, sqlConnection.getTablePrefix() + "_fishingbag");
String sql = String.format(SqlConstants.SQL_SELECT_BAG_BY_UUID, sqlConnection.getTablePrefix() + "_" + "fishingbag");
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, player.getUniqueId().toString());
ResultSet rs = statement.executeQuery();
if (rs.next()) {
int size = rs.getInt(2);
String contents = rs.getString(3);
int version = rs.getInt(2);
if (!force && version != 0) {
statement.close();
connection.close();
return null;
}
int size = rs.getInt(3);
String contents = rs.getString(4);
ItemStack[] itemStacks = InventoryUtil.getInventoryItems(contents);
inventory = Bukkit.createInventory(null, size, "{CustomFishing_Bag_" + player.getName() + "}");
if (itemStacks != null) inventory.setContents(itemStacks);
lockData(player.getUniqueId(), "fishingbag");
}
else {
inventory = Bukkit.createInventory(null, 9, "{CustomFishing_Bag_" + player.getName() + "}");
insertBagData(player.getUniqueId(), InventoryUtil.toBase64(inventory.getContents()));
}
} catch (SQLException e) {
e.printStackTrace();
@@ -81,133 +89,139 @@ public class MySQLStorageImpl implements DataStorageInterface {
}
@Override
public void saveBagData(PlayerBagData playerBagData) {
public void saveBagData(PlayerBagData playerBagData, boolean unlock) {
UUID uuid = playerBagData.getPlayer().getUniqueId();
Inventory inventory = playerBagData.getInventory();
String contents = InventoryUtil.toBase64(inventory.getContents());
if (contents == null) contents = "";
if (exists(uuid, SqlConstants.SQL_SELECT_BAG_BY_UUID, "fishingbag")) {
updateBagData(uuid, inventory.getSize(), contents);
}
else {
insertBagData(uuid, inventory.getSize(), contents);
}
updateBagData(uuid, inventory.getSize(), contents, unlock);
}
/**
* Whether the data is loaded
* @param player player
* @return success or not
*/
@Override
public void loadSellCache(Player player) {
String sql = String.format(SqlConstants.SQL_SELECT_SELL_BY_UUID, sqlConnection.getTablePrefix() + "_sellcache");
public PlayerSellData loadSellData(Player player, boolean force) {
PlayerSellData playerSellData = null;
String sql = String.format(SqlConstants.SQL_SELECT_SELL_BY_UUID, sqlConnection.getTablePrefix() + "_" + "selldata");
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, player.getUniqueId().toString());
ResultSet rs = statement.executeQuery();
if (rs.next()) {
int date = rs.getInt(2);
int money = rs.getInt(3);
plugin.getSellManager().loadPlayerToCache(player.getUniqueId(), date, money);
int version = rs.getInt(2);
if (!force && version != 0) {
statement.close();
connection.close();
return null;
}
int date = rs.getInt(3);
int money = rs.getInt(4);
playerSellData = new PlayerSellData(money, date);
lockData(player.getUniqueId(), "selldata");
}
else {
plugin.getSellManager().loadPlayerToCache(player.getUniqueId(), Calendar.getInstance().get(Calendar.DATE), 0);
Calendar calendar = Calendar.getInstance();
playerSellData = new PlayerSellData(calendar.get(Calendar.MONTH) * 100 + calendar.get(Calendar.DATE), 0);
insertSellData(player.getUniqueId(), playerSellData.getDate());
}
} catch (SQLException e) {
e.printStackTrace();
}
return playerSellData;
}
@Override
public void saveSellCache(UUID uuid, PlayerSellData playerSellData) {
if (exists(uuid, SqlConstants.SQL_SELECT_SELL_BY_UUID, "sellcache")) {
updateSellData(uuid, playerSellData.getDate(), (int) playerSellData.getMoney());
}
else {
insertSellData(uuid, playerSellData.getDate(), (int) playerSellData.getMoney());
}
public void saveSellData(UUID uuid, PlayerSellData playerSellData, boolean unlock) {
updateSellData(uuid, playerSellData.getDate(), (int) playerSellData.getMoney(), unlock);
}
private void createTableIfNotExist(String table, String sqlStat) {
String sql = String.format(sqlStat, table);
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.executeUpdate();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to create table");
}
}
private void insertBagData(UUID uuid, int size, String contents) {
String sql = String.format(SqlConstants.SQL_INSERT_BAG, sqlConnection.getTablePrefix() + "_fishingbag");
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
private void insertBagData(UUID uuid, String contents) {
String sql = String.format(SqlConstants.SQL_INSERT_BAG, sqlConnection.getTablePrefix() + "_" + "fishingbag");
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, uuid.toString());
statement.setInt(2, 1);
statement.setInt(3, 9);
statement.setString(4, contents);
statement.executeUpdate();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to insert data for " + uuid);
}
}
private void insertSellData(UUID uuid, int date) {
String sql = String.format(SqlConstants.SQL_INSERT_SELL, sqlConnection.getTablePrefix() + "_" + "selldata");
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, uuid.toString());
statement.setInt(2, 1);
statement.setInt(3, date);
statement.setInt(4, 0);
statement.executeUpdate();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to insert data for " + uuid);
}
}
private void updateBagData(UUID uuid, int size, String contents, boolean unlock) {
String sql = String.format(SqlConstants.SQL_UPDATE_BAG_BY_UUID, sqlConnection.getTablePrefix() + "_" + "fishingbag");
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setInt(1, unlock ? 0 : 1);
statement.setInt(2, size);
statement.setString(3, contents);
statement.setString(4, uuid.toString());
statement.executeUpdate();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to insert data for " + uuid);
AdventureUtil.consoleMessage("[CustomFishing] Failed to update data for " + uuid);
}
}
private void insertSellData(UUID uuid, int date, int money) {
String sql = String.format(SqlConstants.SQL_INSERT_SELL, sqlConnection.getTablePrefix() + "_sellcache");
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, uuid.toString());
private void updateSellData(UUID uuid, int date, int money, boolean unlock) {
String sql = String.format(SqlConstants.SQL_UPDATE_SELL_BY_UUID, sqlConnection.getTablePrefix() + "_" + "selldata");
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setInt(1, unlock ? 0 : 1);
statement.setInt(2, date);
statement.setInt(3, money);
statement.executeUpdate();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to insert data for " + uuid);
}
}
private void updateBagData(UUID uuid, int size, String contents) {
String sql = String.format(SqlConstants.SQL_UPDATE_BAG_BY_UUID, sqlConnection.getTablePrefix() + "_fishingbag");
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setInt(1, size);
statement.setString(2, contents);
statement.setString(3, uuid.toString());
statement.setString(4, uuid.toString());
statement.executeUpdate();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to update data for " + uuid);
}
}
private void updateSellData(UUID uuid, int date, int money) {
String sql = String.format(SqlConstants.SQL_UPDATE_SELL_BY_UUID, sqlConnection.getTablePrefix() + "_sellcache");
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setInt(1, date);
statement.setInt(2, money);
statement.setString(3, uuid.toString());
statement.executeUpdate();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to update data for " + uuid);
}
}
public boolean exists(UUID uuid, String sqlStat, String suffix) {
String sql = String.format(sqlStat, sqlConnection.getTablePrefix() + "_" + suffix);
boolean exist;
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, uuid.toString());
ResultSet rs = statement.executeQuery();
exist = rs.next();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to select data for " + uuid);
return false;
}
return exist;
}
public void migrate() {
String sql_1 = String.format(SqlConstants.SQL_ALTER_TABLE, sqlConnection.getTablePrefix() + "_fishingbag");
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql_1)) {
String sql_1 = String.format(SqlConstants.SQL_ALTER_TABLE, sqlConnection.getTablePrefix() + "_" + "fishingbag");
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql_1)) {
statement.executeUpdate();
AdventureUtil.consoleMessage("<green>[CustomFishing] 1/2 tables updated");
} catch (SQLException ex) {
AdventureUtil.consoleMessage("<red>[CustomFishing] Failed to migrate data");
}
String sql_2 = String.format(SqlConstants.SQL_ALTER_TABLE, sqlConnection.getTablePrefix() + "_sellcache");
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql_2)) {
String sql_2 = String.format(SqlConstants.SQL_ALTER_TABLE, sqlConnection.getTablePrefix() + "_" + "selldata");
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql_2)) {
statement.executeUpdate();
AdventureUtil.consoleMessage("<green>[CustomFishing] 2/2 tables updated");
} catch (SQLException ex) {
AdventureUtil.consoleMessage("<red>[CustomFishing] Failed to migrate data");
}
}
public void lockData(UUID uuid, String table_suffix) {
String sql = String.format(SqlConstants.SQL_LOCK_BY_UUID, sqlConnection.getTablePrefix() + "_" + table_suffix);
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql);) {
statement.setString(1, uuid.toString());
statement.executeUpdate();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("<red>[CustomFishing] Failed to lock data for " + uuid);
}
}
}

View File

@@ -21,12 +21,13 @@ public class SqlConstants {
public static final String SQL_CREATE_BAG_TABLE = "CREATE TABLE IF NOT EXISTS `%s` ( `uuid` VARCHAR(36) NOT NULL, `version` INT(2) NOT NULL, `size` INT(8) NOT NULL, `contents` LONGTEXT NOT NULL, PRIMARY KEY (`uuid`) )";
public static final String SQL_CREATE_SELL_TABLE = "CREATE TABLE IF NOT EXISTS `%s` ( `uuid` VARCHAR(36) NOT NULL, `version` INT(2) NOT NULL, `date` INT(4) NOT NULL, `money` INT(12) NOT NULL, PRIMARY KEY (`uuid`) )";
public static final String SQL_INSERT_BAG = "INSERT INTO `%s`(`uuid`, `version`, `size`, `contents`) VALUES (?, ?, ?)";
public static final String SQL_INSERT_SELL = "INSERT INTO `%s`(`uuid`, `version`, `date`, `money`) VALUES (?, ?, ?)";
public static final String SQL_UPDATE_BAG_BY_UUID = "UPDATE `%s` SET `version` = 0, `size` = ?, `contents` = ? WHERE `uuid` = ?";
public static final String SQL_UPDATE_SELL_BY_UUID = "UPDATE `%s` SET `version` = 0, `date` = ?, `money` = ? WHERE `uuid` = ?";
public static final String SQL_INSERT_BAG = "INSERT INTO `%s`(`uuid`, `version`, `size`, `contents`) VALUES (?, ?, ?, ?)";
public static final String SQL_INSERT_SELL = "INSERT INTO `%s`(`uuid`, `version`, `date`, `money`) VALUES (?, ?, ?, ?)";
public static final String SQL_UPDATE_BAG_BY_UUID = "UPDATE `%s` SET `version` = ?, `size` = ?, `contents` = ? WHERE `uuid` = ?";
public static final String SQL_UPDATE_SELL_BY_UUID = "UPDATE `%s` SET `version` = ?, `date` = ?, `money` = ? WHERE `uuid` = ?";
public static final String SQL_SELECT_BAG_BY_UUID = "SELECT * FROM `%s` WHERE `uuid` = ?";
public static final String SQL_SELECT_SELL_BY_UUID = "SELECT * FROM `%s` WHERE `uuid` = ?";
public static final String SQL_LOCK_BY_UUID = "UPDATE `%s` SET `version` = 1 WHERE `uuid` = ?";
public static final String SQL_UNLOCK_BY_UUID = "UPDATE `%s` SET `version` = 0 WHERE `uuid` = ?";
public static final String SQL_ALTER_TABLE = "ALTER TABLE `%s` ADD COLUMN `version` INT(2) NOT NULL AFTER `uuid`";
}

View File

@@ -0,0 +1,10 @@
package net.momirealms.customfishing.fishing.bar;
import org.bukkit.configuration.ConfigurationSection;
public class ModeThreeBar extends FishingBar {
public ModeThreeBar(ConfigurationSection section) {
super(section);
}
}

View File

@@ -14,7 +14,7 @@ public class ModeTwoBar extends FishingBar {
private final int judgement_area_width;
private final int fish_icon_width;
private final String[] progress;
private double punishment;
private final double punishment;
public ModeTwoBar(ConfigurationSection section) {
super(section);

View File

@@ -0,0 +1,13 @@
package net.momirealms.customfishing.fishing.mode;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.bar.FishingBar;
import net.momirealms.customfishing.manager.FishingManager;
import org.bukkit.entity.Player;
public class ModeThreeGame extends FishingGame {
public ModeThreeGame(CustomFishing plugin, FishingManager fishingManager, long deadline, Player player, int difficulty, FishingBar fishingBar) {
super(plugin, fishingManager, deadline, player, difficulty, fishingBar);
}
}

View File

@@ -22,7 +22,7 @@ public class ModeTwoGame extends FishingGame {
public ModeTwoGame(CustomFishing plugin, FishingManager fishingManager, long deadline, Player player, int difficulty, ModeTwoBar modeTwoBar) {
super(plugin, fishingManager, deadline, player, difficulty, modeTwoBar);
this.success = false;
this.judgement_position = (double) modeTwoBar.getBar_effective_width() / 2;
this.judgement_position = (double) (modeTwoBar.getBar_effective_width() - modeTwoBar.getJudgement_area_width()) / 2;
this.fish_position = 0;
this.timer = 0;
this.modeTwoBar = modeTwoBar;
@@ -73,12 +73,13 @@ public class ModeTwoGame extends FishingGame {
String bar = "<font:" + modeTwoBar.getFont() + ">" + modeTwoBar.getBarImage()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getJudgement_area_offset() + judgement_position)) + "</font>"
+ modeTwoBar.getJudgement_area_image()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getBar_effective_width() - judgement_position - modeTwoBar.getJudgement_area_width() + 1)) + "</font>"
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (-modeTwoBar.getBar_effective_width() - 2 + fish_position)) + "</font>"
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getBar_effective_width() - judgement_position - modeTwoBar.getJudgement_area_width())) + "</font>"
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (-modeTwoBar.getBar_effective_width() - 1 + fish_position)) + "</font>"
+ modeTwoBar.getFish_image()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getBar_effective_width() - fish_position - modeTwoBar.getFish_icon_width() + 1)) + "</font>"
+ "</font>";
if (hold_time > time_requirement) hold_time = time_requirement;
if (hold_time < 0) hold_time = 0;
AdventureUtil.playerTitle(player,
title.replace("{progress}", modeTwoBar.getProgress()[(int) ((hold_time / time_requirement) * modeTwoBar.getProgress().length)])
, bar,0,500,0

View File

@@ -42,6 +42,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@@ -55,22 +56,25 @@ public class BagDataManager extends Function {
private final JoinQuitListener joinQuitListener;
private final BukkitTask timerSave;
private final CustomFishing plugin;
private final HashMap<UUID, Integer> triedTimes;
public BagDataManager(CustomFishing plugin) {
this.plugin = plugin;
this.dataMap = new ConcurrentHashMap<>();
this.tempData = new HashSet<>();
this.triedTimes = new HashMap<>();
this.inventoryListener = new InventoryListener(this);
this.windowPacketListener = new WindowPacketListener(this);
this.joinQuitListener = new JoinQuitListener(this);
this.timerSave = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> {
AdventureUtil.consoleMessage("[CustomFishing] Saving Fishing bag data...");
DataManager dataManager = plugin.getDataManager();
for (PlayerBagData playerBagData : dataMap.values()) {
dataManager.getDataStorageInterface().saveBagData(playerBagData);
dataManager.getDataStorageInterface().saveBagData(playerBagData, false);
}
AdventureUtil.consoleMessage("[CustomFishing] Fishing bag data saving for " + dataMap.size() + " online players...");
AdventureUtil.consoleMessage("[CustomFishing] Fishing bag data saved for " + dataMap.size() + " online players.");
}, 12000, 12000);
}
@@ -93,7 +97,7 @@ public class BagDataManager extends Function {
unload();
for (PlayerBagData playerBagData : dataMap.values()) {
DataManager dataManager = CustomFishing.getInstance().getDataManager();
dataManager.getDataStorageInterface().saveBagData(playerBagData);
dataManager.getDataStorageInterface().saveBagData(playerBagData, true);
}
dataMap.clear();
tempData.clear();
@@ -104,21 +108,29 @@ public class BagDataManager extends Function {
return dataMap.get(uuid);
}
public void openFishingBag(Player viewer, OfflinePlayer ownerOffline) {
public void openFishingBag(Player viewer, OfflinePlayer ownerOffline, boolean force) {
Player owner = ownerOffline.getPlayer();
//not online
if (owner == null) {
Inventory inventory = plugin.getDataManager().getDataStorageInterface().loadBagData(ownerOffline);
Inventory inventory = plugin.getDataManager().getDataStorageInterface().loadBagData(ownerOffline, force);
if (inventory == null) {
AdventureUtil.playerMessage(viewer, "<red>[CustomFishing] Failed to load bag data for player " + ownerOffline.getName());
AdventureUtil.playerMessage(viewer, "<red>This might be caused when the target player is online but on another server");
AdventureUtil.playerMessage(viewer, "<red>Use /fishingbag open [Player] --force to ignore this warning");
return;
}
PlayerBagData playerBagData = new PlayerBagData(ownerOffline, inventory);
tempData.add(playerBagData);
viewer.openInventory(inventory);
}
//online
else {
PlayerBagData playerBagData = dataMap.get(owner.getUniqueId());
if (playerBagData == null) {
AdventureUtil.consoleMessage("<red>[CustomFishing] Bag data is not loaded for player " + owner.getName());
}
else {
tryOpen(owner, viewer, playerBagData);
openGui(owner, viewer, playerBagData);
}
}
}
@@ -126,9 +138,10 @@ public class BagDataManager extends Function {
@Override
public void onQuit(Player player) {
PlayerBagData playerBagData = dataMap.remove(player.getUniqueId());
triedTimes.remove(player.getUniqueId());
if (playerBagData != null) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
plugin.getDataManager().getDataStorageInterface().saveBagData(playerBagData);
plugin.getDataManager().getDataStorageInterface().saveBagData(playerBagData, true);
});
}
}
@@ -136,17 +149,32 @@ public class BagDataManager extends Function {
@Override
public void onJoin(Player player) {
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
readData(player);
}, 20);
joinReadData(player, false);
}, 15);
}
public void readData(Player player) {
public void joinReadData(Player player, boolean force) {
if (player == null || !player.isOnline()) return;
Inventory inventory = plugin.getDataManager().getDataStorageInterface().loadBagData(player);
Inventory inventory = plugin.getDataManager().getDataStorageInterface().loadBagData(player, force);
if (inventory != null) {
PlayerBagData playerBagData = new PlayerBagData(player, inventory);
dataMap.put(player.getUniqueId(), playerBagData);
}
// If sql exception or data is locked
else if (!force) {
// can still try to load
if (!checkTriedTimes(player.getUniqueId())) {
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
joinReadData(player, false);
}, 20);
}
// tried 3 times
else {
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
joinReadData(player, true);
}, 20);
}
}
}
@Override
@@ -214,14 +242,14 @@ public class BagDataManager extends Function {
if (temp.getInventory() == inventory) {
tempData.remove(temp);
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
plugin.getDataManager().getDataStorageInterface().saveBagData(temp);
plugin.getDataManager().getDataStorageInterface().saveBagData(temp, true);
});
}
}
}
}
public void tryOpen(Player owner, Player viewer, PlayerBagData playerBagData) {
public void openGui(Player owner, Player viewer, PlayerBagData playerBagData) {
Inventory inventory = playerBagData.getInventory();
int size = 1;
for (int i = 6; i > 1; i--) {
@@ -241,4 +269,20 @@ public class BagDataManager extends Function {
viewer.openInventory(inventory);
}
}
public boolean checkTriedTimes(UUID uuid) {
Integer previous = triedTimes.get(uuid);
if (previous == null) {
triedTimes.put(uuid, 1);
return false;
}
else if (previous > 2) {
triedTimes.remove(uuid);
return true;
}
else {
triedTimes.put(uuid, previous + 1);
return false;
}
}
}

View File

@@ -49,11 +49,13 @@ public class ConfigManager {
public static boolean enableFishingBag;
public static boolean alwaysFishingBar;
public static boolean allRodsFishInLava;
public static boolean enableSuccessTitle;
public static String[] successTitle;
public static String[] successSubTitle;
public static int successFadeIn;
public static int successFadeStay;
public static int successFadeOut;
public static boolean enableFailureTitle;
public static String[] failureTitle;
public static String[] failureSubTitle;
public static int failureFadeIn;
@@ -127,6 +129,8 @@ public class ConfigManager {
}
private static void loadTitle(YamlConfiguration config) {
enableSuccessTitle = config.getBoolean("titles.success.enable", true);
enableFailureTitle = config.getBoolean("titles.failure.enable", true);
successTitle = config.getStringList("titles.success.title").toArray(new String[0]);
successSubTitle = config.getStringList("titles.success.subtitle").toArray(new String[0]);
successFadeIn = config.getInt("titles.success.fade.in", 10) * 50;

View File

@@ -589,7 +589,7 @@ public class FishingManager extends Function {
if (itemStack.getType() == Material.AIR) return;
Entity item = location.getWorld().dropItem(location, itemStack);
Vector vector = player.getLocation().subtract(location).toVector().multiply(0.1);
vector = vector.setY((vector.getY()+0.18) * 1.15);
vector = vector.setY((vector.getY()+0.2) * 1.15);
item.setVelocity(vector);
if (isDouble) {
Entity item2 = location.getWorld().dropItem(location, itemStack);
@@ -674,21 +674,25 @@ public class FishingManager extends Function {
}
private void sendSuccessTitle(Player player, String loot) {
AdventureUtil.playerTitle(
player,
ConfigManager.successTitle[new Random().nextInt(ConfigManager.successTitle.length)]
.replace("{loot}", loot)
.replace("{player}", player.getName()),
ConfigManager.successSubTitle[new Random().nextInt(ConfigManager.successSubTitle.length)]
.replace("{loot}", loot)
.replace("{player}", player.getName()),
ConfigManager.successFadeIn,
ConfigManager.successFadeStay,
ConfigManager.successFadeOut
);
if (!ConfigManager.enableSuccessTitle) return;
Bukkit.getScheduler().runTaskLater(plugin, () -> {
AdventureUtil.playerTitle(
player,
ConfigManager.successTitle[new Random().nextInt(ConfigManager.successTitle.length)]
.replace("{loot}", loot)
.replace("{player}", player.getName()),
ConfigManager.successSubTitle[new Random().nextInt(ConfigManager.successSubTitle.length)]
.replace("{loot}", loot)
.replace("{player}", player.getName()),
ConfigManager.successFadeIn,
ConfigManager.successFadeStay,
ConfigManager.successFadeOut
);
}, 8);
}
private void sendSuccessTitle(Player player, ItemStack itemStack) {
if (!ConfigManager.enableSuccessTitle) return;
String title = ConfigManager.successTitle[new Random().nextInt(ConfigManager.successTitle.length)];
Component titleComponent = getTitleComponent(itemStack, title);
String subTitle = ConfigManager.successSubTitle[new Random().nextInt(ConfigManager.successSubTitle.length)];
@@ -734,6 +738,7 @@ public class FishingManager extends Function {
action.doOn(player, null);
}
if (!ConfigManager.enableFailureTitle) return;
Bukkit.getScheduler().runTaskLater(plugin, () -> {
AdventureUtil.playerTitle(
player,

View File

@@ -85,16 +85,18 @@ public class SellManager extends Function {
public static HashMap<Material, Float> vanillaPrices = new HashMap<>();
public static boolean sellLimitation;
public static int upperLimit;
private final HashMap<Player, Inventory> inventoryCache;
private final HashMap<UUID, PlayerSellData> playerCache;
private final HashMap<Player, Inventory> inventoryMap;
private final HashMap<UUID, PlayerSellData> sellDataMap;
private final HashMap<UUID, Integer> triedTimes;
public SellManager(CustomFishing plugin) {
this.plugin = plugin;
this.windowPacketListener = new WindowPacketListener(this);
this.inventoryListener = new InventoryListener(this);
this.inventoryCache = new HashMap<>();
this.inventoryMap = new HashMap<>();
this.joinQuitListener = new JoinQuitListener(this);
this.playerCache = new HashMap<>();
this.sellDataMap = new HashMap<>();
this.triedTimes = new HashMap<>();
}
@Override
@@ -110,10 +112,10 @@ public class SellManager extends Function {
@Override
public void unload() {
for (Player player : this.inventoryCache.keySet()) {
for (Player player : this.inventoryMap.keySet()) {
player.closeInventory();
}
this.inventoryCache.clear();
this.inventoryMap.clear();
CustomFishing.getProtocolManager().removePacketListener(windowPacketListener);
HandlerList.unregisterAll(inventoryListener);
HandlerList.unregisterAll(joinQuitListener);
@@ -122,37 +124,52 @@ public class SellManager extends Function {
public void disable() {
unload();
DataStorageInterface dataStorage = plugin.getDataManager().getDataStorageInterface();
for (Map.Entry<UUID, PlayerSellData> entry : playerCache.entrySet()) {
dataStorage.saveSellCache(entry.getKey(), entry.getValue());
for (Map.Entry<UUID, PlayerSellData> entry : sellDataMap.entrySet()) {
dataStorage.saveSellData(entry.getKey(), entry.getValue(), true);
}
playerCache.clear();
}
public void loadPlayerToCache(UUID uuid, int date, double money) {
playerCache.put(uuid, new PlayerSellData(money, date));
}
public void savePlayerToFile(UUID uuid) {
PlayerSellData sellData = playerCache.remove(uuid);
if (sellData == null) return;
plugin.getDataManager().getDataStorageInterface().saveSellCache(uuid, sellData);
sellDataMap.clear();
}
@Override
public void onQuit(Player player) {
UUID uuid = player.getUniqueId();
PlayerSellData sellData = sellDataMap.remove(uuid);
if (sellData == null) return;
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
savePlayerToFile(player.getUniqueId());
plugin.getDataManager().getDataStorageInterface().saveSellData(uuid, sellData, true);
});
}
@Override
public void onJoin(Player player) {
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
if (player == null || !player.isOnline()) return;
plugin.getDataManager().getDataStorageInterface().loadSellCache(player);
joinReadData(player, false);
}, 20);
}
public void joinReadData(Player player, boolean force) {
if (player == null || !player.isOnline()) return;
PlayerSellData sellData = plugin.getDataManager().getDataStorageInterface().loadSellData(player, force);
if (sellData != null) {
sellDataMap.put(player.getUniqueId(), sellData);
}
// If sql exception or data is locked
else if (!force) {
// can still try to load
if (!checkTriedTimes(player.getUniqueId())) {
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
joinReadData(player, false);
}, 20);
}
// tried 3 times
else {
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
joinReadData(player, true);
}, 20);
}
}
}
private void loadConfig() {
YamlConfiguration config = ConfigUtil.getConfig("sell-fish-gui.yml");
formula = config.getString("price-formula", "{base} + {bonus} * {size}");
@@ -223,7 +240,7 @@ public class SellManager extends Function {
public void openGuiForPlayer(Player player) {
player.closeInventory();
if (!playerCache.containsKey(player.getUniqueId())) {
if (!sellDataMap.containsKey(player.getUniqueId())) {
AdventureUtil.consoleMessage("<red>Sell cache is not loaded for player " + player.getName());
return;
}
@@ -231,7 +248,7 @@ public class SellManager extends Function {
for (Map.Entry<Integer, ItemStack> entry : guiItems.entrySet()) {
inventory.setItem(entry.getKey(), entry.getValue());
}
inventoryCache.put(player, inventory);
inventoryMap.put(player, inventory);
player.openInventory(inventory);
if (openKey != null) AdventureUtil.playerSound(player, soundSource, openKey, 1, 1);
}
@@ -239,7 +256,7 @@ public class SellManager extends Function {
@Override
public void onOpenInventory(InventoryOpenEvent event) {
final Player player = (Player) event.getPlayer();
Inventory inventory = inventoryCache.get(player);
Inventory inventory = inventoryMap.get(player);
if (inventory == null) return;
if (inventory == event.getInventory()) {
for (int slot : functionIconSlots) {
@@ -251,7 +268,7 @@ public class SellManager extends Function {
@Override
public void onClickInventory(InventoryClickEvent event) {
final Player player = (Player) event.getView().getPlayer();
Inventory inventory = inventoryCache.get(player);
Inventory inventory = inventoryMap.get(player);
if (inventory == null) return;
boolean update = true;
if (inventory == event.getClickedInventory()) {
@@ -265,7 +282,7 @@ public class SellManager extends Function {
if (totalPrice > 0) {
PlayerSellData sellData = playerCache.get(player.getUniqueId());
PlayerSellData sellData = sellDataMap.get(player.getUniqueId());
if (sellData == null) {
inventory.close();
@@ -329,7 +346,7 @@ public class SellManager extends Function {
@Override
public void onCloseInventory(InventoryCloseEvent event) {
final Player player = (Player) event.getPlayer();
Inventory inventory = inventoryCache.remove(player);
Inventory inventory = inventoryMap.remove(player);
if (inventory == null) return;
if (event.getInventory() == inventory) {
returnItems(getPlayerItems(event.getInventory()), player);
@@ -428,4 +445,20 @@ public class SellManager extends Function {
);
}
}
public boolean checkTriedTimes(UUID uuid) {
Integer previous = triedTimes.get(uuid);
if (previous == null) {
triedTimes.put(uuid, 1);
return false;
}
else if (previous > 2) {
triedTimes.remove(uuid);
return true;
}
else {
triedTimes.put(uuid, previous + 1);
return false;
}
}
}

View File

@@ -504,7 +504,7 @@ bar_9:
###############
# Game Type 2 #
###############
pull_bar:
bar_10:
game-type: 2
title: '{progress}'
subtitle:
@@ -513,11 +513,11 @@ pull_bar:
judgment-area: '뀍'
fish: '뀎'
arguments:
punishment: 0.1
punishment: 0.2
bar-effective-area-width: 155
judgment-area-offset: -160
judgment-area-width: 33
fish-icon-width: 7
fish-icon-width: 8
hold-time-requirements:
- 3
- 4
@@ -533,4 +533,38 @@ pull_bar:
- '<font:customfishing:icons>뀆</font>'
- '<font:customfishing:icons>뀇</font>'
- '<font:customfishing:icons>뀈</font>'
- '<font:customfishing:icons>뀉</font>'
- '<font:customfishing:icons>뀉</font>'
###############
# Game Type 3 #
###############
bar_11:
game-type: 3
title: '{strain}'
subtitle:
font: 'customfishing:default'
bar: '뀌'
fish: '뀎'
struggling-fish:
- 1
- 2
- 1
- 3
arguments:
punishment: 1
bar-effective-area-width: 155
fish-start-position: 55~105
fish-icon-width: 8
success-position: 16
strain:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9

View File

@@ -108,6 +108,7 @@ mechanics:
titles:
success:
enable: true
title:
- '<green>GG!</green>'
- '<green>Good Job!</green>'
@@ -122,6 +123,7 @@ titles:
stay: 30
out: 10
failure:
enable: true
title:
- '<red>Be concentrated!</red>'
- '<red>What a pity!</red>'

View File

@@ -24,7 +24,7 @@ rainbow:
- 4
- 5
normal:
mode_1:
time: 15
bars:
- bar_1
@@ -53,10 +53,10 @@ normal:
- 6
- 7
pull:
mode_2:
time: 30
bars:
- pull_bar
- bar_10
difficulty:
- 1
- 2
@@ -72,4 +72,41 @@ pull:
- 6
- 6
- 6
- 7
- 7
mode_3:
time: 30
bars:
- bar_11
difficulty:
- 1
- 2
- 3
- 3
- 4
- 4
- 4
- 4
- 5
- 5
- 5
- 6
- 6
- 6
- 7
mixed_mini_games:
time: 30
bars:
- bar_1
- bar_2
- bar_3
- bar_10
- bar_11
difficulty:
- 1
- 2
- 3
- 3
- 4
- 4