vMinecraftListener.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import java.util.logging.Level;
  2. import java.util.logging.Logger;
  3. import java.util.Set;
  4. //=====================================================================
  5. //Class: vMinecraftListener
  6. //Use: The listener to catch incoming chat and commands
  7. //Author: nossr50, TrapAlice, cerevisiae
  8. //=====================================================================
  9. public class vMinecraftListener extends PluginListener {
  10. public int damagetype;
  11. protected static final Logger log = Logger.getLogger("Minecraft");
  12. //=====================================================================
  13. //Function: disable
  14. //Input: None
  15. //Output: None
  16. //Use: Disables vMinecraft, but why would you want to do that? ;)
  17. //=====================================================================
  18. public void disable() {
  19. log.log(Level.INFO, "vMinecraft disabled");
  20. }
  21. //=====================================================================
  22. //Function: onChat
  23. //Input: Player player: The player calling the command
  24. // String message: The message to color
  25. //Output: boolean: If the user has access to the command
  26. // and it is enabled
  27. //Use: Checks for quote, rage, and colors
  28. //=====================================================================
  29. public boolean onChat(Player player, String message){
  30. //Quote (Greentext)
  31. if (message.startsWith("@") ||
  32. vMinecraftSettings.getInstance().isAdminToggled(player.getName()))
  33. return vMinecraftChat.adminChat(player, message);
  34. else if (message.startsWith(">"))
  35. return vMinecraftChat.quote(player, message);
  36. //Rage (FFF)
  37. else if (message.startsWith("FFF"))
  38. return vMinecraftChat.rage(player, message);
  39. //Send through quakeColors otherwise
  40. else
  41. return vMinecraftChat.quakeColors(player, message);
  42. }
  43. //=====================================================================
  44. //Function: onCommand
  45. //Input: Player player: The player calling the command
  46. // String[] split: The arguments
  47. //Output: boolean: If the user has access to the command
  48. // and it is enabled
  49. //Use: Checks for exploits and runs the commands
  50. //=====================================================================
  51. public boolean onCommand(Player player, String[] split) {
  52. //Copy the arguments into their own array.
  53. String[] args = new String[split.length - 1];
  54. System.arraycopy(split, 1, args, 0, args.length);
  55. //Return the results of the command
  56. int exitCode = vMinecraftCommands.cl.call(split[0], player, args);
  57. if(exitCode == 0)
  58. return false;
  59. else if(exitCode == 1)
  60. return true;
  61. else
  62. return false;
  63. }
  64. //=====================================================================
  65. //Function: onHealthChange
  66. //Input: Player player: The player calling the command
  67. // int oldValue: The old health value;
  68. // int newValue: The new health value
  69. //Output: boolean: If the user has access to the command
  70. // and it is enabled
  71. //Use: Checks for exploits and runs the commands
  72. //=====================================================================
  73. public boolean onHealthChange(Player player,int oldValue,int newValue){
  74. if (vMinecraftSettings.getInstance().isEzModo(player.getName())) {
  75. return oldValue > newValue;
  76. }
  77. return false;
  78. }
  79. public void onLogin(Player player){
  80. vMinecraftUsers.addUser(player);
  81. }
  82. public boolean onIgnite(Block block, Player player) {
  83. if(vMinecraftSettings.stopFire){
  84. int x = block.getX();
  85. int y = block.getY();
  86. int z = block.getZ();
  87. if (vMinecraftSettings.fireNoSpread.contains(etc.getServer().getBlockIdAt(x + 1, y, z))
  88. || vMinecraftSettings.fireNoSpread.contains(etc.getServer().getBlockIdAt(x - 1, y, z))
  89. || vMinecraftSettings.fireNoSpread.contains(etc.getServer().getBlockIdAt(x, y + 1, z))
  90. || vMinecraftSettings.fireNoSpread.contains(etc.getServer().getBlockIdAt(x, y - 1, z))
  91. || vMinecraftSettings.fireNoSpread.contains(etc.getServer().getBlockIdAt(x, y, z + 1))
  92. || vMinecraftSettings.fireNoSpread.contains(etc.getServer().getBlockIdAt(x, y, z - 1))
  93. || vMinecraftSettings.fireNoSpread.contains(etc.getServer().getBlockIdAt(x + 1, y + 1, z + 1))
  94. || vMinecraftSettings.fireNoSpread.contains(etc.getServer().getBlockIdAt(x - 1, y - 1, z - 1))) {
  95. return true;
  96. }
  97. }
  98. return false;
  99. }
  100. public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) {
  101. if(defender.isPlayer()){
  102. Player player = (Player)defender;
  103. if (attacker.isPlayer()) {
  104. Player pAttacker = (Player)attacker;
  105. if(player.getHealth() < 1){
  106. vMinecraftChat.gmsg(player, pAttacker.getName() + " has murdered " + player.getName());
  107. }
  108. }
  109. if (player.getHealth() < 1 && !attacker.isPlayer()) {
  110. if (type == type.CREEPER_EXPLOSION) {
  111. damagetype = 1; //Creeper
  112. } else if(type == type.FALL){
  113. damagetype = 2; //Fall
  114. } else if(type == type.FIRE){
  115. damagetype = 3; //Fire going to make it share with firetick since its similar
  116. } else if (type == type.FIRE_TICK){
  117. damagetype = 4; //Firetick
  118. } else if (type == type.LAVA){
  119. damagetype = 5; //Lava
  120. } else if (type == type.WATER){
  121. damagetype = 6; //Water
  122. }
  123. //This should trigger the player death message
  124. } else if (player.getHealth() < 1 && attacker.isPlayer()){
  125. damagetype = 7; //Player
  126. }
  127. if(damagetype == 1){
  128. vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " was blown to bits by a creeper");
  129. damagetype = 0;
  130. } else if (damagetype == 2) {
  131. vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " fell to death!");
  132. damagetype = 0;
  133. } else if (damagetype ==3){
  134. vMinecraftChat.gmsg(player, player.getName() + Colors.Red + " was incinerated");
  135. damagetype = 0;
  136. } else if (damagetype == 4){
  137. vMinecraftChat.gmsg(player, Colors.Red + " Stop drop and roll, not scream, run, and burn " + player.getName());
  138. damagetype = 0;
  139. } else if (damagetype == 5){
  140. vMinecraftChat.gmsg(player, Colors.Red + player.getName() + " drowned in lava");
  141. damagetype = 0;
  142. } else if (damagetype == 6){
  143. vMinecraftChat.gmsg(player, Colors.Blue + player.getName() + " should've attended that swimming class");
  144. damagetype = 0;
  145. } else if (damagetype == 7){
  146. Player pAttacker = (Player)attacker;
  147. vMinecraftChat.gmsg(player, pAttacker.getName() + " has murdered " + player.getName());
  148. damagetype = 0;
  149. }
  150. else {
  151. vMinecraftChat.gmsg(player, Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg());
  152. }
  153. }
  154. return false;
  155. }
  156. }