mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-03-12 13:29:46 +01:00
Add some new API methods
This commit is contained in:
parent
e3dbc6b849
commit
daa98edb6d
@ -20,6 +20,7 @@
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -126,4 +127,9 @@ public interface Backpack extends InventoryHolder
|
||||
setChanged();
|
||||
return getInventory().addItem(itemStacks);
|
||||
}
|
||||
|
||||
static boolean isBackpack(@Nullable Inventory inventory)
|
||||
{
|
||||
return inventory instanceof Backpack;
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -134,4 +135,12 @@ public interface MinepacksPlugin
|
||||
* @return The item filter. Null if item filter is disabled
|
||||
*/
|
||||
@Nullable ItemFilter getItemFilter();
|
||||
|
||||
/**
|
||||
* Checks if an item is a backpack shortcut item.
|
||||
*
|
||||
* @param itemStack item to check.
|
||||
* @return
|
||||
*/
|
||||
boolean isBackpackItem(final @Nullable ItemStack itemStack);
|
||||
}
|
@ -31,7 +31,6 @@
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
@ -39,6 +38,7 @@
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -46,19 +46,18 @@
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ItemShortcut implements Listener
|
||||
public class ItemShortcut extends MinepacksListener
|
||||
{
|
||||
private static final UUID MINEPACKS_UUID = UUID.nameUUIDFromBytes("Minepacks".getBytes());
|
||||
private final Minepacks plugin;
|
||||
private final String itemName, value, openCommand;
|
||||
private final Message messageDoNotRemoveItem;
|
||||
private final boolean improveDeathChestCompatibility, blockAsHat, allowRightClickOnContainers, blockItemFromMoving;
|
||||
private final int preferredSlotId;
|
||||
private final Set<Material> containerMaterials = new HashSet<>();
|
||||
|
||||
public ItemShortcut(Minepacks plugin)
|
||||
public ItemShortcut(final @NotNull Minepacks plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
super(plugin);
|
||||
itemName = ChatColor.translateAlternateColorCodes('&', plugin.getConfiguration().getItemShortcutItemName());
|
||||
value = plugin.getConfiguration().getItemShortcutHeadValue();
|
||||
improveDeathChestCompatibility = plugin.getConfiguration().isItemShortcutImproveDeathChestCompatibilityEnabled();
|
||||
@ -84,7 +83,7 @@ public ItemShortcut(Minepacks plugin)
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isItemShortcut(@Nullable ItemStack stack)
|
||||
public boolean isItemShortcut(final @Nullable ItemStack stack)
|
||||
{
|
||||
//noinspection ConstantConditions
|
||||
return stack != null && stack.getType() == HeadUtils.HEAD_MATERIAL && stack.hasItemMeta() && itemName.equals(stack.getItemMeta().getDisplayName());
|
||||
|
@ -44,6 +44,7 @@
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -77,6 +78,7 @@ public class Minepacks extends JavaPlugin implements MinepacksPlugin
|
||||
private CooldownManager cooldownManager = null;
|
||||
private ItemFilter itemFilter = null;
|
||||
private Sound openSound = null;
|
||||
private ItemShortcut shortcut = null;
|
||||
|
||||
public static Minepacks getInstance()
|
||||
{
|
||||
@ -192,7 +194,12 @@ private void load()
|
||||
pluginManager.registerEvents(itemFilter, this);
|
||||
}
|
||||
if(config.isShulkerboxesDisable()) pluginManager.registerEvents(new DisableShulkerboxes(this), this);
|
||||
if(config.isItemShortcutEnabled()) pluginManager.registerEvents(new ItemShortcut(this), this);
|
||||
if(config.isItemShortcutEnabled())
|
||||
{
|
||||
shortcut = new ItemShortcut(this);
|
||||
pluginManager.registerEvents(shortcut, this);
|
||||
}
|
||||
else shortcut = null;
|
||||
if(config.isWorldWhitelistMode()) pluginManager.registerEvents(new WorldBlacklistUpdater(this), this);
|
||||
//endregion
|
||||
if(config.getFullInvCollect()) collector = new ItemsCollector(this);
|
||||
@ -356,7 +363,7 @@ public WorldBlacklistMode isDisabled(Player player)
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerGameModeAllowed(Player player)
|
||||
public boolean isPlayerGameModeAllowed(final @NotNull Player player)
|
||||
{
|
||||
return gameModes.contains(player.getGameMode()) || player.hasPermission(Permissions.IGNORE_GAME_MODE);
|
||||
}
|
||||
@ -371,4 +378,11 @@ public boolean isPlayerGameModeAllowed(Player player)
|
||||
{
|
||||
return itemFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBackpackItem(final @Nullable ItemStack itemStack)
|
||||
{
|
||||
if(shortcut == null) return false;
|
||||
return shortcut.isItemShortcut(itemStack);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user