vMinecraftListener.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.getInstance().isFrozen(player.getName())){
  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 && vMinecraftUsers.getProfile(player).isDead()){
  78. vMinecraftUsers.getProfile(player).isDead(false);
  79. if(vMinecraftSettings.getInstance().playerspawn())
  80. {
  81. Warp home = null;
  82. home = etc.getDataSource().getHome(player.getName());
  83. player.teleportTo(home.Location);
  84. }
  85. }
  86. return false;
  87. }
  88. public void onLogin(Player player){
  89. vMinecraftChat.sendMessage(player, player, Colors.Rose + "There are currently " + etc.getServer().getPlayerList().size() + " players online.");
  90. vMinecraftUsers.addUser(player);
  91. }
  92. public void onDisconnect(Player player){
  93. vMinecraftUsers.removeUser(player);
  94. }
  95. public boolean onIgnite(Block block, Player player) {
  96. if(vMinecraftSettings.stopFire){
  97. if(block.getStatus() == 3 || block.getStatus() == 1){
  98. return true;
  99. }
  100. if(block.getStatus() == 2 && !player.isAdmin()){
  101. return true;
  102. }
  103. }
  104. return false;
  105. }
  106. public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) {
  107. Player defend = null;
  108. if(defender != null && defender.isPlayer())
  109. {
  110. defend = defender.getPlayer();
  111. if (vMinecraftSettings.getInstance().isEzModo(defend.getName())) {
  112. return true;
  113. }
  114. if (defend.getHealth() > 0)
  115. return false;
  116. if (vMinecraftUsers.getProfile(defend).isDead())
  117. return false;
  118. vMinecraftUsers.getProfile(defend).isDead(true);
  119. Player attack = null;
  120. if(attacker != null && attacker.isPlayer())
  121. attack = attacker.getPlayer();
  122. if(attack != null)
  123. {
  124. vMinecraftChat.gmsg(defend.getName() + " was slain by " + attack.getName());
  125. }
  126. if (type == type.CREEPER_EXPLOSION) {
  127. vMinecraftChat.gmsg(defend.getName() + Colors.Rose + " was blown to bits by a creeper");
  128. } else if(type == type.FALL){
  129. vMinecraftChat.gmsg(defend.getName() + Colors.Rose + " fell to death!");
  130. } else if(type == type.FIRE){
  131. vMinecraftChat.gmsg(defend.getName() + Colors.Rose + " was incinerated");
  132. } else if (type == type.FIRE_TICK){
  133. vMinecraftChat.gmsg(defend.getName() + Colors.Rose + " Stop drop and roll, not scream, run, and burn ");
  134. } else if (type == type.LAVA){
  135. vMinecraftChat.gmsg(defend.getName() + Colors.Rose + " drowned in lava");
  136. } else if (type == type.WATER){
  137. log.log(Level.INFO, "Water");
  138. vMinecraftChat.gmsg(defend.getName() + Colors.Rose + " should've attended that swimming class");
  139. } else {
  140. vMinecraftChat.gmsg(Colors.Gray + defend.getName() + " " + vMinecraftSettings.randomDeathMsg());
  141. }
  142. }
  143. return false;
  144. }
  145. }