From 145c3a1b424b1a27ed9499dd55dc04e985904e88 Mon Sep 17 00:00:00 2001 From: Pepich Date: Wed, 1 Feb 2017 20:37:28 +0100 Subject: [PATCH] Added SkullClick module --- .../modules/skullclick/SkullClick.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/com/redstoner/modules/skullclick/SkullClick.java diff --git a/src/com/redstoner/modules/skullclick/SkullClick.java b/src/com/redstoner/modules/skullclick/SkullClick.java new file mode 100644 index 0000000..e05e404 --- /dev/null +++ b/src/com/redstoner/modules/skullclick/SkullClick.java @@ -0,0 +1,79 @@ +package com.redstoner.modules.skullclick; + +import org.bukkit.block.BlockState; +import org.bukkit.block.Skull; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +import com.redstoner.annotations.AutoRegisterListener; +import com.redstoner.annotations.Version; +import com.redstoner.misc.Utils; +import com.redstoner.modules.Module; + +@Version(major = 1, minor = 0, revision = 0, compatible = 1) +@AutoRegisterListener +public class SkullClick implements Module, Listener +{ + private boolean enabled = false; + private boolean seen = false; + + @SuppressWarnings("deprecation") + @EventHandler + public void onClick(PlayerInteractEvent e) + { + // For some reason the event gets fired twice, this fixes it. Lol. + if (seen) + { + seen = false; + return; + } + seen = true; + if (e.getAction() == Action.RIGHT_CLICK_BLOCK && !e.isCancelled()) + { + BlockState block = e.getClickedBlock().getState(); + if (block instanceof Skull) + { + Skull skull = (Skull) block; + String owner = skull.getOwner(); + if (owner == null || owner.equals("")) + { + Utils.sendMessage(e.getPlayer(), null, "§eThat skull has no owner."); + } + else + { + Utils.sendMessage(e.getPlayer(), null, "§eThat's " + owner + "."); + } + if (!e.getPlayer().isSneaking()) + { + e.setCancelled(true); + } + } + } + } + + @Override + public boolean enabled() + { + return enabled; + } + + @Override + public void onEnable() + { + enabled = true; + } + + @Override + public void onDisable() + { + enabled = false; + } + + @Override + public String getCommandString() + { + return null; + } +}