vMinecraftListener.java 6.0 KB

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