Created
February 26, 2013 06:05
-
-
Save nopresnik/5036254 to your computer and use it in GitHub Desktop.
This file contains 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
public class Events implements Listener { | |
HashMap<String, Long> cooldownJump = new HashMap<String, Long>(); | |
HashMap<String, Long> cooldownSponge = new HashMap<String, Long>(); | |
public JMod plugin; | |
public Events(JMod instance) { | |
plugin = instance; | |
} | |
/*interactions*/ | |
@EventHandler | |
public void onPlayerInteract(PlayerInteractEvent event) { | |
Player player = event.getPlayer(); | |
World world = player.getWorld(); | |
/*Jump ability*/ | |
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { | |
if (player.getItemInHand().getType() == Material.IRON_AXE || player.getItemInHand().getType() == Material.GOLD_AXE || player.getItemInHand().getType() == Material.DIAMOND_AXE || player.getItemInHand().getType() == Material.WOOD_AXE && (event.getAction() == Action.RIGHT_CLICK_BLOCK)) { | |
if (cooldownJump.containsKey(player.getName())) { | |
if (System.currentTimeMillis() >= cooldownJump.get(player.getName())) { | |
player.setVelocity(player.getVelocity().add(new Vector(0, 1, 0))); | |
player.setVelocity(player.getVelocity().multiply(1.5)); | |
world.playSound(player.getLocation(), Sound.ENDERMAN_HIT, 1, 1); | |
plugin.u.sendMessage(player, "Ability", "You used Leap ability (5 second cooldown)"); | |
cooldownJump.put(player.getName(), System.currentTimeMillis() + 5000); | |
} else { | |
plugin.u.sendMessage(player, "Ability", "Leap ability isn't ready yet"); | |
} | |
} else { | |
cooldownJump.put(player.getName(), System.currentTimeMillis() + 8000); | |
} | |
} | |
} | |
/*Sponge jump*/ | |
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { | |
if (event.getClickedBlock().getType() == Material.SPONGE) { | |
if (cooldownSponge.containsKey(player.getName())) { | |
if (System.currentTimeMillis() >= cooldownSponge.get(player.getName())) { | |
player.setVelocity(player.getVelocity().add(new Vector(0, 1.5, 0))); | |
world.playSound(player.getLocation(), Sound.DIG_GRASS, 1, 1); | |
plugin.u.sendMessage(player, "Ability", "You used Sponge ability"); | |
cooldownSponge.put(player.getName(), System.currentTimeMillis() + 1000); | |
} else { | |
} | |
} else { | |
cooldownSponge.put(player.getName(), System.currentTimeMillis() + 1000); | |
} | |
} | |
}/* | |
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { | |
ItemStack stack = event.getItem(); | |
if (plugin.getConfig().getIntegerList("banned-items").contains(stack.getTypeId())) { | |
event.setCancelled(true); | |
plugin.u.sendMessage(player, "Banned Item", "You're not permitted to use " + stack.getType() + " (#" + stack.getTypeId() + ")"); | |
} | |
}*/ | |
} | |
/*Classic hurt sound*/ | |
//TODO: FIX | |
/* | |
@EventHandler | |
public void onEntityDamage(EntityDamageEvent event) { | |
Player player = (Player) event.getEntity(); | |
Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN); | |
if (event.getEntity() instanceof Player) { | |
if (event.getCause() == DamageCause.FALL) { | |
if (block.getType() == Material.SPONGE) { | |
event.setCancelled(true); | |
} | |
} | |
} | |
}*/ | |
@EventHandler | |
public void onPlayerMove(PlayerMoveEvent event) { | |
Player player = event.getPlayer(); | |
Block block = player.getLocation().getBlock().getRelative(BlockFace.SELF); | |
if (block.getType() == Material.WEB) { | |
player.damage(2); | |
}/* | |
if (!player.isOp()) { | |
event.setCancelled(true); | |
player.sendMessage("You don't have permission to move!"); | |
}*/ | |
} | |
/*Allow our own death messages*/ | |
@EventHandler | |
public void onPlayerDeath(PlayerDeathEvent event) { | |
Player player = (Player) event.getEntity(); | |
event.setDeathMessage(""); | |
if ((player.getKiller() instanceof Player)) { | |
plugin.u.broadcastMessage("Death", player.getKiller().getName() + " killed " + player.getName() + " with a " + plugin.u.prettyItemName(player.getKiller().getItemInHand())); | |
} | |
} | |
/*Mobspawner hat*/ | |
@EventHandler | |
public void onBlockPlace(BlockPlaceEvent event) { | |
Player player = event.getPlayer(); | |
Block block = event.getBlock(); | |
if (block.getType() == Material.MOB_SPAWNER) { | |
block.setType(Material.AIR); | |
player.getInventory().setHelmet(new ItemStack(Material.MOB_SPAWNER, 1)); | |
plugin.u.sendMessage(player, "Ability", "This currently doesn't do anything"); | |
} | |
Block stack = event.getBlock(); | |
if (plugin.getConfig().getIntegerList("banned-items").contains(stack.getTypeId())) { | |
event.setCancelled(true); | |
plugin.u.sendMessage(player, "Banned Item", "You're not permitted to use " + stack.getType()); | |
} | |
} | |
@EventHandler | |
public void onPlayerDropItem(PlayerDropItemEvent event) { | |
Entity item = event.getItemDrop(); | |
if (event.getItemDrop().getItemStack().getType() == Material.FIRE) { | |
item.setVelocity(event.getItemDrop().getVelocity().multiply(3.0)); | |
} | |
} | |
@EventHandler | |
public void onPickArrp(PlayerPickupItemEvent event) { | |
if (event.getItem().getItemStack().getType() == Material.FIRE) { | |
event.getPlayer().setFireTicks(60); | |
} | |
} | |
@EventHandler | |
public void entityExplode(EntityExplodeEvent event) { | |
event.setCancelled(true); | |
} | |
/*@EventHandler | |
public void onSignChange(SignChangeEvent event) { | |
Player player = event.getPlayer(); | |
if (event.getLine(0)) | |
}*/ | |
@EventHandler | |
public void onNameTag(PlayerReceiveNameTagEvent event) { | |
if (event.getPlayer().getName().equals("CokeAndSPrite02")) { | |
event.setTag(ChatColor.RED + "CokeAndSPrite02"); | |
} | |
} | |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | |
public void onSignChange(SignChangeEvent event) { | |
Player player = event.getPlayer(); | |
for (int forInt = 0; forInt < 4; forInt++) { | |
if (!event.getLine(forInt).isEmpty()) { | |
String[] splitLine = event.getLine(forInt).split("&"); | |
String newLine = splitLine[0]; | |
for (int i = 1; i < splitLine.length; i++) { | |
int col; | |
if ((splitLine[i].length() == 0) || ((col = "0123456789abcdefklmnor".indexOf(splitLine[i].toLowerCase().charAt(0))) == -1) || (!checkPermissions(player, col)) || (splitLine[i].length() <= 1)) { | |
newLine = newLine + "&"; | |
} else { | |
//int col; | |
newLine = newLine + "§"; | |
} | |
newLine = newLine + splitLine[i]; | |
} | |
event.setLine(forInt, newLine); | |
} | |
} | |
} | |
private boolean checkPermissions(Player player, int colour) { | |
char col = "0123456789abcdefklmnor".charAt(colour); | |
return (colour == 0) || (player.hasPermission("signcolours." + col)) || (player.hasPermission("signcolours.*")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment