Skip to content

Instantly share code, notes, and snippets.

Created August 30, 2016 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0f748b446498bee8e97351805e0194c9 to your computer and use it in GitHub Desktop.
Save anonymous/0f748b446498bee8e97351805e0194c9 to your computer and use it in GitHub Desktop.
package com.Sapphire.SapphireCore.Events;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
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.inventory.ItemStack;
import com.Sapphire.SapphireCore.Main;
public class BankNoteEvents implements Listener {
Main plugin;
public BankNoteEvents(Main plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
Player p = (Player) e.getPlayer();
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (e.getPlayer().getItemInHand().getType() == Material
.getMaterial(plugin.getConfig().getString("BankNote.Item").toUpperCase())) {
ItemStack hand = p.getItemInHand();
if (hand.getItemMeta().getDisplayName().equalsIgnoreCase(
ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("BankNote.Name")))) {
if (hand.getItemMeta().getLore().get(1) != null) {
String x = hand.getItemMeta().getLore().toString();
x = x.replaceAll("[^\\d.]", "");
double da = Double.parseDouble(x);
if(hand.getAmount() > 1) {
hand.setAmount(hand.getAmount() - 1);
plugin.econ.depositPlayer(p, da);
p.playSound(p.getLocation(), Sound.LEVEL_UP, 1.0F, 2.0F);
p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Deposit-Amount")
.replace("%DepositAmount%", x)));
}
if(hand.getAmount() == 1) {
p.setItemInHand(null);
plugin.econ.depositPlayer(p, da);
p.playSound(p.getLocation(), Sound.LEVEL_UP, 1.0F, 2.0F);
p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Deposit-Amount")
.replace("%DepositAmount%", x)));
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment