9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-29 20:09:14 +00:00

checkpoint - 3

This commit is contained in:
XiaoMoMi
2024-05-19 04:13:40 +08:00
parent ddc1f4245f
commit 326c9580eb
102 changed files with 1758 additions and 970 deletions

View File

@@ -1,6 +1,19 @@
dependencies {
compileOnly(project(":common"))
compileOnly(project(":api"))
// papi
compileOnly("me.clip:placeholderapi:2.11.5")
// server
compileOnly("dev.folia:folia-api:1.20.4-R0.1-SNAPSHOT")
// local jars
compileOnly(files("libs/AdvancedEnchantments-api.jar"))
compileOnly(files("libs/BattlePass-4.0.6-api.jar"))
compileOnly(files("libs/RealisticSeasons-api.jar"))
compileOnly(files("libs/mcMMO-api.jar"))
compileOnly(files("libs/ClueScrolls-4.8.7-api.jar"))
compileOnly(files("libs/notquests-5.17.1.jar"))
compileOnly(files("libs/zaphkiel-2.0.24.jar"))
}
java {

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,33 @@
/*
* 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.bukkit.compatibility;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public class PlaceholderAPIUtils {
public static String parse(Player player, String text) {
return PlaceholderAPI.setPlaceholders(player, text);
}
public static String parse(OfflinePlayer player, String text) {
return PlaceholderAPI.setPlaceholders(player, text);
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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.bukkit.compatibility;
import net.milkbowl.vault.economy.Economy;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import org.bukkit.plugin.RegisteredServiceProvider;
public class VaultHook {
private static Economy economy;
public static boolean initialize() {
RegisteredServiceProvider<Economy> rsp = BukkitCustomFishingPlugin.getInstance().getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
economy = rsp.getProvider();
return true;
}
public static Economy getEconomy() {
return economy;
}
}

View File

@@ -0,0 +1,50 @@
/*
* 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.bukkit.compatibility.block;
import dev.lone.itemsadder.api.CustomBlock;
import net.momirealms.customfishing.api.mechanic.block.BlockDataModifier;
import net.momirealms.customfishing.api.mechanic.block.BlockLibrary;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import java.util.List;
public class ItemsAdderBlockImpl implements BlockLibrary {
@Override
public String identification() {
return "ItemsAdder";
}
@Override
public BlockData getBlockData(Player player, String id, List<BlockDataModifier> modifiers) {
BlockData blockData = CustomBlock.getBaseBlockData(id);
for (BlockDataModifier modifier : modifiers) {
modifier.apply(player, blockData);
}
return blockData;
}
@Override
public String getBlockID(Block block) {
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
return customBlock == null ? null : customBlock.getId();
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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.bukkit.compatibility.block;
import net.momirealms.customfishing.api.mechanic.block.BlockDataModifier;
import net.momirealms.customfishing.api.mechanic.block.BlockLibrary;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Locale;
public class VanillaBlockImpl implements BlockLibrary {
@Override
public String identification() {
return "vanilla";
}
@Override
public BlockData getBlockData(Player player, String id, List<BlockDataModifier> modifiers) {
BlockData blockData = Material.valueOf(id.toUpperCase(Locale.ENGLISH)).createBlockData();
for (BlockDataModifier modifier : modifiers) {
modifier.apply(player, blockData);
}
return blockData;
}
@Override
public @Nullable String getBlockID(Block block) {
return block.getType().name();
}
}

View File

@@ -0,0 +1,38 @@
/*
* 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.bukkit.compatibility.enchant;
import net.advancedplugins.ae.api.AEAPI;
import net.momirealms.customfishing.api.integration.EnchantmentProvider;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class AdvancedEnchantmentsImpl implements EnchantmentProvider {
@Override
public List<String> getEnchants(ItemStack itemStack) {
List<String> enchants = new ArrayList<>();
for (Map.Entry<String, Integer> entry : AEAPI.getEnchantmentsOnItem(itemStack).entrySet()) {
enchants.add("AE:" + entry.getKey() + ":" + entry.getValue());
}
return enchants;
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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.bukkit.compatibility.enchant;
import net.momirealms.customfishing.api.integration.EnchantmentProvider;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class VanillaEnchantmentsImpl implements EnchantmentProvider {
@Override
public List<String> getEnchants(ItemStack itemStack) {
Map<Enchantment, Integer> enchantments = itemStack.getEnchantments();
List<String> enchants = new ArrayList<>(enchantments.size());
for (Map.Entry<Enchantment, Integer> en : enchantments.entrySet()) {
String key = en.getKey().getKey() + ":" + en.getValue();
enchants.add(key);
}
return enchants;
}
}

View File

@@ -0,0 +1,47 @@
/*
* 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.bukkit.compatibility.entity;
import dev.lone.itemsadder.api.CustomEntity;
import net.momirealms.customfishing.api.integration.EntityProvider;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
public class ItemsAdderEntityImpl implements EntityProvider {
@Override
public String identifier() {
return "vanilla";
}
@NotNull
@Override
public Entity spawn(@NotNull Location location, @NotNull String id, @NotNull Map<String, Object> propertyMap) {
CustomEntity customEntity = CustomEntity.spawn(
id,
location,
(Boolean) propertyMap.getOrDefault("frustumCulling", true),
(Boolean) propertyMap.getOrDefault("noBase", false),
(Boolean) propertyMap.getOrDefault("noHitbox", false)
);
return customEntity.getEntity();
}
}

View File

@@ -0,0 +1,63 @@
/*
* 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.bukkit.compatibility.entity;
import io.lumine.mythic.api.adapters.AbstractLocation;
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.api.integration.EntityProvider;
import net.momirealms.customfishing.util.ConfigUtils;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Optional;
public class MythicEntityImpl implements EntityProvider {
private MythicBukkit mythicBukkit;
public MythicEntityImpl() {
this.mythicBukkit = MythicBukkit.inst();
}
@Override
public String identifier() {
return "MythicMobs";
}
@NotNull
@Override
public Entity spawn(@NotNull Location location, @NotNull String id, @NotNull Map<String, Object> propertyMap) {
if (this.mythicBukkit == null || mythicBukkit.isClosed()) {
this.mythicBukkit = MythicBukkit.inst();
}
Optional<MythicMob> mythicMob = mythicBukkit.getMobManager().getMythicMob(id);
if (mythicMob.isPresent()) {
MythicMob theMob = mythicMob.get();
Position position = Position.of(location);
AbstractLocation abstractLocation = new AbstractLocation(position);
ActiveMob activeMob = theMob.spawn(abstractLocation, ConfigUtils.getDoubleValue(propertyMap.get("level")));
return activeMob.getEntity().getBukkitEntity();
}
throw new NullPointerException("MythicMobs: " + id + " doesn't exist.");
}
}

View File

@@ -0,0 +1,41 @@
/*
* 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.bukkit.compatibility.entity;
import net.momirealms.customfishing.api.integration.EntityProvider;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
import java.util.Map;
public class VanillaEntityImpl implements EntityProvider {
@Override
public String identifier() {
return "vanilla";
}
@NotNull
@Override
public Entity spawn(@NotNull Location location, @NotNull String id, @NotNull Map<String, Object> propertyMap) {
return location.getWorld().spawnEntity(location, EntityType.valueOf(id.toUpperCase(Locale.ENGLISH)));
}
}

View File

@@ -0,0 +1,44 @@
/*
* 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.bukkit.compatibility.item;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.integration.ItemProvider;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class CustomFishingItemImpl implements ItemProvider {
@Override
public String identification() {
return "CustomFishing";
}
@NotNull
@Override
public ItemStack buildItem(Player player, String id) {
String[] split = id.split(":", 2);
return BukkitCustomFishingPlugin.get().getItemManager().build(player, split[0], split[1]);
}
@Override
public String itemID(ItemStack itemStack) {
return BukkitCustomFishingPlugin.get().getItemManager().getCustomFishingItemID(itemStack);
}
}

View File

@@ -0,0 +1,50 @@
/*
* 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.bukkit.compatibility.item;
import dev.lone.itemsadder.api.CustomStack;
import net.momirealms.customfishing.api.integration.ItemProvider;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class ItemsAdderItemImpl implements ItemProvider {
@Override
public String identification() {
return "ItemsAdder";
}
@NotNull
@Override
public ItemStack buildItem(Player player, String id) {
CustomStack stack = CustomStack.getInstance(id);
if (stack == null) {
LogUtils.severe(id + " doesn't exist in ItemsAdder configs.");
return null;
}
return stack.getItemStack();
}
@Override
public String itemID(ItemStack itemStack) {
CustomStack customStack = CustomStack.byItemStack(itemStack);
if (customStack == null) return null;
return customStack.getNamespacedID();
}
}

View File

@@ -0,0 +1,53 @@
/*
* 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.bukkit.compatibility.item;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.momirealms.customfishing.api.integration.ItemProvider;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
public class MMOItemsItemImpl implements ItemProvider {
@Override
public String identification() {
return "MMOItems";
}
@NotNull
@Override
public ItemStack buildItem(Player player, String id) {
String[] split = id.split(":");
MMOItem mmoItem = MMOItems.plugin.getMMOItem(Type.get(split[0]), split[1].toUpperCase(Locale.ENGLISH));
return mmoItem == null ? new ItemStack(Material.AIR) : mmoItem.newBuilder().build();
}
@Override
public String itemID(ItemStack itemStack) {
NBTItem nbtItem = NBTItem.get(itemStack);
if (!nbtItem.hasTag("MMOITEMS_ITEM_ID")) return null;
return nbtItem.getString("MMOITEMS_ITEM_ID");
}
}

View File

@@ -0,0 +1,80 @@
/*
* 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.bukkit.compatibility.item;
import net.momirealms.customfishing.api.integration.ItemProvider;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class McMMOTreasureImpl implements ItemProvider {
private final Method getMcMMOPlayerMethod;
private final Method getFishingManagerMethod;
private final Method getFishingTreasureMethod;
private final Method getItemStackMethod;
public McMMOTreasureImpl() throws ClassNotFoundException, NoSuchMethodException {
Class<?> userClass = Class.forName("com.gmail.nossr50.util.player.UserManager");
getMcMMOPlayerMethod = userClass.getMethod("getPlayer", Player.class);
Class<?> mcMMOPlayerClass = Class.forName("com.gmail.nossr50.datatypes.player.McMMOPlayer");
getFishingManagerMethod = mcMMOPlayerClass.getMethod("getFishingManager");
Class<?> fishingManagerClass = Class.forName("com.gmail.nossr50.skills.fishing.FishingManager");
getFishingTreasureMethod = fishingManagerClass.getDeclaredMethod("getFishingTreasure");
getFishingTreasureMethod.setAccessible(true);
Class<?> treasureClass = Class.forName("com.gmail.nossr50.datatypes.treasure.Treasure");
getItemStackMethod = treasureClass.getMethod("getDrop");
}
@Override
public String identification() {
return "mcMMO";
}
@NotNull
@Override
public ItemStack buildItem(Player player, String id) {
if (!id.equals("treasure")) return new ItemStack(Material.AIR);
ItemStack itemStack = null;
int times = 0;
while (itemStack == null && times < 5) {
try {
Object mcMMOPlayer = getMcMMOPlayerMethod.invoke(null, player);
Object fishingManager = getFishingManagerMethod.invoke(mcMMOPlayer);
Object treasure = getFishingTreasureMethod.invoke(fishingManager);
if (treasure != null) {
itemStack = (ItemStack) getItemStackMethod.invoke(treasure);
}
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
} finally {
times++;
}
}
return itemStack == null ? new ItemStack(Material.COD) : itemStack;
}
@Override
public String itemID(ItemStack itemStack) {
return null;
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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.bukkit.compatibility.item;
import io.lumine.mythic.bukkit.MythicBukkit;
import net.momirealms.customfishing.api.integration.ItemProvider;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class MythicMobsItemImpl implements ItemProvider {
private MythicBukkit mythicBukkit;
public MythicMobsItemImpl() {
this.mythicBukkit = MythicBukkit.inst();
}
@Override
public String identification() {
return "MythicMobs";
}
@NotNull
@Override
public ItemStack buildItem(Player player, String id) {
if (mythicBukkit == null || mythicBukkit.isClosed()) {
this.mythicBukkit = MythicBukkit.inst();
}
return mythicBukkit.getItemManager().getItemStack(id);
}
@Override
public String itemID(ItemStack itemStack) {
if (mythicBukkit == null || mythicBukkit.isClosed()) {
this.mythicBukkit = MythicBukkit.inst();
}
return mythicBukkit.getItemManager().getMythicTypeFromItem(itemStack);
}
}

View File

@@ -0,0 +1,49 @@
/*
* 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.bukkit.compatibility.item;
import net.momirealms.customfishing.api.integration.ItemProvider;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import pers.neige.neigeitems.item.ItemInfo;
import pers.neige.neigeitems.manager.ItemManager;
import pers.neige.neigeitems.utils.ItemUtils;
public class NeigeItemsItemImpl implements ItemProvider {
@Override
public String identification() {
return "NeigeItems";
}
@NotNull
@Override
public ItemStack buildItem(Player player, String id) {
return ItemManager.INSTANCE.getItemStack(id, player);
}
@Override
public String itemID(ItemStack itemStack) {
ItemInfo itemInfo = ItemUtils.isNiItem(itemStack);
if (itemInfo != null) {
return itemInfo.getId();
}
return null;
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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.bukkit.compatibility.item;
import io.th0rgal.oraxen.api.OraxenItems;
import io.th0rgal.oraxen.items.ItemBuilder;
import net.momirealms.customfishing.api.integration.ItemProvider;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class OraxenItemImpl implements ItemProvider {
@Override
public String identification() {
return "Oraxen";
}
@NotNull
@Override
public ItemStack buildItem(Player player, String id) {
ItemBuilder itemBuilder = OraxenItems.getItemById(id);
return itemBuilder == null ? new ItemStack(Material.AIR) : itemBuilder.build();
}
@Override
public String itemID(ItemStack itemStack) {
return OraxenItems.getIdByItem(itemStack);
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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.bukkit.compatibility.item;
import net.momirealms.customfishing.api.integration.ItemProvider;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
public class VanillaItemImpl implements ItemProvider {
@Override
public String identification() {
return "vanilla";
}
@NotNull
@Override
public ItemStack buildItem(Player player, String id) {
return new ItemStack(Material.valueOf(id.toUpperCase(Locale.ENGLISH)));
}
@Override
public String itemID(ItemStack itemStack) {
return itemStack.getType().name();
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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.bukkit.compatibility.item;
import ink.ptms.zaphkiel.ZapAPI;
import ink.ptms.zaphkiel.Zaphkiel;
import net.momirealms.customfishing.api.integration.ItemProvider;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class ZaphkielItemImpl implements ItemProvider {
private final ZapAPI zapAPI;
public ZaphkielItemImpl() {
this.zapAPI = Zaphkiel.INSTANCE.api();
}
@Override
public String identification() {
return "Zaphkiel";
}
@NotNull
@Override
public ItemStack buildItem(Player player, String id) {
return zapAPI.getItemManager().generateItemStack(id, player);
}
@Override
public String itemID(ItemStack itemStack) {
if (itemStack == null || itemStack.getType() == Material.AIR) return null;
return zapAPI.getItemHandler().getItemId(itemStack);
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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.bukkit.compatibility.level;
import dev.aurelium.auraskills.api.AuraSkillsApi;
import dev.aurelium.auraskills.api.registry.NamespacedId;
import net.momirealms.customfishing.api.integration.LevelerProvider;
import org.bukkit.entity.Player;
public class AuraSkillsImpl implements LevelerProvider {
@Override
public void addXp(Player player, String target, double amount) {
AuraSkillsApi.get().getUser(player.getUniqueId())
.addSkillXp(AuraSkillsApi.get().getGlobalRegistry().getSkill(NamespacedId.fromDefault(target)), amount);
}
@Override
public int getLevel(Player player, String target) {
return AuraSkillsApi.get().getUser(player.getUniqueId()).getSkillLevel(
AuraSkillsApi.get().getGlobalRegistry().getSkill(NamespacedId.fromDefault(target))
);
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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.bukkit.compatibility.level;
import com.archyx.aureliumskills.api.AureliumAPI;
import com.archyx.aureliumskills.leveler.Leveler;
import net.momirealms.customfishing.api.integration.LevelerProvider;
import org.bukkit.entity.Player;
public class AureliumSkillsImpl implements LevelerProvider {
private final Leveler leveler;
public AureliumSkillsImpl() {
leveler = AureliumAPI.getPlugin().getLeveler();
}
@Override
public void addXp(Player player, String target, double amount) {
leveler.addXp(player, AureliumAPI.getPlugin().getSkillRegistry().getSkill(target), amount);
}
@Override
public int getLevel(Player player, String target) {
return AureliumAPI.getSkillLevel(player, AureliumAPI.getPlugin().getSkillRegistry().getSkill(target));
}
}

View File

@@ -0,0 +1,43 @@
/*
* 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.bukkit.compatibility.level;
import com.willfp.ecojobs.api.EcoJobsAPI;
import com.willfp.ecojobs.jobs.Job;
import com.willfp.ecojobs.jobs.Jobs;
import net.momirealms.customfishing.api.integration.LevelerProvider;
import org.bukkit.entity.Player;
public class EcoJobsImpl implements LevelerProvider {
@Override
public void addXp(Player player, String target, double amount) {
for (Job job : EcoJobsAPI.getActiveJobs(player)) {
if (job.getId().equals(target)) {
EcoJobsAPI.giveJobExperience(player, job, amount);
}
}
}
@Override
public int getLevel(Player player, String target) {
Job job = Jobs.getByID(target);
if (job == null) return 0;
return EcoJobsAPI.getJobLevel(player, job);
}
}

View File

@@ -0,0 +1,38 @@
/*
* 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.bukkit.compatibility.level;
import com.willfp.ecoskills.api.EcoSkillsAPI;
import com.willfp.ecoskills.skills.Skills;
import net.momirealms.customfishing.api.integration.LevelerProvider;
import org.bukkit.entity.Player;
import java.util.Objects;
public class EcoSkillsImpl implements LevelerProvider {
@Override
public void addXp(Player player, String target, double amount) {
EcoSkillsAPI.gainSkillXP(player, Objects.requireNonNull(Skills.INSTANCE.getByID(target)), amount);
}
@Override
public int getLevel(Player player, String target) {
return EcoSkillsAPI.getSkillLevel(player, Objects.requireNonNull(Skills.INSTANCE.getByID(target)));
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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.bukkit.compatibility.level;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import net.momirealms.customfishing.api.integration.LevelerProvider;
import org.bukkit.entity.Player;
import java.util.List;
public class JobsRebornImpl implements LevelerProvider {
@Override
public void addXp(Player player, String target, double amount) {
JobsPlayer jobsPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
Job job = Jobs.getJob(target);
if (jobsPlayer != null && jobsPlayer.isInJob(job))
Jobs.getPlayerManager().addExperience(jobsPlayer, job, amount);
}
@Override
public int getLevel(Player player, String target) {
JobsPlayer jobsPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (jobsPlayer != null) {
List<JobProgression> jobs = jobsPlayer.getJobProgression();
Job job = Jobs.getJob(target);
for (JobProgression progression : jobs)
if (progression.getJob().equals(job))
return progression.getLevel();
}
return 0;
}
}

View File

@@ -0,0 +1,37 @@
/*
* 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.bukkit.compatibility.level;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.EXPSource;
import net.momirealms.customfishing.api.integration.LevelerProvider;
import org.bukkit.entity.Player;
public class MMOCoreImpl implements LevelerProvider {
@Override
public void addXp(Player player, String target, double amount) {
MMOCore.plugin.professionManager.get(target).giveExperience(PlayerData.get(player), amount, null ,EXPSource.OTHER);
}
@Override
public int getLevel(Player player, String target) {
return PlayerData.get(player).getCollectionSkills().getLevel(MMOCore.plugin.professionManager.get(target));
}
}

View File

@@ -0,0 +1,36 @@
/*
* 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.bukkit.compatibility.level;
import com.gmail.nossr50.api.ExperienceAPI;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import net.momirealms.customfishing.api.integration.LevelerProvider;
import org.bukkit.entity.Player;
public class McMMOImpl implements LevelerProvider {
@Override
public void addXp(Player player, String target, double amount) {
ExperienceAPI.addRawXP(player, target, (float) amount, "UNKNOWN");
}
@Override
public int getLevel(Player player, String target) {
return ExperienceAPI.getLevel(player, PrimarySkillType.valueOf(target));
}
}

View File

@@ -0,0 +1,144 @@
/*
* 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.bukkit.compatibility.papi;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
public class CompetitionPapi extends PlaceholderExpansion {
private final BukkitCustomFishingPlugin plugin;
public CompetitionPapi(BukkitCustomFishingPlugin plugin) {
this.plugin = plugin;
}
public void load() {
super.register();
}
public void unload() {
super.unregister();
}
@Override
public @NotNull String getIdentifier() {
return "cfcompetition";
}
@Override
public @NotNull String getAuthor() {
return "XiaoMoMi";
}
@Override
public @NotNull String getVersion() {
return "2.0";
}
@Override
public boolean persist() {
return true;
}
@Override
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
switch (params) {
case "goingon" -> {
return String.valueOf(plugin.getCompetitionManager().getOnGoingCompetition() != null);
}
case "nextseconds" -> {
return String.valueOf(plugin.getCompetitionManager().getNextCompetitionSeconds());
}
case "nextsecond" -> {
return plugin.getCompetitionManager().getNextCompetitionSeconds() % 60 + CFLocale.FORMAT_Second;
}
case "nextminute" -> {
int sec = plugin.getCompetitionManager().getNextCompetitionSeconds();
int min = (sec % 3600) / 60;
return sec < 60 ? "" : min + CFLocale.FORMAT_Minute;
}
case "nexthour" -> {
int sec = plugin.getCompetitionManager().getNextCompetitionSeconds();
int h = (sec % (3600 * 24)) / 3600;
return sec < 3600 ? "" : h + CFLocale.FORMAT_Hour;
}
case "nextday" -> {
int sec = plugin.getCompetitionManager().getNextCompetitionSeconds();
int day = sec / (3600 * 24);
return day == 0 ? "" : day + CFLocale.FORMAT_Day;
}
case "rank" -> {
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
if (competition == null) return "";
else return String.valueOf(competition.getRanking().getPlayerRank(player.getName()));
}
case "goal" -> {
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
if (competition == null) return "";
else return competition.getGoal().name();
}
case "seconds" -> {
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
if (competition == null) return "";
return competition.getCachedPlaceholder("{seconds}");
}
case "second" -> {
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
if (competition == null) return "";
return competition.getCachedPlaceholder("{second}");
}
case "minute" -> {
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
if (competition == null) return "";
return competition.getCachedPlaceholder("{minute}");
}
case "hour" -> {
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
if (competition == null) return "";
return competition.getCachedPlaceholder("{hour}");
}
}
String[] split = params.split("_", 2);
switch (split[0]) {
case "score" -> {
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
if (competition == null) return "";
if (split.length == 1) {
return String.format("%.2f", competition.getRanking().getPlayerScore(player.getName()));
} else {
return String.format("%.2f", competition.getRanking().getScoreAt(Integer.parseInt(split[1])));
}
}
case "player" -> {
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
if (competition == null) return "";
if (split.length == 1) return "Invalid format";
return Optional.ofNullable(competition.getRanking().getPlayerAt(Integer.parseInt(split[1]))).orElse("");
}
}
return "null";
}
}

View File

@@ -0,0 +1,126 @@
/*
* 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.bukkit.compatibility.papi;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CustomFishingPapi extends PlaceholderExpansion {
private final BukkitCustomFishingPlugin plugin;
public CustomFishingPapi(BukkitCustomFishingPlugin plugin) {
this.plugin = plugin;
}
public void load() {
super.register();
}
public void unload() {
super.unregister();
}
@Override
public @NotNull String getIdentifier() {
return "customfishing";
}
@Override
public @NotNull String getAuthor() {
return "XiaoMoMi";
}
@Override
public @NotNull String getVersion() {
return "2.0";
}
@Override
public boolean persist() {
return true;
}
@Override
public @Nullable String onRequest(OfflinePlayer offlinePlayer, @NotNull String params) {
String[] split = params.split("_");
Player player = offlinePlayer.getPlayer();
if (player == null)
return "";
switch (split[0]) {
case "market" -> {
if (split.length < 2)
return null;
switch (split[1]) {
case "limit" -> {
if (split.length < 3) {
return String.format("%.2f", plugin.getMarketManager().getEarningLimit(player));
} else {
Player another = Bukkit.getPlayer(split[2]);
if (another == null) {
return "";
}
return String.format("%.2f", plugin.getMarketManager().getEarningLimit(another));
}
}
case "earnings" -> {
OnlineUserData user;
if (split.length < 3) {
user = plugin.getStorageManager().getOnlineUser(player.getUniqueId());
} else {
Player another = Bukkit.getPlayer(split[2]);
if (another == null) {
return "";
}
user = plugin.getStorageManager().getOnlineUser(another.getUniqueId());
}
if (user == null)
return "";
return String.format("%.2f", user.getEarningData().earnings);
}
case "canearn" -> {
if (split.length < 3) {
OnlineUserData user = plugin.getStorageManager().getOnlineUser(player.getUniqueId());
if (user == null)
return "";
return String.format("%.2f", plugin.getMarketManager().getEarningLimit(player) - user.getEarningData().earnings);
} else {
Player another = Bukkit.getPlayer(split[2]);
if (another == null) {
return "";
}
OnlineUserData user = plugin.getStorageManager().getOnlineUser(another.getUniqueId());
if (user == null)
return "";
return String.format("%.2f", plugin.getMarketManager().getEarningLimit(another) - user.getEarningData().earnings);
}
}
}
}
}
return null;
}
}

View File

@@ -0,0 +1,112 @@
/*
* 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.bukkit.compatibility.papi;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class StatisticsPapi extends PlaceholderExpansion {
private final BukkitCustomFishingPlugin plugin;
public StatisticsPapi(BukkitCustomFishingPlugin plugin) {
this.plugin = plugin;
}
public void load() {
super.register();
}
public void unload() {
super.unregister();
}
@Override
public @NotNull String getIdentifier() {
return "fishingstats";
}
@Override
public @NotNull String getAuthor() {
return "XiaoMoMi";
}
@Override
public @NotNull String getVersion() {
return "2.0";
}
@Override
public boolean persist() {
return true;
}
@Override
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
OnlineUserData onlineUser = plugin.getStorageManager().getOnlineUser(player.getUniqueId());
if (onlineUser == null) return "Data not loaded";
Statistics statistics = onlineUser.getStatistics();
String[] split = params.split("_", 2);
switch (split[0]) {
case "total" -> {
return String.valueOf(statistics.getTotalCatchAmount());
}
case "hascaught" -> {
if (split.length == 1) return "Invalid format";
return String.valueOf(statistics.getLootAmount(split[1]) != 0);
}
case "amount" -> {
if (split.length == 1) return "Invalid format";
return String.valueOf(statistics.getLootAmount(split[1]));
}
case "size-record" -> {
return String.format("%.2f", statistics.getSizeRecord(split[1]));
}
case "category" -> {
if (split.length == 1) return "Invalid format";
String[] categorySplit = split[1].split("_", 2);
if (categorySplit.length == 1) return "Invalid format";
List<String> category = plugin.getStatisticsManager().getCategory(categorySplit[1]);
if (category == null) return "Category Not Exists";
if (categorySplit[0].equals("total")) {
int total = 0;
for (String loot : category) {
total += statistics.getLootAmount(loot);
}
return String.valueOf(total);
} else if (categorySplit[0].equals("progress")) {
int size = category.size();
int unlocked = 0;
for (String loot : category) {
if (statistics.getLootAmount(loot) != 0) unlocked++;
}
double percent = ((double) unlocked * 100) / size;
String progress = String.format("%.1f", percent);
return progress.equals("100.0") ? "100" : progress;
}
}
}
return "null";
}
}

View File

@@ -0,0 +1,79 @@
/*
* 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.bukkit.compatibility.quest;
import io.github.battlepass.BattlePlugin;
import io.github.battlepass.api.events.server.PluginReloadEvent;
import net.advancedplugins.bp.impl.actions.ActionRegistry;
import net.advancedplugins.bp.impl.actions.external.executor.ActionQuestExecutor;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.event.FishingResultEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class BattlePassHook implements Listener {
public BattlePassHook() {
Bukkit.getPluginManager().registerEvents(this, BukkitCustomFishingPlugin.get());
}
public void register() {
ActionRegistry actionRegistry = BattlePlugin.getPlugin().getActionRegistry();
actionRegistry.hook("customfishing", BPFishingQuest::new);
}
@EventHandler(ignoreCancelled = true)
public void onBattlePassReload(PluginReloadEvent event){
register();
}
private static class BPFishingQuest extends ActionQuestExecutor {
public BPFishingQuest(JavaPlugin plugin) {
super(plugin, "customfishing");
}
@EventHandler
public void onFish(FishingResultEvent event){
if (event.isCancelled() || event.getResult() == FishingResultEvent.Result.FAILURE)
return;
Player player = event.getPlayer();
// Single Fish Quest
if (event.getLoot().getID() != null)
this.executionBuilder("loot")
.player(player)
.root(event.getLoot().getID())
.progress(event.getAmount())
.buildAndExecute();
// Group Fish Quest
String[] lootGroup = event.getLoot().lootGroup();
if (event.getLoot() != null && lootGroup != null)
for (String group : lootGroup) {
this.executionBuilder("group")
.player(player)
.root(group)
.progress(event.getAmount())
.buildAndExecute();
}
}
}
}

View File

@@ -0,0 +1,190 @@
/*
* 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.bukkit.compatibility.quest;
import net.momirealms.customfishing.api.event.FishingResultEvent;
import org.betonquest.betonquest.BetonQuest;
import org.betonquest.betonquest.Instruction;
import org.betonquest.betonquest.VariableNumber;
import org.betonquest.betonquest.api.CountingObjective;
import org.betonquest.betonquest.api.config.quest.QuestPackage;
import org.betonquest.betonquest.api.profiles.OnlineProfile;
import org.betonquest.betonquest.api.profiles.Profile;
import org.betonquest.betonquest.exceptions.InstructionParseException;
import org.betonquest.betonquest.utils.PlayerConverter;
import org.betonquest.betonquest.utils.location.CompoundLocation;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import java.util.Collections;
import java.util.HashSet;
@SuppressWarnings("DuplicatedCode")
public class BetonQuestHook {
public static void register() {
BetonQuest.getInstance().registerObjectives("customfishing_loot", IDObjective.class);
BetonQuest.getInstance().registerObjectives("customfishing_group", GroupObjective.class);
}
public static class IDObjective extends CountingObjective implements Listener {
private final CompoundLocation playerLocation;
private final VariableNumber rangeVar;
private final HashSet<String> loot_ids;
public IDObjective(Instruction instruction) throws InstructionParseException {
super(instruction, "loot_to_fish");
loot_ids = new HashSet<>();
Collections.addAll(loot_ids, instruction.getArray());
targetAmount = instruction.getVarNum();
preCheckAmountNotLessThanOne(targetAmount);
final QuestPackage pack = instruction.getPackage();
final String loc = instruction.getOptional("playerLocation");
final String range = instruction.getOptional("range");
if (loc != null && range != null) {
playerLocation = new CompoundLocation(pack, loc);
rangeVar = new VariableNumber(pack, range);
} else {
playerLocation = null;
rangeVar = null;
}
}
@EventHandler
public void onFish(FishingResultEvent event) {
if (event.getResult() != FishingResultEvent.Result.FAILURE) {
OnlineProfile onlineProfile = PlayerConverter.getID(event.getPlayer());
if (!containsPlayer(onlineProfile)) {
return;
}
if (isInvalidLocation(event, onlineProfile)) {
return;
}
if (this.loot_ids.contains(event.getLoot().getID()) && this.checkConditions(onlineProfile)) {
getCountingData(onlineProfile).progress(event.getAmount());
completeIfDoneOrNotify(onlineProfile);
}
}
}
private boolean isInvalidLocation(FishingResultEvent event, final Profile profile) {
if (playerLocation == null || rangeVar == null) {
return false;
}
final Location targetLocation;
try {
targetLocation = playerLocation.getLocation(profile);
} catch (final org.betonquest.betonquest.exceptions.QuestRuntimeException e) {
LogUtils.warn(e.getMessage());
return true;
}
final int range = rangeVar.getInt(profile);
final Location playerLoc = event.getPlayer().getLocation();
return !playerLoc.getWorld().equals(targetLocation.getWorld()) || targetLocation.distanceSquared(playerLoc) > range * range;
}
@Override
public void start() {
Bukkit.getPluginManager().registerEvents(this, BetonQuest.getInstance());
}
@Override
public void stop() {
HandlerList.unregisterAll(this);
}
}
public static class GroupObjective extends CountingObjective implements Listener {
private final CompoundLocation playerLocation;
private final VariableNumber rangeVar;
private final HashSet<String> loot_groups;
public GroupObjective(Instruction instruction) throws InstructionParseException {
super(instruction, "group_to_fish");
loot_groups = new HashSet<>();
Collections.addAll(loot_groups, instruction.getArray());
targetAmount = instruction.getVarNum();
preCheckAmountNotLessThanOne(targetAmount);
final QuestPackage pack = instruction.getPackage();
final String loc = instruction.getOptional("playerLocation");
final String range = instruction.getOptional("range");
if (loc != null && range != null) {
playerLocation = new CompoundLocation(pack, loc);
rangeVar = new VariableNumber(pack, range);
} else {
playerLocation = null;
rangeVar = null;
}
}
@EventHandler
public void onFish(FishingResultEvent event) {
if (event.getResult() != FishingResultEvent.Result.FAILURE) {
OnlineProfile onlineProfile = PlayerConverter.getID(event.getPlayer());
if (!containsPlayer(onlineProfile)) {
return;
}
if (isInvalidLocation(event, onlineProfile)) {
return;
}
String[] groups = event.getLoot().lootGroup();
if (groups != null)
for (String group : groups) {
if (this.loot_groups.contains(group) && this.checkConditions(onlineProfile)) {
getCountingData(onlineProfile).progress(event.getAmount());
completeIfDoneOrNotify(onlineProfile);
return;
}
}
}
}
private boolean isInvalidLocation(FishingResultEvent event, final Profile profile) {
if (playerLocation == null || rangeVar == null) {
return false;
}
final Location targetLocation;
try {
targetLocation = playerLocation.getLocation(profile);
} catch (final org.betonquest.betonquest.exceptions.QuestRuntimeException e) {
LogUtils.warn(e.getMessage());
return true;
}
final int range = rangeVar.getInt(profile);
final Location playerLoc = event.getPlayer().getLocation();
return !playerLoc.getWorld().equals(targetLocation.getWorld()) || targetLocation.distanceSquared(playerLoc) > range * range;
}
@Override
public void start() {
Bukkit.getPluginManager().registerEvents(this, BetonQuest.getInstance());
}
@Override
public void stop() {
HandlerList.unregisterAll(this);
}
}
}

View File

@@ -0,0 +1,74 @@
/*
* 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.bukkit.compatibility.quest;
import com.electro2560.dev.cluescrolls.api.*;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.event.FishingResultEvent;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class ClueScrollsHook implements Listener {
private final CustomClue idClue;
private final CustomClue groupClue;
public ClueScrollsHook() {
idClue = ClueScrollsAPI.getInstance().registerCustomClue(BukkitCustomFishingPlugin.getInstance(), "loot", new ClueConfigData("id", DataType.STRING));
groupClue = ClueScrollsAPI.getInstance().registerCustomClue(BukkitCustomFishingPlugin.getInstance(), "group", new ClueConfigData("group", DataType.STRING));
}
public void register() {
Bukkit.getPluginManager().registerEvents(this, BukkitCustomFishingPlugin.get());
}
@EventHandler
public void onFish(FishingResultEvent event) {
if (event.isCancelled() || event.getResult() == FishingResultEvent.Result.FAILURE)
return;
final Player player = event.getPlayer();
idClue.handle(
player,
event.getAmount(),
new ClueDataPair("id", "any")
);
Loot loot = event.getLoot();
if (loot != null) {
idClue.handle(
player,
event.getAmount(),
new ClueDataPair("id", loot.getID())
);
}
if (loot != null && loot.lootGroup() != null) {
for (String group : event.getLoot().lootGroup()) {
groupClue.handle(
player,
event.getAmount(),
new ClueDataPair("group", group)
);
}
}
}
}

View File

@@ -0,0 +1,180 @@
/*
* 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.bukkit.compatibility.quest;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.event.FishingResultEvent;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.checkerframework.checker.nullness.qual.Nullable;
import rocks.gravili.notquests.paper.NotQuests;
import rocks.gravili.notquests.paper.structs.ActiveObjective;
import rocks.gravili.notquests.paper.structs.ActiveQuest;
import rocks.gravili.notquests.paper.structs.QuestPlayer;
import rocks.gravili.notquests.paper.structs.objectives.Objective;
import java.util.Map;
public class NotQuestHook implements Listener {
private final NotQuests notQuestsInstance;
public NotQuestHook() {
this.notQuestsInstance = NotQuests.getInstance();
}
@EventHandler
public void onFish(FishingResultEvent event) {
if (event.isCancelled() || event.getResult() == FishingResultEvent.Result.FAILURE)
return;
Loot loot = event.getLoot();
Player player = event.getPlayer();
final QuestPlayer questPlayer = notQuestsInstance.getQuestPlayerManager().getActiveQuestPlayer(player.getUniqueId());
if (questPlayer != null) {
if (questPlayer.getActiveQuests().size() > 0) {
for (final ActiveQuest activeQuest : questPlayer.getActiveQuests()) {
for (final ActiveObjective activeObjective : activeQuest.getActiveObjectives()) {
if (activeObjective.getObjective() instanceof GroupObjective groupObjective) {
if (activeObjective.isUnlocked()) {
final String[] groups = loot.lootGroup();
if (groups != null)
for (String group : groups) {
if (group.equals(groupObjective.getGroupToFish())) {
activeObjective.addProgress(event.getAmount());
}
}
}
} else if (activeObjective.getObjective() instanceof LootObjective lootObjective) {
if (activeObjective.isUnlocked()) {
if (lootObjective.getLootID().equals(loot.getID()) || lootObjective.getLootID().equals("any")) {
activeObjective.addProgress(event.getAmount());
}
}
}
}
activeQuest.removeCompletedObjectives(true);
}
questPlayer.removeCompletedQuests();
}
}
}
public void register() {
Bukkit.getPluginManager().registerEvents(this, BukkitCustomFishingPlugin.get());
notQuestsInstance.getObjectiveManager().registerObjective("CustomFishingGroup", GroupObjective.class);
notQuestsInstance.getObjectiveManager().registerObjective("CustomFishingGroup", GroupObjective.class);
}
public static class GroupObjective extends Objective {
private String group;
public GroupObjective(NotQuests main) {
super(main);
}
@Override
protected String getTaskDescriptionInternal(QuestPlayer questPlayer, @Nullable ActiveObjective activeObjective) {
return main.getLanguageManager()
.getString(
"chat.objectives.taskDescription.customfishingGroup.base",
questPlayer,
activeObjective,
Map.of("%CUSTOMFISHINGGROUP%", getGroupToFish()));
}
@Override
public void save(FileConfiguration fileConfiguration, String initialPath) {
fileConfiguration.set(initialPath + ".specifics.group", getGroupToFish());
}
@Override
public void load(FileConfiguration fileConfiguration, String initialPath) {
group = fileConfiguration.getString(initialPath + ".specifics.group");
}
@Override
public void onObjectiveUnlock(ActiveObjective activeObjective, boolean b) {
}
@Override
public void onObjectiveCompleteOrLock(ActiveObjective activeObjective, boolean b, boolean b1) {
}
public String getGroupToFish() {
return group;
}
}
public static class LootObjective extends Objective {
private String loot;
public LootObjective(NotQuests main) {
super(main);
}
@Override
protected String getTaskDescriptionInternal(QuestPlayer questPlayer, @Nullable ActiveObjective activeObjective) {
String toReturn;
if (!getLootID().isBlank() && !getLootID().equals("any")) {
toReturn =
main.getLanguageManager()
.getString(
"chat.objectives.taskDescription.customfishingLoot.base",
questPlayer,
activeObjective,
Map.of("%CUSTOMFISHINGLOOT%", getLootID()));
} else {
toReturn =
main.getLanguageManager()
.getString(
"chat.objectives.taskDescription.customfishingLoot.any",
questPlayer,
activeObjective);
}
return toReturn;
}
@Override
public void save(FileConfiguration fileConfiguration, String initialPath) {
fileConfiguration.set(initialPath + ".specifics.id", getLootID());
}
@Override
public void load(FileConfiguration fileConfiguration, String initialPath) {
loot = fileConfiguration.getString(initialPath + ".specifics.id");
}
@Override
public void onObjectiveUnlock(ActiveObjective activeObjective, boolean b) {
}
@Override
public void onObjectiveCompleteOrLock(ActiveObjective activeObjective, boolean b, boolean b1) {
}
public String getLootID() {
return loot;
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* 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.bukkit.compatibility.season;
import net.momirealms.customcrops.api.CustomCropsPlugin;
import net.momirealms.customcrops.api.mechanic.world.season.Season;
import net.momirealms.customfishing.api.integration.SeasonProvider;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
public class CustomCropsSeasonImpl implements SeasonProvider {
@NotNull
@Override
public String getSeason(World world) {
Season season = CustomCropsPlugin.get().getIntegrationManager().getSeason(world);
if (season == null) return "disabled";
return season.name().toUpperCase(Locale.ENGLISH);
}
}

View File

@@ -0,0 +1,39 @@
/*
* 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.bukkit.compatibility.season;
import me.casperge.realisticseasons.api.SeasonsAPI;
import net.momirealms.customfishing.api.integration.SeasonProvider;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
public class RealisticSeasonsImpl implements SeasonProvider {
@NotNull
@Override
public String getSeason(World world) {
return switch (SeasonsAPI.getInstance().getSeason(world)) {
case Season.WINTER -> "winter";
case Season.SPRING -> "spring";
case Season.SUMMER -> "summer";
case Season.FALL -> "autumn";
case Season.DISABLED -> "disabled";
case Season.RESTORE -> "restore";
};
}
}