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-30 11:46:12 +08:00
parent 23f32b99e6
commit 29ccb81c9b
7 changed files with 82 additions and 66 deletions

View File

@@ -102,6 +102,7 @@ public class ConfigReader{
public static boolean vanillaLoot;
public static boolean showBar;
public static boolean mcMMOLoot;
public static boolean hasWhitelist;
public static int fishFinderCoolDown;
public static double timeMultiply;
public static double vanillaRatio;
@@ -110,6 +111,7 @@ public class ConfigReader{
public static String version;
public static String lang;
public static String priority;
public static List<org.bukkit.World> whitelistWorlds = new ArrayList<>();
public static SeasonInterface season;
public static void loadConfig() {
@@ -184,6 +186,8 @@ public class ConfigReader{
}
}
version = config.getString("config-version");
doubleRealIn = config.getBoolean("config.double-reel-in", true);
mcMMOLoot = config.getBoolean("config.other-loot.mcMMO", false);
@@ -199,12 +203,26 @@ public class ConfigReader{
loseDurability = config.getBoolean("config.rod-lose-durability", true);
preventPick = config.getBoolean("config.prevent-other-players-pick-up-loot", false);
version = config.getString("config-version");
priority = config.getString("config.event-priority");
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);
hasWhitelist = config.getBoolean("config.whitelist-worlds.enable",false);
if (hasWhitelist){
whitelistWorlds.clear();
config.getStringList("config.whitelist-worlds.worlds").forEach(whitelistWorld -> {
try {
whitelistWorlds.add(Bukkit.getWorld(whitelistWorld));
}
catch (Exception e){
AdventureUtil.consoleMessage("<red>[CustomFishing] Invalid world " + whitelistWorld);
e.printStackTrace();
}
});
}
}
}
@@ -242,12 +260,12 @@ public class ConfigReader{
YamlConfiguration config = getConfig("messages/messages_" + Config.lang +".yml");
prefix = config.getString("messages.prefix");
reload = config.getString("messages.reload");
escape = config.getString("messages.escape");
noPerm = config.getString("messages.no-perm");
notExist = config.getString("messages.not-exist");
noConsole = config.getString("messages.no-console");
prefix = config.getString("messages.prefix", "messages.prefix is missing");
reload = config.getString("messages.reload", "messages.reload is missing");
escape = config.getString("messages.escape", "messages.escape is missing");
noPerm = config.getString("messages.no-perm", "messages.no-perm is missing");
notExist = config.getString("messages.not-exist", "messages.not-exist is missing");
noConsole = config.getString("messages.no-console", "messages.no-console is missing");
wrongAmount = config.getString("messages.wrong-amount");
lackArgs = config.getString("messages.lack-args");
notOnline = config.getString("messages.not-online");
@@ -264,7 +282,7 @@ public class ConfigReader{
forceSuccess = config.getString("messages.force-competition-success");
forceFailure = config.getString("messages.force-competition-failure");
forceEnd = config.getString("messages.force-competition-end");
forceCancel = config.getString("messages.force-competition-cancel");
forceCancel = config.getString("messages.force-competition-cancel","messages.force-competition-cancel is messing");
noPlayer = config.getString("messages.no-player", "messages.no-player is missing");
noScore = config.getString("messages.no-score", "messages.no-score is missing");
noRod = config.getString("messages.no-rod", "messages.no-rod is missing");
@@ -974,6 +992,6 @@ public class ConfigReader{
});
ENCHANTS.put(key, levelBonus);
});
AdventureUtil.consoleMessage("[CustomFishing] Loaded <green>" + ENCHANTS.size() + " <gray>enchants bonus");
AdventureUtil.consoleMessage("[CustomFishing] Loaded <green>" + ENCHANTS.size() + " <gray>enchantments");
}
}

View File

@@ -24,7 +24,6 @@ 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.hook.McMMOTreasure;
import net.momirealms.customfishing.hook.Placeholders;
import net.momirealms.customfishing.listener.*;
import net.momirealms.customfishing.utils.AdventureUtil;
@@ -61,6 +60,7 @@ public final class CustomFishing extends JavaPlugin {
AdventureUtil.consoleMessage("[CustomFishing] Running on <white>" + Bukkit.getVersion());
Bukkit.getScheduler().runTaskAsynchronously(this, ()-> {
ConfigReader.Reload();
if (ConfigReader.Config.competition){
competitionSchedule = new CompetitionSchedule();
@@ -81,15 +81,15 @@ public final class CustomFishing extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new PapiUnregister(), this);
});
}
ConfigReader.tryEnableJedis();
if (!Objects.equals(ConfigReader.Config.version, "6")){
ConfigUtil.update();
}
if (ConfigReader.Config.preventPick){
Bukkit.getScheduler().runTask(this, () -> {
Bukkit.getPluginManager().registerEvents(new PickUpListener(),this);
});
}
if (!Objects.equals(ConfigReader.Config.version, "7")){
ConfigUtil.update();
}
ConfigReader.tryEnableJedis();
AdventureUtil.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>Plugin Enabled!");
});
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.customfishing.command;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.competition.CompetitionSchedule;
import net.momirealms.customfishing.utils.AdventureUtil;
import net.momirealms.customfishing.ConfigReader;
@@ -30,12 +31,14 @@ public class Execute implements CommandExecutor {
}
if (args[0].equalsIgnoreCase("reload")) {
ConfigReader.Reload();
if (sender instanceof Player){
AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.reload);
}else {
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.reload);
}
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()-> {
ConfigReader.Reload();
if (sender instanceof Player){
AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.reload);
}else {
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.reload);
}
});
return true;
}

View File

@@ -1,6 +1,8 @@
package net.momirealms.customfishing.hook;
import com.willfp.eco.core.items.CustomItem;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
import net.momirealms.customfishing.ConfigReader;
import net.momirealms.customfishing.CustomFishing;
import org.bukkit.NamespacedKey;
@@ -17,12 +19,11 @@ public class EcoItemRegister {
new NamespacedKey(CustomFishing.instance, "rod_" + entry.getKey()),
itemStack -> {
try {
return itemStack.getItemMeta().getPersistentDataContainer()
.get(new NamespacedKey(CustomFishing.instance, "type"),
PersistentDataType.STRING).equalsIgnoreCase("rod")
&& itemStack.getItemMeta().getPersistentDataContainer()
.get(new NamespacedKey(CustomFishing.instance, "id"),
PersistentDataType.STRING).equalsIgnoreCase(entry.getKey());
NBTItem nbtItem = new NBTItem(itemStack);
NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing");
return nbtCompound != null
&& nbtCompound.getString("type").equalsIgnoreCase("rod")
&& nbtCompound.getString("id").equalsIgnoreCase(entry.getKey());
} catch (Exception e) {
return false;
}
@@ -36,12 +37,11 @@ public class EcoItemRegister {
new NamespacedKey(CustomFishing.instance, "bait_" + entry.getKey()),
itemStack -> {
try {
return itemStack.getItemMeta().getPersistentDataContainer()
.get(new NamespacedKey(CustomFishing.instance, "type"),
PersistentDataType.STRING).equalsIgnoreCase("bait")
&& itemStack.getItemMeta().getPersistentDataContainer()
.get(new NamespacedKey(CustomFishing.instance, "id"),
PersistentDataType.STRING).equalsIgnoreCase(entry.getKey());
NBTItem nbtItem = new NBTItem(itemStack);
NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing");
return nbtCompound != null
&& nbtCompound.getString("type").equalsIgnoreCase("bait")
&& nbtCompound.getString("id").equalsIgnoreCase(entry.getKey());
} catch (Exception e) {
return false;
}
@@ -55,12 +55,11 @@ public class EcoItemRegister {
new NamespacedKey(CustomFishing.instance, "util_" + entry.getKey()),
itemStack -> {
try {
return itemStack.getItemMeta().getPersistentDataContainer()
.get(new NamespacedKey(CustomFishing.instance, "type"),
PersistentDataType.STRING).equalsIgnoreCase("util")
&& itemStack.getItemMeta().getPersistentDataContainer()
.get(new NamespacedKey(CustomFishing.instance, "id"),
PersistentDataType.STRING).equalsIgnoreCase(entry.getKey());
NBTItem nbtItem = new NBTItem(itemStack);
NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing");
return nbtCompound != null
&& nbtCompound.getString("type").equalsIgnoreCase("util")
&& nbtCompound.getString("id").equalsIgnoreCase(entry.getKey());
} catch (Exception e) {
return false;
}

View File

@@ -95,6 +95,19 @@ public class FishListener implements Listener {
PlayerFishEvent.State state = event.getState();
Player player = event.getPlayer();
if (ConfigReader.Config.hasWhitelist){
boolean isWhite = false;
for (World world : ConfigReader.Config.whitelistWorlds){
if (world.equals(player.getWorld())){
isWhite = true;
break;
}
}
if (!isWhite){
return;
}
}
switch (state){
case FISHING ->{
@@ -325,7 +338,7 @@ public class FishListener implements Listener {
hook.setMaxWaitTime((int) (timeModifier * hook.getMaxWaitTime()));
hook.setMinWaitTime((int) (timeModifier * hook.getMinWaitTime()));
List<Loot> possibleLoots = getPossibleLootList(new FishingCondition(hook.getLocation(), player));
List<Loot> possibleLoots = getPossibleLootList(new FishingCondition(hook.getLocation(), player), false);
List<Loot> availableLoots = new ArrayList<>();
Modifier modifier = new Modifier();
@@ -933,7 +946,7 @@ public class FishListener implements Listener {
}
coolDown.put(player, time);
//获取玩家位置处可能的Loot实例列表
List<Loot> possibleLoots = getFinder(new FishingCondition(player.getLocation(), player));
List<Loot> possibleLoots = getPossibleLootList(new FishingCondition(player.getLocation(), player), true);
if (possibleLoots.size() == 0){
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.noLoot);
return;
@@ -947,33 +960,11 @@ public class FishListener implements Listener {
/*
获取可能的Loot列表
*/
private List<Loot> getPossibleLootList(FishingCondition fishingCondition) {
private List<Loot> getPossibleLootList(FishingCondition fishingCondition, boolean finder) {
List<Loot> available = new ArrayList<>();
ConfigReader.LOOT.keySet().forEach(key -> {
Loot loot = ConfigReader.LOOT.get(key);
List<Requirement> requirements = loot.getRequirements();
if (requirements == null){
available.add(loot);
}else {
boolean isMet = true;
for (Requirement requirement : requirements){
if (!requirement.isConditionMet(fishingCondition)){
isMet = false;
}
}
if (isMet){
available.add(loot);
}
}
});
return available;
}
private List<Loot> getFinder(FishingCondition fishingCondition) {
List<Loot> available = new ArrayList<>();
ConfigReader.LOOT.keySet().forEach(key -> {
Loot loot = ConfigReader.LOOT.get(key);
if (!loot.isShowInFinder()) return;
if (finder && !loot.isShowInFinder()) return;
List<Requirement> requirements = loot.getRequirements();
if (requirements == null){
available.add(loot);

View File

@@ -1,5 +1,5 @@
# don't change
config-version: '6'
config-version: '7'
config:
#en/es/cn
@@ -23,6 +23,12 @@ config:
CustomCrops: false
RealisticSeasons: false
# Worlds where the special fishing mechanic take effects
whitelist-worlds:
enable: false
worlds:
- world
# Should the fishing bar only show after player reel in
# Otherwise the bar would show immediately the bobber is hooked
double-reel-in: true