TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java

187 lines
7.6 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.blocking;
2020-01-12 14:51:29 +00:00
import java.util.List;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
2020-01-12 14:51:29 +00:00
import me.totalfreedom.totalfreedommod.util.Groups;
import org.bukkit.ChatColor;
import org.bukkit.Material;
2020-01-12 14:51:29 +00:00
import org.bukkit.block.Banner;
import org.bukkit.block.Skull;
2020-01-12 14:51:29 +00:00
import org.bukkit.block.banner.Pattern;
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;
import org.bukkit.inventory.meta.SkullMeta;
public class BlockBlocker extends FreedomService
{
@Override
2020-07-01 01:51:06 +00:00
public void onStart()
{
}
@Override
2020-07-01 01:51:06 +00:00
public void onStop()
{
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event)
{
final Player player = event.getPlayer();
switch (event.getBlockPlaced().getType())
{
case LAVA:
{
2020-05-29 10:14:21 +00:00
if (!ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
{
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:
{
2020-05-29 10:14:21 +00:00
if (!ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
{
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:
2020-06-30 07:25:38 +00:00
case SOUL_FIRE:
{
2020-05-29 10:14:21 +00:00
if (!ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
{
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 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);
}
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-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;
}
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);
}
break;
}
2019-11-03 21:40:05 +00:00
case SPAWNER:
{
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;
}
2020-02-09 04:52:43 +00:00
case BEEHIVE:
case BEE_NEST:
{
if (!ConfigEntry.ALLOW_BEEHIVES.getBoolean())
{
2020-05-29 10:14:21 +00:00
player.sendMessage(ChatColor.GRAY + "Beehives are disabled.");
2020-02-09 04:52:43 +00:00
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
event.setCancelled(true);
}
break;
}
case PLAYER_HEAD:
case PLAYER_WALL_HEAD:
{
Skull skull = (Skull) event.getBlockPlaced().getState();
2020-07-03 00:40:08 +00:00
if (skull.getOwner() != null)
{
2020-05-29 10:14:21 +00:00
if (skull.getOwner().contains("\u00A7"))
{
2020-05-29 10:14:21 +00:00
skull.setOwner(skull.getOwner().replace("\u00A7", ""));
2020-01-03 00:58:52 +00:00
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);
}
}
break;
}
2020-07-02 12:13:20 +00:00
case RESPAWN_ANCHOR:
{
if (!ConfigEntry.ALLOW_RESPAWN_ANCHORS.getBoolean())
{
player.sendMessage(ChatColor.GRAY + "Respawn anchors are disabled.");
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
event.setCancelled(true);
}
break;
}
}
2019-11-03 21:43:29 +00:00
2020-01-12 14:51:29 +00:00
if (Groups.BANNERS.contains(event.getBlockPlaced().getType()))
{
Banner banner = (Banner) event.getBlockPlaced().getState();
2020-06-30 07:25:38 +00:00
List<Pattern> patterns = banner.getPatterns();;
2020-01-12 14:51:29 +00:00
if (patterns.size() >= 2)
{
banner.setPatterns(patterns.subList(0, 2));
player.sendMessage(ChatColor.GRAY + "Your banner had too many patterns on it, so some were removed.");
}
}
}
}