Add experimental placeholder support

This commit is contained in:
GeorgH93 2023-07-08 17:01:02 +02:00
parent ac761a4b9b
commit 070d7d8944
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
5 changed files with 100 additions and 5 deletions

View File

@ -64,7 +64,7 @@ public ItemsCollector(Minepacks plugin)
itemFilter = plugin.getItemFilter();
}
private boolean canUseAutoPickup(Player player)
public boolean canUseAutoPickup(Player player)
{
// Check if player can use in world
if(plugin.isDisabled(player) != WorldBlacklistMode.None) return false;

View File

@ -32,6 +32,7 @@
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Language;
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.ItemFilter;
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.*;
import at.pcgamingfreaks.Minepacks.Bukkit.Placeholder.PlaceholderManager;
import at.pcgamingfreaks.Minepacks.Bukkit.SpecialInfoWorker.NoDatabaseWorker;
import at.pcgamingfreaks.Minepacks.MagicValues;
import at.pcgamingfreaks.Plugin.IPlugin;
@ -79,6 +80,7 @@ public class Minepacks extends JavaPlugin implements MinepacksPlugin, IPlugin
private ItemFilter itemFilter = null;
private Sound openSound = null;
private ItemShortcut shortcut = null;
@Getter private PlaceholderManager placeholderManager = null;
public static Minepacks getInstance()
{
@ -230,6 +232,8 @@ private void load()
if(config.getCommandCooldown() > 0) cooldownManager = new CooldownManager(this);
openSound = config.getOpenSound();
placeholderManager = new PlaceholderManager(this);
}
private void unload()
@ -240,6 +244,7 @@ private void unload()
inventoryClearCommand.close();
inventoryClearCommand = null;
}
if (placeholderManager != null) { placeholderManager.close(); placeholderManager = null; }
if(collector != null) collector.close();
if(commandManager != null) commandManager.close();
if(collector != null) collector.cancel();
@ -408,7 +413,8 @@ public boolean isBackpackItem(final @Nullable ItemStack itemStack)
return shortcut.isItemShortcut(itemStack);
}
public ItemsCollector getItemsCollector() {
public ItemsCollector getItemsCollector()
{
return collector;
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 2023 GeorgH93
*
* 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
* (at your option) 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 <http://www.gnu.org/licenses/>.
*/
package at.pcgamingfreaks.Minepacks.Bukkit.Placeholder;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
import at.pcgamingfreaks.Minepacks.Bukkit.Placeholder.Replacer.AutoPickupEnabled;
public final class PlaceholderManager extends at.pcgamingfreaks.Bukkit.Placeholder.PlaceholderManager
{
public PlaceholderManager(Minepacks plugin)
{
super(plugin);
}
@Override
protected void generatePlaceholdersMap()
{
Minepacks plugin = (Minepacks) getPlugin();
registerPlaceholder(new AutoPickupEnabled(plugin));
}
}

View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2023 GeorgH93
*
* 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
* (at your option) 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 <http://www.gnu.org/licenses/>.
*/
package at.pcgamingfreaks.Minepacks.Bukkit.Placeholder.Replacer;
import at.pcgamingfreaks.Bukkit.Placeholder.PlaceholderName;
import at.pcgamingfreaks.Bukkit.Placeholder.PlaceholderReplacerBase;
import at.pcgamingfreaks.Minepacks.Bukkit.ItemsCollector;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
@PlaceholderName(aliases = "IsAutoPickupEnabled")
public class AutoPickupEnabled extends PlaceholderReplacerBase
{
private final Minepacks plugin;
public AutoPickupEnabled(Minepacks mp)
{
this.plugin = mp;
}
@Override
public @Nullable String replace(OfflinePlayer player)
{
ItemsCollector collector = plugin.getItemsCollector();
if (collector != null)
{
if (player instanceof Player)
{
return collector.canUseAutoPickup((Player) player) ? "true" : "false";
}
return "offline";
}
return "disabled";
}
}

View File

@ -7,13 +7,13 @@
<packaging>pom</packaging>
<properties>
<revision>2.4.21.1</revision>
<revision>2.4.22-SNAPSHOT</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<configFileVersion>34</configFileVersion>
<languageFileVersion>20</languageFileVersion>
<pcgfPluginLibVersion>1.0.39-SNAPSHOT</pcgfPluginLibVersion>
<pcgfPluginLibVersion>1.0.39.1-SNAPSHOT</pcgfPluginLibVersion>
<bukkitVersion>1.15.2-R0.1-SNAPSHOT</bukkitVersion>
<mavenShade.version>3.4.1</mavenShade.version>
@ -37,7 +37,7 @@
</ciManagement>
<name>Minepacks-Parent</name>
<description>Minepacks is a backpack plugin with different backpack sizes, multi language support and SQLite and MySQL storage support.</description>
<description>Minepacks is a backpack plugin with different backpack sizes, multi-language support and SQLite and MySQL storage support.</description>
<url>https://www.spigotmc.org/resources/19286/</url>
<inceptionYear>2014</inceptionYear>
<licenses>