Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.goksi.extremevent;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.Location;
  8. import org.bukkit.World;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandExecutor;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.event.EventHandler;
  14. import org.bukkit.event.Listener;
  15. import org.bukkit.event.entity.PlayerDeathEvent;
  16. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
  17. import org.bukkit.event.player.PlayerRespawnEvent;
  18. import org.bukkit.inventory.ItemStack;
  19.  
  20. import net.md_5.bungee.api.ChatColor;
  21.  
  22. public class Pvp implements CommandExecutor, Listener {
  23.    
  24.     Commands cmds;
  25.     public Pvp(Commands ins) {
  26.         cmds = ins;
  27.         }
  28.     Map<Player, ItemStack[]> items = new HashMap<Player, ItemStack[]>();
  29.     Map<Player, ItemStack[]> armor = new HashMap<Player, ItemStack[]>();
  30.  
  31.     @Override
  32.     public boolean onCommand(CommandSender sender, Command cmd, String lbl, String[] args) {
  33.         if(cmds.event) {
  34.             Player p = (Player) sender;
  35.             if(cmds.mrtv.contains(p)) {
  36.                 p.sendMessage(ChatColor.translateAlternateColorCodes('&', cmds.pl.getConfig().getString("mrtav")));
  37.                 return true;
  38.             }   else {
  39.                 cmds.igr.add(p);
  40.                 clearInv(p);
  41.                 World w = Bukkit.getServer().getWorld("world");
  42.                 int x = cmds.pl.getConfig().getInt("arenaX");
  43.                 int y = cmds.pl.getConfig().getInt("arenaY");
  44.                 int z =  cmds.pl.getConfig().getInt("arenaZ");
  45.                 Location arena = new Location(w, x, y, z);
  46.                 p.teleport(arena);
  47.             }
  48.         }else {
  49.             sender.sendMessage(ChatColor.translateAlternateColorCodes('&', cmds.pl.getConfig().getString("eventDisable")));
  50.             return true;
  51.         }
  52.        
  53.         return false;
  54.     }
  55.    
  56.     public void clearInv(Player p) {
  57.         ItemStack[] contents = p.getInventory().getContents();
  58.         ItemStack[] armorContents = p.getInventory().getArmorContents();
  59.         items.put(p, contents);
  60.         armor.put(p, armorContents);
  61.         p.getInventory().clear();
  62.  
  63.         p.getInventory().setHelmet(null);
  64.         p.getInventory().setChestplate(null);
  65.         p.getInventory().setLeggings(null);
  66.         p.getInventory().setBoots(null);
  67.     }
  68.     public void loadInv(Player p) {
  69.         ItemStack[] contents = items.get(p);
  70.         ItemStack[] armorContents = armor.get(p);
  71.         p.getInventory().setContents(contents);
  72.         p.getInventory().setArmorContents(armorContents);
  73.         armor.remove(p);
  74.         items.remove(p);
  75.     }
  76.     @EventHandler
  77.     public void onDeath(PlayerDeathEvent e) {
  78.         Player p = e.getEntity();
  79.         int ostalo = cmds.igr.size();
  80.         if(cmds.igr.contains(p)) {
  81.             cmds.igr.remove(p);
  82.             cmds.mrtv.add(p);
  83.         } else if(ostalo == 1) {
  84.             Player win = cmds.igr.get(0);
  85.             int x = cmds.pl.getConfig().getInt("spawnX");
  86.             int y = cmds.pl.getConfig().getInt("spawnY");
  87.             int z = cmds.pl.getConfig().getInt("spawnZ");
  88.             World w = win.getWorld();
  89.             Location spawn = new Location(w, x,  y, z);
  90.             win.teleport(spawn);
  91.             this.clearInv(win);
  92.             this.loadInv(win);
  93.             cmds.igr.remove(win);
  94.             cmds.mrtv.add(p);
  95.             Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', cmds.pl.getConfig().getString("win").replaceAll("%igrac%", win.getName())));
  96.                    
  97.         } else return;
  98.        
  99.     }
  100.     public void onRespawn(PlayerRespawnEvent e) {
  101.         Player p = e.getPlayer();
  102.         if(!(armor.get(p) == null) && !(items.get(p) == null)) {
  103.             loadInv(p);
  104.         } else return;
  105.     }
  106.    
  107.     public void onCommand(PlayerCommandPreprocessEvent e) {
  108.         Player p = e.getPlayer();
  109.         if(cmds.igr.contains(p)) {
  110.             String command = e.getMessage();
  111.             if (cmds.pl.getBc().contains(command)) {
  112.                 e.setCancelled(true);
  113.                 p.sendMessage(ChatColor.translateAlternateColorCodes('&', cmds.pl.getConfig().getString("cmdEvent")));
  114.             }
  115.         }
  116.     }
  117.  
  118. }
Advertisement
RAW Paste Data Copied
Advertisement