mirror of
https://github.com/CarmJos/UltraDepository.git
synced 2024-09-19 19:55:45 +00:00
修复日期不更正的问题
This commit is contained in:
parent
bc95c37476
commit
a54a717c2c
@ -107,7 +107,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentAmount > (limit - sold)) {
|
if (amount > (limit - sold)) {
|
||||||
PluginConfig.Sounds.SELL_FAIL.play(player);
|
PluginConfig.Sounds.SELL_FAIL.play(player);
|
||||||
PluginMessages.ITEM_SOLD_LIMIT.send(player, new Object[]{(limit - sold), limit});
|
PluginMessages.ITEM_SOLD_LIMIT.send(player, new Object[]{(limit - sold), limit});
|
||||||
return true;
|
return true;
|
||||||
|
@ -40,9 +40,9 @@ public class PluginConfig {
|
|||||||
public static class Sounds {
|
public static class Sounds {
|
||||||
|
|
||||||
public static final ConfigSound COLLECT = new ConfigSound("sounds.collect");
|
public static final ConfigSound COLLECT = new ConfigSound("sounds.collect");
|
||||||
public static final ConfigSound SELL_SUCCESS = new ConfigSound("sell-success");
|
public static final ConfigSound SELL_SUCCESS = new ConfigSound("sounds.sell-success");
|
||||||
public static final ConfigSound SELL_FAIL = new ConfigSound("sell-fail");
|
public static final ConfigSound SELL_FAIL = new ConfigSound("sounds.sell-fail");
|
||||||
public static final ConfigSound GUI_CLICK = new ConfigSound("gui-click");
|
public static final ConfigSound GUI_CLICK = new ConfigSound("sounds.gui-click");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,7 +56,7 @@ public class PluginConfig {
|
|||||||
public static final ConfigMessageList ADDITIONAL_LORE = new ConfigMessageList(
|
public static final ConfigMessageList ADDITIONAL_LORE = new ConfigMessageList(
|
||||||
ConfigManager.getPluginConfig(), "general.additional-lore", new String[]{},
|
ConfigManager.getPluginConfig(), "general.additional-lore", new String[]{},
|
||||||
new String[]{
|
new String[]{
|
||||||
"%(item_name)", "%(amount)", "%(price)", "%(sold)", "%(limit)"
|
"%(item_name)", "%(amount)", "%(price)", "%(sold)", "%(remain)", "%(limit)"
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,7 @@ import cc.carm.plugin.ultradepository.Main;
|
|||||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||||
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
||||||
import cc.carm.plugin.ultradepository.storage.DataStorage;
|
import cc.carm.plugin.ultradepository.storage.DataStorage;
|
||||||
|
import cc.carm.plugin.ultradepository.util.DateUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -18,14 +19,14 @@ public class UserData {
|
|||||||
DataStorage storage;
|
DataStorage storage;
|
||||||
Map<String, DepositoryData> depositories;
|
Map<String, DepositoryData> depositories;
|
||||||
|
|
||||||
Date day;
|
int date;
|
||||||
|
|
||||||
public UserData(UUID userUUID, DataStorage storage,
|
public UserData(UUID userUUID, DataStorage storage,
|
||||||
Map<String, DepositoryData> depositories, Date day) {
|
Map<String, DepositoryData> depositories, int date) {
|
||||||
this.userUUID = userUUID;
|
this.userUUID = userUUID;
|
||||||
this.storage = storage;
|
this.storage = storage;
|
||||||
this.depositories = depositories;
|
this.depositories = depositories;
|
||||||
this.day = day;
|
this.date = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -117,18 +118,22 @@ public class UserData {
|
|||||||
|
|
||||||
|
|
||||||
public Date getDate() {
|
public Date getDate() {
|
||||||
return this.day;
|
return new Date(DateUtil.getDateMillis(this.date));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isCurrentDay() {
|
public boolean isCurrentDay() {
|
||||||
return this.day.equals(new Date(System.currentTimeMillis()));
|
return this.date == DateUtil.getCurrentDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void checkoutDate() {
|
public void checkoutDate() {
|
||||||
if (isCurrentDay()) return;
|
if (isCurrentDay()) {
|
||||||
this.day = new Date(System.currentTimeMillis()); //更新日期
|
Main.debug("Date is not change, skip clear sold amount.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.date = DateUtil.getCurrentDate(); //更新日期
|
||||||
|
Main.debug("Date changed, clear sold.");
|
||||||
getDepositories().values().stream()
|
getDepositories().values().stream()
|
||||||
.flatMap(value -> value.getContents().values().stream())
|
.flatMap(value -> value.getContents().values().stream())
|
||||||
.forEach(DepositoryItemData::clearSold);
|
.forEach(DepositoryItemData::clearSold);
|
||||||
|
@ -2,11 +2,11 @@ package cc.carm.plugin.ultradepository.manager;
|
|||||||
|
|
||||||
import cc.carm.plugin.ultradepository.Main;
|
import cc.carm.plugin.ultradepository.Main;
|
||||||
import cc.carm.plugin.ultradepository.data.UserData;
|
import cc.carm.plugin.ultradepository.data.UserData;
|
||||||
|
import cc.carm.plugin.ultradepository.util.DateUtil;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.sql.Date;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ public class UserManager {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Main.error("无法正常加载玩家数据,玩家操作将不会被保存,请检查数据配置!");
|
Main.error("无法正常加载玩家数据,玩家操作将不会被保存,请检查数据配置!");
|
||||||
Main.error("Could not load user's data, please check the data configuration!");
|
Main.error("Could not load user's data, please check the data configuration!");
|
||||||
return new UserData(userUUID, Main.getStorage(), new HashMap<>(), new Date(System.currentTimeMillis()));
|
return new UserData(userUUID, Main.getStorage(), new HashMap<>(), DateUtil.getCurrentDate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,4 +64,6 @@ public class UserManager {
|
|||||||
player.hasPermission("UltraDepository.auto") &&
|
player.hasPermission("UltraDepository.auto") &&
|
||||||
player.hasPermission("UltraDepository.auto.enable");
|
player.hasPermission("UltraDepository.auto.enable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package cc.carm.plugin.ultradepository.storage;
|
|||||||
import cc.carm.plugin.ultradepository.Main;
|
import cc.carm.plugin.ultradepository.Main;
|
||||||
import cc.carm.plugin.ultradepository.configuration.values.ConfigValue;
|
import cc.carm.plugin.ultradepository.configuration.values.ConfigValue;
|
||||||
import cc.carm.plugin.ultradepository.data.UserData;
|
import cc.carm.plugin.ultradepository.data.UserData;
|
||||||
|
import cc.carm.plugin.ultradepository.util.DateUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -32,7 +33,7 @@ public class FileStorage implements DataStorage {
|
|||||||
public @NotNull UserData loadData(@NotNull UUID uuid) {
|
public @NotNull UserData loadData(@NotNull UUID uuid) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
Main.debug("正通过 FileStorage 加载 " + uuid + " 的用户数据...");
|
Main.debug("正通过 FileStorage 加载 " + uuid + " 的用户数据...");
|
||||||
return new UserData(uuid, this, new HashMap<>(), new Date(System.currentTimeMillis()));
|
return new UserData(uuid, this, new HashMap<>(), DateUtil.getCurrentDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -12,6 +12,7 @@ import cc.carm.plugin.ultradepository.configuration.values.ConfigValue;
|
|||||||
import cc.carm.plugin.ultradepository.data.DepositoryData;
|
import cc.carm.plugin.ultradepository.data.DepositoryData;
|
||||||
import cc.carm.plugin.ultradepository.data.DepositoryItemData;
|
import cc.carm.plugin.ultradepository.data.DepositoryItemData;
|
||||||
import cc.carm.plugin.ultradepository.data.UserData;
|
import cc.carm.plugin.ultradepository.data.UserData;
|
||||||
|
import cc.carm.plugin.ultradepository.util.DateUtil;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
@ -125,7 +126,7 @@ public class MySQLStorage implements DataStorage {
|
|||||||
if (resultSet != null && resultSet.next()) {
|
if (resultSet != null && resultSet.next()) {
|
||||||
String dataJSON = resultSet.getString("data");
|
String dataJSON = resultSet.getString("data");
|
||||||
Date date = resultSet.getDate("day");
|
Date date = resultSet.getDate("day");
|
||||||
UserData data = new UserData(uuid, this, new HashMap<>(), date);
|
UserData data = new UserData(uuid, this, new HashMap<>(), DateUtil.getDateInt(date));
|
||||||
|
|
||||||
JsonElement dataElement = PARSER.parse(dataJSON);
|
JsonElement dataElement = PARSER.parse(dataJSON);
|
||||||
if (dataElement.isJsonObject()) {
|
if (dataElement.isJsonObject()) {
|
||||||
@ -141,7 +142,7 @@ public class MySQLStorage implements DataStorage {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
Main.debug("当前库内不存在玩家 " + uuid + " 的数据,视作新档。");
|
Main.debug("当前库内不存在玩家 " + uuid + " 的数据,视作新档。");
|
||||||
return new UserData(uuid, this, new HashMap<>(), new Date(System.currentTimeMillis()));
|
return new UserData(uuid, this, new HashMap<>(), DateUtil.getCurrentDate());
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
throw new Exception(exception);
|
throw new Exception(exception);
|
||||||
}
|
}
|
||||||
|
@ -41,11 +41,15 @@ public class DepositoryGUI extends GUI {
|
|||||||
|
|
||||||
|
|
||||||
private GUIItem createGUIItem(DepositoryItem item) {
|
private GUIItem createGUIItem(DepositoryItem item) {
|
||||||
ItemStackFactory factory = new ItemStackFactory(item.getDisplayItem());
|
|
||||||
DepositoryItemData itemData = userData.getItemData(item);
|
DepositoryItemData itemData = userData.getItemData(item);
|
||||||
|
int remain = item.getLimit() - itemData.getSold();
|
||||||
|
|
||||||
|
ItemStackFactory factory = new ItemStackFactory(item.getDisplayItem());
|
||||||
List<String> additionalLore = PluginConfig.General.ADDITIONAL_LORE.get(player, new Object[]{
|
List<String> additionalLore = PluginConfig.General.ADDITIONAL_LORE.get(player, new Object[]{
|
||||||
item.getName(), itemData.getAmount(), item.getPrice(), itemData.getSold(), item.getLimit()
|
item.getName(), itemData.getAmount(), item.getPrice(),
|
||||||
|
itemData.getSold(), remain, item.getLimit()
|
||||||
});
|
});
|
||||||
|
|
||||||
additionalLore.forEach(factory::addLore);
|
additionalLore.forEach(factory::addLore);
|
||||||
List<String> clickLore = PluginConfig.General.CLICK_LORE.get(player, new Object[]{
|
List<String> clickLore = PluginConfig.General.CLICK_LORE.get(player, new Object[]{
|
||||||
item.getName(), itemData.getAmount(), item.getPrice()
|
item.getName(), itemData.getAmount(), item.getPrice()
|
||||||
@ -58,7 +62,16 @@ public class DepositoryGUI extends GUI {
|
|||||||
if (itemData.getAmount() < 1) return;
|
if (itemData.getAmount() < 1) return;
|
||||||
if (type == ClickType.LEFT) {
|
if (type == ClickType.LEFT) {
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
SellItemGUI.open(player, userData, itemData, depository, item);
|
if (itemData.getAmount() >= 1) {
|
||||||
|
if (remain >= 1) {
|
||||||
|
SellItemGUI.open(player, userData, itemData, depository, item);
|
||||||
|
} else {
|
||||||
|
PluginMessages.ITEM_SOLD_LIMIT.send(player, new Object[]{remain, item.getLimit()});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
PluginMessages.NO_ENOUGH_ITEM.send(player);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (type == ClickType.RIGHT) {
|
} else if (type == ClickType.RIGHT) {
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
if (hasEmptySlot(player)) {
|
if (hasEmptySlot(player)) {
|
||||||
|
@ -51,7 +51,8 @@ public class SellItemGUI extends GUI {
|
|||||||
this.currentAmount = Math.max(1, amount); // 不可小于1
|
this.currentAmount = Math.max(1, amount); // 不可小于1
|
||||||
ItemStackFactory factory = new ItemStackFactory(this.itemDisplay);
|
ItemStackFactory factory = new ItemStackFactory(this.itemDisplay);
|
||||||
List<String> additionalLore = PluginConfig.General.ADDITIONAL_LORE.get(player, new Object[]{
|
List<String> additionalLore = PluginConfig.General.ADDITIONAL_LORE.get(player, new Object[]{
|
||||||
getItemName(), getRemainAmount(), getItemPrice(), getSoldAmount(), getSellLimit()
|
getItemName(), getRemainAmount(), getItemPrice(),
|
||||||
|
getSoldAmount(), (getSellLimit() - getSoldAmount()), getSellLimit()
|
||||||
});
|
});
|
||||||
additionalLore.forEach(factory::addLore);
|
additionalLore.forEach(factory::addLore);
|
||||||
|
|
||||||
@ -122,7 +123,7 @@ public class SellItemGUI extends GUI {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(ClickType type) {
|
public void onClick(ClickType type) {
|
||||||
int amount = Math.min(getCurrentAmount(), Math.min(getRemainAmount(), getSellLimit() - getSoldAmount()));
|
int amount = Math.min(getCurrentAmount(), Math.min(getRemainAmount(), getSellLimit() - getSoldAmount()));
|
||||||
if (amount > 0) Main.getEconomyManager().sell(player, getItemPrice(), amount);
|
if (amount > 0) Main.getEconomyManager().sellItem(player, userData, itemData, amount);
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package cc.carm.plugin.ultradepository.util;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
public class DateUtil {
|
||||||
|
|
||||||
|
private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyyMMdd");
|
||||||
|
|
||||||
|
|
||||||
|
public static SimpleDateFormat getFormat() {
|
||||||
|
return FORMAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getCurrentDate() {
|
||||||
|
return getDateInt(new Date(System.currentTimeMillis()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getDateInt(Date date) {
|
||||||
|
return Integer.parseInt(getFormat().format(date));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getDateMillis(int dateInt) {
|
||||||
|
try {
|
||||||
|
return getFormat().parse(Integer.toString(dateInt)).getTime();
|
||||||
|
} catch (ParseException e) {
|
||||||
|
return System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -38,7 +38,7 @@ collect:
|
|||||||
|
|
||||||
sounds:
|
sounds:
|
||||||
collect: ENTITY_EXPERIENCE_ORB_PICKUP
|
collect: ENTITY_EXPERIENCE_ORB_PICKUP
|
||||||
sell-success: ENTITY_VILLAGER_TRADE
|
sell-success: ENTITY_VILLAGER_CELEBRATE
|
||||||
sell-fail: ENTITY_VILLAGER_NO
|
sell-fail: ENTITY_VILLAGER_NO
|
||||||
gui-click: UI_BUTTON_CLICK
|
gui-click: UI_BUTTON_CLICK
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ general:
|
|||||||
- " "
|
- " "
|
||||||
- "&f仓库内数量 &a%(amount)"
|
- "&f仓库内数量 &a%(amount)"
|
||||||
- "&f该物品单价 &a%(price)"
|
- "&f该物品单价 &a%(price)"
|
||||||
- "&f今日可出售 &a%(sold)&8/%(limit)"
|
- "&f今日可出售 &a%(remain)&8/%(limit)"
|
||||||
|
|
||||||
# 提示玩家点击行为的介绍
|
# 提示玩家点击行为的介绍
|
||||||
# 将添加到背包界面内的物品上,避免重复配置
|
# 将添加到背包界面内的物品上,避免重复配置
|
||||||
|
Loading…
Reference in New Issue
Block a user