vListener.java 7.9 KB

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