Ejemplo n.º 1
0
 private boolean cmdFeed(final CommandSender sender, final String[] args) {
   if (args.length == 0) {
     if (!(sender instanceof Player)) {
       this.plugin.sendMessage(sender, MessageId.cmdOnlyAvailableForPlayers);
     } else {
       final Player player = (Player) sender;
       player.setFoodLevel(20);
       player.setSaturation(20f);
       this.plugin.sendMessage(player, MessageId.general_feed_autoFeed);
     }
   } else {
     for (final String arg : args) {
       for (final String playerName : arg.split(",")) {
         final Player player = Bukkit.getPlayer(playerName);
         if (player == null) {
           this.plugin.sendMessage(sender, MessageId.noPlayerFoundForGivenName, playerName);
         } else {
           player.setFoodLevel(20);
           player.setSaturation(20f);
           this.plugin.sendMessage(player, MessageId.general_feed_fedBy, sender.getName());
           this.plugin.sendMessage(sender, MessageId.general_feed_fed, player.getName());
         }
       }
     }
   }
   return true;
 }
 @Override
 public void run(final CommandSender cs, String label, String[] args) {
   if (!r.perm(cs, "uc.sethunger", false, true)) {
     return;
   }
   if (!r.checkArgs(args, 0)) {
     if (!r.isPlayer(cs)) {
       return;
     }
     Player p = (Player) cs;
     p.setFoodLevel(20);
     p.setSaturation(10F);
     r.sendMes(cs, "sethungerMessage", "%Player", r.getDisplayName(p), "%Food", "20");
   } else if (r.checkArgs(args, 0) && !r.checkArgs(args, 1)) {
     if (!r.isPlayer(cs)) {
       return;
     }
     if (r.isInt(args[0])) {
       Integer d = Integer.parseInt(args[0]);
       Player p = (Player) cs;
       p.setFoodLevel(r.normalize(d, 0, 20));
       r.sendMes(
           cs, "sethungerMessage", "%Player", r.getDisplayName(p), "%Food", r.normalize(d, 0, 20));
     } else {
       r.sendMes(cs, "numberFormat", "%Number", args[0]);
     }
   } else if (r.checkArgs(args, 1)) {
     if (!r.perm(cs, "uc.sethunger.others", false, true)) {
       return;
     }
     if (r.isInt(args[0])) {
       Integer d = Integer.parseInt(args[0]);
       Player t = r.searchPlayer(args[1]);
       if (t == null) {
         r.sendMes(cs, "playerNotFound", "%Player", args[1]);
         return;
       }
       t.setFoodLevel(r.normalize(d, 0, 20));
       t.setSaturation(10F);
       r.sendMes(cs, "sethungerMessage", "%Player", t.getName(), "%Food", r.normalize(d, 0, 20));
       r.sendMes(
           t, "sethungerOthers", "%Player", r.getDisplayName(cs), "%Food", r.normalize(d, 0, 20));
     } else if (r.isInt(args[1])) {
       Integer d = Integer.parseInt(args[1]);
       Player t = r.searchPlayer(args[0]);
       if (t == null) {
         r.sendMes(cs, "playerNotFound", "%Player", args[0]);
         return;
       }
       t.setFoodLevel(r.normalize(d, 0, 20));
       t.setSaturation(10F);
       r.sendMes(cs, "sethungerMessage", "%Player", t.getName(), "%Food", r.normalize(d, 0, 20));
       r.sendMes(
           t, "sethungerOthers", "%Player", r.getDisplayName(cs), "%Food", r.normalize(d, 0, 20));
     } else {
       r.sendMes(cs, "numberFormat", "%Number", args[0]);
     }
   }
 }
Ejemplo n.º 3
0
  @EventHandler
  public void onMove(PlayerMoveEvent e) {
    Player p = e.getPlayer();
    double x = p.getLocation().getX();
    double y = p.getLocation().getY() - 1;
    double z = p.getLocation().getZ();
    Location loc = new Location(p.getWorld(), x, y, z);
    Block b1 = loc.getBlock();
    Block b2 = p.getLocation().getBlock();

    if (b1.getType().equals(Material.REDSTONE_BLOCK) && b2.getType().equals(Material.WOOD_PLATE)) {
      // p.sendMessage("ON " + b1.getType().toString() + " + " + b2.getType().toString());
      p.setVelocity(p.getLocation().getDirection().multiply(2).setY(p.getVelocity().getY() + 1));
      p.setFallDistance(0f);
      for (Player all : Bukkit.getOnlinePlayers()) {
        all.playSound(p.getLocation(), Sound.WITHER_SHOOT, 0.1f, 0.1f);
      }
    }

    p.setSaturation(100f);
    p.setFoodLevel(20);
    p.setHealth(20f);

    if (p.getLocation().getY() <= 80) {
      p.teleport(p.getWorld().getSpawnLocation());
      p.setGameMode(GameMode.ADVENTURE);
      p.setAllowFlight(true);
      p.setFlying(false);
    }
  }
Ejemplo n.º 4
0
  public void removeSpectator(Player p) {
    ArrayList<Player> players = new ArrayList<Player>();
    players.addAll(activePlayers);
    players.addAll(inactivePlayers);

    if (p.isOnline()) {
      for (Player pl : Bukkit.getOnlinePlayers()) {
        pl.showPlayer(p);
      }
    }
    // restoreInv(p);
    p.setAllowFlight(false);
    p.setFlying(false);
    p.setFallDistance(0);
    p.setHealth(p.getMaxHealth());
    p.setFoodLevel(20);
    p.setSaturation(20);
    p.teleport(SettingsManager.getInstance().getLobbySpawn());
    // Bukkit.getServer().broadcastPrefixType("Removing Spec "+p.getName()+" "+spectators.size()+"
    // left");
    spectators.remove(p.getName());
    // Bukkit.getServer().broadcastPrefixType("Removed");

    nextspec.remove(p);
  }
Ejemplo n.º 5
0
	@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;
	}
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
0
 @EventHandler
 public void onEat(PlayerItemConsumeEvent e) {
   if (e.getItem() != null) {
     final Player p = e.getPlayer();
     ItemStack item = e.getItem();
     if (Slimefun.hasUnlocked(p, item, true)) {
       if (SlimefunManager.isItemSimiliar(item, SlimefunItems.MONSTER_JERKY, true)) {
         PlayerInventory.consumeItemInHand(p);
         e.setItem(new ItemStack(Material.APPLE));
       } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.FORTUNE_COOKIE, true))
         p.sendMessage(
             Messages.local
                 .getTranslation("messages.fortune-cookie")
                 .get(
                     CSCoreLib.randomizer()
                         .nextInt(
                             Messages.local.getTranslation("messages.fortune-cookie").size())));
       else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BEEF_JERKY, true))
         p.setSaturation((Integer) Slimefun.getItemValue("BEEF_JERKY", "Saturation"));
       else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GRILLED_CHEESE, true))
         p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 8, 0));
       else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BUTTERED_POTATO, true))
         p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 8, 0));
       else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.MEDICINE, true)) {
         if (p.hasPotionEffect(PotionEffectType.POISON))
           p.removePotionEffect(PotionEffectType.POISON);
         if (p.hasPotionEffect(PotionEffectType.WITHER))
           p.removePotionEffect(PotionEffectType.WITHER);
         if (p.hasPotionEffect(PotionEffectType.SLOW)) p.removePotionEffect(PotionEffectType.SLOW);
         if (p.hasPotionEffect(PotionEffectType.SLOW_DIGGING))
           p.removePotionEffect(PotionEffectType.SLOW_DIGGING);
         if (p.hasPotionEffect(PotionEffectType.WEAKNESS))
           p.removePotionEffect(PotionEffectType.WEAKNESS);
         if (p.hasPotionEffect(PotionEffectType.CONFUSION))
           p.removePotionEffect(PotionEffectType.CONFUSION);
         if (p.hasPotionEffect(PotionEffectType.BLINDNESS))
           p.removePotionEffect(PotionEffectType.BLINDNESS);
         p.setFireTicks(0);
       } else if (item.getType() == Material.POTION) {
         SlimefunItem sfItem = SlimefunItem.getByItem(item);
         if (sfItem != null && sfItem instanceof Juice) {
           Bukkit.getScheduler()
               .scheduleSyncDelayedTask(
                   main.instance,
                   new Runnable() {
                     @Override
                     public void run() {
                       p.getInventory().removeItem(new ItemStack(Material.GLASS_BOTTLE, 1));
                     }
                   },
                   1L);
         }
       }
     } else e.setCancelled(true);
   }
 }
