mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-29 03:49:07 +00:00
1.1.0
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -26,10 +26,11 @@ import net.momirealms.customfishing.competition.bossbar.BossBarManager;
|
||||
import net.momirealms.customfishing.helper.LibraryLoader;
|
||||
import net.momirealms.customfishing.hook.Placeholders;
|
||||
import net.momirealms.customfishing.listener.MMOItemsConverter;
|
||||
import net.momirealms.customfishing.listener.PapiReload;
|
||||
import net.momirealms.customfishing.listener.PlayerListener;
|
||||
import net.momirealms.customfishing.utils.AdventureManager;
|
||||
import net.momirealms.customfishing.utils.UpdateConfig;
|
||||
import net.momirealms.customfishing.listener.PapiUnregister;
|
||||
import net.momirealms.customfishing.listener.PickUpListener;
|
||||
import net.momirealms.customfishing.listener.FishListener;
|
||||
import net.momirealms.customfishing.utils.AdventureUtil;
|
||||
import net.momirealms.customfishing.utils.ConfigUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -57,34 +58,46 @@ public final class CustomFishing extends JavaPlugin {
|
||||
miniMessage = MiniMessage.miniMessage();
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("customfishing")).setExecutor(new Execute());
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("customfishing")).setTabCompleter(new TabComplete());
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerListener(),this);
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>Running on " + Bukkit.getVersion());
|
||||
Bukkit.getPluginManager().registerEvents(new FishListener(),this);
|
||||
|
||||
ConfigReader.Reload();
|
||||
if (ConfigReader.Config.competition){
|
||||
competitionSchedule = new CompetitionSchedule();
|
||||
competitionSchedule.checkTime();
|
||||
Bukkit.getPluginManager().registerEvents(new BossBarManager(), this);
|
||||
}
|
||||
if (ConfigReader.Config.convertMMOItems){
|
||||
Bukkit.getPluginManager().registerEvents(new MMOItemsConverter(), this);
|
||||
}
|
||||
if (ConfigReader.Config.papi){
|
||||
placeholders = new Placeholders();
|
||||
placeholders.register();
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#00BFFF>PlaceholderAPI <color:#E1FFFF>Hooked!");
|
||||
Bukkit.getPluginManager().registerEvents(new PapiReload(), this);
|
||||
}
|
||||
ConfigReader.tryEnableJedis();
|
||||
if (!Objects.equals(ConfigReader.Config.version, "3")){
|
||||
UpdateConfig.update();
|
||||
}
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>Plugin Enabled!");
|
||||
AdventureUtil.consoleMessage("[CustomFishing] Running on <white>" + Bukkit.getVersion());
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, ()-> {
|
||||
ConfigReader.Reload();
|
||||
if (ConfigReader.Config.competition){
|
||||
competitionSchedule = new CompetitionSchedule();
|
||||
competitionSchedule.checkTime();
|
||||
Bukkit.getScheduler().runTask(this, () -> {
|
||||
Bukkit.getPluginManager().registerEvents(new BossBarManager(), this);
|
||||
});
|
||||
}
|
||||
if (ConfigReader.Config.convertMMOItems){
|
||||
Bukkit.getScheduler().runTask(this, () -> {
|
||||
Bukkit.getPluginManager().registerEvents(new MMOItemsConverter(), this);
|
||||
});
|
||||
}
|
||||
if (ConfigReader.Config.papi){
|
||||
placeholders = new Placeholders();
|
||||
Bukkit.getScheduler().runTask(this, () -> {
|
||||
placeholders.register();
|
||||
Bukkit.getPluginManager().registerEvents(new PapiUnregister(), this);
|
||||
});
|
||||
}
|
||||
ConfigReader.tryEnableJedis();
|
||||
if (!Objects.equals(ConfigReader.Config.version, "5")){
|
||||
ConfigUtil.update();
|
||||
}
|
||||
if (ConfigReader.Config.preventPick){
|
||||
Bukkit.getScheduler().runTask(this, () -> {
|
||||
Bukkit.getPluginManager().registerEvents(new PickUpListener(),this);
|
||||
});
|
||||
}
|
||||
AdventureUtil.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>Plugin Enabled!");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
if (competitionSchedule != null){
|
||||
competitionSchedule.stopCheck();
|
||||
competitionSchedule = null;
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
package net.momirealms.customfishing.command;
|
||||
|
||||
import net.momirealms.customfishing.competition.CompetitionSchedule;
|
||||
import net.momirealms.customfishing.item.*;
|
||||
import net.momirealms.customfishing.utils.AdventureManager;
|
||||
import net.momirealms.customfishing.utils.AdventureUtil;
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import net.momirealms.customfishing.utils.SaveItem;
|
||||
import net.momirealms.customfishing.utils.ItemUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Execute implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean onCommand(CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
|
||||
if (!(sender.hasPermission("customfishing.admin") || sender.isOp())) {
|
||||
AdventureManager.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.noPerm);
|
||||
AdventureUtil.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.noPerm);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,23 +29,23 @@ public class Execute implements CommandExecutor {
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
ConfigReader.Reload();
|
||||
if (sender instanceof Player){
|
||||
AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.reload);
|
||||
AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.reload);
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.reload);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.reload);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("export")) {
|
||||
if (args[0].equalsIgnoreCase("import")) {
|
||||
if (args.length < 2){
|
||||
lackArgs(sender);
|
||||
return true;
|
||||
}
|
||||
if (sender instanceof Player player){
|
||||
SaveItem.saveToFile(player.getInventory().getItemInMainHand(), args[1]);
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + "Done!");
|
||||
ItemUtil.saveToFile(player.getInventory().getItemInMainHand(), args[1]);
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + "Done! File is saved to /CustomFishing/loots/" + args[1] + ".yml");
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -88,23 +86,23 @@ public class Execute implements CommandExecutor {
|
||||
//检验参数长度 [0]items [1]loot [2]get [3]xxx [4](amount)
|
||||
if (sender instanceof Player player){
|
||||
//是否存在于缓存中
|
||||
if (!ConfigReader.LOOTITEM.containsKey(args[3])){
|
||||
if (!ConfigReader.LootItem.containsKey(args[3])){
|
||||
noItem(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 4){
|
||||
ItemGive.givePlayerLoot(player, args[3], 1);
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3]));
|
||||
ItemUtil.givePlayerLoot(player, args[3], 1);
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3]));
|
||||
}else {
|
||||
if (Integer.parseInt(args[4]) < 1){
|
||||
wrongAmount(sender);
|
||||
return true;
|
||||
}
|
||||
ItemGive.givePlayerLoot(player, args[3], Integer.parseInt(args[4]));
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3]));
|
||||
ItemUtil.givePlayerLoot(player, args[3], Integer.parseInt(args[4]));
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3]));
|
||||
}
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -121,19 +119,19 @@ public class Execute implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
//是否存在于缓存中
|
||||
if (!ConfigReader.LOOTITEM.containsKey(args[4])){
|
||||
if (!ConfigReader.LootItem.containsKey(args[4])){
|
||||
noItem(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 5){
|
||||
ItemGive.givePlayerLoot(player, args[4], 1);
|
||||
ItemUtil.givePlayerLoot(player, args[4], 1);
|
||||
giveItem(sender, args[3], args[4], 1);
|
||||
}else {
|
||||
if (Integer.parseInt(args[5]) < 1){
|
||||
wrongAmount(sender);
|
||||
return true;
|
||||
}
|
||||
ItemGive.givePlayerLoot(player, args[4], Integer.parseInt(args[5]));
|
||||
ItemUtil.givePlayerLoot(player, args[4], Integer.parseInt(args[5]));
|
||||
giveItem(sender, args[3], args[4], Integer.parseInt(args[5]));
|
||||
}
|
||||
return true;
|
||||
@@ -147,23 +145,23 @@ public class Execute implements CommandExecutor {
|
||||
//检验参数长度 [0]items [1]util [2]get [3]xxx [4](amount)
|
||||
if (sender instanceof Player player){
|
||||
//是否存在于缓存中
|
||||
if (!ConfigReader.UTIL.containsKey(args[3])){
|
||||
if (!ConfigReader.UtilItem.containsKey(args[3])){
|
||||
noItem(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 4){
|
||||
ItemGive.givePlayerUtil(player, args[3], 1);
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3]));
|
||||
ItemUtil.givePlayerUtil(player, args[3], 1);
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3]));
|
||||
}else {
|
||||
if (Integer.parseInt(args[4]) < 1){
|
||||
wrongAmount(sender);
|
||||
return true;
|
||||
}
|
||||
ItemGive.givePlayerUtil(player, args[3], Integer.parseInt(args[4]));
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3]));
|
||||
ItemUtil.givePlayerUtil(player, args[3], Integer.parseInt(args[4]));
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3]));
|
||||
}
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -180,19 +178,19 @@ public class Execute implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
//是否存在于缓存中
|
||||
if (!ConfigReader.UTIL.containsKey(args[4])){
|
||||
if (!ConfigReader.UtilItem.containsKey(args[4])){
|
||||
noItem(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 5){
|
||||
ItemGive.givePlayerUtil(player, args[4], 1);
|
||||
ItemUtil.givePlayerUtil(player, args[4], 1);
|
||||
giveItem(sender, args[3], args[4], 1);
|
||||
}else {
|
||||
if (Integer.parseInt(args[5]) < 1){
|
||||
wrongAmount(sender);
|
||||
return true;
|
||||
}
|
||||
ItemGive.givePlayerUtil(player, args[4], Integer.parseInt(args[5]));
|
||||
ItemUtil.givePlayerUtil(player, args[4], Integer.parseInt(args[5]));
|
||||
giveItem(sender, args[3], args[4], Integer.parseInt(args[5]));
|
||||
}
|
||||
return true;
|
||||
@@ -203,23 +201,23 @@ public class Execute implements CommandExecutor {
|
||||
//检验参数长度 [0]items [1]rod [2]get [3]xxx [4](amount)
|
||||
if (sender instanceof Player player){
|
||||
//是否存在于缓存中
|
||||
if (!ConfigReader.ROD.containsKey(args[3])){
|
||||
if (!ConfigReader.RodItem.containsKey(args[3])){
|
||||
noItem(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 4){
|
||||
ItemGive.givePlayerRod(player, args[3], 1);
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3]));
|
||||
ItemUtil.givePlayerRod(player, args[3], 1);
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3]));
|
||||
}else {
|
||||
if (Integer.parseInt(args[4]) < 1){
|
||||
wrongAmount(sender);
|
||||
return true;
|
||||
}
|
||||
ItemGive.givePlayerRod(player, args[3], Integer.parseInt(args[4]));
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3]));
|
||||
ItemUtil.givePlayerRod(player, args[3], Integer.parseInt(args[4]));
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3]));
|
||||
}
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -236,19 +234,19 @@ public class Execute implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
//是否存在于缓存中
|
||||
if (!ConfigReader.ROD.containsKey(args[4])){
|
||||
if (!ConfigReader.RodItem.containsKey(args[4])){
|
||||
noItem(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 5){
|
||||
ItemGive.givePlayerRod(player, args[4], 1);
|
||||
ItemUtil.givePlayerRod(player, args[4], 1);
|
||||
giveItem(sender, args[3], args[4], 1);
|
||||
}else {
|
||||
if (Integer.parseInt(args[5]) < 1){
|
||||
wrongAmount(sender);
|
||||
return true;
|
||||
}
|
||||
ItemGive.givePlayerRod(player, args[4], Integer.parseInt(args[5]));
|
||||
ItemUtil.givePlayerRod(player, args[4], Integer.parseInt(args[5]));
|
||||
giveItem(sender, args[3], args[4], Integer.parseInt(args[5]));
|
||||
}
|
||||
return true;
|
||||
@@ -259,23 +257,23 @@ public class Execute implements CommandExecutor {
|
||||
//检验参数长度 [0]items [1]bait [2]get [3]xxx [4](amount)
|
||||
if (sender instanceof Player player){
|
||||
//是否存在于缓存中
|
||||
if (!ConfigReader.BAIT.containsKey(args[3])){
|
||||
if (!ConfigReader.BaitItem.containsKey(args[3])){
|
||||
noItem(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 4){
|
||||
ItemGive.givePlayerBait(player, args[3], 1);
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3]));
|
||||
ItemUtil.givePlayerBait(player, args[3], 1);
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3]));
|
||||
}else {
|
||||
if (Integer.parseInt(args[4]) < 1){
|
||||
wrongAmount(sender);
|
||||
return true;
|
||||
}
|
||||
ItemGive.givePlayerBait(player, args[3], Integer.parseInt(args[4]));
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3]));
|
||||
ItemUtil.givePlayerBait(player, args[3], Integer.parseInt(args[4]));
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3]));
|
||||
}
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -292,19 +290,19 @@ public class Execute implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
//是否存在于缓存中
|
||||
if (!ConfigReader.BAIT.containsKey(args[4])){
|
||||
if (!ConfigReader.BaitItem.containsKey(args[4])){
|
||||
noItem(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 5){
|
||||
ItemGive.givePlayerBait(player, args[4], 1);
|
||||
ItemUtil.givePlayerBait(player, args[4], 1);
|
||||
giveItem(sender, args[3], args[4], 1);
|
||||
}else {
|
||||
if (Integer.parseInt(args[5]) < 1){
|
||||
wrongAmount(sender);
|
||||
return true;
|
||||
}
|
||||
ItemGive.givePlayerBait(player, args[4], Integer.parseInt(args[5]));
|
||||
ItemUtil.givePlayerBait(player, args[4], Integer.parseInt(args[5]));
|
||||
giveItem(sender, args[3], args[4], Integer.parseInt(args[5]));
|
||||
}
|
||||
return true;
|
||||
@@ -316,74 +314,74 @@ public class Execute implements CommandExecutor {
|
||||
|
||||
private void lackArgs(CommandSender sender){
|
||||
if (sender instanceof Player){
|
||||
AdventureManager.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.lackArgs);
|
||||
AdventureUtil.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.lackArgs);
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.lackArgs);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.lackArgs);
|
||||
}
|
||||
}
|
||||
|
||||
private void notOnline(CommandSender sender){
|
||||
if (sender instanceof Player){
|
||||
AdventureManager.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.notOnline);
|
||||
AdventureUtil.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.notOnline);
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.notOnline);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.notOnline);
|
||||
}
|
||||
}
|
||||
|
||||
private void noItem(CommandSender sender){
|
||||
if (sender instanceof Player){
|
||||
AdventureManager.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.notExist);
|
||||
AdventureUtil.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.notExist);
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.notExist);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.notExist);
|
||||
}
|
||||
}
|
||||
|
||||
private void giveItem(CommandSender sender, String name, String item, int amount){
|
||||
String string = ConfigReader.Message.prefix + ConfigReader.Message.giveItem.replace("{Amount}", String.valueOf(amount)).replace("{Player}",name).replace("{Item}",item);
|
||||
if (sender instanceof Player){
|
||||
AdventureManager.playerMessage((Player) sender, string);
|
||||
AdventureUtil.playerMessage((Player) sender, string);
|
||||
}else {
|
||||
AdventureManager.consoleMessage(string);
|
||||
AdventureUtil.consoleMessage(string);
|
||||
}
|
||||
}
|
||||
|
||||
private void wrongAmount(CommandSender sender){
|
||||
if (sender instanceof Player){
|
||||
AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.wrongAmount);
|
||||
AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.wrongAmount);
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.wrongAmount);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.wrongAmount);
|
||||
}
|
||||
}
|
||||
|
||||
private void forceSuccess(CommandSender sender){
|
||||
if (sender instanceof Player){
|
||||
AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceSuccess);
|
||||
AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceSuccess);
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceSuccess);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
private void forceFailure(CommandSender sender){
|
||||
if (sender instanceof Player){
|
||||
AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceFailure);
|
||||
AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceFailure);
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceFailure);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceFailure);
|
||||
}
|
||||
}
|
||||
|
||||
private void forceEnd(CommandSender sender){
|
||||
if (sender instanceof Player){
|
||||
AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceEnd);
|
||||
AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceEnd);
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceEnd);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceEnd);
|
||||
}
|
||||
}
|
||||
|
||||
private void forceCancel(CommandSender sender){
|
||||
if (sender instanceof Player){
|
||||
AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceCancel);
|
||||
AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceCancel);
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceCancel);
|
||||
AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceCancel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,23 +5,22 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class TabComplete implements TabCompleter {
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
public List<String> onTabComplete(CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
|
||||
if (!(sender.hasPermission("customfishing.admin") || sender.isOp())) {
|
||||
return null;
|
||||
}
|
||||
if (args.length == 1){
|
||||
List<String> arrayList = new ArrayList<>();
|
||||
for (String cmd : Arrays.asList("competition","reload","items","export")) {
|
||||
for (String cmd : Arrays.asList("competition","reload", "items","import")) {
|
||||
if (cmd.startsWith(args[0]))
|
||||
arrayList.add(cmd);
|
||||
}
|
||||
@@ -36,7 +35,7 @@ public class TabComplete implements TabCompleter {
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("export")){
|
||||
if (args[0].equalsIgnoreCase("import")){
|
||||
return List.of("FileName");
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("competition")){
|
||||
@@ -229,18 +228,18 @@ public class TabComplete implements TabCompleter {
|
||||
}
|
||||
|
||||
private List<String> loots(){
|
||||
return new ArrayList<>(ConfigReader.LOOTITEM.keySet());
|
||||
return new ArrayList<>(ConfigReader.LootItem.keySet());
|
||||
}
|
||||
private List<String> utils(){
|
||||
return new ArrayList<>(ConfigReader.UTIL.keySet());
|
||||
return new ArrayList<>(ConfigReader.UtilItem.keySet());
|
||||
}
|
||||
private List<String> rods() {
|
||||
return new ArrayList<>(ConfigReader.ROD.keySet());
|
||||
return new ArrayList<>(ConfigReader.RodItem.keySet());
|
||||
}
|
||||
private List<String> baits() {
|
||||
return new ArrayList<>(ConfigReader.BAIT.keySet());
|
||||
return new ArrayList<>(ConfigReader.BaitItem.keySet());
|
||||
}
|
||||
private List<String> competitions() {
|
||||
return new ArrayList<>(ConfigReader.CompetitionsCommand.keySet());
|
||||
return new ArrayList<>(ConfigReader.CompetitionsC.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,8 @@ import net.momirealms.customfishing.competition.bossbar.BossBarManager;
|
||||
import net.momirealms.customfishing.competition.ranking.Ranking;
|
||||
import net.momirealms.customfishing.competition.ranking.RankingImpl;
|
||||
import net.momirealms.customfishing.competition.ranking.RedisRankingImpl;
|
||||
import net.momirealms.customfishing.competition.reward.Reward;
|
||||
import net.momirealms.customfishing.utils.AdventureManager;
|
||||
import net.momirealms.customfishing.utils.JedisUtil;
|
||||
import net.momirealms.customfishing.object.action.ActionB;
|
||||
import net.momirealms.customfishing.utils.AdventureUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@@ -50,7 +49,7 @@ public class Competition {
|
||||
private final List<String> endCommand;
|
||||
private final List<String> startCommand;
|
||||
private final List<String> joinCommand;
|
||||
private final HashMap<String, List<Reward>> rewardsMap;
|
||||
private final HashMap<String, List<ActionB>> rewardsMap;
|
||||
|
||||
public static long remainingTime;
|
||||
public static float progress;
|
||||
@@ -79,7 +78,7 @@ public class Competition {
|
||||
Collection<? extends Player> playerCollections = Bukkit.getOnlinePlayers();
|
||||
if (playerCollections.size() >= minPlayers || forceStart) {
|
||||
status = true;
|
||||
if (JedisUtil.useRedis){
|
||||
if (ConfigReader.useRedis){
|
||||
ranking = new RedisRankingImpl();
|
||||
}else {
|
||||
ranking = new RankingImpl();
|
||||
@@ -88,7 +87,7 @@ public class Competition {
|
||||
if (startMessage != null){
|
||||
playerCollections.forEach(player -> {
|
||||
startMessage.forEach(message -> {
|
||||
AdventureManager.playerMessage(player, message);
|
||||
AdventureUtil.playerMessage(player, message);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -100,7 +99,7 @@ public class Competition {
|
||||
}
|
||||
else {
|
||||
playerCollections.forEach(player -> {
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.notEnoughPlayers);
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.notEnoughPlayers);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -155,7 +154,7 @@ public class Competition {
|
||||
});
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
newMessage.forEach(message -> {
|
||||
AdventureManager.playerMessage(player, message);
|
||||
AdventureUtil.playerMessage(player, message);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -178,20 +177,20 @@ public class Competition {
|
||||
String playerName = iterator.next();
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
if (player != null){
|
||||
for (Reward reward : rewardsMap.get(String.valueOf(i))) {
|
||||
reward.giveReward(player);
|
||||
for (ActionB action : rewardsMap.get(String.valueOf(i))) {
|
||||
action.doOn(player);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
List<Reward> rewards = rewardsMap.get("participation");
|
||||
if (rewards != null) {
|
||||
List<ActionB> actions = rewardsMap.get("participation");
|
||||
if (actions != null) {
|
||||
iterator.forEachRemaining(playerName -> {
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
if (player != null){
|
||||
for (Reward reward : rewards) {
|
||||
reward.giveReward(player);
|
||||
for (ActionB action : actions) {
|
||||
action.doOn(player);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -213,7 +212,6 @@ public class Competition {
|
||||
|
||||
public void refreshRanking(String player, float score) {
|
||||
if (this.goal != Goal.TOTAL_SCORE) score = 1.0f;
|
||||
if (score == 0) return;
|
||||
ranking.refreshData(player, score);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
package net.momirealms.customfishing.competition;
|
||||
|
||||
import net.momirealms.customfishing.competition.bossbar.BossBarConfig;
|
||||
import net.momirealms.customfishing.competition.reward.Reward;
|
||||
import net.momirealms.customfishing.object.action.ActionB;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -35,7 +35,7 @@ public class CompetitionConfig {
|
||||
private Goal goal;
|
||||
private BossBarConfig bossBarConfig;
|
||||
private final boolean enableBossBar;
|
||||
private HashMap<String, List<Reward>> rewards;
|
||||
private HashMap<String, List<ActionB>> rewards;
|
||||
|
||||
public CompetitionConfig(boolean enableBossBar){this.enableBossBar = enableBossBar;}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class CompetitionConfig {
|
||||
public void setEndCommand(List<String> endCommand) {this.endCommand = endCommand;}
|
||||
public void setJoinCommand(List<String> joinCommand) {this.joinCommand = joinCommand;}
|
||||
public void setMinPlayers(int minPlayers) {this.minPlayers = minPlayers;}
|
||||
public HashMap<String, List<Reward>> getRewards() {return rewards;}
|
||||
public HashMap<String, List<ActionB>> getRewards() {return rewards;}
|
||||
|
||||
public Goal getGoal() {return goal;}
|
||||
public int getMinPlayers() {return minPlayers;}
|
||||
@@ -57,7 +57,7 @@ public class CompetitionConfig {
|
||||
public boolean isEnableBossBar() {return enableBossBar;}
|
||||
public List<String> getEndMessage() {return endMessage;}
|
||||
public List<String> getStartMessage() {return startMessage;}
|
||||
public void setRewards(HashMap<String, List<Reward>> rewards) {this.rewards = rewards;}
|
||||
public void setRewards(HashMap<String, List<ActionB>> rewards) {this.rewards = rewards;}
|
||||
public List<String> getEndCommand() {return endCommand;}
|
||||
public List<String> getJoinCommand() {return joinCommand;}
|
||||
public List<String> getStartCommand() {return startCommand;}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class CompetitionSchedule {
|
||||
}
|
||||
|
||||
public static boolean startCompetition(String competitionName){
|
||||
CompetitionConfig competitionConfig = ConfigReader.CompetitionsCommand.get(competitionName);
|
||||
CompetitionConfig competitionConfig = ConfigReader.CompetitionsC.get(competitionName);
|
||||
if (competitionConfig == null) return false;
|
||||
if (competition != null && competition.isGoingOn()){
|
||||
competition.end();
|
||||
@@ -73,7 +73,7 @@ public class CompetitionSchedule {
|
||||
BukkitTask checkTimeTask = new BukkitRunnable(){
|
||||
public void run(){
|
||||
if (isANewMinute()){
|
||||
CompetitionConfig competitionConfig = ConfigReader.Competitions.get(getCurrentTime());
|
||||
CompetitionConfig competitionConfig = ConfigReader.CompetitionsT.get(getCurrentTime());
|
||||
if (competitionConfig != null){
|
||||
startCompetition(competitionConfig);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package net.momirealms.customfishing.competition.bossbar;
|
||||
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import net.momirealms.customfishing.competition.CompetitionSchedule;
|
||||
import net.momirealms.customfishing.utils.AdventureManager;
|
||||
import net.momirealms.customfishing.utils.AdventureUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -41,7 +41,7 @@ public class BossBarManager implements Listener {
|
||||
BossBarTimer timerTask = new BossBarTimer(player, CompetitionSchedule.competition.getBossBarConfig());
|
||||
cache.put(player, timerTask);
|
||||
}else {
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.competitionOn);
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.competitionOn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +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.competition.reward;
|
||||
|
||||
import net.momirealms.customfishing.utils.AdventureManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MessageImpl implements Reward{
|
||||
|
||||
private final List<String> messages;
|
||||
|
||||
public MessageImpl(List<String> messages){
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveReward(Player player) {
|
||||
if (!player.isOnline()) return;
|
||||
messages.forEach(message -> {
|
||||
AdventureManager.playerMessage(player, message);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,24 +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.competition.reward;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Reward {
|
||||
void giveReward(Player player);
|
||||
}
|
||||
@@ -43,7 +43,6 @@ import java.util.Objects;
|
||||
* Resolves {@link MavenLibrary} annotations for a class, and loads the dependency
|
||||
* into the classloader.
|
||||
*/
|
||||
@NonnullByDefault
|
||||
public final class LibraryLoader {
|
||||
|
||||
@SuppressWarnings("Guava")
|
||||
@@ -119,7 +118,6 @@ public final class LibraryLoader {
|
||||
return jarDir;
|
||||
}
|
||||
|
||||
@NonnullByDefault
|
||||
public static final class Dependency {
|
||||
private final String groupId;
|
||||
private final String artifactId;
|
||||
|
||||
@@ -27,33 +27,32 @@ package net.momirealms.customfishing.helper;
|
||||
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Utility for quickly accessing a logger instance without using {@link Bukkit#getLogger()}
|
||||
*/
|
||||
public final class Log {
|
||||
|
||||
public static void info(@Nonnull String s) {
|
||||
public static void info(@NotNull String s) {
|
||||
CustomFishing.instance.getLogger().info(s);
|
||||
}
|
||||
|
||||
public static void warn(@Nonnull String s) {
|
||||
public static void warn(@NotNull String s) {
|
||||
CustomFishing.instance.getLogger().warning(s);
|
||||
}
|
||||
|
||||
public static void severe(@Nonnull String s) {
|
||||
public static void severe(@NotNull String s) {
|
||||
CustomFishing.instance.getLogger().severe(s);
|
||||
}
|
||||
|
||||
public static void warn(@Nonnull String s, Throwable t) {
|
||||
public static void warn(@NotNull String s, Throwable t) {
|
||||
CustomFishing.instance.getLogger().log(Level.WARNING, s, t);
|
||||
}
|
||||
|
||||
public static void severe(@Nonnull String s, Throwable t) {
|
||||
public static void severe(@NotNull String s, Throwable t) {
|
||||
CustomFishing.instance.getLogger().log(Level.SEVERE, s, t);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,14 +25,14 @@
|
||||
|
||||
package net.momirealms.customfishing.helper;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Annotation to indicate the required libraries for a class.
|
||||
*/
|
||||
@@ -41,7 +41,7 @@ import javax.annotation.Nonnull;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MavenLibraries {
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
MavenLibrary[] value() default {};
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
package net.momirealms.customfishing.helper;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Repeatable;
|
||||
@@ -32,8 +34,6 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Annotation to indicate a required library for a class.
|
||||
*/
|
||||
@@ -48,7 +48,7 @@ public @interface MavenLibrary {
|
||||
*
|
||||
* @return the group id of the library
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
String groupId();
|
||||
|
||||
/**
|
||||
@@ -56,7 +56,7 @@ public @interface MavenLibrary {
|
||||
*
|
||||
* @return the artifact id of the library
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
String artifactId();
|
||||
|
||||
/**
|
||||
@@ -64,7 +64,7 @@ public @interface MavenLibrary {
|
||||
*
|
||||
* @return the version of the library
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
String version();
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ public @interface MavenLibrary {
|
||||
*
|
||||
* @return the repo where the library can be obtained from
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
Repository repo() default @Repository(url = "https://repo1.maven.org/maven2");
|
||||
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* This file is part of helper, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.helper;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Nonnull
|
||||
@Documented
|
||||
@TypeQualifierDefault({
|
||||
ElementType.FIELD,
|
||||
ElementType.METHOD,
|
||||
ElementType.PARAMETER
|
||||
})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface NonnullByDefault {
|
||||
|
||||
}
|
||||
@@ -25,14 +25,13 @@
|
||||
|
||||
package net.momirealms.customfishing.helper;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Represents a maven repository.
|
||||
*/
|
||||
@@ -46,7 +45,7 @@ public @interface Repository {
|
||||
*
|
||||
* @return the base url of the repository
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
String url();
|
||||
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
|
||||
package net.momirealms.customfishing.helper;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Provides access to {@link URLClassLoader}#addURL.
|
||||
*/
|
||||
@@ -63,7 +63,7 @@ public abstract class URLClassLoaderAccess {
|
||||
*
|
||||
* @param url the URL to add
|
||||
*/
|
||||
public abstract void addURL(@Nonnull URL url);
|
||||
public abstract void addURL(@NotNull URL url);
|
||||
|
||||
/**
|
||||
* Accesses using sun.misc.Unsafe, supported on Java 9+.
|
||||
@@ -117,7 +117,7 @@ public abstract class URLClassLoaderAccess {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addURL(@Nonnull URL url) {
|
||||
public void addURL(@NotNull URL url) {
|
||||
this.unopenedURLs.add(url);
|
||||
this.pathURLs.add(url);
|
||||
}
|
||||
@@ -131,7 +131,7 @@ public abstract class URLClassLoaderAccess {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addURL(@Nonnull URL url) {
|
||||
public void addURL(@NotNull URL url) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package net.momirealms.customfishing.hook;
|
||||
|
||||
import net.momirealms.customcrops.api.CustomCropsAPI;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class CustomCropsSeason {
|
||||
|
||||
public static String getSeason(World world){
|
||||
return CustomCropsAPI.getSeason(world.getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.momirealms.customfishing.hook;
|
||||
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemsAdderItem {
|
||||
|
||||
public static ItemStack getItemStack(String namespacedID){
|
||||
return CustomStack.getInstance(namespacedID).getItemStack();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.momirealms.customfishing.hook;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class MMOItemsHook {
|
||||
|
||||
public static ItemStack getItemStack(String name){
|
||||
String[] split = StringUtils.split(name, ":");
|
||||
return MMOItems.plugin.getMMOItem(Type.get(split[0]), split[1]).newBuilder().getItemStack();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.momirealms.customfishing.hook;
|
||||
|
||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class MythicItems {
|
||||
|
||||
public static ItemStack getItemStack(String name){
|
||||
return MythicBukkit.inst().getItemManager().getItemStack(name);
|
||||
}
|
||||
}
|
||||
@@ -24,29 +24,26 @@ import io.lumine.mythic.api.mobs.MythicMob;
|
||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||
import io.lumine.mythic.bukkit.utils.serialize.Position;
|
||||
import io.lumine.mythic.core.mobs.ActiveMob;
|
||||
import net.momirealms.customfishing.item.Loot;
|
||||
import net.momirealms.customfishing.utils.VectorUtil;
|
||||
import net.momirealms.customfishing.object.MobVector;
|
||||
import net.momirealms.customfishing.object.loot.Mob;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class MythicMobsUtils {
|
||||
public class MythicMobsUtil {
|
||||
|
||||
public static void summonMM(Location pLocation, Location bLocation, Loot loot){
|
||||
public static void summonMM(Location pLocation, Location bLocation, Mob mob){
|
||||
MobManager mobManager = MythicBukkit.inst().getMobManager();
|
||||
Optional<MythicMob> mythicMob = mobManager.getMythicMob(loot.getMm());
|
||||
Optional<MythicMob> mythicMob = mobManager.getMythicMob(mob.getMmID());
|
||||
if (mythicMob.isPresent()) {
|
||||
//获取MM怪实例
|
||||
MythicMob theMob = mythicMob.get();
|
||||
//生成MM怪
|
||||
Position position = Position.of(bLocation);
|
||||
AbstractLocation abstractLocation = new AbstractLocation(position);
|
||||
ActiveMob activeMob = theMob.spawn(abstractLocation, loot.getMmLevel());
|
||||
|
||||
VectorUtil vectorUtil = loot.getVectorUtil();
|
||||
Vector vector = pLocation.subtract(bLocation).toVector().multiply((vectorUtil.getHorizontal())-1);
|
||||
vector = vector.setY((vector.getY()+0.2)*vectorUtil.getVertical());
|
||||
ActiveMob activeMob = theMob.spawn(abstractLocation, mob.getMmLevel());
|
||||
MobVector mobVector = mob.getMobVector();
|
||||
Vector vector = pLocation.subtract(bLocation).toVector().multiply((mobVector.getHorizontal())-1);
|
||||
vector = vector.setY((vector.getY()+0.2)*mobVector.getVertical());
|
||||
activeMob.getEntity().setVelocity(new AbstractVector(vector.getX(),vector.getY(),vector.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.momirealms.customfishing.hook;
|
||||
|
||||
import io.th0rgal.oraxen.items.OraxenItems;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class OraxenItem {
|
||||
|
||||
public static ItemStack getItemStack(String namespacedID){
|
||||
return OraxenItems.getItemById(namespacedID).build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.momirealms.customfishing.hook.season;
|
||||
|
||||
import net.momirealms.customcrops.api.CustomCropsAPI;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class CustomCropsSeason implements SeasonInterface{
|
||||
public String getSeason(World world){
|
||||
return CustomCropsAPI.getSeason(world.getName());
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.momirealms.customfishing.hook;
|
||||
package net.momirealms.customfishing.hook.season;
|
||||
|
||||
import me.casperge.realisticseasons.api.SeasonsAPI;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class RealisticSeason {
|
||||
public static String getSeason(World world){
|
||||
public class RealisticSeason implements SeasonInterface{
|
||||
public String getSeason(World world){
|
||||
SeasonsAPI seasonsapi = SeasonsAPI.getInstance();
|
||||
switch (seasonsapi.getSeason(world)){
|
||||
case SPRING -> {
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.momirealms.customfishing.hook.season;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
public interface SeasonInterface {
|
||||
String getSeason(World world);
|
||||
}
|
||||
@@ -31,4 +31,9 @@ public class Aurelium implements SkillXP{
|
||||
public void addXp(Player player, double amount) {
|
||||
leveler.addXp(player, skill, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(Player player) {
|
||||
return AureliumAPI.getSkillLevel(player, skill);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,9 @@ public class EcoSkill implements SkillXP{
|
||||
public void addXp(Player player, double amount) {
|
||||
EcoSkillsAPI.getInstance().giveSkillExperience(player, Skills.FISHING, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(Player player) {
|
||||
return EcoSkillsAPI.getInstance().getSkillLevel(player, Skills.FISHING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,9 @@ public class MMOCore implements SkillXP{
|
||||
Profession profession = net.Indyuce.mmocore.MMOCore.plugin.professionManager.get("fishing");
|
||||
profession.giveExperience(net.Indyuce.mmocore.MMOCore.plugin.dataProvider.getDataManager().get(player), amount, null , EXPSource.OTHER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(Player player) {
|
||||
return net.Indyuce.mmocore.MMOCore.plugin.dataProvider.getDataManager().get(player).getLevel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,5 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public interface SkillXP {
|
||||
void addXp(Player player, double amount);
|
||||
int getLevel(Player player);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package net.momirealms.customfishing.hook.skill;
|
||||
|
||||
import com.gmail.nossr50.api.ExperienceAPI;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class mcMMO implements SkillXP{
|
||||
@@ -26,4 +27,9 @@ public class mcMMO implements SkillXP{
|
||||
public void addXp(Player player, double amount) {
|
||||
ExperienceAPI.addRawXP(player, "FISHING", (float) amount, "UNKNOWN");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(Player player) {
|
||||
return ExperienceAPI.getLevel(player, PrimarySkillType.FISHING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +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.item;
|
||||
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Bait implements Item{
|
||||
|
||||
private String name;
|
||||
private List<String> lore;
|
||||
private Map<String,Object> nbt;
|
||||
private HashMap<String, Double> weightMQ;
|
||||
private HashMap<String, Integer> weightPM;
|
||||
private double time;
|
||||
private double scoreModifier;
|
||||
private double doubleLoot;
|
||||
private int difficulty;
|
||||
private final String material;
|
||||
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
|
||||
private List<ItemFlag> itemFlags;
|
||||
private int custommodeldata;
|
||||
private boolean unbreakable;
|
||||
|
||||
public Bait(String material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public void setName(String name) {this.name = name;}
|
||||
public void setItemFlags(List<ItemFlag> itemFlags) {this.itemFlags = itemFlags;}
|
||||
public void setDifficulty(int difficulty) {this.difficulty = difficulty;}
|
||||
public void setNbt(Map<String,Object> nbt) {this.nbt = nbt;}
|
||||
public void setLore(List<String> lore) {this.lore = lore;}
|
||||
public void setTime(double time) {this.time = time;}
|
||||
public void setWeightMQ(HashMap<String, Double> weightMQ) {this.weightMQ = weightMQ;}
|
||||
public void setWeightPM(HashMap<String, Integer> weightPM) {this.weightPM = weightPM;}
|
||||
public void setDoubleLoot(double doubleLoot) {this.doubleLoot = doubleLoot;}
|
||||
public void setEnchantment(List<net.momirealms.customfishing.utils.Enchantment> enchantment) {this.enchantment = enchantment;}
|
||||
public void setCustommodeldata(int custommodeldata){this.custommodeldata = custommodeldata;}
|
||||
public void setUnbreakable(boolean unbreakable){this.unbreakable = unbreakable;}
|
||||
public void setScoreModifier(double scoreModifier) {this.scoreModifier = scoreModifier;}
|
||||
|
||||
public double getDoubleLoot() {return this.doubleLoot;}
|
||||
public int getDifficulty() {return difficulty;}
|
||||
public double getTime() {return time;}
|
||||
public HashMap<String, Double> getWeightMQ() {return weightMQ;}
|
||||
public HashMap<String, Integer> getWeightPM() {return weightPM;}
|
||||
public double getScoreModifier() {return scoreModifier;}
|
||||
|
||||
@Override
|
||||
public boolean isUnbreakable() {return this.unbreakable;}
|
||||
@Override
|
||||
public int getCustomModelData() {return this.custommodeldata;}
|
||||
@Override
|
||||
public List<String> getLore() {return lore;}
|
||||
@Override
|
||||
public Map<String,Object> getNbt() {return nbt;}
|
||||
@Override
|
||||
public String getMaterial() {return this.material;}
|
||||
@Override
|
||||
public List<net.momirealms.customfishing.utils.Enchantment> getEnchantments() {return this.enchantment;}
|
||||
@Override
|
||||
public List<ItemFlag> getItemFlags() {return this.itemFlags;}
|
||||
@Override
|
||||
public String getName() {return this.name;}
|
||||
}
|
||||
@@ -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.item;
|
||||
|
||||
import net.momirealms.customfishing.utils.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Item {
|
||||
String getMaterial();
|
||||
List<Enchantment> getEnchantments();
|
||||
List<ItemFlag> getItemFlags();
|
||||
String getName();
|
||||
List<String> getLore();
|
||||
Map<String,Object> getNbt();
|
||||
int getCustomModelData();
|
||||
boolean isUnbreakable();
|
||||
}
|
||||
@@ -1,52 +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.item;
|
||||
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemGive {
|
||||
|
||||
public static void givePlayerLoot(Player player, String lootKey, int amount){
|
||||
ItemStack itemStack = ConfigReader.LOOTITEM.get(lootKey);
|
||||
if (itemStack == null) return;
|
||||
itemStack.setAmount(amount);
|
||||
player.getInventory().addItem(itemStack);
|
||||
}
|
||||
|
||||
public static void givePlayerRod(Player player, String rodKey, int amount){
|
||||
ItemStack itemStack = ConfigReader.RODITEM.get(rodKey);
|
||||
itemStack.setAmount(amount);
|
||||
player.getInventory().addItem(itemStack);
|
||||
}
|
||||
|
||||
public static void givePlayerBait(Player player, String baitKey, int amount){
|
||||
ItemStack itemStack = ConfigReader.BAITITEM.get(baitKey);
|
||||
if (itemStack == null) return;
|
||||
itemStack.setAmount(amount);
|
||||
player.getInventory().addItem(itemStack);
|
||||
}
|
||||
|
||||
public static void givePlayerUtil(Player player, String utilKey, int amount){
|
||||
ItemStack itemStack = ConfigReader.UTILITEM.get(utilKey);
|
||||
if (itemStack == null) return;
|
||||
itemStack.setAmount(amount);
|
||||
player.getInventory().addItem(itemStack);
|
||||
}
|
||||
}
|
||||
@@ -1,124 +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.item;
|
||||
|
||||
import net.momirealms.customfishing.requirements.Requirement;
|
||||
import net.momirealms.customfishing.titlebar.Difficulty;
|
||||
import net.momirealms.customfishing.utils.VectorUtil;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Loot implements Item {
|
||||
|
||||
private final String key;
|
||||
private String name;
|
||||
private String nick;
|
||||
private List<String> lore;
|
||||
private Map<String,Object> nbt;
|
||||
private String material;
|
||||
private String mm;
|
||||
private String layout;
|
||||
private VectorUtil vectorUtil;
|
||||
private final Difficulty difficulty;
|
||||
private final int weight;
|
||||
private List<Requirement> requirements;
|
||||
private final int time;
|
||||
private int mmLevel;
|
||||
private int exp;
|
||||
private List<String> msg;
|
||||
private List<String> commands;
|
||||
private List<String> hookCommands;
|
||||
private List<String> hookMsg;
|
||||
private String group;
|
||||
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
|
||||
private List<ItemFlag> itemFlags;
|
||||
private boolean showInFinder;
|
||||
private int custommodeldata;
|
||||
private boolean unbreakable;
|
||||
private double skillXP;
|
||||
private float score;
|
||||
|
||||
public Loot(String key, Difficulty difficulty, int weight, int time){
|
||||
this.key = key;
|
||||
this.difficulty = difficulty;
|
||||
this.weight = weight;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getKey(){return this.key;}
|
||||
public String getNick(){return this.nick;}
|
||||
public List<String> getMsg(){return this.msg;}
|
||||
public String getLayout(){return this.layout;}
|
||||
public String getMm(){return this.mm;}
|
||||
public boolean isShowInFinder() {return this.showInFinder;}
|
||||
public List<String> getCommands(){return this.commands;}
|
||||
public Difficulty getDifficulty(){return this.difficulty;}
|
||||
public int getWeight(){return this.weight;}
|
||||
public List<Requirement> getRequirements() { return this.requirements; }
|
||||
public int getTime(){ return this.time; }
|
||||
public int getMmLevel(){ return this.mmLevel; }
|
||||
public VectorUtil getVectorUtil(){ return this.vectorUtil; }
|
||||
public String getGroup() {return group;}
|
||||
public int getExp() {return exp;}
|
||||
public double getSkillXP() {return skillXP;}
|
||||
public float getScore() {return score;}
|
||||
public List<String> getHookCommands() {return hookCommands;}
|
||||
public List<String> getHookMsg() {return hookMsg;}
|
||||
|
||||
@Override
|
||||
public List<String> getLore(){return this.lore;}
|
||||
@Override
|
||||
public String getName(){return this.name;}
|
||||
@Override
|
||||
public String getMaterial(){return this.material;}
|
||||
@Override
|
||||
public List<net.momirealms.customfishing.utils.Enchantment> getEnchantments() {return this.enchantment;}
|
||||
@Override
|
||||
public List<ItemFlag> getItemFlags() {return this.itemFlags;}
|
||||
@Override
|
||||
public Map<String,Object> getNbt(){return this.nbt;}
|
||||
@Override
|
||||
public int getCustomModelData() {return this.custommodeldata;}
|
||||
@Override
|
||||
public boolean isUnbreakable() {return this.unbreakable;}
|
||||
|
||||
public void setName(String name) {this.name = name;}
|
||||
public void setShowInFinder(boolean showInFinder) {this.showInFinder = showInFinder;}
|
||||
public void setLore(List<String> lore){this.lore = lore;}
|
||||
public void setNbt(Map<String,Object> nbt){this.nbt = nbt;}
|
||||
public void setRequirements(List<Requirement> requirements) {this.requirements = requirements;}
|
||||
public void setMaterial(String material){this.material = material;}
|
||||
public void setNick(String nick){this.nick = nick;}
|
||||
public void setMsg(List<String> msg){this.msg = msg;}
|
||||
public void setMm(String mm){this.mm = mm;}
|
||||
public void setLayout(String layout){this.layout = layout;}
|
||||
public void setVectorUtil(VectorUtil vectorUtil){this.vectorUtil = vectorUtil;}
|
||||
public void setCommands(List<String> commands){this.commands = commands;}
|
||||
public void setMmLevel(int mmLevel){this.mmLevel = mmLevel;}
|
||||
public void setGroup(String group) {this.group = group;}
|
||||
public void setExp(int exp) {this.exp = exp;}
|
||||
public void setItemFlags(List<ItemFlag> itemFlags) {this.itemFlags = itemFlags;}
|
||||
public void setEnchantment(List<net.momirealms.customfishing.utils.Enchantment> enchantment) {this.enchantment = enchantment;}
|
||||
public void setCustommodeldata(int custommodeldata){this.custommodeldata = custommodeldata;}
|
||||
public void setUnbreakable(boolean unbreakable){this.unbreakable = unbreakable;}
|
||||
public void setSkillXP(double skillXP) {this.skillXP = skillXP;}
|
||||
public void setScore(float score) {this.score = score;}
|
||||
public void setHookMsg(List<String> hookMsg) {this.hookMsg = hookMsg;}
|
||||
public void setHookCommands(List<String> hookCommands) {this.hookCommands = hookCommands;}
|
||||
}
|
||||
@@ -1,80 +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.item;
|
||||
|
||||
import net.momirealms.customfishing.utils.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Rod implements Item{
|
||||
|
||||
private String name;
|
||||
private List<String> lore;
|
||||
private Map<String,Object> nbt;
|
||||
private HashMap<String, Double> weightMQ;
|
||||
private HashMap<String, Integer> weightPM;
|
||||
private double time;
|
||||
private double scoreModifier;
|
||||
private int difficulty;
|
||||
private double doubleLoot;
|
||||
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
|
||||
private List<ItemFlag> itemFlags;
|
||||
private int custommodeldata;
|
||||
private boolean unbreakable;
|
||||
|
||||
public void setDifficulty(int difficulty) {this.difficulty = difficulty;}
|
||||
public void setDoubleLoot(double doubleLoot) {this.doubleLoot = doubleLoot;}
|
||||
public void setNbt(Map<String,Object> nbt) {this.nbt = nbt;}
|
||||
public void setLore(List<String> lore) {this.lore = lore;}
|
||||
public void setEnchantment(List<net.momirealms.customfishing.utils.Enchantment> enchantment) {this.enchantment = enchantment;}
|
||||
public void setItemFlags(List<ItemFlag> itemFlags) {this.itemFlags = itemFlags;}
|
||||
public void setTime(double time) {this.time = time;}
|
||||
public void setWeightMQ(HashMap<String, Double> weightMQ) {this.weightMQ = weightMQ;}
|
||||
public void setWeightPM(HashMap<String, Integer> weightPM) {this.weightPM = weightPM;}
|
||||
public void setCustommodeldata(int custommodeldata){this.custommodeldata = custommodeldata;}
|
||||
public void setUnbreakable(boolean unbreakable){this.unbreakable = unbreakable;}
|
||||
public void setName(String name) {this.name = name;}
|
||||
public void setScoreModifier(double scoreModifier) {this.scoreModifier = scoreModifier;}
|
||||
|
||||
public double getTime() {return time;}
|
||||
public HashMap<String, Double> getWeightMQ() {return weightMQ;}
|
||||
public HashMap<String, Integer> getWeightPM() {return weightPM;}
|
||||
public int getDifficulty() {return difficulty;}
|
||||
public double getDoubleLoot() {return this.doubleLoot;}
|
||||
public double getScoreModifier() {return scoreModifier;}
|
||||
|
||||
@Override
|
||||
public boolean isUnbreakable() {return this.unbreakable;}
|
||||
@Override
|
||||
public Map<String,Object> getNbt() {return nbt;}
|
||||
@Override
|
||||
public int getCustomModelData() {return this.custommodeldata;}
|
||||
@Override
|
||||
public String getMaterial() {return "fishing_rod";}
|
||||
@Override
|
||||
public List<Enchantment> getEnchantments() {return this.enchantment;}
|
||||
@Override
|
||||
public List<ItemFlag> getItemFlags() {return this.itemFlags;}
|
||||
@Override
|
||||
public String getName() {return this.name;}
|
||||
@Override
|
||||
public List<String> getLore() {return this.lore;}
|
||||
}
|
||||
@@ -1,65 +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.item;
|
||||
|
||||
import net.momirealms.customfishing.utils.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Util implements Item{
|
||||
|
||||
private String name;
|
||||
private List<String> lore;
|
||||
private Map<String,Object> nbt;
|
||||
private final String material;
|
||||
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
|
||||
private List<ItemFlag> itemFlags;
|
||||
private int custommodeldata;
|
||||
private boolean unbreakable;
|
||||
|
||||
public Util(String material){
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public void setLore(List<String> lore){this.lore = lore;}
|
||||
public void setNbt(Map<String,Object> nbt){this.nbt = nbt;}
|
||||
public void setEnchantment(List<net.momirealms.customfishing.utils.Enchantment> enchantment) {this.enchantment = enchantment;}
|
||||
public void setItemFlags(List<ItemFlag> itemFlags) {this.itemFlags = itemFlags;}
|
||||
public void setCustommodeldata(int custommodeldata){this.custommodeldata = custommodeldata;}
|
||||
public void setUnbreakable(boolean unbreakable){this.unbreakable = unbreakable;}
|
||||
public void setName(String name) {this.name = name;}
|
||||
|
||||
@Override
|
||||
public boolean isUnbreakable() {return this.unbreakable;}
|
||||
@Override
|
||||
public List<String> getLore(){return this.lore;}
|
||||
@Override
|
||||
public String getMaterial(){return this.material;}
|
||||
@Override
|
||||
public String getName(){return this.name;}
|
||||
@Override
|
||||
public List<Enchantment> getEnchantments() {return this.enchantment;}
|
||||
@Override
|
||||
public List<ItemFlag> getItemFlags() {return this.itemFlags;}
|
||||
@Override
|
||||
public Map<String,Object> getNbt(){return this.nbt;}
|
||||
@Override
|
||||
public int getCustomModelData() {return this.custommodeldata;}
|
||||
}
|
||||
@@ -0,0 +1,856 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.listener;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.momirealms.customfishing.competition.CompetitionSchedule;
|
||||
import net.momirealms.customfishing.competition.bossbar.BossBarManager;
|
||||
import net.momirealms.customfishing.hook.*;
|
||||
import net.momirealms.customfishing.object.*;
|
||||
import net.momirealms.customfishing.object.Difficulty;
|
||||
import net.momirealms.customfishing.object.action.ActionB;
|
||||
import net.momirealms.customfishing.object.loot.DroppedItem;
|
||||
import net.momirealms.customfishing.object.loot.Loot;
|
||||
import net.momirealms.customfishing.object.loot.Mob;
|
||||
import net.momirealms.customfishing.utils.AdventureUtil;
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.requirements.FishingCondition;
|
||||
import net.momirealms.customfishing.requirements.Requirement;
|
||||
import net.momirealms.customfishing.titlebar.Timer;
|
||||
import net.momirealms.customfishing.utils.ItemStackUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class FishListener implements Listener {
|
||||
|
||||
private final HashMap<Player, Long> coolDown = new HashMap<>();
|
||||
private final HashMap<Player, Loot> nextLoot = new HashMap<>();
|
||||
private final HashMap<Player, Modifier> modifiers = new HashMap<>();
|
||||
private final HashMap<Player, FishHook> hooks = new HashMap<>();
|
||||
private final HashMap<Player, VanillaLoot> vanilla = new HashMap<>();
|
||||
public static ConcurrentHashMap<Player, FishingPlayer> fishingPlayers = new ConcurrentHashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onFish(PlayerFishEvent event){
|
||||
|
||||
PlayerFishEvent.State state = event.getState();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (state.equals(PlayerFishEvent.State.FISHING)){
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - 2000)) < 2000) {
|
||||
return;
|
||||
}
|
||||
coolDown.put(player, time);
|
||||
|
||||
hooks.put(player, event.getHook());
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()->{
|
||||
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
boolean noRod = true;
|
||||
double timeModifier = 1;
|
||||
double doubleLoot = 0;
|
||||
double scoreModifier = 1;
|
||||
int difficultyModifier = 0;
|
||||
|
||||
HashMap<String, Integer> pm1 = new HashMap<>();
|
||||
HashMap<String, Double> mq1 = new HashMap<>();
|
||||
|
||||
ItemStack mainHandItem = inventory.getItemInMainHand();
|
||||
if (mainHandItem.getType() != Material.AIR){
|
||||
NBTItem nbtItem = new NBTItem(inventory.getItemInMainHand());
|
||||
NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing");
|
||||
if (nbtCompound != null){
|
||||
if (nbtCompound.getString("type").equals("rod")) {
|
||||
String key = nbtCompound.getString("id");
|
||||
Bonus rod = ConfigReader.ROD.get(key);
|
||||
if (rod != null){
|
||||
pm1 = rod.getWeightPM();
|
||||
mq1 = rod.getWeightMQ();
|
||||
if (rod.getTime() != 0) timeModifier *= rod.getTime();
|
||||
if (rod.getDoubleLoot() != 0) doubleLoot += rod.getDoubleLoot();
|
||||
if (rod.getDifficulty() != 0) difficultyModifier += rod.getDifficulty();
|
||||
if (rod.getScore() != 0) scoreModifier *= rod.getScore();
|
||||
noRod = false;
|
||||
}
|
||||
}
|
||||
else if (nbtCompound.getString("type").equals("bait")){
|
||||
String key = nbtCompound.getString("id");
|
||||
Bonus bait = ConfigReader.BAIT.get(key);
|
||||
if (bait != null){
|
||||
pm1 = bait.getWeightPM();
|
||||
mq1 = bait.getWeightMQ();
|
||||
if (bait.getTime() != 0) timeModifier *= bait.getTime();
|
||||
if (bait.getDoubleLoot() != 0) doubleLoot += bait.getDoubleLoot();
|
||||
if (bait.getDifficulty() != 0) difficultyModifier += bait.getDifficulty();
|
||||
if (bait.getScore() != 0) scoreModifier *= bait.getScore();
|
||||
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<String, Integer> pm2 = new HashMap<>();
|
||||
HashMap<String, Double> mq2 = new HashMap<>();
|
||||
|
||||
ItemStack offHandItem = inventory.getItemInOffHand();
|
||||
if (offHandItem.getType() != Material.AIR){
|
||||
NBTItem offHand = new NBTItem(inventory.getItemInOffHand());
|
||||
NBTCompound offHandCompound = offHand.getCompound("CustomFishing");
|
||||
if (offHandCompound != null){
|
||||
if (offHandCompound.getString("type").equals("bait")) {
|
||||
String key = offHandCompound.getString("id");
|
||||
Bonus bait = ConfigReader.BAIT.get(key);
|
||||
if (bait != null){
|
||||
pm2 = bait.getWeightPM();
|
||||
mq2 = bait.getWeightMQ();
|
||||
if (bait.getTime() != 0) timeModifier *= bait.getTime();
|
||||
if (bait.getDoubleLoot() != 0) doubleLoot += bait.getDoubleLoot();
|
||||
if (bait.getDifficulty() != 0) difficultyModifier += bait.getDifficulty();
|
||||
if (bait.getScore() != 0) scoreModifier *= bait.getScore();
|
||||
offHandItem.setAmount(offHandItem.getAmount() - 1);
|
||||
}
|
||||
}else if (noRod && offHandCompound.getString("type").equals("rod")){
|
||||
String key = offHandCompound.getString("id");
|
||||
Bonus rod = ConfigReader.ROD.get(key);
|
||||
if (rod != null){
|
||||
pm2 = rod.getWeightPM();
|
||||
mq2 = rod.getWeightMQ();
|
||||
if (rod.getTime() != 0) timeModifier *= rod.getTime();
|
||||
if (rod.getDoubleLoot() != 0) doubleLoot += rod.getDoubleLoot();
|
||||
if (rod.getDifficulty() != 0) difficultyModifier += rod.getDifficulty();
|
||||
if (rod.getScore() != 0) scoreModifier *= rod.getScore();
|
||||
noRod = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigReader.Config.needSpecialRod && noRod){
|
||||
if (!ConfigReader.Config.vanillaLoot)
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.noRod);
|
||||
nextLoot.put(player, null);
|
||||
return;
|
||||
}
|
||||
|
||||
FishHook hook = event.getHook();
|
||||
hook.setMaxWaitTime((int) (timeModifier * hook.getMaxWaitTime()));
|
||||
hook.setMinWaitTime((int) (timeModifier * hook.getMinWaitTime()));
|
||||
|
||||
List<Loot> possibleLoots = getPossibleLootList(new FishingCondition(hook.getLocation(), player));
|
||||
List<Loot> availableLoots = new ArrayList<>();
|
||||
|
||||
if (possibleLoots.size() == 0){
|
||||
nextLoot.put(player, null);
|
||||
return;
|
||||
}
|
||||
|
||||
Modifier modifier = new Modifier();
|
||||
modifier.setDifficulty(difficultyModifier);
|
||||
modifier.setScore(scoreModifier);
|
||||
modifier.setWillDouble(doubleLoot > Math.random());
|
||||
modifiers.put(player, modifier);
|
||||
|
||||
double[] weights = new double[possibleLoots.size()];
|
||||
int index = 0;
|
||||
for (Loot loot : possibleLoots){
|
||||
double weight = loot.getWeight();
|
||||
String group = loot.getGroup();
|
||||
if (group != null){
|
||||
if (pm1 != null && pm1.get(group) != null){
|
||||
weight += pm1.get(group);
|
||||
}
|
||||
if (pm2!= null && pm2.get(group) != null){
|
||||
weight += pm2.get(group);
|
||||
}
|
||||
if (mq1 != null && mq1.get(group) != null){
|
||||
weight *= mq1.get(group);
|
||||
}
|
||||
if (mq2 != null && mq2.get(group) != null){
|
||||
weight *= mq2.get(group);
|
||||
}
|
||||
}
|
||||
if (weight <= 0) continue;
|
||||
availableLoots.add(loot);
|
||||
weights[index++] = weight;
|
||||
}
|
||||
|
||||
double total = Arrays.stream(weights).sum();
|
||||
double[] weightRatios = new double[index];
|
||||
for (int i = 0; i < index; i++){
|
||||
weightRatios[i] = weights[i]/total;
|
||||
}
|
||||
|
||||
double[] weightRange = new double[index];
|
||||
double startPos = 0;
|
||||
for (int i = 0; i < index; i++) {
|
||||
weightRange[i] = startPos + weightRatios[i];
|
||||
startPos += weightRatios[i];
|
||||
}
|
||||
|
||||
double random = Math.random();
|
||||
int pos = Arrays.binarySearch(weightRange, random);
|
||||
|
||||
if (pos < 0) {
|
||||
pos = -pos - 1;
|
||||
} else {
|
||||
nextLoot.put(player, availableLoots.get(pos));
|
||||
return;
|
||||
}
|
||||
if (pos < weightRange.length && random < weightRange[pos]) {
|
||||
nextLoot.put(player, availableLoots.get(pos));
|
||||
return;
|
||||
}
|
||||
nextLoot.put(player, null);
|
||||
});
|
||||
}
|
||||
|
||||
else if (state.equals(PlayerFishEvent.State.BITE)){
|
||||
|
||||
if (ConfigReader.Config.doubleRealIn) return;
|
||||
|
||||
if (fishingPlayers.get(player) != null) return;
|
||||
|
||||
Loot loot = nextLoot.get(player);
|
||||
|
||||
if (loot == null) return;
|
||||
|
||||
String layout;
|
||||
if (loot.getLayout() != null){
|
||||
layout = loot.getLayout().get((int) (loot.getLayout().size() * Math.random()));
|
||||
}else {
|
||||
Object[] values = ConfigReader.LAYOUT.keySet().toArray();
|
||||
layout = (String) values[new Random().nextInt(values.length)];
|
||||
}
|
||||
|
||||
int difficulty = loot.getDifficulty().getSpeed();
|
||||
difficulty += Objects.requireNonNullElse(modifiers.get(player).getDifficulty(), 0);;
|
||||
if (difficulty < 1){
|
||||
difficulty = 1;
|
||||
}
|
||||
|
||||
Difficulty difficult = new Difficulty(loot.getDifficulty().getTimer(), difficulty);
|
||||
fishingPlayers.put(player,
|
||||
new FishingPlayer(System.currentTimeMillis() + loot.getTime(),
|
||||
new Timer(player, difficult, layout)
|
||||
)
|
||||
);
|
||||
|
||||
for (ActionB action : loot.getHookActions()){
|
||||
action.doOn(player);
|
||||
}
|
||||
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, loot.getTime()/50,3));
|
||||
|
||||
}
|
||||
|
||||
//收杆拉鱼
|
||||
else if (state.equals(PlayerFishEvent.State.CAUGHT_FISH)) {
|
||||
|
||||
//是否需要两次拉杆
|
||||
if (ConfigReader.Config.doubleRealIn) {
|
||||
|
||||
FishingPlayer fishingPlayer = fishingPlayers.remove(player);
|
||||
if (fishingPlayer == null){
|
||||
Entity entity = event.getCaught();
|
||||
if (entity instanceof Item item){
|
||||
//是否有原版战利品
|
||||
if (ConfigReader.Config.vanillaLoot) {
|
||||
//不是原版战利品
|
||||
if (ConfigReader.Config.vanillaRatio < Math.random()) {
|
||||
event.setCancelled(true);
|
||||
vanilla.remove(player);
|
||||
showPlayerBar(player);
|
||||
}
|
||||
//是原版战利品
|
||||
else {
|
||||
//需要走力度条流程
|
||||
if (ConfigReader.Config.showBar){
|
||||
event.setCancelled(true);
|
||||
vanilla.put(player, new VanillaLoot(item.getItemStack(), event.getExpToDrop()));
|
||||
showPlayerBar(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
//如果不许有原版战利品则清除
|
||||
else {
|
||||
if (nextLoot.get(player) == null){
|
||||
item.remove();
|
||||
event.setExpToDrop(0);
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.noLoot);
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
showPlayerBar(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Entity entity = event.getCaught();
|
||||
if (entity instanceof Item item){
|
||||
item.remove();
|
||||
event.setExpToDrop(0);
|
||||
}
|
||||
Loot loot = nextLoot.remove(player);
|
||||
VanillaLoot vanillaLoot = vanilla.remove(player);
|
||||
Timer timer = fishingPlayer.getTimer();
|
||||
Layout layout = ConfigReader.LAYOUT.get(timer.getLayout());
|
||||
int last = (timer.getTimerTask().getProgress())/layout.getRange();
|
||||
|
||||
player.removePotionEffect(PotionEffectType.SLOW);
|
||||
if (ConfigReader.Config.needOpenWater && !event.getHook().isInOpenWater()){
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.notOpenWater);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Math.random() < layout.getSuccessRate()[last]){
|
||||
if (ConfigReader.Config.loseDurability)
|
||||
loseDurability(player);
|
||||
Location location = event.getHook().getLocation();
|
||||
if (loot instanceof Mob mob){
|
||||
MythicMobsUtil.summonMM(player.getLocation(), location, mob);
|
||||
for (ActionB action : loot.getSuccessActions())
|
||||
action.doOn(player);
|
||||
if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) {
|
||||
float score = (float) (loot.getScore() * modifiers.get(player).getScore());
|
||||
CompetitionSchedule.competition.refreshRanking(player.getName(), score);
|
||||
BossBarManager.joinCompetition(player);
|
||||
}
|
||||
}
|
||||
else if (loot instanceof DroppedItem droppedItem){
|
||||
ItemStack itemStack;
|
||||
if (vanillaLoot != null) {
|
||||
itemStack = vanillaLoot.getItemStack();
|
||||
player.giveExp(vanillaLoot.getXp(), true);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,1);
|
||||
Entity item = location.getWorld().dropItem(location, itemStack);
|
||||
Vector vector = player.getLocation().subtract(location).toVector().multiply(0.1);
|
||||
vector = vector.setY((vector.getY()+0.2)*1.2);
|
||||
item.setVelocity(vector);
|
||||
if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) {
|
||||
CompetitionSchedule.competition.refreshRanking(player.getName(), 0);
|
||||
BossBarManager.joinCompetition(player);
|
||||
}
|
||||
if (modifiers.get(player).isWillDouble()) {
|
||||
Entity item2 = location.getWorld().dropItem(location, itemStack);
|
||||
item2.setVelocity(vector);
|
||||
}
|
||||
String title = ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random()));
|
||||
Component titleComponent = getTitleComponent(itemStack, title);
|
||||
String subTitle = ConfigReader.Title.success_subtitle.get((int) (ConfigReader.Title.success_subtitle.size()*Math.random()));
|
||||
Component subtitleComponent = getTitleComponent(itemStack, subTitle);
|
||||
|
||||
AdventureUtil.playerTitle(
|
||||
player,
|
||||
titleComponent,
|
||||
subtitleComponent,
|
||||
ConfigReader.Title.success_in,
|
||||
ConfigReader.Title.success_stay,
|
||||
ConfigReader.Title.success_out
|
||||
);
|
||||
}
|
||||
else {
|
||||
if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) {
|
||||
float score = (float) (loot.getScore() * modifiers.get(player).getScore());
|
||||
CompetitionSchedule.competition.refreshRanking(player.getName(), score);
|
||||
BossBarManager.joinCompetition(player);
|
||||
}
|
||||
for (ActionB action : loot.getSuccessActions())
|
||||
action.doOn(player);
|
||||
dropLoot(player, location, droppedItem);
|
||||
AdventureUtil.playerTitle(
|
||||
player,
|
||||
ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random()))
|
||||
.replace("{loot}",loot.getNick())
|
||||
.replace("{player}", player.getName()),
|
||||
ConfigReader.Title.success_subtitle.get((int) (ConfigReader.Title.success_subtitle.size()*Math.random()))
|
||||
.replace("{loot}",loot.getNick())
|
||||
.replace("{player}", player.getName()),
|
||||
ConfigReader.Title.success_in,
|
||||
ConfigReader.Title.success_stay,
|
||||
ConfigReader.Title.success_out
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (vanillaLoot == null) {
|
||||
fail(player, loot);
|
||||
}
|
||||
}
|
||||
}
|
||||
//不需要两次拉杆
|
||||
//除非设置否则肯定不会有原版掉落物
|
||||
else {
|
||||
|
||||
Entity entity = event.getCaught();
|
||||
if (entity instanceof Item item){
|
||||
|
||||
//如果玩家正在钓鱼
|
||||
//那么拉杆的时候可能也会遇到上钩点,进行正常收杆判断
|
||||
FishingPlayer fishingPlayer = fishingPlayers.remove(player);
|
||||
if (fishingPlayer != null){
|
||||
|
||||
item.remove();
|
||||
event.setExpToDrop(0);
|
||||
|
||||
Loot loot = nextLoot.get(player);
|
||||
Timer timer = fishingPlayer.getTimer();
|
||||
Layout layout = ConfigReader.LAYOUT.get(timer.getLayout());
|
||||
int last = (timer.getTimerTask().getProgress())/layout.getRange();
|
||||
player.removePotionEffect(PotionEffectType.SLOW);
|
||||
|
||||
if (ConfigReader.Config.needOpenWater && !event.getHook().isInOpenWater()){
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.notOpenWater);
|
||||
return;
|
||||
}
|
||||
|
||||
//捕鱼成功
|
||||
if (Math.random() < layout.getSuccessRate()[last]) {
|
||||
Location location = event.getHook().getLocation();
|
||||
if (loot instanceof Mob mob){
|
||||
MythicMobsUtil.summonMM(player.getLocation(), location, mob);
|
||||
}
|
||||
else if (loot instanceof DroppedItem droppedItem){
|
||||
dropLoot(player, location, droppedItem);
|
||||
}
|
||||
for (ActionB action : loot.getSuccessActions())
|
||||
action.doOn(player);
|
||||
if (ConfigReader.Config.loseDurability)
|
||||
loseDurability(player);
|
||||
if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()){
|
||||
float score = (float) (loot.getScore() * modifiers.get(player).getScore());
|
||||
CompetitionSchedule.competition.refreshRanking(player.getName(), score);
|
||||
BossBarManager.joinCompetition(player);
|
||||
}
|
||||
AdventureUtil.playerTitle(
|
||||
player,
|
||||
ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random()))
|
||||
.replace("{loot}",loot.getNick())
|
||||
.replace("{player}", player.getName()),
|
||||
ConfigReader.Title.success_subtitle.get((int) (ConfigReader.Title.success_subtitle.size()*Math.random()))
|
||||
.replace("{loot}",loot.getNick())
|
||||
.replace("{player}", player.getName()),
|
||||
ConfigReader.Title.success_in,
|
||||
ConfigReader.Title.success_stay,
|
||||
ConfigReader.Title.success_out
|
||||
);
|
||||
}
|
||||
//捕鱼失败
|
||||
else {
|
||||
fail(player, loot);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!ConfigReader.Config.vanillaLoot) {
|
||||
item.remove();
|
||||
event.setExpToDrop(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//普通收杆
|
||||
//对于在Vanilla HashMap中有值的,说明是有原版战利品,否则全部是插件战利品
|
||||
else if (state.equals(PlayerFishEvent.State.REEL_IN)){
|
||||
|
||||
FishingPlayer fishingPlayer = fishingPlayers.remove(player);
|
||||
//首先得是钓鱼中的玩家
|
||||
if (fishingPlayer != null){
|
||||
|
||||
Loot loot = nextLoot.remove(player);
|
||||
VanillaLoot vanillaLoot = vanilla.remove(player);
|
||||
Timer timer = fishingPlayer.getTimer();
|
||||
Layout layout = ConfigReader.LAYOUT.get(timer.getLayout());
|
||||
int last = (timer.getTimerTask().getProgress())/layout.getRange();
|
||||
|
||||
player.removePotionEffect(PotionEffectType.SLOW);
|
||||
if (ConfigReader.Config.needOpenWater && !event.getHook().isInOpenWater()){
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.notOpenWater);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Math.random() < layout.getSuccessRate()[last]){
|
||||
if (ConfigReader.Config.loseDurability)
|
||||
loseDurability(player);
|
||||
Location location = event.getHook().getLocation();
|
||||
if (loot instanceof Mob mob){
|
||||
MythicMobsUtil.summonMM(player.getLocation(), location, mob);
|
||||
for (ActionB action : loot.getSuccessActions())
|
||||
action.doOn(player);
|
||||
if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) {
|
||||
float score = (float) (loot.getScore() * modifiers.get(player).getScore());
|
||||
CompetitionSchedule.competition.refreshRanking(player.getName(), score);
|
||||
BossBarManager.joinCompetition(player);
|
||||
}
|
||||
}
|
||||
else if (loot instanceof DroppedItem droppedItem){
|
||||
ItemStack itemStack;
|
||||
|
||||
if (vanillaLoot != null) {
|
||||
itemStack = vanillaLoot.getItemStack();
|
||||
player.giveExp(vanillaLoot.getXp(), true);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,1);
|
||||
Entity item = location.getWorld().dropItem(location, itemStack);
|
||||
Vector vector = player.getLocation().subtract(location).toVector().multiply(0.1);
|
||||
vector = vector.setY((vector.getY()+0.2)*1.2);
|
||||
item.setVelocity(vector);
|
||||
if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) {
|
||||
CompetitionSchedule.competition.refreshRanking(player.getName(), 0);
|
||||
BossBarManager.joinCompetition(player);
|
||||
}
|
||||
if (modifiers.get(player).isWillDouble()) {
|
||||
Entity item2 = location.getWorld().dropItem(location, itemStack);
|
||||
item2.setVelocity(vector);
|
||||
}
|
||||
String[] titleSplit = StringUtils.split(ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random()))
|
||||
.replace("{player}", player.getName()), "{loot}");
|
||||
String[] subtitleSplit = StringUtils.split(ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random()))
|
||||
.replace("{player}", player.getName()), "{loot}");
|
||||
Component titleComponent;
|
||||
Component subComponent;
|
||||
if (titleSplit.length == 1){
|
||||
titleComponent = MiniMessage.miniMessage().deserialize(titleSplit[0]);
|
||||
}
|
||||
else {
|
||||
titleComponent = MiniMessage.miniMessage().deserialize(titleSplit[0]).append(itemStack.displayName()).append(MiniMessage.miniMessage().deserialize(titleSplit[1]));
|
||||
}
|
||||
if (subtitleSplit.length == 1){
|
||||
subComponent = MiniMessage.miniMessage().deserialize(subtitleSplit[0]);
|
||||
}
|
||||
else {
|
||||
subComponent = MiniMessage.miniMessage().deserialize(subtitleSplit[0]).append(itemStack.displayName()).append(MiniMessage.miniMessage().deserialize(subtitleSplit[1]));
|
||||
}
|
||||
AdventureUtil.playerTitle(
|
||||
player,
|
||||
titleComponent,
|
||||
subComponent,
|
||||
ConfigReader.Title.success_in,
|
||||
ConfigReader.Title.success_stay,
|
||||
ConfigReader.Title.success_out
|
||||
);
|
||||
}
|
||||
else {
|
||||
if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) {
|
||||
float score = (float) (loot.getScore() * modifiers.get(player).getScore());
|
||||
CompetitionSchedule.competition.refreshRanking(player.getName(), score);
|
||||
BossBarManager.joinCompetition(player);
|
||||
}
|
||||
for (ActionB action : loot.getSuccessActions())
|
||||
action.doOn(player);
|
||||
dropLoot(player, location, droppedItem);
|
||||
AdventureUtil.playerTitle(
|
||||
player,
|
||||
ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random()))
|
||||
.replace("{loot}",loot.getNick())
|
||||
.replace("{player}", player.getName()),
|
||||
ConfigReader.Title.success_subtitle.get((int) (ConfigReader.Title.success_subtitle.size()*Math.random()))
|
||||
.replace("{loot}",loot.getNick())
|
||||
.replace("{player}", player.getName()),
|
||||
ConfigReader.Title.success_in,
|
||||
ConfigReader.Title.success_stay,
|
||||
ConfigReader.Title.success_out
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (vanillaLoot == null) {
|
||||
fail(player, loot);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//钓上来的是物品
|
||||
if (event.getCaught() instanceof Item item) {
|
||||
//是否允许原版掉落物
|
||||
if (ConfigReader.Config.vanillaLoot) {
|
||||
if (ConfigReader.Config.showBar){
|
||||
item.remove();
|
||||
event.setExpToDrop(0);
|
||||
//event.setCancelled(true);
|
||||
vanilla.put(player, new VanillaLoot(item.getItemStack(), event.getExpToDrop()));
|
||||
showPlayerBar(player);
|
||||
}
|
||||
else {
|
||||
//啥也不干
|
||||
}
|
||||
}
|
||||
//不允许原版掉落物
|
||||
else {
|
||||
item.remove();
|
||||
event.setExpToDrop(0);
|
||||
//event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (state.equals(PlayerFishEvent.State.CAUGHT_ENTITY)){
|
||||
//理论是不存在实体的
|
||||
//说明在钓鱼的时候可能鱼钩勾上了鱿鱼之类的生物
|
||||
//直接按照失败处理
|
||||
if (fishingPlayers.remove(player) != null && event.getCaught() != null){
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.hookOther);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Component getTitleComponent(ItemStack itemStack, String text) {
|
||||
Component subtitleComponent;
|
||||
if (text.contains("{loot}")){
|
||||
text = text.replace("{loot}","|");
|
||||
if (text.startsWith("|")){
|
||||
subtitleComponent = itemStack.displayName().append(MiniMessage.miniMessage().deserialize(text.substring(1)));
|
||||
}
|
||||
else if (text.endsWith("|")){
|
||||
subtitleComponent = MiniMessage.miniMessage().deserialize(text.substring(0,text.length()-1)).append(itemStack.displayName());
|
||||
}
|
||||
else {
|
||||
String[] titleSplit = StringUtils.split(text, "|");
|
||||
subtitleComponent = MiniMessage.miniMessage().deserialize(titleSplit[0]).append(itemStack.displayName()).append(MiniMessage.miniMessage().deserialize(titleSplit[1]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
subtitleComponent = MiniMessage.miniMessage().deserialize(text);
|
||||
}
|
||||
return subtitleComponent;
|
||||
}
|
||||
|
||||
private void dropLoot(Player player, Location location, DroppedItem droppedItem) {
|
||||
ItemStack itemStack;
|
||||
switch (droppedItem.getType()){
|
||||
case "ia" -> itemStack = ItemsAdderItem.getItemStack(droppedItem.getId());
|
||||
case "oraxen" -> itemStack = OraxenItem.getItemStack(droppedItem.getId());
|
||||
case "mm" -> itemStack = MythicItems.getItemStack(droppedItem.getId());
|
||||
case "mmoitems" -> itemStack = MMOItemsHook.getItemStack(droppedItem.getId());
|
||||
default -> itemStack = ConfigReader.LootItem.get(droppedItem.getKey()).clone();
|
||||
}
|
||||
|
||||
if (itemStack.getType() != Material.AIR) {
|
||||
if (droppedItem.getRandomEnchants() != null)
|
||||
ItemStackUtil.addRandomEnchants(itemStack, droppedItem.getRandomEnchants());
|
||||
if (droppedItem.isRandomDurability())
|
||||
ItemStackUtil.addRandomDamage(itemStack);
|
||||
if (ConfigReader.Config.preventPick)
|
||||
ItemStackUtil.addOwner(itemStack, player.getName());
|
||||
Entity item = location.getWorld().dropItem(location, itemStack);
|
||||
Vector vector = player.getLocation().subtract(location).toVector().multiply(0.1);
|
||||
vector = vector.setY((vector.getY()+0.2)*1.2);
|
||||
item.setVelocity(vector);
|
||||
if (modifiers.get(player).isWillDouble()){
|
||||
Entity item2 = location.getWorld().dropItem(location, itemStack);
|
||||
item2.setVelocity(vector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loseDurability(Player player) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE) return;
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
ItemStack mainHand = inventory.getItemInMainHand();
|
||||
if (mainHand.getType() == Material.FISHING_ROD){
|
||||
Damageable damageable = (Damageable) mainHand.getItemMeta();
|
||||
if (damageable.isUnbreakable()) return;
|
||||
Enchantment enchantment = Enchantment.DURABILITY;
|
||||
if (Math.random() < (1/(double) (damageable.getEnchantLevel(enchantment) + 1))){
|
||||
damageable.setDamage(damageable.getDamage() + 1);
|
||||
Bukkit.getScheduler().runTaskLater(CustomFishing.instance, ()->{
|
||||
mainHand.setItemMeta(damageable);
|
||||
},1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ItemStack offHand = inventory.getItemInOffHand();
|
||||
if (offHand.getType() == Material.FISHING_ROD){
|
||||
Damageable damageable = (Damageable) offHand.getItemMeta();
|
||||
if (damageable.isUnbreakable()) return;
|
||||
Enchantment enchantment = Enchantment.DURABILITY;
|
||||
if (Math.random() < (1/(double) (damageable.getEnchantLevel(enchantment) + 1))){
|
||||
damageable.setDamage(damageable.getDamage() + 1);
|
||||
Bukkit.getScheduler().runTaskLater(CustomFishing.instance, ()->{
|
||||
offHand.setItemMeta(damageable);
|
||||
},1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fail(Player player, Loot loot) {
|
||||
fishingPlayers.remove(player);
|
||||
for (ActionB action : loot.getFailureActions())
|
||||
action.doOn(player);
|
||||
AdventureUtil.playerTitle(player, ConfigReader.Title.failure_title.get((int) (ConfigReader.Title.failure_title.size()*Math.random())), ConfigReader.Title.failure_subtitle.get((int) (ConfigReader.Title.failure_subtitle.size()*Math.random())), ConfigReader.Title.failure_in, ConfigReader.Title.failure_stay, ConfigReader.Title.failure_out);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQUit(PlayerQuitEvent event){
|
||||
Player player = event.getPlayer();
|
||||
player.removePotionEffect(PotionEffectType.SLOW);
|
||||
if (hooks.get(player) != null){
|
||||
hooks.get(player).remove();
|
||||
}
|
||||
hooks.remove(player);
|
||||
coolDown.remove(player);
|
||||
nextLoot.remove(player);
|
||||
modifiers.remove(player);
|
||||
fishingPlayers.remove(player);
|
||||
vanilla.remove(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent event){
|
||||
if (!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
|
||||
ItemStack itemStack = event.getItem();
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) return;
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
if (nbtItem.getCompound("CustomFishing") == null) return;
|
||||
if (nbtItem.getCompound("CustomFishing").getString("type").equals("util") && nbtItem.getCompound("CustomFishing").getString("id").equals("fishfinder")){
|
||||
Player player = event.getPlayer();
|
||||
//设置冷却时间
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - ConfigReader.Config.fishFinderCoolDown)) < ConfigReader.Config.fishFinderCoolDown) {
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.coolDown);
|
||||
return;
|
||||
}
|
||||
coolDown.put(player, time);
|
||||
//获取玩家位置处可能的Loot实例列表
|
||||
List<Loot> possibleLoots = getFinder(new FishingCondition(player.getLocation(), player));
|
||||
if (possibleLoots.size() == 0){
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.noLoot);
|
||||
return;
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder(ConfigReader.Message.prefix + ConfigReader.Message.possibleLoots);
|
||||
possibleLoots.forEach(loot -> stringBuilder.append(loot.getNick()).append(ConfigReader.Message.splitChar));
|
||||
AdventureUtil.playerMessage(player, stringBuilder.substring(0, stringBuilder.length()-ConfigReader.Message.splitChar.length()));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
获取可能的Loot列表
|
||||
*/
|
||||
private List<Loot> getPossibleLootList(FishingCondition fishingCondition) {
|
||||
List<Loot> available = new ArrayList<>();
|
||||
ConfigReader.LOOT.keySet().forEach(key -> {
|
||||
Loot loot = ConfigReader.LOOT.get(key);
|
||||
List<Requirement> requirements = loot.getRequirements();
|
||||
if (requirements == null){
|
||||
available.add(loot);
|
||||
}else {
|
||||
boolean isMet = true;
|
||||
for (Requirement requirement : requirements){
|
||||
if (!requirement.isConditionMet(fishingCondition)){
|
||||
isMet = false;
|
||||
}
|
||||
}
|
||||
if (isMet){
|
||||
available.add(loot);
|
||||
}
|
||||
}
|
||||
});
|
||||
return available;
|
||||
}
|
||||
|
||||
private List<Loot> getFinder(FishingCondition fishingCondition) {
|
||||
List<Loot> available = new ArrayList<>();
|
||||
ConfigReader.LOOT.keySet().forEach(key -> {
|
||||
Loot loot = ConfigReader.LOOT.get(key);
|
||||
if (!loot.isShowInFinder()) return;
|
||||
List<Requirement> requirements = loot.getRequirements();
|
||||
if (requirements == null){
|
||||
available.add(loot);
|
||||
}else {
|
||||
boolean isMet = true;
|
||||
for (Requirement requirement : requirements){
|
||||
if (!requirement.isConditionMet(fishingCondition)){
|
||||
isMet = false;
|
||||
}
|
||||
}
|
||||
if (isMet){
|
||||
available.add(loot);
|
||||
}
|
||||
}
|
||||
});
|
||||
return available;
|
||||
}
|
||||
|
||||
private void showPlayerBar(Player player){
|
||||
Loot loot = nextLoot.get(player);
|
||||
|
||||
String layout;
|
||||
if (loot.getLayout() != null){
|
||||
try {
|
||||
layout = loot.getLayout().get((int) (loot.getLayout().size() * Math.random()));
|
||||
}
|
||||
catch (IndexOutOfBoundsException e){
|
||||
AdventureUtil.consoleMessage("<red>[CustomFishing] Layouts should be in a list");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Object[] values = ConfigReader.LAYOUT.keySet().toArray();
|
||||
layout = (String) values[new Random().nextInt(values.length)];
|
||||
}
|
||||
|
||||
int difficulty = loot.getDifficulty().getSpeed();
|
||||
difficulty += Objects.requireNonNullElse(modifiers.get(player).getDifficulty(), 0);;
|
||||
if (difficulty < 1){
|
||||
difficulty = 1;
|
||||
}
|
||||
|
||||
Difficulty difficult = new Difficulty(loot.getDifficulty().getTimer(), difficulty);
|
||||
fishingPlayers.put(player,
|
||||
new FishingPlayer(System.currentTimeMillis() + loot.getTime(),
|
||||
new Timer(player, difficult, layout)
|
||||
)
|
||||
);
|
||||
|
||||
if (vanilla.get(player) == null){
|
||||
for (ActionB action : loot.getHookActions()){
|
||||
action.doOn(player);
|
||||
}
|
||||
}
|
||||
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, loot.getTime()/50,3));
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
@@ -52,7 +53,7 @@ public class MMOItemsConverter implements Listener {
|
||||
if(mainHand.getType() == Material.FISHING_ROD){
|
||||
NBTItem nbtItem = new NBTItem(mainHand);
|
||||
if (nbtItem.getCompound("CustomFishing") == null) {
|
||||
if (nbtItem.getString("MMOITEMS_ITEM_ID") != null){
|
||||
if (!nbtItem.getString("MMOITEMS_ITEM_ID").equals("")){
|
||||
NBTCompound nbtCompound = nbtItem.addCompound("CustomFishing");
|
||||
nbtCompound.setString("type","rod");
|
||||
nbtCompound.setString("id",nbtItem.getString("MMOITEMS_ITEM_ID"));
|
||||
@@ -65,7 +66,7 @@ public class MMOItemsConverter implements Listener {
|
||||
if(offHand.getType() == Material.FISHING_ROD){
|
||||
NBTItem nbtItem = new NBTItem(offHand);
|
||||
if (nbtItem.getCompound("CustomFishing") == null) {
|
||||
if (nbtItem.getString("MMOITEMS_ITEM_ID") != null){
|
||||
if (!nbtItem.getString("MMOITEMS_ITEM_ID").equals("")){
|
||||
NBTCompound nbtCompound = nbtItem.addCompound("CustomFishing");
|
||||
nbtCompound.setString("type", "rod");
|
||||
nbtCompound.setString("id", nbtItem.getString("MMOITEMS_ITEM_ID"));
|
||||
@@ -75,4 +76,9 @@ public class MMOItemsConverter implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event){
|
||||
coolDown.remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.momirealms.customfishing.CustomFishing;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class PapiReload implements Listener {
|
||||
public class PapiUnregister implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onReload(me.clip.placeholderapi.events.ExpansionUnregisterEvent event){
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.momirealms.customfishing.listener;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerAttemptPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class PickUpListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPickUp(PlayerAttemptPickupItemEvent event){
|
||||
ItemStack itemStack = event.getItem().getItemStack();
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
if (nbtItem.hasKey("M_Owner")){
|
||||
if (!Objects.equals(nbtItem.getString("M_Owner"), event.getPlayer().getName())){
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else {
|
||||
nbtItem.removeKey("M_Owner");
|
||||
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,493 +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.listener;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import net.momirealms.customfishing.competition.CompetitionSchedule;
|
||||
import net.momirealms.customfishing.competition.bossbar.BossBarManager;
|
||||
import net.momirealms.customfishing.hook.MythicMobsUtils;
|
||||
import net.momirealms.customfishing.utils.AdventureManager;
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.titlebar.Difficulty;
|
||||
import net.momirealms.customfishing.titlebar.FishingPlayer;
|
||||
import net.momirealms.customfishing.titlebar.Layout;
|
||||
import net.momirealms.customfishing.item.Bait;
|
||||
import net.momirealms.customfishing.item.Loot;
|
||||
import net.momirealms.customfishing.item.Rod;
|
||||
import net.momirealms.customfishing.requirements.FishingCondition;
|
||||
import net.momirealms.customfishing.requirements.Requirement;
|
||||
import net.momirealms.customfishing.titlebar.Timer;
|
||||
import net.momirealms.customfishing.utils.Modifier;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.FishHook;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
private final HashMap<Player, Long> coolDown = new HashMap<>();
|
||||
private final HashMap<Player, Loot> nextLoot = new HashMap<>();
|
||||
private final HashMap<Player, Modifier> modifiers = new HashMap<>();
|
||||
private final HashMap<Player, FishHook> hooks = new HashMap<>();
|
||||
public static ConcurrentHashMap<Player, FishingPlayer> fishingPlayers = new ConcurrentHashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onFish(PlayerFishEvent event){
|
||||
|
||||
PlayerFishEvent.State state = event.getState();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
//抛竿
|
||||
if (state.equals(PlayerFishEvent.State.FISHING)){
|
||||
|
||||
//设置冷却时间
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - 2000)) < 2000) {
|
||||
return;
|
||||
}
|
||||
coolDown.put(player, time);
|
||||
|
||||
hooks.put(player, event.getHook());
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()->{
|
||||
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
boolean noRod = true;
|
||||
double timeModifier = 1;
|
||||
double doubleLoot = 0;
|
||||
double scoreModifier = 1;
|
||||
int difficultyModifier = 0;
|
||||
|
||||
HashMap<String, Integer> pm1 = new HashMap<>();
|
||||
HashMap<String, Double> mq1 = new HashMap<>();
|
||||
|
||||
ItemStack mainHandItem = inventory.getItemInMainHand();
|
||||
if (mainHandItem.getType() != Material.AIR){
|
||||
NBTItem nbtItem = new NBTItem(inventory.getItemInMainHand());
|
||||
NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing");
|
||||
if (nbtCompound != null){
|
||||
if (nbtCompound.getString("type").equals("rod")) {
|
||||
String key = nbtCompound.getString("id");
|
||||
Rod rod = ConfigReader.ROD.get(key);
|
||||
if (rod != null){
|
||||
pm1 = rod.getWeightPM();
|
||||
mq1 = rod.getWeightMQ();
|
||||
if (rod.getTime() != 0) timeModifier *= rod.getTime();
|
||||
if (rod.getDoubleLoot() != 0) doubleLoot += rod.getDoubleLoot();
|
||||
if (rod.getDifficulty() != 0) difficultyModifier += rod.getDifficulty();
|
||||
if (rod.getScoreModifier() != 0) scoreModifier *= rod.getScoreModifier();
|
||||
noRod = false;
|
||||
}
|
||||
}
|
||||
else if (nbtCompound.getString("type").equals("bait")){
|
||||
String key = nbtCompound.getString("id");
|
||||
Bait bait = ConfigReader.BAIT.get(key);
|
||||
if (bait != null){
|
||||
pm1 = bait.getWeightPM();
|
||||
mq1 = bait.getWeightMQ();
|
||||
if (bait.getTime() != 0) timeModifier *= bait.getTime();
|
||||
if (bait.getDoubleLoot() != 0) doubleLoot += bait.getDoubleLoot();
|
||||
if (bait.getDifficulty() != 0) difficultyModifier += bait.getDifficulty();
|
||||
if (bait.getScoreModifier() != 0) scoreModifier *= bait.getScoreModifier();
|
||||
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<String, Integer> pm2 = new HashMap<>();
|
||||
HashMap<String, Double> mq2 = new HashMap<>();
|
||||
|
||||
ItemStack offHandItem = inventory.getItemInOffHand();
|
||||
if (offHandItem.getType() != Material.AIR){
|
||||
NBTItem offHand = new NBTItem(inventory.getItemInOffHand());
|
||||
NBTCompound offHandCompound = offHand.getCompound("CustomFishing");
|
||||
if (offHandCompound != null){
|
||||
if (offHandCompound.getString("type").equals("bait")) {
|
||||
String key = offHandCompound.getString("id");
|
||||
Bait bait = ConfigReader.BAIT.get(key);
|
||||
if (bait != null){
|
||||
pm2 = bait.getWeightPM();
|
||||
mq2 = bait.getWeightMQ();
|
||||
if (bait.getTime() != 0) timeModifier *= bait.getTime();
|
||||
if (bait.getDoubleLoot() != 0) doubleLoot += bait.getDoubleLoot();
|
||||
if (bait.getDifficulty() != 0) difficultyModifier += bait.getDifficulty();
|
||||
if (bait.getScoreModifier() != 0) scoreModifier *= bait.getScoreModifier();
|
||||
offHandItem.setAmount(offHandItem.getAmount() - 1);
|
||||
}
|
||||
}else if (noRod && offHandCompound.getString("type").equals("rod")){
|
||||
String key = offHandCompound.getString("id");
|
||||
Rod rod = ConfigReader.ROD.get(key);
|
||||
if (rod != null){
|
||||
pm2 = rod.getWeightPM();
|
||||
mq2 = rod.getWeightMQ();
|
||||
if (rod.getTime() != 0) timeModifier *= rod.getTime();
|
||||
if (rod.getDoubleLoot() != 0) doubleLoot += rod.getDoubleLoot();
|
||||
if (rod.getDifficulty() != 0) difficultyModifier += rod.getDifficulty();
|
||||
if (rod.getScoreModifier() != 0) scoreModifier *= rod.getScoreModifier();
|
||||
noRod = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//是否需要特殊鱼竿
|
||||
if (ConfigReader.Config.needSpecialRod && noRod){
|
||||
nextLoot.put(player, null);
|
||||
return;
|
||||
}
|
||||
|
||||
//时间修改
|
||||
FishHook hook = event.getHook();
|
||||
hook.setMaxWaitTime((int) (timeModifier * hook.getMaxWaitTime()));
|
||||
hook.setMinWaitTime((int) (timeModifier * hook.getMinWaitTime()));
|
||||
|
||||
//获取抛竿位置处可能的Loot实例列表
|
||||
List<Loot> possibleLoots = getPossibleLootList(new FishingCondition(player, hook.getLocation()));
|
||||
List<Loot> availableLoots = new ArrayList<>();
|
||||
|
||||
if (possibleLoots.size() == 0){
|
||||
nextLoot.put(player, null);
|
||||
return;
|
||||
}
|
||||
|
||||
Modifier modifier = new Modifier();
|
||||
modifier.setDifficultyModifier(difficultyModifier);
|
||||
modifier.setScoreModifier(scoreModifier);
|
||||
modifier.setWillDouble(doubleLoot > Math.random());
|
||||
//修改
|
||||
modifiers.put(player, modifier);
|
||||
|
||||
double[] weights = new double[possibleLoots.size()];
|
||||
int index = 0;
|
||||
for (Loot loot : possibleLoots){
|
||||
double weight = loot.getWeight();
|
||||
String group = loot.getGroup();
|
||||
if (group != null){
|
||||
if (pm1 != null && pm1.get(group) != null){
|
||||
weight += pm1.get(group);
|
||||
}
|
||||
if (pm2!= null && pm2.get(group) != null){
|
||||
weight += pm2.get(group);
|
||||
}
|
||||
if (mq1 != null && mq1.get(group) != null){
|
||||
weight *= mq1.get(group);
|
||||
}
|
||||
if (mq2 != null && mq2.get(group) != null){
|
||||
weight *= mq2.get(group);
|
||||
}
|
||||
}
|
||||
if (weight <= 0) continue;
|
||||
availableLoots.add(loot);
|
||||
weights[index++] = weight;
|
||||
}
|
||||
|
||||
double total = Arrays.stream(weights).sum();
|
||||
double[] weightRatios = new double[index];
|
||||
for (int i = 0; i < index; i++){
|
||||
weightRatios[i] = weights[i]/total;
|
||||
}
|
||||
|
||||
double[] weightRange = new double[index];
|
||||
double startPos = 0;
|
||||
for (int i = 0; i < index; i++) {
|
||||
weightRange[i] = startPos + weightRatios[i];
|
||||
startPos += weightRatios[i];
|
||||
}
|
||||
|
||||
double random = Math.random();
|
||||
int pos = Arrays.binarySearch(weightRange, random);
|
||||
|
||||
if (pos < 0) {
|
||||
pos = -pos - 1;
|
||||
} else {
|
||||
nextLoot.put(player, availableLoots.get(pos));
|
||||
return;
|
||||
}
|
||||
if (pos < weightRange.length && random < weightRange[pos]) {
|
||||
nextLoot.put(player, availableLoots.get(pos));
|
||||
return;
|
||||
}
|
||||
nextLoot.put(player, null);
|
||||
});
|
||||
}
|
||||
|
||||
//咬钩
|
||||
else if (state.equals(PlayerFishEvent.State.BITE)){
|
||||
//如果没有特殊鱼就返回
|
||||
if (nextLoot.get(player) == null) return;
|
||||
//如果正在钓一个鱼了,那么也返回
|
||||
if (fishingPlayers.get(player) != null) return;
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()-> {
|
||||
|
||||
Loot lootInstance = nextLoot.get(player);
|
||||
|
||||
String layout = Optional.ofNullable(lootInstance.getLayout()).orElseGet(() ->{
|
||||
Object[] values = ConfigReader.LAYOUT.keySet().toArray();
|
||||
return (String) values[new Random().nextInt(values.length)];
|
||||
});
|
||||
|
||||
int difficulty = lootInstance.getDifficulty().getSpeed();
|
||||
difficulty += Objects.requireNonNullElse(modifiers.get(player).getDifficultyModifier(), 0);;
|
||||
if (difficulty < 1){
|
||||
difficulty = 1;
|
||||
}
|
||||
Difficulty difficult = new Difficulty(lootInstance.getDifficulty().getTimer(), difficulty);
|
||||
fishingPlayers.put(player,
|
||||
new FishingPlayer(System.currentTimeMillis() + lootInstance.getTime(),
|
||||
new Timer(player, difficult, layout)
|
||||
)
|
||||
);
|
||||
if (lootInstance.getHookMsg() != null){
|
||||
lootInstance.getHookMsg().forEach(msg -> {
|
||||
AdventureManager.playerMessage(player, msg.replace("{loot}",lootInstance.getNick()).replace("{player}", player.getName()));
|
||||
});
|
||||
}
|
||||
Bukkit.getScheduler().runTask(CustomFishing.instance, ()->{
|
||||
if (lootInstance.getHookCommands() != null){
|
||||
lootInstance.getHookCommands().forEach(command ->{
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("{player}", player.getName()));
|
||||
});
|
||||
}
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, lootInstance.getTime()/50,3));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//正常钓到鱼 & 正常收杆
|
||||
else if (state.equals(PlayerFishEvent.State.CAUGHT_FISH) || state.equals(PlayerFishEvent.State.REEL_IN)){
|
||||
//发现有特殊鱼,那么必须掉落特殊鱼
|
||||
if (fishingPlayers.get(player) != null){
|
||||
//清除原版战利品
|
||||
if (event.getCaught() != null){
|
||||
event.getCaught().remove();
|
||||
event.setExpToDrop(0);
|
||||
}
|
||||
Loot lootInstance = nextLoot.get(player);
|
||||
Layout layout = ConfigReader.LAYOUT.get(fishingPlayers.get(player).getTimer().getLayout());
|
||||
int last = (fishingPlayers.get(player).getTimer().getTimerTask().getProgress())/layout.getRange();
|
||||
fishingPlayers.remove(player);
|
||||
player.removePotionEffect(PotionEffectType.SLOW);
|
||||
if (ConfigReader.Config.needOpenWater && !event.getHook().isInOpenWater()){
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.notOpenWater);
|
||||
return;
|
||||
}
|
||||
if (Math.random() < layout.getSuccessRate()[last]){
|
||||
//捕鱼成功
|
||||
Location location = event.getHook().getLocation();
|
||||
//钓上来的是MM怪吗
|
||||
if (lootInstance.getMm() != null){
|
||||
MythicMobsUtils.summonMM(player.getLocation(), location, lootInstance);
|
||||
}else {
|
||||
ItemStack itemStack = ConfigReader.LOOTITEM.get(lootInstance.getKey());
|
||||
if (itemStack.getType() != Material.AIR) {
|
||||
Entity item = location.getWorld().dropItem(location, itemStack);
|
||||
Vector vector = player.getLocation().subtract(location).toVector().multiply(0.1);
|
||||
vector = vector.setY((vector.getY()+0.2)*1.2);
|
||||
item.setVelocity(vector);
|
||||
if (modifiers.get(player).willDouble()){
|
||||
Entity item2 = location.getWorld().dropItem(location, itemStack);
|
||||
item2.setVelocity(vector);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lootInstance.getMsg() != null){
|
||||
lootInstance.getMsg().forEach(msg -> {
|
||||
AdventureManager.playerMessage(player, msg.replace("{loot}",lootInstance.getNick()).replace("{player}", player.getName()));
|
||||
});
|
||||
}
|
||||
if (lootInstance.getCommands() != null){
|
||||
lootInstance.getCommands().forEach(command ->{
|
||||
String finalCommand = command.
|
||||
replaceAll("\\{x}", String.valueOf(Math.round(location.getX()))).
|
||||
replaceAll("\\{y}", String.valueOf(Math.round(location.getY()))).
|
||||
replaceAll("\\{z}", String.valueOf(Math.round(location.getZ()))).
|
||||
replaceAll("\\{player}", player.getName()).
|
||||
replaceAll("\\{world}", player.getWorld().getName()).
|
||||
replaceAll("\\{loot}", lootInstance.getNick());
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), finalCommand);
|
||||
});
|
||||
}
|
||||
if (lootInstance.getExp() != 0){
|
||||
player.giveExp(lootInstance.getExp(),true);
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,1);
|
||||
}
|
||||
if (lootInstance.getSkillXP() != 0){
|
||||
ConfigReader.Config.skillXP.addXp(player, lootInstance.getSkillXP());
|
||||
}
|
||||
if (ConfigReader.Config.loseDurability){
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
ItemStack mainHand = inventory.getItemInMainHand();
|
||||
if (mainHand.getType() == Material.FISHING_ROD){
|
||||
Damageable damageable = (Damageable) mainHand.getItemMeta();
|
||||
if (damageable.hasDamage()) System.out.println(1);
|
||||
damageable.setDamage(damageable.getDamage() + 1);
|
||||
Bukkit.getScheduler().runTaskLater(CustomFishing.instance, ()->{
|
||||
mainHand.setItemMeta((ItemMeta) damageable);
|
||||
},1);
|
||||
}else {
|
||||
ItemStack offHand = inventory.getItemInOffHand();
|
||||
if (offHand.getType() == Material.FISHING_ROD){
|
||||
Damageable damageable = (Damageable) offHand.getItemMeta();
|
||||
damageable.setDamage(damageable.getDamage() + 1);
|
||||
Bukkit.getScheduler().runTaskLater(CustomFishing.instance, ()->{
|
||||
offHand.setItemMeta((ItemMeta) damageable);
|
||||
},1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()){
|
||||
float score = (float) (lootInstance.getScore() * modifiers.get(player).getScoreModifier());
|
||||
CompetitionSchedule.competition.refreshRanking(player.getName(), score);
|
||||
BossBarManager.joinCompetition(player);
|
||||
}
|
||||
//发送Title
|
||||
AdventureManager.playerTitle(player, ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random())).replace("{loot}",lootInstance.getNick()), ConfigReader.Title.success_subtitle.get((int) (ConfigReader.Title.success_subtitle.size()*Math.random())).replace("{loot}",lootInstance.getNick()), ConfigReader.Title.success_in, ConfigReader.Title.success_stay, ConfigReader.Title.success_out);
|
||||
}else {
|
||||
//移除正在钓鱼的状态
|
||||
fishingPlayers.remove(player);
|
||||
//捕鱼失败Title
|
||||
AdventureManager.playerTitle(player, ConfigReader.Title.failure_title.get((int) (ConfigReader.Title.failure_title.size()*Math.random())), ConfigReader.Title.failure_subtitle.get((int) (ConfigReader.Title.failure_subtitle.size()*Math.random())), ConfigReader.Title.failure_in, ConfigReader.Title.failure_stay, ConfigReader.Title.failure_out);
|
||||
}
|
||||
}
|
||||
//筛选后发现这个地方没有特殊鱼
|
||||
else {
|
||||
//是否能钓到原版掉落物
|
||||
if (!ConfigReader.Config.vanillaDrop){
|
||||
if (event.getCaught() != null){
|
||||
event.getCaught().remove();
|
||||
}
|
||||
event.setExpToDrop(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQUit(PlayerQuitEvent event){
|
||||
Player player = event.getPlayer();
|
||||
player.removePotionEffect(PotionEffectType.SLOW);
|
||||
if (hooks.get(player) != null){
|
||||
hooks.get(player).remove();
|
||||
}
|
||||
hooks.remove(player);
|
||||
coolDown.remove(player);
|
||||
nextLoot.remove(player);
|
||||
modifiers.remove(player);
|
||||
fishingPlayers.remove(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent event){
|
||||
if (!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
|
||||
ItemStack itemStack = event.getItem();
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) return;
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
if (nbtItem.getCompound("CustomFishing") == null) return;
|
||||
if (nbtItem.getCompound("CustomFishing").getString("type").equals("util") && nbtItem.getCompound("CustomFishing").getString("id").equals("fishfinder")){
|
||||
Player player = event.getPlayer();
|
||||
//设置冷却时间
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - ConfigReader.Config.fishFinderCoolDown)) < ConfigReader.Config.fishFinderCoolDown) {
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.coolDown);
|
||||
return;
|
||||
}
|
||||
coolDown.put(player, time);
|
||||
//获取玩家位置处可能的Loot实例列表
|
||||
List<Loot> possibleLoots = getFinder(new FishingCondition(player, player.getLocation()));
|
||||
if (possibleLoots.size() == 0){
|
||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.noLoot);
|
||||
return;
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder(ConfigReader.Message.prefix + ConfigReader.Message.possibleLoots);
|
||||
possibleLoots.forEach(loot -> stringBuilder.append(loot.getNick()).append(ConfigReader.Message.splitChar));
|
||||
AdventureManager.playerMessage(player, stringBuilder.substring(0, stringBuilder.length()-ConfigReader.Message.splitChar.length()));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
获取可能的Loot列表
|
||||
*/
|
||||
private List<Loot> getPossibleLootList(FishingCondition fishingCondition) {
|
||||
List<Loot> available = new ArrayList<>();
|
||||
ConfigReader.LOOT.keySet().forEach(key -> {
|
||||
Loot loot = ConfigReader.LOOT.get(key);
|
||||
List<Requirement> requirements = loot.getRequirements();
|
||||
if (requirements == null){
|
||||
available.add(loot);
|
||||
}else {
|
||||
boolean isMet = true;
|
||||
for (Requirement requirement : requirements){
|
||||
if (!requirement.isConditionMet(fishingCondition)){
|
||||
isMet = false;
|
||||
}
|
||||
}
|
||||
if (isMet){
|
||||
available.add(loot);
|
||||
}
|
||||
}
|
||||
});
|
||||
return available;
|
||||
}
|
||||
|
||||
private List<Loot> getFinder(FishingCondition fishingCondition) {
|
||||
List<Loot> available = new ArrayList<>();
|
||||
ConfigReader.LOOT.keySet().forEach(key -> {
|
||||
Loot loot = ConfigReader.LOOT.get(key);
|
||||
if (!loot.isShowInFinder()) return;
|
||||
List<Requirement> requirements = loot.getRequirements();
|
||||
if (requirements == null){
|
||||
available.add(loot);
|
||||
}else {
|
||||
boolean isMet = true;
|
||||
for (Requirement requirement : requirements){
|
||||
if (!requirement.isConditionMet(fishingCondition)){
|
||||
isMet = false;
|
||||
}
|
||||
}
|
||||
if (isMet){
|
||||
available.add(loot);
|
||||
}
|
||||
}
|
||||
});
|
||||
return available;
|
||||
}
|
||||
}
|
||||
61
src/main/java/net/momirealms/customfishing/object/Bonus.java
Normal file
61
src/main/java/net/momirealms/customfishing/object/Bonus.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package net.momirealms.customfishing.object;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Bonus {
|
||||
|
||||
private HashMap<String, Double> weightMQ;
|
||||
private HashMap<String, Integer> weightPM;
|
||||
private double time;
|
||||
private double score;
|
||||
private int difficulty;
|
||||
private double doubleLoot;
|
||||
|
||||
public HashMap<String, Double> getWeightMQ() {
|
||||
return weightMQ;
|
||||
}
|
||||
|
||||
public void setWeightMQ(HashMap<String, Double> weightMQ) {
|
||||
this.weightMQ = weightMQ;
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getWeightPM() {
|
||||
return weightPM;
|
||||
}
|
||||
|
||||
public void setWeightPM(HashMap<String, Integer> weightPM) {
|
||||
this.weightPM = weightPM;
|
||||
}
|
||||
|
||||
public double getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(double time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public double getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(double score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public int getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public void setDifficulty(int difficulty) {
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
|
||||
public double getDoubleLoot() {
|
||||
return doubleLoot;
|
||||
}
|
||||
|
||||
public void setDoubleLoot(double doubleLoot) {
|
||||
this.doubleLoot = doubleLoot;
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,15 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.titlebar;
|
||||
package net.momirealms.customfishing.object;
|
||||
|
||||
public record Difficulty(int timer, int speed) {
|
||||
public int getTimer() {return this.timer;}
|
||||
public int getSpeed() {return this.speed;}
|
||||
|
||||
public int getTimer() {
|
||||
return this.timer;
|
||||
}
|
||||
|
||||
public int getSpeed() {
|
||||
return this.speed;
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,17 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.titlebar;
|
||||
package net.momirealms.customfishing.object;
|
||||
|
||||
import net.momirealms.customfishing.titlebar.Timer;
|
||||
|
||||
public record FishingPlayer(Long fishingTime, Timer timer) {
|
||||
public Long getFishingTime() {return this.fishingTime;}
|
||||
public Timer getTimer() {return this.timer;}
|
||||
|
||||
public Long getFishingTime() {
|
||||
return this.fishingTime;
|
||||
}
|
||||
|
||||
public Timer getTimer() {
|
||||
return this.timer;
|
||||
}
|
||||
}
|
||||
82
src/main/java/net/momirealms/customfishing/object/Item.java
Normal file
82
src/main/java/net/momirealms/customfishing/object/Item.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package net.momirealms.customfishing.object;
|
||||
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Item {
|
||||
|
||||
private final String material;
|
||||
private String name;
|
||||
private List<String> lore;
|
||||
private List<ItemFlag> itemFlags;
|
||||
private int customModelData;
|
||||
private boolean unbreakable;
|
||||
private List<LeveledEnchantment> enchantment;
|
||||
private Map<String, Object> nbt;
|
||||
|
||||
public Item(String material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public Map<String, Object> getNbt() {
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public void setNbt(Map<String, Object> nbt) {
|
||||
this.nbt = nbt;
|
||||
}
|
||||
|
||||
public String getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<String> getLore() {
|
||||
return lore;
|
||||
}
|
||||
|
||||
public void setLore(List<String> lore) {
|
||||
this.lore = lore;
|
||||
}
|
||||
|
||||
public List<ItemFlag> getItemFlags() {
|
||||
return itemFlags;
|
||||
}
|
||||
|
||||
public void setItemFlags(List<ItemFlag> itemFlags) {
|
||||
this.itemFlags = itemFlags;
|
||||
}
|
||||
|
||||
public int getCustomModelData() {
|
||||
return customModelData;
|
||||
}
|
||||
|
||||
public void setCustomModelData(int customModelData) {
|
||||
this.customModelData = customModelData;
|
||||
}
|
||||
|
||||
public boolean isUnbreakable() {
|
||||
return unbreakable;
|
||||
}
|
||||
|
||||
public void setUnbreakable(boolean unbreakable) {
|
||||
this.unbreakable = unbreakable;
|
||||
}
|
||||
|
||||
public List<LeveledEnchantment> getEnchantment() {
|
||||
return enchantment;
|
||||
}
|
||||
|
||||
public void setEnchantment(List<LeveledEnchantment> enchantment) {
|
||||
this.enchantment = enchantment;
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,10 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.titlebar;
|
||||
package net.momirealms.customfishing.object;
|
||||
|
||||
public class Layout {
|
||||
|
||||
private final String key;
|
||||
private final int range;
|
||||
private final double[] successRate;
|
||||
private final int size;
|
||||
@@ -32,8 +31,7 @@ public class Layout {
|
||||
private String pointerOffset;
|
||||
private String title;
|
||||
|
||||
public Layout(String key, int range, double[] successRate, int size){
|
||||
this.key = key;
|
||||
public Layout(int range, double[] successRate, int size){
|
||||
this.range = range;
|
||||
this.successRate = successRate;
|
||||
this.size = size;
|
||||
@@ -15,25 +15,34 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.competition.reward;
|
||||
package net.momirealms.customfishing.object;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
import java.util.List;
|
||||
public class LeveledEnchantment {
|
||||
|
||||
public class CommandImpl implements Reward{
|
||||
private final NamespacedKey key;
|
||||
private final int level;
|
||||
private double chance;
|
||||
|
||||
private final List<String> commands;
|
||||
|
||||
public CommandImpl(List<String> commands){
|
||||
this.commands = commands;
|
||||
public LeveledEnchantment(NamespacedKey key, int level){
|
||||
this.key = key;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveReward(Player player) {
|
||||
commands.forEach(command -> {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command.replace("{player}", player.getName()));
|
||||
});
|
||||
public void setChance(double chance) {
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public double getChance() {
|
||||
return chance;
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,15 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.utils;
|
||||
package net.momirealms.customfishing.object;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
public record MobVector(double horizontal, double vertical) {
|
||||
|
||||
public record Enchantment(NamespacedKey key, int level) {
|
||||
public int getLevel() {return level;}
|
||||
public NamespacedKey getKey() {return key;}
|
||||
public double getHorizontal() {
|
||||
return this.horizontal;
|
||||
}
|
||||
|
||||
public double getVertical() {
|
||||
return this.vertical;
|
||||
}
|
||||
}
|
||||
@@ -15,35 +15,44 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.utils;
|
||||
package net.momirealms.customfishing.object;
|
||||
|
||||
public class Modifier {
|
||||
|
||||
private int difficulty;
|
||||
private double score;
|
||||
private boolean willDouble;
|
||||
private boolean isVanilla;
|
||||
|
||||
public int getDifficultyModifier() {
|
||||
public int getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public void setDifficultyModifier(int difficulty) {
|
||||
public void setDifficulty(int difficulty) {
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
|
||||
public double getScoreModifier() {
|
||||
public double getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScoreModifier(double score) {
|
||||
public void setScore(double score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public boolean willDouble() {
|
||||
public boolean isWillDouble() {
|
||||
return willDouble;
|
||||
}
|
||||
|
||||
public void setWillDouble(boolean willDouble) {
|
||||
this.willDouble = willDouble;
|
||||
}
|
||||
|
||||
public boolean isVanilla() {
|
||||
return isVanilla;
|
||||
}
|
||||
|
||||
public void setVanilla(boolean vanilla) {
|
||||
isVanilla = vanilla;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.momirealms.customfishing.object;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class VanillaLoot {
|
||||
|
||||
private final ItemStack itemStack;
|
||||
private final int xp;
|
||||
|
||||
public VanillaLoot(ItemStack itemStack, int xp) {
|
||||
this.itemStack = itemStack;
|
||||
this.xp = xp;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public int getXp() {
|
||||
return xp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.momirealms.customfishing.object.action;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface ActionB {
|
||||
void doOn(Player player);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.momirealms.customfishing.object.action;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record CommandA(List<String> commands, String nick) implements ActionB {
|
||||
@Override
|
||||
public void doOn(Player player) {
|
||||
commands.forEach(command -> {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),
|
||||
command.
|
||||
replaceAll("\\{x}", String.valueOf(Math.round(player.getLocation().getX()))).
|
||||
replaceAll("\\{y}", String.valueOf(Math.round(player.getLocation().getY()))).
|
||||
replaceAll("\\{z}", String.valueOf(Math.round(player.getLocation().getZ()))).
|
||||
replaceAll("\\{player}", player.getName()).
|
||||
replaceAll("\\{world}", player.getWorld().getName()).
|
||||
replaceAll("\\{loot}", nick)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.momirealms.customfishing.object.action;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record CommandB(List<String> commands) implements ActionB{
|
||||
|
||||
@Override
|
||||
public void doOn(Player player) {
|
||||
commands.forEach(command -> {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),
|
||||
command.
|
||||
replaceAll("\\{x}", String.valueOf(Math.round(player.getLocation().getX()))).
|
||||
replaceAll("\\{y}", String.valueOf(Math.round(player.getLocation().getY()))).
|
||||
replaceAll("\\{z}", String.valueOf(Math.round(player.getLocation().getZ()))).
|
||||
replaceAll("\\{player}", player.getName()).
|
||||
replaceAll("\\{world}", player.getWorld().getName())
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.momirealms.customfishing.object.action;
|
||||
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public record FishingXPB(int amount) implements ActionB {
|
||||
|
||||
@Override
|
||||
public void doOn(Player player) {
|
||||
if (ConfigReader.Config.skillXP != null){
|
||||
ConfigReader.Config.skillXP.addXp(player, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.momirealms.customfishing.object.action;
|
||||
|
||||
import net.momirealms.customfishing.utils.AdventureUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record MessageA(List<String> messages, String loot) implements ActionB{
|
||||
|
||||
@Override
|
||||
public void doOn(Player player) {
|
||||
messages.forEach(message -> {
|
||||
AdventureUtil.playerMessage(player, message.replace("{loot}", loot));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.momirealms.customfishing.object.action;
|
||||
|
||||
import net.momirealms.customfishing.utils.AdventureUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record MessageB(List<String> messages) implements ActionB {
|
||||
|
||||
@Override
|
||||
public void doOn(Player player) {
|
||||
messages.forEach(message -> {
|
||||
AdventureUtil.playerMessage(player, message);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.momirealms.customfishing.object.action;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public record XPA(int amount) implements ActionB {
|
||||
|
||||
@Override
|
||||
public void doOn(Player player) {
|
||||
player.giveExp(amount, true);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.momirealms.customfishing.object.action;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public record XPB(int amount) implements ActionB {
|
||||
|
||||
@Override
|
||||
public void doOn(Player player) {
|
||||
player.giveExp(amount, false);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.momirealms.customfishing.object.loot;
|
||||
|
||||
import net.momirealms.customfishing.object.LeveledEnchantment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DroppedItem extends Loot{
|
||||
|
||||
boolean randomDurability;
|
||||
List<LeveledEnchantment> randomEnchants;
|
||||
String type;
|
||||
String id;
|
||||
|
||||
public DroppedItem(String key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
public boolean isRandomDurability() {
|
||||
return randomDurability;
|
||||
}
|
||||
|
||||
public void setRandomDurability(boolean randomDurability) {
|
||||
this.randomDurability = randomDurability;
|
||||
}
|
||||
|
||||
public List<LeveledEnchantment> getRandomEnchants() {
|
||||
return randomEnchants;
|
||||
}
|
||||
|
||||
public void setRandomEnchants(List<LeveledEnchantment> randomEnchants) {
|
||||
this.randomEnchants = randomEnchants;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
132
src/main/java/net/momirealms/customfishing/object/loot/Loot.java
Normal file
132
src/main/java/net/momirealms/customfishing/object/loot/Loot.java
Normal file
@@ -0,0 +1,132 @@
|
||||
package net.momirealms.customfishing.object.loot;
|
||||
|
||||
import net.momirealms.customfishing.object.Difficulty;
|
||||
import net.momirealms.customfishing.object.action.ActionB;
|
||||
import net.momirealms.customfishing.requirements.Requirement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Loot {
|
||||
|
||||
String key;
|
||||
String nick;
|
||||
Difficulty difficulty;
|
||||
String group;
|
||||
boolean showInFinder;
|
||||
List<String> layout;
|
||||
List<ActionB> successActions;
|
||||
List<ActionB> failureActions;
|
||||
List<ActionB> hookActions;
|
||||
int weight;
|
||||
int time;
|
||||
List<Requirement> requirements;
|
||||
double score;
|
||||
|
||||
public Loot(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public List<ActionB> getHookActions() {
|
||||
return hookActions;
|
||||
}
|
||||
|
||||
public void setHookActions(List<ActionB> hookActions) {
|
||||
this.hookActions = hookActions;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public List<ActionB> getSuccessActions() {
|
||||
return successActions;
|
||||
}
|
||||
|
||||
public void setSuccessActions(List<ActionB> successActions) {
|
||||
this.successActions = successActions;
|
||||
}
|
||||
|
||||
public List<ActionB> getFailureActions() {
|
||||
return failureActions;
|
||||
}
|
||||
|
||||
public void setFailureActions(List<ActionB> failureActions) {
|
||||
this.failureActions = failureActions;
|
||||
}
|
||||
|
||||
public String getNick() {
|
||||
return nick;
|
||||
}
|
||||
|
||||
public void setNick(String nick) {
|
||||
this.nick = nick;
|
||||
}
|
||||
|
||||
public List<String> getLayout() {
|
||||
return layout;
|
||||
}
|
||||
|
||||
public void setLayout(List<String> layout) {
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
public Difficulty getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public void setDifficulty(Difficulty difficulty) {
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public boolean isShowInFinder() {
|
||||
return showInFinder;
|
||||
}
|
||||
|
||||
public void setShowInFinder(boolean showInFinder) {
|
||||
this.showInFinder = showInFinder;
|
||||
}
|
||||
|
||||
public int getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(int weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(int time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public List<Requirement> getRequirements() {
|
||||
return requirements;
|
||||
}
|
||||
|
||||
public void setRequirements(List<Requirement> requirements) {
|
||||
this.requirements = requirements;
|
||||
}
|
||||
|
||||
public double getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(double score) {
|
||||
this.score = score;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.momirealms.customfishing.object.loot;
|
||||
|
||||
import net.momirealms.customfishing.object.MobVector;
|
||||
|
||||
public class Mob extends Loot{
|
||||
|
||||
final String mmID;
|
||||
int mmLevel;
|
||||
MobVector mobVector;
|
||||
|
||||
public Mob(String key, String mmID) {
|
||||
super(key);
|
||||
this.mmID = mmID;
|
||||
}
|
||||
|
||||
public String getMmID() {
|
||||
return mmID;
|
||||
}
|
||||
|
||||
public int getMmLevel() {
|
||||
return mmLevel;
|
||||
}
|
||||
|
||||
public void setMmLevel(int mmLevel) {
|
||||
this.mmLevel = mmLevel;
|
||||
}
|
||||
|
||||
public MobVector getMobVector() {
|
||||
return mobVector;
|
||||
}
|
||||
|
||||
public void setMobVector(MobVector mobVector) {
|
||||
this.mobVector = mobVector;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package net.momirealms.customfishing.requirements;
|
||||
|
||||
import net.momirealms.customfishing.requirements.papi.*;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CustomPapi implements Requirement {
|
||||
|
||||
public static HashSet<String> allPapi = new HashSet<>();
|
||||
|
||||
private PapiRequirement papiRequirement;
|
||||
|
||||
public CustomPapi(Map<String, Object> expressions){
|
||||
expressions.keySet().forEach(key -> {
|
||||
if (key.equals("&&")){
|
||||
List<PapiRequirement> papiRequirements = new ArrayList<>();
|
||||
if (expressions.get(key) instanceof MemorySection map2){
|
||||
addAndRequirements(papiRequirements, map2.getValues(false));
|
||||
}
|
||||
papiRequirement = new ExpressionAnd(papiRequirements);
|
||||
}else if (key.equals("||")){
|
||||
List<PapiRequirement> papiRequirements = new ArrayList<>();
|
||||
if (expressions.get(key) instanceof MemorySection map2){
|
||||
addOrRequirements(papiRequirements, map2.getValues(false));
|
||||
}
|
||||
papiRequirement = new ExpressionOr(papiRequirements);
|
||||
}else {
|
||||
if (expressions.get(key) instanceof MemorySection map){
|
||||
String type = map.getString("type");
|
||||
String papi = map.getString("papi");
|
||||
String value = map.getString("value");
|
||||
allPapi.add(papi);
|
||||
switch (type){
|
||||
case "==" -> papiRequirement = new PapiEquals(papi, value);
|
||||
case ">=" -> papiRequirement = new PapiNoLess(papi, Double.parseDouble(value));
|
||||
case "<=" -> papiRequirement = new PapiNoLarger(papi, Double.parseDouble(value));
|
||||
case "<" -> papiRequirement = new PapiSmaller(papi, Double.parseDouble(value));
|
||||
case ">" -> papiRequirement = new PapiGreater(papi, Double.parseDouble(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(FishingCondition fishingCondition) {
|
||||
return papiRequirement.isMet(fishingCondition.getPapiMap());
|
||||
}
|
||||
|
||||
private void addAndRequirements(List<PapiRequirement> requirements, Map<String, Object> map){
|
||||
List<PapiRequirement> andRequirements = new ArrayList<>();
|
||||
map.keySet().forEach(key -> {
|
||||
if (key.equals("&&")){
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
addAndRequirements(andRequirements, map2.getValues(false));
|
||||
}
|
||||
}else if (key.equals("||")){
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
addOrRequirements(andRequirements, map2.getValues(false));
|
||||
}
|
||||
}else {
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
String type = map2.getString("type");
|
||||
String papi = map2.getString("papi");
|
||||
String value = map2.getString("value");
|
||||
allPapi.add(papi);
|
||||
switch (type){
|
||||
case "==" -> andRequirements.add(new PapiEquals(papi, value));
|
||||
case ">=" -> andRequirements.add(new PapiNoLess(papi, Double.parseDouble(value)));
|
||||
case "<=" -> andRequirements.add(new PapiNoLarger(papi, Double.parseDouble(value)));
|
||||
case "<" -> andRequirements.add(new PapiSmaller(papi, Double.parseDouble(value)));
|
||||
case ">" -> andRequirements.add(new PapiGreater(papi, Double.parseDouble(value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
requirements.add(new ExpressionAnd(andRequirements));
|
||||
}
|
||||
|
||||
private void addOrRequirements(List<PapiRequirement> requirements, Map<String, Object> map){
|
||||
List<PapiRequirement> orRequirements = new ArrayList<>();
|
||||
map.keySet().forEach(key -> {
|
||||
if (key.equals("&&")){
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
addAndRequirements(orRequirements, map2.getValues(false));
|
||||
}
|
||||
}else if (key.equals("||")){
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
addOrRequirements(orRequirements, map2.getValues(false));
|
||||
}
|
||||
}else {
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
String type = map2.getString("type");
|
||||
String papi = map2.getString("papi");
|
||||
String value = map2.getString("value");
|
||||
allPapi.add(papi);
|
||||
switch (type){
|
||||
case "==" -> orRequirements.add(new PapiEquals(papi, value));
|
||||
case ">=" -> orRequirements.add(new PapiNoLess(papi, Double.parseDouble(value)));
|
||||
case "<=" -> orRequirements.add(new PapiNoLarger(papi, Double.parseDouble(value)));
|
||||
case "<" -> orRequirements.add(new PapiSmaller(papi, Double.parseDouble(value)));
|
||||
case ">" -> orRequirements.add(new PapiGreater(papi, Double.parseDouble(value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
requirements.add(new ExpressionOr(orRequirements));
|
||||
}
|
||||
}
|
||||
@@ -17,13 +17,48 @@
|
||||
|
||||
package net.momirealms.customfishing.requirements;
|
||||
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import net.momirealms.customfishing.hook.PapiHook;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public record FishingCondition(Player player, Location location) {
|
||||
import java.util.HashMap;
|
||||
|
||||
public class FishingCondition{
|
||||
|
||||
private final Location location;
|
||||
private final Player player;
|
||||
private HashMap<String, String> papiMap;
|
||||
|
||||
public FishingCondition(Location location, Player player) {
|
||||
this.location = location;
|
||||
this.player = player;
|
||||
if (ConfigReader.Config.papi){
|
||||
this.papiMap = new HashMap<>();
|
||||
CustomPapi.allPapi.forEach(papi -> {
|
||||
this.papiMap.put(papi, PapiHook.parse(player, papi));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, String> getPapiMap() {
|
||||
return papiMap;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public Location getLocation() { return location; }
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FishingCondition{" +
|
||||
"location=" + location +
|
||||
", player=" + player +
|
||||
", papiMap=" + papiMap +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,7 @@
|
||||
|
||||
package net.momirealms.customfishing.requirements;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import net.momirealms.customfishing.hook.CustomCropsSeason;
|
||||
import net.momirealms.customfishing.hook.RealisticSeason;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -33,14 +29,7 @@ public record Season(List<String> seasons) implements Requirement {
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(FishingCondition fishingCondition) {
|
||||
String currentSeason;
|
||||
if (ConfigReader.Config.rsSeason){
|
||||
currentSeason = RealisticSeason.getSeason(fishingCondition.getLocation().getWorld());
|
||||
}else if(ConfigReader.Config.ccSeason){
|
||||
currentSeason = CustomCropsSeason.getSeason(fishingCondition.getLocation().getWorld());
|
||||
}else {
|
||||
currentSeason = ChatColor.stripColor(PlaceholderAPI.setPlaceholders(fishingCondition.getPlayer(), ConfigReader.Config.season_papi));
|
||||
}
|
||||
String currentSeason = ConfigReader.Config.season.getSeason(fishingCondition.getLocation().getWorld());
|
||||
for (String season : seasons) {
|
||||
if (season.equalsIgnoreCase(currentSeason)) {
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.momirealms.customfishing.requirements;
|
||||
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
|
||||
public record SkillLevel(int level) implements Requirement{
|
||||
@Override
|
||||
public boolean isConditionMet(FishingCondition fishingCondition) {
|
||||
return level <= ConfigReader.Config.skillXP.getLevel(fishingCondition.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package net.momirealms.customfishing.requirements;
|
||||
|
||||
import net.momirealms.customfishing.utils.AdventureManager;
|
||||
import net.momirealms.customfishing.utils.AdventureUtil;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.List;
|
||||
@@ -47,7 +47,6 @@ public record Weather(List<String> weathers) implements Requirement {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] 这条消息不应该出现,玩家钓鱼时所处的世界并不存在!</red>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package net.momirealms.customfishing.requirements;
|
||||
|
||||
import net.momirealms.customfishing.utils.AdventureManager;
|
||||
import net.momirealms.customfishing.utils.AdventureUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -33,7 +33,6 @@ public record World(List<String> worlds) implements Requirement {
|
||||
if (world != null) {
|
||||
return worlds.contains(world.getName());
|
||||
}
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] 这条消息不应该出现,玩家钓鱼时所处的世界并不存在!</red>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.momirealms.customfishing.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public record ExpressionAnd(List<PapiRequirement> requirements) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
for (PapiRequirement requirement : requirements) {
|
||||
if (!requirement.isMet(papiMap)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.momirealms.customfishing.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public record ExpressionOr(List<PapiRequirement> requirements) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
for (PapiRequirement requirement : requirements) {
|
||||
if (requirement.isMet(papiMap)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.momirealms.customfishing.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public record PapiEquals(String papi, String requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
String value = papiMap.get(papi);
|
||||
return Objects.equals(value, requirement);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.momirealms.customfishing.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public record PapiGreater(String papi, double requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
double value = Double.parseDouble(papiMap.get(papi));
|
||||
return value > requirement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.momirealms.customfishing.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public record PapiNoLarger(String papi, double requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
double value = Double.parseDouble(papiMap.get(papi));
|
||||
return value <= requirement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.momirealms.customfishing.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public record PapiNoLess(String papi, double requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
double value = Double.parseDouble(papiMap.get(papi));
|
||||
return value >= requirement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.momirealms.customfishing.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface PapiRequirement {
|
||||
boolean isMet(HashMap<String, String> papiMap);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.momirealms.customfishing.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public record PapiSmaller(String papi, double requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
double value = Double.parseDouble(papiMap.get(papi));
|
||||
return value < requirement;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
package net.momirealms.customfishing.titlebar;
|
||||
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.object.Difficulty;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
|
||||
package net.momirealms.customfishing.titlebar;
|
||||
|
||||
import net.momirealms.customfishing.utils.AdventureManager;
|
||||
import net.momirealms.customfishing.object.Layout;
|
||||
import net.momirealms.customfishing.utils.AdventureUtil;
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.titlebar.Difficulty;
|
||||
import net.momirealms.customfishing.titlebar.Layout;
|
||||
import net.momirealms.customfishing.object.Difficulty;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -30,7 +30,7 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import static net.momirealms.customfishing.listener.PlayerListener.fishingPlayers;
|
||||
import static net.momirealms.customfishing.listener.FishListener.fishingPlayers;
|
||||
|
||||
public class TimerTask extends BukkitRunnable {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TimerTask extends BukkitRunnable {
|
||||
private int internalTimer;
|
||||
private final int size;
|
||||
private boolean face;
|
||||
private BukkitScheduler bukkitScheduler;
|
||||
private final BukkitScheduler bukkitScheduler;
|
||||
|
||||
private final String start;
|
||||
private final String bar;
|
||||
@@ -83,6 +83,7 @@ public class TimerTask extends BukkitRunnable {
|
||||
}
|
||||
//移除超时玩家
|
||||
if (System.currentTimeMillis() > fishingPlayers.get(player).getFishingTime()){
|
||||
AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.escape);
|
||||
fishingPlayers.remove(player);
|
||||
bukkitScheduler.cancelTask(taskID);
|
||||
return;
|
||||
@@ -118,7 +119,7 @@ public class TimerTask extends BukkitRunnable {
|
||||
}
|
||||
}
|
||||
stringBuilder.append(end);
|
||||
AdventureManager.playerTitle(player, title, stringBuilder.toString(),0,300,0);
|
||||
AdventureUtil.playerTitle(player, title, stringBuilder.toString(),0,300,0);
|
||||
//移除切换物品的玩家
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
if (playerInventory.getItemInMainHand().getType() != Material.FISHING_ROD && playerInventory.getItemInOffHand().getType() != Material.FISHING_ROD){
|
||||
|
||||
@@ -21,7 +21,6 @@ import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -29,7 +28,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class AdventureManager {
|
||||
public class AdventureUtil {
|
||||
|
||||
public static void consoleMessage(String s) {
|
||||
Audience au = CustomFishing.adventure.sender(Bukkit.getConsoleSender());
|
||||
@@ -50,6 +49,13 @@ public class AdventureManager {
|
||||
au.showTitle(title);
|
||||
}
|
||||
|
||||
public static void playerTitle(Player player, Component s1, Component s2, int in, int duration, int out) {
|
||||
Audience au = CustomFishing.adventure.player(player);
|
||||
Title.Times times = Title.Times.times(Duration.ofMillis(in), Duration.ofMillis(duration), Duration.ofMillis(out));
|
||||
Title title = Title.title(s1, s2, times);
|
||||
au.showTitle(title);
|
||||
}
|
||||
|
||||
public static void playerActionbar(Player player, String s) {
|
||||
Audience au = CustomFishing.adventure.player(player);
|
||||
au.sendActionBar(CustomFishing.miniMessage.deserialize(s));
|
||||
@@ -12,7 +12,7 @@ import net.momirealms.customfishing.helper.Log;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class UpdateConfig {
|
||||
public class ConfigUtil {
|
||||
|
||||
public static void update(){
|
||||
try {
|
||||
@@ -22,19 +22,21 @@ import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.momirealms.customfishing.item.Item;
|
||||
import net.momirealms.customfishing.object.Item;
|
||||
import net.momirealms.customfishing.object.LeveledEnchantment;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemStackGenerator {
|
||||
|
||||
public static ItemStack fromItem(Item item){
|
||||
public class ItemStackUtil {
|
||||
|
||||
public static ItemStack getFromItem(Item item){
|
||||
ItemStack itemStack = new ItemStack(Material.valueOf(item.getMaterial().toUpperCase()));
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (item.getCustomModelData() != 0){
|
||||
@@ -46,49 +48,79 @@ public class ItemStackGenerator {
|
||||
if (item.getItemFlags() != null){
|
||||
item.getItemFlags().forEach(itemMeta::addItemFlags);
|
||||
}
|
||||
if (item.getEnchantments() != null) {
|
||||
if (item.getEnchantment() != null) {
|
||||
if (itemStack.getType() == Material.ENCHANTED_BOOK){
|
||||
EnchantmentStorageMeta meta = (EnchantmentStorageMeta)itemMeta;
|
||||
item.getEnchantments().forEach(enchantment1 -> {
|
||||
meta.addStoredEnchant(org.bukkit.enchantments.Enchantment.getByKey(enchantment1.getKey()),enchantment1.getLevel(),true);
|
||||
});
|
||||
item.getEnchantment().forEach(enchantment -> meta.addStoredEnchant(Objects.requireNonNull(Enchantment.getByKey(enchantment.getKey())),enchantment.getLevel(),true));
|
||||
itemStack.setItemMeta(meta);
|
||||
}else {
|
||||
item.getEnchantments().forEach(enchantment1 -> {
|
||||
itemMeta.addEnchant(Enchantment.getByKey(enchantment1.getKey()),enchantment1.getLevel(),true);
|
||||
});
|
||||
item.getEnchantment().forEach(enchantment -> itemMeta.addEnchant(Objects.requireNonNull(Enchantment.getByKey(enchantment.getKey())),enchantment.getLevel(),true));
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
}else {
|
||||
}
|
||||
else {
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
NBTCompound display = nbtItem.addCompound("display");
|
||||
if (item.getName() != null){
|
||||
NBTCompound display = nbtItem.addCompound("display");
|
||||
String name = item.getName();
|
||||
if (name.contains("&") || name.contains("§")){
|
||||
name = name.replaceAll("&","§");
|
||||
display.setString("Name", GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(name)));
|
||||
}else {
|
||||
display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>" + name)));
|
||||
display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<!i>" + name)));
|
||||
}
|
||||
}
|
||||
if(item.getLore() != null){
|
||||
NBTCompound display = nbtItem.addCompound("display");
|
||||
List<String> lore = display.getStringList("Lore");
|
||||
item.getLore().forEach(line -> {
|
||||
if (line.contains("&") || line.contains("§")){
|
||||
line = line.replaceAll("&","§");
|
||||
lore.add(GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(line)));
|
||||
}else {
|
||||
lore.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>" + line)));
|
||||
lore.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<!i>" + line)));
|
||||
}
|
||||
});
|
||||
}
|
||||
if (item.getNbt() != null){
|
||||
NBTUtil nbtUtil = new NBTUtil(item.getNbt(), nbtItem.getItem());
|
||||
return nbtUtil.getNBTItem().getItem();
|
||||
NBTUtil.setTags(item.getNbt(), nbtItem);
|
||||
}
|
||||
return nbtItem.getItem();
|
||||
}
|
||||
|
||||
public static void addRandomEnchants(ItemStack itemStack, List<LeveledEnchantment> enchantments){
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemStack.getType() == Material.ENCHANTED_BOOK){
|
||||
EnchantmentStorageMeta meta = (EnchantmentStorageMeta)itemMeta;
|
||||
enchantments.forEach(enchantment -> {
|
||||
if (enchantment.getChance() > Math.random()){
|
||||
meta.addStoredEnchant(Objects.requireNonNull(Enchantment.getByKey(enchantment.getKey())),enchantment.getLevel(),true);
|
||||
}
|
||||
});
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
else {
|
||||
enchantments.forEach(enchantment -> {
|
||||
if (enchantment.getChance() > Math.random()){
|
||||
itemMeta.addEnchant(Objects.requireNonNull(Enchantment.getByKey(enchantment.getKey())),enchantment.getLevel(),true);
|
||||
}
|
||||
});
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addRandomDamage(ItemStack itemStack){
|
||||
if (itemStack.getItemMeta() instanceof Damageable damageable){
|
||||
damageable.setDamage((int) (itemStack.getType().getMaxDurability() * Math.random()));
|
||||
itemStack.setItemMeta((ItemMeta) damageable);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addOwner(ItemStack itemStack, String name){
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
nbtItem.setString("M_Owner", name);
|
||||
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,11 @@ package net.momirealms.customfishing.utils;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
@@ -29,7 +31,34 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class SaveItem {
|
||||
public class ItemUtil {
|
||||
|
||||
public static void givePlayerLoot(Player player, String lootKey, int amount){
|
||||
ItemStack itemStack = ConfigReader.LootItem.get(lootKey);
|
||||
if (itemStack == null) return;
|
||||
itemStack.setAmount(amount);
|
||||
player.getInventory().addItem(itemStack);
|
||||
}
|
||||
|
||||
public static void givePlayerRod(Player player, String rodKey, int amount){
|
||||
ItemStack itemStack = ConfigReader.RodItem.get(rodKey);
|
||||
itemStack.setAmount(amount);
|
||||
player.getInventory().addItem(itemStack);
|
||||
}
|
||||
|
||||
public static void givePlayerBait(Player player, String baitKey, int amount){
|
||||
ItemStack itemStack = ConfigReader.BaitItem.get(baitKey);
|
||||
if (itemStack == null) return;
|
||||
itemStack.setAmount(amount);
|
||||
player.getInventory().addItem(itemStack);
|
||||
}
|
||||
|
||||
public static void givePlayerUtil(Player player, String utilKey, int amount){
|
||||
ItemStack itemStack = ConfigReader.UtilItem.get(utilKey);
|
||||
if (itemStack == null) return;
|
||||
itemStack.setAmount(amount);
|
||||
player.getInventory().addItem(itemStack);
|
||||
}
|
||||
|
||||
public static void saveToFile(ItemStack itemStack, String fileName){
|
||||
|
||||
@@ -53,11 +82,11 @@ public class SaveItem {
|
||||
yamlConfiguration.set(fileName + ".unbreakable", itemMeta.isUnbreakable());
|
||||
}
|
||||
if (itemMeta.hasEnchants()) {
|
||||
ArrayList<String> enchants = new ArrayList<>();
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
itemMeta.getEnchants().forEach((enchantment, level) -> {
|
||||
enchants.add(enchantment.getKey() + "/" + level);
|
||||
map.put(String.valueOf(enchantment.getKey()), level);
|
||||
});
|
||||
yamlConfiguration.set(fileName + ".enchantments", enchants);
|
||||
yamlConfiguration.createSection(fileName + ".enchantments", map);
|
||||
}
|
||||
if (itemMeta.getItemFlags().size() > 0){
|
||||
ArrayList<String> itemFlags = new ArrayList<>();
|
||||
@@ -70,16 +99,13 @@ public class SaveItem {
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
|
||||
Map<String, Object> map0 = compoundToMap(nbtItem);
|
||||
if (map0.size() != 0){
|
||||
ArrayList<Map<String, Object>> mapArrayList = new ArrayList<>();
|
||||
mapArrayList.add(map0);
|
||||
yamlConfiguration.set(fileName + ".nbt", mapArrayList);
|
||||
}
|
||||
yamlConfiguration.createSection(fileName + ".nbt", map0);
|
||||
|
||||
File file = new File(CustomFishing.instance.getDataFolder(), File.separator + "export" + File.separator + fileName + ".yml");
|
||||
File file = new File(CustomFishing.instance.getDataFolder(), File.separator + "loots" + File.separator + fileName + ".yml");
|
||||
|
||||
try {
|
||||
yamlConfiguration.save(file);
|
||||
ConfigReader.loadLoot();
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -88,12 +114,12 @@ public class SaveItem {
|
||||
public static Map<String, Object> compoundToMap(NBTCompound nbtCompound){
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
nbtCompound.getKeys().forEach(key -> {
|
||||
if (key.equals("Enchantments")) return;
|
||||
if (key.equals("Name")) return;
|
||||
if (key.equals("Lore")) return;
|
||||
if (key.equals("HideFlags")) return;
|
||||
if (key.equals("CustomModelData")) return;
|
||||
if (key.equals("Unbreakable")) return;
|
||||
if (key.equals("Enchantments")
|
||||
|| key.equals("Name")
|
||||
|| key.equals("Lore")
|
||||
|| key.equals("HideFlags")
|
||||
|| key.equals("CustomModelData")
|
||||
|| key.equals("Unbreakable")) return;
|
||||
switch (nbtCompound.getType(key)){
|
||||
case NBTTagByte -> map.put(key, "(Byte) " + nbtCompound.getByte(key));
|
||||
case NBTTagInt -> map.put(key, "(Int) " + nbtCompound.getInteger(key));
|
||||
@@ -106,37 +132,19 @@ public class SaveItem {
|
||||
case NBTTagIntArray -> map.put(key, "(IntArray) " + Arrays.toString(nbtCompound.getIntArray(key)));
|
||||
case NBTTagCompound -> {
|
||||
Map<String, Object> map1 = compoundToMap(nbtCompound.getCompound(key));
|
||||
if (map1.size() != 0){
|
||||
map.put(key, map1);
|
||||
}
|
||||
if (map1.size() != 0) map.put(key, map1);
|
||||
}
|
||||
case NBTTagList -> {
|
||||
List<Object> list = new ArrayList<>();
|
||||
switch (nbtCompound.getListType(key)){
|
||||
case NBTTagInt -> nbtCompound.getIntegerList(key).forEach(a -> {
|
||||
list.add("(Int) " + a);
|
||||
});
|
||||
case NBTTagDouble -> nbtCompound.getDoubleList(key).forEach(a -> {
|
||||
list.add("(Double) " + a);
|
||||
});
|
||||
case NBTTagString -> nbtCompound.getStringList(key).forEach(a -> {
|
||||
list.add("(String) " + a);
|
||||
});
|
||||
case NBTTagCompound -> nbtCompound.getCompoundList(key).forEach(a -> {
|
||||
list.add(compoundToMap(a));
|
||||
});
|
||||
case NBTTagFloat -> nbtCompound.getFloatList(key).forEach(a -> {
|
||||
list.add("(Float) " + a);
|
||||
});
|
||||
case NBTTagLong -> nbtCompound.getLongList(key).forEach(a -> {
|
||||
list.add("(Long) " + a);
|
||||
});
|
||||
case NBTTagIntArray -> nbtCompound.getIntArrayList(key).forEach(a -> {
|
||||
list.add("(IntArray) " + Arrays.toString(a));
|
||||
});
|
||||
default -> nbtCompound.getUUIDList(key).forEach(a -> {
|
||||
list.add("(UUID) " + a);
|
||||
});
|
||||
case NBTTagInt -> nbtCompound.getIntegerList(key).forEach(a -> list.add("(Int) " + a));
|
||||
case NBTTagDouble -> nbtCompound.getDoubleList(key).forEach(a -> list.add("(Double) " + a));
|
||||
case NBTTagString -> nbtCompound.getStringList(key).forEach(a -> list.add("(String) " + a));
|
||||
case NBTTagCompound -> nbtCompound.getCompoundList(key).forEach(a -> list.add(compoundToMap(a)));
|
||||
case NBTTagFloat -> nbtCompound.getFloatList(key).forEach(a -> list.add("(Float) " + a));
|
||||
case NBTTagLong -> nbtCompound.getLongList(key).forEach(a -> list.add("(Long) " + a));
|
||||
case NBTTagIntArray -> nbtCompound.getIntArrayList(key).forEach(a -> list.add("(IntArray) " + Arrays.toString(a)));
|
||||
default -> nbtCompound.getUUIDList(key).forEach(a -> list.add("(UUID) " + a));
|
||||
}
|
||||
map.put(key, list);
|
||||
}
|
||||
@@ -29,7 +29,6 @@ import java.util.List;
|
||||
public class JedisUtil {
|
||||
|
||||
private static JedisPool jedisPool;
|
||||
public static boolean useRedis;
|
||||
|
||||
public static Jedis getJedis(){
|
||||
return jedisPool.getResource();
|
||||
@@ -49,7 +48,7 @@ public class JedisUtil {
|
||||
|
||||
jedisPool = new JedisPool(jedisPoolConfig, configuration.getString("redis.host","localhost"), configuration.getInt("redis.port",6379));
|
||||
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] <color:#E1FFFF>Redis Enabled!");
|
||||
AdventureUtil.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] <color:#E1FFFF>Redis Enabled!");
|
||||
|
||||
List<Jedis> minIdleJedisList = new ArrayList<>(jedisPoolConfig.getMinIdle());
|
||||
for (int i = 0; i < jedisPoolConfig.getMinIdle(); i++) {
|
||||
|
||||
@@ -19,20 +19,13 @@ package net.momirealms.customfishing.utils;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class NBTUtil {
|
||||
|
||||
private final Map<String,Object> nbt;
|
||||
private final NBTItem nbtItem;
|
||||
|
||||
public NBTUtil(Map<String,Object> nbt, ItemStack itemStack){
|
||||
this.nbt = nbt;
|
||||
this.nbtItem = new NBTItem(itemStack);
|
||||
}
|
||||
|
||||
public static ItemStack addIdentifier(ItemStack itemStack, String type, String id){
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
nbtItem.addCompound("CustomFishing");
|
||||
@@ -41,18 +34,23 @@ public class NBTUtil {
|
||||
return nbtItem.getItem();
|
||||
}
|
||||
|
||||
public NBTItem getNBTItem(){
|
||||
public static NBTItem getNBTItem(Map<String,Object> nbt, ItemStack itemStack){
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
setTags(nbt, nbtItem);
|
||||
return this.nbtItem;
|
||||
return nbtItem;
|
||||
}
|
||||
|
||||
private void setTags(Map<String,Object> map, NBTCompound nbtCompound){
|
||||
public static void setTags(Map<String,Object> map, NBTCompound nbtCompound){
|
||||
map.keySet().forEach(key -> {
|
||||
if (map.get(key) instanceof Map map2){
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
nbtCompound.addCompound(key);
|
||||
setTags(map2, nbtCompound.getCompound(key));
|
||||
setTags(map2.getValues(false), nbtCompound.getCompound(key));
|
||||
}
|
||||
else if(map.get(key) instanceof List list){
|
||||
else if (map.get(key) instanceof Map<?,?> map1){
|
||||
nbtCompound.addCompound(key);
|
||||
setTags((Map<String, Object>) map1, nbtCompound.getCompound(key));
|
||||
}
|
||||
else if (map.get(key) instanceof List list){
|
||||
for (Object o : list) {
|
||||
if (o instanceof String s) {
|
||||
if (s.startsWith("(String) ")) {
|
||||
@@ -72,7 +70,8 @@ public class NBTUtil {
|
||||
int[] array = Arrays.stream(split).mapToInt(Integer::parseInt).toArray();
|
||||
nbtCompound.getIntArrayList(key).add(array);
|
||||
}
|
||||
} else if (o instanceof Map map1) {
|
||||
}
|
||||
else if (o instanceof Map map1) {
|
||||
setTags(map1, nbtCompound.getCompoundList(key).addCompound());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +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.utils;
|
||||
|
||||
public record VectorUtil(double horizontal, double vertical) {
|
||||
public double getHorizontal() {return this.horizontal;}
|
||||
public double getVertical() {return this.vertical;}
|
||||
}
|
||||
Reference in New Issue
Block a user