vMinecraftListener.java 7.4 KB

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