vListener.java 8.4 KB

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