View difference between Paste ID: AJNcxuWQ and t2hWfz2w
SHOW: | | - or go back to the newest paste.
1
package me.benLewis.bukkitPluginEight;
2
3
import java.util.logging.Logger;
4
import org.bukkit.Bukkit;
5
import org.bukkit.ChatColor;
6
import org.bukkit.Effect;
7
import org.bukkit.Material;
8
import org.bukkit.command.Command;
9
import org.bukkit.command.CommandSender;
10
import org.bukkit.entity.Player;
11
import org.bukkit.event.EventHandler;
12
import org.bukkit.event.Listener;
13
import org.bukkit.event.player.PlayerInteractEvent;
14
import org.bukkit.inventory.Inventory;
15
import org.bukkit.inventory.ItemStack;
16
import org.bukkit.inventory.meta.ItemMeta;
17
import org.bukkit.plugin.java.JavaPlugin;
18-
public class walrus extends JavaPlugin{
18+
19
public class walrus extends JavaPlugin implements Listener {
20
	
21
	// #### This is how I am getting the itemstack and its meta data ####
22
	
23
	ItemStack fireCharge = new ItemStack(Material.ENCHANTED_BOOK);
24
	ItemMeta swordMeta = fireCharge.getItemMeta();
25
	
26
	//logger logs messages/actions to the Console
27
	Logger myPluginLogger = Bukkit.getLogger();
28
29
	//Will activate on server startup
30
	public void onEnable(){
31
32
		Bukkit.getServer().getPluginManager().registerEvents(this, this);
33
		myPluginLogger.info(ChatColor.DARK_RED + "Bukkit Plugin EIGHT has been statted");
34
35
	}
36
37
	//Will activate on server shutdown
38
	public void onDisable(){
39
40
		myPluginLogger.info(ChatColor.DARK_RED + "Bukkit Plugin EIGHT has been disabled!");
41
		myPluginLogger.severe(ChatColor.DARK_RED + "SHUTTING DOWN");
42
	}
43
44
	public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String[] args){
45
46
		if(theSender instanceof Player){
47
			Player player = (Player) theSender;
48
49
			if(commandLabel.equalsIgnoreCase("gem")){
50
				ItemStack Gem = new ItemStack(Material.EMERALD);
51
				Inventory gemInv = Bukkit.createInventory(null, 9, ChatColor.GOLD + "The Gem of Seregon");
52
				gemInv.addItem(Gem);
53
				player.openInventory(gemInv);
54
				
55
				// #### This is how I assign it the new metadata and put it in the inv ####
56
				swordMeta.setDisplayName(ChatColor.AQUA + "Spell: " + ChatColor.DARK_RED + "Fire Charge");
57
				fireCharge.setItemMeta(swordMeta);
58
				gemInv.addItem(fireCharge);
59
				
60
				
61
			}
62
			
63
			if(commandLabel.equalsIgnoreCase("rename")){
64
				
65
				if(args.length == 1){
66
					
67
					ItemStack hand = player.getItemInHand();
68
					ItemMeta handMeta = hand.getItemMeta();
69
					handMeta.setDisplayName(ChatColor.WHITE + args[0]);
70
					hand.setItemMeta(handMeta);
71
72
					
73
				}else player.sendMessage(ChatColor.DARK_AQUA + "[" + ChatColor.GOLD + "SeregonNation" + ChatColor.DARK_AQUA + "] " + ChatColor.GOLD + "Try using" + ChatColor.DARK_AQUA + " /rename <new name>");
74
				
75
				
76
			}
77
		}
78
79
		return false;
80
81
	}
82
	// ###############################
83
	// THIS IS THE BIT I AM WORKING ON
84
	// ###############################
85
	
86
	//Calls the event handler, and uses the onClick listener
87
	@SuppressWarnings("deprecation")
88
	@EventHandler
89
	public void onClickEvent(PlayerInteractEvent event){
90
		
91
		//this gets a player through the event, not a command
92
		final Player player = event.getPlayer();
93
		
94
		// #### And this is where I am trying to execute the code if they click with the item in their hand ####
95
		
96
		if(player.getItemInHand().getItemMeta() == swordMeta){
97
			player.playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
98
			player.sendMessage(ChatColor.DARK_AQUA + "[" + ChatColor.GOLD + "SeregonNation" + ChatColor.DARK_AQUA + "] " + ChatColor.GOLD + "" + ChatColor.BOLD + "Your fiery fury has been unleashed!");
99
			this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
100
				public void run() {
101
					player.playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
102
				}
103
			}, 2L);		
104
		}	
105
	}
106
}