vListener.java 8.6 KB

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