public void run() {
    if (gm.isBomb()) {
      int timer = gm.getBombTimer();

      if (timer != 0) {
        timer--;
        gm.setLobbyTimer(timer);

        for (Player p : gm.getArenaPlayers()) {
          p.setLevel(timer);
        }
      } else {
        gm.removePlayer(gm.getPotatoCarrier());

        for (Player p : gm.getArenaPlayers()) {
          p.setLevel(0);
          p.setExp(0);
          p.playSound(p.getLocation(), Sound.LEVEL_UP, 1, 10);
        }

        plugin.getServer().getScheduler().cancelTask(gm.getBomb());
        gm.setBombTimer(-1);
      }
    }
  }
  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());
  }
	@SuppressWarnings("deprecation")
	public void restoreState() {
		if (state == null) {
			return;
		}
		
		bukkitPlayer.getInventory().setContents(state.getContents());
		bukkitPlayer.getInventory().setHelmet(state.getHelmet());
		bukkitPlayer.getInventory().setChestplate(state.getChestplate());
		bukkitPlayer.getInventory().setLeggings(state.getLeggings());
		bukkitPlayer.getInventory().setBoots(state.getBoots());
		
		bukkitPlayer.setExhaustion(state.getExhaustion());
		bukkitPlayer.setSaturation(state.getSaturation());
		
		bukkitPlayer.setFoodLevel(state.getFoodLevel());
		bukkitPlayer.setHealth(state.getHealth());
		
		bukkitPlayer.addPotionEffects(state.getPotioneffects());
		
		bukkitPlayer.setLevel(state.getLevel());
		bukkitPlayer.setExp(state.getExp());
		bukkitPlayer.setAllowFlight(state.isFly());
		
		sendMessage(I18N._("stateRestored"));
		bukkitPlayer.updateInventory();
		state = null;
	}
 private PlayerInventory getInventory(Player p) {
   String group = getWorldGroup(p.getWorld());
   if (group == null) return null;
   PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(p);
   if (!pcm.exists()) pcm.createFile();
   Integer invSize = pcm.getInt("inventory." + group + ".size");
   final PlayerInventory i = p.getInventory();
   i.clear();
   if (pcm.get("inventory." + group + ".slot") == null) return i;
   for (int slot = 0; slot < invSize; slot++) {
     ItemStack is = pcm.getItemStack("inventory." + group + ".slot." + slot);
     if (is == null) continue;
     i.setItem(slot, is);
   }
   i.setHelmet(pcm.getItemStack("inventory." + group + ".slot.helm"));
   i.setChestplate(pcm.getItemStack("inventory." + group + ".slot.chestplate"));
   i.setLeggings(pcm.getItemStack("inventory." + group + ".slot.leggings"));
   i.setBoots(pcm.getItemStack("inventory." + group + ".slot.boots"));
   if (Config.separateXP) {
     Float xp = pcm.getFloat("inventory." + group + ".xp");
     Integer xpLevel = pcm.getInt("inventory." + group + ".xplevel");
     p.setExp(xp);
     p.setLevel(xpLevel);
   }
   return i;
 }
Exemple #5
0
 @Override
 public void addPlayer(Player p) {
   ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
   ItemMeta helmetMeta = setArmourColor(helmet.getItemMeta(), Color.BLUE);
   helmetMeta.addEnchant(Enchantment.OXYGEN, 3, true);
   helmet.setItemMeta(helmetMeta);
   setHelmet(helmet, p);
   setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE), p);
   setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS), p);
   ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
   ItemMeta bootsMeta = setArmourColor(boots.getItemMeta(), Color.BLUE);
   // bootsMeta.addEnchant(Enchantment.DEPTH_STRIDER, 3, true);
   // can't add depth strider because No cheat plus blocks it atm.
   bootsMeta.addEnchant(Enchantment.PROTECTION_FALL, 3, true);
   boots.setItemMeta(bootsMeta);
   setBoots(boots, p);
   ItemStack sword = new ItemStack(Material.GOLD_SWORD);
   ItemMeta swordMeta = sword.getItemMeta();
   swordMeta.setDisplayName(ChatColor.BLUE + "Trident");
   swordMeta.setLore(Arrays.asList("Crouch in water to activate!"));
   swordMeta.addEnchant(Enchantment.DAMAGE_ALL, 1, true);
   swordMeta.addEnchant(Enchantment.DURABILITY, 5, true);
   sword.setItemMeta(swordMeta);
   setWeapon(sword, p);
   p.setLevel(1);
   fillSoup(p);
 }
 @Override
 public void run() {
   for (Player p : Bukkit.getOnlinePlayers()) {
     p.setFoodLevel(Main.lobbyBoolean ? 20 : 16);
     p.setLevel(SQL.getMoney(p.getName()));
   }
 }
  @Override
  public boolean run(
      CommandSender sender,
      Player playerSender,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length != 1) {
      return false;
    }

    int new_level;

    try {
      new_level = Integer.parseInt(args[0]);

      if (new_level < 0) {
        new_level = 0;
      } else if (new_level > 50) {
        new_level = 50;
      }
    } catch (NumberFormatException ex) {
      msg("Invalid level.", ChatColor.RED);
      return true;
    }

    playerSender.setLevel(new_level);

    msg("You have been set to level " + Integer.toString(new_level), ChatColor.AQUA);

    return true;
  }
  @Override
  public void process(Player player) {
    int level = player.getLevel();
    int targetLevel = level + this.levels;

    player.setLevel(targetLevel);
    player.sendMessage("Zwiekszyles swoj poziom z " + level + " do " + targetLevel);
  }
Exemple #9
0
 public static void calculateThirst() {
   Player[] players = plugin.getServer().getOnlinePlayers();
   for (Player player : players) {
     if (Thirst.isAllowed(player) && player.getLevel() > 0) {
       player.setLevel(player.getLevel() - 1);
       sendPlayerThirstMessage(player);
     }
   }
 }
  @EventHandler
  public void onPlayerLevelChange(PlayerLevelChangeEvent event) {
    Player p = event.getPlayer();
    if (event.getNewLevel() > event.getOldLevel()) {

      plugin.playerlvl.put(p.getName().toLowerCase(), (double) p.getLevel());
      double tempoints = plugin.playerPoints.get(p.getName().toLowerCase());
      tempoints++;
      plugin.playerPoints.put(p.getName().toLowerCase(), tempoints);
      plugin.save(p);

    } else if (event.getNewLevel() == 0) {

      ItemStack[] inv = p.getInventory().getContents();
      int capacidad = p.getInventory().getSize();
      int vacio = 0;

      for (int i = 0; i < capacidad; i++) {
        if (inv[i] == null) {
          vacio++;
        }
      }
      if (capacidad == vacio) {
        // como el evento de muerte no me funciona, se da por sentado que as muerto con este metodo
        int level = event.getOldLevel();
        p.setLevel(level);
        plugin.playerlvl.put(p.getName().toLowerCase(), (double) level);
        plugin.save(p);
        // recuperar HP
        plugin.registerPlayer(p);

        p.sendMessage("Has muerto, pero conservarás tus stats y nivel :) ");
      } else {
        plugin.playerlvl.put(p.getName().toLowerCase(), 0.0);
        plugin.playerMH.put(p.getName().toLowerCase(), 0.0);
        plugin.playerPoints.put(p.getName().toLowerCase(), 0.0);
        plugin.save(p);
        p.sendMessage("Has gastado todo tu nivel, has perdido todos los stats :( ");
      }

    } else if (event.getNewLevel() < event.getOldLevel()) {
      int nlvl = event.getNewLevel();
      int olvl = event.getOldLevel();
      int rlvl = olvl - nlvl;
      // rlvl total de niveles a descontar
      double tpoints = plugin.playerPoints.get(p.getName().toLowerCase());

      Double respoints = tpoints - rlvl;
      plugin.playerPoints.put(p.getName().toLowerCase(), respoints);
      plugin.save(p);
      p.sendMessage(
          "Has bajado "
              + rlvl
              + " niveles, se te descontaran en puntos pero conservaras tus stats :/ ");
    }
  }
Exemple #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();
    }
  }
