TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/SignPatch.java

69 lines
2.5 KiB
Java
Raw Normal View History

2017-10-21 17:27:43 +00:00
package me.totalfreedom.totalfreedommod;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
import org.bukkit.ChatColor;
import org.bukkit.Material;
2017-10-29 14:45:38 +00:00
import org.bukkit.craftbukkit.v1_12_R1.block.CraftBlock;
2017-10-21 17:27:43 +00:00
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
2017-10-29 14:45:38 +00:00
import org.bukkit.event.block.Action;
2017-10-21 17:27:43 +00:00
import org.bukkit.event.block.BlockPlaceEvent;
2017-10-29 14:45:38 +00:00
import org.bukkit.event.player.PlayerInteractEvent;
2017-10-21 17:27:43 +00:00
import org.bukkit.inventory.ItemStack;
public class SignPatch extends FreedomService
{
public SignPatch(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayePlaceBlock(BlockPlaceEvent event)
{
final Player player = event.getPlayer();
if (event.getBlock().getType().equals(Material.SIGN) || event.getBlock().getType().equals(Material.SIGN_POST) || event.getBlock().getType().equals(Material.WALL_SIGN))
{
ItemStack sign = event.getItemInHand();
net.minecraft.server.v1_12_R1.ItemStack nmsSign = CraftItemStack.asNMSCopy(sign);
NBTTagCompound compound = (nmsSign.hasTag()) ? nmsSign.getTag() : new NBTTagCompound();
NBTTagCompound bet = compound.getCompound("BlockEntityTag");
String line1 = bet.getString("Text1");
String line2 = bet.getString("Text2");
String line3 = bet.getString("Text3");
String line4 = bet.getString("Text4");
2017-10-21 17:32:15 +00:00
if(line1.contains("run_command") || line2.contains("run_command") || line3.contains("run_command") || line4.contains("run_command"))
2017-10-21 17:27:43 +00:00
{
player.sendMessage(ChatColor.GRAY + "You are not allowed to place command signs.");
event.setCancelled(true);
}
}
}
2017-10-29 14:45:38 +00:00
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteractSign(PlayerInteractEvent event)
{
if(event.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
if (event.getClickedBlock() != null && event.getClickedBlock().getType().equals(Material.SIGN) || event.getClickedBlock().getType().equals(Material.SIGN_POST) || event.getClickedBlock().getType().equals(Material.WALL_SIGN))
{
event.setCancelled(true);
}
}
2017-10-21 17:32:15 +00:00
}