mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2024-12-01 13:33:24 +01:00
Add option to remove/destroy existing shulkerboxes
This commit is contained in:
parent
d477b2ed76
commit
63b97cc201
8
pom.xml
8
pom.xml
@ -31,7 +31,7 @@
|
||||
</licenses>
|
||||
<properties>
|
||||
<author>GeorgH93</author>
|
||||
<website>http://dev.bukkit.org/bukkit-plugins/minepacks/</website>
|
||||
<website>https://www.spigotmc.org/resources/19286/</website>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
@ -72,6 +72,12 @@
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>./</directory>
|
||||
<includes>
|
||||
<include>LICENSE</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -117,11 +117,8 @@ Shulkerboxes:
|
||||
# This setting allows to disable shulkerboxes all together. Players won't be able to craft or use them.
|
||||
DisableShulkerboxes: false
|
||||
# This settings controls how existing shulkerboxes are handled if they are disabled.
|
||||
Existing:
|
||||
# Every existing shulker-box will be removed when a player tries to interact with it. The content will be lost.
|
||||
Remove: false
|
||||
# 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
|
||||
# Options: Ignore, Remove = shulker-box will be removed including it's content, Destroy = shulker-box will be destroyed and it's content will be dropped
|
||||
Existing: "Ignore"
|
||||
|
||||
ItemFilter:
|
||||
# Enables the item filter. Make sure to define items to be filtered.
|
||||
|
@ -1,7 +1,7 @@
|
||||
Language:
|
||||
NotFromConsole: "&cCommand not usable from console."
|
||||
Ingame:
|
||||
NoPermission: "&cYou don't have the Permission to do that."
|
||||
NoPermission: "&cYou don't have the permission to do that."
|
||||
WorldDisabled: "&cThe use of the backpack is not allowed in this world."
|
||||
OwnBackpackClose: "Backpack closed!"
|
||||
OwnBackpackClose_SendMethod: "action_bar"
|
||||
|
@ -24,6 +24,7 @@ permissions:
|
||||
backpack.noCooldown: true
|
||||
backpack.fullpickup: true
|
||||
backpack.ignoreGameMode: true
|
||||
backpack.ignoreWorldBlacklist: true
|
||||
backpack.disable:
|
||||
description: This permission group can be used to disable the plugin for certian users/groups/worlds.
|
||||
children:
|
||||
|
@ -270,14 +270,14 @@ public boolean isShulkerboxesDisable()
|
||||
return getConfig().getBoolean("Shulkerboxes.DisableShulkerboxes", false);
|
||||
}
|
||||
|
||||
public boolean isShulkerboxesExistingRemoveEnabled()
|
||||
public boolean isShulkerboxesExistingDropEnabled()
|
||||
{
|
||||
return getConfig().getBoolean("Shulkerboxes.Existing.Remove", true);
|
||||
return getConfig().getString("Shulkerboxes.Existing", "Ignore").equalsIgnoreCase("Destroy");
|
||||
}
|
||||
|
||||
public boolean isShulkerboxesExistingDestroyEnabled()
|
||||
{
|
||||
return getConfig().getBoolean("Shulkerboxes.Existing.Destroy", true);
|
||||
return getConfig().getString("Shulkerboxes.Existing", "Ignore").equalsIgnoreCase("Destroy") || getConfig().getString("Shulkerboxes.Existing", "Ignore").equalsIgnoreCase("Remove");
|
||||
}
|
||||
//endregion
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2017 GeorgH93
|
||||
* Copyright (C) 2016-2018 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
|
||||
@ -17,12 +17,14 @@
|
||||
|
||||
package at.pcgamingfreaks.Minepacks.Bukkit.Listener;
|
||||
|
||||
import at.pcgamingfreaks.Bukkit.Utils;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
@ -34,9 +36,8 @@
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
//TODO remove shulkerboxes
|
||||
public class DisableShulkerboxes extends MinepacksListener
|
||||
{
|
||||
{ //TODO handle existing shulkerboxes in inventory
|
||||
protected static final Collection<Material> SHULKER_BOX_MATERIALS = new HashSet<>();
|
||||
|
||||
static
|
||||
@ -59,9 +60,13 @@ public class DisableShulkerboxes extends MinepacksListener
|
||||
SHULKER_BOX_MATERIALS.add(Material.YELLOW_SHULKER_BOX);
|
||||
}
|
||||
|
||||
private boolean removeExisting, dropExistingContent;
|
||||
|
||||
public DisableShulkerboxes(final Minepacks plugin)
|
||||
{
|
||||
super(plugin);
|
||||
removeExisting = plugin.config.isShulkerboxesExistingDestroyEnabled();
|
||||
dropExistingContent = plugin.config.isShulkerboxesExistingDropEnabled();
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@ -87,6 +92,19 @@ public void onInventoryOpen(InventoryOpenEvent event)
|
||||
{
|
||||
if(event.getInventory() != null && event.getInventory().getHolder() != null && event.getInventory().getHolder().getClass().getName().toLowerCase().contains("shulker"))
|
||||
{
|
||||
if(removeExisting)
|
||||
{
|
||||
Block shulkerBlock = ((ShulkerBox) event.getInventory().getHolder()).getBlock();
|
||||
if(shulkerBlock != null)
|
||||
{
|
||||
if(dropExistingContent)
|
||||
{
|
||||
Utils.dropInventory(event.getInventory(), shulkerBlock.getLocation());
|
||||
}
|
||||
event.getInventory().clear();
|
||||
shulkerBlock.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -136,6 +154,17 @@ public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
if(SHULKER_BOX_MATERIALS.contains(event.getBlockPlaced().getType()))
|
||||
{
|
||||
event.getItemInHand().setType(Material.AIR);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockMultiPlace(BlockMultiPlaceEvent event)
|
||||
{
|
||||
if(SHULKER_BOX_MATERIALS.contains(event.getBlock().getType()))
|
||||
{
|
||||
event.getItemInHand().setType(Material.AIR);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -143,10 +172,32 @@ public void onBlockPlace(BlockPlaceEvent event)
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
if(SHULKER_BOX_MATERIALS.contains(event.getBlock().getType()))
|
||||
if(handleShulkerBlock(event.getBlock())) event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockDamage(BlockDamageEvent event)
|
||||
{
|
||||
if(handleShulkerBlock(event.getBlock())) event.setCancelled(true);
|
||||
}
|
||||
|
||||
private boolean handleShulkerBlock(Block block)
|
||||
{
|
||||
if(SHULKER_BOX_MATERIALS.contains(block.getType()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
if(removeExisting)
|
||||
{
|
||||
ShulkerBox shulkerBox = (ShulkerBox) block.getState();
|
||||
if(shulkerBox != null)
|
||||
{
|
||||
if(dropExistingContent) Utils.dropInventory(shulkerBox.getInventory(), shulkerBox.getLocation());
|
||||
shulkerBox.getInventory().clear();
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@ -176,15 +227,6 @@ public void onBlockDispense(BlockDispenseEvent event)
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockMultiPlaceEvent event)
|
||||
{
|
||||
if(SHULKER_BOX_MATERIALS.contains(event.getBlock().getType()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPrepareItemCraftEvent(PrepareItemCraftEvent event)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user