示例#1
0
	@Override
	public void onEnable()
	{
		final PluginManager pluginManager = getServer().getPluginManager();
		final IEssentials ess = (IEssentials)pluginManager.getPlugin("Essentials");
		if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion()))
		{
			LOGGER.log(Level.WARNING, _("versionMismatchAll"));
		}
		if (!ess.isEnabled())
		{
			this.setEnabled(false);
			return;
		}

		chatListener = new ConcurrentSkipListMap<String, IEssentialsChatListener>();
		final Map<PlayerChatEvent, String> charges = new HashMap<PlayerChatEvent, String>();
		

		final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, chatListener);
		final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatListener, charges);
		final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatListener, charges);
		pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerLowest, Priority.Lowest, this);
		pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerNormal, Priority.Normal, this);
		pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerHighest, Priority.Highest, this);

		LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
	}
	public void onPlayerRespawn(final PlayerRespawnEvent event)
	{
		final User user = ess.getUser(event.getPlayer());

		if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty())
		{
			return;
		}

		if (ess.getSettings().getRespawnAtHome())
		{
			Location home;
			final Location bed = user.getBedSpawnLocation();
			if (bed != null && bed.getBlock().getType() == Material.BED_BLOCK)
			{
				home = bed;
			}
			else
			{
				home = user.getHome(user.getLocation());
			}
			if (home != null)
			{
				event.setRespawnLocation(home);
				return;
			}
		}
		final Location spawn = spawns.getSpawn(user.getGroup());
		if (spawn != null)
		{
			event.setRespawnLocation(spawn);
		}
	}
示例#3
0
 public final boolean onBlockBreak(final Block block, final Player player, final IEssentials ess) {
   User user = ess.getUser(player);
   try {
     return onBlockBreak(block, user, getUsername(user), ess);
   } catch (SignException ex) {
     ess.showError(user, ex, signName);
   }
   return false;
 }
示例#4
0
 public final boolean onSignBreak(final Block block, final Player player, final IEssentials ess) {
   final ISign sign = new BlockSign(block);
   final User user = ess.getUser(player);
   try {
     return (user.isAuthorized("essentials.signs." + signName.toLowerCase() + ".break")
             || user.isAuthorized("essentials.signs.break." + signName.toLowerCase()))
         && onSignBreak(sign, user, getUsername(user), ess);
   } catch (SignException ex) {
     ess.showError(user, ex, signName);
     return false;
   }
 }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityExplode(final EntityExplodeEvent event) {
    if (event.isCancelled()) {
      return;
    }
    final int maxHeight = ess.getSettings().getProtectCreeperMaxHeight();

    if (event.getEntity() instanceof EnderDragon
        && prot.getSettingBool(ProtectConfig.prevent_enderdragon_blockdmg)) {
      event.setCancelled(true);
      if (prot.getSettingBool(ProtectConfig.enderdragon_fakeexplosions)) {
        event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
      }
      return;
    } else if (event.getEntity() instanceof Creeper
        && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
            || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg)
            || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))) {
      // Nicccccccccce plaaacccccccccce..
      event.setCancelled(true);
      event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
      return;
    } else if (event.getEntity() instanceof TNTPrimed
        && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) {
      event.setCancelled(true);
      return;
    } else if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
        && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) {
      event.setCancelled(true);
      return;
    }
    // This code will prevent explosions near protected rails, signs or protected chests
    // TODO: Use protect db instead of this code

    for (Block block : event.blockList()) {
      if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS
              || block.getType() == Material.RAILS
              || block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL
              || block.getType() == Material.POWERED_RAIL
              || block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL
              || block.getType() == Material.DETECTOR_RAIL)
          && prot.getSettingBool(ProtectConfig.protect_rails)) {
        event.setCancelled(true);
        return;
      }
      if ((block.getType() == Material.WALL_SIGN
              || block.getRelative(BlockFace.NORTH).getType() == Material.WALL_SIGN
              || block.getRelative(BlockFace.EAST).getType() == Material.WALL_SIGN
              || block.getRelative(BlockFace.SOUTH).getType() == Material.WALL_SIGN
              || block.getRelative(BlockFace.WEST).getType() == Material.WALL_SIGN
              || block.getType() == Material.SIGN_POST
              || block.getRelative(BlockFace.UP).getType() == Material.SIGN_POST)
          && prot.getSettingBool(ProtectConfig.protect_signs)) {
        event.setCancelled(true);
        return;
      }
    }
  }
  public void onEnable() {
    final PluginManager pm = this.getServer().getPluginManager();
    ess = (IEssentials) pm.getPlugin("Essentials");

    final EssentialsProtectPlayerListener playerListener =
        new EssentialsProtectPlayerListener(this);
    pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this);

    final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this);
    pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Highest, this);
    pm.registerEvent(Type.BLOCK_FROMTO, blockListener, Priority.Highest, this);
    pm.registerEvent(Type.BLOCK_IGNITE, blockListener, Priority.Highest, this);
    pm.registerEvent(Type.BLOCK_BURN, blockListener, Priority.Highest, this);
    pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
    pm.registerEvent(Type.BLOCK_PISTON_EXTEND, blockListener, Priority.Highest, this);
    pm.registerEvent(Type.BLOCK_PISTON_RETRACT, blockListener, Priority.Highest, this);

    final EssentialsProtectEntityListener entityListener =
        new EssentialsProtectEntityListener(this);
    pm.registerEvent(Type.ENTITY_EXPLODE, entityListener, Priority.Highest, this);
    pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Highest, this);
    pm.registerEvent(Type.CREATURE_SPAWN, entityListener, Priority.Highest, this);
    pm.registerEvent(Type.ENTITY_TARGET, entityListener, Priority.Highest, this);
    pm.registerEvent(Type.EXPLOSION_PRIME, entityListener, Priority.Highest, this);

    final EssentialsProtectWeatherListener weatherListener =
        new EssentialsProtectWeatherListener(this);
    pm.registerEvent(Type.LIGHTNING_STRIKE, weatherListener, Priority.Highest, this);
    pm.registerEvent(Type.THUNDER_CHANGE, weatherListener, Priority.Highest, this);
    pm.registerEvent(Type.WEATHER_CHANGE, weatherListener, Priority.Highest, this);

    reloadConfig();
    ess.addReloadListener(this);
    if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
      LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll"));
    }
    LOGGER.info(
        Util.format(
            "loadinfo",
            this.getDescription().getName(),
            this.getDescription().getVersion(),
            "essentials team"));
  }
示例#7
0
 protected final ItemStack getItemStack(
     final String itemName, final int quantity, final IEssentials ess) throws SignException {
   try {
     final ItemStack item = ess.getItemDb().get(itemName);
     item.setAmount(quantity);
     return item;
   } catch (Exception ex) {
     throw new SignException(ex.getMessage(), ex);
   }
 }
  public void reloadConfig() {
    if (storage != null) {
      storage.onPluginDeactivation();
    }
    for (ProtectConfig protectConfig : ProtectConfig.values()) {
      if (protectConfig.isList()) {
        settingsList.put(
            protectConfig, ess.getSettings().getProtectList(protectConfig.getConfigName()));
      } else if (protectConfig.isString()) {
        settingsString.put(
            protectConfig, ess.getSettings().getProtectString(protectConfig.getConfigName()));
      } else {
        settingsBoolean.put(
            protectConfig,
            ess.getSettings()
                .getProtectBoolean(
                    protectConfig.getConfigName(), protectConfig.getDefaultValueBoolean()));
      }
    }

    if (getSettingString(ProtectConfig.datatype).equalsIgnoreCase("mysql")) {
      try {
        storage =
            new ProtectedBlockMySQL(
                getSettingString(ProtectConfig.mysqlDB),
                getSettingString(ProtectConfig.dbUsername),
                getSettingString(ProtectConfig.dbPassword));
      } catch (PropertyVetoException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
      }
    } else {
      try {
        storage = new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db");
      } catch (PropertyVetoException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
      }
    }
    if (getSettingBool(ProtectConfig.memstore)) {
      storage = new ProtectedBlockMemory(storage, this);
    }
  }
	@Override
	public void onPlayerRespawn(final PlayerRespawnEvent event)
	{		
		final User user = ess.getUser(event.getPlayer());

		if (ess.getSettings().getRespawnAtHome())
		{
			Location home = user.getHome(user.getLocation());
			if (home == null)
			{
				home = user.getBedSpawnLocation();
			}
			if (home != null)
			{
				event.setRespawnLocation(home);
				return;
			}
		}
		final Location spawn = spawns.getSpawn(user.getGroup());
		if (spawn != null)
		{
			event.setRespawnLocation(spawn);
		}
	}