Exemple #12
0
 private void xpstuff(Player player, Integer leftoverxp, Integer bottleamount) {
   HashMap<Integer, ItemStack> leftOver = new HashMap<Integer, ItemStack>();
   player.setTotalExperience(0);
   player.setExp(0);
   player.setLevel(0);
   player.giveExp(leftoverxp);
   ItemStack bottleoenchant = new ItemStack(384, bottleamount);
   leftOver.putAll(player.getInventory().addItem(new ItemStack(bottleoenchant)));
   if (!leftOver.isEmpty()) {
     Location loc = player.getLocation();
     player.getWorld().dropItem(loc, new ItemStack(384, leftOver.get(0).getAmount()));
   }
 }
 public static void fullReset(final Arena arena, final Player player) {
   playersetHealth(player, arena.getArenaConfig().getInt(CFG.PLAYER_HEALTH));
   player.setFireTicks(0);
   player.setFallDistance(0);
   player.setVelocity(new Vector());
   player.setFoodLevel(arena.getArenaConfig().getInt(CFG.PLAYER_FOODLEVEL));
   player.setSaturation(arena.getArenaConfig().getInt(CFG.PLAYER_SATURATION));
   player.setExhaustion((float) arena.getArenaConfig().getDouble(CFG.PLAYER_EXHAUSTION));
   player.setLevel(0);
   player.setExp(0);
   player.setGameMode(GameMode.getByValue(arena.getArenaConfig().getInt(CFG.GENERAL_GAMEMODE)));
   PlayerState.removeEffects(player);
 }
  private void setExp(int base, int amt) {
    int xp = base + amt;
    if (xp < 0) xp = 0;

    Player player = getPlayer();
    int curLvl = player.getLevel();
    int newLvl = getLevelForExp(xp);
    if (curLvl != newLvl) {
      player.setLevel(newLvl);
    }

    float pct = ((float) (xp - getXpForLevel(newLvl)) / (float) xpRequiredForNextLevel[newLvl]);
    player.setExp(pct);
  }
 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());
 }
  private void commandDeposit(CommandSender sender, String[] args) {
    if (!(sender instanceof Player)) {
      sender.sendMessage(ChatColor.RED + "The console does not have an XP bank account.");
      return;
    }
    if (args.length < 2) {
      sender.sendMessage(ChatColor.RED + "Usage: /xpbank deposit <amount>");
      return;
    }

    Player p = (Player) sender;

    Integer depositAmount;

    if (args[1].equals("all")) {
      depositAmount = MinebotXPBank.calculateXP(p);
    } else {
      try {
        depositAmount = Integer.parseInt(args[1]);
      } catch (NumberFormatException e) {
        sender.sendMessage(
            ChatColor.RED + "Please provide a valid number amount of XP to deposit!");
        return;
      }
    }

    Integer currentBalance = MinebotXPBank.getBalance(p.getName());
    if (currentBalance == null) {
      MinebotXPBank.initAccount(p.getName());
      currentBalance = 0;
    }

    int oldExp = MinebotXPBank.calculateXP(p);
    if (depositAmount > oldExp) {
      sender.sendMessage(ChatColor.RED + "You don't have that many XP to deposit.");
    } else {
      int newBalance = currentBalance + depositAmount;
      MinebotXPBank.setBalance(p.getName(), newBalance);
      sender.sendMessage(depositAmount.toString() + " XP " + ChatColor.GREEN + "deposited.");
      sender.sendMessage(ChatColor.GREEN + "New balance: " + ChatColor.WHITE + newBalance + " XP");

      p.setLevel(0);
      p.setExp(0);
      p.giveExp(oldExp - depositAmount);
    }
  }
  /** Check win * */
  private void checkWin() {
    for (Player p : Bukkit.getOnlinePlayers()) {
      if (points.containsKey(p.getName())) {
        if (points.get(p.getName()) == 15) {
          /** Clear inventories * */
          for (Player t : Bukkit.getOnlinePlayers()) {
            t.getInventory().clear();

            t.setLevel(0);
            p.setExp(0f);
          }

          /** Bukkit task * */
          runnable.cancel();

          /** Remove chickens * */
          for (Entity e : chickens) {
            if (!e.isDead()) e.remove();
          }

          /** Broadcast * */
          Bukkit.broadcastMessage(MTP.PREFIX + "" + p.getName() + " �at gewonnen!");

          /** Sounds * */
          for (Player tp : Bukkit.getOnlinePlayers()) {
            if (tp == p) {
              /** Points * */
              MTP.points.put(p.getName(), MTP.points.get(p.getName()) + 1);

              tp.playSound(tp.getLocation(), "win", 1, 1);
            } else tp.playSound(tp.getLocation(), "lose", 1, 1);
          }

          /** Runnable * */
          new BukkitRunnable() {
            public void run() {
              end();
            }
          }.runTaskLater(MTP.getPlugin(), 10 * 20L);

          /** Break * */
          break;
        }
      }
    }
  }
	@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();
	}
  public void restore(Player player) {
    if (!player.isOnline()) {
      plugin.logDebug("Player " + player.getName() + " is offline. Skipping restore...");
      return;
    }

    Restoration restoration = getRestoration(player);

    if (restoration.enabled) {
      player.getInventory().clear();

      player.getInventory().setContents(restoration.inventory);
      player.getInventory().setArmorContents(restoration.armour);
      if (plugin.isMc19or110()) {
        player.getInventory().setItemInOffHand(restoration.offHand);
      }
      if (player.hasPermission(PERM_LEVEL)
          || !plugin.config.permsEnabled()
          || (player.isOp() && plugin.config.opsAllPerms())) {
        plugin.logDebug("Player " + player.getName() + " does have " + PERM_LEVEL + " permission.");
        player.setLevel(restoration.level);
        plugin.logDebug("Player " + player.getName() + " gets " + restoration.level + " level.");
      } else {
        plugin.logDebug(
            "Player " + player.getName() + " does NOT have " + PERM_LEVEL + " permission.");
      }
      if (player.hasPermission(PERM_EXP)
          || !plugin.config.permsEnabled()
          || (player.isOp() && plugin.config.opsAllPerms())) {
        plugin.logDebug("Player " + player.getName() + " does have " + PERM_EXP + " permission.");
        player.setExp(restoration.exp);
        plugin.logDebug("Player " + player.getName() + " gets " + restoration.exp + " XP.");
      } else {
        plugin.logDebug(
            "Player " + player.getName() + " does NOT have " + PERM_EXP + " permission.");
      }
      if (plugin.config.shouldNotify()) {
        plugin.message(player, plugin.config.msgRecovered());
      }
      removeRestoration(player);
      if (hasRestoration(player)) {
        plugin.message(player, "Restore exists!!!");
      }
    }
  }
  private void commandWithdraw(CommandSender sender, String[] args) {
    if (!(sender instanceof Player)) {
      sender.sendMessage(ChatColor.RED + "The console does not have an XP bank account.");
      return;
    }
    if (args.length < 2) {
      sender.sendMessage(ChatColor.RED + "Usage: /xpbank withdraw <amount>");
      return;
    }

    Player p = (Player) sender;
    Integer currentBalance = MinebotXPBank.getBalance(p.getName());
    if (currentBalance == null) {
      MinebotXPBank.initAccount(p.getName());
      currentBalance = 0;
    }

    Integer withdrawAmount;

    if (args[1].equals("all")) {
      withdrawAmount = currentBalance;
    } else {
      try {
        withdrawAmount = Integer.parseInt(args[1]);
      } catch (NumberFormatException e) {
        sender.sendMessage(ChatColor.RED + "Please provide a valid number amount to withdraw!");
        return;
      }
    }

    int newBalance = currentBalance - withdrawAmount;
    if (newBalance < 0) {
      sender.sendMessage(ChatColor.RED + "You don't have that many XP to withdraw.");
    } else {
      MinebotXPBank.setBalance(p.getName(), newBalance);
      sender.sendMessage(withdrawAmount.toString() + " XP " + ChatColor.GREEN + "withdrawn.");
      sender.sendMessage(
          ChatColor.GREEN + "Remaining balance: " + ChatColor.WHITE + newBalance + " XP");

      int oldExp = MinebotXPBank.calculateXP(p);
      p.setLevel(0);
      p.setExp(0);
      p.giveExp(oldExp + withdrawAmount);
    }
  }
