vMinecraftListener.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. //Invincibility for EzModo players
  78. if(vMinecraftSettings.getInstance().isEzModo(player.getName())){
  79. return false;
  80. }
  81. //Sets a player as dead
  82. if (player.getHealth() < 1){
  83. vMinecraftUsers.getProfile(player).isDead(true);
  84. }
  85. if (player.getHealth() > 1 && vMinecraftUsers.getProfile(player).isDead()){
  86. if(vMinecraftSettings.getInstance().playerspawn())
  87. {
  88. Warp home = null;
  89. home = etc.getDataSource().getHome(player.getName());
  90. player.teleportTo(home.Location);
  91. //Makes sure the player has a custom home before telling them about /myspawn
  92. if(etc.getServer().getSpawnLocation() != etc.getDataSource().getHome(player.getName()).Location){
  93. vMinecraftChat.sendMessage(player, Colors.DarkPurple + "Return here with /myspawn, the penalty for returning is the complete loss of inventory");
  94. } else {
  95. vMinecraftChat.sendMessage(player, Colors.DarkPurple + "Set your own spawn with /myspawn");
  96. }
  97. }
  98. vMinecraftUsers.getProfile(player).isDead(false);
  99. vMinecraftChat.gmsg(Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg());
  100. }
  101. return false;
  102. }
  103. public void onLogin(Player player){
  104. vMinecraftChat.sendMessage(player, player, Colors.Rose + "There are currently " + etc.getServer().getPlayerList().size() + " players online.");
  105. vMinecraftUsers.addUser(player);
  106. }
  107. public void onDisconnect(Player player){
  108. vMinecraftUsers.removeUser(player);
  109. }
  110. public boolean onIgnite(Block block, Player player) {
  111. if(vMinecraftSettings.getInstance().stopFire()){
  112. //There are 3 ways fire can spread
  113. //1 = lava, 2 = lighter, 3 = spread (other fire blocks)
  114. //Stop lava from spreading
  115. if(block.getStatus() == 1 && vMinecraftSettings.getInstance().lavaSpread()){
  116. return true;
  117. }
  118. //Stop fire from spreading fire
  119. if (block.getStatus() == 3 && vMinecraftSettings.getInstance().stopFire()){
  120. return true;
  121. }
  122. //Checking to see if any of the blocks fire is trying to spread to is on the "fireblockan" list
  123. if (block.getStatus() == 3){
  124. int x,
  125. y,
  126. z,
  127. g;
  128. x = block.getX();
  129. y = block.getY();
  130. z = block.getZ();
  131. //Finding out the blockid of the current blocks fire is trying to spread to
  132. int blockid = etc.getServer().getBlockIdAt(x, y, z);
  133. //Check to see the blockid doesn't match anything on the list
  134. for(x = 0; x >= vMinecraftSettings.fireblockan.size(); x++){
  135. if (vMinecraftSettings.fireblockan.get(x) == blockid){
  136. return true;
  137. }
  138. }
  139. }
  140. //Stop players without permission from being able to set fires
  141. if(block.getStatus() == 2 && !player.canUseCommand("/flint")){
  142. return true;
  143. }
  144. }
  145. return false;
  146. }
  147. public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) {
  148. return false;
  149. }
  150. }