2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.blocking;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2019-01-28 01:49:07 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.Groups;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Material;
|
2018-08-17 00:20:50 +00:00
|
|
|
import org.bukkit.block.Block;
|
2018-12-29 19:41:48 +00:00
|
|
|
import org.bukkit.block.Dispenser;
|
2018-08-17 00:20:50 +00:00
|
|
|
import org.bukkit.block.ShulkerBox;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.block.BlockPlaceEvent;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class BlockBlocker extends FreedomService
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public BlockBlocker(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
|
|
|
public void onBlockPlace(BlockPlaceEvent event)
|
|
|
|
{
|
|
|
|
final Player player = event.getPlayer();
|
|
|
|
|
|
|
|
switch (event.getBlockPlaced().getType())
|
|
|
|
{
|
|
|
|
case LAVA:
|
|
|
|
{
|
|
|
|
if (ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
|
|
|
|
{
|
|
|
|
FLog.info(String.format("%s placed lava @ %s", player.getName(), FUtil.formatLocation(event.getBlock().getLocation())));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Lava placement is currently disabled.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WATER:
|
|
|
|
{
|
|
|
|
if (ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
|
|
|
|
{
|
|
|
|
FLog.info(String.format("%s placed water @ %s", player.getName(), FUtil.formatLocation(event.getBlock().getLocation())));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Water placement is currently disabled.");
|
|
|
|
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FIRE:
|
|
|
|
{
|
|
|
|
if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
|
|
|
|
{
|
|
|
|
FLog.info(String.format("%s placed fire @ %s", player.getName(), FUtil.formatLocation(event.getBlock().getLocation())));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Fire placement is currently disabled.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TNT:
|
|
|
|
{
|
|
|
|
if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
|
|
|
{
|
|
|
|
FLog.info(String.format("%s placed TNT @ %s", player.getName(), FUtil.formatLocation(event.getBlock().getLocation())));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-06-24 23:24:56 +00:00
|
|
|
case STRUCTURE_BLOCK:
|
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Structure blocks are disabled.");
|
2017-10-13 18:35:11 +00:00
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
2016-06-24 23:24:56 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
break;
|
|
|
|
}
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-17 00:20:50 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
|
|
|
public void onShulkerBoxPlace(BlockPlaceEvent event)
|
|
|
|
{
|
|
|
|
Block block = event.getBlock();
|
2019-01-28 01:49:07 +00:00
|
|
|
if (Groups.SHULKER_BOXES.contains(event.getBlock().getType()))
|
2018-08-17 00:20:50 +00:00
|
|
|
{
|
|
|
|
ShulkerBox shulkerBox = (ShulkerBox)block.getState();
|
|
|
|
boolean empty = true;
|
|
|
|
for (ItemStack itemStack : shulkerBox.getInventory().getContents())
|
|
|
|
{
|
|
|
|
if (itemStack != null)
|
|
|
|
{
|
|
|
|
empty = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty)
|
|
|
|
{
|
|
|
|
shulkerBox.getInventory().clear();
|
|
|
|
event.getPlayer().sendMessage(ChatColor.RED + "For security reasons, your shulker box has been emptied.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-29 19:41:48 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
|
|
|
public void onDispenserPlace(BlockPlaceEvent event)
|
|
|
|
{
|
|
|
|
Block block = event.getBlock();
|
|
|
|
if (block.getType().equals(Material.DISPENSER))
|
|
|
|
{
|
|
|
|
Dispenser dispenser = (Dispenser)block.getState();
|
|
|
|
boolean empty = true;
|
|
|
|
for (ItemStack itemStack : dispenser.getInventory().getContents())
|
|
|
|
{
|
|
|
|
if (itemStack != null)
|
|
|
|
{
|
|
|
|
empty = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty)
|
|
|
|
{
|
|
|
|
dispenser.getInventory().clear();
|
|
|
|
event.getPlayer().sendMessage(ChatColor.RED + "For security reasons, dispenser has been emptied.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|