@Override
  public void run() {
    if (player.isValid() && player.isOnline()) {
      if (player.getInventory().getChestplate() != null
          && player.getInventory().getChestplate().getType() == Material.DIAMOND_CHESTPLATE) {

        if (!player.isSprinting() && player.getFoodLevel() < 20) {
          player.setFoodLevel(player.getFoodLevel() + 1);
          Bukkit.getScheduler()
              .scheduleSyncDelayedTask(
                  MobArenaHealthChecker.plugin, new SprintBarIncrease(player), 10);
        }
      }
    }
  }
Ejemplo n.º 2
0
 public void feedPlayer(Player player, int itemID) {
   int foodLevel = player.getFoodLevel();
   switch (itemID) {
       // Use the itemID passed to determine what the heal amount is
     case 296:
       player.setFoodLevel(foodLevel + Config.amounts.get("Wheat"));
       break; // WHEAT
     case 319:
       player.setHealth(foodLevel + Config.amounts.get("RawPork"));
       break; // RAW_PORKCHOP
     case 320:
       player.setHealth(foodLevel + Config.amounts.get("CookedPork"));
       break; // COOKED_PORKCHOP
     case 349:
       player.setHealth(foodLevel + Config.amounts.get("RawFish"));
       break; // RAW_FISH
     case 350:
       player.setHealth(foodLevel + Config.amounts.get("CookedFish"));
       break; // COOKED_FISH
     case 297:
       player.setHealth(foodLevel + Config.amounts.get("Bread"));
       break; // BREAD
     case 357:
       player.setHealth(foodLevel + Config.amounts.get("Cookie"));
       break; // COOKIE
     case 260:
       player.setHealth(foodLevel + Config.amounts.get("Apple"));
       break; // APPLE
     case 322:
       player.setHealth(foodLevel + Config.amounts.get("GoldenApple"));
       break; // GOLDEN APPLE
     case 282:
       player.setHealth(foodLevel + Config.amounts.get("MushroomStew"));
       break; // MUSHROOM SOUP/STEW
     case 354:
       player.setHealth(foodLevel + Config.amounts.get("Cake"));
       break; // Cake
     case 39:
       player.setHealth(foodLevel + Config.amounts.get("BrownMushroom"));
       break; // MUSHROOM (Brown)
     case 40:
       player.setHealth(foodLevel + Config.amounts.get("RedMushroom"));
       break; // MUSHROOM (Red)
     case 335:
       player.setHealth(foodLevel + Config.amounts.get("Milk"));
       break; // Milk
     case 344:
       player.setHealth(foodLevel + Config.amounts.get("Egg"));
       break; // Egg
     case 353:
       player.setHealth(foodLevel + Config.amounts.get("Sugar"));
       break; // Sugar
     case 338:
       player.setHealth(foodLevel + Config.amounts.get("Sugarcane"));
       break; // Sugar Cane
   }
   if (foodLevel > 20) {
     player.setFoodLevel(20);
   }
 }
Ejemplo n.º 3
0
  public PlayerState(final Player player) {
    name = player.getName();
    debug.i("creating PlayerState of " + name, player);

    fireticks = player.getFireTicks();
    foodlevel = player.getFoodLevel();
    gamemode = player.getGameMode().getValue();
    health = player.getHealth();
    maxhealth = player.getMaxHealth();

    exhaustion = player.getExhaustion();
    experience = player.getExp();
    explevel = player.getLevel();
    saturation = player.getSaturation();

    potionEffects = player.getActivePotionEffects();

    flying = player.isFlying();

    final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(player.getName());
    final Arena arena = aPlayer.getArena();

    if (arena.getArenaConfig().getBoolean(CFG.CHAT_COLORNICK)) {
      displayname = player.getDisplayName();
    }

    fullReset(arena, player);
    final int time = arena.getArenaConfig().getInt(CFG.GENERAL_TIME);
    if (time != -1) {
      player.setPlayerTime(time, false);
    }
  }
Ejemplo n.º 4
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onFoodLevelChangeEvent(FoodLevelChangeEvent e) {
   if (!(e.getEntity() instanceof Player)) return;
   Player p = (Player) e.getEntity();
   PlayerDetails d = getPlayerDetails(p);
   d.modifyPowerBy(e.getFoodLevel() - p.getFoodLevel());
   e.setFoodLevel(d.getMinecraftFood(d.getPower()));
 }
Ejemplo n.º 5
0
  public void reply(Player target, CommandSender commandSender) {
    UserStatus userStatus = new UserStatus();
    User essUser = plugin.essentials.getUser(target);

    // Nick
    userStatus.addRow(new UserStatusRow("Ник: ", target.getName()));
    // HP
    userStatus.addRow(
        new UserStatusRow(
            "Здоровье: ",
            target.getHealth()
                + "/"
                + target.getMaxHealth()
                + " ( +"
                + target.getFoodLevel()
                + " насыщение )"));
    // XP
    userStatus.addRow(
        new UserStatusRow("Уровень: ", target.getExp() + "(уровень " + target.getLevel() + " )"));
    // location
    // TODO: Make output readable
    userStatus.addRow(new UserStatusRow("Местоположение: ", target.getLocation().toString()));
    // balance
    userStatus.addRow(new UserStatusRow("Баланс: ", essUser.getMoney().toString()));
    // IP
    userStatus.addRow(new UserStatusRow("IP: ", target.getAddress().toString()));
    // GameMode
    userStatus.addRow(new UserStatusRow("Игровой режим: ", target.getGameMode().name()));
    // GodMode
    userStatus.addRow(new UserStatusRow("В режиме бога: ", essUser.isGodModeEnabled()));
    // OP
    userStatus.addRow(new UserStatusRow("OP: ", target.isOp()));
    // Fly
    userStatus.addRow(new UserStatusRow("Летает: ", target.isFlying()));
    // AFK
    userStatus.addRow(new UserStatusRow("AFK: ", essUser.isAfk()));
    // InJail
    userStatus.addRow(new UserStatusRow("В тюрьме: ", essUser.isJailed()));
    // InMute
    userStatus.addRow(new UserStatusRow("В муте: ", essUser.isMuted()));
    // InSasVanish
    userStatus.addRow(
        new UserStatusRow(
            "В сас ванише: ",
            ((SasVanish) plugin.sasCommandExecuter.commands.get("sasvanish")).inVanish(target)));
    // PEX
    userStatus.addRow(
        new UserStatusRow(
            "Группы: ", StringUtils.join(PermissionsEx.getUser(target).getGroupsNames(), ", ")));
    // TODO: Display only permissions added customly (not inherited from groups)
    // This commented line displays ALL the permissions of a player
    //        userStatus.addRow(new UserStatusRow("Пермишены: ",
    // StringUtils.join(PermissionsEx.getUser(target).getPermissions(target.getWorld().getName()),
    // ", ")));

    userStatus.send(commandSender);
  }
Ejemplo n.º 6
0
 @EventHandler
 public void onEat(FoodLevelChangeEvent event) {
   if (event.getEntity() instanceof Player) {
     if (GameManager.INSTANCE.getSession((Player) event.getEntity()) == null) return;
     Player p = (Player) event.getEntity();
     if (GameManager.INSTANCE.getSession(p) == null) return;
     int old = p.getFoodLevel();
     int newLevel = event.getFoodLevel();
     if (newLevel - old > 0) {
       p.setHealth(Math.min(p.getHealth() + 1, p.getMaxHealth()));
     }
   }
 }
Ejemplo n.º 7
0
 @EventHandler(priority = EventPriority.NORMAL)
 public void onPlayerFoodChange(final FoodLevelChangeEvent event) {
   if (event.getEntity() instanceof Player) {
     hungerman = (Player) event.getEntity();
     if (hungerman.getWorld().getName().equalsIgnoreCase(Settings.general_worldName)) {
       if (hungerman.getFoodLevel() > event.getFoodLevel()) {
         if (uSkyBlock.getInstance().playerIsOnIsland(hungerman)) {
           if (VaultHandler.checkPerk(
               hungerman.getName(), "usb.extra.hunger", hungerman.getWorld())) {
             event.setCancelled(true);
           }
         }
       }
     }
   }
 }
Ejemplo n.º 8
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();
	}
Ejemplo n.º 9
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);
  }
Ejemplo n.º 10
0
  /**
   * Checks a player.
   *
   * @param player the player
   * @param level the level
   * @return true, if successful
   */
  public boolean check(final Player player, final int level) {
    // Take time once.
    final long time = System.currentTimeMillis();

    final InventoryData data = InventoryData.getData(player);

    boolean cancel = false;

    // Hunger level change seems to not be the result of eating.
    if (data.instantEatFood == null || level <= player.getFoodLevel()) return false;

    // Rough estimation about how long it should take to eat
    final long expectedTimeWhenEatingFinished =
        Math.max(data.instantEatInteract, data.lastClickTime) + 700L;

    if (data.instantEatInteract > 0 && expectedTimeWhenEatingFinished < time) {
      // Acceptable, reduce VL to reward the player.
      data.instantEatVL *= 0.6D;
    } else if (data.instantEatInteract > time) {
      // Security test, if time ran backwards.
    } else {
      final double difference = (expectedTimeWhenEatingFinished - time) / 100D;

      // Player was too fast, increase their violation level.
      data.instantEatVL += difference;

      // Execute whatever actions are associated with this check and the violation level and find
      // out if we should
      // cancel the event.
      cancel =
          executeActions(
              player,
              data.instantEatVL,
              difference,
              InventoryConfig.getConfig(player).instantEatActions);
    }

    data.instantEatInteract = 0;
    data.instantEatFood = null;
    return cancel;
  }
Ejemplo n.º 11
0
  public static final boolean canEat(Player p, Material food) {
    GameMode gm = p.getGameMode();
    if (gm == GameMode.CREATIVE || gm == GameMode.SPECTATOR)
      return false; // Can't eat anything in those gamemodes

    boolean edible = food.isEdible();
    if (!edible) return false;
    boolean special;
    switch (food) {
      case GOLDEN_APPLE:
      case CHORUS_FRUIT:
        special = true;
        break;
        // $CASES-OMITTED$
      default:
        special = false;
    }
    if (p.getFoodLevel() < 20 || special) return true;

    return false;
  }
Ejemplo n.º 12
0
  public GamePlayerData(Player player, boolean isPlayer) {
    this.name = player.getName();

    this.isPlayer = isPlayer;

    this.originLoc = player.getLocation();
    this.compassTarget = player.getCompassTarget();

    this.health = player.getHealth();
    this.food = player.getFoodLevel();
    this.saturation = player.getSaturation();

    this.inv = player.getInventory().getContents();
    this.armor = player.getInventory().getArmorContents();

    player.getInventory().clear();

    this.exp = player.getTotalExperience();

    player.setTotalExperience(0);
  }
Ejemplo n.º 13
0
  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);
  }
Ejemplo n.º 14
0
Archivo: Jail.java Proyecto: sd-/Jail
        public void actionPerformed(ActionEvent event) {
          if (Jail.timeUpdateRunning) return;
          Jail.timeUpdateRunning = true;
          if (UpdateTime == 0) {
            getServer()
                .getScheduler()
                .scheduleSyncDelayedTask(
                    Jail.instance,
                    new Runnable() {

                      public void run() {

                        for (JailPrisoner prisoner :
                            prisoners.values().toArray(new JailPrisoner[0])) {
                          Util.debug(prisoner, "Time event");
                          Player player = getServer().getPlayerExact(prisoner.getName());
                          if (prisoner.getRemainingTime() > 0
                              && (player != null
                                  || (prisoner.getJail() != null
                                      && prisoner
                                          .getJail()
                                          .getSettings()
                                          .getBoolean(Setting.CountdownTimeWhenOffline)))) {
                            Util.debug(prisoner, "Lowering remaining time for prisoner");
                            prisoner.setRemainingTime(prisoner.getRemainingTime() - 1);
                            InputOutput.UpdatePrisoner(prisoner);

                          } else if (player != null
                              && prisoner.getRemainingTime() == 0
                              && prisoner.offlinePending() == false) {
                            Util.debug(
                                prisoner,
                                "Releasing prisoner because his time is up and he is online");
                            PrisonerManager.UnJail(prisoner, player);
                          }

                          if (player != null && prisoner.getJail() != null) {
                            if (prisoner.getJail().getSettings().getDouble(Setting.MaximumAFKTime)
                                > 0.0) {
                              prisoner.setAFKTime(prisoner.getAFKTime() + 1);
                              if (prisoner.getAFKTimeMinutes()
                                  > prisoner
                                      .getJail()
                                      .getSettings()
                                      .getDouble(Setting.MaximumAFKTime)) {
                                Util.debug(prisoner, "Prisoner is AFK. Let's kick him");
                                prisoner.setAFKTime(0);
                                player.kickPlayer(
                                    prisoner
                                        .getJail()
                                        .getSettings()
                                        .getString(Setting.MessageAFKKick));
                              }
                            }
                          }
                        }
                      }
                    },
                    1L);

            UpdateTime++;

          } else {
            UpdateTime++;
            if (UpdateTime > 9) {
              UpdateTime = 0;
            }
          }

          for (JailPrisoner prisoner : prisoners.values()) {
            Player player = getServer().getPlayerExact(prisoner.getName());
            if (player == null
                || prisoner.getJail() == null
                || player.getGameMode() == GameMode.CREATIVE) continue;
            if (!prisoner.getJail().getSettings().getBoolean(Setting.EnableFoodControl)) continue;
            int minfood = prisoner.getJail().getSettings().getInt(Setting.FoodControlMinimumFood);
            int maxfood = prisoner.getJail().getSettings().getInt(Setting.FoodControlMaximumFood);

            if (player.getFoodLevel() < minfood || player.getFoodLevel() > maxfood) {
              player.setFoodLevel((minfood + maxfood) / 2);
            }
          }

          Jail.timeUpdateRunning = false;
        }
Ejemplo n.º 15
0
  public static void spectateOn(final Player player, final Player target) {

    if (getPlugin().CommandExecutor.isSpectating.get(player.getName()) != null) {

      if (getPlugin().CommandExecutor.isSpectating.get(player.getName())) {

        spectateOff(player);
      }
    }

    player.sendMessage("§7You are now spectating " + target.getName() + ".");
    getPlugin().CommandExecutor.origLocation.put(player.getName(), player.getLocation());
    getPlugin().CommandExecutor.isSpectating.put(player.getName(), true);
    getPlugin().CommandExecutor.isBeingSpectated.put(target.getName(), true);

    if (getPlugin().CommandExecutor.spectator.get(target.getName()) == null) {

      getPlugin().CommandExecutor.spectator.put(target.getName(), player.getName());

    } else {

      getPlugin()
          .CommandExecutor
          .spectator
          .put(
              target.getName(),
              getPlugin().CommandExecutor.spectator.get(target.getName()) + "," + player.getName());
    }

    getPlugin().CommandExecutor.target.put(player.getName(), target.getName());
    player
        .getPlayer()
        .teleport(
            getPlugin()
                .getServer()
                .getPlayer(getPlugin().CommandExecutor.target.get(player.getName())));
    getPlugin().CommandExecutor.senderHunger.put(player.getName(), player.getFoodLevel());
    getPlugin().CommandExecutor.senderHealth.put(player.getName(), player.getHealth());

    if (getPlugin().CommandExecutor.isInv.get(player.getName()) == null
        || getPlugin().CommandExecutor.isInv.get(player.getName())) {

      getPlugin()
          .CommandExecutor
          .senderInv
          .put(player.getName(), player.getInventory().getContents());
      getPlugin()
          .CommandExecutor
          .senderArm
          .put(player.getName(), player.getInventory().getArmorContents());

      player.getInventory().clear();
      player.getInventory().setContents(target.getInventory().getContents());
      player.getInventory().setArmorContents(target.getInventory().getArmorContents());
    }

    ArrayList<Player> spectateablePlayers = getSpectateablePlayers();

    spectateablePlayers.remove(player);

    int tempPlayerNumber = 0;

    for (Player p : spectateablePlayers) {

      if (getPlugin().CommandExecutor.target.get(player.getName()).equals(p.getName())) {

        break;
      }

      tempPlayerNumber++;
    }

    getPlugin().CommandExecutor.playerNumber.put(player.getName(), tempPlayerNumber);

    for (Player player1 : getPlugin().getServer().getOnlinePlayers()) {

      player1.hidePlayer(player);
    }

    target.hidePlayer(player);
    player.hidePlayer(target);
  }
Ejemplo n.º 16
0
  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

    // Console ausschließen
    if (!(sender instanceof Player)) {
      sender.sendMessage(ChatColor.RED + "You have to be a player!");
      return false;
    }
    // beenden, wenn Argumente gegeben wurden
    if (args.length != 0) {
      return false;
    }

    Player player = (Player) sender;

    if (cmd.getName().equalsIgnoreCase("care-pack")) {

      if (player.hasPermission("CarePack.ever")) {

        PlayerInventory inventory = player.getInventory();
        // Steinschwert
        ItemStack item = new ItemStack(272, 1);
        inventory.addItem(item);
        // 10 Holz
        item.setTypeId(17);
        item.setData(new MaterialData(0));
        item.setAmount(10);
        inventory.addItem(item);
        // 4 Fackeln
        item.setTypeId(50);
        item.setAmount(4);
        inventory.addItem(item);
        // 1 Bett
        item.setTypeId(355);
        item.setAmount(1);
        inventory.addItem(item);
        // 2 Brot
        item.setTypeId(297);
        item.setAmount(2);
        inventory.addItem(item);
        // 1 Beef
        item.setTypeId(364);
        item.setAmount(1);
        inventory.addItem(item);
        return true;

      } else if ((player.getWorld().getTime() < 7000 && player.getWorld().getTime() > 22000)
          || player.getFoodLevel() < 6
          || player.getSaturation() < 6) {

        PlayerInventory inventory = player.getInventory();
        // Steinschwert
        ItemStack item = new ItemStack(272, 1);
        inventory.addItem(item);
        // 10 Holz
        item.setTypeId(17);
        item.setData(new MaterialData(0));
        item.setAmount(10);
        inventory.addItem(item);
        // 4 Fackeln
        item.setTypeId(50);
        item.setAmount(4);
        inventory.addItem(item);
        // 1 Bett
        item.setTypeId(355);
        item.setAmount(1);
        inventory.addItem(item);
        // 2 Brot
        item.setTypeId(297);
        item.setAmount(2);
        inventory.addItem(item);
        // 1 Beef
        item.setTypeId(364);
        item.setAmount(1);
        inventory.addItem(item);
        return true;

      } else {
        player.sendMessage(ChatColor.RED + "You can't use this command now!");
        return true;
      }
    }

    return false;
  }
Ejemplo n.º 17
0
 @Override
 public boolean check(Player player) {
   return player.getFoodLevel() < food;
 }
