vMinecraftListener.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. vMinecraftCommands.updateInvisibleForAll();
  24. }
  25. //=====================================================================
  26. //Function: onChat
  27. //Input: Player player: The player calling the command
  28. // String message: The message to color
  29. //Output: boolean: If the user has access to the command
  30. // and it is enabled
  31. //Use: Checks for quote, rage, and colors
  32. //=====================================================================
  33. public boolean onChat(Player player, String message){
  34. //Quote (Greentext)
  35. if (message.startsWith("@") ||
  36. vMinecraftSettings.getInstance().isAdminToggled(player.getName()))
  37. return vMinecraftChat.adminChat(player, message);
  38. else if (message.startsWith(">"))
  39. return vMinecraftChat.quote(player, message);
  40. //Rage (FFF)
  41. else if (message.startsWith("FFF"))
  42. return vMinecraftChat.rage(player, message);
  43. //Send through quakeColors otherwise
  44. else
  45. return vMinecraftChat.quakeColors(player, message);
  46. }
  47. //=====================================================================
  48. //Function: onCommand
  49. //Input: Player player: The player calling the command
  50. // String[] split: The arguments
  51. //Output: boolean: If the user has access to the command
  52. // and it is enabled
  53. //Use: Checks for exploits and runs the commands
  54. //=====================================================================
  55. public boolean onCommand(Player player, String[] split) {
  56. //Copy the arguments into their own array.
  57. String[] args = new String[split.length - 1];
  58. System.arraycopy(split, 1, args, 0, args.length);
  59. //Return the results of the command
  60. int exitCode = vMinecraftCommands.cl.call(split[0], player, args);
  61. if(exitCode == 0)
  62. return false;
  63. else if(exitCode == 1)
  64. return true;
  65. else
  66. return false;
  67. }
  68. //=====================================================================
  69. //Function: onHealthChange
  70. //Input: Player player: The player calling the command
  71. // int oldValue: The old health value;
  72. // int newValue: The new health value
  73. //Output: boolean: If the user has access to the command
  74. // and it is enabled
  75. //Use: Checks for exploits and runs the commands
  76. //=====================================================================
  77. public boolean onHealthChange(Player player,int oldValue,int newValue){
  78. //Sets a player as dead
  79. if (player.getHealth() < 1){
  80. vMinecraftUsers.getProfile(player).isDead(true);
  81. }
  82. if (player.getHealth() > 1 && vMinecraftUsers.getProfile(player).isDead()){
  83. if(vMinecraftSettings.getInstance().playerspawn())
  84. {
  85. Warp home = null;
  86. if (etc.getDataSource().getHome(player.getName()) != null){
  87. home = etc.getDataSource().getHome(player.getName());
  88. player.teleportTo(home.Location);
  89. player.sendMessage(Colors.DarkPurple + "Return here with /myspawn");
  90. player.sendMessage(Colors.DarkPurple + "The penalty for returning is the loss of inventory");
  91. }
  92. if(player.canUseCommand("/sethome"))
  93. player.sendMessage(Colors.DarkPurple + "Set your own spawn with /sethome");
  94. }
  95. vMinecraftUsers.getProfile(player).isDead(false);
  96. if(!vMinecraftUsers.getProfile(player).isSilent())
  97. vMinecraftChat.gmsg(Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg());
  98. }
  99. return false;
  100. }
  101. public void onLogin(Player player){
  102. vMinecraftChat.sendMessage(player, player, Colors.Rose + "There are currently " + etc.getServer().getPlayerList().size() + " players online.");
  103. vMinecraftUsers.addUser(player);
  104. }
  105. public void onDisconnect(Player player){
  106. vMinecraftUsers.removeUser(player);
  107. }
  108. public boolean onIgnite(Block block, Player player) {
  109. if(vMinecraftSettings.getInstance().stopFire()){
  110. //There are 3 ways fire can spread
  111. //1 = lava, 2 = lighter, 3 = spread (other fire blocks)
  112. //Stop lava from spreading
  113. if(block.getStatus() == 1 && vMinecraftSettings.getInstance().lavaSpread()){
  114. return true;
  115. }
  116. //Stop fire from spreading fire
  117. if (block.getStatus() == 3 && vMinecraftSettings.getInstance().stopFire()){
  118. return true;
  119. }
  120. //Checking to see if any of the blocks fire is trying to spread to is on the "fireblockan" list
  121. if (block.getStatus() == 3){
  122. int x,
  123. y,
  124. z,
  125. g;
  126. x = block.getX();
  127. y = block.getY();
  128. z = block.getZ();
  129. //Finding out the blockid of the current blocks fire is trying to spread to
  130. int blockid = etc.getServer().getBlockIdAt(x, y, z);
  131. //Check to see the blockid doesn't match anything on the list
  132. for(x = 0; x >= vMinecraftSettings.fireblockan.size(); x++){
  133. if (vMinecraftSettings.fireblockan.get(x) == blockid){
  134. return true;
  135. }
  136. }
  137. }
  138. //Stop players without permission from being able to set fires
  139. if(block.getStatus() == 2 && !player.canUseCommand("/flint")){
  140. return true;
  141. }
  142. }
  143. return false;
  144. }
  145. public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) {
  146. //Invincibility for EzModo players
  147. if(defender.isPlayer()){
  148. Player dplayer = defender.getPlayer();
  149. if(vMinecraftSettings.getInstance().isEzModo(dplayer.getName())){
  150. return true;
  151. }
  152. if(attacker != null && attacker.isPlayer()){
  153. Player aplayer = attacker.getPlayer();
  154. if(vMinecraftUsers.getProfile(dplayer).inParty()){
  155. if(vMinecraftParty.inSameParty(aplayer, dplayer)){
  156. return true;
  157. } else{
  158. return false;
  159. }
  160. }
  161. else {
  162. return false;
  163. }
  164. }
  165. }
  166. return false;
  167. }
  168. }