Untitled
unknown
plain_text
7 days ago
8.0 kB
4
Indexable
Never
public class Trepador extends ConfigurableKit { private ItemStack grapple; private String grappleName; private double v_x = 0.07, v_y = 0.03, v_z = 0.07, gravity = -0.08; private final Material[] blockedGancho = new Material[]{Material.WOODEN_DOOR, Material.FENCE_GATE,Material.FENCE}; @Override protected void onLoadKit() { Delays.getInstance().createNewDelay(getInternalName(), null); this.grapple = KitUtils.addSoulbound(this.getIcon().clone()); ItemMeta m = this.grapple.getItemMeta(); m.setDisplayName(this.grappleName); this.grapple.setItemMeta(m); } @Override public boolean hasDelayItem() { return true; } @Override public List<ItemStack> itemsKit() { return getFinalLoadout().getLoadout(); } @Override public String getPermisoKit() { return "trepador"; } public List<String> getFinalLore(Player arg0) { return Arrays.asList("", "${items.commons.select}"); } @Override public Requirement[] getRequirements() { return new Requirement[]{ new StatsRequirement(TiposDeEstadisticas.GOLPES_NEXUS, 850)}; } @Override public String getInternalName() { return "Trepador"; } @Override public String getDisplayName() { return getNameKit(); } @Override protected ItemStack getIcon() { return new ItemStack(Material.FISHING_ROD); } @Override protected int setDefaults(ConfigurationSection section) { int save = 0; save += ConfigManager.setDefaultIfNotSet(section, "GrappleItemName", ChatColor.GREEN + "Trepador"); save += ConfigManager.setDefaultIfNotSet(section, "VectorMovable.vectorX", 0.07); save += ConfigManager.setDefaultIfNotSet(section, "VectorMovable.vectorY", 0.03); save += ConfigManager.setDefaultIfNotSet(section, "VectorMovable.vectorZ", 0.07); save += ConfigManager.setDefaultIfNotSet(section, "VectorMovable.vectorGravity", -0.08); return save; } @Override protected void loadKitStuff(ConfigurationSection section) { super.loadKitStuff(section); this.grappleName = section.getString("GrappleItemName"); this.v_x = section.getDouble("VectorMovable.vectorX", 0.07); this.v_y = section.getDouble("VectorMovable.vectorY", 0.03); this.v_z = section.getDouble("VectorMovable.vectorZ", 0.07); this.gravity = section.getDouble("VectorMovable.vectorGravity", -0.08); } private boolean isGrappleItem(ItemStack stack) { return stack != null && stack.hasItemMeta() && stack.getItemMeta().hasDisplayName() && (stack.getItemMeta().getDisplayName()).contains(this.grappleName) && KitUtils.isSoulbound(stack); } @Override protected List<String> getDefaultDescription() { ArrayList<String> l = new ArrayList<>(); this.addToList(l, "${anni.kits.climber.description}"); return getKitDescription(); } @EventHandler public void onIteract(PlayerInteractEvent e) { Player player = e.getPlayer(); AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId()); if (p != null && Delays.getInstance().hasActiveDelay(player, this.getInternalName()) && e.getMaterial() != null && e.getMaterial() == Material.FISHING_ROD) { e.setCancelled(true); e.setUseInteractedBlock(Event.Result.DENY); e.setUseItemInHand(Event.Result.DENY); player.updateInventory(); } } @EventHandler(priority = EventPriority.NORMAL) public void grappler(PlayerFishEvent event) { Location hookLoc = event.getHook().getLocation().getBlock().getRelative(BlockFace.DOWN).getLocation(); Player player = event.getPlayer(); AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId()); if (p != null && p.getKit().equals(this) && this.isGrappleItem(player.getItemInHand()) && !Delays.getInstance().hasActiveDelay(player, event.getPlayer().getName())) { if (event.getState() == PlayerFishEvent.State.IN_GROUND || event.getState() == PlayerFishEvent.State.FAILED_ATTEMPT) { if (!hookLoc.getBlock().getType().isSolid() && !hookLoc.getBlock().getType().name().contains("WATER")) { return; } for (Material blockType: blockedGancho){ if(blockType.equals(hookLoc.getBlock().getType())){ return; } } if (!GameVars.isClimberOutSide()) { GameMap map = Game.getGameMap(); if (map != null) { AccessManager areas = map.getAreasAccess(); if (areas != null) { if (areas.getArea(new Loc(player.getLocation(), true)) == null) { p.sendMessage("${anni.kits.climber.out}"); return; } } } } Delays.getInstance().addDelay(player, System.currentTimeMillis() + getCooldown(), event.getPlayer().getName(), getInternalName()); p.playSound(Sound.LAVA_POP, 5, 1); p.playEffect(Effect.BLAZE_SHOOT); player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20 * 5, 0, true, true)); DamageControl.addTempImmunity(player, EntityDamageEvent.DamageCause.FALL, System.currentTimeMillis() + 8000); Location playerloc = player.getLocation(); Location loc = event.getHook().getLocation(); if (playerloc.distance(loc) < 3.0) { this.pullPlayerSlightly(player, loc); } else { this.pullEntityToLocation(player, loc); } player.getItemInHand().setDurability((short) 0); } } } private void pullPlayerSlightly(Player p, Location loc) { if (loc.getY() > p.getLocation().getY()) { p.setVelocity(new Vector(0.0, 0.25, 0.0)); return; } Location playerLoc = p.getLocation(); Vector vector = loc.toVector().subtract(playerLoc.toVector()); if (Utils.isNaNorInifinityVector(vector)) { DTNMain.log("&cError de tipo NaN 0x0002 " + getClass().getName()); return; } p.setVelocity(vector); } private void pullEntityToLocation(Entity e, Location loc) { Location entityLoc = e.getLocation(); entityLoc.setY(entityLoc.getY() + 0.5); e.teleport(entityLoc); double g = (this.gravity); double t = loc.distance(entityLoc); double v_x = (1.0 + (this.v_x) * t) * (loc.getX() - entityLoc.getX()) / t; double v_y = (1.0 + (this.v_y) * t) * (loc.getY() - entityLoc.getY()) / t - 0.5 * g * t; double v_z = (1.0 + (this.v_z) * t) * (loc.getZ() - entityLoc.getZ()) / t; Vector v = e.getVelocity(); v.setX(v_x); v.setY(v_y); v.setZ(v_z); if (Utils.isNaNorInifinityVector(v)) { DTNMain.log("&cError de tipo NaN 0x0002 " + getClass().getName()); return; } e.setVelocity(v); } @Override public void cleanup(Player arg0) { } @Override public Loadout getFinalLoadout() { return new Loadout().addGoldSword().addWoodPick().addWoodAxe().addItem(KitUtils.addSoulbound(this.grapple)).addSoulboundItem(new ItemStack(Material.WORKBENCH)).addNavCompass() .setArmor(getArmorItemStack()); } @Override public void onPlayerSpawn(final Player player, boolean giveItems) { super.onPlayerSpawn(player, giveItems); } }
Leave a Comment