Ejemplo n.º 18
0
  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (args.length == 0 || !(sender instanceof Player)) {
      msg(sender, head);
      msg(sender, "  &lGO TO &b&ohttp://www.diamonddominion.net/vote");
      msg(sender, "  &a&lVOTE FOR US! -=- YOU WILL GET PRIZES");
      msg(sender, "&2|&b/vote redeem&6 to exchange votes prizes.");
      msg(sender, "&2|&b/vote stats&6 to see what you currently have.");
      msg(sender, head);
      //			msg(sender, "Visit the website to use up donation credits you earn.");
      //			msg(sender, "Voting helps our server gain popularity on server listing sites.");
      return true;
    } else {
      Player player = (Player) sender;
      String arg = args[0];
      if (arg.equalsIgnoreCase("redeem")) {
        if (args.length < 3) {
          msg(player, head);
          msg(
              player,
              "You have &b"
                  + VoteSQL.getVotesNotRewarded(player.getName())
                  + "&6 votes to buy prizes.");
          msg(player, "Type &b/vote redeem <prize id> <prize amount>");
          msg(player, "| &2PrizeID&6 | &2VoteCost&6 | -- &2Prize Name &6--");
          for (int x = 1; x <= VotePrize.prizeAmount; x++) {
            msg(
                player,
                "&6 -- &b"
                    + x
                    + " &6-- | -- &b"
                    + VotePrize.getCost(x)
                    + "&6 --- | &a"
                    + VotePrize.getDescription(x));
          }
          msg(player, head);
          return true;
        } else {
          String strid = args[1];
          int id;
          try {
            id = Integer.parseInt(strid);
          } catch (Exception e) {
            msg(player, "&4Error: &cPrize ID is incorrect.");
            msg(player, "Type &b/vote redeem <prize id> <prize amount>");
            return true;
          }
          if (!VotePrize.isValid(id)) {
            msg(player, "&4Error: &cThere is no such prize id.");
            msg(player, "Type &b/vote redeem <prize id> <prize amount>");
            return true;
          }
          String strvotes = args[2];
          int votesNum;
          try {
            votesNum = Integer.parseInt(strvotes);
          } catch (Exception e) {
            msg(player, "&4Error: &cVote number is incorrect.");
            msg(player, "Type &b/vote redeem <prize id> <prize amount>");
            return true;
          }
          redeem(player, id, votesNum);
          return true;
        }
      } else if (arg.equalsIgnoreCase("stats")) {
        msg(player, head);
        msg(player, "&5Your stats:");
        msg(player, "Unredeemed votes: &a" + VoteSQL.getVotesNotRewarded(player.getName()));
        msg(player, "Donation credits: &a" + DonationCredit.getCredits(player.getName()));
        msg(player, "Total votes ever: &a" + VoteSQL.getAllPlayerVotes(player.getName()));
        msg(player, "Votes in last 24 hours: &a" + VoteSQL.getVotesLast24(player.getName()));
        msg(player, head);
        return true;
      } else if (arg.equalsIgnoreCase("complete")) {
        if (!redeemQueue.containsKey(player.getName())) {
          msg(player, "&4Error: &cYou do not have a pending prize request.");
          msg(player, "Type &b/vote redeem <prize id> <prize amount>");
          return true;
        }
        int id = Integer.parseInt(redeemQueue.get(player.getName()).split(";")[0]);
        int amount = Integer.parseInt(redeemQueue.get(player.getName()).split(";")[1]);
        redeemQueue.remove(player.getName());
        ArrayList<Vote> votes = VoteSQL.filterVotes(player.getName(), 0, null, true, false);
        int cost = VotePrize.getCost(id) * amount;
        int has = votes.size();
        if (cost > has) {
          msg(
              player,
              "&4Error: &cYou can't redeem a prize that costs "
                  + cost
                  + " votes, but only have "
                  + has
                  + " votes to spend.");
          return true;
        }
        if (id == 4 || id == 5) {
          msg(player, "&4Error: &cPrizes 4-5 have not been set up yet.");
          return true;
        }
        String name = VotePrize.getName(id).toLowerCase();
        if (name.equals("fly")) {
          if (player.hasPermission("fly.fly")) {
            msg(
                player,
                "&4Error: &cYou already have Premium! You don't need to pay votes for Fly Mode");
            return true;
          }
          if (!plugin.detectedServer().equals("survival")) {
            msg(player, "&4Error: &cFly Mode is only available on the Survival server");
            return true;
          }
        }
        if (name.equals("god")) {
          if (player.hasPermission("fairgod.fair")) {
            msg(
                player,
                "&4Error: &cYou already have Premium! You don't need to pay votes for God Mode");
            return true;
          }
          if (!plugin.detectedServer().equals("survival")) {
            msg(player, "&4Error: &cGod Mode is only available on the Survival server");
            return true;
          }
        }
        if (name.equals("creative")) {
          if (player.hasPermission("customplugin.creative")) {
            msg(
                player,
                "&4Error: &cYou already have DemiGod! You don't need to pay votes for Creative");
            return true;
          }
          if (!plugin.detectedServer().equals("survival")) {
            msg(player, "&4Error: &cCreative Mode is only available on the Survival server");
            return true;
          }
          int a = 0;
          for (ItemStack i : player.getInventory()) {
            if (i != null) a++;
          }
          boolean helm = (player.getInventory().getHelmet() != null);
          boolean ches = (player.getInventory().getChestplate() != null);
          boolean legg = (player.getInventory().getLeggings() != null);
          boolean boot = (player.getInventory().getBoots() != null);
          if (a > 0 || helm || ches || legg || boot) {
            msg(
                player,
                "&4Error: &cYou must clear your inventory completely to switch to creative mode.");
            return true;
          }
        }

        // ---- ----  REWARD SCRIPT  ---- ----

        // Pay Cost
        int voteCounter = 1;
        for (Vote vote : votes) {
          if (voteCounter <= cost) {
            vote.rewardVote(id);
          } else {
            break;
          }
          voteCounter++;
        }

        // Add to DB the reward
        int mins = VotePrize.getExtraVar(id) * amount;
        int expiretime = (int) (System.currentTimeMillis() / 1000) + (60 * mins);

        try {
          Statement st = (Statement) SQL.getConnection().createStatement();
          ResultSet result =
              st.executeQuery(
                  "SELECT * FROM `dd-voterewards` WHERE `player` = '"
                      + player.getName()
                      + "' && `expiretime` > '"
                      + System.currentTimeMillis() / 1000
                      + "';");

          while (result.next()) {
            int qid = result.getInt("prizeid");
            int qexpire = result.getInt("expiretime");
            if (qid == id) {
              expiretime = qexpire + (60 * mins);
            }
          }
        } catch (Exception e) {
          e.printStackTrace();
        }

        SQL.singleQuery(
            "INSERT INTO `dd-voterewards`(`player`, `prizeid`, `expiretime`) VALUES ('"
                + player.getName()
                + "' , '"
                + id
                + "', '"
                + expiretime
                + "')");

        msg(player, head);

        if (id <= 5) {
          Map<Integer, Integer> data = new HashMap<Integer, Integer>();
          if (rewardCache.containsKey(player)) {
            data = rewardCache.get(player);
          }
          data.put(id, expiretime);
          rewardCache.put(player.getName(), data);
        }

        if (name.equals("healing")) {
          double health = player.getHealth();
          health += VotePrize.getExtraVar(id);
          if (health > 20) health = 20;
          player.setFoodLevel((int) health);
          msg(player, "You have been healed.");
        }
        if (name.equals("food")) {
          int foodLevel = player.getFoodLevel();
          foodLevel += VotePrize.getExtraVar(id);
          if (foodLevel > 20) foodLevel = 20;
          player.setFoodLevel(foodLevel);
          msg(player, "You have been fed.");
        }
        if (name.equals("xp")) {
          player.giveExp(VotePrize.getExtraVar(id));
          msg(player, "You have been given &b" + VotePrize.getExtraVar(id) + "&6 XP.");
        }
        if (name.equals("fly")) {
          player.setAllowFlight(true);
          player.setFlying(true);
          msg(player, "You are now flying.");
        }
        if (name.equals("god")) {
          if (!plugin.fairGod.isGod(player)) {
            plugin.fairGod.toggleGod(player, true);
            msg(player, "You now have God mode.");
          }
        }
        if (name.equals("creative")) {
          player.setGameMode(GameMode.CREATIVE);
          msg(player, "You are now in creative.");
        }

        // ---- ----  END REWARD SCRIPT  ---- ----
        msg(
            player,
            "You now have &b"
                + VoteSQL.getVotesNotRewarded(player.getName())
                + "&6 votes to spend.");
        msg(player, head);
        return true;
      } else {
        msg(player, "Command not found");
        return true;
      }
    }
  }
Ejemplo n.º 19
0
 @Override
 public int getFoodLevel() {
   return caller.getFoodLevel();
 }
Ejemplo n.º 20
0
 public boolean commandUse(CommandSender sender, String[] args) {
   Variables var = Necessities.getVar();
   if (args.length == 0) {
     sender.sendMessage(
         var.getEr() + "Error: " + var.getErMsg() + "You must enter a player to view info of.");
     return true;
   }
   GetUUID get = Necessities.getUUID();
   UUID uuid = get.getID(args[0]);
   if (uuid == null) {
     uuid = get.getOfflineID(args[0]);
     if (uuid == null || !Bukkit.getOfflinePlayer(uuid).hasPlayedBefore()) {
       sender.sendMessage(
           var.getEr()
               + "Error: "
               + var.getErMsg()
               + "That player does not exist or has not joined the server. If the player is offline, please use the full and most recent name.");
       return true;
     }
   }
   User u = Necessities.getUM().getUser(uuid);
   sender.sendMessage(
       var.getMessages()
           + "===== WhoIs: "
           + var.getObj()
           + u.getName()
           + var.getMessages()
           + " =====");
   if (u.getPlayer() != null)
     sender.sendMessage(
         var.getMessages() + " - Nick: " + ChatColor.RESET + u.getPlayer().getDisplayName());
   else {
     sender.sendMessage(
         var.getMessages()
             + (u.getNick() == null
                 ? " - Name: " + ChatColor.RESET + u.getName()
                 : " - Nick: " + ChatColor.RESET + u.getNick()));
     Calendar c = Calendar.getInstance();
     c.setTimeInMillis(Bukkit.getOfflinePlayer(uuid).getLastPlayed());
     String second = Integer.toString(c.get(Calendar.SECOND));
     String minute = Integer.toString(c.get(Calendar.MINUTE));
     String hour = Integer.toString(c.get(Calendar.HOUR_OF_DAY));
     String day = Integer.toString(c.get(Calendar.DATE));
     String month = Integer.toString(c.get(Calendar.MONTH) + 1);
     String year = Integer.toString(c.get(Calendar.YEAR));
     hour = corTime(hour);
     minute = corTime(minute);
     second = corTime(second);
     sender.sendMessage(
         var.getMessages()
             + " - Seen last on "
             + ChatColor.RESET
             + month
             + "/"
             + day
             + "/"
             + year
             + " at "
             + hour
             + ":"
             + minute
             + " and "
             + second
             + " "
             + (Integer.parseInt(second) > 1 ? "seconds" : "second"));
   }
   sender.sendMessage(
       var.getMessages() + " - Time played: " + ChatColor.RESET + u.getTimePlayed());
   sender.sendMessage(var.getMessages() + " - Rank: " + ChatColor.RESET + u.getRank().getName());
   String subranks = u.getSubranks();
   if (subranks != null)
     sender.sendMessage(var.getMessages() + " - Subranks: " + ChatColor.RESET + subranks);
   String permissions = u.getPermissions();
   if (permissions != null)
     sender.sendMessage(
         var.getMessages() + " - Permission nodes: " + ChatColor.RESET + permissions);
   if (u.getPlayer() != null) {
     Player p = u.getPlayer();
     sender.sendMessage(
         var.getMessages()
             + " - Health: "
             + ChatColor.RESET
             + (int) p.getHealth()
             + "/"
             + (int) p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
     sender.sendMessage(
         var.getMessages()
             + " - Hunger: "
             + ChatColor.RESET
             + p.getFoodLevel()
             + "/20 (+"
             + (int) p.getSaturation()
             + " saturation)");
     sender.sendMessage(
         var.getMessages()
             + " - Exp: "
             + ChatColor.RESET
             + Utils.addCommas(p.getTotalExperience())
             + " (Level "
             + p.getLevel()
             + ")");
     String location =
         "("
             + p.getWorld().getName()
             + ", "
             + p.getLocation().getBlockX()
             + ", "
             + p.getLocation().getBlockY()
             + ", "
             + p.getLocation().getBlockZ()
             + ")";
     sender.sendMessage(var.getMessages() + " - Location: " + ChatColor.RESET + location);
   }
   if (u.getPlayer() != null) {
     Player p = u.getPlayer();
     sender.sendMessage(
         var.getMessages()
             + " - IP Address: "
             + ChatColor.RESET
             + p.getAddress().toString().split("/")[1].split(":")[0]);
     sender.sendMessage(
         var.getMessages()
             + " - Gamemode: "
             + ChatColor.RESET
             + Utils.capFirst(p.getGameMode().toString()));
   }
   if (u.getPlayer() != null) {
     Player p = u.getPlayer();
     sender.sendMessage(
         var.getMessages()
             + " - Banned: "
             + (p.isBanned() ? ChatColor.GREEN + "true" : ChatColor.DARK_RED + "false"));
     sender.sendMessage(
         var.getMessages()
             + " - Visible: "
             + (Necessities.getHide().isHidden(p)
                 ? ChatColor.DARK_RED + "false"
                 : ChatColor.GREEN + "true"));
     sender.sendMessage(
         var.getMessages()
             + " - OP: "
             + (p.isOp() ? ChatColor.GREEN + "true" : ChatColor.DARK_RED + "false"));
     sender.sendMessage(
         var.getMessages()
             + " - Fly mode: "
             + (p.isFlying()
                 ? ChatColor.GREEN + "true " + ChatColor.RESET + " (flying)"
                 : ChatColor.DARK_RED + "false" + ChatColor.RESET + " (not flying)"));
   } else {
     OfflinePlayer p = Bukkit.getOfflinePlayer(u.getUUID());
     sender.sendMessage(
         var.getMessages()
             + " - Banned: "
             + (p.isBanned() ? ChatColor.GREEN + "true" : ChatColor.DARK_RED + "false"));
     sender.sendMessage(
         var.getMessages()
             + " - OP: "
             + (p.isOp() ? ChatColor.GREEN + "true" : ChatColor.DARK_RED + "false"));
   }
   sender.sendMessage(
       var.getMessages()
           + " - Muted: "
           + (u.isMuted() ? ChatColor.GREEN + "true" : ChatColor.DARK_RED + "false"));
   return true;
 }
Ejemplo n.º 21
0
  public static void playerJoinArena(Player player, String arenaname) {
    boolean found = false;
    boolean alreadyJoined = false;
    for (Arena arena : W.arenaList) {
      if (arena.playersInArena != null) {
        if (arena.playersInArena.contains(player)) {
          alreadyJoined = true;
        }
      }
    }

    if (!alreadyJoined) {
      for (Arena arena : W.arenaList) {
        if (arena.arenaName.equalsIgnoreCase(arenaname)) {
          found = true;
          if (arena.disguiseBlocks.isEmpty()) {
            MessageM.sendFMessage(player, ConfigC.error_joinNoBlocksSet, true);
          } else {
            LocationSerializable zero =
                new LocationSerializable(Bukkit.getWorld("world"), 0, 0, 0, 0, 0);
            if (arena.lobbyWarp != null && arena.hidersWarp != null && arena.seekersWarp != null) {
              if (!arena.lobbyWarp.equals(zero)
                  && !arena.hidersWarp.equals(zero)
                  && !arena.seekersWarp.equals(zero)) {
                if (arena.gameState == ArenaState.WAITING
                    || arena.gameState == ArenaState.STARTING) {
                  if (arena.playersInArena.size() >= arena.maxPlayers) {
                    if (!PlayerM.hasPerm(player, PermsC.joinfull, false)) {
                      MessageM.sendFMessage(player, ConfigC.error_joinFull, true);
                      return;
                    }
                  }
                  arena.playersInArena.add(player);

                  W.pLocation.put(player, player.getLocation());
                  W.pGameMode.put(player, player.getGameMode());

                  player.teleport(arena.lobbyWarp);
                  player.setGameMode(GameMode.SURVIVAL);

                  W.pInventory.put(player, player.getInventory().getContents());
                  player.getInventory().clear();
                  player.updateInventory();
                  W.pArmor.put(player, player.getInventory().getArmorContents());
                  player.getInventory().setHelmet(new ItemStack(Material.AIR));
                  player.getInventory().setChestplate(new ItemStack(Material.AIR));
                  player.getInventory().setLeggings(new ItemStack(Material.AIR));
                  player.getInventory().setBoots(new ItemStack(Material.AIR));
                  W.pEXP.put(player, player.getExp());
                  player.setExp(0);
                  W.pEXPL.put(player, player.getLevel());
                  player.setLevel(0);
                  W.pHealth.put(player, player.getHealth());
                  player.setHealth(20);
                  W.pFood.put(player, player.getFoodLevel());
                  player.setFoodLevel(20);

                  ArenaHandler.sendFMessage(
                      arena,
                      ConfigC.normal_joinJoinedArena,
                      true,
                      "playername-" + player.getName(),
                      "1-" + arena.playersInArena.size(),
                      "2-" + arena.maxPlayers);
                  if (arena.playersInArena.size() < arena.minPlayers) {
                    ArenaHandler.sendFMessage(
                        arena, ConfigC.warning_lobbyNeedAtleast, true, "1-" + arena.minPlayers);
                  }
                } else {
                  MessageM.sendFMessage(player, ConfigC.error_joinArenaIngame, true);
                }
              } else {
                MessageM.sendFMessage(player, ConfigC.error_joinWarpsNotSet, true);
              }
            } else {
              MessageM.sendFMessage(player, ConfigC.error_joinWarpsNotSet, true);
            }
          }
        }
      }
    } else {
      MessageM.sendFMessage(player, ConfigC.error_joinAlreadyJoined, true);
      return;
    }

    if (!found) {
      MessageM.sendFMessage(player, ConfigC.error_noArena, true, "name-" + arenaname);
    }

    SignsHandler.updateSigns();
  }
Ejemplo n.º 22
0
  /**
   * Handle FoodLevelChange events that involve modifying the event.
   *
   * @param event The event to modify
   */
  @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
  public void onFoodLevelChange(FoodLevelChangeEvent event) {
    Entity entity = event.getEntity();

    if (!(entity instanceof Player)) {
      return;
    }

    Player player = (Player) entity;

    if (Misc.isNPCEntity(player)) {
      return;
    }

    int currentFoodLevel = player.getFoodLevel();
    int newFoodLevel = event.getFoodLevel();
    int foodChange = newFoodLevel - currentFoodLevel;

    if (foodChange <= 0) {
      return;
    }

    /*
     * Some foods have 3 ranks
     * Some foods have 5 ranks
     * The number of ranks is based on how 'common' the item is
     * We can adjust this quite easily if we find something is giving too much of a bonus
     */
    switch (player.getItemInHand().getType()) {
      case BAKED_POTATO: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
      case BREAD: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
      case CARROT_ITEM: /* RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */
      case GOLDEN_CARROT: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
      case MUSHROOM_SOUP: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
      case PUMPKIN_PIE: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
        if (Permissions.secondaryAbilityEnabled(player, SecondaryAbility.FARMERS_DIET)) {
          event.setFoodLevel(
              UserManager.getPlayer(player)
                  .getHerbalismManager()
                  .farmersDiet(Herbalism.farmersDietRankLevel1, newFoodLevel));
        }
        return;

      case COOKIE: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
      case MELON: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
      case POISONOUS_POTATO: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
      case POTATO_ITEM: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
        if (Permissions.secondaryAbilityEnabled(player, SecondaryAbility.FARMERS_DIET)) {
          event.setFoodLevel(
              UserManager.getPlayer(player)
                  .getHerbalismManager()
                  .farmersDiet(Herbalism.farmersDietRankLevel2, newFoodLevel));
        }
        return;

      case COOKED_FISH: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
        if (Permissions.secondaryAbilityEnabled(player, SecondaryAbility.FISHERMANS_DIET)) {
          event.setFoodLevel(
              UserManager.getPlayer(player)
                  .getFishingManager()
                  .handleFishermanDiet(Fishing.fishermansDietRankLevel1, newFoodLevel));
        }
        return;

      case RAW_FISH: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
        if (Permissions.secondaryAbilityEnabled(player, SecondaryAbility.FISHERMANS_DIET)) {
          event.setFoodLevel(
              UserManager.getPlayer(player)
                  .getFishingManager()
                  .handleFishermanDiet(Fishing.fishermansDietRankLevel2, newFoodLevel));
        }
        return;

      default:
        return;
    }
  }
Ejemplo n.º 23
0
  /**
   * Monitor FoodLevelChange events.
   *
   * @param event The event to monitor
   */
  @EventHandler(priority = EventPriority.LOW)
  public void onFoodLevelChange(FoodLevelChangeEvent event) {
    if (LoadProperties.herbalismHungerBonus) {
      if (event.getEntity() instanceof Player) {
        Player player = (Player) event.getEntity();
        PlayerProfile PP = Users.getProfile(player);
        int currentFoodLevel = player.getFoodLevel();
        int newFoodLevel = event.getFoodLevel();

        /* Some foods have 3 ranks
         * Some foods have 5 ranks
         * The number of ranks is based on how 'common' the item is
         * We can adjust this quite easily if we find something is giving too much of a bonus
         */

        if (newFoodLevel > currentFoodLevel) {
          Material food = player.getItemInHand().getType();
          int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
          int foodChange = newFoodLevel - currentFoodLevel;
          int rankChange = 0;

          switch (food) {
            case BREAD:
              /* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
              rankChange = 200;
              break;

            case COOKIE:
              /* COOKIE RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
              rankChange = 400;
              break;

            case MELON:
              /* MELON RESTORES  1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
              rankChange = 400;
              break;

            case MUSHROOM_SOUP:
              /* MUSHROOM SOUP RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
              rankChange = 200;
              break;

            default:
              return;
          }

          for (int i = 200; i <= 1000; i += rankChange) {
            if (herbLevel >= i) {
              foodChange++;
            }
          }

          /* Make sure we don't go over the max value */
          newFoodLevel = currentFoodLevel + foodChange;
          if (newFoodLevel > 20) {
            event.setFoodLevel(20);
          } else {
            event.setFoodLevel(newFoodLevel);
          }
        }
      }
    }
  }