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

1.3-beta-4

This commit is contained in:
Xiao-MoMi
2023-03-05 19:55:24 +08:00
parent cf6a2d246a
commit 319e174a69
24 changed files with 306 additions and 53 deletions

View File

@@ -123,7 +123,7 @@ public class MySQLStorageImpl implements DataStorageInterface {
}
else {
Calendar calendar = Calendar.getInstance();
playerSellData = new PlayerSellData(calendar.get(Calendar.MONTH) * 100 + calendar.get(Calendar.DATE), 0);
playerSellData = new PlayerSellData(0, (calendar.get(Calendar.MONTH) +1)* 100 + calendar.get(Calendar.DATE));
insertSellData(player.getUniqueId(), playerSellData.getDate());
}
} catch (SQLException e) {
@@ -202,15 +202,17 @@ public class MySQLStorageImpl implements DataStorageInterface {
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");
AdventureUtil.consoleMessage("<green>[CustomFishing] Tables updated");
} catch (SQLException ex) {
AdventureUtil.consoleMessage(ex.getSQLState());
AdventureUtil.consoleMessage("<red>[CustomFishing] Failed to migrate data");
}
String sql_2 = String.format(SqlConstants.SQL_ALTER_TABLE, sqlConnection.getTablePrefix() + "_" + "selldata");
String sql_2 = String.format(SqlConstants.SQL_DROP_TABLE, sqlConnection.getTablePrefix() + "_" + "sellcache");
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql_2)) {
statement.executeUpdate();
AdventureUtil.consoleMessage("<green>[CustomFishing] 2/2 tables updated");
AdventureUtil.consoleMessage("<green>[CustomFishing] Outdated table deleted");
} catch (SQLException ex) {
AdventureUtil.consoleMessage(ex.getSQLState());
AdventureUtil.consoleMessage("<red>[CustomFishing] Failed to migrate data");
}
}

View File

@@ -28,5 +28,6 @@ public class SqlConstants {
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_ALTER_TABLE = "ALTER TABLE `%s` ADD COLUMN `version` INT NOT NULL DEFAULT `0` AFTER `uuid`";
public static final String SQL_ALTER_TABLE = "ALTER TABLE `%s` ADD COLUMN `version` INT NOT NULL AFTER `uuid`";
public static final String SQL_DROP_TABLE = "DROP TABLE `%s`";
}

View File

@@ -1,3 +1,20 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.fishing;
import net.momirealms.customfishing.fishing.bar.FishingBar;

View File

@@ -1,3 +1,20 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.fishing.bar;
import org.bukkit.configuration.ConfigurationSection;

View File

@@ -1,3 +1,20 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.fishing.bar;
import org.bukkit.configuration.ConfigurationSection;

View File

@@ -1,3 +1,20 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.fishing.bar;
import org.bukkit.configuration.ConfigurationSection;

View File