Ejemplo n.º 8
0
  @EventHandler
  public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    PlayerInfo playerInfo = Xitron.get(player);

    player.setFoodLevel(20);
    player.setSaturation(20);

    if (playerInfo.getGame().equals("SnowPunch")) Snow.playerMove(player);
  }
Ejemplo n.º 9
0
 private boolean cmdFood(final CommandSender sender, final String[] args) {
   if (args.length == 0) {
     return false;
   } else {
     final int value;
     try {
       value = Math.min(20, Integer.parseInt(args[args.length - 1]));
       if (value < 0) {
         return false;
       }
     } catch (final NumberFormatException e) {
       return false;
     }
     if (args.length == 1) {
       if (!(sender instanceof Player)) {
         this.plugin.sendMessage(sender, MessageId.cmdOnlyAvailableForPlayers);
       } else {
         final Player player = (Player) sender;
         player.setFoodLevel(value);
         player.setSaturation(value);
         this.plugin.sendMessage(player, MessageId.general_food_autoSet, Integer.toString(value));
       }
     } else {
       for (int i = 0; i < args.length - 1; i++) {
         final String arg = args[i];
         for (final String playerName : arg.split(",")) {
           final Player player = Bukkit.getPlayer(playerName);
           if (player == null) {
             this.plugin.sendMessage(sender, MessageId.noPlayerFoundForGivenName, playerName);
           } else {
             player.setFoodLevel(value);
             player.setSaturation(value);
             this.plugin.sendMessage(
                 player, MessageId.general_food_setBy, sender.getName(), Integer.toString(value));
             this.plugin.sendMessage(
                 sender, MessageId.general_food_set, player.getName(), Integer.toString(value));
           }
         }
       }
     }
   }
   return true;
 }
Ejemplo n.º 10
0
 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);
 }
Ejemplo n.º 11
0
  private void setWorldDefault(Player player, Group group) {
    File file =
        new File(plugin.getDefaultFilesDirectory() + File.separator + group.getName() + ".json");
    if (!file.exists()) {
      plugin.getPlayerMessenger().sendMessage(player, "Default file for this group not found!");
      return;
    }

    File tmp =
        new File(
            plugin.getDataFolder()
                + File.separator
                + "data"
                + File.separator
                + player.getUniqueId()
                + File.separator
                + "tmp.json");
    try {
      tmp.getParentFile().mkdirs();
      tmp.createNewFile();
    } catch (IOException ex) {
      plugin.getPlayerMessenger().sendMessage(player, "Could not create temporary file! Aborting!");
      return;
    }
    plugin
        .getSerializer()
        .writePlayerDataToFile(
            player,
            PlayerSerialization.serializePlayer(player, plugin),
            new Group("tmp", null, null),
            GameMode.SURVIVAL);

    player.setFoodLevel(20);
    player.setHealth(20);
    player.setSaturation(20);
    player.setTotalExperience(0);

    plugin
        .getSerializer()
        .writeData(file, Serializer.toString(PlayerSerialization.serializePlayer(player, plugin)));

    plugin
        .getSerializer()
        .getPlayerDataFromFile(player, new Group("tmp", null, null), GameMode.SURVIVAL);
    tmp.delete();
    plugin.getPlayerMessenger().sendMessage(player, "Defaults for '" + group.getName() + "' set!");
  }
