vMinecraftListener.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. }
  24. //=====================================================================
  25. //Function: onChat
  26. //Input: Player player: The player calling the command
  27. // String message: The message to color
  28. //Output: boolean: If the user has access to the command
  29. // and it is enabled
  30. //Use: Checks for quote, rage, and colors
  31. //=====================================================================
  32. public boolean onChat(Player player, String message){
  33. //Quote (Greentext)
  34. if (message.startsWith("@") ||
  35. vMinecraftSettings.getInstance().isAdminToggled(player.getName()))
  36. return vMinecraftChat.adminChat(player, message);
  37. else if (message.startsWith(">"))
  38. return vMinecraftChat.quote(player, message);
  39. //Rage (FFF)
  40. else if (message.startsWith("FFF"))
  41. return vMinecraftChat.rage(player, message);
  42. //Send through quakeColors otherwise
  43. else
  44. return vMinecraftChat.quakeColors(player, message);
  45. }
  46. //=====================================================================
  47. //Function: onCommand
  48. //Input: Player player: The player calling the command
  49. // String[] split: The arguments
  50. //Output: boolean: If the user has access to the command
  51. // and it is enabled
  52. //Use: Checks for exploits and runs the commands
  53. //=====================================================================
  54. public boolean onCommand(Player player, String[] split) {
  55. //Copy the arguments into their own array.
  56. String[] args = new String[split.length - 1];
  57. System.arraycopy(split, 1, args, 0, args.length);
  58. //Return the results of the command
  59. int exitCode = vMinecraftCommands.cl.call(split[0], player, args);
  60. if(exitCode == 0)
  61. return false;
  62. else if(exitCode == 1)
  63. return true;
  64. else
  65. return false;
  66. }
  67. //=====================================================================
  68. //Function: onHealthChange
  69. //Input: Player player: The player calling the command
  70. // int oldValue: The old health value;
  71. // int newValue: The new health value
  72. //Output: boolean: If the user has access to the command
  73. // and it is enabled
  74. //Use: Checks for exploits and runs the commands
  75. //=====================================================================
  76. public boolean onHealthChange(Player player,int oldValue,int newValue){
  77. //Sets a player as dead
  78. if (player.getHealth() < 1){
  79. vMinecraftUsers.getProfile(player).isDead(true);
  80. }
  81. if (player.getHealth() > 1 && vMinecraftUsers.getProfile(player).isDead()){
  82. if(vMinecraftSettings.getInstance().playerspawn())
  83. {
  84. Warp home = null;
  85. home = etc.getDataSource().getHome(player.getName());
  86. player.teleportTo(home.Location);
  87. //Makes sure the player has a custom home before telling them about /myspawn
  88. if(etc.getServer().getSpawnLocation() != etc.getDataSource().getHome(player.getName()).Location){
  89. player.sendMessage(Colors.DarkPurple + "Return here with /myspawn, the penalty for returning is the complete loss of inventory");
  90. } else {
  91. player.sendMessage(Colors.DarkPurple + "Set your own spawn with /myspawn");
  92. }
  93. }
  94. vMinecraftUsers.getProfile(player).isDead(false);
  95. vMinecraftChat.gmsg(Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg());
  96. }
  97. return false;
  98. }
  99. public void onLogin(Player player){
  100. vMinecraftChat.sendMessage(player, player, Colors.Rose + "There are currently " + etc.getServer().getPlayerList().size() + " players online.");
  101. vMinecraftUsers.addUser(player);
  102. }
  103. public void onDisconnect(Player player){
  104. vMinecraftUsers.removeUser(player);
  105. }
  106. public boolean onIgnite(Block block, Player player) {
  107. if(vMinecraftSettings.stopFire){
  108. if(block.getStatus() == 3 || block.getStatus() == 1){
  109. return true;
  110. }
  111. if(block.getStatus() == 2 && !player.isAdmin()){
  112. return true;
  113. }
  114. }
  115. return false;
  116. }
  117. public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) {
  118. return false;
  119. }
  120. }