mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-27 10:59:13 +00:00
checkpoint - 3
This commit is contained in:
@@ -20,11 +20,11 @@ package net.momirealms.customfishing;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.event.CustomFishingReloadEvent;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.IntegrationManagerImpl;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.papi.PlaceholderManagerImpl;
|
||||
import net.momirealms.customfishing.bukkit.misc.placeholder.BukkitPlaceholderManager;
|
||||
import net.momirealms.customfishing.mechanic.action.ActionManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.bag.BagManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.block.BlockManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.competition.CompetitionManagerImpl;
|
||||
import net.momirealms.customfishing.bukkit.competition.CompetitionManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.effect.EffectManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.entity.EntityManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.fishing.FishingManagerImpl;
|
||||
@@ -111,7 +111,7 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin {
|
||||
this.lootManager = new LootManagerImpl(this);
|
||||
this.marketManager = new MarketManagerImpl(this);
|
||||
this.entityManager = new EntityManagerImpl(this);
|
||||
this.placeholderManager = new PlaceholderManagerImpl(this);
|
||||
this.placeholderManager = new BukkitPlaceholderManager(this);
|
||||
this.requirementManager = new RequirementManagerImpl(this);
|
||||
this.scheduler = new SchedulerImpl(this);
|
||||
this.storageManager = new StorageManagerImpl(this);
|
||||
@@ -150,7 +150,7 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin {
|
||||
if (this.integrationManager != null) ((IntegrationManagerImpl) this.integrationManager).disable();
|
||||
if (this.competitionManager != null) ((CompetitionManagerImpl) this.competitionManager).disable();
|
||||
if (this.storageManager != null) ((StorageManagerImpl) this.storageManager).disable();
|
||||
if (this.placeholderManager != null) ((PlaceholderManagerImpl) this.placeholderManager).disable();
|
||||
if (this.placeholderManager != null) ((BukkitPlaceholderManager) this.placeholderManager).disable();
|
||||
if (this.statisticsManager != null) ((StatisticsManagerImpl) this.statisticsManager).disable();
|
||||
if (this.actionManager != null) ((ActionManagerImpl) this.actionManager).disable();
|
||||
if (this.totemManager != null) ((TotemManagerImpl) this.totemManager).disable();
|
||||
@@ -198,8 +198,8 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin {
|
||||
((StorageManagerImpl) this.storageManager).reload();
|
||||
((StatisticsManagerImpl) this.statisticsManager).unload();
|
||||
((StatisticsManagerImpl) this.statisticsManager).load();
|
||||
((PlaceholderManagerImpl) this.placeholderManager).unload();
|
||||
((PlaceholderManagerImpl) this.placeholderManager).load();
|
||||
((BukkitPlaceholderManager) this.placeholderManager).unload();
|
||||
((BukkitPlaceholderManager) this.placeholderManager).load();
|
||||
((HookManagerImpl) this.hookManager).unload();
|
||||
((HookManagerImpl) this.hookManager).load();
|
||||
this.commandManager.unload();
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
package net.momirealms.customfishing.bukkit.action;
|
||||
|
||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.mechanic.action.*;
|
||||
import net.momirealms.customfishing.common.helper.AdventureHelper;
|
||||
import net.momirealms.customfishing.common.util.ClassUtils;
|
||||
import net.momirealms.customfishing.common.util.ListUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BukkitActionManager implements ActionManager<Player> {
|
||||
|
||||
private final BukkitCustomFishingPlugin plugin;
|
||||
private final HashMap<String, ActionFactory<Player>> actionFactoryMap = new HashMap<>();
|
||||
private static final String EXPANSION_FOLDER = "expansions/action";
|
||||
|
||||
public BukkitActionManager(BukkitCustomFishingPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.registerBuiltInActions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerAction(String type, ActionFactory<Player> actionFactory) {
|
||||
if (this.actionFactoryMap.containsKey(type)) return false;
|
||||
this.actionFactoryMap.put(type, actionFactory);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unregisterAction(String type) {
|
||||
return this.actionFactoryMap.remove(type) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ActionFactory<Player> getActionFactory(@NotNull String type) {
|
||||
return actionFactoryMap.get(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAction(@NotNull String type) {
|
||||
return actionFactoryMap.containsKey(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action<Player> parseAction(Section section) {
|
||||
ActionFactory<Player> factory = getActionFactory(section.getString("type"));
|
||||
if (factory == null) {
|
||||
plugin.getPluginLogger().warn("Action type: " + section.getString("type") + " doesn't exist.");
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
return factory.process(section.get("value"), section.getDouble("chance", 1d));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Action<Player>[] parseActions(@NotNull Section section) {
|
||||
ArrayList<Action<Player>> actionList = new ArrayList<>();
|
||||
for (Map.Entry<String, Object> entry : section.getStringRouteMappedValues(false).entrySet()) {
|
||||
if (entry.getValue() instanceof Section innerSection) {
|
||||
Action<Player> action = parseAction(innerSection);
|
||||
if (action != null)
|
||||
actionList.add(action);
|
||||
}
|
||||
}
|
||||
return actionList.toArray(new Action[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action<Player> parseAction(@NotNull String type, @NotNull Object args) {
|
||||
ActionFactory<Player> factory = getActionFactory(type);
|
||||
if (factory == null) {
|
||||
plugin.getPluginLogger().warn("Action type: " + type + " doesn't exist.");
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
return factory.process(args, 1);
|
||||
}
|
||||
|
||||
private void registerBuiltInActions() {
|
||||
this.registerMessageAction();
|
||||
}
|
||||
|
||||
private void registerMessageAction() {
|
||||
registerAction("message", (args, chance) -> {
|
||||
List<String> messages = ListUtils.toList(args);
|
||||
return context -> {
|
||||
if (Math.random() > chance) return;
|
||||
List<String> replaced = plugin.getPlaceholderManager().parse(context.getHolder(), messages, context.toPlaceholderMap());
|
||||
Audience audience = plugin.getSenderFactory().getAudience(context.getHolder());
|
||||
for (String text : replaced) {
|
||||
audience.sendMessage(AdventureHelper.getMiniMessage().deserialize(text));
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads custom ActionExpansions from JAR files located in the expansion directory.
|
||||
* This method scans the expansion folder for JAR files, loads classes that extend ActionExpansion,
|
||||
* and registers them with the appropriate action type and ActionFactory.
|
||||
*/
|
||||
@SuppressWarnings({"ResultOfMethodCallIgnored", "unchecked"})
|
||||
private void loadExpansions() {
|
||||
File expansionFolder = new File(plugin.getDataFolder(), EXPANSION_FOLDER);
|
||||
if (!expansionFolder.exists())
|
||||
expansionFolder.mkdirs();
|
||||
|
||||
List<Class<? extends ActionExpansion<Player>>> classes = new ArrayList<>();
|
||||
File[] expansionJars = expansionFolder.listFiles();
|
||||
if (expansionJars == null) return;
|
||||
for (File expansionJar : expansionJars) {
|
||||
if (expansionJar.getName().endsWith(".jar")) {
|
||||
try {
|
||||
Class<? extends ActionExpansion<Player>> expansionClass = (Class<? extends ActionExpansion<Player>>) ClassUtils.findClass(expansionJar, ActionExpansion.class);
|
||||
classes.add(expansionClass);
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
plugin.getPluginLogger().warn("Failed to load expansion: " + expansionJar.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
for (Class<? extends ActionExpansion<Player>> expansionClass : classes) {
|
||||
ActionExpansion<Player> expansion = expansionClass.getDeclaredConstructor().newInstance();
|
||||
unregisterAction(expansion.getActionType());
|
||||
registerAction(expansion.getActionType(), expansion.getActionFactory());
|
||||
plugin.getPluginLogger().info("Loaded action expansion: " + expansion.getActionType() + "[" + expansion.getVersion() + "]" + " by " + expansion.getAuthor() );
|
||||
}
|
||||
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
|
||||
plugin.getPluginLogger().warn("Error occurred when creating expansion instance.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package net.momirealms.customfishing.bukkit.command;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.common.command.AbstractCommandFeature;
|
||||
import net.momirealms.customfishing.common.command.CustomFishingCommandManager;
|
||||
import net.momirealms.customfishing.common.sender.SenderFactory;
|
||||
import net.momirealms.customfishing.common.util.Pair;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.incendo.cloud.bukkit.data.Selector;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class BukkitCommandFeature<C extends CommandSender> extends AbstractCommandFeature<C> {
|
||||
|
||||
public BukkitCommandFeature(CustomFishingCommandManager<C> commandManager) {
|
||||
super(commandManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected SenderFactory<?, C> getSenderFactory() {
|
||||
return (SenderFactory<?, C>) BukkitCustomFishingPlugin.getInstance().getSenderFactory();
|
||||
}
|
||||
|
||||
public Pair<TranslatableComponent.Builder, Component> resolveSelector(Selector<? extends Entity> selector, TranslatableComponent.Builder single, TranslatableComponent.Builder multiple) {
|
||||
Collection<? extends Entity> entities = selector.values();
|
||||
if (entities.size() == 1) {
|
||||
return Pair.of(single, Component.text(entities.iterator().next().getName()));
|
||||
} else {
|
||||
return Pair.of(multiple, Component.text(entities.size()));
|
||||
}
|
||||
}
|
||||
|
||||
public Pair<TranslatableComponent.Builder, Component> resolveSelector(Collection<? extends Entity> selector, TranslatableComponent.Builder single, TranslatableComponent.Builder multiple) {
|
||||
if (selector.size() == 1) {
|
||||
return Pair.of(single, Component.text(selector.iterator().next().getName()));
|
||||
} else {
|
||||
return Pair.of(multiple, Component.text(selector.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.momirealms.customfishing.bukkit.command;
|
||||
|
||||
import net.kyori.adventure.util.Index;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.bukkit.command.feature.ReloadCommand;
|
||||
import net.momirealms.customfishing.common.command.AbstractCommandManager;
|
||||
import net.momirealms.customfishing.common.command.CommandFeature;
|
||||
import net.momirealms.customfishing.common.sender.Sender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.incendo.cloud.SenderMapper;
|
||||
import org.incendo.cloud.execution.ExecutionCoordinator;
|
||||
import org.incendo.cloud.paper.PaperCommandManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitCommandManager extends AbstractCommandManager<CommandSender> {
|
||||
|
||||
private final List<CommandFeature<CommandSender>> FEATURES = List.of(
|
||||
new ReloadCommand(this)
|
||||
);
|
||||
|
||||
private final Index<String, CommandFeature<CommandSender>> INDEX = Index.create(CommandFeature::getFeatureID, FEATURES);
|
||||
|
||||
public BukkitCommandManager(BukkitCustomFishingPlugin plugin) {
|
||||
super(plugin, new PaperCommandManager<>(
|
||||
plugin.getBoostrap(),
|
||||
ExecutionCoordinator.simpleCoordinator(),
|
||||
SenderMapper.identity()
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sender wrapSender(CommandSender sender) {
|
||||
return ((BukkitCustomFishingPlugin) plugin).getSenderFactory().wrap(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Index<String, CommandFeature<CommandSender>> getFeatures() {
|
||||
return INDEX;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.momirealms.customfishing.bukkit.command.feature;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.command.BukkitCommandFeature;
|
||||
import net.momirealms.customfishing.common.command.CustomFishingCommandManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
public class ReloadCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public ReloadCommand(CustomFishingCommandManager<CommandSender> commandManager) {
|
||||
super(commandManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command.Builder<? extends CommandSender> assembleCommand(CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeatureID() {
|
||||
return "reload";
|
||||
}
|
||||
}
|
||||
@@ -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.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;
|
||||
}
|
||||
}
|
||||
@@ -1,50 +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.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();
|
||||
}
|
||||
}
|
||||
@@ -1,51 +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.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();
|
||||
}
|
||||
}
|
||||
@@ -1,38 +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.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;
|
||||
}
|
||||
}
|
||||
@@ -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.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;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.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();
|
||||
}
|
||||
}
|
||||
@@ -1,63 +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.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.");
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.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)));
|
||||
}
|
||||
}
|
||||
@@ -1,44 +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.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);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +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.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();
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.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");
|
||||
}
|
||||
}
|
||||
@@ -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.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;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +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.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);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +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.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;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +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.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);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.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();
|
||||
}
|
||||
}
|
||||
@@ -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.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);
|
||||
}
|
||||
}
|
||||
@@ -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.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))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.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));
|
||||
}
|
||||
}
|
||||
@@ -1,43 +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.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);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +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.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)));
|
||||
}
|
||||
}
|
||||
@@ -1,51 +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.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;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +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.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));
|
||||
}
|
||||
}
|
||||
@@ -1,36 +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.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));
|
||||
}
|
||||
}
|
||||
@@ -1,126 +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.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 CFPapi extends PlaceholderExpansion {
|
||||
|
||||
private final BukkitCustomFishingPlugin plugin;
|
||||
|
||||
public CFPapi(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;
|
||||
}
|
||||
}
|
||||
@@ -1,144 +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.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";
|
||||
}
|
||||
}
|
||||
@@ -1,33 +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.bukkit.compatibility.papi;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ParseUtils {
|
||||
|
||||
public static String setPlaceholders(Player player, String text) {
|
||||
return PlaceholderAPI.setPlaceholders(player, text);
|
||||
}
|
||||
|
||||
public static String setPlaceholders(OfflinePlayer player, String text) {
|
||||
return PlaceholderAPI.setPlaceholders(player, text);
|
||||
}
|
||||
}
|
||||
@@ -1,220 +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.bukkit.compatibility.papi;
|
||||
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.manager.PlaceholderManager;
|
||||
import net.momirealms.customfishing.util.ConfigUtils;
|
||||
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlaceholderManagerImpl implements PlaceholderManager {
|
||||
|
||||
private static PlaceholderManagerImpl instance;
|
||||
private final BukkitCustomFishingPlugin plugin;
|
||||
private final boolean hasPapi;
|
||||
private final Pattern pattern;
|
||||
private final HashMap<String, String> customPlaceholderMap;
|
||||
private CompetitionPapi competitionPapi;
|
||||
private StatisticsPapi statisticsPapi;
|
||||
private CFPapi cfPapi;
|
||||
|
||||
public PlaceholderManagerImpl(BukkitCustomFishingPlugin plugin) {
|
||||
instance = this;
|
||||
this.plugin = plugin;
|
||||
this.hasPapi = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
|
||||
this.pattern = Pattern.compile("\\{[^{}]+}");
|
||||
this.customPlaceholderMap = new HashMap<>();
|
||||
if (this.hasPapi) {
|
||||
competitionPapi = new CompetitionPapi(plugin);
|
||||
statisticsPapi = new StatisticsPapi(plugin);
|
||||
cfPapi = new CFPapi(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
if (competitionPapi != null) competitionPapi.load();
|
||||
if (statisticsPapi != null) statisticsPapi.load();
|
||||
if (cfPapi != null) cfPapi.load();
|
||||
loadCustomPlaceholders();
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
if (competitionPapi != null) competitionPapi.unload();
|
||||
if (statisticsPapi != null) statisticsPapi.unload();
|
||||
if (cfPapi != null) cfPapi.unload();
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
this.customPlaceholderMap.clear();
|
||||
}
|
||||
|
||||
public void loadCustomPlaceholders() {
|
||||
YamlConfiguration config = plugin.getConfig("config.yml");
|
||||
ConfigurationSection section = config.getConfigurationSection("other-settings.placeholder-register");
|
||||
if (section != null) {
|
||||
for (Map.Entry<String, Object> entry : section.getValues(false).entrySet()) {
|
||||
registerCustomPlaceholder(entry.getKey(), (String) entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerCustomPlaceholder(String placeholder, String original) {
|
||||
if (this.customPlaceholderMap.containsKey(placeholder)) {
|
||||
return false;
|
||||
}
|
||||
this.customPlaceholderMap.put(placeholder, original);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set placeholders in a text string for a player.
|
||||
*
|
||||
* @param player The player for whom the placeholders should be set.
|
||||
* @param text The text string containing placeholders.
|
||||
* @return The text string with placeholders replaced if PlaceholderAPI is available; otherwise, the original text.
|
||||
*/
|
||||
@Override
|
||||
public String setPlaceholders(Player player, String text) {
|
||||
return hasPapi ? ParseUtils.setPlaceholders(player, text) : text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set placeholders in a text string for an offline player.
|
||||
*
|
||||
* @param player The offline player for whom the placeholders should be set.
|
||||
* @param text The text string containing placeholders.
|
||||
* @return The text string with placeholders replaced if PlaceholderAPI is available; otherwise, the original text.
|
||||
*/
|
||||
@Override
|
||||
public String setPlaceholders(OfflinePlayer player, String text) {
|
||||
return hasPapi ? ParseUtils.setPlaceholders(player, text) : text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect and extract placeholders from a text string.
|
||||
*
|
||||
* @param text The text string to search for placeholders.
|
||||
* @return A list of detected placeholders in the text.
|
||||
*/
|
||||
@Override
|
||||
public List<String> detectPlaceholders(String text) {
|
||||
List<String> placeholders = new ArrayList<>();
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
while (matcher.find()) placeholders.add(matcher.group());
|
||||
return placeholders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value associated with a single placeholder.
|
||||
*
|
||||
* @param player The player for whom the placeholders are being resolved (nullable).
|
||||
* @param placeholder The placeholder to look up.
|
||||
* @param placeholders A map of placeholders to their corresponding values.
|
||||
* @return The value associated with the placeholder, or the original placeholder if not found.
|
||||
*/
|
||||
@Override
|
||||
public String getSingleValue(@Nullable Player player, String placeholder, Map<String, String> placeholders) {
|
||||
String result = null;
|
||||
if (placeholders != null)
|
||||
result = placeholders.get(placeholder);
|
||||
if (result != null)
|
||||
return result;
|
||||
String custom = customPlaceholderMap.get(placeholder);
|
||||
if (custom == null)
|
||||
return placeholder;
|
||||
return setPlaceholders(player, custom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a text string by replacing placeholders with their corresponding values.
|
||||
*
|
||||
* @param player The offline player for whom the placeholders are being resolved (nullable).
|
||||
* @param text The text string containing placeholders.
|
||||
* @param placeholders A map of placeholders to their corresponding values.
|
||||
* @return The text string with placeholders replaced by their values.
|
||||
*/
|
||||
@Override
|
||||
public String parse(@Nullable OfflinePlayer player, String text, Map<String, String> placeholders) {
|
||||
var list = detectPlaceholders(text);
|
||||
for (String papi : list) {
|
||||
String replacer = null;
|
||||
if (placeholders != null) {
|
||||
replacer = placeholders.get(papi);
|
||||
}
|
||||
if (replacer == null) {
|
||||
String custom = customPlaceholderMap.get(papi);
|
||||
if (custom != null) {
|
||||
replacer = setPlaceholders(player, parse(player, custom, placeholders));
|
||||
}
|
||||
}
|
||||
if (replacer != null) {
|
||||
text = text.replace(papi, replacer);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a list of text strings by replacing placeholders with their corresponding values.
|
||||
*
|
||||
* @param player The player for whom the placeholders are being resolved (can be null for offline players).
|
||||
* @param list The list of text strings containing placeholders.
|
||||
* @param replacements A map of custom replacements for placeholders.
|
||||
* @return The list of text strings with placeholders replaced by their values.
|
||||
*/
|
||||
@Override
|
||||
public List<String> parse(@Nullable OfflinePlayer player, List<String> list, Map<String, String> replacements) {
|
||||
return list.stream()
|
||||
.map(s -> parse(player, s, replacements))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
public static PlaceholderManagerImpl getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean hasPapi() {
|
||||
return hasPapi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getExpressionValue(Player player, String formula, Map<String, String> vars) {
|
||||
return ConfigUtils.getExpressionValue(player, formula, vars);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getExpressionValue(String formula) {
|
||||
return new ExpressionBuilder(formula).build().evaluate();
|
||||
}
|
||||
}
|
||||
@@ -1,112 +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.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";
|
||||
}
|
||||
}
|
||||
@@ -1,79 +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.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,190 +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.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,74 +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.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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,180 +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.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +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.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);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.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 WINTER -> "winter";
|
||||
case SPRING -> "spring";
|
||||
case SUMMER -> "summer";
|
||||
case FALL -> "autumn";
|
||||
case DISABLED -> "disabled";
|
||||
case RESTORE -> "restore";
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -15,21 +15,21 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.mechanic.competition;
|
||||
package net.momirealms.customfishing.bukkit.competition;
|
||||
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.common.Pair;
|
||||
import net.momirealms.customfishing.api.event.CompetitionEvent;
|
||||
import net.momirealms.customfishing.api.mechanic.action.Action;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.CompetitionConfig;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.CompetitionConfigImpl;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.CompetitionGoal;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.Ranking;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.RankingProvider;
|
||||
import net.momirealms.customfishing.api.scheduler.CancellableTask;
|
||||
import net.momirealms.customfishing.mechanic.competition.actionbar.ActionBarManager;
|
||||
import net.momirealms.customfishing.mechanic.competition.bossbar.BossBarManager;
|
||||
import net.momirealms.customfishing.mechanic.competition.ranking.LocalRankingImpl;
|
||||
import net.momirealms.customfishing.mechanic.competition.ranking.RedisRankingImpl;
|
||||
import net.momirealms.customfishing.bukkit.competition.bossbar.BossBarManager;
|
||||
import net.momirealms.customfishing.bukkit.competition.ranking.LocalRankingProvider;
|
||||
import net.momirealms.customfishing.bukkit.competition.actionbar.ActionBarManager;
|
||||
import net.momirealms.customfishing.bukkit.competition.ranking.RedisRankingProvider;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -45,22 +45,22 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Competition implements FishingCompetition {
|
||||
|
||||
private final CompetitionConfig config;
|
||||
private final CompetitionConfigImpl config;
|
||||
private CancellableTask competitionTimerTask;
|
||||
private final CompetitionGoal goal;
|
||||
private final ConcurrentHashMap<String, String> publicPlaceholders;
|
||||
private final Ranking ranking;
|
||||
private final RankingProvider rankingProvider;
|
||||
private float progress;
|
||||
private long remainingTime;
|
||||
private long startTime;
|
||||
private BossBarManager bossBarManager;
|
||||
private ActionBarManager actionBarManager;
|
||||
|
||||
public Competition(CompetitionConfig config) {
|
||||
public Competition(CompetitionConfigImpl config) {
|
||||
this.config = config;
|
||||
this.goal = config.getGoal() == CompetitionGoal.RANDOM ? CompetitionGoal.getRandom() : config.getGoal();
|
||||
if (CFConfig.redisRanking) this.ranking = new RedisRankingImpl();
|
||||
else this.ranking = new LocalRankingImpl();
|
||||
if (CFConfig.redisRanking) this.rankingProvider = new RedisRankingProvider();
|
||||
else this.rankingProvider = new LocalRankingProvider();
|
||||
this.publicPlaceholders = new ConcurrentHashMap<>();
|
||||
this.publicPlaceholders.put("{goal}", BukkitCustomFishingPlugin.get().getCompetitionManager().getCompetitionGoalLocale(goal));
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public class Competition implements FishingCompetition {
|
||||
this.actionBarManager.load();
|
||||
}
|
||||
|
||||
Action[] actions = config.getStartActions();
|
||||
Action[] actions = config.startActions();
|
||||
if (actions != null) {
|
||||
PlayerContext playerContext = new PlayerContext(null, null, this.publicPlaceholders);
|
||||
for (Action action : actions) {
|
||||
@@ -95,7 +95,7 @@ public class Competition implements FishingCompetition {
|
||||
}
|
||||
}
|
||||
|
||||
this.ranking.clear();
|
||||
this.rankingProvider.clear();
|
||||
this.updatePublicPlaceholders();
|
||||
|
||||
CompetitionEvent competitionStartEvent = new CompetitionEvent(CompetitionEvent.State.START, this);
|
||||
@@ -126,9 +126,9 @@ public class Competition implements FishingCompetition {
|
||||
private void updatePublicPlaceholders() {
|
||||
for (int i = 1; i < CFConfig.placeholderLimit + 1; i++) {
|
||||
int finalI = i;
|
||||
Optional.ofNullable(ranking.getPlayerAt(i)).ifPresentOrElse(player -> {
|
||||
Optional.ofNullable(rankingProvider.getPlayerAt(i)).ifPresentOrElse(player -> {
|
||||
publicPlaceholders.put("{" + finalI + "_player}", player);
|
||||
publicPlaceholders.put("{" + finalI + "_score}", String.format("%.2f", ranking.getScoreAt(finalI)));
|
||||
publicPlaceholders.put("{" + finalI + "_score}", String.format("%.2f", rankingProvider.getScoreAt(finalI)));
|
||||
}, () -> {
|
||||
publicPlaceholders.put("{" + finalI + "_player}", CFLocale.MSG_No_Player);
|
||||
publicPlaceholders.put("{" + finalI + "_score}", CFLocale.MSG_No_Score);
|
||||
@@ -150,7 +150,7 @@ public class Competition implements FishingCompetition {
|
||||
if (!competitionTimerTask.isCancelled()) this.competitionTimerTask.cancel();
|
||||
if (this.bossBarManager != null) this.bossBarManager.unload();
|
||||
if (this.actionBarManager != null) this.actionBarManager.unload();
|
||||
this.ranking.clear();
|
||||
this.rankingProvider.clear();
|
||||
this.remainingTime = 0;
|
||||
|
||||
if (triggerEvent) {
|
||||
@@ -176,8 +176,8 @@ public class Competition implements FishingCompetition {
|
||||
|
||||
// give prizes
|
||||
HashMap<String, Action[]> rewardsMap = config.getRewards();
|
||||
if (ranking.getSize() != 0 && rewardsMap != null) {
|
||||
Iterator<Pair<String, Double>> iterator = ranking.getIterator();
|
||||
if (rankingProvider.getSize() != 0 && rewardsMap != null) {
|
||||
Iterator<Pair<String, Double>> iterator = rankingProvider.getIterator();
|
||||
int i = 1;
|
||||
while (iterator.hasNext()) {
|
||||
Pair<String, Double> competitionPlayer = iterator.next();
|
||||
@@ -218,7 +218,7 @@ public class Competition implements FishingCompetition {
|
||||
}
|
||||
|
||||
// 1 seconds delay for other servers to read the redis data
|
||||
BukkitCustomFishingPlugin.get().getScheduler().runTaskAsyncLater(this.ranking::clear, 1, TimeUnit.SECONDS);
|
||||
BukkitCustomFishingPlugin.get().getScheduler().runTaskAsyncLater(this.rankingProvider::clear, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,11 +270,11 @@ public class Competition implements FishingCompetition {
|
||||
|
||||
// refresh data
|
||||
switch (this.goal) {
|
||||
case CATCH_AMOUNT -> ranking.refreshData(player.getName(), 1);
|
||||
case TOTAL_SIZE, TOTAL_SCORE -> ranking.refreshData(player.getName(), score);
|
||||
case CATCH_AMOUNT -> rankingProvider.refreshData(player.getName(), 1);
|
||||
case TOTAL_SIZE, TOTAL_SCORE -> rankingProvider.refreshData(player.getName(), score);
|
||||
case MAX_SIZE -> {
|
||||
if (score > ranking.getPlayerScore(player.getName())) {
|
||||
ranking.setData(player.getName(), score);
|
||||
if (score > rankingProvider.getPlayerScore(player.getName())) {
|
||||
rankingProvider.setData(player.getName(), score);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,7 +288,7 @@ public class Competition implements FishingCompetition {
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPlayerJoined(OfflinePlayer player) {
|
||||
return ranking.getPlayerRank(player.getName()) != -1;
|
||||
return rankingProvider.getPlayerRank(player.getName()) != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -328,7 +328,7 @@ public class Competition implements FishingCompetition {
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public CompetitionConfig getConfig() {
|
||||
public CompetitionConfigImpl getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -350,8 +350,8 @@ public class Competition implements FishingCompetition {
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public Ranking getRanking() {
|
||||
return ranking;
|
||||
public RankingProvider getRanking() {
|
||||
return rankingProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.mechanic.competition;
|
||||
package net.momirealms.customfishing.bukkit.competition;
|
||||
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.common.Pair;
|
||||
@@ -42,8 +42,8 @@ import java.util.concurrent.TimeUnit;
|
||||
public class CompetitionManagerImpl implements CompetitionManager {
|
||||
|
||||
private final BukkitCustomFishingPlugin plugin;
|
||||
private final HashMap<CompetitionSchedule, CompetitionConfig> timeConfigMap;
|
||||
private final HashMap<String, CompetitionConfig> commandConfigMap;
|
||||
private final HashMap<CompetitionSchedule, CompetitionConfigImpl> timeConfigMap;
|
||||
private final HashMap<String, CompetitionConfigImpl> commandConfigMap;
|
||||
private Competition currentCompetition;
|
||||
private CancellableTask timerCheckTask;
|
||||
private int nextCompetitionSeconds;
|
||||
@@ -124,12 +124,12 @@ public class CompetitionManagerImpl implements CompetitionManager {
|
||||
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
|
||||
if (entry.getValue() instanceof ConfigurationSection section) {
|
||||
|
||||
CompetitionConfig.Builder builder = new CompetitionConfig.Builder(entry.getKey())
|
||||
CompetitionConfigImpl.Builder builder = new CompetitionConfigImpl.Builder(entry.getKey())
|
||||
.goal(CompetitionGoal.valueOf(section.getString("goal", "TOTAL_SCORE").toUpperCase(Locale.ENGLISH)))
|
||||
.minPlayers(section.getInt("min-players", 0))
|
||||
.duration(section.getInt("duration", 300))
|
||||
.rewards(getPrizeActions(section.getConfigurationSection("rewards")))
|
||||
.requirements(plugin.getRequirementManager().getRequirements(section.getConfigurationSection("participate-requirements"), false))
|
||||
.requirements(plugin.getRequirementManager().parseRequirements(section.getConfigurationSection("participate-requirements"), false))
|
||||
.joinActions(plugin.getActionManager().getActions(section.getConfigurationSection("participate-actions")))
|
||||
.startActions(plugin.getActionManager().getActions(section.getConfigurationSection("start-actions")))
|
||||
.endActions(plugin.getActionManager().getActions(section.getConfigurationSection("end-actions")))
|
||||
@@ -155,7 +155,7 @@ public class CompetitionManagerImpl implements CompetitionManager {
|
||||
.build());
|
||||
}
|
||||
|
||||
CompetitionConfig competitionConfig = builder.build();
|
||||
CompetitionConfigImpl competitionConfigImpl = builder.build();
|
||||
List<Pair<Integer, Integer>> timePairs = section.getStringList("start-time")
|
||||
.stream().map(it -> ConfigUtils.splitStringIntegerArgs(it, ":")).toList();
|
||||
List<Integer> weekdays = section.getIntegerList("start-weekday");
|
||||
@@ -165,10 +165,10 @@ public class CompetitionManagerImpl implements CompetitionManager {
|
||||
for (Integer weekday : weekdays) {
|
||||
for (Pair<Integer, Integer> timePair : timePairs) {
|
||||
CompetitionSchedule schedule = new CompetitionSchedule(weekday, timePair.left(), timePair.right(), 0);
|
||||
timeConfigMap.put(schedule, competitionConfig);
|
||||
timeConfigMap.put(schedule, competitionConfigImpl);
|
||||
}
|
||||
}
|
||||
commandConfigMap.put(entry.getKey(), competitionConfig);
|
||||
commandConfigMap.put(entry.getKey(), competitionConfigImpl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,7 +207,7 @@ public class CompetitionManagerImpl implements CompetitionManager {
|
||||
nextCompetitionTime = Math.min(nextCompetitionTime, schedule.getTimeDelta(seconds));
|
||||
}
|
||||
this.nextCompetitionSeconds = nextCompetitionTime;
|
||||
CompetitionConfig config = timeConfigMap.get(competitionSchedule);
|
||||
CompetitionConfigImpl config = timeConfigMap.get(competitionSchedule);
|
||||
if (config != null) {
|
||||
startCompetition(config, false, null);
|
||||
}
|
||||
@@ -241,7 +241,7 @@ public class CompetitionManagerImpl implements CompetitionManager {
|
||||
|
||||
@Override
|
||||
public boolean startCompetition(String competition, boolean force, String serverGroup) {
|
||||
CompetitionConfig config = commandConfigMap.get(competition);
|
||||
CompetitionConfigImpl config = commandConfigMap.get(competition);
|
||||
if (config == null) {
|
||||
LogUtils.warn("Competition " + competition + " doesn't exist.");
|
||||
return false;
|
||||
@@ -262,7 +262,7 @@ public class CompetitionManagerImpl implements CompetitionManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startCompetition(CompetitionConfig config, boolean force, @Nullable String serverGroup) {
|
||||
public boolean startCompetition(CompetitionConfigImpl config, boolean force, @Nullable String serverGroup) {
|
||||
if (!force) {
|
||||
int players = Bukkit.getOnlinePlayers().size();
|
||||
if (players < config.getMinPlayersToStart()) {
|
||||
@@ -286,7 +286,7 @@ public class CompetitionManagerImpl implements CompetitionManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void start(CompetitionConfig config) {
|
||||
private void start(CompetitionConfigImpl config) {
|
||||
if (getOnGoingCompetition() != null) {
|
||||
// END
|
||||
currentCompetition.end(true);
|
||||
@@ -318,11 +318,11 @@ public class CompetitionManagerImpl implements CompetitionManager {
|
||||
* Retrieves the configuration for a competition based on its key.
|
||||
*
|
||||
* @param key The key of the competition configuration to retrieve.
|
||||
* @return The {@link CompetitionConfig} for the specified key, or {@code null} if no configuration exists with that key.
|
||||
* @return The {@link CompetitionConfigImpl} for the specified key, or {@code null} if no configuration exists with that key.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public CompetitionConfig getConfig(String key) {
|
||||
public CompetitionConfigImpl getConfig(String key) {
|
||||
return commandConfigMap.get(key);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.mechanic.competition;
|
||||
package net.momirealms.customfishing.bukkit.competition;
|
||||
|
||||
public class CompetitionSchedule {
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.mechanic.competition.actionbar;
|
||||
package net.momirealms.customfishing.bukkit.competition.actionbar;
|
||||
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfigImpl;
|
||||
import net.momirealms.customfishing.mechanic.competition.Competition;
|
||||
import net.momirealms.customfishing.bukkit.competition.Competition;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -15,12 +15,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.mechanic.competition.actionbar;
|
||||
package net.momirealms.customfishing.bukkit.competition.actionbar;
|
||||
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfigImpl;
|
||||
import net.momirealms.customfishing.api.scheduler.CancellableTask;
|
||||
import net.momirealms.customfishing.mechanic.competition.Competition;
|
||||
import net.momirealms.customfishing.bukkit.competition.Competition;
|
||||
import net.momirealms.customfishing.mechanic.misc.DynamicText;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.mechanic.competition.bossbar;
|
||||
package net.momirealms.customfishing.bukkit.competition.bossbar;
|
||||
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfigImpl;
|
||||
import net.momirealms.customfishing.mechanic.competition.Competition;
|
||||
import net.momirealms.customfishing.bukkit.competition.Competition;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.mechanic.competition.bossbar;
|
||||
package net.momirealms.customfishing.bukkit.competition.bossbar;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.InternalStructure;
|
||||
@@ -28,7 +28,7 @@ import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfigImpl;
|
||||
import net.momirealms.customfishing.api.scheduler.CancellableTask;
|
||||
import net.momirealms.customfishing.api.util.ReflectionUtils;
|
||||
import net.momirealms.customfishing.mechanic.competition.Competition;
|
||||
import net.momirealms.customfishing.bukkit.competition.Competition;
|
||||
import net.momirealms.customfishing.mechanic.misc.DynamicText;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -15,22 +15,21 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.mechanic.competition.ranking;
|
||||
package net.momirealms.customfishing.bukkit.competition.ranking;
|
||||
|
||||
import net.momirealms.customfishing.api.common.Pair;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.CompetitionPlayer;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.Ranking;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.RankingProvider;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Implementation of the Ranking interface that manages the ranking of competition players locally.
|
||||
*/
|
||||
public class LocalRankingImpl implements Ranking {
|
||||
public class LocalRankingProvider implements RankingProvider {
|
||||
|
||||
private final Set<CompetitionPlayer> competitionPlayers;
|
||||
|
||||
public LocalRankingImpl() {
|
||||
public LocalRankingProvider() {
|
||||
competitionPlayers = Collections.synchronizedSet(new TreeSet<>());
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.mechanic.competition.ranking;
|
||||
package net.momirealms.customfishing.bukkit.competition.ranking;
|
||||
|
||||
import net.momirealms.customfishing.api.common.Pair;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.CompetitionPlayer;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.Ranking;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.RankingProvider;
|
||||
import net.momirealms.customfishing.storage.method.database.nosql.RedisManager;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.resps.Tuple;
|
||||
@@ -27,7 +27,7 @@ import redis.clients.jedis.resps.Tuple;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class RedisRankingImpl implements Ranking {
|
||||
public class RedisRankingProvider implements RankingProvider {
|
||||
|
||||
/**
|
||||
* Clears the ranking data by removing all players and scores.
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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.misc.placeholder;
|
||||
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.mechanic.misc.placeholder.PlaceholderManager;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.PlaceholderAPIUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BukkitPlaceholderManager implements PlaceholderManager {
|
||||
|
||||
private final BukkitCustomFishingPlugin plugin;
|
||||
private final boolean hasPapi;
|
||||
private final HashMap<String, String> customPlaceholderMap;
|
||||
|
||||
public BukkitPlaceholderManager(BukkitCustomFishingPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.hasPapi = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
|
||||
this.customPlaceholderMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerCustomPlaceholder(String placeholder, String original) {
|
||||
if (this.customPlaceholderMap.containsKey(placeholder)) return false;
|
||||
this.customPlaceholderMap.put(placeholder, original);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> resolvePlaceholders(String text) {
|
||||
List<String> placeholders = new ArrayList<>();
|
||||
Matcher matcher = PATTERN.matcher(text);
|
||||
while (matcher.find()) placeholders.add(matcher.group());
|
||||
return placeholders;
|
||||
}
|
||||
|
||||
private String setPlaceholders(OfflinePlayer player, String text) {
|
||||
return hasPapi ? PlaceholderAPIUtils.parse(player, text) : text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseSingle(@Nullable OfflinePlayer player, String placeholder, Map<String, String> replacements) {
|
||||
String result = null;
|
||||
if (replacements != null)
|
||||
result = replacements.get(placeholder);
|
||||
if (result != null)
|
||||
return result;
|
||||
String custom = customPlaceholderMap.get(placeholder);
|
||||
if (custom == null)
|
||||
return placeholder;
|
||||
return hasPapi ? PlaceholderAPIUtils.parse(player, custom) : custom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(@Nullable OfflinePlayer player, String text, Map<String, String> replacements) {
|
||||
var list = resolvePlaceholders(text);
|
||||
for (String papi : list) {
|
||||
String replacer = null;
|
||||
if (replacements != null) {
|
||||
replacer = replacements.get(papi);
|
||||
}
|
||||
if (replacer == null) {
|
||||
String custom = customPlaceholderMap.get(papi);
|
||||
if (custom != null) {
|
||||
replacer = setPlaceholders(player, parse(player, custom, replacements));
|
||||
}
|
||||
}
|
||||
if (replacer != null) {
|
||||
text = text.replace(papi, replacer);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> parse(@Nullable OfflinePlayer player, List<String> list, Map<String, String> replacements) {
|
||||
return list.stream()
|
||||
.map(s -> parse(player, s, replacements))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
package net.momirealms.customfishing.bukkit.requirement;
|
||||
|
||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.mechanic.action.Action;
|
||||
import net.momirealms.customfishing.api.mechanic.action.ActionManager;
|
||||
import net.momirealms.customfishing.api.mechanic.context.ContextKeys;
|
||||
import net.momirealms.customfishing.api.mechanic.effect.EffectProperties;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.RequirementExpansion;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.RequirementFactory;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager;
|
||||
import net.momirealms.customfishing.common.util.ClassUtils;
|
||||
import net.momirealms.customfishing.common.util.ListUtils;
|
||||
import net.momirealms.customfishing.common.util.Pair;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.EmptyRequirement;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public class BukkitRequirementManager implements RequirementManager<Player> {
|
||||
|
||||
private final BukkitCustomFishingPlugin plugin;
|
||||
private final HashMap<String, RequirementFactory<Player>> requirementFactoryMap = new HashMap<>();
|
||||
private static final String EXPANSION_FOLDER = "expansions/requirement";
|
||||
|
||||
public BukkitRequirementManager(BukkitCustomFishingPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.registerBuiltInRequirements();
|
||||
this.loadExpansions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerRequirement(@NotNull String type, @NotNull RequirementFactory<Player> requirementFactory) {
|
||||
if (this.requirementFactoryMap.containsKey(type)) return false;
|
||||
this.requirementFactoryMap.put(type, requirementFactory);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unregisterRequirement(@NotNull String type) {
|
||||
return this.requirementFactoryMap.remove(type) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RequirementFactory<Player> getRequirementFactory(@NotNull String type) {
|
||||
return requirementFactoryMap.get(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRequirement(@NotNull String type) {
|
||||
return requirementFactoryMap.containsKey(type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Requirement<Player>[] parseRequirements(@NotNull Section section, boolean runActions) {
|
||||
List<Requirement<Player>> requirements = new ArrayList<>();
|
||||
for (Map.Entry<String, Object> entry : section.getStringRouteMappedValues(false).entrySet()) {
|
||||
String typeOrName = entry.getKey();
|
||||
if (hasRequirement(typeOrName)) {
|
||||
requirements.add(parseRequirement(typeOrName, entry.getValue()));
|
||||
} else {
|
||||
requirements.add(parseRequirement(section.getSection(typeOrName), runActions));
|
||||
}
|
||||
}
|
||||
return requirements.toArray(new Requirement[0]);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Requirement<Player> parseRequirement(@NotNull Section section, boolean runActions) {
|
||||
List<Action<Player>> actionList = new ArrayList<>();
|
||||
if (runActions && section.contains("not-met-actions")) {
|
||||
actionList.addAll(List.of(plugin.getActionManager().parseActions(requireNonNull(section.getSection("not-met-actions")))));
|
||||
}
|
||||
String type = section.getString("type");
|
||||
if (type == null) {
|
||||
plugin.getPluginLogger().warn("No requirement type found at " + section.getRouteAsString());
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
var factory = getRequirementFactory(type);
|
||||
if (factory == null) {
|
||||
plugin.getPluginLogger().warn("No requirement type found at " + section.getRouteAsString());
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
return factory.process(section.get("value"), actionList, runActions);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Requirement<Player> parseRequirement(@NotNull String type, @NotNull Object value) {
|
||||
RequirementFactory<Player> factory = getRequirementFactory(type);
|
||||
if (factory == null) {
|
||||
plugin.getPluginLogger().warn("Requirement type: " + type + " doesn't exist.");
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
return factory.process(value);
|
||||
}
|
||||
|
||||
private void registerBuiltInRequirements() {
|
||||
this.registerTimeRequirement();
|
||||
this.registerYRequirement();
|
||||
this.registerInWaterRequirement();
|
||||
this.registerInVoidRequirement();
|
||||
this.registerInLavaRequirement();
|
||||
this.registerAndRequirement();
|
||||
this.registerOrRequirement();
|
||||
}
|
||||
|
||||
private void registerTimeRequirement() {
|
||||
registerRequirement("time", (args, actions, advanced) -> {
|
||||
List<String> list = ListUtils.toList(args);
|
||||
List<Pair<Integer, Integer>> timePairs = list.stream().map(line -> {
|
||||
String[] split = line.split("~");
|
||||
return new Pair<>(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||
}).toList();
|
||||
return context -> {
|
||||
Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
|
||||
long time = location.getWorld().getTime();
|
||||
for (Pair<Integer, Integer> pair : timePairs)
|
||||
if (time >= pair.left() && time <= pair.right())
|
||||
return true;
|
||||
if (advanced) ActionManager.trigger(context, actions);
|
||||
return false;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private void registerYRequirement() {
|
||||
registerRequirement("ypos", (args, actions, advanced) -> {
|
||||
List<String> list = ListUtils.toList(args);
|
||||
List<Pair<Double, Double>> posPairs = list.stream().map(line -> {
|
||||
String[] split = line.split("~");
|
||||
return new Pair<>(Double.parseDouble(split[0]), Double.parseDouble(split[1]));
|
||||
}).toList();
|
||||
return context -> {
|
||||
Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
|
||||
double y = location.getY();
|
||||
for (Pair<Double, Double> pair : posPairs)
|
||||
if (y >= pair.left() && y <= pair.right())
|
||||
return true;
|
||||
if (advanced) ActionManager.trigger(context, actions);
|
||||
return false;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private void registerOrRequirement() {
|
||||
registerRequirement("||", (args, actions, advanced) -> {
|
||||
if (args instanceof Section section) {
|
||||
Requirement<Player>[] requirements = parseRequirements(section, advanced);
|
||||
return context -> {
|
||||
for (Requirement<Player> requirement : requirements)
|
||||
if (requirement.isSatisfied(context))
|
||||
return true;
|
||||
if (advanced) ActionManager.trigger(context, actions);
|
||||
return false;
|
||||
};
|
||||
} else {
|
||||
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at || requirement which should be Section");
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerAndRequirement() {
|
||||
registerRequirement("&&", (args, actions, advanced) -> {
|
||||
if (args instanceof Section section) {
|
||||
Requirement<Player>[] requirements = parseRequirements(section, advanced);
|
||||
return context -> {
|
||||
outer: {
|
||||
for (Requirement<Player> requirement : requirements)
|
||||
if (!requirement.isSatisfied(context))
|
||||
break outer;
|
||||
return true;
|
||||
}
|
||||
if (advanced) ActionManager.trigger(context, actions);
|
||||
return false;
|
||||
};
|
||||
} else {
|
||||
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at && requirement which should be Section");
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerInWaterRequirement() {
|
||||
registerRequirement("in-water", (args, actions, advanced) -> {
|
||||
boolean inWater = (boolean) args;
|
||||
return context -> {
|
||||
boolean in_water = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.WATER_FISHING.key());
|
||||
if (in_water == inWater) return true;
|
||||
if (advanced) ActionManager.trigger(context, actions);
|
||||
return false;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private void registerInVoidRequirement() {
|
||||
registerRequirement("in-void", (args, actions, advanced) -> {
|
||||
boolean inWater = (boolean) args;
|
||||
return context -> {
|
||||
boolean in_water = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.VOID_FISHING.key());
|
||||
if (in_water == inWater) return true;
|
||||
if (advanced) ActionManager.trigger(context, actions);
|
||||
return false;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private void registerInLavaRequirement() {
|
||||
registerRequirement("lava-fishing", (args, actions, advanced) -> {
|
||||
boolean inLava = (boolean) args;
|
||||
if (!inLava) {
|
||||
throw new IllegalArgumentException("");
|
||||
}
|
||||
return context -> {
|
||||
boolean in_lava = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.LAVA_FISHING.key());
|
||||
if (in_lava) return true;
|
||||
if (advanced) ActionManager.trigger(context, actions);
|
||||
return false;
|
||||
};
|
||||
});
|
||||
registerRequirement("in-lava", (args, actions, advanced) -> {
|
||||
boolean inLava = (boolean) args;
|
||||
return context -> {
|
||||
boolean in_lava = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.LAVA_FISHING.key());
|
||||
if (in_lava == inLava) return true;
|
||||
if (advanced) ActionManager.trigger(context, actions);
|
||||
return false;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads requirement expansions from external JAR files located in the expansion folder.
|
||||
* Each expansion JAR should contain classes that extends the RequirementExpansion class.
|
||||
* Expansions are registered and used to create custom requirements.
|
||||
*/
|
||||
@SuppressWarnings({"ResultOfMethodCallIgnored", "unchecked"})
|
||||
private void loadExpansions() {
|
||||
File expansionFolder = new File(plugin.getDataFolder(), EXPANSION_FOLDER);
|
||||
if (!expansionFolder.exists())
|
||||
expansionFolder.mkdirs();
|
||||
List<Class<? extends RequirementExpansion<Player>>> classes = new ArrayList<>();
|
||||
File[] expansionJars = expansionFolder.listFiles();
|
||||
if (expansionJars == null) return;
|
||||
for (File expansionJar : expansionJars) {
|
||||
if (expansionJar.getName().endsWith(".jar")) {
|
||||
try {
|
||||
Class<? extends RequirementExpansion<Player>> expansionClass = (Class<? extends RequirementExpansion<Player>>) ClassUtils.findClass(expansionJar, RequirementExpansion.class);
|
||||
classes.add(expansionClass);
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
plugin.getPluginLogger().warn("Failed to load expansion: " + expansionJar.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
for (Class<? extends RequirementExpansion<Player>> expansionClass : classes) {
|
||||
RequirementExpansion<Player> expansion = expansionClass.getDeclaredConstructor().newInstance();
|
||||
unregisterRequirement(expansion.getRequirementType());
|
||||
registerRequirement(expansion.getRequirementType(), expansion.getRequirementFactory());
|
||||
plugin.getPluginLogger().info("Loaded requirement expansion: " + expansion.getRequirementType() + "[" + expansion.getVersion() + "]" + " by " + expansion.getAuthor());
|
||||
}
|
||||
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
|
||||
plugin.getPluginLogger().warn("Error occurred when creating expansion instance.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, 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.bukkit.sender;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.common.sender.Sender;
|
||||
import net.momirealms.customfishing.common.sender.SenderFactory;
|
||||
import net.momirealms.customfishing.common.util.Tristate;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.RemoteConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitSenderFactory extends SenderFactory<BukkitCustomFishingPlugin, CommandSender> {
|
||||
private final BukkitAudiences audiences;
|
||||
|
||||
public BukkitSenderFactory(BukkitCustomFishingPlugin plugin) {
|
||||
super(plugin);
|
||||
this.audiences = BukkitAudiences.create(plugin.getBoostrap());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
return sender.getName();
|
||||
}
|
||||
return Sender.CONSOLE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID getUniqueId(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
return ((Player) sender).getUniqueId();
|
||||
}
|
||||
return Sender.CONSOLE_UUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Audience getAudience(CommandSender sender) {
|
||||
return this.audiences.sender(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(CommandSender sender, Component message) {
|
||||
// we can safely send async for players and the console - otherwise, send it sync
|
||||
if (sender instanceof Player || sender instanceof ConsoleCommandSender || sender instanceof RemoteConsoleCommandSender) {
|
||||
getAudience(sender).sendMessage(message);
|
||||
} else {
|
||||
getPlugin().getScheduler().executeSync(() -> getAudience(sender).sendMessage(message));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Tristate getPermissionValue(CommandSender sender, String node) {
|
||||
if (sender.hasPermission(node)) {
|
||||
return Tristate.TRUE;
|
||||
} else if (sender.isPermissionSet(node)) {
|
||||
return Tristate.FALSE;
|
||||
} else {
|
||||
return Tristate.UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasPermission(CommandSender sender, String node) {
|
||||
return sender.hasPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performCommand(CommandSender sender, String command) {
|
||||
getPlugin().getBoostrap().getServer().dispatchCommand(sender, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isConsole(CommandSender sender) {
|
||||
return sender instanceof ConsoleCommandSender || sender instanceof RemoteConsoleCommandSender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
this.audiences.close();
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,9 @@ import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
|
||||
import net.momirealms.customfishing.api.mechanic.loot.Loot;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
|
||||
import net.momirealms.customfishing.api.scheduler.CancellableTask;
|
||||
import net.momirealms.customfishing.api.mechanic.action.EmptyAction;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.VaultHook;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.papi.PlaceholderManagerImpl;
|
||||
import net.momirealms.customfishing.bukkit.misc.placeholder.BukkitPlaceholderManager;
|
||||
import net.momirealms.customfishing.common.util.ClassUtils;
|
||||
import net.momirealms.customfishing.util.*;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -157,9 +158,9 @@ public class ActionManagerImpl implements ActionManager {
|
||||
if (factory == null) {
|
||||
LogUtils.warn("Action type: " + section.getString("type") + " doesn't exist.");
|
||||
// to prevent NPE
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
return factory.build(
|
||||
return factory.process(
|
||||
section.get("value"),
|
||||
section.getDouble("chance", 1d)
|
||||
);
|
||||
@@ -297,7 +298,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
ArrayList<String> msg = ConfigUtils.stringListArgs(args);
|
||||
return condition -> {
|
||||
if (Math.random() > chance) return;
|
||||
List<String> replaced = PlaceholderManagerImpl.getInstance().parse(
|
||||
List<String> replaced = BukkitPlaceholderManager.getInstance().parse(
|
||||
condition.getPlayer(),
|
||||
msg,
|
||||
condition.getArgs()
|
||||
@@ -311,7 +312,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
ArrayList<String> msg = ConfigUtils.stringListArgs(args);
|
||||
return condition -> {
|
||||
if (Math.random() > chance) return;
|
||||
List<String> replaced = PlaceholderManagerImpl.getInstance().parse(
|
||||
List<String> replaced = BukkitPlaceholderManager.getInstance().parse(
|
||||
condition.getPlayer(),
|
||||
msg,
|
||||
condition.getArgs()
|
||||
@@ -335,7 +336,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
double distance = LocationUtils.getDistance(player.getLocation(), condition.getLocation());
|
||||
if (distance <= range) {
|
||||
condition.insertArg("{near}", player.getName());
|
||||
List<String> replaced = PlaceholderManagerImpl.getInstance().parse(
|
||||
List<String> replaced = BukkitPlaceholderManager.getInstance().parse(
|
||||
owner,
|
||||
msg,
|
||||
condition.getArgs()
|
||||
@@ -350,7 +351,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: message-nearby");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
registerAction("random-message", (args, chance) -> {
|
||||
@@ -358,7 +359,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
return condition -> {
|
||||
if (Math.random() > chance) return;
|
||||
String random = msg.get(ThreadLocalRandom.current().nextInt(msg.size()));
|
||||
random = PlaceholderManagerImpl.getInstance().parse(condition.getPlayer(), random, condition.getArgs());
|
||||
random = BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), random, condition.getArgs());
|
||||
AdventureHelper.getInstance().sendPlayerMessage(condition.getPlayer(), random);
|
||||
};
|
||||
});
|
||||
@@ -369,7 +370,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
ArrayList<String> cmd = ConfigUtils.stringListArgs(args);
|
||||
return condition -> {
|
||||
if (Math.random() > chance) return;
|
||||
List<String> replaced = PlaceholderManagerImpl.getInstance().parse(
|
||||
List<String> replaced = BukkitPlaceholderManager.getInstance().parse(
|
||||
condition.getPlayer(),
|
||||
cmd,
|
||||
condition.getArgs()
|
||||
@@ -386,7 +387,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
return condition -> {
|
||||
if (Math.random() > chance) return;
|
||||
String random = cmd.get(ThreadLocalRandom.current().nextInt(cmd.size()));
|
||||
random = PlaceholderManagerImpl.getInstance().parse(condition.getPlayer(), random, condition.getArgs());
|
||||
random = BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), random, condition.getArgs());
|
||||
String finalRandom = random;
|
||||
plugin.getScheduler().runTaskSync(() -> {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), finalRandom);
|
||||
@@ -405,7 +406,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
double distance = LocationUtils.getDistance(player.getLocation(), condition.getLocation());
|
||||
if (distance <= range) {
|
||||
condition.insertArg("{near}", player.getName());
|
||||
List<String> replaced = PlaceholderManagerImpl.getInstance().parse(
|
||||
List<String> replaced = BukkitPlaceholderManager.getInstance().parse(
|
||||
owner,
|
||||
cmd,
|
||||
condition.getArgs()
|
||||
@@ -420,7 +421,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: command-nearby");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -442,7 +443,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
return condition -> {
|
||||
if (Math.random() > chance) return;
|
||||
String random = texts.get(ThreadLocalRandom.current().nextInt(texts.size()));
|
||||
random = PlaceholderManagerImpl.getInstance().parse(condition.getPlayer(), random, condition.getArgs());
|
||||
random = BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), random, condition.getArgs());
|
||||
AdventureHelper.getInstance().sendActionbar(condition.getPlayer(), random);
|
||||
};
|
||||
});
|
||||
@@ -458,7 +459,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
double distance = LocationUtils.getDistance(player.getLocation(), condition.getLocation());
|
||||
if (distance <= range) {
|
||||
condition.insertArg("{near}", player.getName());
|
||||
String replaced = PlaceholderManagerImpl.getInstance().parse(
|
||||
String replaced = BukkitPlaceholderManager.getInstance().parse(
|
||||
owner,
|
||||
actionbar,
|
||||
condition.getArgs()
|
||||
@@ -472,7 +473,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: command-nearby");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -545,7 +546,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
(Player) player,
|
||||
location.clone().add(x, y, z),
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
PlaceholderManagerImpl.getInstance().parse(owner, text, condition.getArgs())
|
||||
BukkitPlaceholderManager.getInstance().parse(owner, text, condition.getArgs())
|
||||
),
|
||||
duration
|
||||
);
|
||||
@@ -558,7 +559,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
owner,
|
||||
location.clone().add(x, y, z),
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
PlaceholderManagerImpl.getInstance().parse(owner, text, condition.getArgs())
|
||||
BukkitPlaceholderManager.getInstance().parse(owner, text, condition.getArgs())
|
||||
),
|
||||
duration
|
||||
);
|
||||
@@ -566,7 +567,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: hologram");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -584,7 +585,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: item-amount");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -606,7 +607,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: durability");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -623,7 +624,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: give-item");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -686,7 +687,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: fake-item");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -825,8 +826,8 @@ public class ActionManagerImpl implements ActionManager {
|
||||
if (Math.random() > chance) return;
|
||||
AdventureHelper.getInstance().sendTitle(
|
||||
condition.getPlayer(),
|
||||
PlaceholderManagerImpl.getInstance().parse(condition.getPlayer(), title, condition.getArgs()),
|
||||
PlaceholderManagerImpl.getInstance().parse(condition.getPlayer(), subtitle, condition.getArgs()),
|
||||
BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), title, condition.getArgs()),
|
||||
BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), subtitle, condition.getArgs()),
|
||||
fadeIn,
|
||||
stay,
|
||||
fadeOut
|
||||
@@ -834,7 +835,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: title");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
registerAction("title-nearby", (args, chance) -> {
|
||||
@@ -854,8 +855,8 @@ public class ActionManagerImpl implements ActionManager {
|
||||
condition.insertArg("{near}", player.getName());
|
||||
AdventureHelper.getInstance().sendTitle(
|
||||
condition.getPlayer(),
|
||||
PlaceholderManagerImpl.getInstance().parse(condition.getPlayer(), title, condition.getArgs()),
|
||||
PlaceholderManagerImpl.getInstance().parse(condition.getPlayer(), subtitle, condition.getArgs()),
|
||||
BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), title, condition.getArgs()),
|
||||
BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), subtitle, condition.getArgs()),
|
||||
fadeIn,
|
||||
stay,
|
||||
fadeOut
|
||||
@@ -868,7 +869,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: title-nearby");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
registerAction("random-title", (args, chance) -> {
|
||||
@@ -884,8 +885,8 @@ public class ActionManagerImpl implements ActionManager {
|
||||
if (Math.random() > chance) return;
|
||||
AdventureHelper.getInstance().sendTitle(
|
||||
condition.getPlayer(),
|
||||
PlaceholderManagerImpl.getInstance().parse(condition.getPlayer(), titles.get(ThreadLocalRandom.current().nextInt(titles.size())), condition.getArgs()),
|
||||
PlaceholderManagerImpl.getInstance().parse(condition.getPlayer(), subtitles.get(ThreadLocalRandom.current().nextInt(subtitles.size())), condition.getArgs()),
|
||||
BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), titles.get(ThreadLocalRandom.current().nextInt(titles.size())), condition.getArgs()),
|
||||
BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), subtitles.get(ThreadLocalRandom.current().nextInt(subtitles.size())), condition.getArgs()),
|
||||
fadeIn,
|
||||
stay,
|
||||
fadeOut
|
||||
@@ -893,7 +894,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: random-title");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -912,7 +913,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: potion-effect");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -944,7 +945,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: sound");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -953,7 +954,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
registerAction("conditional", (args, chance) -> {
|
||||
if (args instanceof ConfigurationSection section) {
|
||||
Action[] actions = getActions(section.getConfigurationSection("actions"));
|
||||
Requirement[] requirements = plugin.getRequirementManager().getRequirements(section.getConfigurationSection("conditions"), true);
|
||||
Requirement[] requirements = plugin.getRequirementManager().parseRequirements(section.getConfigurationSection("conditions"), true);
|
||||
return condition -> {
|
||||
if (Math.random() > chance) return;
|
||||
if (requirements != null)
|
||||
@@ -968,7 +969,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: conditional");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -980,7 +981,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
for (Map.Entry<String, Object> entry : section.getValues(false).entrySet()) {
|
||||
if (entry.getValue() instanceof ConfigurationSection inner) {
|
||||
Action[] actions = getActions(inner.getConfigurationSection("actions"));
|
||||
Requirement[] requirements = plugin.getRequirementManager().getRequirements(inner.getConfigurationSection("conditions"), false);
|
||||
Requirement[] requirements = plugin.getRequirementManager().parseRequirements(inner.getConfigurationSection("conditions"), false);
|
||||
conditionActionPairList.add(Pair.of(requirements, actions));
|
||||
}
|
||||
}
|
||||
@@ -1003,7 +1004,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: priority");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1022,7 +1023,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Illegal value format found at action: plugin-exp");
|
||||
return EmptyAction.instance;
|
||||
return EmptyAction.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package net.momirealms.customfishing.mechanic.action;
|
||||
|
||||
import net.momirealms.customfishing.api.mechanic.action.Action;
|
||||
|
||||
/**
|
||||
* An implementation of the Action interface that represents an empty action with no behavior.
|
||||
* This class serves as a default action to prevent NPE.
|
||||
*/
|
||||
public class EmptyAction implements Action {
|
||||
|
||||
public static EmptyAction instance = new EmptyAction();
|
||||
|
||||
@Override
|
||||
public void trigger(PlayerContext playerContext) {
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import net.momirealms.customfishing.api.storage.user.UserData;
|
||||
import net.momirealms.customfishing.api.mechanic.action.Action;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
|
||||
import net.momirealms.customfishing.api.util.InventoryUtils;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.papi.PlaceholderManagerImpl;
|
||||
import net.momirealms.customfishing.bukkit.misc.placeholder.BukkitPlaceholderManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -73,7 +73,7 @@ public class BagManagerImpl implements BagManager, Listener {
|
||||
if (bagStoreLoots) {
|
||||
collectLootActions = plugin.getActionManager().getActions(bagSection.getConfigurationSection("collect-actions"));
|
||||
bagFullActions = plugin.getActionManager().getActions(bagSection.getConfigurationSection("full-actions"));
|
||||
collectRequirements = plugin.getRequirementManager().getRequirements(bagSection.getConfigurationSection("collect-requirements"), false);
|
||||
collectRequirements = plugin.getRequirementManager().parseRequirements(bagSection.getConfigurationSection("collect-requirements"), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class BagManagerImpl implements BagManager, Listener {
|
||||
if (bag.getSize() != rows * 9) {
|
||||
Inventory newBag = InventoryUtils.createInventory(onlinePlayer.getHolder(), rows * 9,
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
PlaceholderManagerImpl.getInstance().parse(
|
||||
BukkitPlaceholderManager.getInstance().parse(
|
||||
player, bagTitle, Map.of("{player}", player.getName())
|
||||
)
|
||||
));
|
||||
|
||||
@@ -165,7 +165,7 @@ public class EffectManagerImpl implements EffectManager {
|
||||
if (section == null) return null;
|
||||
return new EffectCarrier.Builder()
|
||||
.key(key)
|
||||
.requirements(plugin.getRequirementManager().getRequirements(section.getConfigurationSection("requirements"), true))
|
||||
.requirements(plugin.getRequirementManager().parseRequirements(section.getConfigurationSection("requirements"), true))
|
||||
.effect(getEffectModifiers(section.getConfigurationSection("effects")))
|
||||
.actionMap(plugin.getActionManager().getActionMap(section.getConfigurationSection("events")))
|
||||
.build();
|
||||
@@ -368,7 +368,7 @@ public class EffectManagerImpl implements EffectManager {
|
||||
return ((effect, condition) -> effect.setLavaFishing(true));
|
||||
}
|
||||
case "conditional" -> {
|
||||
Requirement[] requirements = plugin.getRequirementManager().getRequirements(section.getConfigurationSection("conditions"), true);
|
||||
Requirement[] requirements = plugin.getRequirementManager().parseRequirements(section.getConfigurationSection("conditions"), true);
|
||||
EffectModifier[] modifiers = getEffectModifiers(section.getConfigurationSection("effects"));
|
||||
return ((effect, condition) -> {
|
||||
for (Requirement requirement : requirements)
|
||||
|
||||
@@ -708,7 +708,7 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
*/
|
||||
private void doSuccessActions(Loot loot, Effect effect, FishingPreparation fishingPreparation, Player player) {
|
||||
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
if (competition != null && RequirementManager.isRequirementMet(fishingPreparation, competition.getConfig().getRequirements())) {
|
||||
if (competition != null && RequirementManager.isRequirementMet(fishingPreparation, competition.getConfig().getJoinRequirements())) {
|
||||
String scoreStr = fishingPreparation.getArg("{CUSTOM_SCORE}");
|
||||
if (scoreStr != null) {
|
||||
competition.refreshData(player, Double.parseDouble(scoreStr));
|
||||
|
||||
@@ -38,7 +38,7 @@ import net.momirealms.customfishing.api.mechanic.loot.Loot;
|
||||
import net.momirealms.customfishing.api.mechanic.misc.value.MathValue;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.item.CustomFishingItemImpl;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.item.VanillaItemImpl;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.papi.PlaceholderManagerImpl;
|
||||
import net.momirealms.customfishing.bukkit.misc.placeholder.BukkitPlaceholderManager;
|
||||
import net.momirealms.customfishing.util.ConfigUtils;
|
||||
import net.momirealms.customfishing.util.ItemUtils;
|
||||
import net.momirealms.customfishing.util.LocationUtils;
|
||||
@@ -580,7 +580,7 @@ public class ItemManagerImpl implements ItemManager, Listener {
|
||||
editors.put("name", (player, nbtItem, placeholders) -> {
|
||||
nbtItem.set(AdventureHelper.getInstance().componentToJson(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"<!i>" + PlaceholderManagerImpl.getInstance().parse(player, name, placeholders)
|
||||
"<!i>" + BukkitPlaceholderManager.getInstance().parse(player, name, placeholders)
|
||||
)
|
||||
), "display", "Name");
|
||||
});
|
||||
@@ -635,7 +635,7 @@ public class ItemManagerImpl implements ItemManager, Listener {
|
||||
editors.put("lore", (player, nbtItem, placeholders) -> {
|
||||
List<String> list = new ArrayList<>(lore.stream().map(s -> AdventureHelper.getInstance().componentToJson(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"<!i>" + PlaceholderManagerImpl.getInstance().parse(player, s, placeholders)
|
||||
"<!i>" + BukkitPlaceholderManager.getInstance().parse(player, s, placeholders)
|
||||
)
|
||||
)).toList());
|
||||
nbtItem.set(list, "display", "Lore");
|
||||
|
||||
@@ -240,7 +240,7 @@ public class LootManagerImpl implements LootManager {
|
||||
if (section.contains("requirements") && section.contains("weight")) {
|
||||
plugin.getRequirementManager().putLegacyLootToMap(
|
||||
loot.getID(),
|
||||
plugin.getRequirementManager().getRequirements(section.getConfigurationSection("requirements"), false),
|
||||
plugin.getRequirementManager().parseRequirements(section.getConfigurationSection("requirements"), false),
|
||||
section.getDouble("weight", 0)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import net.momirealms.customfishing.api.mechanic.market.MarketManager;
|
||||
import net.momirealms.customfishing.api.mechanic.action.Action;
|
||||
import net.momirealms.customfishing.api.mechanic.market.MarketGUIHolder;
|
||||
import net.momirealms.customfishing.api.scheduler.CancellableTask;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.papi.PlaceholderManagerImpl;
|
||||
import net.momirealms.customfishing.bukkit.misc.placeholder.BukkitPlaceholderManager;
|
||||
import net.momirealms.customfishing.util.ConfigUtils;
|
||||
import net.momirealms.customfishing.util.NumberUtils;
|
||||
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||
@@ -497,8 +497,8 @@ public class MarketManagerImpl implements MarketManager, Listener {
|
||||
|
||||
@Override
|
||||
public double getFishPrice(Player player, Map<String, String> vars) {
|
||||
String temp = PlaceholderManagerImpl.getInstance().parse(player, formula, vars);
|
||||
var placeholders = PlaceholderManagerImpl.getInstance().detectPlaceholders(temp);
|
||||
String temp = BukkitPlaceholderManager.getInstance().parse(player, formula, vars);
|
||||
var placeholders = BukkitPlaceholderManager.getInstance().resolvePlaceholders(temp);
|
||||
for (String placeholder : placeholders) {
|
||||
temp = temp.replace(placeholder, "0");
|
||||
}
|
||||
@@ -533,7 +533,7 @@ public class MarketManagerImpl implements MarketManager, Listener {
|
||||
@Override
|
||||
public double getEarningLimit(Player player) {
|
||||
return new ExpressionBuilder(
|
||||
PlaceholderManagerImpl.getInstance().parse(
|
||||
BukkitPlaceholderManager.getInstance().parse(
|
||||
player,
|
||||
earningLimitExpression,
|
||||
new HashMap<>()
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package net.momirealms.customfishing.mechanic.misc;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.compatibility.papi.PlaceholderManagerImpl;
|
||||
import net.momirealms.customfishing.bukkit.misc.placeholder.BukkitPlaceholderManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -39,7 +39,7 @@ public class DynamicText {
|
||||
private void analyze(String value) {
|
||||
// Analyze the provided text to find and replace placeholders with '%s'.
|
||||
// Store the original value, placeholders, and the initial latest value.
|
||||
List<String> placeholdersOwner = new ArrayList<>(PlaceholderManagerImpl.getInstance().detectPlaceholders(value));
|
||||
List<String> placeholdersOwner = new ArrayList<>(BukkitPlaceholderManager.getInstance().resolvePlaceholders(value));
|
||||
String origin = value;
|
||||
for (String placeholder : placeholdersOwner) {
|
||||
origin = origin.replace(placeholder, "%s");
|
||||
@@ -57,13 +57,13 @@ public class DynamicText {
|
||||
// Update the dynamic text by replacing placeholders with actual values.
|
||||
String string = originalValue;
|
||||
if (this.placeholders.length != 0) {
|
||||
PlaceholderManagerImpl placeholderManagerImpl = PlaceholderManagerImpl.getInstance();
|
||||
BukkitPlaceholderManager bukkitPlaceholderManager = BukkitPlaceholderManager.getInstance();
|
||||
if ("%s".equals(originalValue)) {
|
||||
string = placeholderManagerImpl.getSingleValue(owner, this.placeholders[0], placeholders);
|
||||
string = bukkitPlaceholderManager.getSingleValue(owner, this.placeholders[0], placeholders);
|
||||
} else {
|
||||
Object[] values = new String[this.placeholders.length];
|
||||
for (int i = 0; i < this.placeholders.length; i++) {
|
||||
values[i] = placeholderManagerImpl.getSingleValue(owner, this.placeholders[i], placeholders);
|
||||
values[i] = bukkitPlaceholderManager.getSingleValue(owner, this.placeholders[i], placeholders);
|
||||
}
|
||||
string = String.format(originalValue, values);
|
||||
}
|
||||
|
||||
@@ -1,33 +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.mechanic.requirement;
|
||||
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
|
||||
|
||||
/**
|
||||
* Represents an empty requirement that always returns true when checking conditions.
|
||||
*/
|
||||
public class EmptyRequirement implements Requirement {
|
||||
|
||||
public static EmptyRequirement instance = new EmptyRequirement();
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlayerContext playerContext) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -21,15 +21,12 @@ import net.momirealms.customfishing.BukkitCustomFishingPluginImpl;
|
||||
import net.momirealms.customfishing.api.common.Pair;
|
||||
import net.momirealms.customfishing.api.integration.LevelerProvider;
|
||||
import net.momirealms.customfishing.api.integration.SeasonProvider;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.*;
|
||||
import net.momirealms.customfishing.api.mechanic.action.Action;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition;
|
||||
import net.momirealms.customfishing.api.mechanic.loot.Loot;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.RequirementExpansion;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.RequirementFactory;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.VaultHook;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.papi.ParseUtils;
|
||||
import net.momirealms.customfishing.bukkit.misc.placeholder.papi.ParseUtils;
|
||||
import net.momirealms.customfishing.common.util.ClassUtils;
|
||||
import net.momirealms.customfishing.util.ClassUtils;
|
||||
import net.momirealms.customfishing.util.ConfigUtils;
|
||||
@@ -271,7 +268,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
for (Map.Entry<String, Object> entry : section.getValues(false).entrySet()) {
|
||||
String typeOrName = entry.getKey();
|
||||
if (hasRequirement(typeOrName)) {
|
||||
requirements.add(getRequirement(typeOrName, entry.getValue()));
|
||||
requirements.add(parseRequirement(typeOrName, entry.getValue()));
|
||||
} else {
|
||||
requirements.add(getRequirement(section.getConfigurationSection(typeOrName), advanced));
|
||||
}
|
||||
@@ -294,7 +291,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
@NotNull
|
||||
@Override
|
||||
public Requirement getRequirement(ConfigurationSection section, boolean advanced) {
|
||||
if (section == null) return EmptyRequirement.instance;
|
||||
if (section == null) return EmptyRequirement.INSTANCE;
|
||||
List<Action> actionList = null;
|
||||
if (advanced) {
|
||||
actionList = new ArrayList<>();
|
||||
@@ -311,11 +308,11 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
String type = section.getString("type");
|
||||
if (type == null) {
|
||||
LogUtils.warn("No requirement type found at " + section.getCurrentPath());
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
var builder = getRequirementFactory(type);
|
||||
if (builder == null) {
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
return builder.build(section.get("value"), actionList, advanced);
|
||||
}
|
||||
@@ -331,11 +328,11 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
*/
|
||||
@Override
|
||||
@NotNull
|
||||
public Requirement getRequirement(@NotNull String type, @NotNull Object value) {
|
||||
public Requirement parseRequirement(@NotNull String type, @NotNull Object value) {
|
||||
RequirementFactory factory = getRequirementFactory(type);
|
||||
if (factory == null) {
|
||||
LogUtils.warn("Requirement type: " + type + " doesn't exist.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
return factory.build(value);
|
||||
}
|
||||
@@ -457,7 +454,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at || requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -480,7 +477,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at && requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -675,7 +672,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at cooldown requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -747,7 +744,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at >= requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
registerRequirement(">", (args, actions, advanced) -> {
|
||||
@@ -763,7 +760,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at > requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -780,7 +777,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at regex requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -799,7 +796,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at !startsWith requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
registerRequirement("!=", (args, actions, advanced) -> {
|
||||
@@ -815,7 +812,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at !startsWith requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -835,7 +832,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at < requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
registerRequirement("<=", (args, actions, advanced) -> {
|
||||
@@ -851,7 +848,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at <= requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -870,7 +867,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at startsWith requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
registerRequirement("!startsWith", (args, actions, advanced) -> {
|
||||
@@ -886,7 +883,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at !startsWith requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -905,7 +902,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at endsWith requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
registerRequirement("!endsWith", (args, actions, advanced) -> {
|
||||
@@ -921,7 +918,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at !endsWith requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -940,7 +937,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at contains requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
registerRequirement("!contains", (args, actions, advanced) -> {
|
||||
@@ -956,7 +953,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at !contains requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -974,7 +971,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at in-list requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
registerRequirement("!in-list", (args, actions, advanced) -> {
|
||||
@@ -989,7 +986,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at in-list requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1008,7 +1005,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at equals requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
registerRequirement("!equals", (args, actions, advanced) -> {
|
||||
@@ -1024,7 +1021,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at !equals requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1067,7 +1064,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at item-in-hand requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1232,7 +1229,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
for (String e : list) {
|
||||
LogUtils.warn(" - " + e);
|
||||
}
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1265,7 +1262,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at competition requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1289,7 +1286,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
};
|
||||
} else {
|
||||
LogUtils.warn("Wrong value format found at plugin-level requirement.");
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1302,7 +1299,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
PotionEffectType type = PotionEffectType.getByName(split[0]);
|
||||
if (type == null) {
|
||||
LogUtils.warn("Potion effect doesn't exist: " + split[0]);
|
||||
return EmptyRequirement.instance;
|
||||
return EmptyRequirement.INSTANCE;
|
||||
}
|
||||
int required = Integer.parseInt(split[1]);
|
||||
String operator = potions.substring(split[0].length(), potions.length() - split[1].length());
|
||||
|
||||
@@ -220,7 +220,7 @@ public class TotemManagerImpl implements TotemManager, Listener {
|
||||
TotemConfig totemConfig = new TotemConfig.Builder(entry.getKey())
|
||||
.setTotemModels(getTotemModels(section.getConfigurationSection("pattern")))
|
||||
.setParticleSettings(getParticleSettings(section.getConfigurationSection("particles")))
|
||||
.setRequirements(plugin.getRequirementManager().getRequirements(section.getConfigurationSection("requirements"), true))
|
||||
.setRequirements(plugin.getRequirementManager().parseRequirements(section.getConfigurationSection("requirements"), true))
|
||||
.setRadius(section.getDouble("radius", 8))
|
||||
.setDuration(section.getInt("duration", 300))
|
||||
.build();
|
||||
|
||||
@@ -23,7 +23,7 @@ import net.momirealms.customfishing.api.storage.data.InventoryData;
|
||||
import net.momirealms.customfishing.api.storage.data.PlayerData;
|
||||
import net.momirealms.customfishing.api.storage.data.StatisticData;
|
||||
import net.momirealms.customfishing.api.storage.user.UserData;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.papi.PlaceholderManagerImpl;
|
||||
import net.momirealms.customfishing.bukkit.misc.placeholder.BukkitPlaceholderManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -59,7 +59,7 @@ public class OfflineUser implements UserData<OfflinePlayer> {
|
||||
// Set up the inventory for the FishingBagHolder
|
||||
this.holder.setInventory(InventoryUtils.createInventory(this.holder, playerData.getBagData().size,
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
PlaceholderManagerImpl.getInstance().parse(
|
||||
BukkitPlaceholderManager.getInstance().parse(
|
||||
offlinePlayer,
|
||||
BukkitCustomFishingPlugin.get().getBagManager().getBagTitle(),
|
||||
Map.of("{player}", Optional.ofNullable(offlinePlayer.getName()).orElse(String.valueOf(uuid)))
|
||||
|
||||
@@ -20,7 +20,7 @@ package net.momirealms.customfishing.util;
|
||||
import net.momirealms.customfishing.api.common.Pair;
|
||||
import net.momirealms.customfishing.api.common.Tuple;
|
||||
import net.momirealms.customfishing.api.mechanic.misc.value.MathValue;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.papi.PlaceholderManagerImpl;
|
||||
import net.momirealms.customfishing.bukkit.misc.placeholder.BukkitPlaceholderManager;
|
||||
import net.momirealms.customfishing.mechanic.misc.value.ExpressionMathValue;
|
||||
import net.momirealms.customfishing.mechanic.misc.value.PlainMathValue;
|
||||
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||
@@ -328,7 +328,7 @@ public class ConfigUtils {
|
||||
}
|
||||
|
||||
public static double getExpressionValue(Player player, String formula, Map<String, String> vars) {
|
||||
formula = PlaceholderManagerImpl.getInstance().parse(player, formula, vars);
|
||||
formula = BukkitPlaceholderManager.getInstance().parse(player, formula, vars);
|
||||
return new ExpressionBuilder(formula).build().evaluate();
|
||||
}
|
||||
|
||||
|
||||
20
core/src/main/resources/commands.yml
Normal file
20
core/src/main/resources/commands.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# Don't change this
|
||||
#
|
||||
config-version: "${config_version}"
|
||||
|
||||
#
|
||||
# For safety reasons, editing this file requires a restart to apply
|
||||
#
|
||||
reload:
|
||||
enable: true
|
||||
permission: customfishing.reload
|
||||
usage:
|
||||
- /customfishing reload
|
||||
- /cfishing reload
|
||||
|
||||
sellfish:
|
||||
enable: true
|
||||
permission: customfishing.sellfish
|
||||
usage:
|
||||
- /sellfish
|
||||
Reference in New Issue
Block a user