mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-28 03:19:12 +00:00
click
This commit is contained in:
@@ -47,7 +47,7 @@ public class CommandManagerImpl implements CommandManager {
|
||||
public void load() {
|
||||
new CommandAPICommand("customfishing")
|
||||
.withAliases("cfishing")
|
||||
.withPermission(CommandPermission.OP)
|
||||
.withPermission("customfishing.admin")
|
||||
.withSubcommands(
|
||||
getReloadCommand(),
|
||||
getMarketCommand(),
|
||||
|
||||
@@ -39,10 +39,21 @@ public class LocalRankingImpl implements Ranking {
|
||||
*
|
||||
* @param competitionPlayer The CompetitionPlayer to add.
|
||||
*/
|
||||
@Override
|
||||
public void addPlayer(CompetitionPlayer competitionPlayer) {
|
||||
competitionPlayers.add(competitionPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a competition player from the ranking.
|
||||
*
|
||||
* @param player player's name
|
||||
*/
|
||||
@Override
|
||||
public void removePlayer(String player) {
|
||||
competitionPlayers.removeIf(e -> e.getPlayer().equals(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a competition player from the ranking.
|
||||
*
|
||||
|
||||
@@ -54,6 +54,20 @@ public class RedisRankingImpl implements Ranking {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(CompetitionPlayer competitionPlayer) {
|
||||
try (Jedis jedis = RedisManager.getInstance().getJedis()) {
|
||||
jedis.zincrby("cf_competition", competitionPlayer.getScore(), competitionPlayer.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlayer(String player) {
|
||||
try (Jedis jedis = RedisManager.getInstance().getJedis()) {
|
||||
jedis.del("cf_competition", player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator for iterating over pairs of player names and scores in descending order.
|
||||
*
|
||||
|
||||
@@ -51,7 +51,9 @@ import net.momirealms.customfishing.util.ItemUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -176,20 +178,6 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeftClick(PlayerInteractEvent event) {
|
||||
if (event.useItemInHand() == Event.Result.DENY)
|
||||
return;
|
||||
if (event.getAction() != org.bukkit.event.block.Action.LEFT_CLICK_AIR)
|
||||
return;
|
||||
GamingPlayer gamingPlayer = gamingPlayerMap.get(event.getPlayer().getUniqueId());
|
||||
if (gamingPlayer != null) {
|
||||
if (gamingPlayer.onLeftClick()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a fishing hook entity associated with a given UUID.
|
||||
*
|
||||
|
||||
@@ -28,6 +28,7 @@ import net.momirealms.customfishing.api.util.LogUtils;
|
||||
import net.momirealms.customfishing.api.util.OffsetUtils;
|
||||
import net.momirealms.customfishing.mechanic.requirement.RequirementManagerImpl;
|
||||
import net.momirealms.customfishing.util.ClassUtils;
|
||||
import net.momirealms.customfishing.util.ConfigUtils;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -57,6 +58,7 @@ public class GameManagerImpl implements GameManager {
|
||||
this.registerAccurateClickGame();
|
||||
this.registerHoldGame();
|
||||
this.registerTensionGame();
|
||||
this.registerClickGame();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
@@ -497,6 +499,52 @@ public class GameManagerImpl implements GameManager {
|
||||
}));
|
||||
}
|
||||
|
||||
private void registerClickGame() {
|
||||
this.registerGameType("click", (section -> {
|
||||
|
||||
var title = section.getString("title","<red>{click}");
|
||||
var subtitle = section.getString("subtitle", "<gray>Click <white>{clicks} <gray>times to win. Time left <white>{time}s");
|
||||
|
||||
return (player, fishHook, settings) -> new AbstractGamingPlayer(player, fishHook, settings) {
|
||||
|
||||
private int clickedTimes;
|
||||
private final int requiredTimes = settings.getDifficulty();
|
||||
|
||||
@Override
|
||||
public void arrangeTask() {
|
||||
this.task = CustomFishingPlugin.get().getScheduler().runTaskAsyncTimer(this, 50, 50, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
showUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onRightClick() {
|
||||
clickedTimes++;
|
||||
if (clickedTimes >= requiredTimes) {
|
||||
setGameResult(true);
|
||||
endGame();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void showUI() {
|
||||
AdventureManagerImpl.getInstance().sendTitle(
|
||||
player,
|
||||
title.replace("{click}", String.valueOf(clickedTimes)),
|
||||
subtitle.replace("{clicks}", String.valueOf(requiredTimes)).replace("{time}", String.format("%.1f", ((double) deadline - System.currentTimeMillis())/1000)),
|
||||
0,
|
||||
500,
|
||||
0
|
||||
);
|
||||
}
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads minigame expansions from the expansion folder.
|
||||
*/
|
||||
|
||||
@@ -317,7 +317,7 @@ public class ItemManagerImpl implements ItemManager, Listener {
|
||||
itemCFBuilder
|
||||
.amount(section.getInt("amount", 1))
|
||||
.stackable(section.getBoolean("stackable", true))
|
||||
.size(ConfigUtils.getSizePair(section.getString("size")))
|
||||
.size(ConfigUtils.getFloatPair(section.getString("size")))
|
||||
.price((float) section.getDouble("price.base"), (float) section.getDouble("price.bonus"))
|
||||
.customModelData(section.getInt("custom-model-data"))
|
||||
.nbt(section.getConfigurationSection("nbt"))
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package net.momirealms.customfishing.storage.method.database.sql;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import net.momirealms.customfishing.api.CustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.data.*;
|
||||
@@ -68,31 +69,33 @@ public abstract class AbstractHikariDatabase extends AbstractSQLDatabase impleme
|
||||
public void initialize() {
|
||||
YamlConfiguration config = plugin.getConfig("database.yml");
|
||||
ConfigurationSection section = config.getConfigurationSection(sqlBrand);
|
||||
|
||||
if (section == null) {
|
||||
LogUtils.warn("Failed to load database config. It seems that your config is broken. Please regenerate a new one.");
|
||||
return;
|
||||
}
|
||||
|
||||
super.tablePrefix = section.getString("table-prefix", "customfishing");
|
||||
dataSource = new HikariDataSource();
|
||||
dataSource.setDriverClassName(driverClass);
|
||||
dataSource.setJdbcUrl(String.format("jdbc:%s://%s:%s/%s%s",
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
hikariConfig.setUsername(section.getString("user", "root"));
|
||||
hikariConfig.setPassword(section.getString("password", "pa55w0rd"));
|
||||
hikariConfig.setJdbcUrl(String.format("jdbc:%s://%s:%s/%s%s",
|
||||
sqlBrand.toLowerCase(Locale.ENGLISH),
|
||||
section.getString("host", "localhost"),
|
||||
section.getString("port", "3306"),
|
||||
section.getString("database", "minecraft"),
|
||||
section.getString("connection-parameters")
|
||||
));
|
||||
|
||||
dataSource.setUsername(section.getString("user", "root"));
|
||||
dataSource.setPassword(section.getString("password", "pa55w0rd"));
|
||||
|
||||
dataSource.setMaximumPoolSize(section.getInt("Pool-Settings.max-pool-size", 10));
|
||||
dataSource.setMinimumIdle(section.getInt("Pool-Settings.min-idle", 10));
|
||||
dataSource.setMaxLifetime(section.getLong("Pool-Settings.max-lifetime", 180000L));
|
||||
dataSource.setKeepaliveTime(section.getLong("Pool-Settings.keep-alive-time", 60000L));
|
||||
dataSource.setConnectionTimeout(section.getLong("Pool-Settings.time-out", 20000L));
|
||||
dataSource.setPoolName("CustomFishingHikariPool");
|
||||
hikariConfig.setDriverClassName(driverClass);
|
||||
hikariConfig.setMaximumPoolSize(section.getInt("Pool-Settings.max-pool-size", 10));
|
||||
hikariConfig.setMinimumIdle(section.getInt("Pool-Settings.min-idle", 10));
|
||||
hikariConfig.setMaxLifetime(section.getLong("Pool-Settings.max-lifetime", 180000L));
|
||||
hikariConfig.setConnectionTimeout(section.getLong("Pool-Settings.time-out", 20000L));
|
||||
hikariConfig.setPoolName("CustomFishingHikariPool");
|
||||
try {
|
||||
hikariConfig.setKeepaliveTime(section.getLong("Pool-Settings.keep-alive-time", 60000L));
|
||||
} catch (NoSuchMethodError ignored) {
|
||||
}
|
||||
|
||||
final Properties properties = new Properties();
|
||||
properties.putAll(
|
||||
@@ -111,7 +114,8 @@ public abstract class AbstractHikariDatabase extends AbstractSQLDatabase impleme
|
||||
"elideSetAutoCommits", "true",
|
||||
"maintainTimeStats", "false")
|
||||
);
|
||||
dataSource.setDataSourceProperties(properties);
|
||||
hikariConfig.setDataSourceProperties(properties);
|
||||
dataSource = new HikariDataSource(hikariConfig);
|
||||
super.createTableIfNotExist();
|
||||
}
|
||||
|
||||
|
||||
@@ -105,21 +105,39 @@ public class ConfigUtils {
|
||||
/**
|
||||
* Parses a string representing a size range and returns a pair of floats.
|
||||
*
|
||||
* @param size The size string in the format "min~max".
|
||||
* @param string The size string in the format "min~max".
|
||||
* @return A pair of floats representing the minimum and maximum size.
|
||||
*/
|
||||
@Nullable
|
||||
public static Pair<Float, Float> getSizePair(String size) {
|
||||
if (size == null) return null;
|
||||
String[] split = size.split("~", 2);
|
||||
public static Pair<Float, Float> getFloatPair(String string) {
|
||||
if (string == null) return null;
|
||||
String[] split = string.split("~", 2);
|
||||
if (split.length != 2) {
|
||||
LogUtils.warn("Illegal size argument: " + size);
|
||||
LogUtils.warn("Illegal size argument: " + string);
|
||||
LogUtils.warn("Correct usage example: 10.5~25.6");
|
||||
return null;
|
||||
throw new IllegalArgumentException("Illegal float range");
|
||||
}
|
||||
return Pair.of(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a string representing a size range and returns a pair of ints.
|
||||
*
|
||||
* @param string The size string in the format "min~max".
|
||||
* @return A pair of ints representing the minimum and maximum size.
|
||||
*/
|
||||
@Nullable
|
||||
public static Pair<Integer, Integer> getIntegerPair(String string) {
|
||||
if (string == null) return null;
|
||||
String[] split = string.split("~", 2);
|
||||
if (split.length != 2) {
|
||||
LogUtils.warn("Illegal size argument: " + string);
|
||||
LogUtils.warn("Correct usage example: 10~20");
|
||||
throw new IllegalArgumentException("Illegal int range");
|
||||
}
|
||||
return Pair.of(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a list of strings in the format "key:value" into a list of Pairs with keys and WeightModifiers.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user