Exemple #21
0
  @EventHandler
  public void onFly(PlayerToggleFlightEvent e) {
    final Player p = e.getPlayer();

    Runnable jump2 =
        new Runnable() {
          public void run() {
            p.setLevel(2);
            p.setFallDistance(-100);
          }
        };
    Runnable jump1 =
        new Runnable() {
          public void run() {
            p.setLevel(1);
            p.setFallDistance(-100);
          }
        };
    Runnable jump =
        new Runnable() {
          public void run() {
            p.setAllowFlight(true);
            p.setFlying(false);
            p.setLevel(0);
            p.setFallDistance(-100);
          }
        };

    if (p.getGameMode().equals(GameMode.ADVENTURE) && e.isFlying() == true) {
      p.setFlying(false);
      p.setAllowFlight(false);
      p.setLevel(3);

      for (Player all : Bukkit.getOnlinePlayers()) {
        all.playSound(p.getLocation(), Sound.WITHER_SHOOT, 0.1f, 0.1f);
      }

      p.setVelocity(p.getLocation().getDirection().multiply(3).setY(p.getVelocity().getY() + 1.5));
      Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, jump2, 20L);
      Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, jump1, 40L);
      Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, jump, 60L);
    }
  }
 public void cmdRestore(Player player) {
   if (player.hasPermission(PERM_RESTORE_INV)) {
     if (hasRestoration(player)) {
       Restoration restoration = getRestoration(player);
       player.getInventory().clear();
       player.getInventory().setContents(restoration.inventory);
       player.getInventory().setArmorContents(restoration.armour);
       if (plugin.isMc19or110()) {
         player.getInventory().setItemInOffHand(restoration.offHand);
       }
       player.setLevel(restoration.level);
       player.setExp(restoration.exp);
       removeRestoration(player);
     } else {
       plugin.message(player, "Nothing to restore.");
     }
   } else {
     plugin.message(player, plugin.config.msgNoPerm());
   }
 }
