vMinecraftListener.java 5.5 KB

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