Ejemplo n.º 12
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());
 }
Ejemplo n.º 13
0
  public void restore(Player player) {
    if (player.getName().equals(name)) {
      player.getInventory().clear();

      player.teleport(originLoc);
      player.setCompassTarget(compassTarget);

      player.setHealth(health);
      player.setFoodLevel(food);
      player.setSaturation(saturation);

      player.getInventory().setContents(inv);
      player.getInventory().setArmorContents(armor);

      player.setTotalExperience(exp);
    }
  }
Ejemplo n.º 14
0
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (args.length == 0) {
      ((Player) sender).setAllowFlight(!((Player) sender).getAllowFlight());
      sender.sendMessage(
          ChatColor.GOLD
              + "Toggled fly for "
              + ChatColor.RED
              + sender.getName()
              + ChatColor.GOLD
              + ". Flight: "
              + ChatColor.RED
              + ((Player) sender).getAllowFlight());

      return true;
    } else {
      String pla = args[0];
      Player p = Bukkit.getPlayer(pla);
      if (p == null) {
        sender.sendMessage(ChatColor.RED + "That player is not online.");
        return true;
      }
      p.setSaturation(20);
      p.setAllowFlight(!p.getAllowFlight());
      p.sendMessage(ChatColor.GOLD + "Allowed Flight: " + ChatColor.RED + p.getAllowFlight());
      sender.sendMessage(
          ChatColor.GOLD
              + "Toggled flight for "
              + ChatColor.RED
              + p.getName()
              + ChatColor.GOLD
              + ". Allowed Flight: "
              + ChatColor.RED
              + p.getAllowFlight());
      return true;
    }
  }
Ejemplo n.º 15
0
 @Override
 public void setSaturation(float saturation) {
   caller.setSaturation(saturation);
 }
Ejemplo n.º 16
0
  public void unload() {
    final Player player = Bukkit.getPlayerExact(name);

    if (player == null) {
      final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(name);
      PVPArena.instance.getAgm().disconnect(aPlayer.getArena(), aPlayer);
      return;
    }
    debug.i("restoring PlayerState of " + name, player);

    player.setFireTicks(fireticks);
    player.setFoodLevel(foodlevel);
    player.setGameMode(GameMode.getByValue(gamemode));

    final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(player.getName());
    player.setFoodLevel(foodlevel);
    if (player.getMaxHealth() != maxhealth) {
      final double newHealth = player.getMaxHealth() * health / maxhealth;
      if (newHealth > player.getMaxHealth()) {
        player.setHealth(player.getMaxHealth());
      } else {
        player.setHealth(newHealth);
      }

    } else {
      player.setHealth(health);
    }
    player.setSaturation(saturation);
    player.setGameMode(GameMode.getByValue(gamemode));
    player.setLevel(explevel);
    player.setExp(experience);
    player.setExhaustion(exhaustion);
    player.setFallDistance(0);
    player.setVelocity(new Vector());
    if (aPlayer.getArena() != null
        && aPlayer.getArena().getArenaConfig().getBoolean(CFG.CHAT_COLORNICK)) {
      player.setDisplayName(displayname);
    }

    if (aPlayer.getArena() != null) {

      ArenaModuleManager.unload(aPlayer.getArena(), player);
      PVPArena.instance.getAgm().unload(aPlayer.getArena(), player);
    }

    removeEffects(player);
    player.addPotionEffects(potionEffects);

    aPlayer.setTelePass(false);
    player.setFireTicks(fireticks);

    if (aPlayer.getArena() != null) {
      player.setNoDamageTicks(
          aPlayer.getArena().getArenaConfig().getInt(CFG.TIME_TELEPORTPROTECT) * 20);
    }
    player.resetPlayerTime();
    if (flying && !player.getAllowFlight()) {
      player.setAllowFlight(true);
    }
    player.setFlying(flying);
  }