9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-29 03:49:07 +00:00
This commit is contained in:
Xiao-MoMi
2022-08-10 09:49:55 +08:00
parent 187796e1b5
commit 6d44100b93
34 changed files with 2121 additions and 237 deletions

View File

@@ -17,6 +17,12 @@
package net.momirealms.customfishing;
import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import net.kyori.adventure.bossbar.BossBar;
import net.momirealms.customfishing.competition.CompetitionConfig;
import net.momirealms.customfishing.competition.Goal;
@@ -24,6 +30,7 @@ import net.momirealms.customfishing.competition.bossbar.BossBarConfig;
import net.momirealms.customfishing.competition.reward.CommandImpl;
import net.momirealms.customfishing.competition.reward.MessageImpl;
import net.momirealms.customfishing.competition.reward.Reward;
import net.momirealms.customfishing.helper.Log;
import net.momirealms.customfishing.titlebar.Difficulty;
import net.momirealms.customfishing.titlebar.Layout;
import net.momirealms.customfishing.hook.skill.Aurelium;
@@ -46,6 +53,7 @@ import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.io.IOException;
import java.util.*;
public class ConfigReader{
@@ -74,6 +82,7 @@ public class ConfigReader{
Config.loadConfig();
Message.loadMessage();
Title.loadTitle();
loadBars();
loadLoot();
loadUtil();
loadRod();
@@ -91,6 +100,7 @@ public class ConfigReader{
public static boolean needOpenWater;
public static boolean needSpecialRod;
public static boolean competition;
public static boolean convertMMOItems;
public static String season_papi;
public static String lang;
public static int fishFinderCoolDown;
@@ -99,6 +109,12 @@ public class ConfigReader{
public static void loadConfig() {
try {
YamlDocument.create(new File(CustomFishing.instance.getDataFolder(), "config.yml"), CustomFishing.instance.getResource("config.yml"), GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, UpdaterSettings.builder().setVersioning(new BasicVersioning("config-version")).build());
}catch (IOException e){
Log.warn(e.getMessage());
}
CustomFishing.instance.saveDefaultConfig();
CustomFishing.instance.reloadConfig();
FileConfiguration config = CustomFishing.instance.getConfig();
@@ -170,36 +186,13 @@ public class ConfigReader{
}
vanillaDrop = config.getBoolean("config.vanilla-loot-when-no-custom-fish");
convertMMOItems = config.getBoolean("config.convert-MMOITEMS");
needOpenWater = config.getBoolean("config.need-open-water");
needSpecialRod = config.getBoolean("config.need-special-rod");
fishFinderCoolDown = config.getInt("config.fishfinder-cooldown");
timeMultiply = config.getDouble("config.time-multiply");
lang = config.getString("config.lang","cn");
competition = config.getBoolean("config.fishing-competition",true);
/*
计算获取布局
*/
LAYOUT.clear();
Set<String> keys = Objects.requireNonNull(config.getConfigurationSection("config.success-rate")).getKeys(false);
keys.forEach(key -> {
int range = config.getInt("config.success-rate." + key + ".range");
Set<String> rates = Objects.requireNonNull(config.getConfigurationSection("config.success-rate." + key + ".layout")).getKeys(false);
double[] successRate = new double[rates.size()];
for(int i = 0; i < rates.size(); i++){
successRate[i] = config.getDouble("config.success-rate." + key + ".layout." +(i + 1));
}
int size = rates.size()*range -1;
Layout layout = new Layout(key, range, successRate, size);
layout.setTitle(config.getString("config.success-rate." + key + ".title"," "));
layout.setBar(config.getString("config.success-rate." + key + ".subtitle.bar",""));
layout.setEnd(config.getString("config.success-rate." + key + ".subtitle.end","</font>"));
layout.setStart(config.getString("config.success-rate." + key + ".subtitle.start","<font:customfishing:default>"));
layout.setPointer(config.getString("config.success-rate." + key + ".subtitle.pointer",""));
layout.setPointerOffset(config.getString("config.success-rate." + key + ".subtitle.pointer_offset",""));
layout.setOffset(config.getString("config.success-rate." + key + ".subtitle.offset",""));
LAYOUT.put(key, layout);
});
}
}
@@ -423,7 +416,7 @@ public class ConfigReader{
if (loot.getMaterial().equalsIgnoreCase("AIR")){
LOOTITEM.put(key, new ItemStack(Material.AIR));
}else {
LOOTITEM.put(key, NBTUtil.addIdentifier(ItemStackGenerator.fromItem(loot), "loot", key));
LOOTITEM.put(key, ItemStackGenerator.fromItem(loot));
}
});
@@ -796,6 +789,9 @@ public class ConfigReader{
if (config.contains(key + ".broadcast.end")){
competitionConfig.setEndMessage(config.getStringList(key + ".broadcast.end"));
}
if (config.contains(key + ".min-players")){
competitionConfig.setMinPlayers(config.getInt(key + ".min-players"));
}
if (config.contains(key + ".prize")){
HashMap<String, List<Reward>> rewardsMap = new HashMap<>();
config.getConfigurationSection(key + ".prize").getKeys(false).forEach(rank -> {
@@ -826,4 +822,28 @@ public class ConfigReader{
JedisUtil.useRedis = false;
}
}
}
public static void loadBars(){
LAYOUT.clear();
YamlConfiguration config = ConfigReader.getConfig("bars.yml");
Set<String> keys = Objects.requireNonNull(config.getConfigurationSection("")).getKeys(false);
keys.forEach(key -> {
int range = config.getInt(key + ".range");
Set<String> rates = Objects.requireNonNull(config.getConfigurationSection(key + ".layout")).getKeys(false);
double[] successRate = new double[rates.size()];
for(int i = 0; i < rates.size(); i++){
successRate[i] = config.getDouble(key + ".layout." +(i + 1));
}
int size = rates.size()*range -1;
Layout layout = new Layout(key, range, successRate, size);
layout.setTitle(config.getString(key + ".title"," "));
layout.setBar(config.getString(key + ".subtitle.bar",""));
layout.setEnd(config.getString(key + ".subtitle.end","</font>"));
layout.setStart(config.getString(key + ".subtitle.start","<font:customfishing:default>"));
layout.setPointer(config.getString(key + ".subtitle.pointer",""));
layout.setPointerOffset(config.getString(key + ".subtitle.pointer_offset",""));
layout.setOffset(config.getString(key + ".subtitle.offset",""));
LAYOUT.put(key, layout);
});
}
}

View File

@@ -23,6 +23,7 @@ import net.momirealms.customfishing.command.TabComplete;
import net.momirealms.customfishing.competition.CompetitionSchedule;
import net.momirealms.customfishing.competition.bossbar.BossBarManager;
import net.momirealms.customfishing.helper.LibraryLoader;
import net.momirealms.customfishing.listener.MMOItemsConverter;
import net.momirealms.customfishing.listener.PlayerListener;
import net.momirealms.customfishing.utils.AdventureManager;
import org.bukkit.Bukkit;
@@ -41,6 +42,7 @@ public final class CustomFishing extends JavaPlugin {
instance = this;
LibraryLoader.load("redis.clients","jedis","4.2.3","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("org.apache.commons","commons-pool2","2.11.1","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3","https://repo.maven.apache.org/maven2/");
}
@Override
@@ -56,6 +58,9 @@ public final class CustomFishing extends JavaPlugin {
competitionSchedule.checkTime();
Bukkit.getPluginManager().registerEvents(new BossBarManager(), this);
}
if (ConfigReader.Config.convertMMOItems){
Bukkit.getPluginManager().registerEvents(new MMOItemsConverter(), this);
}
ConfigReader.tryEnableJedis();
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>Plugin Enabled!");
}

View File

@@ -41,6 +41,7 @@ public class CompetitionConfig {
public void setGoal(Goal goal) {this.goal = goal;}
public void setEndMessage(List<String> endMessage) {this.endMessage = endMessage;}
public void setStartMessage(List<String> startMessage) {this.startMessage = startMessage;}
public void setMinPlayers(int minPlayers) {this.minPlayers = minPlayers;}
public HashMap<String, List<Reward>> getRewards() {return rewards;}
public Goal getGoal() {return goal;}

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.competition.ranking;
import net.momirealms.customfishing.competition.CompetitionPlayer;

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.competition.ranking;
import net.momirealms.customfishing.competition.CompetitionPlayer;

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.hook;
import me.clip.placeholderapi.PlaceholderAPI;

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.hook.skill;
import com.archyx.aureliumskills.api.AureliumAPI;

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.hook.skill;
import net.Indyuce.mmocore.experience.EXPSource;

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.hook.skill;
import org.bukkit.entity.Player;

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.hook.skill;
import com.gmail.nossr50.api.ExperienceAPI;

View File

@@ -0,0 +1,78 @@
/*
* 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.listener;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import java.util.HashMap;
public class MMOItemsConverter implements Listener {
private final HashMap<Player, Long> coolDown = new HashMap<>();
@EventHandler
public void onFish(PlayerFishEvent event){
if (event.getState() == PlayerFishEvent.State.FISHING){
Player player = event.getPlayer();
long time = System.currentTimeMillis();
if (time - (coolDown.getOrDefault(player, time - 5000)) < 5000) {
return;
}
coolDown.put(player, time);
PlayerInventory inventory = player.getInventory();
ItemStack mainHand = inventory.getItemInMainHand();
if(mainHand.getType() == Material.FISHING_ROD){
NBTItem nbtItem = new NBTItem(mainHand);
if (nbtItem.getCompound("CustomFishing") == null) {
if (nbtItem.getString("MMOITEMS_ITEM_ID") != null){
NBTCompound nbtCompound = nbtItem.addCompound("CustomFishing");
nbtCompound.setString("type","rod");
nbtCompound.setString("id",nbtItem.getString("MMOITEMS_ITEM_ID"));
mainHand.setItemMeta(nbtItem.getItem().getItemMeta());
}
}
}
ItemStack offHand = inventory.getItemInOffHand();
if(offHand.getType() == Material.FISHING_ROD){
NBTItem nbtItem = new NBTItem(offHand);
if (nbtItem.getCompound("CustomFishing") == null) {
if (nbtItem.getString("MMOITEMS_ITEM_ID") != null){
NBTCompound nbtCompound = nbtItem.addCompound("CustomFishing");
nbtCompound.setString("type", "rod");
nbtCompound.setString("id", nbtItem.getString("MMOITEMS_ITEM_ID"));
offHand.setItemMeta(nbtItem.getItem().getItemMeta());
}
}
}
}
}
}

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.utils;
import net.momirealms.customfishing.helper.Log;

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.utils;
public class Modifier {