Add listener to globally disable specific blocks

This commit is contained in:
Bea 2022-11-11 18:25:22 +01:00
parent 568b719512
commit a33204b7b8
3 changed files with 103 additions and 0 deletions

View File

@ -30,6 +30,12 @@
<version>1.19.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jetbrains/annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
</dependency>
</dependencies>
</project>

View File

@ -3,7 +3,9 @@ package wtf.beatrice.limbomanager;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import wtf.beatrice.limbomanager.listeners.CommandCanceller;
import wtf.beatrice.limbomanager.listeners.PlayerHider;
import wtf.beatrice.limbomanager.listeners.RiskyBlocksHandler;
public class LimboManager extends JavaPlugin {
@ -17,6 +19,8 @@ public class LimboManager extends JavaPlugin {
pluginManager = Bukkit.getServer().getPluginManager();
pluginManager.registerEvents(new PlayerHider(), this);
pluginManager.registerEvents(new CommandCanceller(), this);
pluginManager.registerEvents(new RiskyBlocksHandler(), this);
}

View File

@ -0,0 +1,93 @@
package wtf.beatrice.limbomanager.listeners;
import org.bukkit.Material;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockMultiPlaceEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.inventory.*;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class RiskyBlocksHandler implements Listener
{
List<Material> riskyMaterials = new ArrayList<>()
{{
add(Material.TNT);
add(Material.ANVIL);
add(Material.CHIPPED_ANVIL);
add(Material.DAMAGED_ANVIL);
add(Material.MINECART);
add(Material.CHEST_MINECART);
add(Material.COMMAND_BLOCK_MINECART);
add(Material.HOPPER_MINECART);
add(Material.FURNACE_MINECART);
add(Material.TNT_MINECART);
add(Material.COMMAND_BLOCK);
add(Material.CHAIN_COMMAND_BLOCK);
add(Material.CHAIN_COMMAND_BLOCK);
}};
@EventHandler
public void onBlockPlace(BlockPlaceEvent event)
{
checkAndCancel(event, event.getBlockPlaced().getType());
}
@EventHandler
public void onBlockPlace(BlockMultiPlaceEvent event)
{
checkAndCancel(event, event.getBlockPlaced().getType());
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event)
{
if(event.getCurrentItem() != null)
{
checkAndCancel(event, event.getCurrentItem().getType());
}
if(event.getCursor() != null)
{
checkAndCancel(event, event.getCursor().getType());
}
}
@EventHandler
public void onInventoryDrag(InventoryDragEvent event)
{
if(event.getCursor() != null)
{
checkAndCancel(event, event.getCursor().getType());
}
checkAndCancel(event, event.getOldCursor().getType());
}
@EventHandler
public void onInvMoveItem(InventoryMoveItemEvent event)
{
checkAndCancel(event, event.getItem().getType());
}
@EventHandler
public void onInvPickup(InventoryPickupItemEvent event)
{
checkAndCancel(event, event.getItem().getItemStack().getType());
}
private void checkAndCancel(Cancellable event, @NotNull Material material)
{
if(riskyMaterials.contains(material))
{
event.setCancelled(true);
}
}
}