Skip to content

Instantly share code, notes, and snippets.

@nijikokun
Created May 16, 2011 23:48
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 nijikokun/b3ec9be7651842e81353 to your computer and use it in GitHub Desktop.
Save nijikokun/b3ec9be7651842e81353 to your computer and use it in GitHub Desktop.
import com.nijikokun.register.payment.Method.MethodAccount;
public class SneakPlayerListener extends PlayerListener {
private final Sneak plugin;
private Method economy;
private final HashMap<String, Long> delays = new HashMap<String, Long>();
public SneakPlayerListener(Sneak plugin) {
this.plugin = plugin;
this.economy = plugin.getMethod();
}
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!event.isCancelled()) {
Player player = event.getPlayer();
Entity entity = event.getRightClicked();
World world = player.getWorld();
WorldConfig worldConfig = plugin.getConfigManager().getWorldConfig(world);
if (entity instanceof Player) {
Player target = (Player)entity;
if (player.isSneaking() && target != null) {
if (Sneak.hasPermissions(player, "Sneak.use")) {
if ((economy.hasAccount(target.getName())) && (economy.hasAccount(player.getName()))) {
MethodAccount _target = economy.getAccount(target.getName());
MethodAccount _player = economy.getAccount(player.getName());
if(_target == null || _player == null) return;
int delay = 10 * 1000;
if (delays.containsKey(player.getName())) {
if ((System.currentTimeMillis() - delays.get(player.getName())) < delay) {
player.sendMessage(ChatColor.RED + "You can't sneak " + target.getName() + " so often.");
return;
}
}
double amount = _target.balance() / 100 * 10.0;
if (_target.hasEnough(amount)) {
_target.subtract(amount);
_player.add(amount);
String format = economy.format(amount);
player.sendMessage(ChatColor.GREEN + "You sneaked " + target.getName() + " and got " + format + ".");
target.sendMessage(ChatColor.RED + "You where sneaked by " + player.getName() + " and lost " + format + ".");
delays.put(player.getName(), System.currentTimeMillis());
} else {
player.sendMessage(ChatColor.RED + target.getName() + " have no money");
}
} else {
player.sendMessage(ChatColor.RED + "You or " + target.getName() + "don't have an account.");
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment