mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-29 03:49:07 +00:00
1.2.17
This commit is contained in:
@@ -97,6 +97,7 @@ public final class CustomFishing extends JavaPlugin {
|
||||
|
||||
ConfigUtil.reload();
|
||||
registerCommands();
|
||||
integrationManager.registerQuests();
|
||||
|
||||
AdventureUtil.consoleMessage("[CustomFishing] Plugin Enabled!");
|
||||
new Metrics(this, 16648);
|
||||
|
||||
@@ -262,6 +262,12 @@ public class Competition {
|
||||
return bossBarManager;
|
||||
}
|
||||
|
||||
public void tryAddBossBarToPlayer(Player player) {
|
||||
if (bossBarManager != null) {
|
||||
bossBarManager.tryJoin(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void refreshData(Player player, float score, boolean doubleScore) {
|
||||
if (this.goal == CompetitionGoal.CATCH_AMOUNT) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package net.momirealms.customfishing.integration;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -24,4 +25,6 @@ public interface ItemInterface {
|
||||
|
||||
@Nullable
|
||||
ItemStack build(String id);
|
||||
|
||||
boolean loseCustomDurability(ItemStack itemStack, Player player);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,10 @@ package net.momirealms.customfishing.integration.item;
|
||||
|
||||
import net.momirealms.customfishing.integration.ItemInterface;
|
||||
import net.momirealms.customfishing.manager.LootManager;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CustomFishingItemImpl implements ItemInterface {
|
||||
@@ -30,4 +33,15 @@ public class CustomFishingItemImpl implements ItemInterface {
|
||||
if (material.contains(":")) return null;
|
||||
return LootManager.build(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loseCustomDurability(ItemStack itemStack, Player player) {
|
||||
Damageable damageable = (Damageable) itemStack.getItemMeta();
|
||||
Enchantment enchantment = Enchantment.DURABILITY;
|
||||
if (Math.random() < (1 / (double) (damageable.getEnchantLevel(enchantment) + 1))){
|
||||
damageable.setDamage(damageable.getDamage() + 1);
|
||||
itemStack.setItemMeta(damageable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package net.momirealms.customfishing.integration.item;
|
||||
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import net.momirealms.customfishing.integration.ItemInterface;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -32,4 +33,15 @@ public class ItemsAdderItemImpl implements ItemInterface {
|
||||
CustomStack customStack = CustomStack.getInstance(material);
|
||||
return customStack == null ? null : customStack.getItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loseCustomDurability(ItemStack itemStack, Player player) {
|
||||
CustomStack customStack = CustomStack.byItemStack(itemStack);
|
||||
if (customStack == null) return false;
|
||||
if (customStack.hasCustomDurability()) {
|
||||
customStack.setDurability(customStack.getDurability() - 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,11 @@ package net.momirealms.customfishing.integration.item;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.interaction.util.DurabilityItem;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.momirealms.customfishing.integration.ItemInterface;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -36,4 +38,14 @@ public class MMOItemsItemImpl implements ItemInterface {
|
||||
MMOItem mmoItem = MMOItems.plugin.getMMOItem(Type.get(split[0]), split[1]);
|
||||
return mmoItem == null ? null : mmoItem.newBuilder().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loseCustomDurability(ItemStack itemStack, Player player) {
|
||||
DurabilityItem durabilityItem = new DurabilityItem(player, itemStack);
|
||||
durabilityItem.decreaseDurability(1);
|
||||
final ItemStack newVersion = durabilityItem.toItem();
|
||||
if (newVersion == null) return false;
|
||||
itemStack.setItemMeta(newVersion.getItemMeta());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ package net.momirealms.customfishing.integration.item;
|
||||
|
||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||
import io.lumine.mythic.core.items.ItemExecutor;
|
||||
import io.lumine.mythic.core.items.MythicItem;
|
||||
import net.momirealms.customfishing.integration.ItemInterface;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -38,4 +40,9 @@ public class MythicMobsItemImpl implements ItemInterface {
|
||||
material = material.substring(11);
|
||||
return itemManager.getItemStack(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loseCustomDurability(ItemStack itemStack, Player player) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package net.momirealms.customfishing.integration.item;
|
||||
import io.th0rgal.oraxen.items.ItemBuilder;
|
||||
import io.th0rgal.oraxen.items.OraxenItems;
|
||||
import net.momirealms.customfishing.integration.ItemInterface;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -33,4 +34,9 @@ public class OraxenItemImpl implements ItemInterface {
|
||||
ItemBuilder itemBuilder = OraxenItems.getItemById(material);
|
||||
return itemBuilder == null ? null : itemBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loseCustomDurability(ItemStack itemStack, Player player) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.momirealms.customfishing.integration.quest;
|
||||
|
||||
import com.electro2560.dev.cluescrolls.api.ClueScrollsAPI;
|
||||
import com.electro2560.dev.cluescrolls.api.CustomClue;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.api.event.FishResultEvent;
|
||||
import net.momirealms.customfishing.object.fishing.FishResult;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class ClueScrollHook implements Listener {
|
||||
|
||||
private final CustomClue fishClue;
|
||||
private final CustomClue mobClue;
|
||||
private final CustomClue commonClue;
|
||||
|
||||
public ClueScrollHook () {
|
||||
commonClue = ClueScrollsAPI.getInstance().registerCustomClue(CustomFishing.plugin, "fish");
|
||||
fishClue = ClueScrollsAPI.getInstance().registerCustomClue(CustomFishing.plugin, "catch_fish");
|
||||
mobClue = ClueScrollsAPI.getInstance().registerCustomClue(CustomFishing.plugin, "catch_mob");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFish(FishResultEvent event) {
|
||||
if (event.getResult() == FishResult.CAUGHT_LOOT || event.getResult() == FishResult.CAUGHT_VANILLA) {
|
||||
fishClue.handle(event.getPlayer(), 1);
|
||||
commonClue.handle(event.getPlayer(), 1);
|
||||
}
|
||||
if (event.getResult() == FishResult.CAUGHT_MOB) {
|
||||
mobClue.handle(event.getPlayer(), 1);
|
||||
commonClue.handle(event.getPlayer(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,14 +58,12 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
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 org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -511,7 +509,7 @@ public class FishingManager extends Function {
|
||||
if (Competition.currentCompetition != null){
|
||||
float score = (float) (droppedItem.getScore() * scoreMultiplier);
|
||||
Competition.currentCompetition.refreshData(player, (float) (score * bonus.getScore()), isDouble);
|
||||
Competition.currentCompetition.getBossBarManager().tryJoin(player);
|
||||
Competition.currentCompetition.tryAddBossBarToPlayer(player);
|
||||
}
|
||||
|
||||
dropItem(player, location, fishResultEvent.isDouble(), drop);
|
||||
@@ -551,7 +549,7 @@ public class FishingManager extends Function {
|
||||
|
||||
if (Competition.currentCompetition != null){
|
||||
Competition.currentCompetition.refreshData(player, 0, isDouble);
|
||||
Competition.currentCompetition.getBossBarManager().tryJoin(player);
|
||||
Competition.currentCompetition.tryAddBossBarToPlayer(player);
|
||||
}
|
||||
|
||||
player.giveExp(new Random().nextInt(24), true);
|
||||
@@ -594,7 +592,7 @@ public class FishingManager extends Function {
|
||||
|
||||
if (Competition.currentCompetition != null){
|
||||
Competition.currentCompetition.refreshData(player, 0, isDouble);
|
||||
Competition.currentCompetition.getBossBarManager().tryJoin(player);
|
||||
Competition.currentCompetition.tryAddBossBarToPlayer(player);
|
||||
}
|
||||
|
||||
player.giveExp(vanillaLoot.getXp(), true);
|
||||
@@ -617,7 +615,7 @@ public class FishingManager extends Function {
|
||||
if (Competition.currentCompetition != null) {
|
||||
float score = (float) (loot.getScore() * scoreMultiplier);
|
||||
Competition.currentCompetition.refreshData(player, (float) (score * bonus.getScore()), false);
|
||||
Competition.currentCompetition.getBossBarManager().tryJoin(player);
|
||||
Competition.currentCompetition.tryAddBossBarToPlayer(player);
|
||||
}
|
||||
|
||||
mobInterface.summon(player.getLocation(), location, mob);
|
||||
@@ -684,27 +682,17 @@ public class FishingManager extends Function {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
ItemStack mainHand = inventory.getItemInMainHand();
|
||||
if (mainHand.getType() == Material.FISHING_ROD){
|
||||
setDurability(mainHand);
|
||||
CustomFishing.plugin.getIntegrationManager().loseCustomDurability(mainHand, player);
|
||||
}
|
||||
else {
|
||||
ItemStack offHand = inventory.getItemInOffHand();
|
||||
if (offHand.getType() == Material.FISHING_ROD){
|
||||
setDurability(offHand);
|
||||
CustomFishing.plugin.getIntegrationManager().loseCustomDurability(offHand, player);
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
|
||||
private void setDurability(ItemStack rod) {
|
||||
Damageable damageable = (Damageable) rod.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.plugin, () -> rod.setItemMeta(damageable),1);
|
||||
}
|
||||
}
|
||||
|
||||
private void fail(Player player, Loot loot, boolean isVanilla) {
|
||||
|
||||
FishResultEvent fishResultEvent = new FishResultEvent(player, FishResult.FAILURE, false, null);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package net.momirealms.customfishing.manager;
|
||||
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.helper.Log;
|
||||
import net.momirealms.customfishing.integration.*;
|
||||
import net.momirealms.customfishing.integration.antigrief.*;
|
||||
@@ -26,6 +27,7 @@ import net.momirealms.customfishing.integration.block.VanillaBlockImpl;
|
||||
import net.momirealms.customfishing.integration.item.*;
|
||||
import net.momirealms.customfishing.integration.mob.MythicMobsMobImpl;
|
||||
import net.momirealms.customfishing.integration.papi.PlaceholderManager;
|
||||
import net.momirealms.customfishing.integration.quest.ClueScrollHook;
|
||||
import net.momirealms.customfishing.integration.season.CustomCropsSeasonImpl;
|
||||
import net.momirealms.customfishing.integration.season.RealisticSeasonsImpl;
|
||||
import net.momirealms.customfishing.integration.skill.*;
|
||||
@@ -35,7 +37,9 @@ import net.momirealms.customfishing.util.ConfigUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
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.Damageable;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -80,7 +84,6 @@ public class IntegrationManager extends Function {
|
||||
this.blockInterface = new VanillaBlockImpl();
|
||||
|
||||
List<ItemInterface> itemInterfaceList = new ArrayList<>();
|
||||
itemInterfaceList.add(new CustomFishingItemImpl());
|
||||
if (config.getBoolean("integrations.ItemsAdder") && pluginManager.getPlugin("ItemsAdder") != null) {
|
||||
this.blockInterface = new ItemsAdderBlockImpl();
|
||||
itemInterfaceList.add(new ItemsAdderItemImpl());
|
||||
@@ -100,6 +103,7 @@ public class IntegrationManager extends Function {
|
||||
this.mobInterface = new MythicMobsMobImpl();
|
||||
hookMessage("MythicMobs");
|
||||
}
|
||||
itemInterfaceList.add(new CustomFishingItemImpl());
|
||||
this.itemInterfaces = itemInterfaceList.toArray(new ItemInterface[0]);
|
||||
|
||||
if (pluginManager.getPlugin("eco") != null) {
|
||||
@@ -205,6 +209,15 @@ public class IntegrationManager extends Function {
|
||||
antiGriefs = antiGriefsList.toArray(new AntiGriefInterface[0]);
|
||||
}
|
||||
|
||||
public void registerQuests() {
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("ClueScrolls")) {
|
||||
ClueScrollHook clueScrollHook = new ClueScrollHook();
|
||||
Bukkit.getPluginManager().registerEvents(clueScrollHook, CustomFishing.plugin);
|
||||
hookMessage("ClueScrolls");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
this.seasonInterface = null;
|
||||
@@ -264,6 +277,16 @@ public class IntegrationManager extends Function {
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
public void loseCustomDurability(ItemStack itemStack, Player player) {
|
||||
Damageable damageable = (Damageable) itemStack.getItemMeta();
|
||||
if (damageable.isUnbreakable()) return;
|
||||
for (ItemInterface itemInterface : getItemInterfaces()) {
|
||||
if (itemInterface.loseCustomDurability(itemStack, player)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void hookMessage(String plugin){
|
||||
AdventureUtil.consoleMessage("[CustomFishing] <white>" + plugin + " Hooked!");
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
||||
Reference in New Issue
Block a user