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;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Material;
|
2020-01-04 23:35:41 +00:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.Chest;
|
|
|
|
import org.bukkit.block.ShulkerBox;
|
2020-01-02 04:37:20 +00:00
|
|
|
import org.bukkit.block.Skull;
|
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;
|
2020-01-03 00:58:52 +00:00
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
2020-01-02 04:37:20 +00:00
|
|
|
import org.bukkit.inventory.meta.SkullMeta;
|
2015-11-15 23:32:04 +00:00
|
|
|
|
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:
|
|
|
|
{
|
2019-12-10 00:59:17 +00:00
|
|
|
if (!ConfigEntry.ALLOW_STRUCTURE_BLOCKS.getBoolean())
|
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Structure blocks are disabled.");
|
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2016-06-24 23:24:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-07-17 19:35:36 +00:00
|
|
|
case JIGSAW:
|
|
|
|
{
|
2019-12-10 00:59:17 +00:00
|
|
|
if (!ConfigEntry.ALLOW_JIGSAWS.getBoolean())
|
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Jigsaws are disabled.");
|
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2019-07-17 19:35:36 +00:00
|
|
|
break;
|
2019-07-31 16:46:47 +00:00
|
|
|
}
|
2019-08-27 23:25:50 +00:00
|
|
|
case GRINDSTONE:
|
|
|
|
{
|
2019-12-10 00:59:17 +00:00
|
|
|
if (!ConfigEntry.ALLOW_GRINDSTONES.getBoolean())
|
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Grindstones are disabled.");
|
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2019-08-27 23:25:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-11-17 03:28:10 +00:00
|
|
|
case JUKEBOX:
|
|
|
|
{
|
2019-12-10 00:59:17 +00:00
|
|
|
if (!ConfigEntry.ALLOW_JUKEBOXES.getBoolean())
|
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Jukeboxes are disabled.");
|
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2019-11-17 03:28:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-11-03 21:40:05 +00:00
|
|
|
case SPAWNER:
|
2019-11-26 04:08:13 +00:00
|
|
|
{
|
2019-12-10 00:59:17 +00:00
|
|
|
if (!ConfigEntry.ALLOW_SPAWNERS.getBoolean())
|
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Spawners are disabled.");
|
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2019-11-03 21:40:05 +00:00
|
|
|
break;
|
2019-11-26 04:08:13 +00:00
|
|
|
}
|
2020-01-02 04:37:20 +00:00
|
|
|
case PLAYER_HEAD:
|
|
|
|
case PLAYER_WALL_HEAD:
|
|
|
|
{
|
2020-01-02 23:26:51 +00:00
|
|
|
Skull skull = (Skull) event.getBlockPlaced().getState();
|
2020-01-03 00:58:52 +00:00
|
|
|
if (skull.hasOwner())
|
2020-01-02 04:37:20 +00:00
|
|
|
{
|
2020-01-03 00:58:52 +00:00
|
|
|
if (skull.getOwner().contains("§"))
|
2020-01-02 04:37:20 +00:00
|
|
|
{
|
2020-01-03 00:58:52 +00:00
|
|
|
skull.setOwner(skull.getOwner().replace("§", ""));
|
|
|
|
SkullMeta meta = (SkullMeta) event.getItemInHand().getItemMeta();
|
|
|
|
if (meta != null)
|
|
|
|
{
|
|
|
|
ItemStack newHead = new ItemStack(Material.PLAYER_HEAD, 1);
|
|
|
|
ItemMeta headMeta = newHead.getItemMeta();
|
|
|
|
headMeta.setDisplayName(ChatColor.YELLOW + "C-sectioned Head");
|
|
|
|
newHead.setItemMeta(headMeta);
|
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), newHead);
|
|
|
|
player.sendMessage(ChatColor.GRAY + "The player head you are attempting to place has a section symbol. Your player head has been C-sectioned.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2020-01-04 06:16:54 +00:00
|
|
|
if (skull.getOwner().length() > 100)
|
2020-01-03 00:58:52 +00:00
|
|
|
{
|
2020-01-04 06:16:54 +00:00
|
|
|
player.sendMessage(ChatColor.GRAY + "Instead of using Pi to crash players, be useful with your life and use it to discover things.");
|
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
|
|
|
event.setCancelled(true);
|
2020-01-02 04:37:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
2019-11-03 21:43:29 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
}
|