mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-01-07 19:28:11 +01:00
Fix bug where the auto-pickup feature bypassed the item filter
Fixes #48
This commit is contained in:
parent
6d07050346
commit
6c93d1adf7
6
pom.xml
6
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>at.pcgamingfreaks</groupId>
|
||||
<artifactId>Minepacks</artifactId>
|
||||
<version>2.0.11-RC2</version>
|
||||
<version>2.0.11</version>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:GeorgH93/Minepacks.git</connection>
|
||||
@ -55,7 +55,7 @@
|
||||
<dependency>
|
||||
<groupId>at.pcgamingfreaks</groupId>
|
||||
<artifactId>Minepacks-API</artifactId>
|
||||
<version>2.0</version>
|
||||
<version>2.0.11</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
@ -78,7 +78,7 @@
|
||||
<dependency>
|
||||
<groupId>at.pcgamingfreaks</groupId>
|
||||
<artifactId>PluginLib</artifactId>
|
||||
<version>1.0.16-SNAPSHOT</version>
|
||||
<version>1.0.17-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- BadRabbit -->
|
||||
<dependency>
|
||||
|
@ -18,6 +18,7 @@
|
||||
package at.pcgamingfreaks.Minepacks.Bukkit;
|
||||
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.WorldBlacklistMode;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.ItemFilter;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -35,12 +36,14 @@ public class ItemsCollector extends BukkitRunnable
|
||||
private final Minepacks plugin;
|
||||
private final double radius;
|
||||
private final BukkitTask task;
|
||||
private final ItemFilter itemFilter;
|
||||
|
||||
public ItemsCollector(Minepacks plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.radius = plugin.getConfiguration().getFullInvRadius();
|
||||
task = runTaskTimer(plugin, plugin.getConfiguration().getFullInvCheckInterval(), plugin.getConfiguration().getFullInvCheckInterval());
|
||||
itemFilter = plugin.getItemFilter();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,6 +68,7 @@ public void run()
|
||||
Item item = (Item) entity;
|
||||
if(!item.isDead() && item.getPickupDelay() <= 0)
|
||||
{
|
||||
if(itemFilter != null && itemFilter.isItemBlocked(item.getItemStack())) continue;
|
||||
HashMap<Integer, ItemStack> full = backpack.getInventory().addItem(item.getItemStack());
|
||||
backpack.setChanged();
|
||||
if(!full.isEmpty())
|
||||
|
@ -36,7 +36,7 @@
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ItemFilter extends MinepacksListener
|
||||
public class ItemFilter extends MinepacksListener implements at.pcgamingfreaks.Minepacks.Bukkit.API.ItemFilter
|
||||
{
|
||||
private final Message messageNotAllowedInBackpack;
|
||||
private final Collection<MinecraftMaterial> blockedMaterials = new HashSet<>();
|
||||
@ -81,7 +81,7 @@ public ItemFilter(final Minepacks plugin)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onItemMove(InventoryMoveItemEvent event)
|
||||
{
|
||||
if(event.getDestination().getHolder() instanceof Backpack && blockedMaterials.contains(new MinecraftMaterial(event.getItem())))
|
||||
if(event.getDestination().getHolder() instanceof Backpack && isItemBlocked(event.getItem()))
|
||||
{
|
||||
if(event.getSource().getHolder() instanceof Player)
|
||||
{
|
||||
@ -99,9 +99,9 @@ public void onItemMove(InventoryClickEvent event)
|
||||
if(event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD && event.getHotbarButton() != -1)
|
||||
{
|
||||
ItemStack item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
|
||||
if(item != null && blockedMaterials.contains(new MinecraftMaterial(item))) event.setCancelled(true);
|
||||
if(item != null && isItemBlocked(item)) event.setCancelled(true);
|
||||
}
|
||||
else if(event.getCurrentItem() != null && blockedMaterials.contains(new MinecraftMaterial(event.getCurrentItem())))
|
||||
else if(event.getCurrentItem() != null && isItemBlocked(event.getCurrentItem()))
|
||||
{
|
||||
if(event.getClickedInventory() != null && event.getClickedInventory().getHolder() instanceof Backpack) return; // Allow user to move blacklisted items out of the backpack
|
||||
|
||||
@ -114,10 +114,16 @@ else if(event.getCurrentItem() != null && blockedMaterials.contains(new Minecraf
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onItemMove(InventoryDragEvent event)
|
||||
{
|
||||
if(event.getInventory().getHolder() instanceof Backpack && event.getOldCursor() != null && blockedMaterials.contains(new MinecraftMaterial(event.getOldCursor())))
|
||||
if(event.getInventory().getHolder() instanceof Backpack && event.getOldCursor() != null && isItemBlocked(event.getOldCursor()))
|
||||
{
|
||||
messageNotAllowedInBackpack.send(event.getView().getPlayer(), itemNameResolver.getName(event.getOldCursor()));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemBlocked(ItemStack item)
|
||||
{
|
||||
return blockedMaterials.contains(new MinecraftMaterial(item));
|
||||
}
|
||||
}
|
@ -75,6 +75,7 @@ public class Minepacks extends JavaPlugin implements MinepacksPlugin
|
||||
private CommandManager commandManager;
|
||||
private Collection<GameMode> gameModes;
|
||||
private CooldownManager cooldownManager = null;
|
||||
private ItemFilter itemFilter = null;
|
||||
|
||||
public static Minepacks getInstance()
|
||||
{
|
||||
@ -188,7 +189,11 @@ private void load()
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new BackpackEventListener(this), this);
|
||||
if(config.getDropOnDeath()) pluginManager.registerEvents(new DropOnDeath(this), this);
|
||||
if(config.isItemFilterEnabled()) pluginManager.registerEvents(new ItemFilter(this), this);
|
||||
if(config.isItemFilterEnabled())
|
||||
{
|
||||
itemFilter = new ItemFilter(this);
|
||||
pluginManager.registerEvents(itemFilter, this);
|
||||
}
|
||||
if(config.isShulkerboxesDisable()) pluginManager.registerEvents(new DisableShulkerboxes(this), this);
|
||||
//endregion
|
||||
if(config.getFullInvCollect()) collector = new ItemsCollector(this);
|
||||
@ -209,6 +214,7 @@ private void unload()
|
||||
if(cooldownManager != null) cooldownManager.close();
|
||||
cooldownManager = null;
|
||||
getServer().getScheduler().cancelTasks(this); // Kill all running task
|
||||
itemFilter = null;
|
||||
}
|
||||
|
||||
public void reload()
|
||||
@ -347,4 +353,10 @@ public boolean isPlayerGameModeAllowed(Player player)
|
||||
{
|
||||
return cooldownManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ItemFilter getItemFilter()
|
||||
{
|
||||
return itemFilter;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user