Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. package com.leontg77.uhc.scenario.types;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. import java.util.Map.Entry;
  8.  
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.ChatColor;
  11. import org.bukkit.command.Command;
  12. import org.bukkit.command.CommandExecutor;
  13. import org.bukkit.command.CommandSender;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.event.EventHandler;
  16. import org.bukkit.event.Listener;
  17. import org.bukkit.event.entity.PlayerDeathEvent;
  18. import org.bukkit.event.player.PlayerMoveEvent;
  19.  
  20. import com.leontg77.uhc.Main;
  21. import com.leontg77.uhc.scenario.Scenario;
  22. import com.leontg77.uhc.utils.PlayerUtils;
  23.  
  24. /**
  25. * Assassins scenario class
  26. *
  27. * @author audicymc
  28. *
  29. * Modified by Vawqer really badly to see if I could
  30. *
  31. */
  32. public class MysteryAssassins extends Scenario implements Listener, CommandExecutor {
  33. private HashMap<String, String> assassins = new HashMap<String, String>();
  34. private boolean enabled = false;
  35.  
  36. public MysteryAssassins() {
  37. super("Mystery Assassins", "Each player has a target that they must kill. Killing anyone that is not your target or assassin will result in no items dropping. When your target dies, you get their target.");
  38. Main main = Main.plugin;
  39.  
  40. main.getCommand("target").setExecutor(this);
  41. }
  42.  
  43. public void setEnabled(boolean enable) {
  44. enabled = enable;
  45.  
  46. if (enable) {
  47. PlayerUtils.broadcast(Main.PREFIX + "Assigning targets...");
  48. ArrayList<Player> players = new ArrayList<Player>(PlayerUtils.getPlayers());
  49. Collections.shuffle(players);
  50.  
  51. for (int i = 0; i < players.size(); i++) {
  52. Player assassin = players.get(i);
  53. Player target = players.get(i < players.size() - 1 ? i + 1 : 0);
  54.  
  55. setTarget(assassin.getName(), target.getName());
  56. }
  57. }
  58. }
  59.  
  60. public boolean isEnabled() {
  61. return enabled;
  62. }
  63.  
  64. @EventHandler
  65. public void onPlayerDeath(PlayerDeathEvent event) {
  66. Player player = event.getEntity();
  67. Player killer = player.getKiller();
  68.  
  69. if (assassins.containsKey(player.getName())) {
  70. String assassin = getAssassin(player.getName());
  71. String target = getTarget(player.getName());
  72.  
  73. if (killer != null && !killer.getName().equals(assassin) && !killer.getName().equals(target)) {
  74. event.getDrops().clear();
  75. }
  76.  
  77. setTarget(assassin, target);
  78. assassins.remove(player.getName());
  79. event.setDeathMessage(Main.PREFIX + ChatColor.GREEN + "A player �7was eliminated!");
  80. }
  81. }
  82.  
  83. @EventHandler
  84. public void onPlayerMove(PlayerMoveEvent event) {
  85. Player player = event.getPlayer();
  86. String target = getAssassin(player.getName());
  87.  
  88. if (target != null) {
  89. Player targetP = Bukkit.getServer().getPlayer(target);
  90.  
  91. if (targetP != null) {
  92. targetP.setCompassTarget(player.getLocation());
  93. }
  94. }
  95. }
  96.  
  97. @Override
  98. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  99. if (!(sender instanceof Player)) {
  100. sender.sendMessage(ChatColor.RED + "Only players can have targets.");
  101. return true;
  102. }
  103.  
  104. Player player = (Player) sender;
  105.  
  106. if (!isEnabled()) {
  107. player.sendMessage(Main.PREFIX + "\"Assassins\" is not enabled.");
  108. return true;
  109. }
  110.  
  111. player.sendMessage(Main.PREFIX + "Your target is a mystery!");
  112. return true;
  113. }
  114.  
  115. /**
  116. * Get the assassins map
  117. * @return the Assassins map
  118. */
  119. public Map<String, String> getAssassins() {
  120. return assassins;
  121. }
  122.  
  123. /**
  124. * Get the assassin that has the target.
  125. * @param target the target.
  126. * @return the assassin.
  127. */
  128. private String getAssassin(String target) {
  129. for (Entry<String, String> e : assassins.entrySet()) {
  130. if (e.getValue().equalsIgnoreCase(target)) {
  131. return e.getKey();
  132. }
  133. }
  134. return null;
  135. }
  136.  
  137. /**
  138. * Get the target for an assassin
  139. * @param assassin the assassin.
  140. * @return the target of the assassin
  141. */
  142. private String getTarget(String assassin) {
  143. for (Entry<String, String> e : assassins.entrySet()) {
  144. if (e.getKey().equalsIgnoreCase(assassin)) {
  145. return e.getValue();
  146. }
  147. }
  148. return null;
  149. }
  150.  
  151. /**
  152. * Set a new target for the assassin.
  153. * @param assassin the assassin.
  154. * @param target the new target.
  155. */
  156. private void setTarget(String assassin, String target) {
  157. assassins.put(assassin, target);
  158.  
  159. Player player = Bukkit.getServer().getPlayer(assassin);
  160.  
  161. if (player != null) {
  162. player.sendMessage(Main.PREFIX + "Your new target has been assigned!");
  163. }
  164. }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement