9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-29 11:59:11 +00:00
This commit is contained in:
Xiao-MoMi
2022-11-12 12:56:09 +08:00
parent bf919d70d8
commit 0bd8e447d0
18 changed files with 160 additions and 14 deletions

View File

@@ -234,10 +234,26 @@ public class Competition {
return ranking.getFirstScore();
}
public float getSecondScore() {
return ranking.getSecondScore();
}
public float getThirdScore() {
return ranking.getThirdScore();
}
public String getFirstPlayer() {
return ranking.getFirstPlayer();
}
public String getSecondPlayer() {
return ranking.getSecondPlayer();
}
public String getThirdPlayer() {
return ranking.getThirdPlayer();
}
public boolean isJoined(Player player) {
return ranking.getCompetitionPlayer(player.getName()) != null;
}

View File

@@ -137,8 +137,28 @@ public class LocalRankingImpl implements RankingInterface {
return getScoreAt(1);
}
@Override
public float getSecondScore() {
return getScoreAt(2);
}
@Override
public float getThirdScore() {
return getScoreAt(3);
}
@Override
public String getFirstPlayer() {
return Optional.ofNullable(getPlayerAt(1)).orElse(MessageManager.noPlayer);
}
@Override
public String getSecondPlayer() {
return Optional.ofNullable(getPlayerAt(2)).orElse(MessageManager.noPlayer);
}
@Override
public String getThirdPlayer() {
return Optional.ofNullable(getPlayerAt(3)).orElse(MessageManager.noPlayer);
}
}

View File

@@ -31,5 +31,9 @@ public interface RankingInterface {
CompetitionPlayer[] getTop3Player();
void refreshData(String player, float score);
float getFirstScore();
float getSecondScore();
float getThirdScore();
String getFirstPlayer();
String getSecondPlayer();
String getThirdPlayer();
}

View File

@@ -123,6 +123,26 @@ public class RedisRankingImpl implements RankingInterface {
return (float) players.get(0).getScore();
}
@Override
public float getSecondScore() {
Jedis jedis = JedisUtil.getJedis();
List<Tuple> players = jedis.zrevrangeWithScores("cf_competition", 1, 1);
jedis.close();
if (players == null) return 0;
if (players.size() == 0) return 0;
return (float) players.get(0).getScore();
}
@Override
public float getThirdScore() {
Jedis jedis = JedisUtil.getJedis();
List<Tuple> players = jedis.zrevrangeWithScores("cf_competition", 2, 2);
jedis.close();
if (players == null) return 0;
if (players.size() == 0) return 0;
return (float) players.get(0).getScore();
}
@Override
public String getFirstPlayer() {
Jedis jedis = JedisUtil.getJedis();
@@ -132,4 +152,24 @@ public class RedisRankingImpl implements RankingInterface {
if (player.size() == 0) return MessageManager.noPlayer;
return player.get(0);
}
@Override
public String getSecondPlayer() {
Jedis jedis = JedisUtil.getJedis();
List<String> player = jedis.zrevrange("cf_competition", 1,1);
jedis.close();
if (player == null) return MessageManager.noPlayer;
if (player.size() == 0) return MessageManager.noPlayer;
return player.get(0);
}
@Override
public String getThirdPlayer() {
Jedis jedis = JedisUtil.getJedis();
List<String> player = jedis.zrevrange("cf_competition", 2,2);
jedis.close();
if (player == null) return MessageManager.noPlayer;
if (player.size() == 0) return MessageManager.noPlayer;
return player.get(0);
}
}

View File

@@ -53,6 +53,7 @@ public class SqlConnection {
hikariConfig.setMaximumPoolSize(config.getInt(storageMode + ".Pool-Settings.maximum-pool-size"));
hikariConfig.setMinimumIdle(config.getInt(storageMode + ".Pool-Settings.minimum-idle"));
hikariConfig.setMaxLifetime(config.getInt(storageMode + ".Pool-Settings.maximum-lifetime"));
hikariConfig.setConnectionTimeout(5000);
for (String property : config.getConfigurationSection(storageMode + ".properties").getKeys(false)) {
hikariConfig.addDataSourceProperty(property, config.getString(storageMode + ".properties." + property));
}

View File

@@ -17,7 +17,10 @@
package net.momirealms.customfishing.integration;
import net.momirealms.customfishing.manager.TotemManager;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.jetbrains.annotations.Nullable;
@@ -42,4 +45,8 @@ public interface BlockInterface {
}
return true;
}
static void placeVanillaBlock(String id, Location location) {
location.getBlock().setType(Material.valueOf(id));
}
}

View File

@@ -20,6 +20,7 @@ package net.momirealms.customfishing.integration.block;
import dev.lone.itemsadder.api.CustomBlock;
import net.momirealms.customfishing.integration.BlockInterface;
import net.momirealms.customfishing.manager.TotemManager;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -39,11 +40,16 @@ public class ItemsAdderBlockImpl implements BlockInterface {
@Override
public void placeBlock(String id, Location location) {
if (BlockInterface.isVanillaItem(id)) {
location.getBlock().setType(Material.valueOf(id));
String blockID = TotemManager.INVERTED.get(id);
if (blockID == null) {
AdventureUtil.consoleMessage(id + " does not exist in totem-blocks.yml");
return;
}
if (BlockInterface.isVanillaItem(blockID)) {
BlockInterface.placeVanillaBlock(blockID, location);
}
else {
CustomBlock.place(id, location);
CustomBlock.place(blockID, location);
}
}

View File

@@ -17,11 +17,13 @@
package net.momirealms.customfishing.integration.block;
import dev.lone.itemsadder.api.CustomBlock;
import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanic;
import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanicFactory;
import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanicListener;
import net.momirealms.customfishing.integration.BlockInterface;
import net.momirealms.customfishing.manager.TotemManager;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -36,11 +38,16 @@ public class OraxenBlockImpl implements BlockInterface {
@Override
public void placeBlock(String id, Location location) {
if (BlockInterface.isVanillaItem(id)) {
location.getBlock().setType(Material.valueOf(id));
String blockID = TotemManager.INVERTED.get(id);
if (blockID == null) {
AdventureUtil.consoleMessage(id + " does not exist in totem-blocks.yml");
return;
}
if (BlockInterface.isVanillaItem(blockID)) {
BlockInterface.placeVanillaBlock(blockID, location);
}
else {
NoteBlockMechanicFactory.setBlockModel(location.getBlock(), id);
NoteBlockMechanicFactory.setBlockModel(location.getBlock(), blockID);
}
}

View File

@@ -19,6 +19,7 @@ package net.momirealms.customfishing.integration.block;
import net.momirealms.customfishing.integration.BlockInterface;
import net.momirealms.customfishing.manager.TotemManager;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -32,7 +33,12 @@ public class VanillaBlockImpl implements BlockInterface {
@Override
public void placeBlock(String id, Location location) {
location.getBlock().setType(Material.valueOf(id));
String blockID = TotemManager.INVERTED.get(id);
if (blockID == null) {
AdventureUtil.consoleMessage(id + " does not exist in totem-blocks.yml");
return;
}
BlockInterface.placeVanillaBlock(blockID, location);
}
@Nullable

View File

@@ -70,6 +70,18 @@ public class CompetitionPapi extends PlaceholderExpansion {
case "1st_player" -> {
return Competition.currentCompetition.getFirstPlayer();
}
case "2nd_score" -> {
return String.format("%.1f", Competition.currentCompetition.getSecondScore());
}
case "2nd_player" -> {
return Competition.currentCompetition.getSecondPlayer();
}
case "3rd_score" -> {
return String.format("%.1f", Competition.currentCompetition.getThirdScore());
}
case "3rd_player" -> {
return Competition.currentCompetition.getThirdPlayer();
}
}
return "null";
}

View File

@@ -41,6 +41,7 @@ public class ConfigManager {
public static double vanillaLootRatio;
public static double mcMMOLootChance;
public static boolean needRodToFish;
public static boolean needRodForLoot;
public static boolean rodLoseDurability;
public static boolean enableCompetition;
public static boolean disableJobsXp;
@@ -105,6 +106,7 @@ public class ConfigManager {
enableMcMMOLoot = config.getBoolean("mechanics.other-loots.mcMMO.enable", false);
mcMMOLootChance = config.getDouble("mechanics.other-loots.mcMMO.chance", 0.5);
needRodToFish = config.getBoolean("mechanics.need-special-rod-to-fish", false);
needRodForLoot = config.getBoolean("mechanics.need-special-rod-for-loots", false);
rodLoseDurability = config.getBoolean("mechanics.rod-lose-durability", true);
enableCompetition = config.getBoolean("mechanics.fishing-competition.enable", true);

View File

@@ -203,7 +203,6 @@ public class FishingManager extends Function {
offHandItem.setAmount(offHandItem.getAmount() - 1);
baitItem = offHandItem.clone();
noBait = false;
}
}
else if (noSpecialRod && nbtCompound.getString("type").equals("rod")) {
@@ -261,6 +260,8 @@ public class FishingManager extends Function {
return;
}
initialBonus.setHasSpecialRod(!noSpecialRod);
int entityID = 0;
if (baitItem != null) {
baitItem.setAmount(1);

View File

@@ -39,6 +39,7 @@ import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@@ -134,7 +135,10 @@ public class BobberCheckTask extends BukkitRunnable {
if (fishHook.isInWater()) {
stop();
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.plugin, () -> {
List<Loot> possibleLoots = fishingManager.getPossibleLootList(new FishingCondition(fishHook.getLocation(), player), false, LootManager.WATERLOOTS.values());
List<Loot> possibleLoots = new ArrayList<>();
if (!(ConfigManager.needRodForLoot && !bonus.hasSpecialRod())) {
possibleLoots = fishingManager.getPossibleLootList(new FishingCondition(fishHook.getLocation(), player), false, LootManager.WATERLOOTS.values());
}
fishingManager.getNextLoot(player, bonus, possibleLoots);
if (ConfigManager.enableWaterAnimation) {
ArmorStandUtil.sendAnimationToPlayer(fishHook.getLocation(), player, ConfigManager.water_item, ConfigManager.water_time);
@@ -185,7 +189,10 @@ public class BobberCheckTask extends BukkitRunnable {
private void randomTime() {
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.plugin, () -> {
List<Loot> possibleLoots = fishingManager.getPossibleLootList(new FishingCondition(fishHook.getLocation(), player), false, LootManager.LAVALOOTS.values());
List<Loot> possibleLoots = new ArrayList<>();
if (!(ConfigManager.needRodForLoot && !bonus.hasSpecialRod())) {
possibleLoots = fishingManager.getPossibleLootList(new FishingCondition(fishHook.getLocation(), player), false, LootManager.LAVALOOTS.values());
}
fishingManager.getNextLoot(player, bonus, possibleLoots);
});
cancelTask();

View File

@@ -30,6 +30,7 @@ public class Bonus {
private int difficulty;
private double doubleLoot;
private boolean canLavaFishing;
private boolean hasSpecialRod;
public HashMap<String, Double> getWeightMD() {
return weightMD;
@@ -108,4 +109,12 @@ public class Bonus {
if (anotherBonus.getScore() != 0) this.score += (anotherBonus.getScore() - 1);
if (anotherBonus.canLavaFishing()) this.canLavaFishing = true;
}
public boolean hasSpecialRod() {
return hasSpecialRod;
}
public void setHasSpecialRod(boolean hasSpecialRod) {
this.hasSpecialRod = hasSpecialRod;
}
}

View File

@@ -45,8 +45,12 @@ public class JedisUtil {
jedisPoolConfig.setMaxIdle(configuration.getInt("Redis.MaxIdle",8));
jedisPoolConfig.setMinIdle(configuration.getInt("Redis.MinIdle",1));
jedisPoolConfig.setMaxWaitMillis(configuration.getInt("redis.MaxWaitMillis",30000));
jedisPool = new JedisPool(jedisPoolConfig, configuration.getString("Redis.host","localhost"), configuration.getInt("Redis.port",6379));
if (configuration.getString("Redis.password") != null) {
jedisPool = new JedisPool(jedisPoolConfig, configuration.getString("Redis.host","localhost"), configuration.getInt("Redis.port",6379), 2000, configuration.getString("Redis.password"));
}
else {
jedisPool = new JedisPool(jedisPoolConfig, configuration.getString("Redis.host","localhost"), configuration.getInt("Redis.port",6379));
}
AdventureUtil.consoleMessage("[CustomFishing] <white>Redis Server Connected!");

View File

@@ -1,5 +1,5 @@
# don't change
config-version: '13'
config-version: '14'
# chinese/english/spanish
lang: english
@@ -82,6 +82,9 @@ mechanics:
# Does the special fishing mechanic requires special rod
# 是否需要特殊鱼竿才能体验钓鱼机制
need-special-rod-to-fish: false
# Does the CustomFishing loots requires special rod
# 是否需要特殊鱼竿才能获取钓鱼插件物品库的内容
need-special-rod-for-loots: false
# Does rod lose durability when player successfully fish
# 钓鱼成功后是否消耗耐久度
rod-lose-durability: true

View File

@@ -43,6 +43,7 @@ MariaDB:
# Sync competition scores between servers without lag!
Redis:
host: localhost
#password: 123456
port: 6379
MaxTotal: 10
MaxIdle: 10