@EventHandler
  public void onPlayerInteract(PlayerInteractEvent e) {
    Player p = e.getPlayer();

    if (e.getAction() != Action.RIGHT_CLICK_BLOCK || p.getItemInHand().getType() != sc.getTool()) {
      return;
    }

    Block block = e.getClickedBlock();

    if (block.getType() != Material.MOB_SPAWNER) {
      return;
    }

    CreatureSpawner cs = (CreatureSpawner) block.getState();
    Spawner s = sc.getSpawner(block.getLocation());

    if (s == null) {
      return;
    }

    if (s.getOwner().equals(p.getName()) || p.hasPermission("sc.bypass")) {
      EntityType currentMob = cs.getSpawnedType();
      ActiveList<EntityType> al = sc.buildAllowed(p);

      if (al.isEmpty()) {
        p.sendMessage(sc.getMsg("NO_PERMISSION_SET"));
        return;
      }

      if (al.contains(currentMob)) {
        al.setActive(currentMob);
      }

      al.setActive(al.next());
      s.setMobType(al.getActive());
      s.setDate(new Date());
      cs.setSpawnedType(al.getActive());
      cs.update();

      if (s.getOwner().equals(p.getName()) && currentMob != al.getActive()) {
        p.sendMessage(
            String.format(
                sc.getMsg("CHANGED_MONSTER"), currentMob.getName(), al.getActive().getName()));
      } else {
        p.sendMessage(
            String.format(
                sc.getMsg("CHANGED_MONSTER_OTHER"),
                s.getOwner(),
                currentMob.getName(),
                al.getActive().getName()));
      }

      sc.writeDataAsynchronously();
      return;
    }

    p.sendMessage(String.format(sc.getMsg("OWNER_IS"), s.getOwner()));
  }
  public void setSpawnedType(EntityType entityType) {
    if (entityType == null || entityType.getName() == null) {
      throw new IllegalArgumentException(
          "Can't spawn EntityType " + entityType + " from mobspawners!");
    }

    spawner.setMobID(entityType.getName());
  }
Example #3
0
 @SuppressWarnings("deprecation")
 public static String getName(EntityType paramEntityType) {
   for (String str : creatureMap.keySet()) {
     if (creatureMap.get(str) == paramEntityType) {
       return str;
     }
   }
   return paramEntityType.getName();
 }
Example #4
0
  /*
   * Another example of a event handler. This one will give you the name of
   * the entity you interact with, if it is a Creature it will give you the
   * creature Id.
   */
  @EventHandler
  public void onPlayerInteract(PlayerInteractEntityEvent event) {
    final EntityType entityType = event.getRightClicked().getType();

    event
        .getPlayer()
        .sendMessage(
            MessageFormat.format(
                "You interacted with a {0} it has an id of {1}",
                entityType.getName(), entityType.getTypeId()));
  }
  private AbstractRewardSource getRewardSource(EntityType entityType) {
    AbstractRewardSource source = null;

    if (hasRewardSource(entityType)) {
      source = getSources().get(entityType).get(nextInt(getSources().get(entityType).size()));
    } else {
      LoggerUtil.getInstance()
          .debug(this.getClass(), "No reward defined for entity type: " + entityType.getName());
    }

    return source;
  }
Example #6
0
 public static void load() {
   final FileConfiguration config = UDSPlugin.getPlugin().getConfig();
   BLOCK_CREEPERS = config.getBoolean("block.creeper");
   BLOCK_ENDERMEN = config.getBoolean("block.endermen");
   BLOCK_SILVERFISH = config.getBoolean("block.silverfish");
   BLOCK_TNT = config.getBoolean("block.tnt");
   BLOCK_WITHER = config.getBoolean("block.wither");
   MAP_DATA = (byte) config.getInt("map-data");
   BASE_COST = config.getInt("cost.base");
   BUILD_COST = config.getInt("cost.build");
   CITY_COST = config.getInt("cost.city");
   CLAN_COST = config.getInt("cost.clan");
   EXPAND_COST = config.getInt("cost.expand");
   HOME_COST = config.getInt("cost.home");
   MAP_COST = config.getInt("cost.map");
   SHOP_COST = config.getInt("cost.shop");
   VIP_COST = config.getInt("cost.vip");
   UNDO_COUNT = config.getInt("range.undo");
   DRAIN_RANGE = config.getInt("range.drain");
   MOVE_RANGE = config.getInt("range.move");
   EDIT_RANGE = config.getInt("range.edit");
   COMPASS_RANGE = config.getInt("range.compass");
   BUTCHER_RANGE = config.getInt("range.butcher");
   VIP_SPAWNS = config.getInt("vip.spawns");
   WORLD_BORDER = config.getInt("range.world");
   WORLD_BORDER_SQRD = WORLD_BORDER * WORLD_BORDER;
   SPAWNER_EXP = config.getInt("exp.spawner");
   REQUEST_TTL = config.getLong("request-timeout") * TimeUtils.SECOND;
   MINECART_TTL = config.getLong("minecart.life") * TimeUtils.SECOND;
   PVP_TIME = config.getLong("pvp-time") * TimeUtils.SECOND;
   SLOW_TIME = config.getLong("auto-save") * TimeUtils.MINUTE;
   DRAGON_RESPAWN = config.getLong("respawn-dragon") * TimeUtils.MINUTE;
   VIP_TIME = config.getLong("vip.time") * TimeUtils.DAY;
   CURRENCIES = config.getString("currency.plural");
   WELCOME_MSG = config.getString("welcome.message");
   WELCOME_ADMIN = config.getString("welcome.admin");
   SERVER_OWNER = config.getString("server-owner");
   CURRENCY = config.getString("currency.singular");
   MAIN_WORLD = config.getString("world-name");
   WELCOME_GIFT = Material.getMaterial(config.getString("welcome.gift"));
   if (WELCOME_GIFT == null) WELCOME_GIFT = Material.EMERALD;
   SERVER_RULES = config.getStringList("server-rules");
   PISTON_POWER = config.getDouble("piston-power");
   SHARES = config.getStringList("inventory-shares");
   GMAIL_ADDRESS = config.getString("gmail.email");
   SKULL = config.getDouble("head-drop-chance");
   GMAIL_PASSWORD = config.getString("gmail.password");
   VIP_WHITELIST.clear();
   for (int typeId : config.getIntegerList("item-whitelist")) {
     VIP_WHITELIST.add(Material.getMaterial(typeId));
   }
   KITS.clear();
   for (String kit : config.getStringList("kits")) {
     final String[] kitSplit = kit.split(",");
     final List<ItemStack> items =
         new ArrayList<ItemStack>(ArrayUtils.subarray(kitSplit, 3, kitSplit.length - 1).length);
     for (Object item : ArrayUtils.subarray(kitSplit, 3, kitSplit.length - 1)) {
       items.add(new ItemStack(Material.getMaterial(Integer.parseInt((String) item))));
     }
     KITS.add(
         new Kit(
             kitSplit[0],
             Integer.parseInt(kitSplit[1]),
             items,
             PlayerRank.getByName(kitSplit[2])));
   }
   MOB_REWARDS.clear();
   for (EntityType entityType : EntityType.values()) {
     String entityName = "mob-rewards." + entityType.getName();
     if (entityName != null) {
       entityName = entityName.toLowerCase();
       MOB_REWARDS.put(entityType, config.getInt(entityName));
     }
   }
   GLOBAL_FLAGS.clear();
   for (RegionFlag flag : RegionFlag.values()) {
     final String flagname = "global-flags." + flag.toString().toLowerCase();
     GLOBAL_FLAGS.put(flag, config.getBoolean(flagname));
   }
 }
 @EventHandler(priority = EventPriority.LOW)
 public void onEntityDeath(EntityDeathEvent event) {
   if (event.getEntity() == event.getEntity().getKiller()) return;
   Player player = getLastDamager(event.getEntity());
   EntityType creature = event.getEntity().getType();
   if (player == null) return;
   if (player.getGameMode() == GameMode.CREATIVE
       && !getPlugin().getSettingsManager().isG_ALLOW_CREATIVE()) {
     return;
   }
   if (!getPlugin().getPermissionManager().hasPermission(player, "mbr.user.collect")) {
     return;
   }
   double amount = getPlugin().getAPI().getEntityValue(event.getEntity());
   if (amount == 0.0) {
     return;
   }
   if (amount < 0.0
       && getPlugin().getPermissionManager().hasPermission(player, "mbr.user.finebypass")) {
     return;
   }
   MobBountyReloadedPaymentEvent mbrpe =
       new MobBountyReloadedPaymentEvent(player.getName(), amount, event.getEntity());
   getPlugin().getServer().getPluginManager().callEvent(mbrpe);
   MobBountyReloadedKillstreakEvent mbrke = null;
   List<String> creatureNames = getPlugin().getSettingsManager().getKS_ALLOWED_CREATURES();
   if (creatureNames == null) {
     creatureNames = new ArrayList<String>();
   }
   if (creatureNames.contains(creature.getName())) {
     mbrke = new MobBountyReloadedKillstreakEvent(player.getName(), event.getEntity());
     getPlugin().getServer().getPluginManager().callEvent(mbrke);
   }
   if (!mbrpe.isCancelled()) {
     Player playerEvent = Bukkit.getServer().getPlayer(mbrpe.getPlayerName());
     if (playerEvent != null) {
       MobBountyPlayerKillData playerKillData = MobBountyAPI.playerData.get(playerEvent.getName());
       if (playerKillData == null) {
         playerKillData = new MobBountyPlayerKillData();
         MobBountyAPI.playerData.put(playerEvent.getName(), playerKillData);
       }
       double amountEvent = mbrpe.getAmount();
       if (amountEvent != 0.0) {
         double mult = getPlugin().getAPI().getMult(playerEvent);
         double amt = mult * amountEvent;
         getPlugin().getAPI().makeTransaction(mbrpe.getPlayerName(), amt);
         boolean bln = getPlugin().getSettingsManager().isG_KILLCACHE_USE();
         if (bln) {
           handleKillCache(playerEvent, playerKillData, amt);
         } else {
           sendNonKillCache(mbrpe, playerEvent, amountEvent, amt);
         }
       }
     }
   }
   if (mbrke != null && !mbrke.isCancelled()) {
     MobBountyPlayerKillData playerData = MobBountyAPI.playerData.get(mbrke.getPlayerName());
     if (playerData == null) {
       playerData = new MobBountyPlayerKillData();
       MobBountyAPI.playerData.put(mbrke.getPlayerName(), playerData);
     }
     playerData.killStreak++;
     Double confBonus =
         getPlugin()
             .getSettingsManager()
             .getKS_KILLBONUSES()
             .get(String.valueOf(playerData.killStreak));
     if (confBonus == null || confBonus == 0.0) {
       return;
     }
     getPlugin().getEconManager().payAccount(mbrke.getPlayerName(), confBonus);
     Player playerEvent = getPlugin().getServer().getPlayer(mbrke.getPlayerName());
     if (playerEvent != null) {
       String string = getPlugin().getSettingsManager().getL_MESSAGES().get("Killstreak");
       if (string != null) {
         getPlugin()
             .getAPI()
             .sendMessage(
                 playerEvent,
                 getPlugin()
                     .getAPI()
                     .formatString(
                         string,
                         playerEvent.getName(),
                         mbrke.getEntity().getType().getName(),
                         playerEvent.getWorld().getName(),
                         confBonus,
                         confBonus,
                         confBonus,
                         "",
                         "",
                         "",
                         "",
                         "",
                         0,
                         "",
                         "",
                         playerData.killStreak));
       }
       MobBountyAPI.playerData.put(playerEvent.getName(), playerData);
     }
   }
 }
