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

1.3-beta-1

This commit is contained in:
Xiao-MoMi
2023-03-03 23:15:37 +08:00
parent a6d97160c4
commit 1b1cf93b2a
160 changed files with 3406 additions and 3277 deletions

View File

@@ -4,7 +4,7 @@ plugins {
}
group = 'net.momirealms'
version = '1.2.23.2'
version = '1.3.0-beta-1'
repositories {
mavenCentral()

View File

@@ -20,88 +20,61 @@ package net.momirealms.customfishing;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.momirealms.biomeapi.BiomeAPI;
import net.momirealms.customfishing.commands.FishingBagCommand;
import net.momirealms.customfishing.commands.PluginCommand;
import net.momirealms.customfishing.commands.MainCommand;
import net.momirealms.customfishing.commands.SellFishCommand;
import net.momirealms.customfishing.helper.LibraryLoader;
import net.momirealms.customfishing.helper.VersionHelper;
import net.momirealms.customfishing.manager.*;
import net.momirealms.customfishing.util.AdventureUtil;
import net.momirealms.customfishing.util.ConfigUtil;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
public final class CustomFishing extends JavaPlugin {
public static CustomFishing plugin;
public static BukkitAudiences adventure;
public static ProtocolManager protocolManager;
private static CustomFishing plugin;
private static BukkitAudiences adventure;
private static ProtocolManager protocolManager;
private IntegrationManager integrationManager;
private FishingManager fishingManager;
private CompetitionManager competitionManager;
private BonusManager bonusManager;
private EffectManager effectManager;
private LootManager lootManager;
private LayoutManager layoutManager;
private BarMechanicManager barMechanicManager;
private BagDataManager bagDataManager;
private TotemManager totemManager;
private DataManager dataManager;
private SellManager sellManager;
private OffsetManager offsetManager;
private VersionHelper versionHelper;
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// .' \\| |// `.
// / \\||| : |||// \
// / _||||| -:- |||||_ \
// | | \\\ - /'| | |
// | \_| `\`---'// |_/ |
// \ .-\__ `-. -'__/-. /
// ___`. .' /--.--\ `. .'___
// ."" '< `.___\_<|>_/___.' _> \"".
// | | : `- \`. ;`. _/; .'/ / .' ; |
// \ \ `-. \_\_`. _.'_/_/ -' _.' /
// ================-.`___`-.__\ \___ /__.-'_.'_.-'================
// `=--=-'
// 佛祖保佑 永无BUG 永不卡服
@Override
public void onLoad() {
plugin = this;
LibraryLoader.load("redis.clients","jedis","4.3.1","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/");
LibraryLoader.load("com.zaxxer","HikariCP","5.0.1","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("net.objecthunter","exp4j","0.4.8","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("org.mariadb.jdbc","mariadb-java-client","3.0.6","https://repo.maven.apache.org/maven2/");
loadLibs();
}
@Override
public void onEnable() {
adventure = BukkitAudiences.create(this);
protocolManager = ProtocolLibrary.getProtocolManager();
this.fishingManager = new FishingManager();
this.dataManager = new DataManager();
this.integrationManager = new IntegrationManager();
this.competitionManager = new CompetitionManager();
this.bonusManager = new BonusManager();
this.lootManager = new LootManager();
this.layoutManager = new LayoutManager();
this.versionHelper = new VersionHelper(this);
this.fishingManager = new FishingManager(this);
this.dataManager = new DataManager(this);
this.integrationManager = new IntegrationManager(this);
this.competitionManager = new CompetitionManager(this);
this.effectManager = new EffectManager(this);
this.lootManager = new LootManager(this);
this.barMechanicManager = new BarMechanicManager(this);
this.totemManager = new TotemManager(this);
this.sellManager = new SellManager();
this.bagDataManager = new BagDataManager();
this.versionHelper = new VersionHelper();
reloadConfig();
registerCommands();
registerQuests();
this.sellManager = new SellManager(this);
this.bagDataManager = new BagDataManager(this);
this.offsetManager = new OffsetManager(this);
this.reload();
this.registerCommands();
this.registerQuests();
AdventureUtil.consoleMessage("[CustomFishing] Plugin Enabled!");
new Metrics(this, 16648);
}
@@ -111,40 +84,46 @@ public final class CustomFishing extends JavaPlugin {
this.fishingManager.unload();
this.integrationManager.unload();
this.competitionManager.unload();
this.bonusManager.unload();
this.effectManager.unload();
this.lootManager.unload();
this.layoutManager.unload();
this.bagDataManager.unload();
this.barMechanicManager.unload();
this.bagDataManager.disable();
this.totemManager.unload();
this.sellManager.unload();
this.sellManager.disable();
this.dataManager.unload();
if (adventure != null) {
adventure.close();
adventure = null;
}
}
private void registerCommands() {
PluginCommand pluginCommand = new PluginCommand();
Bukkit.getPluginCommand("customfishing").setExecutor(pluginCommand);
Bukkit.getPluginCommand("customfishing").setTabCompleter(pluginCommand);
MainCommand mainCommand = new MainCommand();
PluginCommand cfCommand = Bukkit.getPluginCommand("customfishing");
if (cfCommand != null) {
cfCommand.setExecutor(mainCommand);
cfCommand.setTabCompleter(mainCommand);
}
FishingBagCommand fishingBagCommand = new FishingBagCommand();
Bukkit.getPluginCommand("fishingbag").setExecutor(fishingBagCommand);
Bukkit.getPluginCommand("fishingbag").setTabCompleter(fishingBagCommand);
PluginCommand fbCommand = Bukkit.getPluginCommand("fishingbag");
if (fbCommand != null) {
fbCommand.setExecutor(fishingBagCommand);
fbCommand.setTabCompleter(fishingBagCommand);
}
SellFishCommand sellFishCommand = new SellFishCommand();
Bukkit.getPluginCommand("sellfish").setExecutor(sellFishCommand);
Bukkit.getPluginCommand("sellfish").setTabCompleter(sellFishCommand);
PluginCommand sfCommand = Bukkit.getPluginCommand("sellfish");
if (sfCommand != null) {
sfCommand.setExecutor(sellFishCommand);
sfCommand.setTabCompleter(sellFishCommand);
}
}
public static CustomFishing getInstance() {
return plugin;
}
public void reloadConfig() {
ConfigUtil.reload();
private void loadLibs() {
LibraryLoader.load("redis.clients","jedis","4.3.1","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/");
LibraryLoader.load("com.zaxxer","HikariCP","5.0.1","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("net.objecthunter","exp4j","0.4.8","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("org.mariadb.jdbc","mariadb-java-client","3.0.6","https://repo.maven.apache.org/maven2/");
}
private void registerQuests() {
@@ -163,18 +142,14 @@ public final class CustomFishing extends JavaPlugin {
return competitionManager;
}
public BonusManager getBonusManager() {
return bonusManager;
public EffectManager getEffectManager() {
return effectManager;
}
public LootManager getLootManager() {
return lootManager;
}
public LayoutManager getLayoutManager() {
return layoutManager;
}
public TotemManager getTotemManager() {
return totemManager;
}
@@ -194,4 +169,49 @@ public final class CustomFishing extends JavaPlugin {
public VersionHelper getVersionHelper() {
return versionHelper;
}
public BarMechanicManager getBarMechanicManager() {
return barMechanicManager;
}
public OffsetManager getOffsetManager() {
return offsetManager;
}
public void reload() {
ConfigManager.load();
MessageManager.load();
getIntegrationManager().unload();
getIntegrationManager().load();
getBarMechanicManager().unload();
getBarMechanicManager().load();
getEffectManager().unload();
getEffectManager().load();
getOffsetManager().unload();
getOffsetManager().load();
getLootManager().unload();
getLootManager().load();
getTotemManager().unload();
getTotemManager().load();
getFishingManager().unload();
getFishingManager().load();
getSellManager().unload();
getSellManager().load();
getCompetitionManager().unload();
getCompetitionManager().load();
getBagDataManager().unload();
getBagDataManager().load();
}
public static BukkitAudiences getAdventure() {
return adventure;
}
public static ProtocolManager getProtocolManager() {
return protocolManager;
}
public static CustomFishing getInstance() {
return plugin;
}
}

View File

@@ -18,7 +18,7 @@
package net.momirealms.customfishing.api;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.competition.Competition;
import net.momirealms.customfishing.fishing.competition.Competition;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
@@ -38,7 +38,7 @@ public class CustomFishingAPI {
* @return size
*/
public static float getFishSize(ItemStack fish) {
return CustomFishing.plugin.getFishingManager().getSize(fish);
return CustomFishing.getInstance().getFishingManager().getSize(fish);
}
/**
@@ -46,7 +46,7 @@ public class CustomFishingAPI {
* @return plugin instance
*/
public static CustomFishing getInstance() {
return CustomFishing.plugin;
return CustomFishing.getInstance();
}
/**
@@ -55,7 +55,7 @@ public class CustomFishingAPI {
* @return price
*/
public static double getItemPrice(ItemStack itemStack) {
return CustomFishing.plugin.getSellManager().getSingleItemPrice(itemStack);
return CustomFishing.getInstance().getSellManager().getSingleItemPrice(itemStack);
}
/**
@@ -64,6 +64,6 @@ public class CustomFishingAPI {
* @return itemStack
*/
public static ItemStack buildItem(String id) {
return CustomFishing.plugin.getIntegrationManager().build(id);
return CustomFishing.getInstance().getIntegrationManager().build(id);
}
}

View File

@@ -17,7 +17,7 @@
package net.momirealms.customfishing.api.event;
import net.momirealms.customfishing.object.loot.Loot;
import net.momirealms.customfishing.fishing.loot.Loot;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;

View File

@@ -17,7 +17,6 @@
package net.momirealms.customfishing.api.event;
import net.momirealms.customfishing.object.fishing.Difficulty;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@@ -27,10 +26,10 @@ import org.jetbrains.annotations.NotNull;
public class FishHookEvent extends PlayerEvent implements Cancellable {
private boolean cancelled;
private final Difficulty difficulty;
private int difficulty;
private static final HandlerList handlerList = new HandlerList();
public FishHookEvent(@NotNull Player who, Difficulty difficulty) {
public FishHookEvent(@NotNull Player who, int difficulty) {
super(who);
this.cancelled = false;
this.difficulty = difficulty;
@@ -56,7 +55,11 @@ public class FishHookEvent extends PlayerEvent implements Cancellable {
return getHandlerList();
}
public Difficulty getDifficulty() {
public int getDifficulty() {
return difficulty;
}
public void setDifficulty(int difficulty) {
this.difficulty = difficulty;
}
}

View File

@@ -17,7 +17,7 @@
package net.momirealms.customfishing.api.event;
import net.momirealms.customfishing.object.fishing.FishResult;
import net.momirealms.customfishing.fishing.FishResult;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;

View File

@@ -17,7 +17,7 @@
package net.momirealms.customfishing.api.event;
import net.momirealms.customfishing.object.fishing.Bonus;
import net.momirealms.customfishing.fishing.Effect;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@@ -26,14 +26,14 @@ import org.jetbrains.annotations.NotNull;
public class RodCastEvent extends PlayerEvent implements Cancellable {
private final Bonus bonus;
private final Effect effect;
private boolean isCancelled;
private static final HandlerList handlerList = new HandlerList();
public RodCastEvent(@NotNull Player who, @NotNull Bonus bonus) {
public RodCastEvent(@NotNull Player who, @NotNull Effect effect) {
super(who);
this.isCancelled = false;
this.bonus = bonus;
this.effect = effect;
}
@Override
@@ -56,7 +56,7 @@ public class RodCastEvent extends PlayerEvent implements Cancellable {
return getHandlerList();
}
public Bonus getBonus() {
return bonus;
public Effect getBonus() {
return effect;
}
}

View File

@@ -17,7 +17,7 @@
package net.momirealms.customfishing.api.event;
import net.momirealms.customfishing.object.totem.TotemConfig;
import net.momirealms.customfishing.fishing.totem.TotemConfig;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;

View File

@@ -29,11 +29,11 @@ import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class PluginCommand implements TabExecutor {
public class MainCommand implements TabExecutor {
private final Map<String, SubCommand> subCommandMap;
public PluginCommand() {
public MainCommand() {
subCommandMap = new ConcurrentHashMap<>();
regDefaultSubCommands();
}

View File

@@ -38,7 +38,7 @@ public class SellFishCommand implements TabExecutor {
return true;
}
player.closeInventory();
CustomFishing.plugin.getSellManager().openGuiForPlayer(player);
CustomFishing.getInstance().getSellManager().openGuiForPlayer(player);
return true;
}

View File

@@ -17,9 +17,9 @@
package net.momirealms.customfishing.commands.subcmd;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.commands.AbstractSubCommand;
import net.momirealms.customfishing.commands.SubCommand;
import net.momirealms.customfishing.manager.BonusManager;
import net.momirealms.customfishing.manager.MessageManager;
import net.momirealms.customfishing.util.AdventureUtil;
import net.momirealms.customfishing.util.ItemStackUtil;
@@ -45,7 +45,7 @@ public class BaitCommand extends AbstractSubCommand {
}
else if (args.get(0).equalsIgnoreCase("get")) {
if (sender instanceof Player player){
if (!BonusManager.BAITITEMS.containsKey(args.get(1))){
if (!CustomFishing.getInstance().getEffectManager().getBaitItems().containsKey(args.get(1))) {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
return true;
}
@@ -74,7 +74,7 @@ public class BaitCommand extends AbstractSubCommand {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notOnline.replace("{Player}", args.get(1)));
return true;
}
if (!BonusManager.BAITITEMS.containsKey(args.get(2))){
if (!CustomFishing.getInstance().getEffectManager().getBaitItems().containsKey(args.get(1))) {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
return true;
}
@@ -138,6 +138,6 @@ public class BaitCommand extends AbstractSubCommand {
}
private List<String> baits() {
return new ArrayList<>(BonusManager.BAITITEMS.keySet());
return new ArrayList<>(CustomFishing.getInstance().getEffectManager().getBaitItems().keySet());
}
}

View File

@@ -17,10 +17,10 @@
package net.momirealms.customfishing.commands.subcmd;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.commands.AbstractSubCommand;
import net.momirealms.customfishing.commands.SubCommand;
import net.momirealms.customfishing.competition.CompetitionSchedule;
import net.momirealms.customfishing.manager.CompetitionManager;
import net.momirealms.customfishing.fishing.competition.CompetitionSchedule;
import net.momirealms.customfishing.manager.MessageManager;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.command.CommandSender;
@@ -42,22 +42,23 @@ public class CompetitionCommand extends AbstractSubCommand {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.lackArgs);
return true;
}
if (args.get(0).equals("start")){
if (args.size() < 2){
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.lackArgs);
return true;
switch (args.get(0)) {
case "start" -> {
if (args.size() < 2) {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.lackArgs);
return true;
}
if (CompetitionSchedule.startCompetition(args.get(1))) AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.forceSuccess);
else AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.forceFailure);
}
if (CompetitionSchedule.startCompetition(args.get(1))){
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.forceSuccess);
} else {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.forceFailure);
case "end" -> {
CompetitionSchedule.endCompetition();
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.forceEnd);
}
case "cancel" -> {
CompetitionSchedule.cancelCompetition();
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.forceCancel);
}
} else if (args.get(0).equals("end")) {
CompetitionSchedule.endCompetition();
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.forceEnd);
} else if (args.get(0).equals("cancel")) {
CompetitionSchedule.cancelCompetition();
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.forceCancel);
}
return true;
}
@@ -79,6 +80,6 @@ public class CompetitionCommand extends AbstractSubCommand {
}
private List<String> competitions() {
return new ArrayList<>(CompetitionManager.competitionsC.keySet());
return new ArrayList<>(CustomFishing.getInstance().getCompetitionManager().getCompetitionsC().keySet());
}
}

View File

@@ -17,12 +17,12 @@
package net.momirealms.customfishing.commands.subcmd;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.commands.AbstractSubCommand;
import net.momirealms.customfishing.commands.SubCommand;
import net.momirealms.customfishing.manager.LootManager;
import net.momirealms.customfishing.fishing.loot.DroppedItem;
import net.momirealms.customfishing.fishing.loot.Loot;
import net.momirealms.customfishing.manager.MessageManager;
import net.momirealms.customfishing.object.loot.DroppedItem;
import net.momirealms.customfishing.object.loot.Loot;
import net.momirealms.customfishing.util.AdventureUtil;
import net.momirealms.customfishing.util.ItemStackUtil;
import org.bukkit.Bukkit;
@@ -142,12 +142,12 @@ public class LootCommand extends AbstractSubCommand {
private List<String> loots() {
List<String> loots = new ArrayList<>();
for (Map.Entry<String, Loot> en : LootManager.WATERLOOTS.entrySet()) {
for (Map.Entry<String, Loot> en : CustomFishing.getInstance().getLootManager().getWaterLoots().entrySet()) {
if (en.getValue() instanceof DroppedItem) {
loots.add(en.getKey());
}
}
for (Map.Entry<String, Loot> en : LootManager.LAVALOOTS.entrySet()) {
for (Map.Entry<String, Loot> en : CustomFishing.getInstance().getLootManager().getLavaLoots().entrySet()) {
if (en.getValue() instanceof DroppedItem) {
loots.add(en.getKey());
}

View File

@@ -29,17 +29,13 @@ public class OpenBagCommand extends AbstractSubCommand {
return true;
}
if (args.size() == 1) {
if (!sender.hasPermission("customfishing.admin")) {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.noPerm);
return true;
}
Player viewer = Bukkit.getPlayer(args.get(0));
if (viewer == null) {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.playerNotExist);
return true;
}
viewer.closeInventory();
CustomFishing.plugin.getBagDataManager().openFishingBag(viewer, viewer);
CustomFishing.getInstance().getBagDataManager().openFishingBag(viewer, viewer);
}
return true;
}
@@ -47,7 +43,6 @@ public class OpenBagCommand extends AbstractSubCommand {
@Override
public List<String> onTabComplete(CommandSender sender, List<String> args) {
if (!ConfigManager.enableFishingBag) return null;
if (!sender.hasPermission("customfishing.admin")) return null;
if (args.size() == 1) {
List<String> arrayList = new ArrayList<>();
for (String cmd : online_players()) {

View File

@@ -52,7 +52,7 @@ public class OpenCommand extends AbstractSubCommand {
return true;
}
player.closeInventory();
CustomFishing.plugin.getBagDataManager().openFishingBag(player, player);
CustomFishing.getInstance().getBagDataManager().openFishingBag(player, player);
}
if (args.size() == 1) {
if (!sender.hasPermission("customfishing.admin")) {
@@ -65,7 +65,7 @@ public class OpenCommand extends AbstractSubCommand {
return true;
}
player.closeInventory();
CustomFishing.plugin.getBagDataManager().openFishingBag(player, offlinePlayer);
CustomFishing.getInstance().getBagDataManager().openFishingBag(player, offlinePlayer);
}
return true;
}

View File

@@ -18,11 +18,11 @@
package net.momirealms.customfishing.commands.subcmd;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.commands.AbstractSubCommand;
import net.momirealms.customfishing.commands.SubCommand;
import net.momirealms.customfishing.manager.MessageManager;
import net.momirealms.customfishing.util.AdventureUtil;
import net.momirealms.customfishing.util.ConfigUtil;
import org.bukkit.command.CommandSender;
import java.util.List;
@@ -39,7 +39,7 @@ public final class ReloadCommand extends AbstractSubCommand {
public boolean onCommand(CommandSender sender, List<String> args) {
if (args.size() < 1) {
long time1 = System.currentTimeMillis();
ConfigUtil.reload();
CustomFishing.getInstance().reload();
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.reload.replace("{time}", String.valueOf(System.currentTimeMillis() - time1)));
return true;
}

View File

@@ -17,9 +17,9 @@
package net.momirealms.customfishing.commands.subcmd;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.commands.AbstractSubCommand;
import net.momirealms.customfishing.commands.SubCommand;
import net.momirealms.customfishing.manager.BonusManager;
import net.momirealms.customfishing.manager.MessageManager;
import net.momirealms.customfishing.util.AdventureUtil;
import net.momirealms.customfishing.util.ItemStackUtil;
@@ -46,7 +46,7 @@ public class RodCommand extends AbstractSubCommand {
}
if (args.get(0).equalsIgnoreCase("get")) {
if (sender instanceof Player player){
if (!BonusManager.RODITEMS.containsKey(args.get(1))){
if (!CustomFishing.getInstance().getEffectManager().getRodItems().containsKey(args.get(1))){
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
return true;
}
@@ -75,7 +75,7 @@ public class RodCommand extends AbstractSubCommand {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notOnline.replace("{Player}", args.get(1)));
return true;
}
if (!BonusManager.RODITEMS.containsKey(args.get(2))){
if (!CustomFishing.getInstance().getEffectManager().getRodItems().containsKey(args.get(2))){
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
return true;
}
@@ -139,6 +139,6 @@ public class RodCommand extends AbstractSubCommand {
}
private List<String> rods() {
return new ArrayList<>(BonusManager.RODITEMS.keySet());
return new ArrayList<>(CustomFishing.getInstance().getEffectManager().getRodItems().keySet());
}
}

View File

@@ -33,7 +33,7 @@ public class SellShopCommand extends AbstractSubCommand {
}
player.closeInventory();
CustomFishing.plugin.getSellManager().openGuiForPlayer(player);
CustomFishing.getInstance().getSellManager().openGuiForPlayer(player);
return true;
}

View File

@@ -17,9 +17,9 @@
package net.momirealms.customfishing.commands.subcmd;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.commands.AbstractSubCommand;
import net.momirealms.customfishing.commands.SubCommand;
import net.momirealms.customfishing.manager.BonusManager;
import net.momirealms.customfishing.manager.MessageManager;
import net.momirealms.customfishing.util.AdventureUtil;
import net.momirealms.customfishing.util.ItemStackUtil;
@@ -45,7 +45,7 @@ public class UtilCommand extends AbstractSubCommand {
}
else if (args.get(0).equalsIgnoreCase("get")) {
if (sender instanceof Player player){
if (!BonusManager.UTILITEMS.containsKey(args.get(1))){
if (!CustomFishing.getInstance().getEffectManager().getUtilItems().containsKey(args.get(1))){
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
return true;
}
@@ -74,7 +74,7 @@ public class UtilCommand extends AbstractSubCommand {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notOnline.replace("{Player}", args.get(1)));
return true;
}
if (!BonusManager.UTILITEMS.containsKey(args.get(2))){
if (!CustomFishing.getInstance().getEffectManager().getUtilItems().containsKey(args.get(2))){
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
return true;
}
@@ -138,6 +138,6 @@ public class UtilCommand extends AbstractSubCommand {
}
private List<String> utils() {
return new ArrayList<>(BonusManager.UTILITEMS.keySet());
return new ArrayList<>(CustomFishing.getInstance().getEffectManager().getUtilItems().keySet());
}
}

View File

@@ -35,26 +35,25 @@ import java.util.UUID;
public class FileStorageImpl implements DataStorageInterface {
private YamlConfiguration data;
private final CustomFishing plugin;
public FileStorageImpl(CustomFishing plugin) {
this.plugin = plugin;
}
@Override
public void initialize() {
data = ConfigUtil.readData(new File(CustomFishing.plugin.getDataFolder(), "sell-cache.yml"));
}
@Override
public void disable() {
try {
data.save(new File(CustomFishing.plugin.getDataFolder(), "sell-cache.yml"));
}
catch (IOException e) {
e.printStackTrace();
}
}
@Override
public Inventory loadBagData(OfflinePlayer player) {
YamlConfiguration config = ConfigUtil.readData(new File(CustomFishing.plugin.getDataFolder(), "fishingbag_data" + File.separator + player.getUniqueId() + ".yml"));
YamlConfiguration config = ConfigUtil.readData(new File(plugin.getDataFolder(), "fishingbag_data" + File.separator + player.getUniqueId() + ".yml"));
String contents = config.getString("contents");
int size = config.getInt("size", 9);
ItemStack[] itemStacks = InventoryUtil.getInventoryItems(contents);
@@ -71,7 +70,7 @@ public class FileStorageImpl implements DataStorageInterface {
data.set("contents", contents);
data.set("size", inventory.getSize());
try {
data.save(new File(CustomFishing.plugin.getDataFolder(), "fishingbag_data" + File.separator + playerBagData.getPlayer().getUniqueId() + ".yml"));
data.save(new File(plugin.getDataFolder(), "fishingbag_data" + File.separator + playerBagData.getPlayer().getUniqueId() + ".yml"));
}
catch (IOException e) {
e.printStackTrace();
@@ -81,14 +80,22 @@ public class FileStorageImpl implements DataStorageInterface {
@Override
public void loadSellCache(Player player) {
UUID uuid = player.getUniqueId();
int date = data.getInt(uuid + ".date");
double money = data.getDouble(uuid + ".sell");
CustomFishing.plugin.getSellManager().loadPlayerToCache(player.getUniqueId(), date, money);
YamlConfiguration data = ConfigUtil.readData(new File(plugin.getDataFolder(), "sell-data" + File.separator + uuid + ".yml"));
int date = data.getInt("date");
double money = data.getDouble("earnings");
plugin.getSellManager().loadPlayerToCache(player.getUniqueId(), date, money);
}
@Override
public void saveSellCache(UUID uuid, PlayerSellData playerSellData) {
data.set(uuid + ".date", playerSellData.getDate());
data.set(uuid + ".sell", playerSellData.getMoney());
YamlConfiguration data = new YamlConfiguration();
data.set("date", playerSellData.getDate());
data.set("earnings", playerSellData.getMoney());
try {
data.save(new File(plugin.getDataFolder(), "sell-data" + File.separator + uuid + ".yml"));
}
catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -37,7 +37,13 @@ import java.util.UUID;
public class MySQLStorageImpl implements DataStorageInterface {
public static SqlConnection sqlConnection = new SqlConnection();
private final SqlConnection sqlConnection;
private final CustomFishing plugin;
public MySQLStorageImpl(CustomFishing plugin) {
this.plugin = plugin;
this.sqlConnection = new SqlConnection(this);
}
@Override
public void initialize() {
@@ -54,10 +60,8 @@ public class MySQLStorageImpl implements DataStorageInterface {
@Override
public Inventory loadBagData(OfflinePlayer player) {
Inventory inventory = null;
try {
Connection connection = sqlConnection.getConnectionAndCheck();
String sql = String.format(SqlConstants.SQL_SELECT_BAG_BY_UUID, sqlConnection.getTablePrefix() + "_fishingbag");;
PreparedStatement statement = connection.prepareStatement(sql);
String sql = String.format(SqlConstants.SQL_SELECT_BAG_BY_UUID, sqlConnection.getTablePrefix() + "_fishingbag");
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, player.getUniqueId().toString());
ResultSet rs = statement.executeQuery();
if (rs.next()) {
@@ -70,7 +74,6 @@ public class MySQLStorageImpl implements DataStorageInterface {
else {
inventory = Bukkit.createInventory(null, 9, "{CustomFishing_Bag_" + player.getName() + "}");
}
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -93,21 +96,18 @@ public class MySQLStorageImpl implements DataStorageInterface {
@Override
public void loadSellCache(Player player) {
try {
Connection connection = sqlConnection.getConnectionAndCheck();
String sql = String.format(SqlConstants.SQL_SELECT_SELL_BY_UUID, sqlConnection.getTablePrefix() + "_sellcache");
PreparedStatement statement = connection.prepareStatement(sql);
String sql = String.format(SqlConstants.SQL_SELECT_SELL_BY_UUID, sqlConnection.getTablePrefix() + "_sellcache");
try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, player.getUniqueId().toString());
ResultSet rs = statement.executeQuery();
if (rs.next()) {
int date = rs.getInt(2);
int money = rs.getInt(3);
CustomFishing.plugin.getSellManager().loadPlayerToCache(player.getUniqueId(), date, money);
plugin.getSellManager().loadPlayerToCache(player.getUniqueId(), date, money);
}
else {
CustomFishing.plugin.getSellManager().loadPlayerToCache(player.getUniqueId(), Calendar.getInstance().get(Calendar.DATE), 0);
plugin.getSellManager().loadPlayerToCache(player.getUniqueId(), Calendar.getInstance().get(Calendar.DATE), 0);
}
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -125,11 +125,8 @@ public class MySQLStorageImpl implements DataStorageInterface {
private void createTableIfNotExist(String table, String sqlStat) {
String sql = String.format(sqlStat, table);
try {
Connection connection = sqlConnection.getConnection();
PreparedStatement statement = connection.prepareStatement(sql);
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.executeUpdate();
connection.close();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to create table");
}
@@ -137,13 +134,11 @@ public class MySQLStorageImpl implements DataStorageInterface {
private void insertBagData(UUID uuid, int size, String contents) {
String sql = String.format(SqlConstants.SQL_INSERT_BAG, sqlConnection.getTablePrefix() + "_fishingbag");
try {
Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql);
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, uuid.toString());
statement.setInt(2, size);
statement.setString(3, contents);
statement.executeUpdate();
connection.close();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to insert data for " + uuid);
}
@@ -151,13 +146,11 @@ public class MySQLStorageImpl implements DataStorageInterface {
private void insertSellData(UUID uuid, int date, int money) {
String sql = String.format(SqlConstants.SQL_INSERT_SELL, sqlConnection.getTablePrefix() + "_sellcache");
try {
Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql);
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, uuid.toString());
statement.setInt(2, date);
statement.setInt(3, money);
statement.executeUpdate();
connection.close();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to insert data for " + uuid);
}
@@ -165,13 +158,11 @@ public class MySQLStorageImpl implements DataStorageInterface {
private void updateBagData(UUID uuid, int size, String contents) {
String sql = String.format(SqlConstants.SQL_UPDATE_BAG_BY_UUID, sqlConnection.getTablePrefix() + "_fishingbag");
try {
Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql);
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setInt(1, size);
statement.setString(2, contents);
statement.setString(3, uuid.toString());
statement.executeUpdate();
connection.close();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to update data for " + uuid);
}
@@ -179,13 +170,11 @@ public class MySQLStorageImpl implements DataStorageInterface {
private void updateSellData(UUID uuid, int date, int money) {
String sql = String.format(SqlConstants.SQL_UPDATE_SELL_BY_UUID, sqlConnection.getTablePrefix() + "_sellcache");
try {
Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql);
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setInt(1, date);
statement.setInt(2, money);
statement.setString(3, uuid.toString());
statement.executeUpdate();
connection.close();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to update data for " + uuid);
}
@@ -194,16 +183,31 @@ public class MySQLStorageImpl implements DataStorageInterface {
public boolean exists(UUID uuid, String sqlStat, String suffix) {
String sql = String.format(sqlStat, sqlConnection.getTablePrefix() + "_" + suffix);
boolean exist;
try {
Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql);
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, uuid.toString());
ResultSet rs = statement.executeQuery();
exist = rs.next();
connection.close();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to select data for " + uuid);
return false;
}
return exist;
}
public void migrate() {
String sql_1 = String.format(SqlConstants.SQL_ALTER_TABLE, sqlConnection.getTablePrefix() + "_fishingbag");
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql_1)) {
statement.executeUpdate();
AdventureUtil.consoleMessage("<green>[CustomFishing] 1/2 tables updated");
} catch (SQLException ex) {
AdventureUtil.consoleMessage("<red>[CustomFishing] Failed to migrate data");
}
String sql_2 = String.format(SqlConstants.SQL_ALTER_TABLE, sqlConnection.getTablePrefix() + "_sellcache");
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql_2)) {
statement.executeUpdate();
AdventureUtil.consoleMessage("<green>[CustomFishing] 2/2 tables updated");
} catch (SQLException ex) {
AdventureUtil.consoleMessage("<red>[CustomFishing] Failed to migrate data");
}
}
}

View File

@@ -20,10 +20,13 @@ package net.momirealms.customfishing.data.storage;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import com.zaxxer.hikari.pool.HikariPool;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.util.AdventureUtil;
import net.momirealms.customfishing.util.ConfigUtil;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
@@ -33,9 +36,14 @@ public class SqlConnection {
private boolean firstTry = false;
private HikariDataSource hikariDataSource;
private String tablePrefix;
private final MySQLStorageImpl mySQLStorage;
public SqlConnection(MySQLStorageImpl mySQLStorage) {
this.mySQLStorage = mySQLStorage;
}
public void createNewHikariConfiguration() {
ConfigUtil.update("database.yml");
YamlConfiguration config = ConfigUtil.getConfig("database.yml");
String storageMode = config.getString("data-storage-method", "MySQL");
@@ -68,6 +76,17 @@ public class SqlConnection {
} catch (HikariPool.PoolInitializationException e) {
AdventureUtil.consoleMessage("[CustomFishing] Failed to create sql connection");
}
if (config.getBoolean("migration", false)) {
mySQLStorage.migrate();
config.set("migration", false);
try {
config.save(new File(CustomFishing.getInstance().getDataFolder(), "database.yml"));
}
catch (IOException e) {
AdventureUtil.consoleMessage("<RED>[CustomFishing] Error occurred when saving database config");
}
}
}
public boolean setGlobalConnection() {

View File

@@ -19,12 +19,14 @@ package net.momirealms.customfishing.data.storage;
public class SqlConstants {
public static final String SQL_CREATE_BAG_TABLE = "CREATE TABLE IF NOT EXISTS `%s` ( `uuid` VARCHAR(36) NOT NULL , `size` INT(8) NOT NULL , `contents` LONGTEXT NOT NULL , PRIMARY KEY (`uuid`) )";
public static final String SQL_CREATE_SELL_TABLE = "CREATE TABLE IF NOT EXISTS `%s` ( `uuid` VARCHAR(36) NOT NULL , `date` INT(4) NOT NULL , `money` INT(12) NOT NULL , PRIMARY KEY (`uuid`) )";
public static final String SQL_INSERT_BAG = "INSERT INTO `%s`(`uuid`, `size`, `contents`) VALUES (?, ?, ?)";
public static final String SQL_INSERT_SELL = "INSERT INTO `%s`(`uuid`, `date`, `money`) VALUES (?, ?, ?)";
public static final String SQL_UPDATE_BAG_BY_UUID = "UPDATE `%s` SET `size` = ?, `contents` = ? WHERE `uuid` = ?";
public static final String SQL_UPDATE_SELL_BY_UUID = "UPDATE `%s` SET `date` = ?, `money` = ? WHERE `uuid` = ?";
public static final String SQL_CREATE_BAG_TABLE = "CREATE TABLE IF NOT EXISTS `%s` ( `uuid` VARCHAR(36) NOT NULL, `version` INT(2) NOT NULL, `size` INT(8) NOT NULL, `contents` LONGTEXT NOT NULL, PRIMARY KEY (`uuid`) )";
public static final String SQL_CREATE_SELL_TABLE = "CREATE TABLE IF NOT EXISTS `%s` ( `uuid` VARCHAR(36) NOT NULL, `version` INT(2) NOT NULL, `date` INT(4) NOT NULL, `money` INT(12) NOT NULL, PRIMARY KEY (`uuid`) )";
public static final String SQL_INSERT_BAG = "INSERT INTO `%s`(`uuid`, `version`, `size`, `contents`) VALUES (?, ?, ?)";
public static final String SQL_INSERT_SELL = "INSERT INTO `%s`(`uuid`, `version`, `date`, `money`) VALUES (?, ?, ?)";
public static final String SQL_UPDATE_BAG_BY_UUID = "UPDATE `%s` SET `version` = 0, `size` = ?, `contents` = ? WHERE `uuid` = ?";
public static final String SQL_UPDATE_SELL_BY_UUID = "UPDATE `%s` SET `version` = 0, `date` = ?, `money` = ? WHERE `uuid` = ?";
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(2) NOT NULL AFTER `uuid`";
}

View File

@@ -15,15 +15,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.fishing;
package net.momirealms.customfishing.fishing;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.loot.Loot;
import net.momirealms.customfishing.manager.ConfigManager;
import net.momirealms.customfishing.manager.FishingManager;
import net.momirealms.customfishing.manager.LootManager;
import net.momirealms.customfishing.object.loot.Loot;
import net.momirealms.customfishing.util.AdventureUtil;
import net.momirealms.customfishing.util.ArmorStandUtil;
import net.momirealms.customfishing.util.FakeItemUtil;
@@ -45,28 +44,30 @@ import java.util.Random;
public class BobberCheckTask extends BukkitRunnable {
private final FishHook fishHook;
private final CustomFishing plugin;
private int timer;
private final Player player;
private final Bonus bonus;
private final Effect effect;
private final FishingManager fishingManager;
private boolean hooked;
private boolean reserve;
private int jump_timer;
private final int lureLevel;
private BukkitTask cache_1;
private BukkitTask cache_2;
private BukkitTask cache_3;
private ArmorStand entityCache;
private BukkitTask task_1;
private BukkitTask task_2;
private BukkitTask task_3;
private ArmorStand hookedEntity;
private final int entityID;
private boolean land;
private boolean first;
public BobberCheckTask(Player player, Bonus bonus, FishHook fishHook, FishingManager fishingManager, int lureLevel, int entityID) {
public BobberCheckTask(CustomFishing plugin, Player player, Effect effect, FishHook fishHook, FishingManager fishingManager, int lureLevel, int entityID) {
this.fishHook = fishHook;
this.plugin = plugin;
this.fishingManager = fishingManager;
this.player = player;
this.timer = 0;
this.bonus = bonus;
this.effect = effect;
this.reserve = true;
this.jump_timer = 0;
this.lureLevel = lureLevel;
@@ -79,8 +80,8 @@ public class BobberCheckTask extends BukkitRunnable {
public void run() {
timer ++;
if (!land && entityID != 0) {
CustomFishing.protocolManager.sendServerPacket(player, FakeItemUtil.getVelocity(entityID, fishHook.getVelocity()));
CustomFishing.protocolManager.sendServerPacket(player, FakeItemUtil.getTpPacket(entityID, fishHook.getLocation()));
CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtil.getVelocity(entityID, fishHook.getVelocity()));
CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtil.getTpPacket(entityID, fishHook.getLocation()));
}
if (timer > 3600) {
stop();
@@ -96,7 +97,7 @@ public class BobberCheckTask extends BukkitRunnable {
}
if (fishHook.getLocation().getBlock().getType() == Material.LAVA) {
land = true;
if (!bonus.canLavaFishing()) {
if (!effect.canLavaFishing()) {
stop();
return;
}
@@ -128,12 +129,12 @@ public class BobberCheckTask extends BukkitRunnable {
}
if (fishHook.isInWater()) {
stop();
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.plugin, () -> {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
List<Loot> possibleLoots = new ArrayList<>();
if (!(ConfigManager.needRodForLoot && !bonus.hasSpecialRod())) {
possibleLoots = fishingManager.getPossibleLootList(new FishingCondition(fishHook.getLocation(), player), false, LootManager.WATERLOOTS.values());
if (!(ConfigManager.needRodForLoot && !effect.hasSpecialRod())) {
possibleLoots = fishingManager.getPossibleLootList(new FishingCondition(fishHook.getLocation(), player), false, plugin.getLootManager().getWaterLoots().values());
}
fishingManager.getNextLoot(player, bonus, possibleLoots);
fishingManager.getNextLoot(player, effect, possibleLoots);
if (ConfigManager.enableWaterAnimation) {
ArmorStandUtil.sendAnimationToPlayer(fishHook.getLocation(), player, ConfigManager.water_item, ConfigManager.water_time);
}
@@ -149,63 +150,63 @@ public class BobberCheckTask extends BukkitRunnable {
cancel();
cancelTask();
fishingManager.removePlayerFromLavaFishing(player);
if (entityCache != null && !entityCache.isDead()) {
entityCache.remove();
entityCache = null;
if (hookedEntity != null && !hookedEntity.isDead()) {
hookedEntity.remove();
hookedEntity = null;
}
sendRemovePacket();
}
private void sendRemovePacket() {
if (entityID == 0) return;
CustomFishing.protocolManager.sendServerPacket(player, FakeItemUtil.getDestroyPacket(entityID));
CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtil.getDestroyPacket(entityID));
}
public void cancelTask() {
if (cache_1 != null) {
cache_1.cancel();
cache_1 = null;
if (task_1 != null) {
task_1.cancel();
task_1 = null;
}
if (cache_2 != null) {
cache_2.cancel();
cache_2 = null;
if (task_2 != null) {
task_2.cancel();
task_2 = null;
}
if (cache_3 != null) {
cache_3.cancel();
cache_3 = null;
if (task_3 != null) {
task_3.cancel();
task_3 = null;
}
}
private void randomTime() {
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.plugin, () -> {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
List<Loot> possibleLoots = new ArrayList<>();
if (!(ConfigManager.needRodForLoot && !bonus.hasSpecialRod())) {
possibleLoots = fishingManager.getPossibleLootList(new FishingCondition(fishHook.getLocation(), player), false, LootManager.LAVALOOTS.values());
if (!(ConfigManager.needRodForLoot && !effect.hasSpecialRod())) {
possibleLoots = fishingManager.getPossibleLootList(new FishingCondition(fishHook.getLocation(), player), false, plugin.getLootManager().getLavaLoots().values());
}
fishingManager.getNextLoot(player, bonus, possibleLoots);
fishingManager.getNextLoot(player, effect, possibleLoots);
});
cancelTask();
int random = new Random().nextInt(ConfigManager.lavaMaxTime) + ConfigManager.lavaMinTime;
random -= lureLevel * 100;
random *= bonus.getTime();
random *= effect.getTimeModifier();
if (random < ConfigManager.lavaMinTime) random = ConfigManager.lavaMinTime;
cache_1 = Bukkit.getScheduler().runTaskLater(CustomFishing.plugin, () -> {
task_1 = Bukkit.getScheduler().runTaskLater(plugin, () -> {
hooked = true;
if (entityCache != null && !entityCache.isDead()) entityCache.remove();
if (hookedEntity != null && !hookedEntity.isDead()) hookedEntity.remove();
AdventureUtil.playerSound(player, Sound.Source.NEUTRAL, Key.key("minecraft:block.pointed_dripstone.drip_lava_into_cauldron"), 1, 1);
if (ConfigManager.instantBar) fishingManager.showBar(player);
}, random);
cache_2 = Bukkit.getScheduler().runTaskLater(CustomFishing.plugin, () -> {
task_2 = Bukkit.getScheduler().runTaskLater(plugin, () -> {
hooked = false;
reserve = true;
}, random + 40);
cache_3 = new LavaEffect(fishHook.getLocation()).runTaskTimerAsynchronously(CustomFishing.plugin,random - 60,1);
task_3 = new LavaEffect(fishHook.getLocation()).runTaskTimerAsynchronously(plugin,random - 60,1);
}
private void spawnArmorStand(Location armorLoc) {
armorLoc.setY(armorLoc.getBlockY() + 0.2);
if (entityCache != null && !entityCache.isDead()) entityCache.remove();
entityCache = armorLoc.getWorld().spawn(armorLoc, ArmorStand.class, a -> {
if (hookedEntity != null && !hookedEntity.isDead()) hookedEntity.remove();
hookedEntity = armorLoc.getWorld().spawn(armorLoc, ArmorStand.class, a -> {
a.setInvisible(true);
a.setCollidable(false);
a.setInvulnerable(true);
@@ -214,7 +215,7 @@ public class BobberCheckTask extends BukkitRunnable {
a.setSmall(true);
a.setGravity(false);
});
fishHook.setHookedEntity(entityCache);
fishHook.setHookedEntity(hookedEntity);
}
public boolean isHooked() {

View File

@@ -15,23 +15,34 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.fishing;
package net.momirealms.customfishing.fishing;
import net.momirealms.customfishing.manager.ConfigManager;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class Bonus {
public class Effect {
private HashMap<String, Double> weightMD;
private HashMap<String, Integer> weightAS;
private double time;
private double score;
private double timeModifier;
private double sizeMultiplier;
private double scoreMultiplier;
private int difficulty;
private double doubleLoot;
private double doubleLootChance;
private boolean canLavaFishing;
private boolean hasSpecialRod;
public double getSizeMultiplier() {
return sizeMultiplier + 1;
}
public void setSizeMultiplier(double sizeMultiplier) {
this.sizeMultiplier = sizeMultiplier;
}
public HashMap<String, Double> getWeightMD() {
return weightMD;
}
@@ -48,20 +59,16 @@ public class Bonus {
this.weightAS = weightAS;
}
public double getTime() {
return time;
public double getTimeModifier() {
return timeModifier;
}
public void setTime(double time) {
this.time = time;
public void setTimeModifier(double timeModifier) {
this.timeModifier = timeModifier;
}
private double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
public void setScoreMultiplier(double scoreMultiplier) {
this.scoreMultiplier = scoreMultiplier;
}
public int getDifficulty() {
@@ -72,46 +79,47 @@ public class Bonus {
this.difficulty = difficulty;
}
public double getDoubleLoot() {
return doubleLoot;
public double getDoubleLootChance() {
return doubleLootChance;
}
public void setDoubleLoot(double doubleLoot) {
this.doubleLoot = doubleLoot;
public void setDoubleLootChance(double doubleLootChance) {
this.doubleLootChance = doubleLootChance;
}
public boolean canLavaFishing() {
return canLavaFishing;
return canLavaFishing || ConfigManager.allRodsFishInLava;
}
public void setCanLavaFishing(boolean canLavaFishing) {
this.canLavaFishing = canLavaFishing;
}
public void addBonus(Bonus anotherBonus) {
HashMap<String, Integer> weightAS = anotherBonus.getWeightAS();
public void addEffect(Effect anotherEffect) {
HashMap<String, Integer> weightAS = anotherEffect.getWeightAS();
if (weightAS != null) {
for (Map.Entry<String, Integer> en : weightAS.entrySet()) {
String group = en.getKey();
this.weightAS.put(group, Optional.ofNullable(this.weightAS.get(group)).orElse(0) + en.getValue());
}
}
HashMap<String, Double> weightMD = anotherBonus.getWeightMD();
HashMap<String, Double> weightMD = anotherEffect.getWeightMD();
if (weightMD != null){
for (Map.Entry<String, Double> en : weightMD.entrySet()) {
String group = en.getKey();
this.weightMD.put(group, Optional.ofNullable(this.weightMD.get(group)).orElse(1d) + en.getValue());
}
}
if (anotherBonus.getTime() != 0) this.time += (anotherBonus.getTime() - 1);
if (anotherBonus.getDoubleLoot() != 0) this.doubleLoot += anotherBonus.getDoubleLoot();
if (anotherBonus.getDifficulty() != 0) this.difficulty += anotherBonus.getDifficulty();
if (anotherBonus.getScore() != 0) this.score += anotherBonus.getScore();
if (anotherBonus.canLavaFishing()) this.canLavaFishing = true;
if (anotherEffect.getTimeModifier() != 0) this.timeModifier += (anotherEffect.getTimeModifier() - 1);
if (anotherEffect.getDoubleLootChance() != 0) this.doubleLootChance += anotherEffect.getDoubleLootChance();
if (anotherEffect.getDifficulty() != 0) this.difficulty += anotherEffect.getDifficulty();
if (anotherEffect.getScoreMultiplier() != 0) this.scoreMultiplier += anotherEffect.getScoreMultiplier();
if (anotherEffect.getSizeMultiplier() != 0) this.sizeMultiplier += anotherEffect.getSizeMultiplier();
if (anotherEffect.canLavaFishing()) this.canLavaFishing = true;
}
public double getScoreBonus() {
return score + 1;
public double getScoreMultiplier() {
return scoreMultiplier + 1;
}
public boolean hasSpecialRod() {

View File

@@ -15,12 +15,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.fishing;
package net.momirealms.customfishing.fishing;
public enum FishResult {
FAILURE,
CAUGHT_MOB,
CAUGHT_LOOT,
CAUGHT_VANILLA
CATCH_MOB,
CATCH_SPECIAL_ITEM,
CATCH_VANILLA_ITEM
}

View File

@@ -15,11 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.fishing;
package net.momirealms.customfishing.fishing;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.requirements.CustomPapi;
import net.momirealms.customfishing.integration.papi.PlaceholderManager;
import net.momirealms.customfishing.object.requirements.CustomPapi;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@@ -34,7 +34,7 @@ public class FishingCondition{
public FishingCondition(Location location, Player player) {
this.location = location;
this.player = player;
PlaceholderManager placeholderManager = CustomFishing.plugin.getIntegrationManager().getPlaceholderManager();
PlaceholderManager placeholderManager = CustomFishing.getInstance().getIntegrationManager().getPlaceholderManager();
this.papiMap = new HashMap<>();
for (String papi : CustomPapi.allPapi) {
this.papiMap.put(papi, placeholderManager.parse(player, papi));

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.fishing;
package net.momirealms.customfishing.fishing;
import org.bukkit.Location;
import org.bukkit.Particle;

View File

@@ -0,0 +1,30 @@
package net.momirealms.customfishing.fishing;
import net.momirealms.customfishing.fishing.bar.FishingBar;
import java.util.Random;
public class MiniGameConfig {
private final int time;
private final FishingBar[] bars;
private final int[] difficulties;
public MiniGameConfig(int time, FishingBar[] bars, int[] difficulties) {
this.time = time;
this.bars = bars;
this.difficulties = difficulties;
}
public FishingBar getRandomBar() {
return bars[new Random().nextInt(bars.length)];
}
public int getRandomDifficulty() {
return difficulties[new Random().nextInt(difficulties.length)];
}
public int getTime() {
return this.time;
}
}

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.fishing;
package net.momirealms.customfishing.fishing;
import org.bukkit.inventory.ItemStack;

View File

@@ -0,0 +1,30 @@
package net.momirealms.customfishing.fishing.bar;
import org.bukkit.configuration.ConfigurationSection;
import java.util.Random;
public abstract class FishingBar {
protected String[] titles;
protected String font;
protected String barImage;
public FishingBar(ConfigurationSection section) {
this.titles = section.getStringList("title").size() == 0 ? new String[]{section.getString("title")} : section.getStringList("title").toArray(new String[0]);
this.font = section.getString("subtitle.font", "customfishing:bar");
this.barImage = section.getString("subtitle.bar","");
}
public String getRandomTitle() {
return titles[new Random().nextInt(titles.length)];
}
public String getBarImage() {
return barImage;
}
public String getFont() {
return font;
}
}

View File

@@ -0,0 +1,73 @@
/*
* 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;
import java.util.Objects;
import java.util.Set;
public class ModeOneBar extends FishingBar {
private final int widthPerSection;
private final double[] successRate;
private final int totalWidth;
private final int pointerWidth;
private final String pointerImage;
private final int pointerOffset;
public ModeOneBar(ConfigurationSection section) {
super(section);
Set<String> chances = Objects.requireNonNull(section.getConfigurationSection("success-rate-sections")).getKeys(false);
this.widthPerSection = section.getInt("arguments.width-per-section", 16);
this.successRate = new double[chances.size()];
for(int i = 0; i < chances.size(); i++)
successRate[i] = section.getDouble("success-rate-sections." + (i + 1));
this.totalWidth = chances.size() * widthPerSection - 1;
this.pointerImage = section.getString("subtitle.pointer","");
this.pointerOffset = section.getInt("arguments.pointer-offset");
this.pointerWidth = section.getInt("arguments.pointer-width");
}
public int getWidthPerSection() {
return widthPerSection;
}
public double[] getSuccessRate() {
return successRate;
}
public int getTotalWidth() {
return totalWidth;
}
public String getPointerImage() {
return pointerImage;
}
public int getPointerWidth() {
return pointerWidth;
}
public int getPointerOffset() {
return pointerOffset;
}
}

View File

@@ -0,0 +1,67 @@
package net.momirealms.customfishing.fishing.bar;
import org.bukkit.configuration.ConfigurationSection;
import java.util.Random;
public class ModeTwoBar extends FishingBar {
private final int[] time_requirements;
private final String judgement_area_image;
private final String fish_image;
private final int bar_effective_width;
private final int judgement_area_offset;
private final int judgement_area_width;
private final int fish_icon_width;
private final String[] progress;
private double punishment;
public ModeTwoBar(ConfigurationSection section) {
super(section);
this.time_requirements = section.getIntegerList("hold-time-requirements").stream().mapToInt(Integer::intValue).toArray();
this.judgement_area_image = section.getString("subtitle.judgment-area");
this.fish_image = section.getString("subtitle.fish");
this.bar_effective_width = section.getInt("arguments.bar-effective-area-width");
this.judgement_area_offset = section.getInt("arguments.judgment-area-offset");
this.judgement_area_width = section.getInt("arguments.judgment-area-width");
this.fish_icon_width = section.getInt("arguments.fish-icon-width");
this.punishment = section.getDouble("arguments.punishment");
this.progress = section.getStringList("progress").toArray(new String[0]);
}
public int getRandomTimeRequirement() {
return time_requirements[new Random().nextInt(time_requirements.length)] * 20;
}
public String getJudgement_area_image() {
return judgement_area_image;
}
public String getFish_image() {
return fish_image;
}
public int getBar_effective_width() {
return bar_effective_width;
}
public int getJudgement_area_offset() {
return judgement_area_offset;
}
public int getJudgement_area_width() {
return judgement_area_width;
}
public int getFish_icon_width() {
return fish_icon_width;
}
public String[] getProgress() {
return progress;
}
public double getPunishment() {
return punishment;
}
}

View File

@@ -15,13 +15,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.competition;
package net.momirealms.customfishing.fishing.competition;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.competition.bossbar.BossBarManager;
import net.momirealms.customfishing.competition.ranking.LocalRankingImpl;
import net.momirealms.customfishing.competition.ranking.RankingInterface;
import net.momirealms.customfishing.competition.ranking.RedisRankingImpl;
import net.momirealms.customfishing.fishing.competition.bossbar.BossBarManager;
import net.momirealms.customfishing.fishing.competition.ranking.LocalRankingImpl;
import net.momirealms.customfishing.fishing.competition.ranking.RankingInterface;
import net.momirealms.customfishing.fishing.competition.ranking.RedisRankingImpl;
import net.momirealms.customfishing.integration.papi.PlaceholderManager;
import net.momirealms.customfishing.manager.ConfigManager;
import net.momirealms.customfishing.manager.MessageManager;
@@ -54,32 +54,26 @@ public class Competition {
public void begin(boolean forceStart) {
this.goal = competitionConfig.getGoal();
if (this.goal == CompetitionGoal.RANDOM) {
this.goal = getRandomGoal();
}
if (this.goal == CompetitionGoal.RANDOM) this.goal = getRandomGoal();
this.remainingTime = this.competitionConfig.getDuration();
this.startTime = Instant.now().getEpochSecond();
Collection<? extends Player> playerCollections = Bukkit.getOnlinePlayers();
if (playerCollections.size() >= competitionConfig.getMinPlayers() || forceStart) {
if (ConfigManager.useRedis){
ranking = new RedisRankingImpl();
} else {
ranking = new LocalRankingImpl();
}
if (ConfigManager.useRedis) this.ranking = new RedisRankingImpl();
else this.ranking = new LocalRankingImpl();
startTimer();
for (String startMsg : competitionConfig.getStartMessage()) {
for (Player player : playerCollections) {
for (String startMsg : competitionConfig.getStartMessage())
for (Player player : playerCollections)
AdventureUtil.playerMessage(player, startMsg);
}
}
for (String startCmd : competitionConfig.getStartCommand()) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), startCmd);
}
if (competitionConfig.isEnableBossBar()) {
bossBarManager = new BossBarManager();
bossBarManager.load();
for (String startCmd : competitionConfig.getStartCommand()) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), startCmd);
if (competitionConfig.isBossBarEnabled()) {
this.bossBarManager = new BossBarManager();
this.bossBarManager.load();
}
}
else {
@@ -98,14 +92,14 @@ public class Competition {
end();
}
}
}.runTaskTimer(CustomFishing.plugin, 0, 20);
}.runTaskTimer(CustomFishing.getInstance(), 0, 20);
}
public void cancel() {
if (this.bossBarManager != null) {
bossBarManager.unload();
}
ranking.clear();
this.ranking.clear();
this.timerTask.cancel();
currentCompetition = null;
}
@@ -118,8 +112,7 @@ public class Competition {
givePrize();
List<String> newMessage = new ArrayList<>();
PlaceholderManager placeholderManager = CustomFishing.plugin.getIntegrationManager().getPlaceholderManager();
PlaceholderManager placeholderManager = CustomFishing.getInstance().getIntegrationManager().getPlaceholderManager();
for (String endMsg : competitionConfig.getEndMessage()) {
List<String> placeholders = new ArrayList<>(placeholderManager.detectPlaceholders(endMsg));
for (String placeholder : placeholders) {
@@ -148,7 +141,7 @@ public class Competition {
currentCompetition = null;
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomFishing.plugin, ()-> {
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomFishing.getInstance(), ()-> {
ranking.clear();
}, 600);
}
@@ -190,13 +183,10 @@ public class Competition {
}
private boolean decreaseTime() {
long tVac;
long current = Instant.now().getEpochSecond();
int duration = competitionConfig.getDuration();
progress = (float) remainingTime / duration;
remainingTime = duration - (current - startTime);
if ((tVac = (current - startTime) + 1) != duration - remainingTime) {
for (long i = duration - remainingTime; i < tVac; i++) {

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.competition;
package net.momirealms.customfishing.fishing.competition;
import net.momirealms.customfishing.competition.bossbar.BossBarConfig;
import net.momirealms.customfishing.fishing.competition.bossbar.BossBarConfig;
import net.momirealms.customfishing.object.action.ActionInterface;
import java.util.Calendar;
@@ -90,7 +90,7 @@ public class CompetitionConfig {
return bossBarConfig;
}
public boolean isEnableBossBar() {
public boolean isBossBarEnabled() {
return enableBossBar;
}

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.competition;
package net.momirealms.customfishing.fishing.competition;
public enum CompetitionGoal {

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.competition;
package net.momirealms.customfishing.fishing.competition;
import org.jetbrains.annotations.NotNull;

View File

@@ -15,10 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.competition;
package net.momirealms.customfishing.fishing.competition;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.manager.CompetitionManager;
import net.momirealms.customfishing.object.Function;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
@@ -42,7 +41,7 @@ public class CompetitionSchedule extends Function {
private int doubleCheckTime;
public static boolean startCompetition(String competitionName) {
CompetitionConfig competitionConfig = CompetitionManager.competitionsC.get(competitionName);
CompetitionConfig competitionConfig = CustomFishing.getInstance().getCompetitionManager().getCompetitionsC().get(competitionName);
if (competitionConfig == null) return false;
if (Competition.currentCompetition != null) {
Competition.currentCompetition.end();
@@ -76,13 +75,13 @@ public class CompetitionSchedule extends Function {
this.checkTimeTask = new BukkitRunnable() {
public void run() {
if (isANewMinute()) {
CompetitionConfig competitionConfig = CompetitionManager.competitionsT.get(getCurrentTime());
CompetitionConfig competitionConfig = CustomFishing.getInstance().getCompetitionManager().getCompetitionsT().get(getCurrentTime());
if (competitionConfig != null && competitionConfig.canStart()) {
startCompetition(competitionConfig);
}
}
}
}.runTaskTimer(CustomFishing.plugin, 60 - LocalTime.now().getSecond(), 100);
}.runTaskTimer(CustomFishing.getInstance(), 60 - LocalTime.now().getSecond(), 100);
}
public void stopCheck() {

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.competition.bossbar;
package net.momirealms.customfishing.fishing.competition.bossbar;
import org.bukkit.boss.BarColor;

View File

@@ -15,11 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.competition.bossbar;
package net.momirealms.customfishing.fishing.competition.bossbar;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.competition.Competition;
import net.momirealms.customfishing.listener.SimpleListener;
import net.momirealms.customfishing.fishing.competition.Competition;
import net.momirealms.customfishing.listener.JoinQuitListener;
import net.momirealms.customfishing.manager.MessageManager;
import net.momirealms.customfishing.object.Function;
import net.momirealms.customfishing.util.AdventureUtil;
@@ -32,20 +32,20 @@ import java.util.HashMap;
public class BossBarManager extends Function {
public static HashMap<Player, BossBarSender> cache = new HashMap<>();
private final SimpleListener simpleListener;
private final JoinQuitListener joinQuitListener;
public BossBarManager() {
this.simpleListener = new SimpleListener(this);
this.joinQuitListener = new JoinQuitListener(this);
}
@Override
public void load() {
Bukkit.getPluginManager().registerEvents(this.simpleListener, CustomFishing.plugin);
Bukkit.getPluginManager().registerEvents(this.joinQuitListener, CustomFishing.getInstance());
}
@Override
public void unload() {
if (this.simpleListener != null) HandlerList.unregisterAll(this.simpleListener);
if (this.joinQuitListener != null) HandlerList.unregisterAll(this.joinQuitListener);
for (BossBarSender bossBarSender : cache.values()) {
bossBarSender.hide();
}

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.competition.bossbar;
package net.momirealms.customfishing.fishing.competition.bossbar;
public enum BossBarOverlay {
NOTCHED_6,

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.competition.bossbar;
package net.momirealms.customfishing.fishing.competition.bossbar;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.InternalStructure;
@@ -25,8 +25,8 @@ import com.comphenix.protocol.wrappers.WrappedChatComponent;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.competition.Competition;
import net.momirealms.customfishing.object.TextCache;
import net.momirealms.customfishing.fishing.competition.Competition;
import net.momirealms.customfishing.object.DynamicText;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.boss.BarColor;
import org.bukkit.entity.Player;
@@ -46,8 +46,8 @@ public class BossBarSender {
private int timer_2;
private int counter;
private final int size;
private final TextCache[] texts;
private TextCache text;
private final DynamicText[] texts;
private DynamicText text;
private BukkitTask bukkitTask;
private final UUID uuid;
private boolean force;
@@ -62,9 +62,9 @@ public class BossBarSender {
public BossBarSender(Player player, BossBarConfig config){
String[] str = config.getText();
this.size = str.length;
texts = new TextCache[str.length];
texts = new DynamicText[str.length];
for (int i = 0; i < str.length; i++) {
texts[i] = new TextCache(player, str[i]);
texts[i] = new DynamicText(player, str[i]);
}
text = texts[0];
this.player = player;
@@ -76,7 +76,7 @@ public class BossBarSender {
public void show() {
this.isShown = true;
CustomFishing.protocolManager.sendServerPacket(player, getPacket());
CustomFishing.getProtocolManager().sendServerPacket(player, getPacket());
this.bukkitTask = new BukkitRunnable() {
@Override
@@ -99,12 +99,12 @@ public class BossBarSender {
timer_1 = 0;
if (text.update() || force) {
force = false;
CustomFishing.protocolManager.sendServerPacket(player, getUpdatePacket());
CustomFishing.protocolManager.sendServerPacket(player, getProgressPacket());
CustomFishing.getProtocolManager().sendServerPacket(player, getUpdatePacket());
CustomFishing.getProtocolManager().sendServerPacket(player, getProgressPacket());
}
}
}
}.runTaskTimerAsynchronously(CustomFishing.plugin,0,1);
}.runTaskTimerAsynchronously(CustomFishing.getInstance(),0,1);
}
private PacketContainer getUpdatePacket() {
@@ -171,7 +171,7 @@ public class BossBarSender {
Field remove = bar.getDeclaredField("f");
remove.setAccessible(true);
packet.getModifier().write(1, remove.get(null));
CustomFishing.protocolManager.sendServerPacket(player, packet);
CustomFishing.getProtocolManager().sendServerPacket(player, packet);
} catch (ClassNotFoundException e){
AdventureUtil.consoleMessage("<red>[CustomFishing] Failed to remove bossbar for " + player.getName());
} catch (NoSuchFieldException | IllegalAccessException e) {

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.competition.ranking;
package net.momirealms.customfishing.fishing.competition.ranking;
import net.momirealms.customfishing.competition.CompetitionPlayer;
import net.momirealms.customfishing.fishing.competition.CompetitionPlayer;
import java.util.*;

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.competition.ranking;
package net.momirealms.customfishing.fishing.competition.ranking;
import net.momirealms.customfishing.competition.CompetitionPlayer;
import net.momirealms.customfishing.fishing.competition.CompetitionPlayer;
import org.jetbrains.annotations.Nullable;
import java.util.Iterator;

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.competition.ranking;
package net.momirealms.customfishing.fishing.competition.ranking;
import net.momirealms.customfishing.competition.CompetitionPlayer;
import net.momirealms.customfishing.fishing.competition.CompetitionPlayer;
import net.momirealms.customfishing.util.JedisUtil;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.resps.Tuple;

View File

@@ -15,33 +15,31 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.loot;
package net.momirealms.customfishing.fishing.loot;
import net.momirealms.customfishing.object.fishing.Difficulty;
import net.momirealms.customfishing.fishing.MiniGameConfig;
import net.momirealms.customfishing.object.LeveledEnchantment;
import org.jetbrains.annotations.Nullable;
public class DroppedItem extends Loot{
public class DroppedItem extends Loot {
private boolean randomDurability;
private final boolean randomDurability;
private LeveledEnchantment[] randomEnchants;
private final String material;
private String[] size;
private float basicPrice;
private float sizeBonus;
public DroppedItem(String key, Difficulty[] difficulty, int time, int weight, String material) {
super(key, difficulty, time, weight);
public DroppedItem(String key, String nick, String material, MiniGameConfig[] fishingGames, int weight, boolean showInFinder, double score, boolean randomDurability) {
super(key, nick, fishingGames, weight, showInFinder, score);
this.material = material;
this.randomDurability = randomDurability;
}
public boolean isRandomDurability() {
return randomDurability;
}
public void setRandomDurability(boolean randomDurability) {
this.randomDurability = randomDurability;
}
@Nullable
public LeveledEnchantment[] getRandomEnchants() {
return randomEnchants;

View File

@@ -15,18 +15,23 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.loot;
package net.momirealms.customfishing.fishing.loot;
import net.momirealms.customfishing.object.LeveledEnchantment;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemFlag;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class Item {
private final String key;
private int amount;
private final Material material;
private String name;
private List<String> lore;
@@ -42,6 +47,40 @@ public class Item {
this.key = key;
}
public Item(ConfigurationSection section, String key) {
this.key = key;
this.material = Material.valueOf(section.getString("material", "cod").toUpperCase());
this.amount = section.getInt("amount", 1);
this.setUnbreakable(section.getBoolean("unbreakable", false));
if (section.contains("display.lore")) this.setLore(section.getStringList("display.lore"));
if (section.contains("display.name")) this.setName(section.getString("display.name"));
if (section.contains("custom-model-data")) this.setCustomModelData(section.getInt("custom-model-data"));
if (section.contains("enchantments")) {
List<LeveledEnchantment> enchantmentList = new ArrayList<>();
Objects.requireNonNull(section.getConfigurationSection("enchantments")).getKeys(false).forEach(enchant -> {
LeveledEnchantment leveledEnchantment = new LeveledEnchantment(
NamespacedKey.fromString(enchant),
section.getInt("enchantments." + enchant)
);
enchantmentList.add(leveledEnchantment);
});
this.setEnchantment(enchantmentList);
}
if (section.contains("item_flags")) {
ArrayList<ItemFlag> itemFlags = new ArrayList<>();
section.getStringList("item_flags").forEach(flag -> itemFlags.add(ItemFlag.valueOf(flag)));
this.setItemFlags(itemFlags);
}
if (section.contains("nbt")) {
ConfigurationSection nbtSection = section.getConfigurationSection(".nbt");
if (nbtSection == null) return;
this.setNbt(nbtSection.getValues(false));
}
if (section.contains("head64")) {
this.setHead64(section.getString("head64"));
}
}
public Material getMaterial() {
return material;
}
@@ -114,6 +153,10 @@ public class Item {
return key;
}
public int getAmount() {
return amount;
}
public Item cloneWithPrice(double price){
Item newItem = new Item(this.material, this.key);
if (this.lore != null){

View File

@@ -15,57 +15,50 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.loot;
package net.momirealms.customfishing.fishing.loot;
import net.momirealms.customfishing.fishing.MiniGameConfig;
import net.momirealms.customfishing.fishing.requirements.RequirementInterface;
import net.momirealms.customfishing.object.action.ActionInterface;
import net.momirealms.customfishing.object.fishing.Difficulty;
import net.momirealms.customfishing.object.fishing.Layout;
import net.momirealms.customfishing.object.requirements.RequirementInterface;
public class Loot {
public static Loot EMPTY = new Loot("empty", new Difficulty[]{new Difficulty(1, 1)}, 5000, 10);
public static Loot EMPTY = new Loot("null", "null", new MiniGameConfig[0], 0, false, 0d);
protected String key;
protected String nick;
protected Difficulty[] difficulty;
protected final String key;
protected final String nick;
protected String group;
protected boolean showInFinder;
protected Layout[] layout;
protected final boolean showInFinder;
protected ActionInterface[] successActions;
protected ActionInterface[] failureActions;
protected ActionInterface[] hookActions;
protected int weight;
protected int time;
protected ActionInterface[] consumeActions;
protected RequirementInterface[] requirements;
protected double score;
protected final MiniGameConfig[] fishingGames;
protected final int weight;
protected final double score;
public Loot(String key, Difficulty[] difficulty, int time, int weight) {
public Loot(String key, String nick, MiniGameConfig[] fishingGames, int weight, boolean showInFinder, double score) {
this.key = key;
this.difficulty = difficulty;
this.time = time;
this.nick = nick;
this.weight = weight;
this.showInFinder = showInFinder;
this.score = score;
this.fishingGames = fishingGames;
}
public MiniGameConfig[] getFishingGames() {
return fishingGames;
}
public String getKey() {
return key;
}
public String getNick() {
return nick;
}
public void setNick(String nick) {
this.nick = nick;
}
public Difficulty[] getDifficulty() {
return difficulty;
}
public void setDifficulty(Difficulty[] difficulty) {
this.difficulty = difficulty;
}
public String getGroup() {
return group;
}
@@ -78,18 +71,6 @@ public class Loot {
return showInFinder;
}
public void setShowInFinder(boolean showInFinder) {
this.showInFinder = showInFinder;
}
public Layout[] getLayout() {
return layout;
}
public void setLayout(Layout[] layout) {
this.layout = layout;
}
public ActionInterface[] getSuccessActions() {
return successActions;
}
@@ -102,6 +83,14 @@ public class Loot {
return failureActions;
}
public ActionInterface[] getConsumeActions() {
return consumeActions;
}
public void setConsumeActions(ActionInterface[] consumeActions) {
this.consumeActions = consumeActions;
}
public void setFailureActions(ActionInterface[] failureActions) {
this.failureActions = failureActions;
}
@@ -118,12 +107,8 @@ public class Loot {
return weight;
}
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
public double getScore() {
return score;
}
public RequirementInterface[] getRequirements() {
@@ -133,12 +118,4 @@ public class Loot {
public void setRequirements(RequirementInterface[] requirements) {
this.requirements = requirements;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
}

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.loot;
package net.momirealms.customfishing.fishing.loot;
import net.momirealms.customfishing.object.fishing.Difficulty;
import net.momirealms.customfishing.fishing.MiniGameConfig;
import org.jetbrains.annotations.NotNull;
public class Mob extends Loot{
@@ -26,11 +26,11 @@ public class Mob extends Loot{
private final int mobLevel;
private final MobVector mobVector;
public Mob(String key, Difficulty[] difficulty, int time, int weight, String mobID, int level, MobVector vector) {
super(key, difficulty, time, weight);
public Mob(String key, String nick, MiniGameConfig[] fishingGames, int weight, boolean showInFinder, double score, String mobID, int mobLevel, MobVector mobVector) {
super(key, nick, fishingGames, weight, showInFinder, score);
this.mobID = mobID;
this.mobLevel = level;
this.mobVector = vector;
this.mobLevel = mobLevel;
this.mobVector = mobVector;
}
public String getMobID() {

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.loot;
package net.momirealms.customfishing.fishing.loot;
public record MobVector(double horizontal, double vertical) {

View File

@@ -0,0 +1,69 @@
package net.momirealms.customfishing.fishing.mode;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.bar.FishingBar;
import net.momirealms.customfishing.manager.FishingManager;
import net.momirealms.customfishing.manager.MessageManager;
import net.momirealms.customfishing.manager.OffsetManager;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
public abstract class FishingGame extends BukkitRunnable {
protected OffsetManager offsetManager;
protected long deadline;
protected FishingManager fishingManager;
protected CustomFishing plugin;
protected Player player;
protected int difficulty;
protected String title;
public FishingGame(CustomFishing plugin, FishingManager fishingManager, long deadline, Player player, int difficulty, FishingBar fishingBar) {
this.offsetManager = plugin.getOffsetManager();
this.fishingManager = fishingManager;
this.player = player;
this.deadline = deadline;
this.difficulty = difficulty;
this.title = fishingBar.getRandomTitle();
}
@Override
public void run() {
}
public void showBar() {
}
public boolean isSuccess() {
return false;
}
protected boolean timeOut() {
if (System.currentTimeMillis() > deadline) {
AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.escape);
cancel();
fishingManager.removeFishingPlayer(player);
fishingManager.removeBobber(player);
fishingManager.fail(player, null, true);
return true;
}
return false;
}
protected boolean switchItem() {
PlayerInventory playerInventory = player.getInventory();
if (playerInventory.getItemInMainHand().getType() != Material.FISHING_ROD && playerInventory.getItemInOffHand().getType() != Material.FISHING_ROD) {
cancel();
fishingManager.removeFishingPlayer(player);
player.removePotionEffect(PotionEffectType.SLOW);
return true;
}
return false;
}
}

View File

@@ -0,0 +1,70 @@
/*
* 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;
import net.momirealms.customfishing.fishing.bar.ModeOneBar;
import net.momirealms.customfishing.manager.FishingManager;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.entity.Player;
public class ModeOneGame extends FishingGame {
private int progress;
private boolean face;
private final ModeOneBar modeOneBar;
public ModeOneGame(CustomFishing plugin, FishingManager fishingManager, long deadline, Player player, int difficulty, ModeOneBar modeOneBar) {
super(plugin, fishingManager, deadline, player, difficulty, modeOneBar);
this.face = true;
this.modeOneBar = modeOneBar;
}
@Override
public void run() {
if (timeOut() || switchItem()) return;
if (face) progress += difficulty;
else progress -= difficulty;
if (progress > modeOneBar.getTotalWidth()) {
face = !face;
progress = 2 * modeOneBar.getTotalWidth() - progress;
}
else if (progress < 0) {
face = !face;
progress = -progress;
}
showBar();
}
@Override
public void showBar() {
String bar =
"<font:" + modeOneBar.getFont() + ">" + modeOneBar.getBarImage()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars(modeOneBar.getPointerOffset() + progress) + "</font>"
+ modeOneBar.getPointerImage()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars(modeOneBar.getTotalWidth() - progress - modeOneBar.getPointerWidth()) + "</font></font>";
AdventureUtil.playerTitle(player, title, bar,0,500,0);
}
@Override
public boolean isSuccess() {
int last = progress / modeOneBar.getWidthPerSection();
return (Math.random() < modeOneBar.getSuccessRate()[last]);
}
}

View File

@@ -0,0 +1,139 @@
package net.momirealms.customfishing.fishing.mode;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.bar.ModeTwoBar;
import net.momirealms.customfishing.manager.FishingManager;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
public class ModeTwoGame extends FishingGame {
private boolean success;
private double hold_time;
private final ModeTwoBar modeTwoBar;
private double judgement_position;
private double fish_position;
private double judgement_velocity;
private double fish_velocity;
private int timer;
private final int time_requirement;
public ModeTwoGame(CustomFishing plugin, FishingManager fishingManager, long deadline, Player player, int difficulty, ModeTwoBar modeTwoBar) {
super(plugin, fishingManager, deadline, player, difficulty, modeTwoBar);
this.success = false;
this.judgement_position = (double) modeTwoBar.getBar_effective_width() / 2;
this.fish_position = 0;
this.timer = 0;
this.modeTwoBar = modeTwoBar;
this.time_requirement = modeTwoBar.getRandomTimeRequirement();
}
@Override
public void run() {
if (timeOut() || switchItem()) return;
if (player.isSneaking()) addV();
else reduceV();
if (timer < 20) {
timer++;
}
else {
timer = 0;
if (Math.random() > ((double) 1 / (difficulty + 1))) {
burst();
}
}
judgement_position += judgement_velocity;
fish_position += fish_velocity;
fraction();
calibrate();
if (fish_position >= judgement_position && fish_position + modeTwoBar.getFish_icon_width() <= judgement_position + modeTwoBar.getJudgement_area_width()) {
hold_time++;
}
else {
hold_time -= modeTwoBar.getPunishment();
}
if (hold_time >= time_requirement) {
cancel();
success = true;
FishHook fishHook = fishingManager.getBobber(player);
if (fishHook != null) {
fishingManager.proceedReelIn(fishHook.getLocation(), player, this);
fishingManager.removeBobber(player);
}
fishingManager.removeFishingPlayer(player);
return;
}
showBar();
}
@Override
public void showBar() {
String bar = "<font:" + modeTwoBar.getFont() + ">" + modeTwoBar.getBarImage()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getJudgement_area_offset() + judgement_position)) + "</font>"
+ modeTwoBar.getJudgement_area_image()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getBar_effective_width() - judgement_position - modeTwoBar.getJudgement_area_width() + 1)) + "</font>"
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (-modeTwoBar.getBar_effective_width() - 2 + fish_position)) + "</font>"
+ modeTwoBar.getFish_image()
+ "<font:" + offsetManager.getFont() + ">" + offsetManager.getOffsetChars((int) (modeTwoBar.getBar_effective_width() - fish_position - modeTwoBar.getFish_icon_width() + 1)) + "</font>"
+ "</font>";
if (hold_time > time_requirement) hold_time = time_requirement;
AdventureUtil.playerTitle(player,
title.replace("{progress}", modeTwoBar.getProgress()[(int) ((hold_time / time_requirement) * modeTwoBar.getProgress().length)])
, bar,0,500,0
);
}
private void burst() {
if (Math.random() < (judgement_position / modeTwoBar.getBar_effective_width())) {
judgement_velocity = -2 - Math.random() * difficulty;
}
else {
judgement_velocity = 2 + Math.random() * difficulty;
}
}
private void fraction() {
if (judgement_velocity > 0) {
judgement_velocity -= 0.15;
if (judgement_velocity < 0) judgement_velocity = 0;
}
else {
judgement_velocity += 0.15;
if (judgement_velocity > 0) judgement_velocity = 0;
}
}
private void reduceV() {
fish_velocity -= 0.3;
}
private void addV() {
fish_velocity += 0.45;
}
private void calibrate() {
if (fish_position < 0) {
fish_position = 0;
fish_velocity = 0;
}
if (fish_position + modeTwoBar.getFish_icon_width() > modeTwoBar.getBar_effective_width()) {
fish_position = modeTwoBar.getBar_effective_width() - modeTwoBar.getFish_icon_width();
fish_velocity = 0;
}
if (judgement_position < 0) {
judgement_position = 0;
judgement_velocity = 0;
}
if (judgement_position + modeTwoBar.getJudgement_area_width() > modeTwoBar.getBar_effective_width()) {
judgement_position = modeTwoBar.getBar_effective_width() - modeTwoBar.getJudgement_area_width();
judgement_velocity = 0;
}
}
@Override
public boolean isSuccess() {
return success;
}
}

View File

@@ -15,11 +15,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements;
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.biomeapi.BiomeAPI;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.object.fishing.FishingCondition;
import net.momirealms.customfishing.fishing.FishingCondition;
import java.util.List;

View File

@@ -15,10 +15,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements;
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.object.fishing.FishingCondition;
import net.momirealms.customfishing.object.requirements.papi.*;
import net.momirealms.customfishing.fishing.FishingCondition;
import net.momirealms.customfishing.fishing.requirements.papi.*;
import org.bukkit.configuration.MemorySection;
import java.util.ArrayList;

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements;
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.object.fishing.FishingCondition;
import net.momirealms.customfishing.fishing.FishingCondition;
public record PermissionImpl(String permission) implements RequirementInterface {

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements;
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.object.fishing.FishingCondition;
import net.momirealms.customfishing.fishing.FishingCondition;
public interface RequirementInterface {
boolean isConditionMet(FishingCondition fishingCondition);

View File

@@ -15,11 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements;
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.FishingCondition;
import net.momirealms.customfishing.integration.SeasonInterface;
import net.momirealms.customfishing.object.fishing.FishingCondition;
import java.util.List;
@@ -27,7 +27,7 @@ public record SeasonImpl(List<String> seasons) implements RequirementInterface {
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
SeasonInterface seasonInterface = CustomFishing.plugin.getIntegrationManager().getSeasonInterface();
SeasonInterface seasonInterface = CustomFishing.getInstance().getIntegrationManager().getSeasonInterface();
if (seasonInterface == null) return true;
String currentSeason = seasonInterface.getSeason(fishingCondition.getLocation().getWorld());
for (String season : seasons) {

View File

@@ -0,0 +1,12 @@
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.FishingCondition;
public record SkillLevelImpl(int level) implements RequirementInterface {
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
return CustomFishing.getInstance().getIntegrationManager().getSkillInterface().getLevel(fishingCondition.getPlayer()) >= level;
}
}

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements;
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.object.fishing.FishingCondition;
import net.momirealms.customfishing.fishing.FishingCondition;
import org.apache.commons.lang.StringUtils;
import java.util.List;

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements;
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.object.fishing.FishingCondition;
import net.momirealms.customfishing.fishing.FishingCondition;
import org.bukkit.World;
import java.util.List;

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements;
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.object.fishing.FishingCondition;
import net.momirealms.customfishing.fishing.FishingCondition;
import java.util.List;

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements;
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.object.fishing.FishingCondition;
import net.momirealms.customfishing.fishing.FishingCondition;
import org.apache.commons.lang.StringUtils;
import java.util.List;

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements.papi;
package net.momirealms.customfishing.fishing.requirements.papi;
import org.bukkit.entity.Player;

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements.papi;
package net.momirealms.customfishing.fishing.requirements.papi;
import org.bukkit.entity.Player;

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements.papi;
package net.momirealms.customfishing.fishing.requirements.papi;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements.papi;
package net.momirealms.customfishing.fishing.requirements.papi;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements.papi;
package net.momirealms.customfishing.fishing.requirements.papi;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements.papi;
package net.momirealms.customfishing.fishing.requirements.papi;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements.papi;
package net.momirealms.customfishing.fishing.requirements.papi;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements.papi;
package net.momirealms.customfishing.fishing.requirements.papi;
import org.bukkit.entity.Player;

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.requirements.papi;
package net.momirealms.customfishing.fishing.requirements.papi;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.totem;
package net.momirealms.customfishing.fishing.totem;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.manager.FishingManager;
@@ -54,7 +54,7 @@ public class ActivatedTotem extends BukkitRunnable {
this.hasHolo = totem.getHoloText() != null;
this.nearbyPlayerSet = Collections.synchronizedSet(new HashSet<>());
this.particleTimerTask = new TotemParticle(location, totem.getRadius(), totem.getParticle());
this.particleTimerTask.runTaskTimerAsynchronously(CustomFishing.plugin, 0, 4);
this.particleTimerTask.runTaskTimerAsynchronously(CustomFishing.getInstance(), 0, 4);
this.direction = direction;
}
@@ -74,7 +74,7 @@ public class ActivatedTotem extends BukkitRunnable {
if (nearbyPlayers.remove(player)) {
if (hasHolo) {
for (int i = 0; i < entityID.length; i++) {
CustomFishing.protocolManager.sendServerPacket(player, ArmorStandUtil.getMetaPacket(entityID[i],
CustomFishing.getProtocolManager().sendServerPacket(player, ArmorStandUtil.getMetaPacket(entityID[i],
totem.getHoloText()[entityID.length - 1 - i].replace("{time}", String.valueOf(totem.getDuration() - timer))
.replace("{max_time}", String.valueOf(totem.getDuration()))
));
@@ -85,7 +85,7 @@ public class ActivatedTotem extends BukkitRunnable {
else {
if (hasHolo) {
for (int j : entityID) {
CustomFishing.protocolManager.sendServerPacket(player, ArmorStandUtil.getDestroyPacket(j));
CustomFishing.getProtocolManager().sendServerPacket(player, ArmorStandUtil.getDestroyPacket(j));
}
}
nearbyPlayerSet.remove(player);
@@ -95,8 +95,8 @@ public class ActivatedTotem extends BukkitRunnable {
for (Player newComer : nearbyPlayers) {
if (hasHolo) {
for (int i = 0; i < entityID.length; i++) {
CustomFishing.protocolManager.sendServerPacket(newComer, ArmorStandUtil.getSpawnPacket(entityID[i], location.clone().add(0.5, totem.getHoloOffset() + i * 0.4, 0.5)));
CustomFishing.protocolManager.sendServerPacket(newComer, ArmorStandUtil.getMetaPacket(entityID[i],
CustomFishing.getProtocolManager().sendServerPacket(newComer, ArmorStandUtil.getSpawnPacket(entityID[i], location.clone().add(0.5, totem.getHoloOffset() + i * 0.4, 0.5)));
CustomFishing.getProtocolManager().sendServerPacket(newComer, ArmorStandUtil.getMetaPacket(entityID[i],
totem.getHoloText()[entityID.length - 1 - i].replace("{time}", String.valueOf(totem.getDuration() - timer))
.replace("{max_time}", String.valueOf(totem.getDuration()))
));
@@ -119,11 +119,11 @@ public class ActivatedTotem extends BukkitRunnable {
this.particleTimerTask.cancel();
cancel();
fishingManager.removeTotem(location);
CustomFishing.plugin.getTotemManager().clearBreakDetectCache(totem.getFinalModel(), location, direction);
CustomFishing.getInstance().getTotemManager().clearBreakDetectCache(totem.getFinalModel(), location, direction);
if (hasHolo) {
for (Player player : nearbyPlayerSet) {
for (int j : entityID) {
CustomFishing.protocolManager.sendServerPacket(player, ArmorStandUtil.getDestroyPacket(j));
CustomFishing.getProtocolManager().sendServerPacket(player, ArmorStandUtil.getDestroyPacket(j));
}
}
}

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.totem;
package net.momirealms.customfishing.fishing.totem;
public class CorePos {

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.totem;
package net.momirealms.customfishing.fishing.totem;
public class FinalModel {

View File

@@ -16,7 +16,7 @@
*/
package net.momirealms.customfishing.object.totem;
package net.momirealms.customfishing.fishing.totem;
import java.util.Arrays;

View File

@@ -15,11 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.totem;
package net.momirealms.customfishing.fishing.totem;
import net.momirealms.customfishing.fishing.Effect;
import net.momirealms.customfishing.fishing.requirements.RequirementInterface;
import net.momirealms.customfishing.object.action.ActionInterface;
import net.momirealms.customfishing.object.fishing.Bonus;
import net.momirealms.customfishing.object.requirements.RequirementInterface;
import org.bukkit.Particle;
import org.bukkit.potion.PotionEffect;
@@ -31,20 +31,20 @@ public class Totem {
private final int radius;
private final Particle particle;
private final int duration;
private final Bonus bonus;
private final Effect effect;
private ActionInterface[] activatorActions;
private ActionInterface[] nearbyActions;
private double holoOffset;
private String[] holoText;
private PotionEffect[] potionEffects;
public Totem(OriginalModel originalModel, FinalModel finalModel, int radius, int duration, Particle particle, Bonus bonus) {
public Totem(OriginalModel originalModel, FinalModel finalModel, int radius, int duration, Particle particle, Effect effect) {
this.originalModel = originalModel;
this.finalModel = finalModel;
this.radius = radius;
this.duration = duration;
this.particle = particle;
this.bonus = bonus;
this.effect = effect;
}
public RequirementInterface[] getRequirements() {
@@ -80,8 +80,8 @@ public class Totem {
return duration;
}
public Bonus getBonus() {
return bonus;
public Effect getBonus() {
return effect;
}
public ActionInterface[] getActivatorActions() {

View File

@@ -15,11 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.totem;
package net.momirealms.customfishing.fishing.totem;
import net.momirealms.customfishing.fishing.Effect;
import net.momirealms.customfishing.fishing.requirements.RequirementInterface;
import net.momirealms.customfishing.object.action.ActionInterface;
import net.momirealms.customfishing.object.fishing.Bonus;
import net.momirealms.customfishing.object.requirements.RequirementInterface;
import org.bukkit.Particle;
import org.bukkit.potion.PotionEffect;
@@ -31,20 +31,20 @@ public class TotemConfig {
private final int radius;
private final Particle particle;
private final int duration;
private final Bonus bonus;
private final Effect effect;
private ActionInterface[] activatorActions;
private ActionInterface[] nearbyActions;
private double holoOffset;
private String[] holoText;
private PotionEffect[] potionEffects;
public TotemConfig(OriginalModel originalModel, FinalModel finalModel, int radius, int duration, Particle particle, Bonus bonus) {
public TotemConfig(OriginalModel originalModel, FinalModel finalModel, int radius, int duration, Particle particle, Effect effect) {
this.originalModel = originalModel;
this.finalModel = finalModel;
this.radius = radius;
this.duration = duration;
this.particle = particle;
this.bonus = bonus;
this.effect = effect;
}
public RequirementInterface[] getRequirements() {
@@ -80,8 +80,8 @@ public class TotemConfig {
return duration;
}
public Bonus getBonus() {
return bonus;
public Effect getBonus() {
return effect;
}
public ActionInterface[] getActivatorActions() {

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.object.totem;
package net.momirealms.customfishing.fishing.totem;
import org.bukkit.Location;
import org.bukkit.Particle;

View File

@@ -45,7 +45,7 @@ import java.util.Objects;
public final class LibraryLoader {
@SuppressWarnings("Guava")
private static final Supplier<URLClassLoaderAccess> URL_INJECTOR = Suppliers.memoize(() -> URLClassLoaderAccess.create((URLClassLoader) CustomFishing.plugin.getClass().getClassLoader()));
private static final Supplier<URLClassLoaderAccess> URL_INJECTOR = Suppliers.memoize(() -> URLClassLoaderAccess.create((URLClassLoader) CustomFishing.getInstance().getClass().getClassLoader()));
/**
* Resolves all {@link MavenLibrary} annotations on the given object.
@@ -109,7 +109,7 @@ public final class LibraryLoader {
}
private static File getLibFolder(Dependency dependency) {
File pluginDataFolder = CustomFishing.plugin.getDataFolder();
File pluginDataFolder = CustomFishing.getInstance().getDataFolder();
File serverDir = pluginDataFolder.getParentFile().getParentFile();
File helperDir = new File(serverDir, "libraries");

View File

@@ -37,23 +37,23 @@ import java.util.logging.Level;
public final class Log {
public static void info(@NotNull String s) {
CustomFishing.plugin.getLogger().info(s);
CustomFishing.getInstance().getLogger().info(s);
}
public static void warn(@NotNull String s) {
CustomFishing.plugin.getLogger().warning(s);
CustomFishing.getInstance().getLogger().warning(s);
}
public static void severe(@NotNull String s) {
CustomFishing.plugin.getLogger().severe(s);
CustomFishing.getInstance().getLogger().severe(s);
}
public static void warn(@NotNull String s, Throwable t) {
CustomFishing.plugin.getLogger().log(Level.WARNING, s, t);
CustomFishing.getInstance().getLogger().log(Level.WARNING, s, t);
}
public static void severe(@NotNull String s, Throwable t) {
CustomFishing.plugin.getLogger().log(Level.SEVERE, s, t);
CustomFishing.getInstance().getLogger().log(Level.SEVERE, s, t);
}
private Log() {

View File

@@ -1,15 +1,26 @@
package net.momirealms.customfishing.helper;
import org.bukkit.Bukkit;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.VersionChecker;
import net.momirealms.customfishing.CustomFishing;
import java.lang.reflect.Field;
public class VersionHelper {
private boolean isNewerThan1_19_R2;
private String version;
private final CustomFishing plugin;
public VersionHelper(CustomFishing plugin) {
this.plugin = plugin;
isVersionNewerThan1_19_R2();
disableUseLessInfo();
}
public boolean isVersionNewerThan1_19_R2() {
if (version == null) {
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
version = plugin.getServer().getClass().getPackage().getName().split("\\.")[3];
String[] split = version.split("_");
int main_ver = Integer.parseInt(split[1]);
if (main_ver >= 20) isNewerThan1_19_R2 = true;
@@ -18,4 +29,37 @@ public class VersionHelper {
}
return isNewerThan1_19_R2;
}
private void disableUseLessInfo() {
MinecraftVersion.disableBStats();
MinecraftVersion.disableUpdateCheck();
VersionChecker.hideOk = true;
try {
Field field = MinecraftVersion.class.getDeclaredField("version");
field.setAccessible(true);
MinecraftVersion minecraftVersion;
try {
minecraftVersion = MinecraftVersion.valueOf(version.replace("v", "MC"));
} catch (IllegalArgumentException ex) {
minecraftVersion = MinecraftVersion.UNKNOWN;
}
field.set(MinecraftVersion.class, minecraftVersion);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
boolean hasGsonSupport;
try {
Class.forName("com.google.gson.Gson");
hasGsonSupport = true;
} catch (Exception ex) {
hasGsonSupport = false;
}
try {
Field field= MinecraftVersion.class.getDeclaredField("hasGsonSupport");
field.setAccessible(true);
field.set(Boolean.class, hasGsonSupport);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -1,47 +0,0 @@
/*
* 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.integration;
import net.momirealms.customfishing.CustomFishing;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public interface AntiGriefInterface {
boolean canBreak(Location location, Player player);
boolean canPlace(Location location, Player player);
static boolean testBreak(Player player, Location location) {
for (AntiGriefInterface antiGrief : CustomFishing.plugin.getIntegrationManager().getAntiGriefs()) {
if(!antiGrief.canBreak(location, player)) {
return false;
}
}
return true;
}
static boolean testPlace(Player player, Location location) {
for (AntiGriefInterface antiGrief : CustomFishing.plugin.getIntegrationManager().getAntiGriefs()) {
if(!antiGrief.canPlace(location, player)) {
return false;
}
}
return true;
}
}

View File

@@ -17,7 +17,7 @@
package net.momirealms.customfishing.integration;
import net.momirealms.customfishing.object.loot.Mob;
import net.momirealms.customfishing.fishing.loot.Mob;
import org.bukkit.Location;
public interface MobInterface {

View File

@@ -26,7 +26,7 @@ public class VaultHook {
private Economy economy;
public boolean initialize() {
RegisteredServiceProvider<Economy> rsp = CustomFishing.plugin.getServer().getServicesManager().getRegistration(Economy.class);
RegisteredServiceProvider<Economy> rsp = CustomFishing.getInstance().getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}

View File

@@ -1,45 +0,0 @@
/*
* 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.integration.antigrief;
import net.momirealms.customfishing.integration.AntiGriefInterface;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags;
import java.util.Optional;
public class BentoBoxHook implements AntiGriefInterface {
@Override
public boolean canBreak(Location location, Player player) {
User user = User.getInstance(player);
Optional<Island> islandOptional = BentoBox.getInstance().getIslands().getIslandAt(location);
return islandOptional.map(island -> island.isAllowed(user, Flags.BREAK_BLOCKS)).orElse(true);
}
@Override
public boolean canPlace(Location location, Player player) {
User user = User.getInstance(player);
Optional<Island> islandOptional = BentoBox.getInstance().getIslands().getIslandAt(location);
return islandOptional.map(island -> island.isAllowed(user, Flags.PLACE_BLOCKS)).orElse(true);
}
}

View File

@@ -1,39 +0,0 @@
/*
* 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.integration.antigrief;
import net.crashcraft.crashclaim.api.CrashClaimAPI;
import net.crashcraft.crashclaim.permissions.PermissionRoute;
import net.momirealms.customfishing.integration.AntiGriefInterface;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class CrashClaimHook implements AntiGriefInterface {
@Override
public boolean canBreak(Location location, Player player) {
CrashClaimAPI crashClaimAPI = net.crashcraft.crashclaim.CrashClaim.getPlugin().getApi();
return crashClaimAPI.getPermissionHelper().hasPermission(player.getUniqueId(), location, PermissionRoute.BUILD);
}
@Override
public boolean canPlace(Location location, Player player) {
CrashClaimAPI crashClaimAPI = net.crashcraft.crashclaim.CrashClaim.getPlugin().getApi();
return crashClaimAPI.getPermissionHelper().hasPermission(player.getUniqueId(), location, PermissionRoute.BUILD);
}
}

View File

@@ -1,35 +0,0 @@
/*
* 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.integration.antigrief;
import net.momirealms.customfishing.integration.AntiGriefInterface;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class GriefDefenderHook implements AntiGriefInterface {
@Override
public boolean canBreak(Location location, Player player) {
return com.griefdefender.api.GriefDefender.getCore().getUser(player.getUniqueId()).canBreak(location);
}
@Override
public boolean canPlace(Location location, Player player) {
return com.griefdefender.api.GriefDefender.getCore().getUser(player.getUniqueId()).canPlace(player.getInventory().getItemInMainHand(), location);
}
}

View File

@@ -1,35 +0,0 @@
/*
* 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.integration.antigrief;
import net.momirealms.customfishing.integration.AntiGriefInterface;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class GriefPreventionHook implements AntiGriefInterface {
@Override
public boolean canBreak(Location location, Player player) {
return me.ryanhamshire.GriefPrevention.GriefPrevention.instance.allowBreak(player, location.getBlock(), location) == null;
}
@Override
public boolean canPlace(Location location, Player player) {
return me.ryanhamshire.GriefPrevention.GriefPrevention.instance.allowBuild(player, location) == null;
}
}

View File

@@ -1,53 +0,0 @@
/*
* 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.integration.antigrief;
import net.momirealms.customfishing.integration.AntiGriefInterface;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.kingdoms.constants.group.Kingdom;
import org.kingdoms.constants.land.Land;
import org.kingdoms.constants.player.KingdomPlayer;
public class KingdomsXHook implements AntiGriefInterface {
@Override
public boolean canBreak(Location location, Player player) {
return kingdomsCheck(location, player);
}
@Override
public boolean canPlace(Location location, Player player) {
return kingdomsCheck(location, player);
}
private boolean kingdomsCheck(Location location, Player player) {
Land land = Land.getLand(location);
if (land == null) return true;
if (land.isClaimed()) {
KingdomPlayer kp = KingdomPlayer.getKingdomPlayer(player);
Kingdom cropKingdom = land.getKingdom();
if (kp.getKingdom() != null) {
Kingdom kingdom = kp.getKingdom();
return kingdom != cropKingdom;
}
else return false;
}
else return true;
}
}

View File

@@ -1,53 +0,0 @@
/*
* 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.integration.antigrief;
import me.angeschossen.lands.api.LandsIntegration;
import me.angeschossen.lands.api.flags.types.RoleFlag;
import me.angeschossen.lands.api.land.LandWorld;
import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customfishing.integration.AntiGriefInterface;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class LandsHook implements AntiGriefInterface {
private final LandsIntegration api;
public LandsHook() {
api = LandsIntegration.of(CustomCrops.plugin);;
}
@Override
public boolean canBreak(Location location, Player player) {
LandWorld world = api.getWorld(location.getWorld());
if (world != null) {
return world.hasRoleFlag(player.getUniqueId(), location, RoleFlag.of("BLOCK_BREAK"));
}
return true;
}
@Override
public boolean canPlace(Location location, Player player) {
LandWorld world = api.getWorld(location.getWorld());
if (world != null) {
return world.hasRoleFlag(player.getUniqueId(), location, RoleFlag.of("BLOCK_PLACE"));
}
return true;
}
}

View File

@@ -1,42 +0,0 @@
/*
* 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.integration.antigrief;
import com.plotsquared.core.location.Location;
import net.momirealms.customfishing.integration.AntiGriefInterface;
import org.bukkit.entity.Player;
public class PlotSquaredHook implements AntiGriefInterface {
@Override
public boolean canBreak(org.bukkit.Location location, Player player) {
return isAllowed(location, player);
}
@Override
public boolean canPlace(org.bukkit.Location location, Player player) {
return isAllowed(location, player);
}
private boolean isAllowed(org.bukkit.Location location, Player player) {
Location plotLoc = Location.at(location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
if (plotLoc.isPlotRoad()) return false;
if (plotLoc.getPlotArea() != null) return plotLoc.getPlotArea().getPlot(plotLoc).isAdded(player.getUniqueId());
else return true;
}
}

View File

@@ -1,48 +0,0 @@
/*
* 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.integration.antigrief;
import com.bekvon.bukkit.residence.containers.Flags;
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
import com.bekvon.bukkit.residence.protection.ResidencePermissions;
import net.momirealms.customfishing.integration.AntiGriefInterface;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class ResidenceHook implements AntiGriefInterface {
@Override
public boolean canBreak(Location location, Player player) {
ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location);
if(res!=null){
ResidencePermissions perms = res.getPermissions();
return perms.playerHas(player, Flags.destroy, true);
}
return true;
}
@Override
public boolean canPlace(Location location, Player player) {
ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location);
if(res!=null){
ResidencePermissions perms = res.getPermissions();
return perms.playerHas(player, Flags.build, true);
}
return true;
}
}

View File

@@ -1,41 +0,0 @@
/*
* 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.integration.antigrief;
import com.palmergames.bukkit.towny.object.TownyPermission;
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
import net.momirealms.customfishing.integration.AntiGriefInterface;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class TownyHook implements AntiGriefInterface {
@Override
public boolean canBreak(Location location, Player player) {
return TownyPermission(player, location, TownyPermission.ActionType.DESTROY);
}
@Override
public boolean canPlace(Location location, Player player) {
return TownyPermission(player, location, TownyPermission.ActionType.BUILD);
}
private boolean TownyPermission(Player player, Location location, TownyPermission.ActionType actionType){
return PlayerCacheUtil.getCachePermission(player, location, location.getBlock().getType(), actionType);
}
}

View File

@@ -1,68 +0,0 @@
/*
* 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.integration.antigrief;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import net.momirealms.customfishing.integration.AntiGriefInterface;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class WorldGuardHook implements AntiGriefInterface {
@Override
public boolean canPlace(Location location, Player player) {
if (player.isOp()) return true;
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
World world = BukkitAdapter.adapt(location.getWorld());
WorldGuardPlatform platform = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform();
if (hasRegion(world, BukkitAdapter.asBlockVector(location))){
RegionQuery query = platform.getRegionContainer().createQuery();
return query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.BUILD);
}
else return true;
}
@Override
public boolean canBreak(Location location, Player player) {
if (player.isOp()) return true;
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
World world = BukkitAdapter.adapt(location.getWorld());
WorldGuardPlatform platform = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform();
if (hasRegion(world, BukkitAdapter.asBlockVector(location))){
RegionQuery query = platform.getRegionContainer().createQuery();
return query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.BLOCK_BREAK);
}
else return true;
}
private boolean hasRegion(World world, BlockVector3 vector){
RegionContainer container = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionManager regionManager = container.get(world);
if (regionManager == null) return true;
return regionManager.getApplicableRegions(vector).size() > 0;
}
}

View File

@@ -18,8 +18,8 @@
package net.momirealms.customfishing.integration.block;
import dev.lone.itemsadder.api.CustomBlock;
import net.momirealms.customfishing.CustomFishing;
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;
@@ -40,9 +40,9 @@ public class ItemsAdderBlockImpl implements BlockInterface {
@Override
public void placeBlock(String id, Location location) {
String blockID = TotemManager.INVERTED.get(id);
String blockID = CustomFishing.getInstance().getTotemManager().getInvertedBlock(id);
if (blockID == null) {
AdventureUtil.consoleMessage(id + " does not exist in totem-blocks.yml");
AdventureUtil.consoleMessage(id + " does not exist in default.yml");
return;
}
if (BlockInterface.isVanillaItem(blockID)) {
@@ -64,6 +64,6 @@ public class ItemsAdderBlockImpl implements BlockInterface {
else {
id = customBlock.getNamespacedID();
}
return TotemManager.BLOCKS.get(id);
return CustomFishing.getInstance().getTotemManager().getBlockID(id);
}
}

View File

@@ -20,8 +20,8 @@ package net.momirealms.customfishing.integration.block;
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.CustomFishing;
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;
@@ -37,9 +37,9 @@ public class OraxenBlockImpl implements BlockInterface {
@Override
public void placeBlock(String id, Location location) {
String blockID = TotemManager.INVERTED.get(id);
String blockID = CustomFishing.getInstance().getTotemManager().getInvertedBlock(id);
if (blockID == null) {
AdventureUtil.consoleMessage(id + " does not exist in totem-blocks.yml");
AdventureUtil.consoleMessage(id + " does not exist in default.yml");
return;
}
if (BlockInterface.isVanillaItem(blockID)) {
@@ -66,6 +66,6 @@ public class OraxenBlockImpl implements BlockInterface {
else {
id = mechanic.getItemID();
}
return TotemManager.BLOCKS.get(id);
return CustomFishing.getInstance().getTotemManager().getBlockID(id);
}
}

View File

@@ -17,8 +17,8 @@
package net.momirealms.customfishing.integration.block;
import net.momirealms.customfishing.CustomFishing;
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;
@@ -33,9 +33,9 @@ public class VanillaBlockImpl implements BlockInterface {
@Override
public void placeBlock(String id, Location location) {
String blockID = TotemManager.INVERTED.get(id);
String blockID = CustomFishing.getInstance().getTotemManager().getInvertedBlock(id);
if (blockID == null) {
AdventureUtil.consoleMessage(id + " does not exist in totem-blocks.yml");
AdventureUtil.consoleMessage(id + " does not exist in default.yml");
return;
}
BlockInterface.placeVanillaBlock(blockID, location);
@@ -44,7 +44,7 @@ public class VanillaBlockImpl implements BlockInterface {
@Nullable
@Override
public String getID(Block block) {
return TotemManager.BLOCKS.get(block.getType().name());
return CustomFishing.getInstance().getTotemManager().getBlockID(block.getType().name());
}
@Override

View File

@@ -17,8 +17,8 @@
package net.momirealms.customfishing.integration.item;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.integration.ItemInterface;
import net.momirealms.customfishing.manager.LootManager;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -27,11 +27,17 @@ import org.jetbrains.annotations.Nullable;
public class CustomFishingItemImpl implements ItemInterface {
private final CustomFishing plugin;
public CustomFishingItemImpl(CustomFishing plugin) {
this.plugin = plugin;
}
@Override
@Nullable
public ItemStack build(String material) {
if (material.contains(":")) return null;
return LootManager.build(material);
return plugin.getLootManager().build(material);
}
@Override

View File

@@ -21,7 +21,6 @@ import com.willfp.eco.core.items.CustomItem;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.manager.BonusManager;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
@@ -31,9 +30,9 @@ public class EcoItemRegister {
public static void registerItems() {
// Rods
for (Map.Entry<String, ItemStack> entry : BonusManager.RODITEMS.entrySet()) {
for (Map.Entry<String, ItemStack> entry : CustomFishing.getInstance().getEffectManager().getRodItems().entrySet()) {
new CustomItem(
new NamespacedKey(CustomFishing.plugin, "rod_" + entry.getKey()),
new NamespacedKey(CustomFishing.getInstance(), "rod_" + entry.getKey()),
itemStack -> {
try {
NBTItem nbtItem = new NBTItem(itemStack);
@@ -49,9 +48,9 @@ public class EcoItemRegister {
).register();
}
// Baits
for (Map.Entry<String, ItemStack> entry : BonusManager.BAITITEMS.entrySet()) {
for (Map.Entry<String, ItemStack> entry : CustomFishing.getInstance().getEffectManager().getBaitItems().entrySet()) {
new CustomItem(
new NamespacedKey(CustomFishing.plugin, "bait_" + entry.getKey()),
new NamespacedKey(CustomFishing.getInstance(), "bait_" + entry.getKey()),
itemStack -> {
try {
NBTItem nbtItem = new NBTItem(itemStack);
@@ -67,9 +66,9 @@ public class EcoItemRegister {
).register();
}
// Utils
for (Map.Entry<String, ItemStack> entry : BonusManager.UTILITEMS.entrySet()) {
for (Map.Entry<String, ItemStack> entry : CustomFishing.getInstance().getEffectManager().getUtilItems().entrySet()) {
new CustomItem(
new NamespacedKey(CustomFishing.plugin, "util_" + entry.getKey()),
new NamespacedKey(CustomFishing.getInstance(), "util_" + entry.getKey()),
itemStack -> {
try {
NBTItem nbtItem = new NBTItem(itemStack);

Some files were not shown because too many files have changed in this diff Show More