vMinecraftListener.java 5.5 KB

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