Exemple #23
0
  public void addPlayer() {
    spawnBack = player.getLocation().clone().add(0.5D, 0.5D, 0.5D);
    health = player.getHealth();
    hunger = player.getFoodLevel();
    setInventory(player.getInventory().getContents());
    gamemode = player.getGameMode();
    xpAmount = player.getExp();

    /** Clear all of this * */
    player.setHealth(20.0);
    player.setFoodLevel(20);
    player.getInventory().clear();
    player.getInventory().setHelmet(null);
    player.getInventory().setChestplate(null);
    player.getInventory().setLeggings(null);
    player.getInventory().setBoots(null);
    player.setGameMode(GameMode.SURVIVAL);
    player.setExp(0);
    player.setLevel(0);
  }
 public void cmdCollect(Player player) {
   if (player.hasPermission(PERM_SAVE_INV)) {
     if (plugin.config.shouldNotify()) {
       plugin.message(player, plugin.config.msgSaving());
     }
     Restoration restoration = new Restoration();
     restoration.enabled = false;
     restoration.inventory = Arrays.copyOfRange(player.getInventory().getContents(), 0, 36);
     restoration.armour = player.getInventory().getArmorContents();
     if (plugin.isMc19or110()) {
       restoration.offHand = player.getInventory().getItemInOffHand();
     }
     restoration.playerName = player.getDisplayName();
     restoration.level = player.getLevel();
     restoration.exp = player.getExp();
     player.setLevel(0);
     player.setExp(0f);
     player.getInventory().clear();
     addRestoration(player, restoration);
   } else {
     plugin.message(player, plugin.config.msgNoPerm());
   }
 }
  public static void saveInventory(Player player) {
    armourContents.put(player.getName(), player.getInventory().getArmorContents());
    inventoryContents.put(player.getName(), player.getInventory().getContents());
    locations.put(player.getName(), player.getLocation());
    xp.put(player.getName(), Float.valueOf(player.getExp()));
    xpLevel.put(player.getName(), Integer.valueOf(player.getLevel()));
    gameModes.put(player.getName(), player.getGameMode());
    potions.put(player.getName(), player.getActivePotionEffects());
    foodLevel.put(player.getName(), Integer.valueOf(player.getFoodLevel()));
    Health.put(player.getName(), Double.valueOf(player.getHealth()));
    flight.put(player.getName(), Boolean.valueOf(player.getAllowFlight()));

    player.setAllowFlight(false);
    player.setHealth(20.0D);
    player.setFoodLevel(20);
    for (PotionEffect effect : player.getActivePotionEffects()) {
      player.removePotionEffect(effect.getType());
    }
    player.getInventory().clear();
    player.setLevel(0);
    player.setExp(0.0F);
    player.setGameMode(GameMode.SURVIVAL);
  }
Exemple #26
0
 public static void changeLobby(Player p, int i, boolean teleport) {
   LobbyList.put(p.getUniqueId(), i);
   for (Player o : Bukkit.getOnlinePlayers()) {
     p.showPlayer(o);
     if (LobbyList.containsKey(o.getUniqueId())) {
       if (LobbyList.get(o.getUniqueId()) != i) {
         p.hidePlayer(o);
         o.hidePlayer(p);
       } else {
         o.showPlayer(p);
       }
     } else {
       p.hidePlayer(o);
       o.hidePlayer(p);
     }
   }
   p.setExp(0);
   p.setLevel(getLobby(p));
   if (teleport) {
     p.teleport(GameAPI.getSpawnLocation());
     p.getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 7);
   }
 }
  /** Damage * */
  @EventHandler
  public void onDamageByEntity(EntityDamageByEntityEvent e) {
    if (e.getEntity() instanceof Chicken) {
      if (e.getDamager() instanceof Arrow) {
        /** Arrow * */
        Arrow a = (Arrow) e.getDamager();

        if (a.getShooter() instanceof Player) {
          /** Player * */
          Player p = (Player) a.getShooter();

          /** Remove from list * */
          if (chickens.contains(e.getEntity())) chickens.remove(e.getEntity());

          /** Remove * */
          e.getEntity().remove();

          /** Give player point * */
          points.put(p.getName(), points.get(p.getName()) + 1);

          /** Play sound * */
          p.playSound(p.getLocation(), Sound.NOTE_PLING, 1, 3);

          /** Title * */
          Util.sendTitle(p, 5, 10, 5, "", "Getroffen!");

          /** Level and exp * */
          p.setLevel(points.get(p.getName()));
          p.setExp((1f / 15) * points.get(p.getName()));

          /** Check win * */
          checkWin();
        }
      }
    }
  }
 public void manageDeath(PlayerKilledEvent event) {
   Gamer killed = event.getKilled();
   final Player p = killed.getPlayer();
   p.setHealth(20);
   if (event.isCancelled()) return;
   for (HumanEntity human : p.getInventory().getViewers()) human.closeInventory();
   p.leaveVehicle();
   p.eject();
   p.setLevel(0);
   p.setExp(0F);
   if (event.getDeathMessage().equals(ChatColor.stripColor(event.getDeathMessage())))
     event.setDeathMessage(ChatColor.DARK_RED + event.getDeathMessage());
   event.setDeathMessage(
       this.formatDeathMessage(
           event.getDeathMessage().replace("%Remaining%", "" + (getAliveGamers().size() - 1)), p));
   if (event.getKillerPlayer() != null) {
     event.getKillerPlayer().addKill();
     event.setDeathMessage(
         this.formatDeathMessage(event.getDeathMessage(), event.getKillerPlayer().getPlayer()));
   }
   Bukkit.broadcastMessage(event.getDeathMessage());
   int reward = hg.getPrize(getAliveGamers().size());
   if (reward > 0) killed.addBalance(reward);
   hg.cannon();
   killed.clearInventory();
   World world = p.getWorld();
   for (ItemStack item : event.getDrops()) {
     if (item == null
         || item.getType() == Material.AIR
         || item.containsEnchantment(EnchantmentManager.UNLOOTABLE)) continue;
     else if (item.hasItemMeta())
       world
           .dropItemNaturally(event.getDropsLocation(), item.clone())
           .getItemStack()
           .setItemMeta(item.getItemMeta());
     else world.dropItemNaturally(event.getDropsLocation(), item);
   }
   setSpectator(killed);
   ScoreboardManager.makeScore(
       "Main", DisplaySlot.SIDEBAR, cm.getScoreboardPlayersLength(), getAliveGamers().size());
   hg.checkWinner();
   p.setVelocity(new Vector());
   for (PotionEffect effect : p.getActivePotionEffects()) p.removePotionEffect(effect.getType());
   p.teleport(p.getWorld().getHighestBlockAt(p.getLocation()).getLocation().clone().add(0, 10, 0));
   p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 9), true);
   p.sendBlockChange(p.getLocation(), Material.PORTAL.getId(), (byte) 0);
   p.sendBlockChange(p.getLocation(), Material.AIR.getId(), (byte) 0);
   for (Entity entity : p.getWorld().getEntities()) {
     if (entity instanceof Tameable
         && ((Tameable) entity).isTamed()
         && ((Tameable) entity).getOwner().getName().equals(p.getName())) {
       if (entity instanceof Wolf) ((Wolf) entity).setSitting(true);
       else if (entity instanceof Ocelot) ((Ocelot) entity).setSitting(true);
       else entity.remove();
     }
     if (entity instanceof Creature && ((Creature) entity).getTarget() == p)
       ((Creature) entity).setTarget(null);
   }
   if (HungergamesApi.getConfigManager().getMainConfig().isKickOnDeath()
       && !p.hasPermission("hungergames.spectate"))
     p.kickPlayer(String.format(cm.getKickDeathMessage(), event.getDeathMessage()));
   HungergamesApi.getAbilityManager().unregisterPlayer(p);
   HungergamesApi.getInventoryManager().updateSpectatorHeads();
 }
Exemple #29
0
 @Override
 public void setLevel(int lvl) {
   caller.setLevel(lvl);
 }
 public boolean setPlayerLevel(String player, int level) {
   Player p = getPlayerExact(player);
   p.setLevel(level);
   p.saveData();
   return true;
 }