示例#10
0
 public final boolean onSignCreate(final SignChangeEvent event, final IEssentials ess) {
   final ISign sign = new EventSign(event);
   final User user = ess.getUser(event.getPlayer());
   if (!(user.isAuthorized("essentials.signs." + signName.toLowerCase() + ".create")
       || user.isAuthorized("essentials.signs.create." + signName.toLowerCase()))) {
     // Return true, so other plugins can use the same sign title, just hope
     // they won't change it to §1[Signname]
     return true;
   }
   sign.setLine(0, Util.format("signFormatFail", this.signName));
   try {
     final boolean ret = onSignCreate(sign, user, getUsername(user), ess);
     if (ret) {
       sign.setLine(0, getSuccessName());
     }
     return ret;
   } catch (ChargeException ex) {
     ess.showError(user, ex, signName);
   } catch (SignException ex) {
     ess.showError(user, ex, signName);
   }
   // Return true, so the player sees the wrong sign.
   return true;
 }
	public void onPlayerJoin(final PlayerJoinEvent event)
	{
		if (event.getPlayer().hasPlayedBefore())
		{
			LOGGER.log(Level.FINE, "Old player join");
			return;
		}

		final User user = ess.getUser(event.getPlayer());

		if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn()))
		{
			ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L);
		}

		if (ess.getSettings().getAnnounceNewPlayers())
		{
			final IText output = new KeywordReplacer(ess.getSettings().getAnnounceNewPlayerFormat(), user, ess);
			final SimpleTextPager pager = new SimpleTextPager(output);
			ess.broadcastMessage(user, pager.getString(0));
		}

		final String kitName = ess.getSettings().getNewPlayerKit();
		if (!kitName.isEmpty())
		{
			try
			{
				final Map<String, Object> kit = ess.getSettings().getKit(kitName.toLowerCase(Locale.ENGLISH));
				final List<String> items = Kit.getItems(user, kit);
				Kit.expandItems(ess, user, items);
			}
			catch (Exception ex)
			{
				LOGGER.log(Level.WARNING, ex.getMessage());
			}
		}

		LOGGER.log(Level.FINE, "New player join");
	}
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onCreatureSpawn(final CreatureSpawnEvent event) {
   if (event.getEntity() instanceof Player) {
     return;
   }
   if (event.isCancelled()) {
     return;
   }
   final CreatureType creature = event.getCreatureType();
   if (creature == null) {
     return;
   }
   final String creatureName = creature.toString().toLowerCase(Locale.ENGLISH);
   if (creatureName == null || creatureName.isEmpty()) {
     return;
   }
   if (ess.getSettings().getProtectPreventSpawn(creatureName)) {
     event.setCancelled(true);
   }
 }
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onEntityTarget(final EntityTargetEvent event) {
   if (event.isCancelled()) {
     return;
   }
   if (!(event.getTarget() instanceof Player)) {
     return;
   }
   final User user = ess.getUser(event.getTarget());
   if ((event.getReason() == TargetReason.CLOSEST_PLAYER
           || event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY
           || event.getReason() == TargetReason.PIG_ZOMBIE_TARGET
           || event.getReason() == TargetReason.RANDOM_TARGET
           || event.getReason() == TargetReason.TARGET_ATTACKED_OWNER
           || event.getReason() == TargetReason.OWNER_ATTACKED_TARGET)
       && prot.getSettingBool(ProtectConfig.prevent_entitytarget)
       && !user.isAuthorized("essentials.protect.entitytarget.bypass")) {
     event.setCancelled(true);
     return;
   }
 }
 @Override
 public void alert(final User user, final String item, final String type) {
   final Location loc = user.getLocation();
   final String warnMessage =
       Util.format(
           "alertFormat",
           user.getName(),
           type,
           item,
           loc.getWorld().getName()
               + ","
               + loc.getBlockX()
               + ","
               + loc.getBlockY()
               + ","
               + loc.getBlockZ());
   LOGGER.log(Level.WARNING, warnMessage);
   for (Player p : this.getServer().getOnlinePlayers()) {
     final User alertUser = ess.getUser(p);
     if (alertUser.isAuthorized("essentials.protect.alerts")) {
       alertUser.sendMessage(warnMessage);
     }
   }
 }
	@Override
	public void onPlayerJoin(final PlayerJoinEvent event)
	{
		final User user = ess.getUser(event.getPlayer());

		if (!user.isNew() || user.getBedSpawnLocation() != null)
		{
			return;
		}
		user.setNew(false);
		if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn()))
		{
			ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user));
		}

		if (ess.getSettings().getAnnounceNewPlayers())
		{
			ess.broadcastMessage(user, ess.getSettings().getAnnounceNewPlayerFormat(user));
		}
	}
	@Override
	public void onPlayerJoin(final PlayerJoinEvent event)
	{
		final User user = ess.getUser(event.getPlayer());

		if (user.hasPlayedBefore())
		{
			LOGGER.log(Level.FINE, "Old player join");
			return;
		}		
		if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn()))
		{
			ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L);
		}

		if (ess.getSettings().getAnnounceNewPlayers())
		{
			ess.broadcastMessage(user, ess.getSettings().getAnnounceNewPlayerFormat(user));
		}
		
		LOGGER.log(Level.FINE, "New player join");
	}
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityDamage(final EntityDamageEvent event) {
    if (event.isCancelled()) {
      return;
    }
    final Entity target = event.getEntity();

    if (target instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_death)) {
      event.setCancelled(true);
      return;
    }

    final User user = ess.getUser(target);
    if (event instanceof EntityDamageByBlockEvent) {
      final DamageCause cause = event.getCause();

      if (prot.getSettingBool(ProtectConfig.disable_contactdmg)
          && cause == DamageCause.CONTACT
          && !(target instanceof Player
              && user.isAuthorized("essentials.protect.damage.contact")
              && !user.isAuthorized("essentials.protect.damage.disable"))) {
        event.setCancelled(true);
        return;
      }
      if (prot.getSettingBool(ProtectConfig.disable_lavadmg)
          && cause == DamageCause.LAVA
          && !(target instanceof Player
              && user.isAuthorized("essentials.protect.damage.lava")
              && !user.isAuthorized("essentials.protect.damage.disable"))) {
        event.setCancelled(true);
        return;
      }
      if (prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)
          && cause == DamageCause.BLOCK_EXPLOSION
          && !(target instanceof Player
              && user.isAuthorized("essentials.protect.damage.tnt")
              && !user.isAuthorized("essentials.protect.damage.disable"))) {
        event.setCancelled(true);
        return;
      }
    }

    if (event instanceof EntityDamageByEntityEvent) {
      final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent) event;
      final Entity eAttack = edEvent.getDamager();
      final User attacker = ess.getUser(eAttack);

      // PVP Settings
      if (target instanceof Player
          && eAttack instanceof Player
          && prot.getSettingBool(ProtectConfig.disable_pvp)
          && (!user.isAuthorized("essentials.protect.pvp")
              || !attacker.isAuthorized("essentials.protect.pvp"))) {
        event.setCancelled(true);
        return;
      }

      // Creeper explode prevention
      if (eAttack instanceof Creeper
          && prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
          && !(target instanceof Player
              && user.isAuthorized("essentials.protect.damage.creeper")
              && !user.isAuthorized("essentials.protect.damage.disable"))) {
        event.setCancelled(true);
        return;
      }

      if (eAttack instanceof Creeper
          && prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg)
          && !(target instanceof Player
              && user.isAuthorized("essentials.protect.damage.creeper")
              && !user.isAuthorized("essentials.protect.damage.disable"))) {
        event.setCancelled(true);
        return;
      }

      if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
          && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg)
          && !(target instanceof Player
              && user.isAuthorized("essentials.protect.damage.fireball")
              && !user.isAuthorized("essentials.protect.damage.disable"))) {
        event.setCancelled(true);
        return;
      }

      if (eAttack instanceof TNTPrimed
          && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg)
          && !(target instanceof Player
              && user.isAuthorized("essentials.protect.damage.tnt")
              && !user.isAuthorized("essentials.protect.damage.disable"))) {
        event.setCancelled(true);
        return;
      }

      if (edEvent.getDamager() instanceof Projectile
          && target instanceof Player
          && ((prot.getSettingBool(ProtectConfig.disable_projectiles)
                  && !(user.isAuthorized("essentials.protect.damage.projectiles")
                      && !user.isAuthorized("essentials.protect.damage.disable")))
              || (((Projectile) edEvent.getDamager()).getShooter() instanceof Player
                  && prot.getSettingBool(ProtectConfig.disable_pvp)
                  && (!user.isAuthorized("essentials.protect.pvp")
                      || !ess.getUser(((Projectile) edEvent.getDamager()).getShooter())
                          .isAuthorized("essentials.protect.pvp"))))) {
        event.setCancelled(true);
        return;
      }
    }

    final DamageCause cause = event.getCause();
    if (target instanceof Player) {
      if (cause == DamageCause.FALL
          && prot.getSettingBool(ProtectConfig.disable_fall)
          && !(user.isAuthorized("essentials.protect.damage.fall")
              && !user.isAuthorized("essentials.protect.damage.disable"))) {
        event.setCancelled(true);
        return;
      }

      if (cause == DamageCause.SUFFOCATION
          && prot.getSettingBool(ProtectConfig.disable_suffocate)
          && !(user.isAuthorized("essentials.protect.damage.suffocation")
              && !user.isAuthorized("essentials.protect.damage.disable"))) {
        event.setCancelled(true);
        return;
      }
      if ((cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK)
          && prot.getSettingBool(ProtectConfig.disable_firedmg)
          && !(user.isAuthorized("essentials.protect.damage.fire")
              && !user.isAuthorized("essentials.protect.damage.disable"))) {
        event.setCancelled(true);
        return;
      }
      if (cause == DamageCause.DROWNING
          && prot.getSettingBool(ProtectConfig.disable_drown)
          && !(user.isAuthorized("essentials.protect.damage.drowning")
              && !user.isAuthorized("essentials.protect.damage.disable"))) {
        event.setCancelled(true);
        return;
      }
      if (cause == DamageCause.LIGHTNING
          && prot.getSettingBool(ProtectConfig.disable_lightning)
          && !(user.isAuthorized("essentials.protect.damage.lightning")
              && !user.isAuthorized("essentials.protect.damage.disable"))) {
        event.setCancelled(true);
        return;
      }
    }
  }