2017-12-28 05:50:39 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.blocking;
|
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
2019-12-14 20:39:57 +00:00
|
|
|
import net.minecraft.server.v1_15_R1.NBTTagCompound;
|
2017-12-28 05:50:39 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Material;
|
2019-07-17 19:35:36 +00:00
|
|
|
import org.bukkit.Tag;
|
2019-12-14 20:39:57 +00:00
|
|
|
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
2017-12-28 05:50:39 +00: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 23:00:54 +00:00
|
|
|
//codebeat:disable[LOC,ABC]
|
|
|
|
|
2017-12-28 05:50:39 +00:00
|
|
|
public class SignBlocker extends FreedomService
|
|
|
|
{
|
|
|
|
|
|
|
|
public SignBlocker(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
|
|
|
public void onPlayerPlaceBlock(BlockPlaceEvent event)
|
|
|
|
{
|
|
|
|
|
|
|
|
final Player player = event.getPlayer();
|
2019-11-07 02:29:04 +00:00
|
|
|
if (Tag.SIGNS.getValues().contains(event.getBlock().getType()))
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
|
|
|
ItemStack sign = event.getItemInHand();
|
2019-12-14 20:39:57 +00:00
|
|
|
net.minecraft.server.v1_15_R1.ItemStack nmsSign = CraftItemStack.asNMSCopy(sign);
|
2017-12-28 05:50:39 +00:00
|
|
|
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");
|
2018-01-01 03:43:10 +00:00
|
|
|
if (line1.contains("run_command") || line2.contains("run_command") || line3.contains("run_command") || line4.contains("run_command"))
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.GRAY + "You are not allowed to place command signs.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2019-11-03 21:40:05 +00:00
|
|
|
if (line1.contains("translate") || line2.contains("translate") || line3.contains("translate") || line4.contains("translate"))
|
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.GRAY + "You are not allowed to place broken strings that Mojang never fixed.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2019-11-18 22:25:14 +00:00
|
|
|
if (line1.contains("translation.test.") || line2.contains("translation.test.") || line3.contains("translation.test.") || line4.contains("translation.test."))
|
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.BOLD + "No.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2017-12-28 05:50:39 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-01 03:43:10 +00:00
|
|
|
|
2017-12-28 05:50:39 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
|
|
|
public void onPlayerInteractSign(PlayerInteractEvent event)
|
|
|
|
{
|
2018-01-01 03:43:10 +00:00
|
|
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-12-28 05:50:39 +00:00
|
|
|
|
2019-07-17 19:35:36 +00:00
|
|
|
if (event.getClickedBlock() != null && Tag.SIGNS.getValues().contains(event.getClickedBlock().getType()))
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|