Last active
September 20, 2019 22:02
-
-
Save hburn7/6fd69277c3f98431aea97696adb12e4b to your computer and use it in GitHub Desktop.
My plugin that is supposed to give users some bonuses as well as teleport them to home when they right click (either a block or the air) with said item in hand.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.kaguyabot.customitemgenerator; | |
import org.bukkit.ChatColor; | |
import org.bukkit.Material; | |
import org.bukkit.Sound; | |
import org.bukkit.enchantments.Enchantment; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.block.Action; | |
import org.bukkit.event.player.PlayerInteractEvent; | |
import org.bukkit.permissions.PermissionAttachment; | |
import org.bukkit.potion.PotionEffect; | |
import org.bukkit.potion.PotionEffectType; | |
import java.util.*; | |
public class ArchangelEyeListener implements Listener { | |
@EventHandler | |
public void onPlayerInteract(PlayerInteractEvent e) { | |
if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { | |
Player p = e.getPlayer(); | |
if(e.getItem() != null && e.getItem().getType().equals(Material.ENDER_EYE) | |
&& e.getItem().containsEnchantment(Enchantment.CHANNELING) | |
&& e.getItem().getItemMeta().getDisplayName().equalsIgnoreCase( | |
ChatColor.LIGHT_PURPLE + "Archangel's Eye of Liberation")) { | |
Logger logger = new Logger(); | |
HashMap<UUID, PermissionAttachment> perms = new HashMap<UUID, PermissionAttachment>(); | |
CustomItemGenerator customItemGeneratorClass = new CustomItemGenerator(); | |
PermissionAttachment attachment = p.addAttachment(customItemGeneratorClass); | |
perms.put(p.getUniqueId(), attachment); | |
PermissionAttachment pperms = perms.get(p.getUniqueId()); | |
pperms.setPermission("essentials.home", true); | |
p.getInventory().getItemInMainHand().subtract(1); | |
p.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 30, 1)); | |
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 15, 2)); | |
p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 30, 2)); | |
p.sendMessage(ChatColor.GOLD + "A voice from above whispers..." + ChatColor.ITALIC + "\"You have been liberated...\""); | |
p.playSound(p.getLocation(), Sound.AMBIENT_CAVE, 2, 0); | |
p.playSound(p.getBedSpawnLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 2, 0); | |
p.performCommand("home"); | |
pperms.setPermission("essentials.home", false); | |
logger.log(String.format("Player {0} consumed 1x" + ChatColor.AQUA + | |
"Archangel's Eye of Liberation to return to safety.", p.getName())); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.kaguyabot.customitemgenerator; | |
import org.bukkit.command.CommandExecutor; | |
import org.bukkit.event.Listener; | |
import org.bukkit.plugin.PluginManager; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public final class CustomItemGenerator extends JavaPlugin implements Listener, CommandExecutor { | |
@Override | |
public void onEnable() { | |
PluginManager manager = getServer().getPluginManager(); | |
manager.registerEvents(new ArchangelEyeListener(), this); | |
getLogger().info("[CustomItemGenerator]: Started"); | |
getCommand("archgive").setExecutor(new ArchgiveCommand()); | |
} | |
@Override | |
public void onDisable() { | |
getLogger().info("[CustomItemGenerator]: Shutdown"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment