@EventHandler
 void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
   if (event.getPlayer().hasMetadata("give-pet")) {
     if (event.getRightClicked() instanceof Tameable) {
       Tameable pet = (Tameable) event.getRightClicked();
       if (pet.isTamed() && pet.getOwner() instanceof Player) {
         Player player = (Player) pet.getOwner();
         if (player.equals(event.getPlayer())
             || event.getPlayer().hasPermission("omneity3.give-pet.override")) {
           OfflinePlayer reciever =
               plugin
                   .getServer()
                   .getOfflinePlayer(
                       (String) event.getPlayer().getMetadata("give-pet").get(0).value());
           pet.setOwner(reciever);
           event.getPlayer().removeMetadata("give-pet", plugin);
         } else {
           event.getPlayer().sendMessage("This pet is not yours to give");
           event.getPlayer().removeMetadata("give-pet", plugin);
         }
       } else {
         event.getPlayer().sendMessage("This pet is not tamed");
         event.getPlayer().removeMetadata("give-pet", plugin);
       }
     } else {
       event.getPlayer().sendMessage("That entity can not be a pet");
       event.getPlayer().removeMetadata("give-pet", plugin);
     }
   }
 }
Example #2
0
 public static void addSeconds(final Player player, final int seconds) {
   if (!b******g.fdsjfhkdsjfdsjhk().getServerHandler().isEOTW()
       && DTRBitmaskType.SAFE_ZONE.appliesAt(player.getLocation())) {
     return;
   }
   if (isTagged(player)) {
     final int secondsTaggedFor =
         (int)
             ((SpawnTagHandler.spawnTags.get(player.getName()) - System.currentTimeMillis())
                 / 1000L);
     final int newSeconds = Math.min(secondsTaggedFor + seconds, 60);
     SpawnTagHandler.spawnTags.put(
         player.getName(), System.currentTimeMillis() + newSeconds * 1000L);
   } else {
     player.sendMessage(
         ChatColor.YELLOW + "You have been spawn-tagged for §c" + seconds + " §eseconds!");
     SpawnTagHandler.spawnTags.put(player.getName(), System.currentTimeMillis() + seconds * 1000L);
   }
 }
Example #3
0
 public static boolean isTagged(final Player player) {
   return SpawnTagHandler.spawnTags.containsKey(player.getName())
       && SpawnTagHandler.spawnTags.get(player.getName()) > System.currentTimeMillis();
 }
Example #4
0
 public static long getTag(final Player player) {
   return SpawnTagHandler.spawnTags.get(player.getName()) - System.currentTimeMillis();
 }
Example #5
0
 public static void removeTag(final Player player) {
   SpawnTagHandler.spawnTags.remove(player.getName());
 }
Example #6
0
  @EventHandler
  public void onDrop(EntityDamageEvent event) {
    if (!event.getEntity().getWorld().getName().equals(name)) return;
    if (event.getEntity() instanceof Player) return;

    final Entity e = event.getEntity();
    EntityType et = e.getType();
    final Location loc = e.getLocation();
    if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
      if (et == EntityType.CREEPER) {
        Bukkit.getScheduler()
            .runTaskLater(
                MapsPlugin.getInstance(),
                new Runnable() {
                  public void run() {
                    loc.getWorld().createExplosion(loc, (float) 4);
                  }
                },
                30);
      } else if (et == EntityType.COW) {
        Random rdom = new Random();

        for (int i = 0; i <= 3; i++) {
          loc.getWorld()
              .spawnEntity(loc, EntityType.PRIMED_TNT)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 1.5, rdom.nextDouble() - 0.5));
        }

      } else if (et == EntityType.PIG) {
        Random rdom = new Random();
        loc.getWorld()
            .spawnEntity(loc, EntityType.PIG_ZOMBIE)
            .setVelocity(new Vector(rdom.nextDouble(), 3, rdom.nextDouble()));
      } else if (et == EntityType.PIG_ZOMBIE) {
        Bukkit.getScheduler()
            .runTaskLater(
                MapsPlugin.getInstance(),
                new Runnable() {
                  public void run() {
                    loc.getWorld().createExplosion(loc, (float) 6);
                  }
                },
                30);
      } else if (et == EntityType.SHEEP) {
        Random rdom = new Random();

        for (int i = 0; i <= 10; i++) {
          loc.getWorld()
              .spawnFallingBlock(loc, Material.WOOL, (byte) 0)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 2, rdom.nextDouble() - 0.5));
        }

      } else if (et == EntityType.SQUID) {
        Random rdom = new Random();
        loc.getWorld()
            .spawnFallingBlock(loc, Material.WATER, (byte) 0)
            .setVelocity(new Vector(rdom.nextDouble() - 0.5, 1, rdom.nextDouble() - 0.5));
      } else if (et == EntityType.WOLF) {
        Random rdom = new Random();
        List<Entity> l = e.getNearbyEntities(3, 3, 3);

        for (Entity ee : l) {
          if (ee instanceof Player) {
            Player p = (Player) ee;
            p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 5, 1));
          }
        }
      } else if (et == EntityType.OCELOT) {
        Random rdom = new Random();
        List<Entity> l = e.getNearbyEntities(3, 3, 3);
        for (Entity ee : l) {
          if (ee instanceof Player) {
            Player p = (Player) ee;
            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 5, 1));
          }
        }
      } else if (et == EntityType.SPIDER) {
        Random rdom = new Random();

        for (int i = 0; i <= 4; i++) {
          loc.getWorld()
              .spawnFallingBlock(loc, Material.WEB, (byte) 0)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 1, rdom.nextDouble() - 0.5));
        }
      } else if (et == EntityType.HORSE) {
        Random rdom = new Random();
        List<Entity> l = e.getNearbyEntities(10, 10, 10);
        for (Entity ee : l) {
          if (ee instanceof Player) {
            Player p = (Player) ee;
            p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 5, 2));
            p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20, 2));
          }
        }
      } else if (et == EntityType.SKELETON) {
        Random rdom = new Random();

        for (int i = 0; i <= 4; i++) {
          loc.getWorld()
              .spawnEntity(loc, EntityType.ZOMBIE)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 3, rdom.nextDouble() - 0.5));
        }

      } else if (et == EntityType.SILVERFISH) {
        Random rdom = new Random();
        loc.getWorld()
            .spawnFallingBlock(loc, Material.MONSTER_EGGS, (byte) 0)
            .setVelocity(new Vector(rdom.nextDouble() - 0.5, 3, rdom.nextDouble() - 0.5));
        Bukkit.getScheduler()
            .runTaskLater(
                MapsPlugin.getInstance(),
                new Runnable() {
                  public void run() {
                    loc.getWorld().createExplosion(loc, (float) 2);
                  }
                },
                30);
      } else if (et == EntityType.CAVE_SPIDER) {
        Random rdom = new Random();
        for (int i = 0; i <= 3; i++) {
          loc.getWorld()
              .spawnEntity(loc, EntityType.SPIDER)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 3, rdom.nextDouble() - 0.5));
        }
      } else if (et == EntityType.WITHER_SKULL) {
        Random rdom = new Random();
      }
      if (et == EntityType.ZOMBIE) {
        Bukkit.getScheduler()
            .runTaskLater(
                MapsPlugin.getInstance(),
                new Runnable() {
                  public void run() {
                    loc.getWorld().strikeLightning(loc);
                  }
                },
                30);
      } else if (et == EntityType.IRON_GOLEM) {
        Random rdom = new Random();
        for (int i = 0; i <= 3; i++) {
          loc.getWorld()
              .spawnEntity(loc, EntityType.VILLAGER)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 3, rdom.nextDouble() - 0.5));
        }
      } else if (et == EntityType.VILLAGER) {
        Random rdom = new Random();

        for (int i = 0; i <= 3; i++) {
          loc.getWorld()
              .spawnFallingBlock(loc, Material.ANVIL, (byte) 0)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 1.5, rdom.nextDouble() - 0.5));
        }
      } else if (et == EntityType.MUSHROOM_COW) {
        Random rdom = new Random();
        for (int i = 0; i <= 5; i++) {
          loc.getWorld()
              .spawnEntity(loc, EntityType.PRIMED_TNT)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 1.5, rdom.nextDouble() - 0.5));
        }
      }
      if (et == EntityType.SLIME) {
        Bukkit.getScheduler()
            .runTaskLater(
                MapsPlugin.getInstance(),
                new Runnable() {
                  public void run() {
                    loc.getWorld().createExplosion(loc, (float) 6);
                  }
                },
                30);
      } else if (et == EntityType.SKELETON) {
        Random rdom = new Random();
        loc.getWorld()
            .spawnFallingBlock(loc, Material.LAVA, (byte) 0)
            .setVelocity(new Vector(rdom.nextDouble() - 0.5, 1, rdom.nextDouble() - 0.5));
      }
    }
  }
  @SuppressWarnings("deprecation")
  @Override
  protected boolean onCommand(Player player, String command, String[] args) {
    if (command.equalsIgnoreCase("createkit")) {
      if (player.hasPermission(Permissions.COMMAND_KIT_CREATE)) {
        if (this.getPlugin().cmdValues.createKits) {
          if (Utilities.inPvPWorld(player)) {
            if (args.length == 0) {
              Lang.sendMessage(
                  player,
                  Lang.COMMAND_GEN_USAGE,
                  command.toLowerCase() + " [<kit>|<kit> <guiitem>]");
              Lang.sendMessage(player, Lang.COMMAND_CREATE_KIT_DESCRIPTION);
            } else if (args.length > 0 && args.length < 3) {
              String kitName = args[0];

              boolean containsKit = this.getPlugin().getKitsConfig().contains(kitName);
              if (!containsKit) {
                List<String> currentKits = this.getPlugin().getKitList();
                List<String> currentKitsLC = Utilities.toLowerCaseList(currentKits);
                if (currentKitsLC.contains(kitName.toLowerCase()))
                  kitName = currentKits.get(currentKitsLC.indexOf(kitName.toLowerCase()));
                containsKit = this.getPlugin().getKitsConfig().contains(kitName);
              }

              if (!this.containsIllegalCharacters(kitName)) {
                if (args.length == 2) {
                  if (args[1].contains(":")) {
                    String[] guiSplit = args[1].split(":");
                    if (guiSplit.length == 2) {
                      if (!this.isInteger(guiSplit[0]) || !this.isInteger(guiSplit[1])) {
                        Lang.sendMessage(
                            player,
                            Lang.COMMAND_GEN_USAGE,
                            command.toLowerCase() + " [<kit>|<kit> <guiitem>]");
                        return true;
                      }
                    } else {
                      if (!this.isInteger(args[1])) {
                        Lang.sendMessage(
                            player,
                            Lang.COMMAND_GEN_USAGE,
                            command.toLowerCase() + " [<kit>|<kit> <guiitem>]");
                        return true;
                      }
                    }
                  } else {
                    if (!this.isInteger(args[1])) {
                      Lang.sendMessage(
                          player,
                          Lang.COMMAND_GEN_USAGE,
                          command.toLowerCase() + " [<kit>|<kit> <guiitem>]");
                      return true;
                    }
                  }
                }

                Map<Integer, ItemStack> itemsInInv = new HashMap<>();
                List<ItemStack> armourInInv = new ArrayList<>();
                ItemStack[] pContents = player.getInventory().getContents();
                if (pContents == null) pContents = new ItemStack[player.getInventory().getSize()];
                for (int i = 0; i < player.getInventory().getSize(); i++) {
                  if (pContents.length > i && pContents[i] != null) itemsInInv.put(i, pContents[i]);
                  else itemsInInv.put(i, new ItemStack(Material.AIR));
                }
                for (ItemStack armour : player.getInventory().getArmorContents())
                  if (armour != null && armour.getType() != Material.AIR) armourInInv.add(armour);
                PlayerCreateKitEvent createKitEvent =
                    new PlayerCreateKitEvent(player, kitName, itemsInInv, armourInInv, false);
                player.getServer().getPluginManager().callEvent(createKitEvent);

                if (!createKitEvent.isCancelled()) {
                  itemsInInv = createKitEvent.getKitContentsWithSlots();
                  armourInInv = createKitEvent.getKitArmour();
                  if (itemsInInv.size() > 0 || armourInInv.size() > 0) {
                    if (containsKit) {
                      this.getPlugin().getKitsConfig().set(kitName, null);
                      this.getPlugin().saveKitsConfig();
                      if (this.getPlugin().kitList.containsKey(kitName))
                        this.getPlugin().kitList.remove(kitName);
                    }

                    final Kit kit =
                        new Kit(kitName, itemsInInv).setRealName(kitName).setArmour(armourInInv);
                    if (args.length == 2) {
                      ItemStack guiItem = null;
                      try {
                        guiItem = new ItemStack(Integer.parseInt(args[1]));
                      } catch (Exception ignored) {
                      }
                      try {
                        if (args[1].contains(":")) {
                          String[] guiSplit = args[1].split(":");
                          guiItem = new ItemStack(Integer.parseInt(guiSplit[0]));
                          guiItem.setDurability(Short.parseShort(guiSplit[1]));
                        }
                      } catch (Exception ignored) {
                      }
                      if (guiItem != null) {
                        if (guiItem.getType() != Material.AIR) {
                          kit.setGuiItem(guiItem);
                        }
                      }
                    }

                    List<PotionEffect> kitPotionEffects = new ArrayList<>();
                    for (PotionEffect potionEffect : player.getActivePotionEffects()) {
                      if (potionEffect != null) kitPotionEffects.add(potionEffect);
                    }
                    if (!kitPotionEffects.isEmpty()) kit.setPotionEffects(kitPotionEffects);

                    kit.setMaxHealth((int) player.getMaxHealth());

                    this.getPlugin().getKitsConfig().set(kitName, kit.serialize());
                    this.getPlugin().kitList.put(kitName, kit);
                    this.getPlugin().saveKitsConfig();

                    try {
                      player
                          .getServer()
                          .getPluginManager()
                          .addPermission(new Permission("kingkits.kits." + kitName.toLowerCase()));
                      player
                          .getServer()
                          .getPluginManager()
                          .addPermission(new Permission("kingkits.free." + kitName.toLowerCase()));
                    } catch (Exception ignored) {
                    }
                    Lang.sendMessage(
                        player,
                        containsKit ? Lang.COMMAND_CREATE_OVERWRITTEN : Lang.COMMAND_CREATE_CREATED,
                        kitName);

                    if (this.getPlugin().configValues.removeItemsOnCreateKit) {
                      player.getInventory().clear();
                      player.getInventory().setArmorContents(null);
                    }
                  } else {
                    Lang.sendMessage(player, Lang.COMMAND_CREATE_EMPTY_INV);
                  }
                } else {
                  Lang.sendMessage(player, Lang.COMMAND_CREATE_DENIED);
                }
              } else {
                Lang.sendMessage(player, Lang.COMMAND_CREATE_ILLEGAL_CHARACTERS);
              }
            } else {
              Lang.sendMessage(
                  player,
                  Lang.COMMAND_GEN_USAGE,
                  command.toLowerCase() + " [<kit>|<kit> <guiitem>]");
            }
          } else {
            Lang.sendMessage(player, Lang.COMMAND_GEN_WORLD);
          }
        } else {
          Lang.sendMessage(player, Lang.COMMAND_GEN_DISABLED);
        }
      } else {
        this.sendNoAccess(player);
      }
      return true;
    }
    return false;
  }