vMinecraftListener.java 5.8 KB

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