Added event that fires when top ten heads are clicked.

This commit is contained in:
tastybento 2017-10-24 20:52:30 -07:00
parent 61bf5ac921
commit 8d3d6edd66
3 changed files with 58 additions and 3 deletions

View File

@ -417,7 +417,7 @@ public class LevelCalcByChunk {
// Fire the island post level calculation event // Fire the island post level calculation event
final IslandPostLevelEvent event3 = new IslandPostLevelEvent(targetPlayer, island, event.getLevel(), event.getPointsToNextLevel()); final IslandPostLevelEvent event3 = new IslandPostLevelEvent(targetPlayer, island, event.getLevel(), event.getPointsToNextLevel());
bSkyBlock.getServer().getPluginManager().callEvent(event3); plugin.getServer().getPluginManager().callEvent(event3);
if(!event3.isCancelled()){ if(!event3.isCancelled()){
// Check that sender still is online // Check that sender still is online

View File

@ -44,6 +44,7 @@ import org.bukkit.inventory.meta.SkullMeta;
import bskyblock.addin.level.config.Settings; import bskyblock.addin.level.config.Settings;
import bskyblock.addin.level.database.object.Levels; import bskyblock.addin.level.database.object.Levels;
import bskyblock.addin.level.database.object.TopTenList; import bskyblock.addin.level.database.object.TopTenList;
import bskyblock.addin.level.event.TopTenClick;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.database.BSBDatabase; import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
@ -173,6 +174,7 @@ public class TopTen implements Listener {
} }
player.openInventory(gui); player.openInventory(gui);
player.updateInventory();
return true; return true;
} }
@ -189,6 +191,7 @@ public class TopTen implements Listener {
ItemStack playerSkull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); ItemStack playerSkull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
if (playerName == null) return null; if (playerName == null) return null;
SkullMeta meta = (SkullMeta) playerSkull.getItemMeta(); SkullMeta meta = (SkullMeta) playerSkull.getItemMeta();
//meta.setOwningPlayer(plugin.getServer().getOfflinePlayer(player));
meta.setOwner(playerName); meta.setOwner(playerName);
meta.setDisplayName((plugin.getLocale(player).get("topten.guiHeading").replace("[name]", BSkyBlock.getPlugin().getIslands().getIslandName(player))).replace("[rank]", String.valueOf(rank))); meta.setDisplayName((plugin.getLocale(player).get("topten.guiHeading").replace("[name]", BSkyBlock.getPlugin().getIslands().getIslandName(player))).replace("[rank]", String.valueOf(rank)));
//meta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "<!> " + ChatColor.YELLOW + "Island: " + ChatColor.GOLD + ChatColor.UNDERLINE + plugin.getGrid().getIslandName(player) + ChatColor.GRAY + " (#" + rank + ")"); //meta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "<!> " + ChatColor.YELLOW + "Island: " + ChatColor.GOLD + ChatColor.UNDERLINE + plugin.getGrid().getIslandName(player) + ChatColor.GRAY + " (#" + rank + ")");
@ -242,9 +245,10 @@ public class TopTen implements Listener {
event.setCancelled(true); event.setCancelled(true);
player.updateInventory(); player.updateInventory();
if(event.getCurrentItem() != null && event.getCurrentItem().getType().equals(Material.SKULL_ITEM) && event.getCurrentItem().hasItemMeta()){ if(event.getCurrentItem() != null && event.getCurrentItem().getType().equals(Material.SKULL_ITEM) && event.getCurrentItem().hasItemMeta()){
// TODO warp
//Util.runCommand(player, "is warp " + ((SkullMeta)event.getCurrentItem().getItemMeta()).getOwner());
player.closeInventory(); player.closeInventory();
// Fire click event
TopTenClick clickEvent = new TopTenClick(((SkullMeta)event.getCurrentItem().getItemMeta()).getOwningPlayer().getName());
plugin.getServer().getPluginManager().callEvent(clickEvent);
return; return;
} }
if (event.getSlotType().equals(SlotType.OUTSIDE)) { if (event.getSlotType().equals(SlotType.OUTSIDE)) {

View File

@ -0,0 +1,51 @@
package bskyblock.addin.level.event;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* This event is fired when a player clicks on a top ten head.
*
* @author tastybento
*/
public class TopTenClick extends Event implements Cancellable {
private boolean cancelled;
private static final HandlerList handlers = new HandlerList();
private final String owner;
public TopTenClick(String owner) {
this.owner = owner;
}
/**
* @return name of head owner that was clicked
*/
public String getOwner() {
return owner;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}