vListener.java 8.6 KB

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