@@ -46,6 +46,7 @@ public class Item {
public Item(Material material, String key) {
this.material = material;
this.key = key;
this.amount = 1;
}
public Item(ConfigurationSection section, String key) {

View File

@@ -1,3 +1,20 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.fishing.mode;
import net.momirealms.customfishing.CustomFishing;

View File

@@ -1,3 +1,20 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.fishing.mode;
import net.momirealms.customfishing.CustomFishing;

View File

@@ -1,3 +1,20 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.fishing.mode;
import net.momirealms.customfishing.CustomFishing;

View File

@@ -2,11 +2,14 @@ package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.FishingCondition;
import net.momirealms.customfishing.integration.SkillInterface;
public record SkillLevelImpl(int level) implements RequirementInterface {
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
return CustomFishing.getInstance().getIntegrationManager().getSkillInterface().getLevel(fishingCondition.getPlayer()) >= level;
SkillInterface skillInterface = CustomFishing.getInstance().getIntegrationManager().getSkillInterface();
if (skillInterface == null) return false;
return skillInterface.getLevel(fishingCondition.getPlayer()) >= level;
}
}

View File

@@ -22,6 +22,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
public class InventoryListener implements Listener {
@@ -46,4 +47,9 @@ public class InventoryListener implements Listener {
public void onClose(InventoryCloseEvent event){
function.onCloseInventory(event);
}
@EventHandler
public void onDrag(InventoryDragEvent event) {
function.onDragInventory(event);
}
}

View File

@@ -837,8 +837,8 @@ public class FishingManager extends Function {
available.add(loot);
}
else {
for (RequirementInterface requirement : requirements){
if (!requirement.isConditionMet(fishingCondition)){
for (RequirementInterface requirement : requirements) {
if (!requirement.isConditionMet(fishingCondition)) {
continue outer;
}
}

View File

@@ -115,6 +115,10 @@ public class LootManager extends Function {
mobSection.getDouble("vector.vertical",1.3)
)
);
setActions(mobSection, loot);
setRequirements(mobSection.getConfigurationSection("requirements"), loot);
if (mobSection.getBoolean("in-lava", false)) lavaLoots.put(key, loot);
else waterLoots.put(key, loot);
}
@@ -221,15 +225,17 @@ public class LootManager extends Function {
(float) section.getDouble(action + ".pitch")
));
case "potion-effect" -> {
PotionEffectType type = PotionEffectType.getByName(section.getString(action + ".type", "BLINDNESS").toUpperCase());
if (type == null) AdventureUtil.consoleMessage("<red>[CustomFishing] Potion effect " + section.getString(action + ".type", "BLINDNESS") + " doesn't exists");
actions.add(new PotionEffectImpl(
new PotionEffect(
type == null ? PotionEffectType.LUCK : type,
section.getInt(action + ".duration"),
section.getInt(action + ".amplifier")
)
));
List<PotionEffect> potionEffectList = new ArrayList<>();
for (String key : section.getConfigurationSection(action).getKeys(false)) {
PotionEffectType type = PotionEffectType.getByName(section.getString(action + "." + key + ".type", "BLINDNESS").toUpperCase());
if (type == null) AdventureUtil.consoleMessage("<red>[CustomFishing] Potion effect " + section.getString(action + "." + key + ".type", "BLINDNESS") + " doesn't exists");
potionEffectList.add(new PotionEffect(
type == null ? PotionEffectType.LUCK : type,
section.getInt(action + "." + key + ".duration"),
section.getInt(action + "." + key + ".amplifier")
));
}
actions.add(new PotionEffectImpl(potionEffectList.toArray(new PotionEffect[0])));
}
}
}
@@ -242,6 +248,7 @@ public class LootManager extends Function {
if (section != null) {
for (String type : section.getKeys(false)) {
switch (type) {
case "biome" -> requirements.add(new BiomeImpl(section.getStringList(type)));
case "weather" -> requirements.add(new WeatherImpl(section.getStringList(type)));
case "ypos" -> requirements.add(new YPosImpl(section.getStringList(type)));
case "season" -> requirements.add(new SeasonImpl(section.getStringList(type)));

View File

@@ -49,6 +49,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@@ -171,7 +172,7 @@ public class SellManager extends Function {
}
private void loadConfig() {
YamlConfiguration config = ConfigUtil.getConfig("sell-fish-gui.yml");
YamlConfiguration config = ConfigUtil.getConfig("sell-fish.yml");
formula = config.getString("price-formula", "{base} + {bonus} * {size}");
sellLimitation = config.getBoolean("sell-limitation.enable", false);
upperLimit = config.getInt("sell-limitation.upper-limit", 10000);
@@ -203,10 +204,16 @@ public class SellManager extends Function {
if (sellIconSection != null) {
sellIcon = new Item(sellIconSection, "sellIcon");
}
else {
AdventureUtil.consoleMessage("<red>[CustomFishing] Sell icon is missing");
}
ConfigurationSection denyIconSection = config.getConfigurationSection("functional-icons.deny");
if (denyIconSection != null) {
denyIcon = new Item(denyIconSection, "denyIcon");
}
else {
AdventureUtil.consoleMessage("<red>[CustomFishing] Deny icon is missing");
}
for (int slot : config.getIntegerList("functional-icons.slots")) {
guiItems.put(slot - 1, ItemStackUtil.getFromItem(sellIcon));
@@ -293,7 +300,7 @@ public class SellManager extends Function {
}
Calendar calendar = Calendar.getInstance();
int currentDate = calendar.get(Calendar.DATE);
int currentDate = (calendar.get(Calendar.MONTH) + 1) * 100 + calendar.get(Calendar.DATE);
if (currentDate != sellData.getDate()) {
sellData.setDate(currentDate);
sellData.setMoney(0);
@@ -343,6 +350,19 @@ public class SellManager extends Function {
}
}
@Override
public void onDragInventory(InventoryDragEvent event) {
final Player player = (Player) event.getView().getPlayer();
Inventory inventory = inventoryMap.get(player);
if (inventory == null) return;
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
ItemStack icon = ItemStackUtil.getFromItem(sellIcon.cloneWithPrice(getTotalPrice(getPlayerItems(inventory))));
for (int slot : functionIconSlots) {
inventory.setItem(slot, icon);
}
});
}
@Override
public void onCloseInventory(InventoryCloseEvent event) {
final Player player = (Player) event.getPlayer();
@@ -374,7 +394,7 @@ public class SellManager extends Function {
private boolean hasEmptySlot(PlayerInventory inventory) {
for (ItemStack itemStack : inventory.getStorageContents()) {
if (itemStack.getType() == Material.AIR) return true;
if (itemStack == null || itemStack.getType() == Material.AIR) return true;
}
return false;
}

View File

@@ -22,6 +22,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
@@ -66,4 +67,7 @@ public class Function {
public void onConsumeItem(PlayerItemConsumeEvent event) {
}
public void onDragInventory(InventoryDragEvent event) {
}
}

View File

@@ -21,10 +21,12 @@ import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.Nullable;
public record PotionEffectImpl(PotionEffect potionEffect) implements ActionInterface {
public record PotionEffectImpl(PotionEffect[] potionEffects) implements ActionInterface {
@Override
public void doOn(Player player, @Nullable Player anotherPlayer) {
player.addPotionEffect(potionEffect);
for (PotionEffect potionEffect : potionEffects) {
player.addPotionEffect(potionEffect);
}
}
}

View File

@@ -20,6 +20,7 @@ package net.momirealms.customfishing.util;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
@@ -34,8 +35,7 @@ public class InventoryUtil {
* @param contents items
* @return base64
*/
@Nullable
public static String toBase64(ItemStack[] contents) {
public static @NotNull String toBase64(ItemStack[] contents) {
boolean convert = false;
for (ItemStack content : contents) {
if (content != null) {
@@ -58,7 +58,7 @@ public class InventoryUtil {
throw new RuntimeException("[CustomFishing] Data save error", e);
}
}
return null;
return "";
}
/**

View File

@@ -17,7 +17,7 @@ worlds:
# Mechanic settings
mechanics:
# Add custom nbt tags to the loots so plugin could identify
# Disable this will lose the trigger actions when eating fish
# Disable this will be unable to trigger the actions when eating fish
# 为每个战利品增加特殊的CustomFishing NBT标签以被插件识别
# 禁用此项目将会导致吃食物触发的动作失效
add-custom-fishing-tags-to-loots: true

View File

@@ -6,7 +6,7 @@ rubbish:
lore:
- '<gray>Maybe we need to protect the environment...'
weight: 130
custom-model-data: 640
custom-model-data: 50000
action:
success:
mending: 3

View File

@@ -21,9 +21,10 @@ rainbow_fish:
# The score to get in competition
# 比赛中获取的分数
score: 10
minigame:
-
# Specify the fish's mini-games
# 指定鱼的小游戏
mini-game:
- rainbow
# Basic elements of an item
# You can use MiniMessage format in name & lore
@@ -36,6 +37,8 @@ rainbow_fish:
- '<gray>This is a <font:uniform>rainbow fish!'
- '<gray>It is {size}cm long!'
custom-model-data: 1
# 数量
amount: 1
# unbreakable
# 不可破坏
@@ -46,7 +49,7 @@ rainbow_fish:
size: 10~200
# Optional
# The base price and size bonus, and you can customize price formula in sell-fish-gui.yml
# The base price and size bonus, and you can customize price formula in sell-fish.yml
price:
base: 50
bonus: 0.3
@@ -64,9 +67,10 @@ rainbow_fish:
action:
consume:
potion-effect:
type: blindness
amplifier: 1
duration: 200
effect_1:
type: blindness
amplifier: 1
duration: 200
success:
message:
- 'You got a {loot} lol'
@@ -78,6 +82,11 @@ rainbow_fish:
mending: 5
# Fishing Skill xp (requires skill plugin hook)
skill-xp: 100
sound:
source: player
key: 'minecraft:block.amethyst_block.break'
volume: 1
pitch: 1
failure:
message:
- 'The fish escaped'

View File

@@ -23,18 +23,4 @@ skeletalknight:
weather:
- thunder
world:
- world
piranha:
enable: false
mobID: piranha
name: 'Piranha'
weight: 50
time: 1000000
difficulty: 1-1
action:
success:
command:
- 'say {player} Caught a piranha!'
vector:
vertical: 2
- world

View File

@@ -14,7 +14,7 @@ nature_fishing_cane:
lore:
- '<gray>The wild power makes it easier to be hooked'
- '<gray>But also increase the difficulty'
custom-model-data: 2
custom-model-data: 50001
modifier:
time: 0.9
difficulty: 1
@@ -24,7 +24,7 @@ silver_fishing_rod:
name: 'Silver Fishing Rod'
lore:
- '<gray>Increase the chance of getting silver quality fish'
custom-model-data: 3
custom-model-data: 50002
modifier:
weight-add:
silver: 20
@@ -35,7 +35,7 @@ golden_fishing_rod:
name: 'Golden Fishing Rod'
lore:
- '<gray>Increase the chance of getting golden quality fish'
custom-model-data: 4
custom-model-data: 50003
modifier:
weight-add:
silver: -20
@@ -46,7 +46,7 @@ star_fishing_rod:
name: 'Star Fishing Rod'
lore:
- '<gray>Grants you the ability to fish in the lava'
custom-model-data: 5
custom-model-data: 50004
modifier:
weight-add:
silver: 20

View File

@@ -0,0 +1,93 @@
container-title: '<gradient:#A52A2A:#800000:#A52A2A>Sell Fish</gradient>'
rows: 6
# Limit the money player can earn per day
sell-limitation:
enable: true
upper-limit: 10000
price-formula: '{base} + {bonus} * {size}'
vanilla-item-price:
COD: 10
PUFFERFISH: 10
SALMON: 10
TROPICAL_FISH: 10
sounds:
open: minecraft:block.chest.open
close: minecraft:block.chest.close
success: minecraft:block.amethyst_block.break
deny: minecraft:block.anvil.destroy
confirm: minecraft:entity.villager.trade
type: player
actions:
message:
enable: true
text: 'You earned {money}$ from selling the fish! You can still gain {remains}$ from selling fish today'
title:
enable: true
title: '<green>Success'
subtitle: 'You earned {money}$ from selling the fish'
in: 20
stay: 40
out: 20
actionbar:
enable: true
text: 'You earned {money}$ from selling the fish'
commands:
enable: false
value:
- 'cmi broadcast {player} earned {money}'
functional-icons:
slots:
- 50
sell:
material: IRON_BLOCK
display:
name: '<#00CED1><bold>● <bold:false>Sell the fish'
lore:
- '<font:uniform><gradient:#E6E6FA:#48D1CC:#E6E6FA>You will gain {money}$</gradient></font>'
custom-model-data: 1
deny:
material: REDSTONE_BLOCK
display:
name: '<red><bold>● <bold:false>Denied'
lore:
- '<font:uniform><gradient:#E6E6FA:red:#E6E6FA>Nothing to sell!</gradient></font>'
custom-model-data: 1
decorative-icons:
glass-pane:
material: BLACK_STAINED_GLASS_PANE
display:
name: ' '
slots:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 18
- 19
- 27
- 28
- 36
- 37
- 45
- 46
- 47
- 48
- 49
- 51
- 52
- 53
- 54