Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.34 KB | None | 0 0
  1. public void playerJoin(Player p, Location loc)
  2. {
  3.     // Store location and health.
  4.     //if (!locations.containsKey(p))
  5.     //  locations.put(p,loc);
  6.     //if (!healthMap.containsKey(p))
  7.     //  healthMap.put(p,p.getHealth());
  8.    
  9.     // Flag that the player has joined.
  10.     setPlayerHasJoined( p, loc );
  11.    
  12.     // Heal player.
  13.     p.setHealth(20);
  14.    
  15.     // Sit pets.
  16.     //MAUtils.sitPets(p);
  17.    
  18.     // Prevent unwanted things when coming from entry location.
  19.     preventUnwantedsFromEntry( p );
  20.    
  21.     // Update chunk.
  22.     //updateChunk(lobbyLoc);
  23.    
  24.     //lobbyPlayers.add(p);
  25.     //p.teleport(lobbyLoc);
  26.  
  27.     // Notify listeners.
  28.     //for (MobArenaListener listener : plugin.getAM().listeners)
  29.     //  listener.onPlayerJoin(p);
  30.     movePlayerToLobby( p );
  31. }
  32.  
  33. public void playerLeave(Player p)
  34. {
  35.     // If they are in the Arena or in the Lobby, clear the inventory.
  36.     if (arenaPlayers.contains(p) || lobbyPlayers.contains(p))
  37.         MAUtils.clearInventory( p );
  38.    
  39.     // Restore old inventory and fork over rewards.
  40.     restoreInvAndGiveRewards( p );
  41.    
  42.     // Grab the player's entry location, and warp them there.
  43.     //Location entry = locations.get(p);
  44.     //if (entry != null)
  45.     //{
  46.     //  updateChunk(entry);
  47.     //  p.teleport(entry);
  48.     //}
  49.     movePlayerToEntry( p );
  50.    
  51.     //locations.remove(p);
  52.     //if (healthMap.containsKey(p)) p.setHealth(healthMap.remove(p));
  53.    
  54.     // Remove from the arenaMap and all the sets.
  55.     //plugin.getAM().arenaMap.remove(p);
  56.     //removePlayer(p);
  57.     finishWithPlayer( p );
  58.    
  59.     // End the arena if conditions are met.
  60.     endArena();
  61. }
  62.  
  63. public void playerDeath(Player p)
  64. {
  65.     // If spectate-on-death: false, pass on to playerLeave.
  66.     //if (!specOnDeath)
  67.     //{
  68.         //playerLeave(p);
  69.         //return;
  70.     //}
  71.    
  72.     // Clear inventory
  73.     MAUtils.clearInventory( p );
  74.    
  75.     // Clear class inventory, restore old inventory and fork over rewards.
  76.     restoreInvAndGiveRewards( p );
  77.  
  78.     // Remove player from sets, warp to spectator area, then add to specPlayers.  
  79.     //p.teleport(spectatorLoc);
  80.    
  81.     //if (healthMap.containsKey(p)) p.setHealth(healthMap.remove(p));
  82.     //removePlayer(p);
  83.    
  84.     //specPlayers.add(p);
  85.    
  86.     // If Player will be spectating on death,
  87.     if ( specOnDeath )
  88.     {
  89.         // Restore health, remove from sets.
  90.         resetPlayer( p );
  91.         // Move to spectator area.
  92.         movePlayerToSpec( p );
  93.     }
  94.     // Otherwise, Player goes back to entry location,
  95.     else
  96.     {
  97.         // Move to entry location.
  98.         movePlayerToEntry( p );
  99.         // Remove entry location, remove from ArenaMap, Restore health, and remove from sets.
  100.         finishWithPlayer( p );
  101.     }
  102.  
  103.     // Update the monster targets.
  104.     if (running && spawnThread != null)
  105.         spawnThread.updateTargets();
  106.    
  107.     // Announce and notify
  108.     MAUtils.tellAll(this, MAMessages.get(Msg.PLAYER_DIED, p.getName()));
  109.     for (MobArenaListener listener : plugin.getAM().listeners)
  110.         listener.onPlayerDeath(p);
  111.  
  112.     // End the arena if conditions are met.
  113.     endArena();
  114. }
  115.  
  116. public void playerSpec(Player p, Location loc)
  117. {
  118.     //if (!locations.containsKey(p))
  119.     //  locations.put(p,loc);  
  120.     //if (!healthMap.containsKey(p))
  121.     //  healthMap.put(p,p.getHealth());
  122.     setPlayerHasJoined( p );
  123.    
  124.     // Prevent unwanted things when coming from entry location.
  125.     preventUnwantedsFromEntry( p );
  126.    
  127.     //specPlayers.add(p);
  128.     //p.teleport(spectatorLoc);
  129.     movePlayerToSpec( p );
  130. }
  131.  
  132. public void restoreInvAndGiveRewards(final Player p)
  133. {
  134.     final List<ItemStack> rewards = rewardMap.get(p);
  135.     final boolean hadRewards = rewardedPlayers.contains(p);
  136.    
  137.     //if (clear) MAUtils.clearInventory(p);
  138.    
  139.     Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
  140.         new Runnable()
  141.         {
  142.             public void run()
  143.             {
  144.                 if (!emptyInvJoin)
  145.                     MAUtils.restoreInventory(p);
  146.                
  147.                 if (hadRewards)
  148.                     return;
  149.                
  150.                 MAUtils.giveRewards(p, rewards, plugin);
  151.                 if (running)
  152.                     rewardedPlayers.add(p);
  153.             }
  154.         });
  155. }
  156.  
  157.  
  158. // =========== NEW FUNCTIONS =================
  159.  
  160.  
  161. // Called whenever a player enters a MobArena area (spectator or lobby).
  162. private void setPlayerHasJoined (Player p, Location loc)
  163. {
  164.     // Store entry location
  165.     if (!locations.containsKey(p))
  166.         locations.put(p,loc);
  167.    
  168.     // Store entry health
  169.     if (!healthMap.containsKey(p))
  170.         healthMap.put(p,p.getHealth());
  171. }
  172.  
  173. private void movePlayerToLobby (Player p)
  174. {
  175.     // Update chunk.
  176.     updateChunk(lobbyLoc);
  177.    
  178.     // Add player to lobby list.
  179.     lobbyPlayers.add(p);
  180.    
  181.     // Warp player.
  182.     p.teleport(lobbyLoc);
  183.  
  184.     // Notify listeners for API.
  185.     for (MobArenaListener listener : plugin.getAM().listeners)
  186.         listener.onPlayerJoin(p);
  187. }
  188.  
  189. private void movePlayerToSpec (Player p)
  190. {
  191.     // Update chunk.
  192.     updateChunk(spectatorLoc);
  193.    
  194.     // Add player to spec list.
  195.     specPlayers.add(p);
  196.    
  197.     // Warp player.
  198.     p.teleport(spectatorLoc);
  199. }
  200.  
  201. private void movePlayerToEntry (Player p)
  202. {
  203.     // Find entry location
  204.     Location entry = locations.get(p);
  205.     if (entry != null)
  206.     {
  207.         // Update the chunk.
  208.         updateChunk(entry);
  209.        
  210.         // Move the player.
  211.         p.teleport(entry);
  212.     }
  213. }
  214.  
  215. private void finishWithPlayer (Player p)
  216. {
  217.     // Remove their entry location.
  218.     locations.remove(p);
  219.    
  220.     // Remove from the arenaMap.
  221.     plugin.getAM().arenaMap.remove(p);
  222.    
  223.     // Remove from sets and restore health.
  224.     resetPlayer( p )
  225. }
  226.  
  227. private void resetPlayer (Player p)
  228. {
  229.     // Restore their health.
  230.     if (healthMap.containsKey(p)) p.setHealth(healthMap.remove(p));
  231.    
  232.     // Remove from sets.
  233.     removePlayer(p);
  234. }
  235.  
  236. private void preventUnwantedsFromEntry (Player p)
  237. {
  238.     // Sit pets
  239.     MAUtils.sitPets(p);
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement