mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-27 10:59:13 +00:00
checkpoint - 1
This commit is contained in:
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
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.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.mechanic.effect.EffectManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.entity.EntityManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.fishing.FishingManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.game.GameManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.hook.HookManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.item.ItemManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.loot.LootManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.market.MarketManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.misc.ChatCatcherManager;
|
||||
import net.momirealms.customfishing.mechanic.misc.CoolDownManager;
|
||||
import net.momirealms.customfishing.mechanic.requirement.RequirementManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.statistic.StatisticsManagerImpl;
|
||||
import net.momirealms.customfishing.mechanic.totem.TotemManagerImpl;
|
||||
import net.momirealms.customfishing.setting.CFConfig;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import net.momirealms.customfishing.storage.StorageManagerImpl;
|
||||
import net.momirealms.customfishing.version.VersionManagerImpl;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin {
|
||||
|
||||
private static ProtocolManager protocolManager;
|
||||
private CoolDownManager coolDownManager;
|
||||
private ChatCatcherManager chatCatcherManager;
|
||||
private DependencyManager dependencyManager;
|
||||
|
||||
public BukkitCustomFishingPluginImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
this.versionManager = new VersionManagerImpl(this);
|
||||
this.dependencyManager = new DependencyManagerImpl(this, new ReflectionClassPathAppender(this.getClassLoader()));
|
||||
this.dependencyManager.loadDependencies(new ArrayList<>(
|
||||
List.of(
|
||||
Dependency.GSON,
|
||||
Dependency.SLF4J_API,
|
||||
Dependency.SLF4J_SIMPLE,
|
||||
Dependency.BOOSTED_YAML,
|
||||
Dependency.EXP4J,
|
||||
Dependency.MYSQL_DRIVER,
|
||||
Dependency.MARIADB_DRIVER,
|
||||
Dependency.MONGODB_DRIVER_SYNC,
|
||||
Dependency.MONGODB_DRIVER_CORE,
|
||||
Dependency.MONGODB_DRIVER_BSON,
|
||||
Dependency.JEDIS,
|
||||
Dependency.COMMONS_POOL_2,
|
||||
Dependency.COMMONS_LANG_3,
|
||||
Dependency.H2_DRIVER,
|
||||
Dependency.SQLITE_DRIVER,
|
||||
Dependency.BSTATS_BASE,
|
||||
Dependency.HIKARI,
|
||||
Dependency.BSTATS_BUKKIT,
|
||||
versionManager.isMojmap() ? Dependency.COMMAND_API_MOJMAP : Dependency.COMMAND_API
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
NBTUtils.disableNBTAPILogs();
|
||||
ReflectionUtils.load();
|
||||
|
||||
this.actionManager = new ActionManagerImpl(this);
|
||||
this.adventure = new AdventureHelper(this);
|
||||
this.bagManager = new BagManagerImpl(this);
|
||||
this.blockManager = new BlockManagerImpl(this);
|
||||
this.commandManager = new CommandManagerImpl(this);
|
||||
this.effectManager = new EffectManagerImpl(this);
|
||||
this.fishingManager = new FishingManagerImpl(this);
|
||||
this.gameManager = new GameManagerImpl(this);
|
||||
this.itemManager = new ItemManagerImpl(this);
|
||||
this.lootManager = new LootManagerImpl(this);
|
||||
this.marketManager = new MarketManagerImpl(this);
|
||||
this.entityManager = new EntityManagerImpl(this);
|
||||
this.placeholderManager = new PlaceholderManagerImpl(this);
|
||||
this.requirementManager = new RequirementManagerImpl(this);
|
||||
this.scheduler = new SchedulerImpl(this);
|
||||
this.storageManager = new StorageManagerImpl(this);
|
||||
this.competitionManager = new CompetitionManagerImpl(this);
|
||||
this.integrationManager = new IntegrationManagerImpl(this);
|
||||
this.statisticsManager = new StatisticsManagerImpl(this);
|
||||
this.coolDownManager = new CoolDownManager(this);
|
||||
this.totemManager = new TotemManagerImpl(this);
|
||||
this.hookManager = new HookManagerImpl(this);
|
||||
this.chatCatcherManager = new ChatCatcherManager(this);
|
||||
this.reload();
|
||||
super.initialized = true;
|
||||
|
||||
if (CFConfig.metrics) new Metrics(this, 16648);
|
||||
if (CFConfig.updateChecker)
|
||||
this.versionManager.checkUpdate().thenAccept(result -> {
|
||||
if (!result) this.getAdventure().sendConsoleMessage("[CustomFishing] You are using the latest version.");
|
||||
else this.getAdventure().sendConsoleMessage("[CustomFishing] Update is available: <u>https://polymart.org/resource/2723<!u>");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (this.adventure != null) ((AdventureHelper) this.adventure).close();
|
||||
if (this.bagManager != null) ((BagManagerImpl) this.bagManager).disable();
|
||||
if (this.blockManager != null) ((BlockManagerImpl) this.blockManager).disable();
|
||||
if (this.effectManager != null) ((EffectManagerImpl) this.effectManager).disable();
|
||||
if (this.fishingManager != null) ((FishingManagerImpl) this.fishingManager).disable();
|
||||
if (this.gameManager != null) ((GameManagerImpl) this.gameManager).disable();
|
||||
if (this.itemManager != null) ((ItemManagerImpl) this.itemManager).disable();
|
||||
if (this.lootManager != null) ((LootManagerImpl) this.lootManager).disable();
|
||||
if (this.marketManager != null) ((MarketManagerImpl) this.marketManager).disable();
|
||||
if (this.entityManager != null) ((EntityManagerImpl) this.entityManager).disable();
|
||||
if (this.requirementManager != null) ((RequirementManagerImpl) this.requirementManager).disable();
|
||||
if (this.scheduler != null) ((SchedulerImpl) this.scheduler).shutdown();
|
||||
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.statisticsManager != null) ((StatisticsManagerImpl) this.statisticsManager).disable();
|
||||
if (this.actionManager != null) ((ActionManagerImpl) this.actionManager).disable();
|
||||
if (this.totemManager != null) ((TotemManagerImpl) this.totemManager).disable();
|
||||
if (this.hookManager != null) ((HookManagerImpl) this.hookManager).disable();
|
||||
if (this.coolDownManager != null) this.coolDownManager.disable();
|
||||
if (this.chatCatcherManager != null) this.chatCatcherManager.disable();
|
||||
if (this.commandManager != null) this.commandManager.unload();
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the plugin
|
||||
*/
|
||||
@Override
|
||||
public void reload() {
|
||||
CFConfig.load();
|
||||
CFLocale.load();
|
||||
((SchedulerImpl) this.scheduler).reload();
|
||||
((RequirementManagerImpl) this.requirementManager).unload();
|
||||
((RequirementManagerImpl) this.requirementManager).load();
|
||||
((ActionManagerImpl) this.actionManager).unload();
|
||||
((ActionManagerImpl) this.actionManager).load();
|
||||
((GameManagerImpl) this.gameManager).unload();
|
||||
((GameManagerImpl) this.gameManager).load();
|
||||
((ItemManagerImpl) this.itemManager).unload();
|
||||
((ItemManagerImpl) this.itemManager).load();
|
||||
((LootManagerImpl) this.lootManager).unload();
|
||||
((LootManagerImpl) this.lootManager).load();
|
||||
((FishingManagerImpl) this.fishingManager).unload();
|
||||
((FishingManagerImpl) this.fishingManager).load();
|
||||
((TotemManagerImpl) this.totemManager).unload();
|
||||
((TotemManagerImpl) this.totemManager).load();
|
||||
((EffectManagerImpl) this.effectManager).unload();
|
||||
((EffectManagerImpl) this.effectManager).load();
|
||||
((MarketManagerImpl) this.marketManager).unload();
|
||||
((MarketManagerImpl) this.marketManager).load();
|
||||
((BagManagerImpl) this.bagManager).unload();
|
||||
((BagManagerImpl) this.bagManager).load();
|
||||
((BlockManagerImpl) this.blockManager).unload();
|
||||
((BlockManagerImpl) this.blockManager).load();
|
||||
((EntityManagerImpl) this.entityManager).unload();
|
||||
((EntityManagerImpl) this.entityManager).load();
|
||||
((CompetitionManagerImpl) this.competitionManager).unload();
|
||||
((CompetitionManagerImpl) this.competitionManager).load();
|
||||
((StorageManagerImpl) this.storageManager).reload();
|
||||
((StatisticsManagerImpl) this.statisticsManager).unload();
|
||||
((StatisticsManagerImpl) this.statisticsManager).load();
|
||||
((PlaceholderManagerImpl) this.placeholderManager).unload();
|
||||
((PlaceholderManagerImpl) this.placeholderManager).load();
|
||||
((HookManagerImpl) this.hookManager).unload();
|
||||
((HookManagerImpl) this.hookManager).load();
|
||||
this.commandManager.unload();
|
||||
this.commandManager.load();
|
||||
this.coolDownManager.unload();
|
||||
this.coolDownManager.load();
|
||||
this.chatCatcherManager.unload();
|
||||
this.chatCatcherManager.load();
|
||||
|
||||
CustomFishingReloadEvent event = new CustomFishingReloadEvent(this);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a YAML configuration from a file within the plugin's data folder.
|
||||
*
|
||||
* @param file The name of the configuration file.
|
||||
* @return A YamlConfiguration object representing the configuration.
|
||||
*/
|
||||
@Override
|
||||
public YamlConfiguration getConfig(String file) {
|
||||
File config = new File(this.getDataFolder(), file);
|
||||
if (!config.exists()) this.saveResource(file, false);
|
||||
return YamlConfiguration.loadConfiguration(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a specified plugin is enabled on the Bukkit server.
|
||||
*
|
||||
* @param plugin The name of the plugin to check.
|
||||
* @return True if the plugin is enabled, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isHookedPluginEnabled(String plugin) {
|
||||
return Bukkit.getPluginManager().isPluginEnabled(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a debugging message if the debug mode is enabled.
|
||||
*
|
||||
* @param message The debugging message to be logged.
|
||||
*/
|
||||
@Override
|
||||
public void debug(String message) {
|
||||
if (!CFConfig.debug) return;
|
||||
LogUtils.info(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the CoolDownManager instance associated with the plugin.
|
||||
*
|
||||
* @return The CoolDownManager instance.
|
||||
*/
|
||||
public CoolDownManager getCoolDownManager() {
|
||||
return coolDownManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ChatCatcherManager instance associated with the plugin.
|
||||
*
|
||||
* @return The ChatCatcherManager instance.
|
||||
*/
|
||||
public ChatCatcherManager getChatCatcherManager() {
|
||||
return chatCatcherManager;
|
||||
}
|
||||
|
||||
public DependencyManager getDependencyManager() {
|
||||
return dependencyManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the ProtocolManager instance used for managing packets.
|
||||
*
|
||||
* @return The ProtocolManager instance.
|
||||
*/
|
||||
@NotNull
|
||||
public static ProtocolManager getProtocolManager() {
|
||||
return protocolManager;
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, PacketContainer packet) {
|
||||
protocolManager.sendServerPacket(player, packet);
|
||||
}
|
||||
|
||||
public static void sendPackets(Player player, PacketContainer... packets) {
|
||||
List<PacketContainer> bundle = new ArrayList<>(Arrays.asList(packets));
|
||||
PacketContainer bundlePacket = new PacketContainer(PacketType.Play.Server.BUNDLE);
|
||||
bundlePacket.getPacketBundles().write(0, bundle);
|
||||
sendPacket(player, bundlePacket);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of InvUI, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2021 NichtStudioCode
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.adventure;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Languages {
|
||||
|
||||
private static final Languages INSTANCE = new Languages();
|
||||
private final Map<String, Map<String, String>> translations = new HashMap<>();
|
||||
private Function<Player, Locale> languageProvider = Player::locale;
|
||||
private boolean serverSideTranslations = true;
|
||||
|
||||
private Languages() {
|
||||
}
|
||||
|
||||
public static Languages getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void addLanguage(@NotNull String lang, @NotNull Map<String, String> translations) {
|
||||
this.translations.put(lang, translations);
|
||||
}
|
||||
|
||||
public void loadLanguage(@NotNull String lang, @NotNull Reader reader) throws IOException {
|
||||
var translations = new HashMap<String, String>();
|
||||
try (var jsonReader = new JsonReader(reader)) {
|
||||
jsonReader.beginObject();
|
||||
while (jsonReader.hasNext()) {
|
||||
var key = jsonReader.nextName();
|
||||
var value = jsonReader.nextString();
|
||||
translations.put(key, value);
|
||||
}
|
||||
|
||||
addLanguage(lang, translations);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadLanguage(@NotNull String lang, @NotNull File file, @NotNull Charset charset) throws IOException {
|
||||
try (var reader = new FileReader(file, charset)) {
|
||||
loadLanguage(lang, reader);
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable String getFormatString(@NotNull String lang, @NotNull String key) {
|
||||
var map = translations.get(lang);
|
||||
if (map == null)
|
||||
return null;
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
public void setLanguageProvider(@NotNull Function<Player, Locale> languageProvider) {
|
||||
this.languageProvider = languageProvider;
|
||||
}
|
||||
|
||||
public @NotNull Locale getLanguage(@NotNull Player player) {
|
||||
return languageProvider.apply(player);
|
||||
}
|
||||
|
||||
public void enableServerSideTranslations(boolean enable) {
|
||||
serverSideTranslations = enable;
|
||||
}
|
||||
|
||||
public boolean doesServerSideTranslations() {
|
||||
return serverSideTranslations;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* This file is part of InvUI, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2021 NichtStudioCode
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.adventure;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
|
||||
public class ShadedAdventureComponentUtils {
|
||||
|
||||
private static final Style FORMATTING_TEMPLATE = Style.style()
|
||||
.color(NamedTextColor.WHITE)
|
||||
.decoration(TextDecoration.ITALIC, false)
|
||||
.decoration(TextDecoration.BOLD, false)
|
||||
.decoration(TextDecoration.STRIKETHROUGH, false)
|
||||
.decoration(TextDecoration.UNDERLINED, false)
|
||||
.decoration(TextDecoration.OBFUSCATED, false)
|
||||
.build();
|
||||
|
||||
public static Component withoutPreFormatting(Component component) {
|
||||
return component.style(component.style().merge(FORMATTING_TEMPLATE, Style.Merge.Strategy.IF_ABSENT_ON_TARGET));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of InvUI, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2021 NichtStudioCode
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.adventure;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.inventoryaccess.component.ComponentWrapper;
|
||||
|
||||
public class ShadedAdventureComponentWrapper implements ComponentWrapper {
|
||||
|
||||
public static final ShadedAdventureComponentWrapper EMPTY = new ShadedAdventureComponentWrapper(Component.empty());
|
||||
|
||||
private final Component component;
|
||||
|
||||
public ShadedAdventureComponentWrapper(Component component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String serializeToJson() {
|
||||
return GsonComponentSerializer.gson().serialize(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ComponentWrapper localized(@NotNull String lang) {
|
||||
if (!Languages.getInstance().doesServerSideTranslations())
|
||||
return this;
|
||||
|
||||
return new ShadedAdventureComponentWrapper(ShadedAdventureShadedComponentLocalizer.getInstance().localize(lang, component));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ComponentWrapper withoutPreFormatting() {
|
||||
return new ShadedAdventureComponentWrapper(ShadedAdventureComponentUtils.withoutPreFormatting(component));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ShadedAdventureComponentWrapper clone() {
|
||||
try {
|
||||
return (ShadedAdventureComponentWrapper) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is part of InvUI, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2021 NichtStudioCode
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.adventure;
|
||||
|
||||
import net.kyori.adventure.text.*;
|
||||
|
||||
public class ShadedAdventureShadedComponentLocalizer extends ShadedComponentLocalizer<Component> {
|
||||
|
||||
private static final ShadedAdventureShadedComponentLocalizer INSTANCE = new ShadedAdventureShadedComponentLocalizer();
|
||||
|
||||
private ShadedAdventureShadedComponentLocalizer() {
|
||||
super(Component::text);
|
||||
}
|
||||
|
||||
public static ShadedAdventureShadedComponentLocalizer getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Override
|
||||
public Component localize(String lang, Component component) {
|
||||
if (!(component instanceof BuildableComponent))
|
||||
throw new IllegalStateException("Component is not a BuildableComponent");
|
||||
|
||||
return localize(lang, (BuildableComponent) component);
|
||||
}
|
||||
|
||||
@SuppressWarnings("NonExtendableApiUsage")
|
||||
private <C extends BuildableComponent<C, B>, B extends ComponentBuilder<C, B>> BuildableComponent<?, ?> localize(String lang, BuildableComponent<C, B> component) {
|
||||
ComponentBuilder<?, ?> builder;
|
||||
if (component instanceof TranslatableComponent) {
|
||||
builder = localizeTranslatable(lang, (TranslatableComponent) component).toBuilder();
|
||||
} else {
|
||||
builder = component.toBuilder();
|
||||
}
|
||||
|
||||
builder.mapChildrenDeep(child -> {
|
||||
if (child instanceof TranslatableComponent)
|
||||
return localizeTranslatable(lang, (TranslatableComponent) child);
|
||||
return child;
|
||||
});
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private BuildableComponent<?, ?> localizeTranslatable(String lang, TranslatableComponent component) {
|
||||
var formatString = Languages.getInstance().getFormatString(lang, component.key());
|
||||
if (formatString == null)
|
||||
return component;
|
||||
|
||||
var children = decomposeFormatString(lang, formatString, component, component.args());
|
||||
return Component.textOfChildren(children.toArray(ComponentLike[]::new)).style(component.style());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of InvUI, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2021 NichtStudioCode
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.adventure;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
abstract class ShadedComponentLocalizer<T> {
|
||||
|
||||
private static final Pattern FORMAT_PATTERN = Pattern.compile("%(?:(\\d+)\\$)?([A-Za-z%]|$)");
|
||||
|
||||
private Function<String, T> componentCreator;
|
||||
|
||||
public ShadedComponentLocalizer(Function<String, T> componentCreator) {
|
||||
this.componentCreator = componentCreator;
|
||||
}
|
||||
|
||||
public void setComponentCreator(Function<String, T> componentCreator) {
|
||||
this.componentCreator = componentCreator;
|
||||
}
|
||||
|
||||
public abstract T localize(String lang, T component);
|
||||
|
||||
protected List<T> decomposeFormatString(String lang, String formatString, T component, List<T> args) {
|
||||
var matcher = FORMAT_PATTERN.matcher(formatString);
|
||||
|
||||
var components = new ArrayList<T>();
|
||||
var sb = new StringBuilder();
|
||||
var nextArgIdx = 0;
|
||||
|
||||
var i = 0;
|
||||
while (matcher.find(i)) {
|
||||
var start = matcher.start();
|
||||
var end = matcher.end();
|
||||
|
||||
// check for escaped %
|
||||
var matchedStr = formatString.substring(i, start);
|
||||
if ("%%".equals(matchedStr)) {
|
||||
sb.append('%');
|
||||
} else {
|
||||
// check for invalid format, only %s is supported
|
||||
var argType = matcher.group(2);
|
||||
if (!"s".equals(argType)) {
|
||||
throw new IllegalStateException("Unsupported format: '" + matchedStr + "'");
|
||||
}
|
||||
|
||||
// retrieve argument index
|
||||
var argIdxStr = matcher.group(1);
|
||||
var argIdx = argIdxStr == null ? nextArgIdx++ : Integer.parseInt(argIdxStr) - 1;
|
||||
|
||||
// validate argument index
|
||||
if (argIdx < 0)
|
||||
throw new IllegalStateException("Invalid argument index: " + argIdx);
|
||||
|
||||
// append the text before the argument
|
||||
sb.append(formatString, i, start);
|
||||
// add text component
|
||||
components.add(componentCreator.apply(sb.toString()));
|
||||
// add argument component
|
||||
components.add(args.size() <= argIdx ? componentCreator.apply("") : localize(lang, args.get(argIdx)));
|
||||
// clear string builder
|
||||
sb.setLength(0);
|
||||
}
|
||||
|
||||
// start next search after matcher end index
|
||||
i = end;
|
||||
}
|
||||
|
||||
// append the text after the last argument
|
||||
if (i < formatString.length()) {
|
||||
sb.append(formatString, i, formatString.length());
|
||||
components.add(componentCreator.apply(sb.toString()));
|
||||
}
|
||||
|
||||
return components;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
* 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.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.integration.EnchantmentProvider;
|
||||
import net.momirealms.customfishing.api.integration.LevelerProvider;
|
||||
import net.momirealms.customfishing.api.integration.SeasonProvider;
|
||||
import net.momirealms.customfishing.api.integration.IntegrationManager;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.block.ItemsAdderBlockImpl;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.enchant.AdvancedEnchantmentsImpl;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.enchant.VanillaEnchantmentsImpl;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.entity.ItemsAdderEntityImpl;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.entity.MythicEntityImpl;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.item.*;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.level.*;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.quest.BattlePassHook;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.quest.BetonQuestHook;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.quest.ClueScrollsHook;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.season.CustomCropsSeasonImpl;
|
||||
import net.momirealms.customfishing.bukkit.compatibility.season.RealisticSeasonsImpl;
|
||||
import net.momirealms.customfishing.compatibility.item.*;
|
||||
import net.momirealms.customfishing.compatibility.level.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class IntegrationManagerImpl implements IntegrationManager {
|
||||
|
||||
private final BukkitCustomFishingPlugin plugin;
|
||||
private final HashMap<String, LevelerProvider> levelPluginMap;
|
||||
private final HashMap<String, EnchantmentProvider> enchantmentPluginMap;
|
||||
private SeasonProvider seasonProvider;
|
||||
|
||||
public IntegrationManagerImpl(BukkitCustomFishingPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.levelPluginMap = new HashMap<>();
|
||||
this.enchantmentPluginMap = new HashMap<>();
|
||||
this.load();
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
this.enchantmentPluginMap.clear();
|
||||
this.levelPluginMap.clear();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
if (Bukkit.getPluginManager().getPlugin("ItemsAdder") != null) {
|
||||
plugin.getItemManager().registerItemLibrary(new ItemsAdderItemImpl());
|
||||
plugin.getBlockManager().registerBlockLibrary(new ItemsAdderBlockImpl());
|
||||
plugin.getEntityManager().registerEntityProvider(new ItemsAdderEntityImpl());
|
||||
hookMessage("ItemsAdder");
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("MMOItems") != null) {
|
||||
plugin.getItemManager().registerItemLibrary(new MMOItemsItemImpl());
|
||||
hookMessage("MMOItems");
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("Oraxen") != null) {
|
||||
plugin.getItemManager().registerItemLibrary(new OraxenItemImpl());
|
||||
hookMessage("Oraxen");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("Zaphkiel")) {
|
||||
plugin.getItemManager().registerItemLibrary(new ZaphkielItemImpl());
|
||||
hookMessage("Zaphkiel");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("NeigeItems")) {
|
||||
plugin.getItemManager().registerItemLibrary(new NeigeItemsItemImpl());
|
||||
hookMessage("NeigeItems");
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) {
|
||||
plugin.getItemManager().registerItemLibrary(new MythicMobsItemImpl());
|
||||
plugin.getEntityManager().registerEntityProvider(new MythicEntityImpl());
|
||||
hookMessage("MythicMobs");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("EcoJobs")) {
|
||||
registerLevelerProvider("EcoJobs", new EcoJobsImpl());
|
||||
hookMessage("EcoJobs");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("EcoSkills")) {
|
||||
registerLevelerProvider("EcoSkills", new EcoSkillsImpl());
|
||||
hookMessage("EcoSkills");
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("Jobs") != null) {
|
||||
registerLevelerProvider("JobsReborn", new JobsRebornImpl());
|
||||
hookMessage("JobsReborn");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("MMOCore")) {
|
||||
registerLevelerProvider("MMOCore", new MMOCoreImpl());
|
||||
hookMessage("MMOCore");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("mcMMO")) {
|
||||
try {
|
||||
plugin.getItemManager().registerItemLibrary(new McMMOTreasureImpl());
|
||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
LogUtils.warn("Failed to initialize mcMMO Treasure");
|
||||
}
|
||||
registerLevelerProvider("mcMMO", new McMMOImpl());
|
||||
hookMessage("mcMMO");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("AureliumSkills")) {
|
||||
registerLevelerProvider("AureliumSkills", new AureliumSkillsImpl());
|
||||
hookMessage("AureliumSkills");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("AuraSkills")) {
|
||||
registerLevelerProvider("AuraSkills", new AuraSkillsImpl());
|
||||
hookMessage("AuraSkills");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("EcoEnchants")) {
|
||||
this.enchantmentPluginMap.put("EcoEnchants", new VanillaEnchantmentsImpl());
|
||||
hookMessage("EcoEnchants");
|
||||
} else {
|
||||
this.enchantmentPluginMap.put("vanilla", new VanillaEnchantmentsImpl());
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("AdvancedEnchantments")) {
|
||||
this.enchantmentPluginMap.put("AdvancedEnchantments", new AdvancedEnchantmentsImpl());
|
||||
hookMessage("AdvancedEnchantments");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("RealisticSeasons")) {
|
||||
this.seasonProvider = new RealisticSeasonsImpl();
|
||||
} else if (plugin.isHookedPluginEnabled("CustomCrops")) {
|
||||
this.seasonProvider = new CustomCropsSeasonImpl();
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("Vault")) {
|
||||
VaultHook.initialize();
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("BattlePass")){
|
||||
BattlePassHook battlePassHook = new BattlePassHook();
|
||||
battlePassHook.register();
|
||||
hookMessage("BattlePass");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("ClueScrolls")) {
|
||||
ClueScrollsHook clueScrollsHook = new ClueScrollsHook();
|
||||
clueScrollsHook.register();
|
||||
hookMessage("ClueScrolls");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("BetonQuest")) {
|
||||
BetonQuestHook.register();
|
||||
hookMessage("BetonQuest");
|
||||
}
|
||||
// if (plugin.isHookedPluginEnabled("NotQuests")) {
|
||||
// NotQuestHook notQuestHook = new NotQuestHook();
|
||||
// notQuestHook.register();
|
||||
// hookMessage("NotQuests");
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a level plugin with the specified name.
|
||||
*
|
||||
* @param plugin The name of the level plugin.
|
||||
* @param level The implementation of the LevelInterface.
|
||||
* @return true if the registration was successful, false if the plugin name is already registered.
|
||||
*/
|
||||
@Override
|
||||
public boolean registerLevelerProvider(String plugin, LevelerProvider level) {
|
||||
if (levelPluginMap.containsKey(plugin)) return false;
|
||||
levelPluginMap.put(plugin, level);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a level plugin with the specified name.
|
||||
*
|
||||
* @param plugin The name of the level plugin to unregister.
|
||||
* @return true if the unregistration was successful, false if the plugin name is not found.
|
||||
*/
|
||||
@Override
|
||||
public boolean unregisterLevelerProvider(String plugin) {
|
||||
return levelPluginMap.remove(plugin) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an enchantment provided by a plugin.
|
||||
*
|
||||
* @param plugin The name of the plugin providing the enchantment.
|
||||
* @param enchantment The enchantment to register.
|
||||
* @return true if the registration was successful, false if the enchantment name is already in use.
|
||||
*/
|
||||
@Override
|
||||
public boolean registerEnchantment(String plugin, EnchantmentProvider enchantment) {
|
||||
if (enchantmentPluginMap.containsKey(plugin)) return false;
|
||||
enchantmentPluginMap.put(plugin, enchantment);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters an enchantment provided by a plugin.
|
||||
*
|
||||
* @param plugin The name of the plugin providing the enchantment.
|
||||
* @return true if the enchantment was successfully unregistered, false if the enchantment was not found.
|
||||
*/
|
||||
@Override
|
||||
public boolean unregisterEnchantment(String plugin) {
|
||||
return enchantmentPluginMap.remove(plugin) != null;
|
||||
}
|
||||
|
||||
private void hookMessage(String plugin) {
|
||||
LogUtils.info( plugin + " hooked!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the LevelInterface provided by a plugin.
|
||||
*
|
||||
* @param plugin The name of the plugin providing the LevelInterface.
|
||||
* @return The LevelInterface provided by the specified plugin, or null if the plugin is not registered.
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public LevelerProvider getLevelPlugin(String plugin) {
|
||||
return levelPluginMap.get(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an enchantment plugin by its plugin name.
|
||||
*
|
||||
* @param plugin The name of the enchantment plugin.
|
||||
* @return The enchantment plugin interface, or null if not found.
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public EnchantmentProvider getEnchantmentPlugin(String plugin) {
|
||||
return enchantmentPluginMap.get(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of enchantment keys with level applied to the given ItemStack.
|
||||
*
|
||||
* @param itemStack The ItemStack to check for enchantments.
|
||||
* @return A list of enchantment names applied to the ItemStack.
|
||||
*/
|
||||
@Override
|
||||
public List<String> getEnchantments(ItemStack itemStack) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
for (EnchantmentProvider enchantmentProvider : enchantmentPluginMap.values()) {
|
||||
list.addAll(enchantmentProvider.getEnchants(itemStack));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current season interface, if available.
|
||||
*
|
||||
* @return The current season interface, or null if not available.
|
||||
*/
|
||||
@Nullable
|
||||
public SeasonProvider getSeasonInterface() {
|
||||
return seasonProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current season interface.
|
||||
*
|
||||
* @param season The season interface to set.
|
||||
*/
|
||||
@Override
|
||||
public void setSeasonInterface(SeasonProvider season) {
|
||||
this.seasonProvider = season;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public class VaultHook {
|
||||
|
||||
private static Economy economy;
|
||||
|
||||
public static boolean initialize() {
|
||||
RegisteredServiceProvider<Economy> rsp = BukkitCustomFishingPlugin.getInstance().getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
economy = rsp.getProvider();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Economy getEconomy() {
|
||||
return economy;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.block;
|
||||
|
||||
import dev.lone.itemsadder.api.CustomBlock;
|
||||
import net.momirealms.customfishing.api.mechanic.block.BlockDataModifier;
|
||||
import net.momirealms.customfishing.api.mechanic.block.BlockLibrary;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemsAdderBlockImpl implements BlockLibrary {
|
||||
|
||||
@Override
|
||||
public String identification() {
|
||||
return "ItemsAdder";
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData getBlockData(Player player, String id, List<BlockDataModifier> modifiers) {
|
||||
BlockData blockData = CustomBlock.getBaseBlockData(id);
|
||||
for (BlockDataModifier modifier : modifiers) {
|
||||
modifier.apply(player, blockData);
|
||||
}
|
||||
return blockData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBlockID(Block block) {
|
||||
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
||||
return customBlock == null ? null : customBlock.getId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.block;
|
||||
|
||||
import net.momirealms.customfishing.api.mechanic.block.BlockDataModifier;
|
||||
import net.momirealms.customfishing.api.mechanic.block.BlockLibrary;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class VanillaBlockImpl implements BlockLibrary {
|
||||
|
||||
@Override
|
||||
public String identification() {
|
||||
return "vanilla";
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData getBlockData(Player player, String id, List<BlockDataModifier> modifiers) {
|
||||
BlockData blockData = Material.valueOf(id.toUpperCase(Locale.ENGLISH)).createBlockData();
|
||||
for (BlockDataModifier modifier : modifiers) {
|
||||
modifier.apply(player, blockData);
|
||||
}
|
||||
return blockData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getBlockID(Block block) {
|
||||
return block.getType().name();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.enchant;
|
||||
|
||||
import net.advancedplugins.ae.api.AEAPI;
|
||||
import net.momirealms.customfishing.api.integration.EnchantmentProvider;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AdvancedEnchantmentsImpl implements EnchantmentProvider {
|
||||
|
||||
@Override
|
||||
public List<String> getEnchants(ItemStack itemStack) {
|
||||
List<String> enchants = new ArrayList<>();
|
||||
for (Map.Entry<String, Integer> entry : AEAPI.getEnchantmentsOnItem(itemStack).entrySet()) {
|
||||
enchants.add("AE:" + entry.getKey() + ":" + entry.getValue());
|
||||
}
|
||||
return enchants;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.enchant;
|
||||
|
||||
import net.momirealms.customfishing.api.integration.EnchantmentProvider;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class VanillaEnchantmentsImpl implements EnchantmentProvider {
|
||||
|
||||
@Override
|
||||
public List<String> getEnchants(ItemStack itemStack) {
|
||||
Map<Enchantment, Integer> enchantments = itemStack.getEnchantments();
|
||||
List<String> enchants = new ArrayList<>(enchantments.size());
|
||||
for (Map.Entry<Enchantment, Integer> en : enchantments.entrySet()) {
|
||||
String key = en.getKey().getKey() + ":" + en.getValue();
|
||||
enchants.add(key);
|
||||
}
|
||||
return enchants;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.entity;
|
||||
|
||||
import dev.lone.itemsadder.api.CustomEntity;
|
||||
import net.momirealms.customfishing.api.integration.EntityProvider;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemsAdderEntityImpl implements EntityProvider {
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
return "vanilla";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Entity spawn(@NotNull Location location, @NotNull String id, @NotNull Map<String, Object> propertyMap) {
|
||||
CustomEntity customEntity = CustomEntity.spawn(
|
||||
id,
|
||||
location,
|
||||
(Boolean) propertyMap.getOrDefault("frustumCulling", true),
|
||||
(Boolean) propertyMap.getOrDefault("noBase", false),
|
||||
(Boolean) propertyMap.getOrDefault("noHitbox", false)
|
||||
);
|
||||
return customEntity.getEntity();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.entity;
|
||||
|
||||
import io.lumine.mythic.api.adapters.AbstractLocation;
|
||||
import io.lumine.mythic.api.mobs.MythicMob;
|
||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||
import io.lumine.mythic.bukkit.utils.serialize.Position;
|
||||
import io.lumine.mythic.core.mobs.ActiveMob;
|
||||
import net.momirealms.customfishing.api.integration.EntityProvider;
|
||||
import net.momirealms.customfishing.util.ConfigUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MythicEntityImpl implements EntityProvider {
|
||||
|
||||
private MythicBukkit mythicBukkit;
|
||||
|
||||
public MythicEntityImpl() {
|
||||
this.mythicBukkit = MythicBukkit.inst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
return "MythicMobs";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Entity spawn(@NotNull Location location, @NotNull String id, @NotNull Map<String, Object> propertyMap) {
|
||||
if (this.mythicBukkit == null || mythicBukkit.isClosed()) {
|
||||
this.mythicBukkit = MythicBukkit.inst();
|
||||
}
|
||||
Optional<MythicMob> mythicMob = mythicBukkit.getMobManager().getMythicMob(id);
|
||||
if (mythicMob.isPresent()) {
|
||||
MythicMob theMob = mythicMob.get();
|
||||
Position position = Position.of(location);
|
||||
AbstractLocation abstractLocation = new AbstractLocation(position);
|
||||
ActiveMob activeMob = theMob.spawn(abstractLocation, ConfigUtils.getDoubleValue(propertyMap.get("level")));
|
||||
return activeMob.getEntity().getBukkitEntity();
|
||||
}
|
||||
throw new NullPointerException("MythicMobs: " + id + " doesn't exist.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.entity;
|
||||
|
||||
import net.momirealms.customfishing.api.integration.EntityProvider;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class VanillaEntityImpl implements EntityProvider {
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
return "vanilla";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Entity spawn(@NotNull Location location, @NotNull String id, @NotNull Map<String, Object> propertyMap) {
|
||||
return location.getWorld().spawnEntity(location, EntityType.valueOf(id.toUpperCase(Locale.ENGLISH)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.item;
|
||||
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.integration.ItemProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CustomFishingItemImpl implements ItemProvider {
|
||||
|
||||
@Override
|
||||
public String identification() {
|
||||
return "CustomFishing";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack buildItem(Player player, String id) {
|
||||
String[] split = id.split(":", 2);
|
||||
return BukkitCustomFishingPlugin.get().getItemManager().build(player, split[0], split[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String itemID(ItemStack itemStack) {
|
||||
return BukkitCustomFishingPlugin.get().getItemManager().getCustomFishingItemID(itemStack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.item;
|
||||
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import net.momirealms.customfishing.api.integration.ItemProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ItemsAdderItemImpl implements ItemProvider {
|
||||
|
||||
@Override
|
||||
public String identification() {
|
||||
return "ItemsAdder";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack buildItem(Player player, String id) {
|
||||
CustomStack stack = CustomStack.getInstance(id);
|
||||
if (stack == null) {
|
||||
LogUtils.severe(id + " doesn't exist in ItemsAdder configs.");
|
||||
return null;
|
||||
}
|
||||
return stack.getItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String itemID(ItemStack itemStack) {
|
||||
CustomStack customStack = CustomStack.byItemStack(itemStack);
|
||||
if (customStack == null) return null;
|
||||
return customStack.getNamespacedID();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.item;
|
||||
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.momirealms.customfishing.api.integration.ItemProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class MMOItemsItemImpl implements ItemProvider {
|
||||
|
||||
@Override
|
||||
public String identification() {
|
||||
return "MMOItems";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack buildItem(Player player, String id) {
|
||||
String[] split = id.split(":");
|
||||
MMOItem mmoItem = MMOItems.plugin.getMMOItem(Type.get(split[0]), split[1].toUpperCase(Locale.ENGLISH));
|
||||
return mmoItem == null ? new ItemStack(Material.AIR) : mmoItem.newBuilder().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String itemID(ItemStack itemStack) {
|
||||
NBTItem nbtItem = NBTItem.get(itemStack);
|
||||
if (!nbtItem.hasTag("MMOITEMS_ITEM_ID")) return null;
|
||||
return nbtItem.getString("MMOITEMS_ITEM_ID");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.item;
|
||||
|
||||
import net.momirealms.customfishing.api.integration.ItemProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class McMMOTreasureImpl implements ItemProvider {
|
||||
|
||||
private final Method getMcMMOPlayerMethod;
|
||||
private final Method getFishingManagerMethod;
|
||||
private final Method getFishingTreasureMethod;
|
||||
private final Method getItemStackMethod;
|
||||
|
||||
public McMMOTreasureImpl() throws ClassNotFoundException, NoSuchMethodException {
|
||||
Class<?> userClass = Class.forName("com.gmail.nossr50.util.player.UserManager");
|
||||
getMcMMOPlayerMethod = userClass.getMethod("getPlayer", Player.class);
|
||||
Class<?> mcMMOPlayerClass = Class.forName("com.gmail.nossr50.datatypes.player.McMMOPlayer");
|
||||
getFishingManagerMethod = mcMMOPlayerClass.getMethod("getFishingManager");
|
||||
Class<?> fishingManagerClass = Class.forName("com.gmail.nossr50.skills.fishing.FishingManager");
|
||||
getFishingTreasureMethod = fishingManagerClass.getDeclaredMethod("getFishingTreasure");
|
||||
getFishingTreasureMethod.setAccessible(true);
|
||||
Class<?> treasureClass = Class.forName("com.gmail.nossr50.datatypes.treasure.Treasure");
|
||||
getItemStackMethod = treasureClass.getMethod("getDrop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identification() {
|
||||
return "mcMMO";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack buildItem(Player player, String id) {
|
||||
if (!id.equals("treasure")) return new ItemStack(Material.AIR);
|
||||
ItemStack itemStack = null;
|
||||
int times = 0;
|
||||
while (itemStack == null && times < 5) {
|
||||
try {
|
||||
Object mcMMOPlayer = getMcMMOPlayerMethod.invoke(null, player);
|
||||
Object fishingManager = getFishingManagerMethod.invoke(mcMMOPlayer);
|
||||
Object treasure = getFishingTreasureMethod.invoke(fishingManager);
|
||||
if (treasure != null) {
|
||||
itemStack = (ItemStack) getItemStackMethod.invoke(treasure);
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
times++;
|
||||
}
|
||||
}
|
||||
return itemStack == null ? new ItemStack(Material.COD) : itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String itemID(ItemStack itemStack) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.item;
|
||||
|
||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||
import net.momirealms.customfishing.api.integration.ItemProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MythicMobsItemImpl implements ItemProvider {
|
||||
|
||||
private MythicBukkit mythicBukkit;
|
||||
|
||||
public MythicMobsItemImpl() {
|
||||
this.mythicBukkit = MythicBukkit.inst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identification() {
|
||||
return "MythicMobs";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack buildItem(Player player, String id) {
|
||||
if (mythicBukkit == null || mythicBukkit.isClosed()) {
|
||||
this.mythicBukkit = MythicBukkit.inst();
|
||||
}
|
||||
return mythicBukkit.getItemManager().getItemStack(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String itemID(ItemStack itemStack) {
|
||||
if (mythicBukkit == null || mythicBukkit.isClosed()) {
|
||||
this.mythicBukkit = MythicBukkit.inst();
|
||||
}
|
||||
return mythicBukkit.getItemManager().getMythicTypeFromItem(itemStack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.item;
|
||||
|
||||
import net.momirealms.customfishing.api.integration.ItemProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import pers.neige.neigeitems.item.ItemInfo;
|
||||
import pers.neige.neigeitems.manager.ItemManager;
|
||||
import pers.neige.neigeitems.utils.ItemUtils;
|
||||
|
||||
public class NeigeItemsItemImpl implements ItemProvider {
|
||||
|
||||
@Override
|
||||
public String identification() {
|
||||
return "NeigeItems";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack buildItem(Player player, String id) {
|
||||
return ItemManager.INSTANCE.getItemStack(id, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String itemID(ItemStack itemStack) {
|
||||
ItemInfo itemInfo = ItemUtils.isNiItem(itemStack);
|
||||
if (itemInfo != null) {
|
||||
return itemInfo.getId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.item;
|
||||
|
||||
import io.th0rgal.oraxen.api.OraxenItems;
|
||||
import io.th0rgal.oraxen.items.ItemBuilder;
|
||||
import net.momirealms.customfishing.api.integration.ItemProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class OraxenItemImpl implements ItemProvider {
|
||||
|
||||
@Override
|
||||
public String identification() {
|
||||
return "Oraxen";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack buildItem(Player player, String id) {
|
||||
ItemBuilder itemBuilder = OraxenItems.getItemById(id);
|
||||
return itemBuilder == null ? new ItemStack(Material.AIR) : itemBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String itemID(ItemStack itemStack) {
|
||||
return OraxenItems.getIdByItem(itemStack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.item;
|
||||
|
||||
import net.momirealms.customfishing.api.integration.ItemProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class VanillaItemImpl implements ItemProvider {
|
||||
|
||||
@Override
|
||||
public String identification() {
|
||||
return "vanilla";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack buildItem(Player player, String id) {
|
||||
return new ItemStack(Material.valueOf(id.toUpperCase(Locale.ENGLISH)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String itemID(ItemStack itemStack) {
|
||||
return itemStack.getType().name();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.item;
|
||||
|
||||
import ink.ptms.zaphkiel.ZapAPI;
|
||||
import ink.ptms.zaphkiel.Zaphkiel;
|
||||
import net.momirealms.customfishing.api.integration.ItemProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ZaphkielItemImpl implements ItemProvider {
|
||||
|
||||
private final ZapAPI zapAPI;
|
||||
|
||||
public ZaphkielItemImpl() {
|
||||
this.zapAPI = Zaphkiel.INSTANCE.api();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identification() {
|
||||
return "Zaphkiel";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack buildItem(Player player, String id) {
|
||||
return zapAPI.getItemManager().generateItemStack(id, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String itemID(ItemStack itemStack) {
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) return null;
|
||||
return zapAPI.getItemHandler().getItemId(itemStack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.level;
|
||||
|
||||
import dev.aurelium.auraskills.api.AuraSkillsApi;
|
||||
import dev.aurelium.auraskills.api.registry.NamespacedId;
|
||||
import net.momirealms.customfishing.api.integration.LevelerProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AuraSkillsImpl implements LevelerProvider {
|
||||
|
||||
@Override
|
||||
public void addXp(Player player, String target, double amount) {
|
||||
AuraSkillsApi.get().getUser(player.getUniqueId())
|
||||
.addSkillXp(AuraSkillsApi.get().getGlobalRegistry().getSkill(NamespacedId.fromDefault(target)), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(Player player, String target) {
|
||||
return AuraSkillsApi.get().getUser(player.getUniqueId()).getSkillLevel(
|
||||
AuraSkillsApi.get().getGlobalRegistry().getSkill(NamespacedId.fromDefault(target))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.level;
|
||||
|
||||
import com.archyx.aureliumskills.api.AureliumAPI;
|
||||
import com.archyx.aureliumskills.leveler.Leveler;
|
||||
import net.momirealms.customfishing.api.integration.LevelerProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AureliumSkillsImpl implements LevelerProvider {
|
||||
|
||||
private final Leveler leveler;
|
||||
|
||||
public AureliumSkillsImpl() {
|
||||
leveler = AureliumAPI.getPlugin().getLeveler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addXp(Player player, String target, double amount) {
|
||||
leveler.addXp(player, AureliumAPI.getPlugin().getSkillRegistry().getSkill(target), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(Player player, String target) {
|
||||
return AureliumAPI.getSkillLevel(player, AureliumAPI.getPlugin().getSkillRegistry().getSkill(target));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.level;
|
||||
|
||||
import com.willfp.ecojobs.api.EcoJobsAPI;
|
||||
import com.willfp.ecojobs.jobs.Job;
|
||||
import com.willfp.ecojobs.jobs.Jobs;
|
||||
import net.momirealms.customfishing.api.integration.LevelerProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class EcoJobsImpl implements LevelerProvider {
|
||||
|
||||
@Override
|
||||
public void addXp(Player player, String target, double amount) {
|
||||
for (Job job : EcoJobsAPI.getActiveJobs(player)) {
|
||||
if (job.getId().equals(target)) {
|
||||
EcoJobsAPI.giveJobExperience(player, job, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(Player player, String target) {
|
||||
Job job = Jobs.getByID(target);
|
||||
if (job == null) return 0;
|
||||
return EcoJobsAPI.getJobLevel(player, job);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.level;
|
||||
|
||||
import com.willfp.ecoskills.api.EcoSkillsAPI;
|
||||
import com.willfp.ecoskills.skills.Skills;
|
||||
import net.momirealms.customfishing.api.integration.LevelerProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class EcoSkillsImpl implements LevelerProvider {
|
||||
|
||||
@Override
|
||||
public void addXp(Player player, String target, double amount) {
|
||||
EcoSkillsAPI.gainSkillXP(player, Objects.requireNonNull(Skills.INSTANCE.getByID(target)), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(Player player, String target) {
|
||||
return EcoSkillsAPI.getSkillLevel(player, Objects.requireNonNull(Skills.INSTANCE.getByID(target)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.level;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import net.momirealms.customfishing.api.integration.LevelerProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JobsRebornImpl implements LevelerProvider {
|
||||
|
||||
@Override
|
||||
public void addXp(Player player, String target, double amount) {
|
||||
JobsPlayer jobsPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
||||
Job job = Jobs.getJob(target);
|
||||
if (jobsPlayer != null && jobsPlayer.isInJob(job))
|
||||
Jobs.getPlayerManager().addExperience(jobsPlayer, job, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(Player player, String target) {
|
||||
JobsPlayer jobsPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
||||
if (jobsPlayer != null) {
|
||||
List<JobProgression> jobs = jobsPlayer.getJobProgression();
|
||||
Job job = Jobs.getJob(target);
|
||||
for (JobProgression progression : jobs)
|
||||
if (progression.getJob().equals(job))
|
||||
return progression.getLevel();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.level;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.experience.EXPSource;
|
||||
import net.momirealms.customfishing.api.integration.LevelerProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MMOCoreImpl implements LevelerProvider {
|
||||
|
||||
@Override
|
||||
public void addXp(Player player, String target, double amount) {
|
||||
MMOCore.plugin.professionManager.get(target).giveExperience(PlayerData.get(player), amount, null ,EXPSource.OTHER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(Player player, String target) {
|
||||
return PlayerData.get(player).getCollectionSkills().getLevel(MMOCore.plugin.professionManager.get(target));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.level;
|
||||
|
||||
import com.gmail.nossr50.api.ExperienceAPI;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import net.momirealms.customfishing.api.integration.LevelerProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class McMMOImpl implements LevelerProvider {
|
||||
|
||||
@Override
|
||||
public void addXp(Player player, String target, double amount) {
|
||||
ExperienceAPI.addRawXP(player, target, (float) amount, "UNKNOWN");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(Player player, String target) {
|
||||
return ExperienceAPI.getLevel(player, PrimarySkillType.valueOf(target));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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.data.user.OnlineUser;
|
||||
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" -> {
|
||||
OnlineUser 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) {
|
||||
OnlineUser 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 "";
|
||||
}
|
||||
|
||||
OnlineUser user = plugin.getStorageManager().getOnlineUser(another.getUniqueId());
|
||||
if (user == null)
|
||||
return "";
|
||||
return String.format("%.2f", plugin.getMarketManager().getEarningLimit(another) - user.getEarningData().earnings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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 net.momirealms.customfishing.setting.CFLocale;
|
||||
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";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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.data.user.OnlineUser;
|
||||
import net.momirealms.customfishing.api.mechanic.statistic.Statistics;
|
||||
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) {
|
||||
OnlineUser 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";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.quest;
|
||||
|
||||
import io.github.battlepass.BattlePlugin;
|
||||
import io.github.battlepass.api.events.server.PluginReloadEvent;
|
||||
import net.advancedplugins.bp.impl.actions.ActionRegistry;
|
||||
import net.advancedplugins.bp.impl.actions.external.executor.ActionQuestExecutor;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.event.FishingResultEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class BattlePassHook implements Listener {
|
||||
|
||||
public BattlePassHook() {
|
||||
Bukkit.getPluginManager().registerEvents(this, BukkitCustomFishingPlugin.get());
|
||||
}
|
||||
|
||||
public void register() {
|
||||
ActionRegistry actionRegistry = BattlePlugin.getPlugin().getActionRegistry();
|
||||
actionRegistry.hook("customfishing", BPFishingQuest::new);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBattlePassReload(PluginReloadEvent event){
|
||||
register();
|
||||
}
|
||||
|
||||
private static class BPFishingQuest extends ActionQuestExecutor {
|
||||
public BPFishingQuest(JavaPlugin plugin) {
|
||||
super(plugin, "customfishing");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFish(FishingResultEvent event){
|
||||
if (event.isCancelled() || event.getResult() == FishingResultEvent.Result.FAILURE)
|
||||
return;
|
||||
Player player = event.getPlayer();
|
||||
|
||||
// Single Fish Quest
|
||||
if (event.getLoot().getID() != null)
|
||||
this.executionBuilder("loot")
|
||||
.player(player)
|
||||
.root(event.getLoot().getID())
|
||||
.progress(event.getAmount())
|
||||
.buildAndExecute();
|
||||
|
||||
// Group Fish Quest
|
||||
String[] lootGroup = event.getLoot().getLootGroup();
|
||||
if (event.getLoot() != null && lootGroup != null)
|
||||
for (String group : lootGroup) {
|
||||
this.executionBuilder("group")
|
||||
.player(player)
|
||||
.root(group)
|
||||
.progress(event.getAmount())
|
||||
.buildAndExecute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.quest;
|
||||
|
||||
import net.momirealms.customfishing.api.event.FishingResultEvent;
|
||||
import org.betonquest.betonquest.BetonQuest;
|
||||
import org.betonquest.betonquest.Instruction;
|
||||
import org.betonquest.betonquest.VariableNumber;
|
||||
import org.betonquest.betonquest.api.CountingObjective;
|
||||
import org.betonquest.betonquest.api.config.quest.QuestPackage;
|
||||
import org.betonquest.betonquest.api.profiles.OnlineProfile;
|
||||
import org.betonquest.betonquest.api.profiles.Profile;
|
||||
import org.betonquest.betonquest.exceptions.InstructionParseException;
|
||||
import org.betonquest.betonquest.utils.PlayerConverter;
|
||||
import org.betonquest.betonquest.utils.location.CompoundLocation;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public class BetonQuestHook {
|
||||
|
||||
public static void register() {
|
||||
BetonQuest.getInstance().registerObjectives("customfishing_loot", IDObjective.class);
|
||||
BetonQuest.getInstance().registerObjectives("customfishing_group", GroupObjective.class);
|
||||
}
|
||||
|
||||
public static class IDObjective extends CountingObjective implements Listener {
|
||||
|
||||
private final CompoundLocation playerLocation;
|
||||
private final VariableNumber rangeVar;
|
||||
private final HashSet<String> loot_ids;
|
||||
|
||||
public IDObjective(Instruction instruction) throws InstructionParseException {
|
||||
super(instruction, "loot_to_fish");
|
||||
loot_ids = new HashSet<>();
|
||||
Collections.addAll(loot_ids, instruction.getArray());
|
||||
targetAmount = instruction.getVarNum();
|
||||
preCheckAmountNotLessThanOne(targetAmount);
|
||||
final QuestPackage pack = instruction.getPackage();
|
||||
final String loc = instruction.getOptional("playerLocation");
|
||||
final String range = instruction.getOptional("range");
|
||||
if (loc != null && range != null) {
|
||||
playerLocation = new CompoundLocation(pack, loc);
|
||||
rangeVar = new VariableNumber(pack, range);
|
||||
} else {
|
||||
playerLocation = null;
|
||||
rangeVar = null;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFish(FishingResultEvent event) {
|
||||
if (event.getResult() != FishingResultEvent.Result.FAILURE) {
|
||||
OnlineProfile onlineProfile = PlayerConverter.getID(event.getPlayer());
|
||||
if (!containsPlayer(onlineProfile)) {
|
||||
return;
|
||||
}
|
||||
if (isInvalidLocation(event, onlineProfile)) {
|
||||
return;
|
||||
}
|
||||
if (this.loot_ids.contains(event.getLoot().getID()) && this.checkConditions(onlineProfile)) {
|
||||
getCountingData(onlineProfile).progress(event.getAmount());
|
||||
completeIfDoneOrNotify(onlineProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInvalidLocation(FishingResultEvent event, final Profile profile) {
|
||||
if (playerLocation == null || rangeVar == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Location targetLocation;
|
||||
try {
|
||||
targetLocation = playerLocation.getLocation(profile);
|
||||
} catch (final org.betonquest.betonquest.exceptions.QuestRuntimeException e) {
|
||||
LogUtils.warn(e.getMessage());
|
||||
return true;
|
||||
}
|
||||
final int range = rangeVar.getInt(profile);
|
||||
final Location playerLoc = event.getPlayer().getLocation();
|
||||
return !playerLoc.getWorld().equals(targetLocation.getWorld()) || targetLocation.distanceSquared(playerLoc) > range * range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
Bukkit.getPluginManager().registerEvents(this, BetonQuest.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GroupObjective extends CountingObjective implements Listener {
|
||||
|
||||
private final CompoundLocation playerLocation;
|
||||
private final VariableNumber rangeVar;
|
||||
private final HashSet<String> loot_groups;
|
||||
|
||||
public GroupObjective(Instruction instruction) throws InstructionParseException {
|
||||
super(instruction, "group_to_fish");
|
||||
loot_groups = new HashSet<>();
|
||||
Collections.addAll(loot_groups, instruction.getArray());
|
||||
targetAmount = instruction.getVarNum();
|
||||
preCheckAmountNotLessThanOne(targetAmount);
|
||||
final QuestPackage pack = instruction.getPackage();
|
||||
final String loc = instruction.getOptional("playerLocation");
|
||||
final String range = instruction.getOptional("range");
|
||||
if (loc != null && range != null) {
|
||||
playerLocation = new CompoundLocation(pack, loc);
|
||||
rangeVar = new VariableNumber(pack, range);
|
||||
} else {
|
||||
playerLocation = null;
|
||||
rangeVar = null;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFish(FishingResultEvent event) {
|
||||
if (event.getResult() != FishingResultEvent.Result.FAILURE) {
|
||||
OnlineProfile onlineProfile = PlayerConverter.getID(event.getPlayer());
|
||||
if (!containsPlayer(onlineProfile)) {
|
||||
return;
|
||||
}
|
||||
if (isInvalidLocation(event, onlineProfile)) {
|
||||
return;
|
||||
}
|
||||
String[] groups = event.getLoot().getLootGroup();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.quest;
|
||||
|
||||
import com.electro2560.dev.cluescrolls.api.*;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.event.FishingResultEvent;
|
||||
import net.momirealms.customfishing.api.mechanic.loot.Loot;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class ClueScrollsHook implements Listener {
|
||||
|
||||
private final CustomClue idClue;
|
||||
private final CustomClue groupClue;
|
||||
|
||||
public ClueScrollsHook() {
|
||||
idClue = ClueScrollsAPI.getInstance().registerCustomClue(BukkitCustomFishingPlugin.getInstance(), "loot", new ClueConfigData("id", DataType.STRING));
|
||||
groupClue = ClueScrollsAPI.getInstance().registerCustomClue(BukkitCustomFishingPlugin.getInstance(), "group", new ClueConfigData("group", DataType.STRING));
|
||||
}
|
||||
|
||||
public void register() {
|
||||
Bukkit.getPluginManager().registerEvents(this, BukkitCustomFishingPlugin.get());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFish(FishingResultEvent event) {
|
||||
if (event.isCancelled() || event.getResult() == FishingResultEvent.Result.FAILURE)
|
||||
return;
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
idClue.handle(
|
||||
player,
|
||||
event.getAmount(),
|
||||
new ClueDataPair("id", "any")
|
||||
);
|
||||
|
||||
Loot loot = event.getLoot();
|
||||
if (loot != null) {
|
||||
idClue.handle(
|
||||
player,
|
||||
event.getAmount(),
|
||||
new ClueDataPair("id", loot.getID())
|
||||
);
|
||||
}
|
||||
|
||||
if (loot != null && loot.getLootGroup() != null) {
|
||||
for (String group : event.getLoot().getLootGroup()) {
|
||||
groupClue.handle(
|
||||
player,
|
||||
event.getAmount(),
|
||||
new ClueDataPair("group", group)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.quest;
|
||||
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.event.FishingResultEvent;
|
||||
import net.momirealms.customfishing.api.mechanic.loot.Loot;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import rocks.gravili.notquests.paper.NotQuests;
|
||||
import rocks.gravili.notquests.paper.structs.ActiveObjective;
|
||||
import rocks.gravili.notquests.paper.structs.ActiveQuest;
|
||||
import rocks.gravili.notquests.paper.structs.QuestPlayer;
|
||||
import rocks.gravili.notquests.paper.structs.objectives.Objective;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class NotQuestHook implements Listener {
|
||||
|
||||
private final NotQuests notQuestsInstance;
|
||||
|
||||
public NotQuestHook() {
|
||||
this.notQuestsInstance = NotQuests.getInstance();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFish(FishingResultEvent event) {
|
||||
if (event.isCancelled() || event.getResult() == FishingResultEvent.Result.FAILURE)
|
||||
return;
|
||||
Loot loot = event.getLoot();
|
||||
Player player = event.getPlayer();
|
||||
final QuestPlayer questPlayer = notQuestsInstance.getQuestPlayerManager().getActiveQuestPlayer(player.getUniqueId());
|
||||
if (questPlayer != null) {
|
||||
if (questPlayer.getActiveQuests().size() > 0) {
|
||||
for (final ActiveQuest activeQuest : questPlayer.getActiveQuests()) {
|
||||
for (final ActiveObjective activeObjective : activeQuest.getActiveObjectives()) {
|
||||
if (activeObjective.getObjective() instanceof GroupObjective groupObjective) {
|
||||
if (activeObjective.isUnlocked()) {
|
||||
final String[] groups = loot.getLootGroup();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.season;
|
||||
|
||||
import net.momirealms.customcrops.api.CustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.mechanic.world.season.Season;
|
||||
import net.momirealms.customfishing.api.integration.SeasonProvider;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class CustomCropsSeasonImpl implements SeasonProvider {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getSeason(World world) {
|
||||
Season season = CustomCropsPlugin.get().getIntegrationManager().getSeason(world);
|
||||
if (season == null) return "disabled";
|
||||
return season.name().toUpperCase(Locale.ENGLISH);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.compatibility.season;
|
||||
|
||||
import me.casperge.realisticseasons.api.SeasonsAPI;
|
||||
import net.momirealms.customfishing.api.integration.SeasonProvider;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RealisticSeasonsImpl implements SeasonProvider {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getSeason(World world) {
|
||||
return switch (SeasonsAPI.getInstance().getSeason(world)) {
|
||||
case WINTER -> "winter";
|
||||
case SPRING -> "spring";
|
||||
case SUMMER -> "summer";
|
||||
case FALL -> "autumn";
|
||||
case DISABLED -> "disabled";
|
||||
case RESTORE -> "restore";
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package net.momirealms.customfishing.bukkit.item;
|
||||
|
||||
import com.saicone.rtag.RtagItem;
|
||||
import net.momirealms.customfishing.bukkit.item.impl.ComponentItemFactory;
|
||||
import net.momirealms.customfishing.bukkit.item.impl.UniversalItemFactory;
|
||||
import net.momirealms.customfishing.common.item.Item;
|
||||
import net.momirealms.customfishing.common.item.ItemFactory;
|
||||
import net.momirealms.customfishing.common.plugin.CustomFishingPlugin;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class BukkitItemFactory extends ItemFactory<CustomFishingPlugin, RtagItem, ItemStack> {
|
||||
|
||||
protected BukkitItemFactory(CustomFishingPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
public static BukkitItemFactory create(CustomFishingPlugin plugin) {
|
||||
Objects.requireNonNull(plugin, "plugin");
|
||||
switch (plugin.getServerVersion()) {
|
||||
case "1.17", "1.17.1",
|
||||
"1.18", "1.18.1", "1.18.2",
|
||||
"1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4",
|
||||
"1.20", "1.20.1", "1.20.2", "1.20.3", "1.20.4" -> {
|
||||
return new UniversalItemFactory(plugin);
|
||||
}
|
||||
case "1.20.5", "1.20.6" -> {
|
||||
return new ComponentItemFactory(plugin);
|
||||
}
|
||||
default -> throw new IllegalStateException("Unsupported server version: " + plugin.getServerVersion());
|
||||
}
|
||||
}
|
||||
|
||||
public Item<ItemStack> wrap(ItemStack item) {
|
||||
Objects.requireNonNull(item, "item");
|
||||
return wrap(new RtagItem(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setTag(RtagItem item, Object value, Object... path) {
|
||||
item.set(value, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Object> getTag(RtagItem item, Object... path) {
|
||||
return Optional.ofNullable(item.get(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update(RtagItem item) {
|
||||
item.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack load(RtagItem item) {
|
||||
return item.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getItem(RtagItem item) {
|
||||
return item.getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack loadCopy(RtagItem item) {
|
||||
return item.loadCopy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package net.momirealms.customfishing.bukkit.item;
|
||||
|
||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.integration.ItemProvider;
|
||||
import net.momirealms.customfishing.api.mechanic.context.Context;
|
||||
import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem;
|
||||
import net.momirealms.customfishing.api.mechanic.item.ItemManager;
|
||||
import net.momirealms.customfishing.api.mechanic.misc.function.FormatFunction;
|
||||
import net.momirealms.customfishing.api.mechanic.misc.function.ItemPropertyFunction;
|
||||
import net.momirealms.customfishing.api.mechanic.misc.value.MathValue;
|
||||
import net.momirealms.customfishing.api.mechanic.misc.value.TextValue;
|
||||
import net.momirealms.customfishing.common.config.node.Node;
|
||||
import net.momirealms.customfishing.common.item.Item;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public class BukkitItemManager implements ItemManager {
|
||||
|
||||
private final BukkitCustomFishingPlugin plugin;
|
||||
private final HashMap<String, ItemProvider> itemProviders = new HashMap<>();
|
||||
private final HashMap<Key, CustomFishingItem> itemMap = new HashMap<>();
|
||||
private final BukkitItemFactory factory;
|
||||
|
||||
public BukkitItemManager(BukkitCustomFishingPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.factory = BukkitItemFactory.create(plugin);
|
||||
this.registerVanilla();
|
||||
}
|
||||
|
||||
private void registerVanilla() {
|
||||
this.itemProviders.put("vanilla", new ItemProvider() {
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack buildItem(Player player, String id) {
|
||||
return new ItemStack(Material.valueOf(id.toUpperCase(Locale.ENGLISH)));
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public String itemID(ItemStack itemStack) {
|
||||
return itemStack.getType().name();
|
||||
}
|
||||
@Override
|
||||
public String identifier() {
|
||||
return "vanilla";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack build(Context<Player> context, Key key) {
|
||||
CustomFishingItem item = requireNonNull(itemMap.get(key), () -> "No item found for " + key);
|
||||
ItemStack itemStack = getOriginalStack(context.getHolder(), item.material());
|
||||
Item<ItemStack> wrappedItemStack = factory.wrap(itemStack);
|
||||
for (BiConsumer<Item<ItemStack>, Context<Player>> consumer : item.tagConsumers()) {
|
||||
consumer.accept(wrappedItemStack, context);
|
||||
}
|
||||
return wrappedItemStack.getItem();
|
||||
}
|
||||
|
||||
private ItemStack getOriginalStack(Player player, String material) {
|
||||
if (material.contains(":")) {
|
||||
try {
|
||||
return new ItemStack(Material.valueOf(material.toUpperCase(Locale.ENGLISH)));
|
||||
} catch (IllegalArgumentException e) {
|
||||
plugin.getPluginLogger().severe("material " + material + " not exists", e);
|
||||
return new ItemStack(Material.PAPER);
|
||||
}
|
||||
} else {
|
||||
String[] split = material.split(":", 2);
|
||||
ItemProvider provider = requireNonNull(itemProviders.get(split[0]), "item provider " + split[0] + " not found");
|
||||
return requireNonNull(provider.buildItem(player, split[0]), "item " + split[0] + " not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package net.momirealms.customfishing.bukkit.item.impl;
|
||||
|
||||
import com.saicone.rtag.RtagItem;
|
||||
import com.saicone.rtag.data.ComponentType;
|
||||
import net.momirealms.customfishing.bukkit.item.BukkitItemFactory;
|
||||
import net.momirealms.customfishing.common.item.ComponentKeys;
|
||||
import net.momirealms.customfishing.common.plugin.CustomFishingPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ComponentItemFactory extends BukkitItemFactory {
|
||||
|
||||
public ComponentItemFactory(CustomFishingPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customModelData(RtagItem item, Integer data) {
|
||||
if (data == null) {
|
||||
item.removeComponent(ComponentKeys.CUSTOM_MODEL_DATA);
|
||||
} else {
|
||||
item.setComponent(ComponentKeys.CUSTOM_MODEL_DATA, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> customModelData(RtagItem item) {
|
||||
if (!item.hasComponent(ComponentKeys.CUSTOM_MODEL_DATA)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(Integer) ComponentType.encodeJava(
|
||||
ComponentKeys.CUSTOM_MODEL_DATA,
|
||||
item.getComponent(ComponentKeys.CUSTOM_MODEL_DATA)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void displayName(RtagItem item, String json) {
|
||||
if (json == null) {
|
||||
item.removeComponent(ComponentKeys.CUSTOM_NAME);
|
||||
} else {
|
||||
item.setComponent(ComponentKeys.CUSTOM_NAME, json);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> displayName(RtagItem item) {
|
||||
if (item.getComponent(ComponentKeys.CUSTOM_NAME) == null) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(String) ComponentType.encodeJava(
|
||||
ComponentKeys.CUSTOM_NAME,
|
||||
item.getComponent(ComponentKeys.CUSTOM_NAME)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void skull(RtagItem item, String skullData) {
|
||||
final Map<String, Object> profile = Map.of(
|
||||
"properties", List.of(
|
||||
Map.of(
|
||||
"name", "textures",
|
||||
"value", skullData
|
||||
)
|
||||
)
|
||||
);
|
||||
item.setComponent("minecraft:profile", profile);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Optional<List<String>> lore(RtagItem item) {
|
||||
if (item.getComponent(ComponentKeys.LORE) == null) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(List<String>) ComponentType.encodeJava(
|
||||
ComponentKeys.LORE,
|
||||
item.getComponent(ComponentKeys.LORE)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void lore(RtagItem item, List<String> lore) {
|
||||
if (lore == null || lore.isEmpty()) {
|
||||
item.removeComponent(ComponentKeys.LORE);
|
||||
} else {
|
||||
item.setComponent(ComponentKeys.LORE, lore);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean unbreakable(RtagItem item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void unbreakable(RtagItem item, boolean unbreakable) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Boolean> glint(RtagItem item) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void glint(RtagItem item, Boolean glint) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package net.momirealms.customfishing.bukkit.item.impl;
|
||||
|
||||
import com.saicone.rtag.RtagItem;
|
||||
import net.momirealms.customfishing.bukkit.item.BukkitItemFactory;
|
||||
import net.momirealms.customfishing.common.plugin.CustomFishingPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class UniversalItemFactory extends BukkitItemFactory {
|
||||
|
||||
public UniversalItemFactory(CustomFishingPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void displayName(RtagItem item, String json) {
|
||||
if (json != null) {
|
||||
item.set(json, "display", "Name");
|
||||
} else {
|
||||
item.remove("display", "Name");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> displayName(RtagItem item) {
|
||||
if (!item.hasTag("display", "Name")) return Optional.empty();
|
||||
return Optional.of(item.get("display", "Name"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customModelData(RtagItem item, Integer data) {
|
||||
if (data == null) {
|
||||
item.remove("CustomModelData");
|
||||
} else {
|
||||
item.set(data, "CustomModelData");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> customModelData(RtagItem item) {
|
||||
if (!item.hasTag("CustomModelData")) return Optional.empty();
|
||||
return Optional.of(item.get("CustomModelData"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void skull(RtagItem item, String skullData) {
|
||||
if (skullData == null) {
|
||||
item.remove("SkullOwner");
|
||||
} else {
|
||||
item.set(List.of(Map.of("Value", skullData)), "SkullOwner", "Properties", "textures");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<List<String>> lore(RtagItem item) {
|
||||
if (!item.hasTag("display", "Lore")) return Optional.empty();
|
||||
return Optional.of(item.get("display", "Lore"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void lore(RtagItem item, List<String> lore) {
|
||||
if (lore == null || lore.isEmpty()) {
|
||||
item.remove("display", "Lore");
|
||||
} else {
|
||||
item.set(lore, "display", "Lore");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean unbreakable(RtagItem item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void unbreakable(RtagItem item, boolean unbreakable) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Boolean> glint(RtagItem item) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void glint(RtagItem item, Boolean glint) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.gui;
|
||||
|
||||
public interface Icon {
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.gui;
|
||||
|
||||
import net.momirealms.customfishing.gui.icon.BackToPageItem;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
|
||||
public interface ParentPage {
|
||||
|
||||
void reOpen();
|
||||
|
||||
default Item getBackItem() {
|
||||
return new BackToPageItem(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.gui;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public interface SectionPage extends YamlPage {
|
||||
|
||||
ConfigurationSection getSection();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.gui;
|
||||
|
||||
public interface YamlPage extends ParentPage {
|
||||
|
||||
void save();
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.gui.icon;
|
||||
|
||||
import net.momirealms.customfishing.gui.Icon;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class BackGroundItem extends AbstractItem implements Icon {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).setDisplayName("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.gui.icon;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.Icon;
|
||||
import net.momirealms.customfishing.gui.page.file.FileSelector;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class BackToFolderItem extends AbstractItem implements Icon {
|
||||
|
||||
private final File file;
|
||||
|
||||
public BackToFolderItem(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (file != null && (file.getPath().startsWith("plugins\\CustomFishing\\contents") || file.getPath().startsWith("plugins/CustomFishing/contents"))) {
|
||||
return new ItemBuilder(Material.ORANGE_STAINED_GLASS_PANE)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_BACK_TO_PARENT_FOLDER
|
||||
)))
|
||||
.setLore(List.of(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"<#FFA500>-> " + file.getName()
|
||||
))));
|
||||
} else {
|
||||
return new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (file != null && (file.getPath().startsWith("plugins\\CustomFishing\\contents") || file.getPath().startsWith("plugins/CustomFishing/contents")))
|
||||
new FileSelector(player, file);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.gui.icon;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.ParentPage;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class BackToPageItem extends AbstractItem {
|
||||
|
||||
private final ParentPage parentPage;
|
||||
|
||||
public BackToPageItem(ParentPage parentPage) {
|
||||
this.parentPage = parentPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.ORANGE_STAINED_GLASS_PANE)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_BACK_TO_PARENT_PAGE
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
parentPage.reOpen();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.gui.icon;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.Icon;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.controlitem.PageItem;
|
||||
|
||||
public class NextPageItem extends PageItem implements Icon {
|
||||
|
||||
public NextPageItem() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider(PagedGui<?> gui) {
|
||||
ItemBuilder builder = new ItemBuilder(Material.GREEN_STAINED_GLASS_PANE);
|
||||
builder.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NEXT_PAGE
|
||||
)))
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
gui.hasNextPage()
|
||||
? CFLocale.GUI_GOTO_NEXT_PAGE
|
||||
.replace("{0}", String.valueOf(gui.getCurrentPage() + 2))
|
||||
.replace("{1}", String.valueOf(gui.getPageAmount()))
|
||||
: CFLocale.GUI_CANNOT_GOTO_NEXT_PAGE
|
||||
)));
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.gui.icon;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.Icon;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.controlitem.PageItem;
|
||||
|
||||
public class PreviousPageItem extends PageItem implements Icon {
|
||||
|
||||
public PreviousPageItem() {
|
||||
super(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider(PagedGui<?> gui) {
|
||||
ItemBuilder builder = new ItemBuilder(Material.RED_STAINED_GLASS_PANE);
|
||||
builder.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_PREVIOUS_PAGE
|
||||
)))
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
gui.hasPreviousPage()
|
||||
? CFLocale.GUI_GOTO_PREVIOUS_PAGE
|
||||
.replace("{0}", String.valueOf(gui.getCurrentPage()))
|
||||
.replace("{1}", String.valueOf(gui.getPageAmount()))
|
||||
: CFLocale.GUI_CANNOT_GOTO_PREVIOUS_PAGE
|
||||
)));
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.gui.icon;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.Icon;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import xyz.xenondevs.invui.gui.ScrollGui;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.controlitem.ScrollItem;
|
||||
|
||||
public class ScrollDownItem extends ScrollItem implements Icon {
|
||||
|
||||
public ScrollDownItem() {
|
||||
super(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider(ScrollGui<?> gui) {
|
||||
ItemBuilder builder = new ItemBuilder(Material.GREEN_STAINED_GLASS_PANE);
|
||||
builder.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_SCROLL_DOWN
|
||||
)));
|
||||
if (!gui.canScroll(1))
|
||||
builder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CANNOT_SCROLL_DOWN
|
||||
)));
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.gui.icon;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.Icon;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import xyz.xenondevs.invui.gui.ScrollGui;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.controlitem.ScrollItem;
|
||||
|
||||
public class ScrollUpItem extends ScrollItem implements Icon {
|
||||
|
||||
public ScrollUpItem() {
|
||||
super(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider(ScrollGui<?> gui) {
|
||||
ItemBuilder builder = new ItemBuilder(Material.RED_STAINED_GLASS_PANE);
|
||||
builder.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_SCROLL_UP
|
||||
)));
|
||||
if (!gui.canScroll(-1))
|
||||
builder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CANNOT_SCROLL_UP
|
||||
)));
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.AmountEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class AmountItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public AmountItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.IRON_NUGGET)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_AMOUNT
|
||||
)))
|
||||
.setAmount(itemPage.getSection().getInt("amount", 1));
|
||||
if (itemPage.getSection().contains("amount")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getInt("amount")
|
||||
)))
|
||||
.addLoreLines("");
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new AmountEditor(player, itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("amount", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.CustomModelDataEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class CMDItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public CMDItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.GLOW_INK_SAC)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_MODEL_DATA
|
||||
)));
|
||||
if (itemPage.getSection().contains("custom-model-data")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getInt("custom-model-data")
|
||||
)))
|
||||
.addLoreLines("");
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new CustomModelDataEditor(player, itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("custom-model-data", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.DisplayNameEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class DisplayNameItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public DisplayNameItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.NAME_TAG)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_DISPLAY_NAME
|
||||
)));
|
||||
if (itemPage.getSection().contains("display.name")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getString("display.name")
|
||||
)))
|
||||
.addLoreLines("");
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new DisplayNameEditor(player, itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("display.name", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.DurabilityEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class DurabilityItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public DurabilityItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.DIAMOND_CHESTPLATE)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_DURABILITY
|
||||
)));
|
||||
if (itemPage.getSection().contains("max-durability")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getInt("max-durability")
|
||||
)))
|
||||
.addLoreLines("");
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new DurabilityEditor(player, itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("max-durability", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.EnchantmentEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class EnchantmentItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public EnchantmentItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.IRON_HOE)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_ENCHANTMENT
|
||||
)))
|
||||
.addEnchantment(Enchantment.ARROW_FIRE,1,true)
|
||||
.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
if (itemPage.getSection().contains("enchantments")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE
|
||||
)));
|
||||
for (Map.Entry<String, Object> entry : itemPage.getSection().getConfigurationSection("enchantments").getValues(false).entrySet()) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
" <gray>- <white>" + entry.getKey() + ":" + entry.getValue()
|
||||
)));
|
||||
}
|
||||
itemBuilder.addLoreLines("").addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new EnchantmentEditor(player, itemPage, false);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("enchantments", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.BukkitCustomFishingPluginImpl;
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Head64Item extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public Head64Item(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.PLAYER_HEAD)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_HEAD64
|
||||
)));
|
||||
if (itemPage.getSection().contains("head64")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE
|
||||
)));
|
||||
String head64 = itemPage.getSection().getString("head64", "");
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
for (int i = 0; i < head64.length(); i += 16) {
|
||||
if (i + 16 > head64.length()) {
|
||||
list.add(head64.substring(i));
|
||||
} else {
|
||||
list.add(head64.substring(i, i + 16));
|
||||
}
|
||||
}
|
||||
for (String line : list) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"<white>"+ line
|
||||
)));
|
||||
}
|
||||
itemBuilder.addLoreLines("").addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
player.closeInventory();
|
||||
AdventureHelper.getInstance().sendMessageWithPrefix(player, "Input the head64 value in chat");
|
||||
((BukkitCustomFishingPluginImpl) BukkitCustomFishingPlugin.get()).getChatCatcherManager().catchMessage(player, "head64", itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("head64", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.ItemFlagEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class ItemFlagItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public ItemFlagItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.CYAN_BANNER)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_FLAG
|
||||
)));
|
||||
if (itemPage.getSection().contains("item-flags")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE
|
||||
)));
|
||||
for (String lore : itemPage.getSection().getStringList("item-flags")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
" <gray>-</gray> " + lore
|
||||
)));
|
||||
}
|
||||
itemBuilder.addLoreLines("");
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new ItemFlagEditor(player, itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("item-flags", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.LoreEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class LoreItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public LoreItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.BIRCH_SIGN)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_LORE
|
||||
)));
|
||||
if (itemPage.getSection().contains("display.lore")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE
|
||||
)));
|
||||
for (String lore : itemPage.getSection().getStringList("display.lore")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
" <gray>-</gray> " + lore
|
||||
)));
|
||||
}
|
||||
itemBuilder.addLoreLines("");
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new LoreEditor(player, itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("display.lore", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.MaterialEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class MaterialItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public MaterialItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.COD)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_MATERIAL
|
||||
)));
|
||||
if (itemPage.getSection().contains("material")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getString("material")
|
||||
)))
|
||||
.addLoreLines("");
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new MaterialEditor(player, itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("material", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.NBTEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import net.momirealms.customfishing.util.ConfigUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class NBTItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public NBTItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.COMMAND_BLOCK)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_NBT
|
||||
)));
|
||||
var section = itemPage.getSection().getConfigurationSection("nbt");
|
||||
if (section != null) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE
|
||||
)));
|
||||
for (String line : ConfigUtils.getReadableSection(section.getValues(false))) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
line
|
||||
)));
|
||||
}
|
||||
itemBuilder.addLoreLines("").addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new NBTEditor(player, itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("nbt", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class PreventGrabItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public PreventGrabItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.DRAGON_EGG)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_PREVENT_GRAB
|
||||
)));
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getBoolean("prevent-grabbing", false)
|
||||
)))
|
||||
.addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_TO_TOGGLE
|
||||
)));
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
itemPage.getSection().set("prevent-grabbing", !itemPage.getSection().getBoolean("prevent-grabbing", false));
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.PriceEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class PriceItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public PriceItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.GOLD_INGOT)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_PRICE
|
||||
)));
|
||||
if (itemPage.getSection().contains("price")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE
|
||||
)))
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_PRICE_BASE + itemPage.getSection().getDouble("price.base")
|
||||
)))
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_PRICE_BONUS + itemPage.getSection().getDouble("price.bonus")
|
||||
)))
|
||||
.addLoreLines("");
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new PriceEditor(player, itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("price", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class RandomDurabilityItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public RandomDurabilityItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.LEATHER_BOOTS)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_RANDOM_DURABILITY
|
||||
)))
|
||||
.setDamage(15);
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getBoolean("random-durability", false)
|
||||
)))
|
||||
.addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_TO_TOGGLE
|
||||
)));
|
||||
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
itemPage.getSection().set("random-durability", !itemPage.getSection().getBoolean("random-durability", false));
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.SizeEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class SizeItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public SizeItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.PUFFERFISH)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_SIZE
|
||||
)));
|
||||
if (itemPage.getSection().contains("size")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getString("size")
|
||||
)))
|
||||
.addLoreLines("");
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new SizeEditor(player, itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("size", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class StackableItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public StackableItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.CHEST_MINECART)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_STACKABLE
|
||||
)));
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getBoolean("stackable", true)
|
||||
)))
|
||||
.addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_TO_TOGGLE
|
||||
)));
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
itemPage.getSection().set("stackable", !itemPage.getSection().getBoolean("stackable", true));
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.EnchantmentEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class StoredEnchantmentItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public StoredEnchantmentItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.ENCHANTED_BOOK)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_STORED_ENCHANTMENT
|
||||
)))
|
||||
.addEnchantment(Enchantment.ARROW_FIRE,1,true)
|
||||
.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
if (itemPage.getSection().contains("stored-enchantments")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE
|
||||
)));
|
||||
for (Map.Entry<String, Object> entry : itemPage.getSection().getConfigurationSection("stored-enchantments").getValues(false).entrySet()) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
" <gray>- <white>" + entry.getKey() + ":" + entry.getValue()
|
||||
)));
|
||||
}
|
||||
itemBuilder.addLoreLines("").addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new EnchantmentEditor(player, itemPage, true);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("stored-enchantments", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class TagItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public TagItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.TOTEM_OF_UNDYING)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_TAG
|
||||
)));
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getBoolean("tag", true)
|
||||
)))
|
||||
.addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_TO_TOGGLE
|
||||
)));
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
itemPage.getSection().set("tag", !itemPage.getSection().getBoolean("tag", true));
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.gui.icon.property.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class UnbreakableItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public UnbreakableItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.BEDROCK)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_UNBREAKABLE
|
||||
)));
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getBoolean("unbreakable", false)
|
||||
)))
|
||||
.addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_TO_TOGGLE
|
||||
)));
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
itemPage.getSection().set("unbreakable", !itemPage.getSection().getBoolean("unbreakable", false));
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.gui.icon.property.loot;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class DisableGameItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public DisableGameItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.LEAD)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LOOT_DISABLE_GAME
|
||||
)));
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getBoolean("disable-game", false)
|
||||
)))
|
||||
.addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_TO_TOGGLE
|
||||
)));
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
itemPage.getSection().set("disable-game", !itemPage.getSection().getBoolean("disable-game", false));
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.gui.icon.property.loot;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class DisableStatsItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public DisableStatsItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.WRITTEN_BOOK)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LOOT_DISABLE_STATS
|
||||
)));
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getBoolean("disable-stat", false)
|
||||
)))
|
||||
.addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_TO_TOGGLE
|
||||
)));
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
itemPage.getSection().set("disable-game", !itemPage.getSection().getBoolean("disable-stat", false));
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.gui.icon.property.loot;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class InstantGameItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public InstantGameItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.FISHING_ROD)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LOOT_INSTANT_GAME
|
||||
)));
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getBoolean("instant-game", false)
|
||||
)))
|
||||
.addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_TO_TOGGLE
|
||||
)));
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
itemPage.getSection().set("instant-game", !itemPage.getSection().getBoolean("instant-game", false));
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.gui.icon.property.loot;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.NickEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class NickItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public NickItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.WRITABLE_BOOK)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LOOT_NICK
|
||||
)));
|
||||
if (itemPage.getSection().contains("nick")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getString("nick")
|
||||
)))
|
||||
.addLoreLines("");
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new NickEditor(player, itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("nick", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.gui.icon.property.loot;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.page.property.ScoreEditor;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class ScoreItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public ScoreItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.NETHER_STAR)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LOOT_SCORE
|
||||
)));
|
||||
if (itemPage.getSection().contains("score")) {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getDouble("score")
|
||||
)))
|
||||
.addLoreLines("");
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_RESET
|
||||
)));
|
||||
} else {
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
)));
|
||||
}
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
new ScoreEditor(player, itemPage);
|
||||
} else if (clickType.isRightClick()) {
|
||||
itemPage.getSection().set("score", null);
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.gui.icon.property.loot;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
|
||||
public class ShowInFinderItem extends AbstractItem {
|
||||
|
||||
private final SectionPage itemPage;
|
||||
|
||||
public ShowInFinderItem(SectionPage itemPage) {
|
||||
this.itemPage = itemPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.COMPASS)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LOOT_SHOW_IN_FINDER
|
||||
)));
|
||||
itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CURRENT_VALUE + itemPage.getSection().getBoolean("show-in-fishfinder", true)
|
||||
)))
|
||||
.addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_TO_TOGGLE
|
||||
)));
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
itemPage.getSection().set("show-in-fishfinder", !itemPage.getSection().getBoolean("show-in-fishfinder", true));
|
||||
itemPage.save();
|
||||
itemPage.reOpen();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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.gui.page.file;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.gui.icon.BackToFolderItem;
|
||||
import net.momirealms.customfishing.gui.icon.ScrollDownItem;
|
||||
import net.momirealms.customfishing.gui.icon.ScrollUpItem;
|
||||
import net.momirealms.customfishing.gui.page.item.ItemSelector;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.ScrollGui;
|
||||
import xyz.xenondevs.invui.gui.structure.Markers;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.window.Window;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
|
||||
public class FileSelector {
|
||||
|
||||
public FileSelector(Player player, File folder) {
|
||||
File[] files = folder.listFiles();
|
||||
Deque<Item> items = new ArrayDeque<>();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isFile() && file.getName().endsWith(".yml")) {
|
||||
items.addLast(new FileItem(file));
|
||||
} else if (file.isDirectory()) {
|
||||
String path = file.getPath().replace("/", "\\");
|
||||
String[] split = path.split("\\\\");
|
||||
String type = split[3];
|
||||
switch (type) {
|
||||
case "item", "rod", "bait", "util", "hook" -> items.addFirst(new FolderItem(file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Gui gui = ScrollGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x u",
|
||||
"x x x x x x x x #",
|
||||
"x x x x x x x x b",
|
||||
"x x x x x x x x #",
|
||||
"x x x x x x x x d"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.addIngredient('u', new ScrollUpItem())
|
||||
.addIngredient('d', new ScrollDownItem())
|
||||
.addIngredient('b', new BackToFolderItem(folder.getParentFile()))
|
||||
.setContent(items.stream().toList())
|
||||
.build();
|
||||
|
||||
Window window = Window.single()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_SELECT_FILE
|
||||
)))
|
||||
.setGui(gui)
|
||||
.build();
|
||||
|
||||
// gui.playAnimation(new SequentialAnimation(1, true), slotElement -> {
|
||||
// if (slotElement instanceof SlotElement.ItemSlotElement itemSlotElement) {
|
||||
// return !(itemSlotElement.getItem() instanceof Icon);
|
||||
// }
|
||||
// return true;
|
||||
// });
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public static class FileItem extends AbstractItem {
|
||||
|
||||
private final File file;
|
||||
|
||||
public FileItem(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.PAPER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"<#FDF5E6>" + file.getName()
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
String path = file.getPath().replace("/", "\\");
|
||||
String[] split = path.split("\\\\");
|
||||
String type = split[3];
|
||||
switch (type) {
|
||||
case "item", "rod", "bait", "util", "hook" -> {
|
||||
new ItemSelector(player, file, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class FolderItem extends AbstractItem {
|
||||
|
||||
private final File file;
|
||||
|
||||
public FolderItem(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.BOOK).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"<#D2B48C><b>" + file.getName()
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
new FileSelector(player, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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.gui.page.item;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.gui.icon.BackToPageItem;
|
||||
import net.momirealms.customfishing.gui.icon.NextPageItem;
|
||||
import net.momirealms.customfishing.gui.icon.PreviousPageItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.gui.structure.Markers;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractSectionEditor implements SectionPage {
|
||||
|
||||
protected final Player player;
|
||||
protected final ItemSelector itemSelector;
|
||||
protected final ConfigurationSection section;
|
||||
protected final String key;
|
||||
|
||||
public AbstractSectionEditor(Player player, ItemSelector itemSelector, ConfigurationSection section, String key) {
|
||||
this.player = player;
|
||||
this.itemSelector = itemSelector;
|
||||
this.section = section;
|
||||
this.key = key;
|
||||
this.reOpen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSection getSection() {
|
||||
return section;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reOpen() {
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure(
|
||||
"# a #"
|
||||
)
|
||||
.addIngredient('a', new RefreshExample())
|
||||
.addIngredient('#', border)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # a # c # b # #"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.addIngredient('a', new PreviousPageItem())
|
||||
.addIngredient('b', new NextPageItem())
|
||||
.addIngredient('c', new BackToPageItem(itemSelector))
|
||||
.setContent(getItemList())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_EDIT_KEY.replace("{0}", key))
|
||||
))
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
itemSelector.save();
|
||||
}
|
||||
|
||||
public class RefreshExample extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(BukkitCustomFishingPlugin.get().getItemManager().getItemBuilder(section, "bait", key).build(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
notifyWindows();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract List<Item> getItemList();
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.gui.page.item;
|
||||
|
||||
import net.momirealms.customfishing.gui.icon.property.item.*;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public class BaitEditor extends AbstractSectionEditor {
|
||||
|
||||
public BaitEditor(Player player, String key, ItemSelector itemSelector, ConfigurationSection section) {
|
||||
super(player, itemSelector, section, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Item> getItemList() {
|
||||
ArrayList<Item> items = new ArrayList<>();
|
||||
items.add(new MaterialItem(this));
|
||||
items.add(new DisplayNameItem(this));
|
||||
items.add(new LoreItem(this));
|
||||
items.add(new CMDItem(this));
|
||||
items.add(new TagItem(this));
|
||||
items.add(new UnbreakableItem(this));
|
||||
items.add(new DurabilityItem(this));
|
||||
items.add(new RandomDurabilityItem(this));
|
||||
items.add(new StackableItem(this));
|
||||
items.add(new ItemFlagItem(this));
|
||||
items.add(new Head64Item(this));
|
||||
items.add(new NBTItem(this));
|
||||
items.add(new EnchantmentItem(this));
|
||||
items.add(new StoredEnchantmentItem(this));
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.gui.page.item;
|
||||
|
||||
import net.momirealms.customfishing.gui.icon.property.item.*;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public class HookEditor extends AbstractSectionEditor {
|
||||
|
||||
public HookEditor(Player player, String key, ItemSelector itemSelector, ConfigurationSection section) {
|
||||
super(player, itemSelector, section, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Item> getItemList() {
|
||||
ArrayList<Item> items = new ArrayList<>();
|
||||
items.add(new MaterialItem(this));
|
||||
items.add(new DisplayNameItem(this));
|
||||
items.add(new LoreItem(this));
|
||||
items.add(new CMDItem(this));
|
||||
items.add(new TagItem(this));
|
||||
items.add(new UnbreakableItem(this));
|
||||
items.add(new DurabilityItem(this));
|
||||
items.add(new RandomDurabilityItem(this));
|
||||
items.add(new StackableItem(this));
|
||||
items.add(new ItemFlagItem(this));
|
||||
items.add(new Head64Item(this));
|
||||
items.add(new NBTItem(this));
|
||||
items.add(new EnchantmentItem(this));
|
||||
items.add(new StoredEnchantmentItem(this));
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
/*
|
||||
* 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.gui.page.item;
|
||||
|
||||
import com.saicone.rtag.RtagItem;
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.gui.YamlPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.gui.icon.BackToFolderItem;
|
||||
import net.momirealms.customfishing.gui.icon.NextPageItem;
|
||||
import net.momirealms.customfishing.gui.icon.PreviousPageItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.gui.structure.Markers;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemSelector implements YamlPage {
|
||||
|
||||
private final String SEARCH;
|
||||
private final Player player;
|
||||
private final YamlConfiguration yaml;
|
||||
private String prefix;
|
||||
private final File file;
|
||||
private long coolDown;
|
||||
private final String type;
|
||||
|
||||
public ItemSelector(Player player, File file, String type) {
|
||||
this.yaml = YamlConfiguration.loadConfiguration(file);
|
||||
this.player = player;
|
||||
this.file = file;
|
||||
this.type = type;
|
||||
this.SEARCH = CFLocale.GUI_SEARCH;
|
||||
this.prefix = SEARCH;
|
||||
this.reOpenWithFilter(SEARCH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reOpen() {
|
||||
reOpenWithFilter(prefix);
|
||||
}
|
||||
|
||||
public void reOpenWithFilter(String filter) {
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a # #")
|
||||
.addIngredient('a', new SimpleItem(new ItemBuilder(Material.NAME_TAG).setDisplayName(filter)))
|
||||
.addIngredient('#', border)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # a # c # b # #"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.addIngredient('a', new PreviousPageItem())
|
||||
.addIngredient('b', new NextPageItem())
|
||||
.addIngredient('c', new BackToFolderItem(file.getParentFile()))
|
||||
.setContent(getItemList())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_SELECT_ITEM
|
||||
)))
|
||||
.addRenameHandler(s -> {
|
||||
long current = System.currentTimeMillis();
|
||||
if (current - coolDown < 100) return;
|
||||
if (s.equals(filter)) return;
|
||||
prefix = s;
|
||||
coolDown = current;
|
||||
reOpenWithFilter(s);
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public void reOpenWithNewKey() {
|
||||
String tempKey = CFLocale.GUI_TEMP_NEW_KEY;
|
||||
prefix = tempKey;
|
||||
var confirmIcon = new ConfirmIcon();
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a # b")
|
||||
.addIngredient('a', new SimpleItem(new ItemBuilder(Material.NAME_TAG).setDisplayName(tempKey)))
|
||||
.addIngredient('b', confirmIcon)
|
||||
.addIngredient('#', border)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # a # c # b # #"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.addIngredient('a', new PreviousPageItem())
|
||||
.addIngredient('b', new NextPageItem())
|
||||
.addIngredient('c', new BackToFolderItem(file.getParentFile()))
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_SET_NEW_KEY)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
long current = System.currentTimeMillis();
|
||||
if (current - coolDown < 100) return;
|
||||
if (s.equals(tempKey)) return;
|
||||
prefix = s;
|
||||
coolDown = current;
|
||||
confirmIcon.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public List<Item> getItemList() {
|
||||
List<Item> itemList = new ArrayList<>();
|
||||
for (Map.Entry<String, Object> entry : this.yaml.getValues(false).entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (entry.getValue() instanceof ConfigurationSection section) {
|
||||
if (!prefix.equals(SEARCH) && !entry.getKey().startsWith(prefix)) continue;
|
||||
String material = section.getString("material");
|
||||
if (material != null) {
|
||||
ItemStack build = BukkitCustomFishingPlugin.get().getItemManager().getItemBuilder(section, type, key).build(player);
|
||||
RtagItem rtagItem = new RtagItem(build);
|
||||
if (BukkitCustomFishingPlugin.get().getVersionManager().isNewerThan1_20_5()) {
|
||||
rtagItem.getComponent("");
|
||||
} else {
|
||||
rtagItem.remove("display");
|
||||
}
|
||||
ItemBuilder itemBuilder = new ItemBuilder(rtagItem.getItem());
|
||||
itemList.add(new ItemInList(key, itemBuilder, this));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
itemList.add(new ItemInList(key, new ItemBuilder(Material.STRUCTURE_VOID), this));
|
||||
}
|
||||
itemList.add(new AddKey());
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public void removeKey(String key) {
|
||||
yaml.set(key, null);
|
||||
}
|
||||
|
||||
public void openEditor(String key) {
|
||||
switch (type) {
|
||||
case "item" -> new SectionEditor(player, key, this, yaml.getConfigurationSection(key));
|
||||
case "rod" -> new RodEditor(player, key, this, yaml.getConfigurationSection(key));
|
||||
case "bait" -> new BaitEditor(player, key, this, yaml.getConfigurationSection(key));
|
||||
case "hook" -> new HookEditor(player, key, this, yaml.getConfigurationSection(key));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
try {
|
||||
yaml.save(file);
|
||||
} catch (IOException e) {
|
||||
LogUtils.warn("Failed to save file", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ItemInList extends AbstractItem {
|
||||
|
||||
private final String key;
|
||||
private final ItemBuilder itemBuilder;
|
||||
private final ItemSelector itemSelector;
|
||||
|
||||
public ItemInList(String key, ItemBuilder itemBuilder, ItemSelector itemSelector) {
|
||||
this.key = key;
|
||||
this.itemBuilder = itemBuilder.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
key
|
||||
))).addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_DELETE
|
||||
)));
|
||||
this.itemSelector = itemSelector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
this.itemSelector.openEditor(key);
|
||||
} else if (clickType.isRightClick()) {
|
||||
this.itemSelector.removeKey(key);
|
||||
this.itemSelector.save();
|
||||
this.itemSelector.reOpenWithFilter(itemSelector.prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AddKey extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.ANVIL).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ADD_NEW_KEY
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
reOpenWithNewKey();
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfirmIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (prefix != null && !yaml.contains(prefix) && prefix.matches("^[a-zA-Z0-9_]+$")) {
|
||||
var builder = new ItemBuilder(Material.NAME_TAG)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
prefix
|
||||
)));
|
||||
builder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_CANCEL
|
||||
)));
|
||||
return builder;
|
||||
} else {
|
||||
return new ItemBuilder(Material.BARRIER)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_DUPE_INVALID_KEY
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
if (prefix != null && !yaml.contains(prefix) && prefix.matches("^[a-zA-Z0-9_]+$")) {
|
||||
yaml.createSection(prefix);
|
||||
save();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
prefix = SEARCH;
|
||||
reOpenWithFilter(SEARCH);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.gui.page.item;
|
||||
|
||||
import net.momirealms.customfishing.gui.icon.property.item.*;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public class RodEditor extends AbstractSectionEditor {
|
||||
|
||||
public RodEditor(Player player, String key, ItemSelector itemSelector, ConfigurationSection section) {
|
||||
super(player, itemSelector, section, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Item> getItemList() {
|
||||
ArrayList<Item> items = new ArrayList<>();
|
||||
items.add(new MaterialItem(this));
|
||||
items.add(new DisplayNameItem(this));
|
||||
items.add(new LoreItem(this));
|
||||
items.add(new CMDItem(this));
|
||||
items.add(new TagItem(this));
|
||||
items.add(new UnbreakableItem(this));
|
||||
items.add(new DurabilityItem(this));
|
||||
items.add(new RandomDurabilityItem(this));
|
||||
items.add(new ItemFlagItem(this));
|
||||
items.add(new NBTItem(this));
|
||||
items.add(new EnchantmentItem(this));
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.gui.page.item;
|
||||
|
||||
import net.momirealms.customfishing.gui.icon.property.item.*;
|
||||
import net.momirealms.customfishing.gui.icon.property.loot.*;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SectionEditor extends AbstractSectionEditor {
|
||||
|
||||
public SectionEditor(Player player, String key, ItemSelector itemSelector, ConfigurationSection section) {
|
||||
super(player, itemSelector, section, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Item> getItemList() {
|
||||
ArrayList<Item> items = new ArrayList<>();
|
||||
items.add(new MaterialItem(this));
|
||||
items.add(new NickItem(this));
|
||||
items.add(new DisplayNameItem(this));
|
||||
items.add(new LoreItem(this));
|
||||
items.add(new CMDItem(this));
|
||||
items.add(new AmountItem(this));
|
||||
items.add(new TagItem(this));
|
||||
items.add(new UnbreakableItem(this));
|
||||
items.add(new DurabilityItem(this));
|
||||
items.add(new RandomDurabilityItem(this));
|
||||
items.add(new StackableItem(this));
|
||||
items.add(new PreventGrabItem(this));
|
||||
items.add(new PriceItem(this));
|
||||
items.add(new ShowInFinderItem(this));
|
||||
items.add(new DisableStatsItem(this));
|
||||
items.add(new DisableGameItem(this));
|
||||
items.add(new InstantGameItem(this));
|
||||
items.add(new ScoreItem(this));
|
||||
items.add(new SizeItem(this));
|
||||
items.add(new ItemFlagItem(this));
|
||||
items.add(new Head64Item(this));
|
||||
items.add(new NBTItem(this));
|
||||
items.add(new EnchantmentItem(this));
|
||||
items.add(new StoredEnchantmentItem(this));
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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.gui.page.property;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
public class AmountEditor {
|
||||
|
||||
private final SectionPage parentPage;
|
||||
private String amount;
|
||||
private final ConfigurationSection section;
|
||||
|
||||
public AmountEditor(Player player, SectionPage parentPage) {
|
||||
this.parentPage = parentPage;
|
||||
this.section = parentPage.getSection();
|
||||
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
var confirm = new ConfirmIcon();
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a # b")
|
||||
.addIngredient('a', new ItemBuilder(Material.IRON_NUGGET).setDisplayName(String.valueOf(section.getInt("amount", 1))))
|
||||
.addIngredient('#', border)
|
||||
.addIngredient('b', confirm)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', new ItemStack(Material.AIR))
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_TITLE_AMOUNT)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
amount = s;
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public class ConfirmIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (amount == null || amount.isEmpty()) {
|
||||
return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_DELETE_PROPERTY
|
||||
)));
|
||||
} else {
|
||||
try {
|
||||
int m = Integer.parseInt(amount);
|
||||
if (m >= 1) {
|
||||
return new ItemBuilder(Material.IRON_NUGGET)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
)))
|
||||
.setAmount(m);
|
||||
} else {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_INVALID_NUMBER
|
||||
)));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_INVALID_NUMBER
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (amount == null || amount.isEmpty()) {
|
||||
section.set("amount", null);
|
||||
} else {
|
||||
try {
|
||||
int value = Integer.parseInt(amount);
|
||||
if (value >= 1) {
|
||||
section.set("amount", value);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
parentPage.reOpen();
|
||||
parentPage.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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.gui.page.property;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
public class CustomModelDataEditor {
|
||||
|
||||
private final Player player;
|
||||
private final SectionPage parentPage;
|
||||
private String cmd;
|
||||
private final ConfigurationSection section;
|
||||
private final String material;
|
||||
|
||||
public CustomModelDataEditor(Player player, SectionPage parentPage) {
|
||||
this.player = player;
|
||||
this.parentPage = parentPage;
|
||||
this.section = parentPage.getSection();
|
||||
this.material = section.getString("material");
|
||||
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
var confirm = new ConfirmIcon();
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure(
|
||||
"a # b"
|
||||
)
|
||||
.addIngredient('a', new ItemBuilder(BukkitCustomFishingPlugin.get()
|
||||
.getItemManager()
|
||||
.getItemStackAppearance(player, material)
|
||||
)
|
||||
.setCustomModelData(section.getInt("custom-model-data", 0))
|
||||
.setDisplayName(String.valueOf(section.getInt("custom-model-data", 0))))
|
||||
.addIngredient('#', border)
|
||||
.addIngredient('b', confirm)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', new ItemStack(Material.AIR))
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_TITLE_MODEL_DATA)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
cmd = s;
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public class ConfirmIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (cmd == null || cmd.isEmpty()) {
|
||||
return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_DELETE_PROPERTY
|
||||
)));
|
||||
} else {
|
||||
try {
|
||||
int value = Integer.parseInt(cmd);
|
||||
if (value >= 0) {
|
||||
return new ItemBuilder(
|
||||
BukkitCustomFishingPlugin.get()
|
||||
.getItemManager()
|
||||
.getItemStackAppearance(player, material)
|
||||
)
|
||||
.setCustomModelData(value)
|
||||
.setDisplayName(CFLocale.GUI_NEW_VALUE + value)
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
)));
|
||||
} else {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_INVALID_NUMBER
|
||||
)));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_INVALID_NUMBER
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (cmd == null || cmd.isEmpty()) {
|
||||
section.set("custom-model-data", null);
|
||||
} else {
|
||||
try {
|
||||
int value = Integer.parseInt(cmd);
|
||||
if (value >= 0) {
|
||||
section.set("custom-model-data", value);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
parentPage.reOpen();
|
||||
parentPage.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.gui.page.property;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
public class DisplayNameEditor {
|
||||
|
||||
private final SectionPage parentPage;
|
||||
private String name;
|
||||
private final ConfigurationSection section;
|
||||
|
||||
public DisplayNameEditor(Player player, SectionPage parentPage) {
|
||||
this.parentPage = parentPage;
|
||||
this.section = parentPage.getSection();
|
||||
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
var confirm = new ConfirmIcon();
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a # b")
|
||||
.addIngredient('a', new ItemBuilder(Material.NAME_TAG).setDisplayName(section.getString("display.name", CFLocale.GUI_NEW_DISPLAY_NAME)))
|
||||
.addIngredient('#', border)
|
||||
.addIngredient('b', confirm)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', new ItemStack(Material.AIR))
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_TITLE_DISPLAY_NAME)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
name = s;
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public class ConfirmIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (name == null || name.isEmpty()) {
|
||||
return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_DELETE_PROPERTY
|
||||
)));
|
||||
} else {
|
||||
return new ItemBuilder(Material.NAME_TAG)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"<!i>" + name
|
||||
)))
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
section.set("display.name", null);
|
||||
} else {
|
||||
section.set("display.name", name);
|
||||
}
|
||||
parentPage.reOpen();
|
||||
parentPage.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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.gui.page.property;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
public class DurabilityEditor {
|
||||
|
||||
private final SectionPage parentPage;
|
||||
private String dur;
|
||||
private final ConfigurationSection section;
|
||||
|
||||
public DurabilityEditor(Player player, SectionPage parentPage) {
|
||||
this.parentPage = parentPage;
|
||||
this.section = parentPage.getSection();
|
||||
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
var confirm = new ConfirmIcon();
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a # b")
|
||||
.addIngredient('a', new ItemBuilder(Material.NETHERITE_PICKAXE).setDisplayName(String.valueOf(section.getInt("max-durability", 64))))
|
||||
.addIngredient('#', border)
|
||||
.addIngredient('b', confirm)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', new ItemStack(Material.AIR))
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_TITLE_CUSTOM_DURABILITY)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
dur = s;
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public class ConfirmIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (dur == null || dur.isEmpty()) {
|
||||
return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_DELETE_PROPERTY
|
||||
)));
|
||||
} else {
|
||||
try {
|
||||
int m = Integer.parseInt(dur);
|
||||
if (m >= 1) {
|
||||
return new ItemBuilder(Material.NETHERITE_PICKAXE)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NEW_VALUE + dur
|
||||
)))
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
)))
|
||||
.setDamage(Math.max(0, Material.NETHERITE_PICKAXE.getMaxDurability() - m));
|
||||
} else {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_INVALID_NUMBER
|
||||
)));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_INVALID_NUMBER
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (dur == null || dur.isEmpty()) {
|
||||
section.set("max-durability", null);
|
||||
} else {
|
||||
try {
|
||||
int value = Integer.parseInt(dur);
|
||||
if (value >= 1) {
|
||||
section.set("max-durability", value);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
parentPage.reOpen();
|
||||
parentPage.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* 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.gui.page.property;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.gui.structure.Markers;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class EnchantmentEditor {
|
||||
|
||||
private final Player player;
|
||||
private final SectionPage parentPage;
|
||||
private final ArrayList<String> enchantments;
|
||||
private final ConfigurationSection section;
|
||||
private int index;
|
||||
private final boolean store;
|
||||
|
||||
public EnchantmentEditor(Player player, SectionPage parentPage, boolean store) {
|
||||
this.player = player;
|
||||
this.parentPage = parentPage;
|
||||
this.section = parentPage.getSection();
|
||||
this.store = store;
|
||||
this.index = 0;
|
||||
this.enchantments = new ArrayList<>();
|
||||
this.enchantments.add(CFLocale.GUI_SELECT_ONE_ENCHANTMENT);
|
||||
ConfigurationSection eSection = section.getConfigurationSection(store ? "stored-enchantments" : "enchantments");
|
||||
if (eSection != null)
|
||||
for (Map.Entry<String, Object> entry : eSection.getValues(false).entrySet()) {
|
||||
this.enchantments.add(entry.getKey() + ":" + entry.getValue());
|
||||
}
|
||||
reOpen(0);
|
||||
}
|
||||
|
||||
public void reOpen(int idx) {
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
var confirm = new ConfirmIcon();
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a # b")
|
||||
.addIngredient('a', new ItemBuilder(Material.NAME_TAG).setDisplayName(enchantments.get(idx)))
|
||||
.addIngredient('#', border)
|
||||
.addIngredient('b', confirm)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.setContent(getContents())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(store ? CFLocale.GUI_TITLE_STORED_ENCHANTMENT : CFLocale.GUI_TITLE_ENCHANTMENT)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
if (index == 0) return;
|
||||
enchantments.set(index, s);
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public List<Item> getContents() {
|
||||
ArrayList<Item> items = new ArrayList<>();
|
||||
int i = 1;
|
||||
List<String> subList = enchantments.subList(1, enchantments.size());
|
||||
for (String lore : subList) {
|
||||
items.add(new EnchantmentElement(lore, i++));
|
||||
}
|
||||
items.add(new AddEnchantment());
|
||||
return items;
|
||||
}
|
||||
|
||||
public class AddEnchantment extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.ANVIL).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ADD_NEW_ENCHANTMENT
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
enchantments.add("namespace:enchantment:level");
|
||||
index = enchantments.size() - 1;
|
||||
reOpen(index);
|
||||
}
|
||||
}
|
||||
|
||||
public class EnchantmentElement extends AbstractItem {
|
||||
|
||||
private final String line;
|
||||
private final int idx;
|
||||
|
||||
public EnchantmentElement(String line, int idx) {
|
||||
this.line = line;
|
||||
this.idx = idx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.ENCHANTED_BOOK).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
line
|
||||
))).addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_DELETE
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType == ClickType.LEFT) {
|
||||
index = idx;
|
||||
reOpen(idx);
|
||||
} else if (clickType == ClickType.RIGHT) {
|
||||
enchantments.remove(idx);
|
||||
index = Math.min(index, enchantments.size() - 1);
|
||||
reOpen(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfirmIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
List<String> subList = enchantments.subList(1, enchantments.size());
|
||||
if (subList.isEmpty()) {
|
||||
return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_DELETE_PROPERTY
|
||||
)));
|
||||
} else {
|
||||
var builder = new ItemBuilder(Material.NAME_TAG)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
)));
|
||||
for (String enchantment : subList) {
|
||||
String[] split = enchantment.split(":");
|
||||
if (split.length != 3) {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ILLEGAL_FORMAT
|
||||
)));
|
||||
}
|
||||
try {
|
||||
Integer.parseInt(split[2]);
|
||||
builder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
" <gray>-</gray> " + enchantment
|
||||
)));
|
||||
} catch (NumberFormatException e) {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ILLEGAL_FORMAT
|
||||
)));
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
List<String> subList = enchantments.subList(1, enchantments.size());
|
||||
for (String line : subList) {
|
||||
String[] split = line.split(":");
|
||||
if (split.length != 3) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Integer.parseInt(split[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
section.set(store ? "stored-enchantments" : "enchantments", null);
|
||||
for (String line : subList) {
|
||||
String[] split = line.split(":");
|
||||
section.set((store ? "stored-enchantments" : "enchantments") + "." + split[0] + ":" + split[1], Integer.parseInt(split[2]));
|
||||
}
|
||||
parentPage.reOpen();
|
||||
parentPage.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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.gui.page.property;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.gui.structure.Markers;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemFlagEditor {
|
||||
|
||||
private final Player player;
|
||||
private final SectionPage parentPage;
|
||||
private final List<String> flags;
|
||||
private final ConfigurationSection section;
|
||||
|
||||
public ItemFlagEditor(Player player, SectionPage parentPage) {
|
||||
this.player = player;
|
||||
this.parentPage = parentPage;
|
||||
this.section = parentPage.getSection();
|
||||
this.flags = section.getStringList("item-flags");
|
||||
reOpen();
|
||||
}
|
||||
|
||||
public void reOpen() {
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure(
|
||||
"# a #"
|
||||
)
|
||||
.addIngredient('a', new ItemBuilder(BukkitCustomFishingPlugin.get().getItemManager().getItemBuilder(section, "item", "id").build(player)))
|
||||
.addIngredient('#', new SimpleItem(new ItemBuilder(Material.AIR)))
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.setContent(getContents())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_TITLE_ITEM_FLAG)
|
||||
))
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public List<Item> getContents() {
|
||||
ArrayList<Item> items = new ArrayList<>();
|
||||
for (ItemFlag itemFlag : ItemFlag.values()) {
|
||||
items.add(new ItemFlagToggleItem(itemFlag.name()));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public class ItemFlagToggleItem extends AbstractItem {
|
||||
|
||||
private final String flag;
|
||||
|
||||
public ItemFlagToggleItem(String flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (flags.contains(flag)) {
|
||||
return new ItemBuilder(Material.GREEN_BANNER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"<green>" + flag
|
||||
)));
|
||||
} else {
|
||||
return new ItemBuilder(Material.RED_BANNER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"<red>" + flag
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (flags.contains(flag)) {
|
||||
flags.remove(flag);
|
||||
} else {
|
||||
flags.add(flag);
|
||||
}
|
||||
if (flags.size() != 0) {
|
||||
section.set("item-flags", flags);
|
||||
} else {
|
||||
section.set("item-flags", null);
|
||||
}
|
||||
parentPage.save();
|
||||
reOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* 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.gui.page.property;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.gui.structure.Markers;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LoreEditor {
|
||||
|
||||
private final Player player;
|
||||
private final SectionPage parentPage;
|
||||
private final ArrayList<String> lore;
|
||||
private final ConfigurationSection section;
|
||||
private int index;
|
||||
|
||||
public LoreEditor(Player player, SectionPage parentPage) {
|
||||
this.player = player;
|
||||
this.parentPage = parentPage;
|
||||
this.section = parentPage.getSection();
|
||||
this.index = 0;
|
||||
this.lore = new ArrayList<>(section.getStringList("display.lore"));
|
||||
this.lore.add(0, CFLocale.GUI_SELECT_ONE_LORE);
|
||||
reOpen(0);
|
||||
}
|
||||
|
||||
public void reOpen(int idx) {
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
var confirm = new ConfirmIcon();
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a # b")
|
||||
.addIngredient('a', new ItemBuilder(Material.NAME_TAG).setDisplayName(lore.get(idx)))
|
||||
.addIngredient('#', border)
|
||||
.addIngredient('b', confirm)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.setContent(getContents())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_TITLE_LORE)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
if (index == 0) return;
|
||||
lore.set(index, s);
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public List<Item> getContents() {
|
||||
ArrayList<Item> items = new ArrayList<>();
|
||||
int i = 1;
|
||||
List<String> subList = lore.subList(1, lore.size());
|
||||
for (String lore : subList) {
|
||||
items.add(new LoreElement(lore, i++));
|
||||
}
|
||||
items.add(new AddLore());
|
||||
return items;
|
||||
}
|
||||
|
||||
public class AddLore extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.ANVIL).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ADD_NEW_LORE
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
lore.add("Text");
|
||||
index = lore.size() - 1;
|
||||
reOpen(index);
|
||||
}
|
||||
}
|
||||
|
||||
public class LoreElement extends AbstractItem {
|
||||
|
||||
private final String line;
|
||||
private final int idx;
|
||||
|
||||
public LoreElement(String line, int idx) {
|
||||
this.line = line;
|
||||
this.idx = idx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.PAPER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
line
|
||||
))).addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_DELETE
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType == ClickType.LEFT) {
|
||||
index = idx;
|
||||
reOpen(idx);
|
||||
} else if (clickType == ClickType.RIGHT) {
|
||||
lore.remove(idx);
|
||||
index = Math.min(index, lore.size() - 1);
|
||||
reOpen(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfirmIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
List<String> subList = lore.subList(1, lore.size());
|
||||
if (subList.isEmpty()) {
|
||||
return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_DELETE_PROPERTY
|
||||
)));
|
||||
} else {
|
||||
var builder = new ItemBuilder(Material.NAME_TAG)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
)));
|
||||
for (String lore : subList) {
|
||||
builder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
" <gray>-</gray> " + lore
|
||||
)));
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
List<String> subList = lore.subList(1, lore.size());
|
||||
if (lore.isEmpty()) {
|
||||
section.set("display.lore", null);
|
||||
} else {
|
||||
section.set("display.lore", subList);
|
||||
}
|
||||
parentPage.reOpen();
|
||||
parentPage.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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.gui.page.property;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.mechanic.item.ItemManagerImpl;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.gui.structure.Markers;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MaterialEditor {
|
||||
|
||||
private final Player player;
|
||||
private final SectionPage parentPage;
|
||||
private String material;
|
||||
private final ConfigurationSection section;
|
||||
|
||||
public MaterialEditor(Player player, SectionPage parentPage) {
|
||||
this.player = player;
|
||||
this.parentPage = parentPage;
|
||||
this.section = parentPage.getSection();
|
||||
this.material = section.getString("material");
|
||||
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
var confirm = new ConfirmIcon();
|
||||
var itemBuilder = new ItemBuilder(BukkitCustomFishingPlugin.get()
|
||||
.getItemManager()
|
||||
.getItemStackAppearance(player, material)
|
||||
)
|
||||
.setDisplayName(section.getString("material", ""));
|
||||
|
||||
if (section.contains("custom-model-data"))
|
||||
itemBuilder.setCustomModelData(section.getInt("custom-model-data", 0));
|
||||
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a # b")
|
||||
.addIngredient('a', itemBuilder)
|
||||
.addIngredient('#', border)
|
||||
.addIngredient('b', confirm)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.setContent(getCompatibilityItemList())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_TITLE_MATERIAL)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
material = s;
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public List<Item> getCompatibilityItemList() {
|
||||
ArrayList<Item> items = new ArrayList<>();
|
||||
for (String lib : ((ItemManagerImpl) BukkitCustomFishingPlugin.get().getItemManager()).getItemLibraries()) {
|
||||
switch (lib) {
|
||||
case "MMOItems" -> items.add(new SimpleItem(new ItemBuilder(Material.BELL).setDisplayName(lib + ":TYPE:ID")));
|
||||
case "ItemsAdder" -> items.add(new SimpleItem(new ItemBuilder(Material.BELL).setDisplayName(lib + ":namespace:id")));
|
||||
case "vanilla", "CustomFishing" -> {}
|
||||
default -> items.add(new SimpleItem(new ItemBuilder(Material.BELL).setDisplayName(lib + ":ID")));
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public class ConfirmIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (material == null || material.isEmpty()) {
|
||||
return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_DELETE_PROPERTY
|
||||
)));
|
||||
} else {
|
||||
var builder = new ItemBuilder(
|
||||
BukkitCustomFishingPlugin.get()
|
||||
.getItemManager()
|
||||
.getItemStackAppearance(player, material)
|
||||
).setDisplayName(CFLocale.GUI_NEW_VALUE + material)
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
)));
|
||||
if (section.contains("custom-model-data"))
|
||||
builder.setCustomModelData(section.getInt("custom-model-data"));
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (material == null || material.isEmpty()) {
|
||||
section.set("material", null);
|
||||
} else if (BukkitCustomFishingPlugin.get().getItemManager().getItemStackAppearance(player, material).getType() == Material.BARRIER) {
|
||||
return;
|
||||
} else {
|
||||
section.set("material", material);
|
||||
}
|
||||
parentPage.reOpen();
|
||||
parentPage.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,697 @@
|
||||
/*
|
||||
* 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.gui.page.property;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import net.momirealms.customfishing.util.ConfigUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.gui.structure.Markers;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public class NBTEditor {
|
||||
|
||||
private final Player player;
|
||||
private final SectionPage parentPage;
|
||||
private ConfigurationSection nbtSection;
|
||||
private ConfigurationSection currentSection;
|
||||
private String value;
|
||||
private String currentNode;
|
||||
|
||||
public NBTEditor(Player player, SectionPage parentPage) {
|
||||
this.player = player;
|
||||
this.parentPage = parentPage;
|
||||
this.nbtSection = parentPage.getSection().getConfigurationSection("nbt");
|
||||
if (this.nbtSection == null)
|
||||
this.nbtSection = parentPage.getSection().createSection("nbt");
|
||||
this.currentSection = nbtSection;
|
||||
this.currentNode = "";
|
||||
reOpenMain();
|
||||
}
|
||||
|
||||
public List<Item> getNBTContents() {
|
||||
Deque<Item> deque = new ArrayDeque<>();
|
||||
for (Map.Entry<String, Object> entry : currentSection.getValues(false).entrySet()) {
|
||||
String path = Objects.equals(currentNode, "") ? entry.getKey() : currentNode + "." + entry.getKey();
|
||||
if (entry.getValue() instanceof List<?> list) {
|
||||
deque.addLast(new InvListIcon(path));
|
||||
} else if (entry.getValue() instanceof String str) {
|
||||
deque.addLast(new InvValueIcon(path, str));
|
||||
} else if (entry.getValue() instanceof ConfigurationSection inner) {
|
||||
deque.addFirst(new InvCompoundIcon(path, inner));
|
||||
} else if (entry.getValue() instanceof Map<?,?> map) {
|
||||
deque.addLast(new InvMapIcon(path));
|
||||
}
|
||||
}
|
||||
deque.addLast(new NewCompoundIcon());
|
||||
deque.addLast(new NewListIcon());
|
||||
deque.addLast(new NewValueIcon());
|
||||
if (currentSection.getParent() != null && !currentSection.getName().equals("nbt")) {
|
||||
deque.addLast(new BackToParentIcon());
|
||||
}
|
||||
return new ArrayList<>(deque);
|
||||
}
|
||||
|
||||
public void reOpenMain() {
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("b b c")
|
||||
.addIngredient('b', new ItemStack(Material.AIR))
|
||||
.addIngredient('c', new SaveIcon())
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.setContent(getNBTContents())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_NBT_EDIT_TITLE)))
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public void reOpenAddCompound() {
|
||||
var confirm = new ConfirmCompoundItem();
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a b c")
|
||||
.addIngredient('a', new ItemBuilder(Material.COMMAND_BLOCK_MINECART).setDisplayName(""))
|
||||
.addIngredient('b', new ItemStack(Material.AIR))
|
||||
.addIngredient('c', confirm)
|
||||
.build();
|
||||
|
||||
value = "";
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.setContent(getNBTContents())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_TITLE_NBT_COMPOUND)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
value = s;
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public void reOpenAddList() {
|
||||
var confirm = new ConfirmListItem();
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a b c")
|
||||
.addIngredient('a', new ItemBuilder(Material.CHAIN_COMMAND_BLOCK).setDisplayName(""))
|
||||
.addIngredient('b', new ItemStack(Material.AIR))
|
||||
.addIngredient('c', confirm)
|
||||
.build();
|
||||
|
||||
value = "";
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.setContent(getNBTContents())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_TITLE_NBT_LIST)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
value = s;
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public void reOpenAddValue() {
|
||||
var confirm =new ConfirmValueItem();
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a b c")
|
||||
.addIngredient('a', new ItemBuilder(Material.COMMAND_BLOCK).setDisplayName(""))
|
||||
.addIngredient('b', new ItemStack(Material.AIR))
|
||||
.addIngredient('c', confirm)
|
||||
.build();
|
||||
|
||||
value = "";
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.setContent(getNBTContents())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_TITLE_NBT_KEY)))
|
||||
.addRenameHandler(s -> {
|
||||
value = s;
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public void reOpenSetValue(String key, String type) {
|
||||
var save = new SaveValueIcon(key);
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a b c")
|
||||
.addIngredient('a', new ItemBuilder(Material.COMMAND_BLOCK).setDisplayName(type == null ? "" : "(" + type + ") "))
|
||||
.addIngredient('b', new ItemStack(Material.AIR))
|
||||
.addIngredient('c', save)
|
||||
.build();
|
||||
|
||||
value = "";
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.setContent(getTypeContents(key))
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_NBT_SET_VALUE_TITLE)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
value = s;
|
||||
save.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public void removeByNode(String node) {
|
||||
nbtSection.set(node, null);
|
||||
parentPage.save();
|
||||
}
|
||||
|
||||
public List<Item> getTypeContents(String key) {
|
||||
ArrayList<Item> list = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : Map.of(
|
||||
"String","some text",
|
||||
"Byte","1",
|
||||
"Short","123",
|
||||
"Int","123456",
|
||||
"Long","123456789",
|
||||
"Double", "1.2345",
|
||||
"Float", "1.23",
|
||||
"Boolean", "true",
|
||||
"IntArray", "[111,222,333,444]",
|
||||
"ByteArray","[1,2,3,4]"
|
||||
).entrySet()) {
|
||||
list.add(new TypeItem(key, entry.getKey(), entry.getValue()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public class TypeItem extends AbstractItem {
|
||||
|
||||
private final String type;
|
||||
private final String tip;
|
||||
private final String key;
|
||||
|
||||
public TypeItem(String key, String type, String tip) {
|
||||
this.type = type;
|
||||
this.tip = tip;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.BELL).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"(" + type + ") " + tip
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
reOpenSetValue(key, type);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfirmCompoundItem extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (value == null || value.equals("") || value.contains(".") || currentSection.contains(value)) {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NBT_INVALID_KEY
|
||||
)));
|
||||
}
|
||||
|
||||
return new ItemBuilder(Material.COMMAND_BLOCK_MINECART).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NEW_VALUE + value
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_CANCEL
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
if (value == null || value.equals("") || value.contains(".")) {
|
||||
return;
|
||||
}
|
||||
if (currentSection.contains(value)) {
|
||||
return;
|
||||
}
|
||||
currentSection.createSection(value);
|
||||
parentPage.save();
|
||||
}
|
||||
reOpenMain();
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfirmListItem extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (value == null || value.equals("") || value.contains(".") || currentSection.contains(value)) {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NBT_INVALID_KEY
|
||||
)));
|
||||
}
|
||||
return new ItemBuilder(Material.CHAIN_COMMAND_BLOCK).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NEW_VALUE + value
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_CANCEL
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
if (value == null || value.equals("") || value.contains(".")) {
|
||||
return;
|
||||
}
|
||||
if (currentSection.contains(value)) {
|
||||
return;
|
||||
}
|
||||
currentSection.set(value, new ArrayList<>());
|
||||
parentPage.save();
|
||||
}
|
||||
reOpenMain();
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfirmValueItem extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (value == null || value.equals("") || value.contains(".") || currentSection.contains(value)) {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NBT_INVALID_KEY
|
||||
)));
|
||||
}
|
||||
|
||||
return new ItemBuilder(Material.COMMAND_BLOCK).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NEW_VALUE + value
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_CANCEL
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
if (value == null || value.equals("") || value.contains(".")) {
|
||||
return;
|
||||
}
|
||||
if (currentSection.contains(value)) {
|
||||
return;
|
||||
}
|
||||
reOpenSetValue(value, null);
|
||||
} else if (clickType.isRightClick()) {
|
||||
reOpenMain();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class NewCompoundIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.OAK_SIGN).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NBT_ADD_COMPOUND
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
reOpenAddCompound();
|
||||
}
|
||||
}
|
||||
|
||||
public class NewListIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.SPRUCE_SIGN).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NBT_ADD_LIST
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
reOpenAddList();
|
||||
}
|
||||
}
|
||||
|
||||
public class NewValueIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.ACACIA_SIGN).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NBT_ADD_VALUE
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
reOpenAddValue();
|
||||
}
|
||||
}
|
||||
|
||||
public class InvCompoundIcon extends AbstractItem {
|
||||
|
||||
private final String node;
|
||||
private final ConfigurationSection compound;
|
||||
|
||||
public InvCompoundIcon(String node, ConfigurationSection compound) {
|
||||
this.compound = compound;
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
String[] splits = node.split("\\.");
|
||||
return new ItemBuilder(Material.COMMAND_BLOCK_MINECART).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"Compound: " + splits[splits.length -1]
|
||||
))).addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_DELETE
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick()) {
|
||||
currentSection = compound;
|
||||
currentNode = node;
|
||||
} else if (clickType.isRightClick()) {
|
||||
removeByNode(node);
|
||||
}
|
||||
reOpenMain();
|
||||
}
|
||||
}
|
||||
|
||||
public class InvValueIcon extends AbstractItem {
|
||||
|
||||
private final String node;
|
||||
private final String value;
|
||||
|
||||
public InvValueIcon(String node, String value) {
|
||||
this.node = node;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
String[] splits = node.split("\\.");
|
||||
return new ItemBuilder(Material.REPEATING_COMMAND_BLOCK).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
splits[splits.length -1] + ": " + value
|
||||
)))
|
||||
.addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_LEFT_CLICK_EDIT
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_DELETE
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
String[] split = node.split("\\.");
|
||||
if (clickType.isLeftClick()) {
|
||||
reOpenSetValue(split[split.length-1], NBTUtils.getTypeAndData(value)[0]);
|
||||
} else if (clickType.isRightClick()) {
|
||||
removeByNode(node);
|
||||
reOpenMain();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class InvListIcon extends AbstractItem {
|
||||
|
||||
private final String node;
|
||||
|
||||
public InvListIcon(String node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
String[] splits = node.split("\\.");
|
||||
return new ItemBuilder(Material.CHAIN_COMMAND_BLOCK).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"List: " + splits[splits.length -1]
|
||||
)))
|
||||
.addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"<st>" + CFLocale.GUI_LEFT_CLICK_EDIT + "</st>"
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_DELETE
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isRightClick()) {
|
||||
removeByNode(node);
|
||||
reOpenMain();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class InvMapIcon extends AbstractItem {
|
||||
|
||||
private final String node;
|
||||
|
||||
public InvMapIcon(String node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
String[] splits = node.split("\\.");
|
||||
return new ItemBuilder(Material.COMMAND_BLOCK).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"Map: " + splits[splits.length -1]
|
||||
)))
|
||||
.addLoreLines("")
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"<st>" + CFLocale.GUI_LEFT_CLICK_EDIT + "</st>"
|
||||
))).addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_DELETE
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isRightClick()) {
|
||||
removeByNode(node);
|
||||
reOpenMain();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SaveValueIcon extends AbstractItem {
|
||||
|
||||
private final String key;
|
||||
|
||||
public SaveValueIcon(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
try {
|
||||
NBTUtils.getTypeAndData(value);
|
||||
return new ItemBuilder(Material.COMMAND_BLOCK)
|
||||
.setDisplayName(value)
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
)))
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_RIGHT_CLICK_CANCEL
|
||||
)));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ILLEGAL_FORMAT
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType == ClickType.LEFT) {
|
||||
try {
|
||||
NBTUtils.getTypeAndData(value);
|
||||
currentSection.set(key, value);
|
||||
parentPage.save();
|
||||
reOpenMain();
|
||||
} catch (IllegalArgumentException e) {
|
||||
reOpenMain();
|
||||
}
|
||||
} else if (clickType == ClickType.RIGHT) {
|
||||
reOpenMain();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SaveIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (nbtSection.getValues(false).size() > 0) {
|
||||
var builder = new ItemBuilder(Material.ACACIA_SIGN).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NBT_PREVIEW
|
||||
)));
|
||||
for (String line : ConfigUtils.getReadableSection(nbtSection.getValues(false))) {
|
||||
builder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
line
|
||||
)));
|
||||
}
|
||||
return builder;
|
||||
} else {
|
||||
return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_DELETE_PROPERTY
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (nbtSection.getValues(false).size() == 0) {
|
||||
Objects.requireNonNull(nbtSection.getParent()).set("nbt", null);
|
||||
}
|
||||
parentPage.save();
|
||||
parentPage.reOpen();
|
||||
}
|
||||
}
|
||||
|
||||
public class BackToParentIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.MINECART).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NBT_BACK_TO_COMPOUND
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
currentSection = currentSection.getParent();
|
||||
currentNode = currentNode.lastIndexOf(".") == -1 ? "" : currentNode.substring(0, currentNode.lastIndexOf("."));
|
||||
reOpenMain();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.gui.page.property;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
public class NickEditor {
|
||||
|
||||
private final SectionPage parentPage;
|
||||
private String nick;
|
||||
private final ConfigurationSection section;
|
||||
|
||||
public NickEditor(Player player, SectionPage parentPage) {
|
||||
this.parentPage = parentPage;
|
||||
this.section = parentPage.getSection();
|
||||
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
var confirm = new ConfirmIcon();
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a # b")
|
||||
.addIngredient('a', new ItemBuilder(Material.WRITABLE_BOOK).setDisplayName(section.getString("nick", CFLocale.GUI_NICK_NEW)))
|
||||
.addIngredient('#', border)
|
||||
.addIngredient('b', confirm)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', new ItemStack(Material.AIR))
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_NICK_TITLE)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
nick = s;
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public class ConfirmIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (nick == null || nick.isEmpty()) {
|
||||
return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_DELETE_PROPERTY
|
||||
)));
|
||||
} else {
|
||||
return new ItemBuilder(Material.WRITABLE_BOOK)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
"<!i><white>" + nick
|
||||
)))
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (nick == null || nick.isEmpty()) {
|
||||
section.set("nick", null);
|
||||
} else {
|
||||
section.set("nick", nick);
|
||||
}
|
||||
parentPage.reOpen();
|
||||
parentPage.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* 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.gui.page.property;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
public class PriceEditor {
|
||||
|
||||
private final Player player;
|
||||
private final SectionPage parentPage;
|
||||
private final String[] price;
|
||||
private int index;
|
||||
private final ConfigurationSection section;
|
||||
|
||||
public PriceEditor(Player player, SectionPage parentPage) {
|
||||
this.player = player;
|
||||
this.parentPage = parentPage;
|
||||
this.section = parentPage.getSection();
|
||||
this.index = 0;
|
||||
this.price = new String[]{section.getString("price.base","0"), section.getString("price.bonus","0")};
|
||||
reOpen();
|
||||
}
|
||||
|
||||
public void reOpen() {
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
var confirm = new ConfirmIcon();
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a # b")
|
||||
.addIngredient('a', new ItemBuilder(Material.GOLD_INGOT).setDisplayName(price[index]))
|
||||
.addIngredient('#', border)
|
||||
.addIngredient('b', confirm)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"a b x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', new ItemStack(Material.AIR))
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.addIngredient('a', new BaseItem())
|
||||
.addIngredient('b', new BonusItem())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_PRICE_TITLE)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
if (s == null || s.equals("")) {
|
||||
price[index] = "0";
|
||||
return;
|
||||
}
|
||||
price[index] = s;
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public class BaseItem extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.GOLD_BLOCK).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_PRICE_BASE
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
index = 0;
|
||||
reOpen();
|
||||
}
|
||||
}
|
||||
|
||||
public class BonusItem extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.GOLD_NUGGET).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_PRICE_BONUS
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
index = 1;
|
||||
reOpen();
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfirmIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (price[0].equals("0") && price[1].equals("0")) {
|
||||
return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_DELETE_PROPERTY
|
||||
)));
|
||||
} else {
|
||||
try {
|
||||
Double.parseDouble(price[0]);
|
||||
Double.parseDouble(price[1]);
|
||||
return new ItemBuilder(Material.GOLD_INGOT)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NEW_VALUE
|
||||
)))
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_PRICE_BASE + price[0]
|
||||
)))
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_ITEM_PRICE_BONUS + price[1]
|
||||
)))
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
)));
|
||||
} catch (NumberFormatException e) {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_INVALID_NUMBER
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (price[0].equals("0") && price[1].equals("0")) {
|
||||
section.set("price", null);
|
||||
} else {
|
||||
try {
|
||||
double base = Double.parseDouble(price[0]);
|
||||
double bonus = Double.parseDouble(price[1]);
|
||||
if (base != 0) {
|
||||
section.set("price.base", base);
|
||||
}
|
||||
if (bonus != 0) {
|
||||
section.set("price.bonus", bonus);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
parentPage.reOpen();
|
||||
parentPage.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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.gui.page.property;
|
||||
|
||||
import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.gui.SectionPage;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.setting.CFLocale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.PagedGui;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.AnvilWindow;
|
||||
|
||||
public class ScoreEditor {
|
||||
|
||||
private final SectionPage parentPage;
|
||||
private String score;
|
||||
private final ConfigurationSection section;
|
||||
|
||||
public ScoreEditor(Player player, SectionPage parentPage) {
|
||||
this.parentPage = parentPage;
|
||||
this.section = parentPage.getSection();
|
||||
|
||||
Item border = new SimpleItem(new ItemBuilder(Material.AIR));
|
||||
var confirm = new ConfirmIcon();
|
||||
Gui upperGui = Gui.normal()
|
||||
.setStructure("a # b")
|
||||
.addIngredient('a', new ItemBuilder(Material.NETHER_STAR).setDisplayName(String.valueOf(section.getDouble("score", 0))))
|
||||
.addIngredient('#', border)
|
||||
.addIngredient('b', confirm)
|
||||
.build();
|
||||
|
||||
var gui = PagedGui.items()
|
||||
.setStructure(
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"x x x x x x x x x",
|
||||
"# # # # c # # # #"
|
||||
)
|
||||
.addIngredient('x', new ItemStack(Material.AIR))
|
||||
.addIngredient('c', parentPage.getBackItem())
|
||||
.addIngredient('#', new BackGroundItem())
|
||||
.build();
|
||||
|
||||
var window = AnvilWindow.split()
|
||||
.setViewer(player)
|
||||
.setTitle(new ShadedAdventureComponentWrapper(
|
||||
AdventureHelper.getInstance().getComponentFromMiniMessage(CFLocale.GUI_SCORE_TITLE)
|
||||
))
|
||||
.addRenameHandler(s -> {
|
||||
score = s;
|
||||
confirm.notifyWindows();
|
||||
})
|
||||
.setUpperGui(upperGui)
|
||||
.setLowerGui(gui)
|
||||
.build();
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
public class ConfirmIcon extends AbstractItem {
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
if (score == null || score.isEmpty()) {
|
||||
return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_DELETE_PROPERTY
|
||||
)));
|
||||
} else {
|
||||
try {
|
||||
Double.parseDouble(score);
|
||||
return new ItemBuilder(Material.NETHER_STAR)
|
||||
.setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_NEW_VALUE + score
|
||||
)))
|
||||
.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_CLICK_CONFIRM
|
||||
)));
|
||||
} catch (NumberFormatException e) {
|
||||
return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage(
|
||||
CFLocale.GUI_INVALID_NUMBER
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (score == null || score.isEmpty()) {
|
||||
section.set("score", null);
|
||||
} else {
|
||||
try {
|
||||
double value = Double.parseDouble(score);
|
||||
if (value >= 0) {
|
||||
section.set("score", value);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
parentPage.reOpen();
|
||||
parentPage.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user