Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import org.bukkit.Bukkit;
  2. import org.bukkit.ChatColor;
  3. import org.bukkit.Location;
  4. import org.bukkit.entity.Player;
  5. import org.bukkit.entity.Snowball;
  6. import org.bukkit.event.EventHandler;
  7. import org.bukkit.event.Listener;
  8. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  9. import org.bukkit.plugin.java.JavaPlugin;
  10.  
  11. public class Switcher extends JavaPlugin implements Listener{
  12.    
  13.     public void onEnable() {
  14.         Bukkit.getServer().getPluginManager().registerEvents(this, this);
  15.  
  16.     }
  17.    
  18.     public void onDisable() {
  19.        
  20.     }
  21.    
  22.     @EventHandler
  23.     public void switcher(EntityDamageByEntityEvent e) {
  24.         if (e.getEntity() instanceof Player && e.getDamager() instanceof Snowball) {
  25.             Snowball snowball = (Snowball) e.getDamager();
  26.             if (snowball.getShooter() instanceof Player) {
  27.                 Player s = (Player) snowball.getShooter();
  28.                 Player d = (Player) e.getEntity();
  29.            
  30.                 Location loc1 = s.getPlayer().getLocation().clone();
  31.                 Location loc2 = e.getEntity().getLocation().clone();
  32.                 s.getPlayer().teleport(loc2);
  33.                 e.getEntity().teleport(loc1);
  34.                
  35.                
  36.                
  37.                
  38.                 s.sendMessage(ChatColor.GREEN + "You switched positions with " + ChatColor.RED + d.getName() + ChatColor.GREEN + "!");
  39.                 d.sendMessage(ChatColor.RED + "You were switched by " + ChatColor.GREEN + s.getName() + ChatColor.RED + "!");
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement