2017-12-27 22:50:39 -07:00
|
|
|
package me.totalfreedom.totalfreedommod.blocking;
|
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
2020-11-02 23:33:04 -06:00
|
|
|
import net.minecraft.server.v1_16_R3.NBTTagCompound;
|
2017-12-27 22:50:39 -07:00
|
|
|
import org.bukkit.ChatColor;
|
2019-07-17 12:35:36 -07:00
|
|
|
import org.bukkit.Tag;
|
2020-11-02 23:33:04 -06:00
|
|
|
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
2017-12-27 22:50:39 -07:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.block.Action;
|
|
|
|
import org.bukkit.event.block.BlockPlaceEvent;
|
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2019-11-18 18:00:54 -05:00
|
|
|
//codebeat:disable[LOC,ABC]
|
|
|
|
|
2017-12-27 22:50:39 -07:00
|
|
|
public class SignBlocker extends FreedomService
|
|
|
|
{
|
|
|
|
@Override
|
2020-06-30 21:51:06 -04:00
|
|
|
public void onStart()
|
2017-12-27 22:50:39 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-06-30 21:51:06 -04:00
|
|
|
public void onStop()
|
2017-12-27 22:50:39 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
|
|
|
public void onPlayerPlaceBlock(BlockPlaceEvent event)
|
|
|
|
{
|
|
|
|
|
|
|
|
final Player player = event.getPlayer();
|
2019-11-06 21:29:04 -05:00
|
|
|
if (Tag.SIGNS.getValues().contains(event.getBlock().getType()))
|
2017-12-27 22:50:39 -07:00
|
|
|
{
|
|
|
|
ItemStack sign = event.getItemInHand();
|
2020-11-02 23:33:04 -06:00
|
|
|
net.minecraft.server.v1_16_R3.ItemStack nmsSign = CraftItemStack.asNMSCopy(sign);
|
2017-12-27 22:50:39 -07:00
|
|
|
NBTTagCompound compound = (nmsSign.hasTag()) ? nmsSign.getTag() : new NBTTagCompound();
|
2020-12-25 14:46:43 -05:00
|
|
|
assert compound != null;
|
2017-12-27 22:50:39 -07:00
|
|
|
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-12-31 20:43:10 -07:00
|
|
|
if (line1.contains("run_command") || line2.contains("run_command") || line3.contains("run_command") || line4.contains("run_command"))
|
2017-12-27 22:50:39 -07:00
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.GRAY + "You are not allowed to place command signs.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-31 20:43:10 -07:00
|
|
|
|
2017-12-27 22:50:39 -07:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
|
|
|
public void onPlayerInteractSign(PlayerInteractEvent event)
|
|
|
|
{
|
2017-12-31 20:43:10 -07:00
|
|
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-12-27 22:50:39 -07:00
|
|
|
|
2019-07-17 12:35:36 -07:00
|
|
|
if (event.getClickedBlock() != null && Tag.SIGNS.getValues().contains(event.getClickedBlock().getType()))
|
2017-12-27 22:50:39 -07:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2020-12-03 19:28:53 -05:00
|
|
|
}
|