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.config.ConfigEntry;
|
2019-08-07 07:31:05 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.Groups;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Material;
|
2022-06-04 13:59:35 +00:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.EntityType;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
2020-07-28 20:24:41 +00:00
|
|
|
import org.bukkit.event.player.PlayerBedEnterEvent;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class InteractBlocker extends FreedomService
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
|
|
|
public void onPlayerInteract(PlayerInteractEvent event)
|
|
|
|
{
|
|
|
|
switch (event.getAction())
|
|
|
|
{
|
|
|
|
case RIGHT_CLICK_AIR:
|
|
|
|
case RIGHT_CLICK_BLOCK:
|
|
|
|
{
|
|
|
|
handleRightClick(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-06-17 02:36:29 +00:00
|
|
|
default:
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2021-06-17 02:36:29 +00:00
|
|
|
// Do nothing
|
2015-11-15 23:32:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 04:35:41 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
|
|
|
public void onRightClickBell(PlayerInteractEvent event)
|
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
if (event.getClickedBlock() != null && event.getClickedBlock().getType().equals(Material.BELL) && !ConfigEntry.ALLOW_BELLS.getBoolean())
|
2019-07-31 04:35:41 +00:00
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
event.setCancelled(true);
|
2019-07-31 04:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-28 20:24:41 +00:00
|
|
|
@EventHandler
|
|
|
|
public void onBedEnter(PlayerBedEnterEvent event)
|
|
|
|
{
|
|
|
|
Player player = event.getPlayer();
|
2020-07-28 21:55:38 +00:00
|
|
|
if (Groups.EXPLOSIVE_BED_BIOMES.contains(event.getBed().getBiome()))
|
2020-07-28 20:24:41 +00:00
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.RED + "You may not sleep here.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
private void handleRightClick(PlayerInteractEvent event)
|
|
|
|
{
|
|
|
|
final Player player = event.getPlayer();
|
|
|
|
|
2019-07-17 19:35:36 +00:00
|
|
|
if (event.getClickedBlock() != null)
|
2019-07-11 02:13:57 +00:00
|
|
|
{
|
2020-07-15 08:22:32 +00:00
|
|
|
if (event.getClickedBlock().getType().equals(Material.STRUCTURE_BLOCK) || event.getClickedBlock().getType().equals(Material.JIGSAW) || event.getClickedBlock().getType().equals(Material.RESPAWN_ANCHOR))
|
2019-07-17 19:35:36 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
event.getPlayer().closeInventory();
|
|
|
|
}
|
2019-07-11 02:13:57 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 07:31:05 +00:00
|
|
|
if (Groups.SPAWN_EGGS.contains(event.getMaterial()))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
2022-06-04 13:59:35 +00:00
|
|
|
Block clickedBlock = event.getClickedBlock();
|
|
|
|
if (clickedBlock == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EntityType eggType = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Material mat = event.getMaterial();
|
|
|
|
if (mat == Material.MOOSHROOM_SPAWN_EGG)
|
|
|
|
{
|
|
|
|
eggType = EntityType.MUSHROOM_COW;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eggType = EntityType.valueOf(mat.name().substring(0, mat.name().length() - 10));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException ignored)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
if (eggType != null)
|
|
|
|
{
|
|
|
|
clickedBlock.getWorld().spawnEntity(clickedBlock.getLocation().add(event.getBlockFace().getDirection()).add(0.5, 0.5, 0.5), eggType);
|
|
|
|
}
|
2019-08-07 07:31:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
switch (event.getMaterial())
|
|
|
|
{
|
|
|
|
case WATER_BUCKET:
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
if (plugin.al.isAdmin(player) || ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LAVA_BUCKET:
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
if (plugin.al.isAdmin(player) || ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-07-25 02:08:29 +00:00
|
|
|
case TNT_MINECART:
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
if (ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
|
|
|
player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
break;
|
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
|
2019-08-27 23:25:50 +00:00
|
|
|
case ARMOR_STAND:
|
|
|
|
{
|
|
|
|
if (ConfigEntry.ALLOW_ARMOR_STANDS.getBoolean())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Armor stands are currently disabled.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
break;
|
|
|
|
}
|
2019-11-03 21:40:05 +00:00
|
|
|
case MINECART:
|
|
|
|
{
|
|
|
|
if (ConfigEntry.ALLOW_MINECARTS.getBoolean())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Minecarts are currently disabled.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
break;
|
|
|
|
}
|
2020-04-29 23:29:43 +00:00
|
|
|
case WRITTEN_BOOK:
|
|
|
|
{
|
|
|
|
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
|
|
|
player.sendMessage(ChatColor.GRAY + "Books are currently disabled.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
break;
|
|
|
|
}
|
2021-06-17 02:36:29 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
break;
|
|
|
|
}
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|