Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.limegaming.gnarusly.GhostOnDeath;
- import java.util.HashSet;
- import java.util.Set;
- import org.bukkit.Bukkit;
- import org.bukkit.Material;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.LivingEntity;
- import org.bukkit.entity.Player;
- import org.bukkit.entity.Projectile;
- import org.bukkit.entity.ThrownPotion; //Not used yet
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.EntityDamageByEntityEvent;
- import org.bukkit.event.entity.PlayerDeathEvent;
- import org.bukkit.event.entity.PotionSplashEvent;
- import org.bukkit.event.player.PlayerBucketEmptyEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.potion.PotionEffectType;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.ChatColor;
- public class GhostOnDeathListener implements Listener {
- public Set<String> list = new HashSet<String>();
- private class RemoveNameTask extends BukkitRunnable {
- private final String victimName;
- public RemoveNameTask(String name) { victimName = name; }
- @Override
- public void run() {
- GhostOnDeathListener.this.list.remove(victimName);
- Bukkit.broadcastMessage("[");
- }
- }
- @EventHandler
- public void onDeath(PlayerDeathEvent event) {
- Player victim = (Player) event.getEntity();
- if (victim.getKiller() != null) {
- Player killer = victim.getKiller();
- final String victimName = ((Player) victim).getPlayer().getName();
- //Not done yet, going to import DC and magic API
- victim.sendMessage("You are the victim!");
- killer.sendMessage("You are the killer!");
- /* Adds user to list of victims */
- list.add(victimName);
- /* Makes user into a ghost */
- GhostOnDeathMain.ghostFactory.setGhost(victim, true);
- GhostOnDeathMain.ghostFactory.addPlayer(killer);
- new RemoveNameTask(victimName).runTaskLater(GhostOnDeathMain.getPlugin(), 24000);
- }
- }
- @EventHandler
- public static void onPvP(EntityDamageByEntityEvent event) {
- if ((event.getEntity() instanceof Player)) {
- /* Checks to see if the damager is a player */
- if (event.getDamager() instanceof Player) {
- Entity victim = event.getEntity();
- Player killer = (Player)event.getDamager();
- String killer2 = killer.getName();
- String victimName = ((Player) victim).getPlayer().getName();
- if (list.contains(victimName)) {
- /* Outputs message that you can't attack protected user */
- killer.sendMessage("That player is under PVP protection. Do not attempt to kill them.");
- /* Stops Killer from hurting them. */
- event.setCancelled(true);
- }
- else if (list.contains(killer2)) {
- killer.sendMessage("You're under PVP Protection. Do not PVP.");
- event.setCancelled(true);
- }
- }
- else if (event.getDamager() instanceof Projectile) {
- /* Checks to see if the damager is a projectile */
- LivingEntity shooter = ((Projectile)event.getDamager()).getShooter();
- /*Checks to see if the person shot is a player
- * and the shooter is a player. */
- if (shooter instanceof Player && event.getEntity() instanceof Player) {
- Player killer = (Player)shooter;
- String killerName = ((Player) killer).getPlayer().getName();
- Entity victim = (Player) event.getEntity();
- String victimName = ((Player) victim).getPlayer().getName();
- /*Checks to see if victim died*/
- if (list.contains(victimName)) {
- /*Stops killer from hurting them*/
- event.setCancelled(true);
- killer.sendMessage("That player is under PVP protection. Do not attempt to kill them.");
- }
- else if (list.contains(killerName)) {
- killer.sendMessage("You're under PVP Protection. Do not PVP.");
- event.setCancelled(true);
- }
- }
- }
- }
- }
- @EventHandler
- public static void onPlayerJoin(PlayerJoinEvent event) {
- Player player = event.getPlayer();
- String playerName = event.getPlayer().getName();
- if (list.contains(playerName)) {
- GhostOnDeathMain.ghostFactory.setGhost(player, true);
- }
- else {
- GhostOnDeathMain.ghostFactory.setGhost(player, false);
- player.removePotionEffect(PotionEffectType.INVISIBILITY);
- }
- }
- @EventHandler
- public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
- Player player = event.getPlayer();
- String playerName = event.getPlayer().getName();
- if (list.contains(playerName)) {
- Material bucket = event.getBucket();
- if (bucket.toString().contains("LAVA")) {
- event.setCancelled(true);
- player.sendMessage("You can't use a lava bucket while under PVP protection!");
- }
- if (bucket.toString().contains("WATER")) {
- //nothing
- }
- }
- }
- @EventHandler
- public void PotionHit(PotionSplashEvent event){
- Entity damager = event.getPotion().getShooter();
- if (damager instanceof Player){
- for(LivingEntity player : event.getAffectedEntities()){
- if(player instanceof Player){
- Player playerName = (Player) player;
- //not finished yet
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement