Exemplo n.º 1
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerDamage(EntityDamageByEntityEvent evt) {
    if (evt.getDamager() instanceof Player) {
      Player p = (Player) evt.getDamager();

      if (p.hasPotionEffect(PotionEffectType.INCREASE_DAMAGE)) {
        for (PotionEffect eff : p.getActivePotionEffects()) {
          if (eff.getType().equals(PotionEffectType.INCREASE_DAMAGE)) {
            double div = (eff.getAmplifier() + 1) * 1.3D + 1.0D;
            int dmg;

            if (evt.getDamage() / div <= 1.0D) {
              dmg = (eff.getAmplifier() + 1) * 3 + 1;
            } else {
              double flatdmg = 2.0;
              dmg = (int) (evt.getDamage() / div) + (int) ((eff.getAmplifier() + 1) * flatdmg);
            }

            evt.setDamage(dmg);
            break;
          }
        }
      }
    }
  }
Exemplo n.º 2
0
 public static void resetPlayer(Player player) {
   player.setHealth(player.getMaxHealth());
   player.setFoodLevel(20);
   player.setSaturation(20);
   player.getInventory().clear();
   player
       .getInventory()
       .setArmorContents(
           new ItemStack[] {
             new ItemStack(Material.AIR),
             new ItemStack(Material.AIR),
             new ItemStack(Material.AIR),
             new ItemStack(Material.AIR)
           });
   for (PotionEffect effect : player.getActivePotionEffects()) {
     try {
       player.removePotionEffect(effect.getType());
     } catch (NullPointerException ignored) {
     }
   }
   player.setTotalExperience(0);
   player.setExp(0);
   player.setPotionParticles(true);
   player.setWalkSpeed(0.2F);
   player.setFlySpeed(0.2F);
 }
Exemplo n.º 3
0
  private boolean hasFireResistance(Player player) {
    for (PotionEffect pe : player.getActivePotionEffects()) {
      if (pe.getType().equals(PotionEffectType.FIRE_RESISTANCE)) return true;
    }

    return false;
  }
Exemplo n.º 4
0
  public void clean() {

    PlayerInventory inv = this.player.getInventory();
    inv.setArmorContents(new ItemStack[4]);
    inv.setContents(new ItemStack[] {});

    this.player.setAllowFlight(false);
    this.player.setFlying(false);
    this.player.setExp(0.0F);
    this.player.setLevel(0);
    this.player.setSneaking(false);
    this.player.setSprinting(false);
    this.player.setFoodLevel(20);
    this.player.setMaxHealth(20.0D);
    this.player.setHealth(20.0D);
    this.player.setFireTicks(0);
    this.player.setGameMode(GameMode.SURVIVAL);

    boolean teamnameOnTab = Main.getInstance().getBooleanConfig("teamname-on-tab", true);
    boolean overwriteNames = Main.getInstance().getBooleanConfig("overwrite-names", false);
    if (overwriteNames) {
      Game game = Main.getInstance().getGameManager().getGameOfPlayer(this.player);
      if (game != null) {
        Team team = game.getPlayerTeam(this.player);
        if (team != null) {
          this.player.setDisplayName(team.getChatColor() + this.player.getName());
        } else {
          this.player.setDisplayName(this.player.getName());
        }
      }
    }

    if (teamnameOnTab && Utils.isSupportingTitles()) {
      Game game = Main.getInstance().getGameManager().getGameOfPlayer(this.player);
      if (game != null) {
        Team team = game.getPlayerTeam(this.player);
        if (team != null) {
          this.player.setPlayerListName(
              team.getChatColor()
                  + team.getName()
                  + ChatColor.WHITE
                  + " | "
                  + team.getChatColor()
                  + this.player.getName());
        } else {
          this.player.setPlayerListName(this.player.getName());
        }
      }
    }

    if (this.player.isInsideVehicle()) {
      this.player.leaveVehicle();
    }

    for (PotionEffect e : this.player.getActivePotionEffects()) {
      this.player.removePotionEffect(e.getType());
    }

    this.player.updateInventory();
  }
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    boolean hasarg = false;
    Player p = null;
    if (args.length == 1) {
      hasarg = true;
      p = this.getServer().getPlayer(args[0]);
    }

    if (sender instanceof Player) {
      if (!((Player) sender).hasPermission("command.rmeffect")) {
        sender.sendMessage("You can't use this command.");
        return true;
      }
    }
    for (Player player : this.getServer().getOnlinePlayers()) {
      for (PotionEffect effect : player.getActivePotionEffects()) {
        if (hasarg && p != null) {
          p.removePotionEffect(effect.getType());
        } else {
          player.removePotionEffect(effect.getType());
        }
      }
    }
    getServer().dispatchCommand(sender, "effect night_vision all");
    sender.sendMessage("Effects removed.");

    return true;
  }
Exemplo n.º 6
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPotionSplashEvent(PotionSplashEvent event) {
    LivingEntity shooter = event.getPotion().getShooter();
    if (!(shooter instanceof Player)) return;
    Player damager = (Player) shooter;

    // So, the idea here is because we can't really determine how much damage a potion actually
    // caused
    // somebody (like poison, weakness, or the API doesn't even seem to tell you the difference
    // between harm I and harm II),
    // we just award 6 damage points to the thrower as long as the potion is sufficiently bad.
    int damage = 6;

    boolean badpotion = false;
    for (PotionEffect effect : event.getPotion().getEffects()) {
      // apparently these aren't really enums, because == doesn't work
      if (effect.getType().equals(PotionEffectType.HARM)
          || effect.getType().equals(PotionEffectType.POISON)
          || effect.getType().equals(PotionEffectType.WEAKNESS)) {
        badpotion = true;
        break;
      }
    }

    if (!badpotion) // don't award damage for helpful or do-nothing potions, to prevent pearl
      // stealing
      return;

    for (Entity entity : event.getAffectedEntities()) {
      if (!(entity instanceof Player)) continue;

      recordDamage((Player) entity, damager, damage);
    }
  }
Exemplo n.º 7
0
  public static void restoreInventory(Player player) {
    player.getInventory().clear();
    player.teleport((Location) locations.get(player.getName()));
    for (PotionEffect effect : player.getActivePotionEffects()) {
      player.removePotionEffect(effect.getType());
    }
    player.getInventory().setContents((ItemStack[]) inventoryContents.get(player.getName()));
    player.getInventory().setArmorContents((ItemStack[]) armourContents.get(player.getName()));
    player.setExp(((Float) xp.get(player.getName())).floatValue());
    player.setLevel(((Integer) xpLevel.get(player.getName())).intValue());
    player.setGameMode((GameMode) gameModes.get(player.getName()));
    player.addPotionEffects((Collection<PotionEffect>) potions.get(player.getName()));
    player.setFoodLevel(((Integer) foodLevel.get(player.getName())).intValue());
    player.setHealth(((Double) Health.get(player.getName())).doubleValue());
    player.setAllowFlight(((Boolean) flight.get(player.getName())).booleanValue());

    flight.remove(player.getName());
    Health.remove(player.getName());
    foodLevel.remove(player.getName());
    potions.remove(player.getName());
    xpLevel.remove(player.getName());
    xp.remove(player.getName());
    locations.remove(player.getName());
    armourContents.remove(player.getName());
    inventoryContents.remove(player.getName());
    gameModes.remove(player.getName());
  }
  @EventHandler
  public void onPlayerDeath(PlayerDiedEvent event) {
    if (event.getGame() != this.game) return;

    Player player = event.getPlayer();

    if (deadPlayers.containsKey(player)) return;

    DeadPlayer deadPlayer = new DeadPlayer(player, this.game);
    deadPlayers.put(player, deadPlayer);
    deadPlayer.spawn();

    for (PotionEffect effect : player.getActivePotionEffects()) {
      player.removePotionEffect(effect.getType());
    }

    game.broadcast(ChatColor.BOLD.toString() + ChatColor.DARK_RED + event.getDeathMessage());

    for (Player p : game.getPlayers()) {
      plugin.sendActionbarMessage(
          p,
          ChatColor.YELLOW.toString()
              + ChatColor.BOLD.toString()
              + player.getName()
              + " has been downed! Go revive them!");
    }

    if (deadPlayers.size() == game.getPlayers().size()) safelyEndGame();
  }
Exemplo n.º 9
0
  /**
   * Clears the player's inventory and removes any active potion effects.
   *
   * @param player
   */
  public void clear(Player player) {
    player.getInventory().clear();
    player.getInventory().setArmorContents(null);

    for (PotionEffect pot : player.getActivePotionEffects()) {
      player.removePotionEffect(pot.getType());
    }
  }
Exemplo n.º 10
0
 @EventHandler
 public void onJoin(PlayerJoinEvent e) {
   Player p = e.getPlayer();
   cInv.createPotionGUI();
   for (PotionEffect effect : p.getActivePotionEffects()) {
     p.removePotionEffect(effect.getType());
   }
 }
Exemplo n.º 11
0
  @SuppressWarnings("deprecation")
  public void leaveGame(Player player, boolean normalLeave) {

    player.setGameMode(GameMode.CREATIVE);
    // player.setAllowFlight(true);

    player.setHealth(20.0);
    player.setFoodLevel(20);
    player.setLevel(0);

    for (PotionEffect effect : player.getActivePotionEffects()) {
      player.removePotionEffect(effect.getType());
    }

    // Session session = HyperPVP.getSession(player);
    // session.setInterruptThread(true);

    if (normalLeave) {
      player.sendMessage(ChatColor.AQUA + "You are now spectating!");
      HyperPVP.setListName(ChatColor.AQUA, player);
      player.getInventory().clear();
      player.updateInventory();
    }

    CycleUtil.addSpectator(player, normalLeave);
    HyperPVP.getGameSessions().remove(player.getName());

    CycleUtil.hidePlayerWhereAppropriate(player, false);
    player.getInventory().setHelmet(null);
    player.getInventory().setBoots(null);
    player.getInventory().setChestplate(null);
    player.getInventory().setLeggings(null);

    try {
      HyperPVP.getStorage()
          .executeQuery(
              "UPDATE servers SET team_one = '"
                  + this.getTeamMembers(this.teams.get(0).getColor()).size()
                  + "' WHERE bungee_name = '"
                  + HyperPVP.getConfiguration().getConfig().getString("Server").toLowerCase()
                  + "'");

      if (this.type != GameType.FFA) {
        HyperPVP.getStorage()
            .executeQuery(
                "UPDATE servers SET team_two = '"
                    + this.getTeamMembers(this.teams.get(1).getColor()).size()
                    + "' WHERE bungee_name = '"
                    + HyperPVP.getConfiguration().getConfig().getString("Server").toLowerCase()
                    + "'");
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 12
0
 @EventHandler
 public void potionEffects(PlayerChangedWorldEvent e) {
   if (!Config.separateInv || !Config.removePotionEffects) return;
   Player p = e.getPlayer();
   Collection<PotionEffect> potionEffects = p.getActivePotionEffects();
   if (potionEffects.isEmpty()) return;
   for (PotionEffect pe : potionEffects) {
     if (!p.hasPotionEffect(pe.getType())) continue;
     p.removePotionEffect(pe.getType());
   }
 }
Exemplo n.º 13
0
 public static void savePotion(ItemStack potion, String name) {
   if (potion.getType() != Material.POTION) return;
   PotionMeta meta = (PotionMeta) potion.getItemMeta();
   ConfigurationSection potionYaml = yaml.createSection(name);
   for (int i = 0; i < meta.getCustomEffects().size(); i++) {
     PotionEffect effect = meta.getCustomEffects().get(i);
     ConfigurationSection effectYaml = potionYaml.createSection("effect_" + i);
     effectYaml.set("type", effect.getType().getName().toLowerCase());
     effectYaml.set("duration", effect.getDuration());
     effectYaml.set("amplifier", effect.getAmplifier() + 1);
     effectYaml.set("showParticles", effect.isAmbient());
   }
 }
Exemplo n.º 14
0
  public boolean addCustomEffect(PotionEffect effect, boolean overwrite) {
    Validate.notNull(effect, "Potion effect must not be null");

    int index = indexOfEffect(effect.getType());
    if (index != -1) {
      if (overwrite) {
        PotionEffect old = customEffects.get(index);
        if (old.getAmplifier() == effect.getAmplifier()
            && old.getDuration() == effect.getDuration()
            && old.isAmbient() == effect.isAmbient()) {
          return false;
        }
        customEffects.set(index, effect);
        return true;
      } else {
        return false;
      }
    } else {
      if (customEffects == null) {
        customEffects = new ArrayList<PotionEffect>();
      }
      customEffects.add(effect);
      return true;
    }
  }
Exemplo n.º 15
0
 @EventHandler
 public void splash(PotionSplashEvent event) {
   Collection<PotionEffect> effects = event.getPotion().getEffects();
   for (PotionEffect effect : effects) {
     if (effect.getType() == PotionEffectType.INCREASE_DAMAGE) {
       if (effect.getAmplifier() > 0) {
         event.setCancelled(true);
       }
     }
     if (effect.getType() == PotionEffectType.INVISIBILITY) {
       event.setCancelled(true);
     }
   }
 }
Exemplo n.º 16
0
  @Override
  void applyToItem(NBTTagCompound tag) {
    super.applyToItem(tag);
    if (hasCustomEffects()) {
      NBTTagList effectList = new NBTTagList();
      tag.set(POTION_EFFECTS.NBT, effectList);

      for (PotionEffect effect : customEffects) {
        NBTTagCompound effectData = new NBTTagCompound();
        effectData.setByte(ID.NBT, (byte) effect.getType().getId());
        effectData.setByte(AMPLIFIER.NBT, (byte) effect.getAmplifier());
        effectData.setInt(DURATION.NBT, effect.getDuration());
        effectData.setBoolean(AMBIENT.NBT, effect.isAmbient());
        effectList.add(effectData);
      }
    }
  }
Exemplo n.º 17
0
  @Override
  public SpellResult perform(CastContext context) {
    Entity entity = context.getTargetEntity();
    if (entity == null || !(entity instanceof LivingEntity)) {
      return SpellResult.NO_TARGET;
    }

    LivingEntity targetEntity = (LivingEntity) entity;
    Collection<PotionEffect> currentEffects = targetEntity.getActivePotionEffects();
    for (PotionEffect effect : currentEffects) {
      if (negativeEffects.contains(effect.getType())) {
        context.registerPotionEffects(targetEntity);
        targetEntity.removePotionEffect(effect.getType());
      }
    }
    return SpellResult.CAST;
  }
Exemplo n.º 18
0
 public static void clearupperson(Player p) {
   p.setAllowFlight(false);
   p.setLevel(0);
   p.setExp(0);
   p.setFoodLevel(20);
   p.setSaturation(10);
   p.setHealth(20D);
   PlayerInventory pi = p.getInventory();
   pi.clear();
   pi.setHeldItemSlot(0);
   ItemStack Air = new ItemStack(Material.AIR);
   pi.setHelmet(Air);
   pi.setChestplate(Air);
   pi.setLeggings(Air);
   pi.setBoots(Air);
   for (PotionEffect effect : p.getActivePotionEffects()) p.removePotionEffect(effect.getType());
 }
Exemplo n.º 19
0
	@SuppressWarnings("deprecation")
	public void saveState() {
		bukkitPlayer.setGameMode(GameMode.SURVIVAL);//Set to survival
		
		//Define player states variables
		ItemStack[] contents = bukkitPlayer.getInventory().getContents();
		
		ItemStack helmet = bukkitPlayer.getInventory().getHelmet();
		ItemStack chestplate = bukkitPlayer.getInventory().getChestplate();
		ItemStack leggings = bukkitPlayer.getInventory().getLeggings();
		ItemStack boots = bukkitPlayer.getInventory().getBoots();
		
		float exhaustion = bukkitPlayer.getExhaustion();
		float saturation = bukkitPlayer.getSaturation();
		
		int foodLevel = bukkitPlayer.getFoodLevel();
		double health = bukkitPlayer.getHealth();
		
		GameMode gm = bukkitPlayer.getGameMode();
		Collection<PotionEffect> potionEffects = bukkitPlayer.getActivePotionEffects();
		
		float exp = bukkitPlayer.getExp();
		int level = bukkitPlayer.getLevel();
		
		boolean fly = bukkitPlayer.getAllowFlight();
		
		//Save state
		state = new PlayerState(contents, helmet, chestplate, leggings, boots, exhaustion, saturation, foodLevel, health, gm, potionEffects, exp, level, fly);
		
		//Set to default state
		bukkitPlayer.setFoodLevel(20);
		bukkitPlayer.setHealth(20.0);
		bukkitPlayer.setAllowFlight(false);//Disable fly mode (Essentials etc.)
		bukkitPlayer.setFireTicks(0);
		bukkitPlayer.getInventory().clear();
		bukkitPlayer.getInventory().setArmorContents(new ItemStack[4]);
		bukkitPlayer.setLevel(0);
		bukkitPlayer.setExp(0);
		
		for (PotionEffect effect : bukkitPlayer.getActivePotionEffects()) {
			bukkitPlayer.removePotionEffect(effect.getType());
		}
		
		bukkitPlayer.sendMessage(I18N._("stateSaved"));
		bukkitPlayer.updateInventory();
	}
Exemplo n.º 20
0
 private void endRound() {
   Bukkit.broadcastMessage(
       ChatColor.LIGHT_PURPLE + "[BattleReverie] " + ChatColor.GOLD + "Round over!");
   try {
     if (!p1.equals("???"))
       Bukkit.getPlayer(p1)
           .teleport(new Location(Bukkit.getWorld(getName()), 0, 87, 0, 87.998F, 7.1F));
     if (!p2.equals("???"))
       Bukkit.getPlayer(p2)
           .teleport(new Location(Bukkit.getWorld(getName()), 0, 87, 0, 87.998F, 7.1F));
     if (!p3.equals("???"))
       Bukkit.getPlayer(p3)
           .teleport(new Location(Bukkit.getWorld(getName()), 0, 87, 0, 87.998F, 7.1F));
     if (!p4.equals("???"))
       Bukkit.getPlayer(p4)
           .teleport(new Location(Bukkit.getWorld(getName()), 0, 87, 0, 87.998F, 7.1F));
   } catch (NullPointerException ex) {
   }
   p1 = "???";
   p2 = "???";
   p3 = "???";
   p4 = "???";
   for (Player p : getInGame()) {
     p.getInventory().clear();
     p.getInventory().setHelmet(new ItemStack(Material.AIR, 1));
     p.getInventory().setChestplate(new ItemStack(Material.AIR, 1));
     p.getInventory().setBoots(new ItemStack(Material.AIR, 1));
     p.getInventory().setLeggings(new ItemStack(Material.AIR, 1));
     for (PotionEffect po : p.getActivePotionEffects()) {
       p.removePotionEffect(po.getType());
     }
     p.setHealth(20);
     p.setFoodLevel(20);
     p.updateInventory();
   }
   Bukkit.getScheduler()
       .runTaskLater(
           plugin,
           new Runnable() {
             public void run() {
               newRound();
             }
           },
           40L);
 }
Exemplo n.º 21
0
  public boolean removeCustomEffect(PotionEffectType type) {
    Validate.notNull(type, "Potion effect type must not be null");

    if (!hasCustomEffects()) {
      return false;
    }

    boolean changed = false;
    Iterator<PotionEffect> iterator = customEffects.iterator();
    while (iterator.hasNext()) {
      PotionEffect effect = iterator.next();
      if (effect.getType() == type) {
        iterator.remove();
        changed = true;
      }
    }
    return changed;
  }
  /*
   * Called when a block is damaged.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockDispense(BlockDispenseEvent event) {
    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    if (wcfg.blockPotions.size() > 0) {
      ItemStack item = event.getItem();
      if (item.getType() == Material.POTION && !BukkitUtil.isWaterPotion(item)) {
        Potion potion = Potion.fromDamage(BukkitUtil.getPotionEffectBits(item));
        for (PotionEffect effect : potion.getEffects()) {
          if (potion.isSplash() && wcfg.blockPotions.contains(effect.getType())) {
            event.setCancelled(true);
            return;
          }
        }
      }
    }
  }
Exemplo n.º 23
0
 private void writeConfig(MovingVan van, Player p, String name, String perm) {
   ArrayList<String> tmpList = new ArrayList<String>();
   for (ItemStack is : Arrays.asList(p.getInventory().getContents())) {
     if (is != null) {
       tmpList.add(new String(is.getTypeId() + ":" + is.getAmount() + ":" + is.getDurability()));
     }
   }
   config.set("Kits." + name + ".Perm", perm);
   config.set("Kits." + name + ".Items", tmpList.toArray());
   if (p.getInventory().getHelmet() != null) {
     config.set("Kits." + name + ".Armor.Head", p.getInventory().getHelmet().getTypeId());
   } else {
     config.set("Kits." + name + ".Armor.Head", 0);
   }
   if (p.getInventory().getChestplate() != null) {
     config.set("Kits." + name + ".Armor.Chest", p.getInventory().getChestplate().getTypeId());
   } else {
     config.set("Kits." + name + ".Armor.Chest", 0);
   }
   if (p.getInventory().getLeggings() != null) {
     config.set("Kits." + name + ".Armor.Legs", p.getInventory().getLeggings().getTypeId());
   } else {
     config.set("Kits." + name + ".Armor.Legs", 0);
   }
   if (p.getInventory().getBoots() != null) {
     config.set("Kits." + name + ".Armor.Boots", p.getInventory().getBoots().getTypeId());
   } else {
     config.set("Kits." + name + ".Armor.Boots", 0);
   }
   ArrayList<Integer> tmpPots = new ArrayList<Integer>();
   for (PotionEffect pot : p.getActivePotionEffects()) {
     tmpPots.add(pot.getType().getId());
   }
   ArrayList<Integer> tmpInts = new ArrayList<Integer>();
   for (PotionEffect pot : p.getActivePotionEffects()) {
     tmpInts.add(pot.getType().getId());
   }
   config.set("Kits." + name + ".PotionEffects.Day", tmpInts.toArray());
   config.set("Kits." + name + ".PotionEffects.Night", tmpInts.toArray());
   saveConfig();
   reloadConfig();
   config = getConfig();
 }
 @Override
 public void tick(Player player) {
   if (item.getHasPermission() == true && player.hasPermission(item.getPermission()) == false) {
     player.sendMessage(ChatColor.RED + String.format(Locale.get("message.error.permission")));
   } else {
     boolean hasEffect = false;
     for (PotionEffect potionEffect : player.getActivePotionEffects()) {
       if (potionEffect.getType().equals(effect)) {
         hasEffect = true;
         if (potionEffect.getDuration() <= 10)
           player.addPotionEffect(new PotionEffect(effect, 30, amplifier, true), true);
         break;
       }
     }
     if (!hasEffect) {
       player.addPotionEffect(new PotionEffect(effect, 30, amplifier, true), true);
     }
   }
 }
 @Override
 public void apply(LivingEntity target) {
   if (potionEffectType == null) {
     return;
   }
   int dur = duration / MS_PER_TICK;
   if (target.hasPotionEffect(potionEffectType)) {
     PotionEffect potionEffect = null;
     for (PotionEffect potEff : target.getActivePotionEffects()) {
       if (potEff.getType() == potionEffectType) {
         potionEffect = potEff;
         break;
       }
     }
     if (potionEffect != null) {
       dur += potionEffect.getDuration();
     }
   }
   target.addPotionEffect(new PotionEffect(potionEffectType, dur, intensity));
 }
Exemplo n.º 26
0
  /**
   * Scores the specified {@link PotionEffect}.
   *
   * @param effect The effect to score.
   * @return The score.
   * @throws IllegalArgumentException If an effect with an unknown {@link PotionEffectType} was
   *     specified.
   */
  public static double getScore(final PotionEffect effect) throws IllegalArgumentException {
    Preconditions.checkNotNull(effect, "Effect");

    //  Duration, in ticks
    int duration = effect.getDuration();
    //  Level (>= 1 is normal effect, == 0 is no effect, < 0 is inverse effect)
    int level = effect.getAmplifier();
    PotionEffectType effectType = effect.getType();
    PotionClassification classification =
        (level >= 0
            ? PotionUtils.potionEffectTypeImplications.get(effectType)
            : PotionUtils.inversePotionEffectTypeImplications.get(effectType));

    if (effectType == null || classification == null)
      throw new IllegalArgumentException("Unknown (or null) PotionEffectType");

    double score = classification.getScore();
    score *= Math.abs(level);
    return score * ((double) duration / 20);
  }
Exemplo n.º 27
0
  public void playerLeave(final Player p, boolean teleport) {
    msgFall(PrefixType.INFO, "game.playerleavegame", "player-" + p.getName());
    if (teleport) {
      p.teleport(SettingsManager.getInstance().getLobbySpawn());
    }
    // Remove any potion/fire effects
    for (PotionEffect effect : p.getActivePotionEffects()) {
      p.removePotionEffect(effect.getType());
    }
    if (p.getFireTicks() > 0) {
      p.setFireTicks(0);
    }

    sm.removePlayer(p, gameID);
    scoreBoard.removePlayer(p);
    activePlayers.remove(p);
    inactivePlayers.remove(p);
    voted.remove(p);

    for (Object in : spawns.keySet().toArray()) {
      if (spawns.get(in) == p) spawns.remove(in);
    }

    HookManager.getInstance().runHook("PLAYER_REMOVED", "player-" + p.getName());
    LobbyManager.getInstance().updateWall(gameID);

    if (activePlayers.size() < 2 && mode == GameMode.INGAME) {
      mode = GameMode.FINISHING;
      tasks.add(
          Bukkit.getScheduler()
              .scheduleSyncDelayedTask(
                  GameManager.getInstance().getPlugin(),
                  new Runnable() {
                    public void run() {
                      playerWin(p);
                      endGame();
                    }
                  },
                  1L));
    }
  }
Exemplo n.º 28
0
 @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 public void onPotionSplash(final PotionSplashEvent event) {
   ThrownPotion potion = event.getPotion();
   Collection<PotionEffect> effects =
       ((PotionMeta) potion.getItem().getItemMeta()).getCustomEffects();
   Bukkit.broadcastMessage(
       "A "
           + event.getEntity().getType().getName()
           + " splashed a potion with "
           + effects.size()
           + " effects attached:");
   for (PotionEffect effect : effects) {
     Bukkit.broadcastMessage(
         "Type: "
             + effect.getType().getName()
             + ", Level: "
             + (effect.getAmplifier() + 1)
             + ", Duration: "
             + effect.getDuration());
   }
 }
Exemplo n.º 29
0
  @EventHandler
  public static void addPotionInfo(ItemInfoEvent event) {
    ItemStack item = event.getItem();

    if (item.getType() != Material.POTION || item.getDurability() == 0) {
      return;
    }

    Potion potion = Potion.fromItemStack(item);

    StringBuilder message = new StringBuilder(50);

    message.append(ChatColor.GRAY);

    if (potion.getType() == null) {
      return;
    }

    if (potion.isSplash()) {
      message.append("Splash ");
    }

    message.append("Potion of ");
    message.append(capitalizeFirstLetter(potion.getType().name(), '_')).append(' ');
    message.append(toRoman(potion.getLevel()));

    CommandSender sender = event.getSender();

    sender.sendMessage(message.toString());

    for (PotionEffect effect : potion.getEffects()) {
      sender.sendMessage(
          ChatColor.DARK_GRAY
              + capitalizeFirstLetter(effect.getType().getName(), '_')
              + ' '
              + toTime(effect.getDuration() / 20));
    }
  }
Exemplo n.º 30
0
  public void restore() {
    this.player.getInventory().setContents(this.inventory);
    this.player.getInventory().setArmorContents(this.armor);
    this.player.setGameMode(this.mode);

    if (this.mode == GameMode.CREATIVE) {
      this.player.setAllowFlight(true);
    }

    this.player.addPotionEffects(this.effects);
    this.player.setLevel(this.level);
    this.player.setExp(this.xp);
    this.player.setPlayerListName(this.listName);
    this.player.setDisplayName(this.displayName);
    this.player.setFoodLevel(this.foodLevel);

    for (PotionEffect e : this.player.getActivePotionEffects()) {
      this.player.removePotionEffect(e.getType());
    }

    this.player.addPotionEffects(this.effects);
    this.player.updateInventory();
  }