PageRenderTime 31ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerModesListener.java

https://gitlab.com/igserfurtmcschulserver/CustomWorldGuard
Java | 82 lines | 45 code | 14 blank | 23 comment | 8 complexity | c0f2b9e4a71657ee6d28c26a396074f1 MD5 | raw file
  1. /*
  2. * WorldGuard, a suite of tools for Minecraft
  3. * Copyright (C) sk89q <http://www.sk89q.com>
  4. * Copyright (C) WorldGuard team and contributors
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU Lesser General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
  14. * for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.sk89q.worldguard.bukkit.listener;
  20. import com.sk89q.worldguard.bukkit.ConfigurationManager;
  21. import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
  22. import com.sk89q.worldguard.bukkit.event.player.ProcessPlayerEvent;
  23. import com.sk89q.worldguard.session.Session;
  24. import com.sk89q.worldguard.session.handler.GodMode;
  25. import com.sk89q.worldguard.session.handler.WaterBreathing;
  26. import org.bukkit.entity.Player;
  27. import org.bukkit.event.EventHandler;
  28. import java.util.logging.Level;
  29. import java.util.logging.Logger;
  30. public class PlayerModesListener extends AbstractListener {
  31. private static final Logger log = Logger.getLogger(PlayerModesListener.class.getCanonicalName());
  32. private static final String INVINCIBLE_PERMISSION = "worldguard.auto-invincible";
  33. private static final String INVINCIBLE_GROUP = "wg-invincible";
  34. private static final String AMPHIBIOUS_GROUP = "wg-amphibious";
  35. /**
  36. * Construct the listener.
  37. *
  38. * @param plugin an instance of WorldGuardPlugin
  39. */
  40. public PlayerModesListener(WorldGuardPlugin plugin) {
  41. super(plugin);
  42. }
  43. private boolean hasGodModeGroup(Player player) {
  44. return getConfig().useGodGroup && getPlugin().inGroup(player, INVINCIBLE_GROUP);
  45. }
  46. private boolean hasGodModePermission(Player player) {
  47. return getConfig().useGodPermission && getPlugin().hasPermission(player, INVINCIBLE_PERMISSION);
  48. }
  49. private boolean hasAmphibiousGroup(Player player) {
  50. return getConfig().useAmphibiousGroup && getPlugin().inGroup(player, AMPHIBIOUS_GROUP);
  51. }
  52. @EventHandler
  53. public void onProcessPlayer(ProcessPlayerEvent event) {
  54. ConfigurationManager config = getConfig();
  55. Player player = event.getPlayer();
  56. Session session = getPlugin().getSessionManager().get(player);
  57. if (hasGodModeGroup(player) || hasGodModePermission(player)) {
  58. if (GodMode.set(player, session, true)) {
  59. log.log(Level.INFO, "Enabled auto-god mode for " + player.getName());
  60. }
  61. }
  62. if (hasAmphibiousGroup(player)) {
  63. if (WaterBreathing.set(player, session, true)) {
  64. log.log(Level.INFO, "Enabled water breathing mode for " + player.getName() + " (player is in group 'wg-amphibious')");
  65. }
  66. }
  67. }
  68. }