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

122 lines
3.5 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.blocking;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
2019-07-11 02:13:57 +00:00
import me.totalfreedom.totalfreedommod.util.FLog;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
public class InteractBlocker extends FreedomService
{
public InteractBlocker(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event)
{
switch (event.getAction())
{
case RIGHT_CLICK_AIR:
case RIGHT_CLICK_BLOCK:
{
handleRightClick(event);
break;
}
case LEFT_CLICK_AIR:
case LEFT_CLICK_BLOCK:
{
//
break;
}
}
}
2019-07-31 04:35:41 +00:00
@EventHandler(priority = EventPriority.HIGH)
public void onRightClickBell(PlayerInteractEvent event)
{
if (event.getClickedBlock().getType().equals(Material.BELL))
{
if (!ConfigEntry.ALLOW_BELLS.getBoolean())
{
event.setCancelled(true);
}
}
}
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
{
2019-07-17 19:35:36 +00:00
if (event.getClickedBlock().getType().equals(Material.STRUCTURE_BLOCK) || event.getClickedBlock().getType().equals(Material.JIGSAW))
{
event.setCancelled(true);
event.getPlayer().closeInventory();
}
2019-07-11 02:13:57 +00:00
}
switch (event.getMaterial())
{
case WATER_BUCKET:
{
if (plugin.al.isAdmin(player) || ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
{
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:
{
if (plugin.al.isAdmin(player) || ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
{
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:
{
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;
}
}
}
}