mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-01-03 18:47:43 +01:00
Add an item filter
Change listener class structure Rename some methods
This commit is contained in:
parent
77e152077b
commit
f8dd837012
@ -113,6 +113,12 @@ Shulkerboxes:
|
|||||||
# Every existing shulker-box will be destroyed when a player tries to interact with it. The content will be dropped to the ground.
|
# Every existing shulker-box will be destroyed when a player tries to interact with it. The content will be dropped to the ground.
|
||||||
Destroy: false
|
Destroy: false
|
||||||
|
|
||||||
|
ItemFilter:
|
||||||
|
# Enables the item filter. Make sure to define items to be filtered.
|
||||||
|
Enable: false
|
||||||
|
# List off items not allowed in the backpack. Can be name or id.
|
||||||
|
Blacklist: []
|
||||||
|
|
||||||
# Enables/Disables the auto-update function of the plugin.
|
# Enables/Disables the auto-update function of the plugin.
|
||||||
auto-update: true
|
auto-update: true
|
||||||
|
|
||||||
@ -120,4 +126,4 @@ auto-update: true
|
|||||||
DisableV2Info: false
|
DisableV2Info: false
|
||||||
|
|
||||||
# Config file version. Don't touch it!
|
# Config file version. Don't touch it!
|
||||||
Version: 13
|
Version: 14
|
@ -21,16 +21,14 @@
|
|||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class Config extends Configuration
|
public class Config extends Configuration
|
||||||
{
|
{
|
||||||
private static final int CONFIG_VERSION = 13;
|
private static final int CONFIG_VERSION = 14;
|
||||||
|
|
||||||
public Config(JavaPlugin plugin)
|
public Config(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
@ -255,25 +253,44 @@ public double getFullInvRadius()
|
|||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region Shulkerboxes
|
//region Shulkerboxes
|
||||||
public boolean getShulkerboxesPreventInBackpack()
|
public boolean isShulkerboxesPreventInBackpackEnabled()
|
||||||
{
|
{
|
||||||
return config.getBoolean("Shulkerboxes.PreventInBackpack", true);
|
return config.getBoolean("Shulkerboxes.PreventInBackpack", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getShulkerboxesDisableShulkerboxes()
|
public boolean isShulkerboxesDisable()
|
||||||
{
|
{
|
||||||
return config.getBoolean("Shulkerboxes.DisableShulkerboxes", false);
|
return config.getBoolean("Shulkerboxes.DisableShulkerboxes", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getShulkerboxesExistingRemove()
|
public boolean isShulkerboxesExistingRemoveEnabled()
|
||||||
{
|
{
|
||||||
return config.getBoolean("Shulkerboxes.Existing.Remove", true);
|
return config.getBoolean("Shulkerboxes.Existing.Remove", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getShulkerboxesExistingDestroy()
|
public boolean isShulkerboxesExistingDestroyEnabled()
|
||||||
{
|
{
|
||||||
return config.getBoolean("Shulkerboxes.Existing.Destroy", true);
|
return config.getBoolean("Shulkerboxes.Existing.Destroy", true);
|
||||||
}
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
//region Item filter
|
||||||
|
public boolean isItemFilterEnabled()
|
||||||
|
{
|
||||||
|
return config.getBoolean("ItemFilter.Enable", false) || config.getBoolean("Shulkerboxes.PreventInBackpack", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<Material> getItemFilterBlacklist()
|
||||||
|
{
|
||||||
|
List<String> stringBlacklist = config.getStringList("ItemFilter.Blacklist", new LinkedList<String>());
|
||||||
|
Collection<Material> blacklist = new LinkedList<>();
|
||||||
|
for(String item : stringBlacklist)
|
||||||
|
{
|
||||||
|
Material mat = Material.matchMaterial(item);
|
||||||
|
if(mat != null) blacklist.add(mat);
|
||||||
|
}
|
||||||
|
return blacklist;
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
//endregion
|
//endregion
|
||||||
}
|
}
|
@ -30,11 +30,35 @@
|
|||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class DisableShulkerboxes extends ShulkerboxesListener implements Listener
|
//TODO remove shulkerboxes
|
||||||
|
public class DisableShulkerboxes extends MinepacksListener
|
||||||
{
|
{
|
||||||
//TODO remove shulkerboxes
|
protected static final Collection<Material> SHULKER_BOX_MATERIALS = new HashSet<>();
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.BLACK_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.BLUE_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.SILVER_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.BROWN_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.CYAN_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.GREEN_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.GRAY_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.LIGHT_BLUE_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.LIME_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.MAGENTA_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.ORANGE_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.PINK_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.PURPLE_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.RED_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.WHITE_SHULKER_BOX);
|
||||||
|
SHULKER_BOX_MATERIALS.add(Material.YELLOW_SHULKER_BOX);
|
||||||
|
}
|
||||||
|
|
||||||
public DisableShulkerboxes(final Minepacks plugin)
|
public DisableShulkerboxes(final Minepacks plugin)
|
||||||
{
|
{
|
||||||
super(plugin);
|
super(plugin);
|
||||||
|
@ -23,18 +23,15 @@
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class DropOnDeath implements Listener
|
public class DropOnDeath extends MinepacksListener
|
||||||
{
|
{
|
||||||
private final Minepacks plugin;
|
|
||||||
|
|
||||||
public DropOnDeath(Minepacks plugin)
|
public DropOnDeath(Minepacks plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -26,19 +26,17 @@
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
public class EventListener implements Listener
|
public class EventListener extends MinepacksListener
|
||||||
{
|
{
|
||||||
private final Minepacks plugin;
|
|
||||||
private final Message messageOwnBackpackClose, messageOtherBackpackClose;
|
private final Message messageOwnBackpackClose, messageOtherBackpackClose;
|
||||||
|
|
||||||
public EventListener(Minepacks mp)
|
public EventListener(Minepacks plugin)
|
||||||
{
|
{
|
||||||
plugin = mp;
|
super(plugin);
|
||||||
messageOwnBackpackClose = plugin.lang.getMessage("Ingame.OwnBackpackClose");
|
messageOwnBackpackClose = plugin.lang.getMessage("Ingame.OwnBackpackClose");
|
||||||
messageOtherBackpackClose = plugin.lang.getMessage("Ingame.PlayerBackpackClose").replaceAll("\\{OwnerName\\}", "%1\\$s").replaceAll("\\{OwnerDisplayName\\}", "%2\\$s");
|
messageOtherBackpackClose = plugin.lang.getMessage("Ingame.PlayerBackpackClose").replaceAll("\\{OwnerName\\}", "%1\\$s").replaceAll("\\{OwnerDisplayName\\}", "%2\\$s");
|
||||||
}
|
}
|
||||||
|
@ -21,28 +21,39 @@
|
|||||||
import at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack;
|
import at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack;
|
||||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||||
|
|
||||||
public class PreventShulkerboxesInBackpack extends ShulkerboxesListener implements Listener
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class ItemFilter extends MinepacksListener
|
||||||
{
|
{
|
||||||
private final Message messageNotAllowedInBackpack;
|
private final Message messageNotAllowedInBackpack;
|
||||||
|
private final Collection<Material> blockedMaterials = new HashSet<>();
|
||||||
|
|
||||||
public PreventShulkerboxesInBackpack(final Minepacks plugin)
|
public ItemFilter(final Minepacks plugin)
|
||||||
{
|
{
|
||||||
super(plugin);
|
super(plugin);
|
||||||
messageNotAllowedInBackpack = plugin.lang.getMessage("Ingame.Shulkerboxes.NotAllowedInBackpack");
|
|
||||||
|
if(plugin.getConfiguration().isShulkerboxesPreventInBackpackEnabled())
|
||||||
|
{
|
||||||
|
blockedMaterials.addAll(DisableShulkerboxes.SHULKER_BOX_MATERIALS);
|
||||||
|
}
|
||||||
|
blockedMaterials.addAll(plugin.getConfiguration().getItemFilterBlacklist());
|
||||||
|
|
||||||
|
messageNotAllowedInBackpack = plugin.lang.getMessage("Ingame.Shulkerboxes.NotAllowedInBackpack"); //TODO change message
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onItemMove(InventoryMoveItemEvent event)
|
public void onItemMove(InventoryMoveItemEvent event)
|
||||||
{
|
{
|
||||||
if(event.getDestination().getHolder() instanceof Backpack && SHULKER_BOX_MATERIALS.contains(event.getItem().getType()))
|
if(event.getDestination().getHolder() instanceof Backpack && blockedMaterials.contains(event.getItem().getType()))
|
||||||
{
|
{
|
||||||
if(event.getSource().getHolder() instanceof Player)
|
if(event.getSource().getHolder() instanceof Player)
|
||||||
{
|
{
|
||||||
@ -55,7 +66,7 @@ public void onItemMove(InventoryMoveItemEvent event)
|
|||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onItemMove(InventoryClickEvent event)
|
public void onItemMove(InventoryClickEvent event)
|
||||||
{
|
{
|
||||||
if(event.getInventory().getHolder() instanceof Backpack && event.getCurrentItem() != null && SHULKER_BOX_MATERIALS.contains(event.getCurrentItem().getType()))
|
if(event.getInventory().getHolder() instanceof Backpack && event.getCurrentItem() != null && blockedMaterials.contains(event.getCurrentItem().getType()))
|
||||||
{
|
{
|
||||||
messageNotAllowedInBackpack.send(event.getView().getPlayer());
|
messageNotAllowedInBackpack.send(event.getView().getPlayer());
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -65,7 +76,7 @@ public void onItemMove(InventoryClickEvent event)
|
|||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onItemMove(InventoryDragEvent event)
|
public void onItemMove(InventoryDragEvent event)
|
||||||
{
|
{
|
||||||
if(event.getInventory().getHolder() instanceof Backpack && event.getOldCursor() != null && SHULKER_BOX_MATERIALS.contains(event.getOldCursor().getType()))
|
if(event.getInventory().getHolder() instanceof Backpack && event.getOldCursor() != null && blockedMaterials.contains(event.getOldCursor().getType()))
|
||||||
{
|
{
|
||||||
messageNotAllowedInBackpack.send(event.getView().getPlayer());
|
messageNotAllowedInBackpack.send(event.getView().getPlayer());
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.Listener;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||||
|
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
abstract class MinepacksListener implements Listener
|
||||||
|
{
|
||||||
|
protected final Minepacks plugin;
|
||||||
|
|
||||||
|
protected MinepacksListener(Minepacks plugin)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
}
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016-2017 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.Listener;
|
|
||||||
|
|
||||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
abstract class ShulkerboxesListener
|
|
||||||
{
|
|
||||||
protected static final Set<Material> SHULKER_BOX_MATERIALS = new HashSet<>();
|
|
||||||
|
|
||||||
protected final Minepacks plugin;
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.BLACK_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.BLUE_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.SILVER_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.BROWN_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.CYAN_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.GREEN_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.GRAY_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.LIGHT_BLUE_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.LIME_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.MAGENTA_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.ORANGE_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.PINK_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.PURPLE_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.RED_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.WHITE_SHULKER_BOX);
|
|
||||||
SHULKER_BOX_MATERIALS.add(Material.YELLOW_SHULKER_BOX);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ShulkerboxesListener(Minepacks plugin)
|
|
||||||
{
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
}
|
|
@ -31,7 +31,7 @@
|
|||||||
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Database;
|
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Database;
|
||||||
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.DropOnDeath;
|
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.DropOnDeath;
|
||||||
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.EventListener;
|
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.EventListener;
|
||||||
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.PreventShulkerboxesInBackpack;
|
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.ItemFilter;
|
||||||
import at.pcgamingfreaks.StringUtils;
|
import at.pcgamingfreaks.StringUtils;
|
||||||
import at.pcgamingfreaks.Version;
|
import at.pcgamingfreaks.Version;
|
||||||
|
|
||||||
@ -102,8 +102,8 @@ public void onEnable()
|
|||||||
PluginManager pluginManager = getServer().getPluginManager();
|
PluginManager pluginManager = getServer().getPluginManager();
|
||||||
pluginManager.registerEvents(new EventListener(this), this);
|
pluginManager.registerEvents(new EventListener(this), this);
|
||||||
if(config.getDropOnDeath()) pluginManager.registerEvents(new DropOnDeath(this), this);
|
if(config.getDropOnDeath()) pluginManager.registerEvents(new DropOnDeath(this), this);
|
||||||
if(config.getShulkerboxesPreventInBackpack()) pluginManager.registerEvents(new PreventShulkerboxesInBackpack(this), this);
|
if(config.isItemFilterEnabled()) pluginManager.registerEvents(new ItemFilter(this), this);
|
||||||
if(config.getShulkerboxesDisableShulkerboxes()) pluginManager.registerEvents(new DisableShulkerboxes(this), this);
|
if(config.isShulkerboxesDisable()) pluginManager.registerEvents(new DisableShulkerboxes(this), this);
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
if(config.getFullInvCollect())
|
if(config.getFullInvCollect())
|
||||||
|
Loading…
Reference in New Issue
Block a user