Example #8
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onCreatureSpawn(CreatureSpawnEvent evt) {

    Location l = evt.getEntity().getLocation();
    World w = l.getWorld();
    Chunk c = w.getChunkAt(l);

    Region r;

    ArrayList<Region> regionSet = new ArrayList<Region>();

    for (Region region : GlobalRegionManager.getRegions()) {
      for (Chunk chunk : region.getChunkGrid().getChunks()) {
        if (chunk.getWorld() == w) {
          if (areChunksEqual(chunk, c)) {
            if (!regionSet.contains(region)) {
              regionSet.add(region);
            }
          }
        }
      }
    }

    if (regionSet.isEmpty()) {
      if (GlobalRegionManager.getGlobalWorldSetting(w) != null) {
        if (!GlobalRegionManager.getGlobalWorldSetting(w).canCreatureSpawn(evt.getEntityType())) {
          evt.setCancelled(true);
        }
        return;
      }
    }

    ArrayList<Region> currentRegionSet = new ArrayList<Region>();

    for (Region reg : regionSet) {
      if (extReg.isInsideCuboid(
          l, reg.getL1().toBukkitLocation(), reg.getL2().toBukkitLocation())) {
        currentRegionSet.add(reg);
      }
    }

    if (currentRegionSet.isEmpty()) { // If player is in chunk range but not
      // inside region then cancel the
      // check.
      if (GlobalRegionManager.getGlobalWorldSetting(w) != null) {
        if (!GlobalRegionManager.getGlobalWorldSetting(w).canCreatureSpawn(evt.getEntityType())) {
          evt.setCancelled(true);
        }
      }
      return;
    }

    if (currentRegionSet.size() > 1) {
      r = srm.getCurrentRegion(null, currentRegionSet);
    } else {
      r = currentRegionSet.get(0);
    }

    if (!r.canMobsSpawn()) {
      EntityType ce = evt.getEntityType();
      if (ce == EntityType.CHICKEN
          || ce == EntityType.COW
          || ce == EntityType.PIG
          || ce == EntityType.SHEEP
          || ce == EntityType.SQUID) {
        LogRunner.addLogMessage(
            r,
            LogRunner.getPrefix(r)
                + (" Mob '" + ce.getName() + "' tried to spawn but was prevented."));
        evt.setCancelled(true);
        return;
      }
    }

    if (!r.canMonstersSpawn()) {
      EntityType ce = evt.getEntityType();
      if (ce != EntityType.CHICKEN
          && ce != EntityType.COW
          && ce != EntityType.PIG
          && ce != EntityType.SHEEP
          && ce != EntityType.SQUID) {
        LogRunner.addLogMessage(
            r,
            LogRunner.getPrefix(r)
                + (" Monster '" + ce.getName() + "' tried to spawn but was prevented."));
        evt.setCancelled(true);
        return;
      }
    }
  }
Example #9
0
 @Override
 public void save(DataKey key) {
   key.setString("", type.getName());
 }