/** * Apply this templates data to an EnderDragonBattle object * * @param nmsAbstract an instance of the NMSAbstract interface * @param dragon the dragon to modify * @param battle the battle to modify */ public void applyToBattle(NMSAbstract nmsAbstract, EnderDragon dragon, DragonBattle battle) { Validate.notNull(nmsAbstract, "Instance of NMSAbstract cannot be null. See DragonEggDrop#getNMSAbstract()"); Validate.notNull(dragon, "Ender Dragon cannot be null"); Validate.notNull(battle, "Instance of DragonBattle cannot be null"); if (name != null) { dragon.setCustomName(name); battle.setBossBarTitle(name); } battle.setBossBarStyle(barStyle, barColour); this.attributes.forEach((a, v) -> { AttributeInstance attribute = dragon.getAttribute(a); if (attribute != null) { attribute.setBaseValue(v); } }); // Set health... max health attribute doesn't do that for me. -,- if (attributes.containsKey(Attribute.GENERIC_MAX_HEALTH)) { dragon.setHealth(attributes.get(Attribute.GENERIC_MAX_HEALTH)); } }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerLogin(PlayerJoinEvent e) { Player p = e.getPlayer(); World world = p.getWorld(); double GAS = module().getDouble("generic-attack-speed"); AttributeInstance attribute = p.getAttribute(Attribute.GENERIC_ATTACK_SPEED); double baseValue = attribute.getBaseValue(); if(!Config.moduleEnabled("disable-attack-cooldown", world)) GAS = 4; //If module is disabled, set attack speed to 1.9 default if(baseValue!=GAS){ attribute.setBaseValue(GAS); p.saveData(); } }
@EventHandler(priority = EventPriority.HIGHEST) public void onWorldChange(PlayerChangedWorldEvent e) { Player player = e.getPlayer(); World world = player.getWorld(); double GAS = module().getDouble("generic-attack-speed"); AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); double baseValue = attribute.getBaseValue(); if(!Config.moduleEnabled("disable-attack-cooldown", world)) GAS = 4; //If module is disabled, set attack speed to 1.9 default if(baseValue!=GAS){ attribute.setBaseValue(GAS); player.saveData(); } }
private Player mockPlayer(String name, GameMode gameMode) { Player mock = mock(Player.class); PlayerInventory inv = mock(PlayerInventory.class); inv.setContents(new ItemStack[39]); inv.setArmorContents(new ItemStack[4]); Inventory enderChest = mock(Inventory.class); enderChest.setContents(new ItemStack[27]); given(mock.getInventory()).willReturn(inv); given(mock.getEnderChest()).willReturn(enderChest); given(mock.getName()).willReturn(name); given(mock.getUniqueId()).willReturn(TestHelper.TEST_UUID); given(mock.getGameMode()).willReturn(gameMode); AttributeInstance attribute = mock(AttributeInstance.class); given(mock.getAttribute(Attribute.GENERIC_MAX_HEALTH)).willReturn(attribute); given(attribute.getBaseValue()).willReturn(20.0); return mock; }
@EventHandler public void onSpawn(CreatureSpawnEvent event) { LivingEntity e = event.getEntity(); WorldSettings set = plugin.getWorlds().get(event.getEntity().getWorld().getName()); if (set == null) { return; } if (!set.getEntities().contains(e.getType())) { return; } if (!set.shouldExist(e)) { event.setCancelled(true); } else if (rand.nextDouble() > set.getRatio(e.getType())) { event.setCancelled(true); } else { AttributeInstance maxHealth = e.getAttribute(Attribute.GENERIC_MAX_HEALTH); maxHealth.setBaseValue(maxHealth.getBaseValue() * set.getHealth(e.getType())); e.setHealth(e.getMaxHealth()); } }
private boolean addModifier0(Attribute attribute, AttributeModifier modifier) { final AttributeInstance attributeInstance = player.getAttribute(attribute); if(attributeInstance != null && !attributeInstance.getModifiers().contains(modifier)) { attributeInstance.addModifier(modifier); return true; } return false; }
private boolean removeModifier0(Attribute attribute, AttributeModifier modifier) { AttributeInstance attributeValue = player.getAttribute(attribute); if(attributeValue != null && attributeValue.getModifiers().contains(modifier)) { attributeValue.removeModifier(modifier); return true; } return false; }
@Override public AttributeInstance getAttribute(Attribute attribute) { if (attributes.containsKey(attribute)) { return attributes.get(attribute); } else { throw new UnimplementedOperationException(); } }
public DungeonBoss(Location loc, EntityType type, String name, boolean finalBoss) { super(loc, type, name); this.finalBoss = finalBoss; getBukkit().setCustomName(ChatColor.RED + name); getBukkit().setCustomNameVisible(true); AttributeInstance a = getLiving().getAttribute(Attribute.GENERIC_MAX_HEALTH); a.addModifier(new AttributeModifier("mult", 1, AttributeModifier.Operation.ADD_SCALAR)); // Double boss health. getLiving().setHealth(a.getValue()); // Max out health. }
private void clearStats() { Player player = this.player.getPlayer(); AttributeInstance speedAttribute = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); AttributeModifier rpgInvModifier = null; for (AttributeModifier modifier : speedAttribute.getModifiers()) { if (modifier.getUniqueId().compareTo(Attributes.SPEED_MODIFIER_ID) == 0) { rpgInvModifier = modifier; } } if (rpgInvModifier != null) { speedAttribute.removeModifier(rpgInvModifier); } }
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); if (api.getGameManager().isLegacyPvP()) { AttributeInstance genericAttackSpeedAttribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); if (genericAttackSpeedAttribute != null) genericAttackSpeedAttribute.setBaseValue(1024.0D); } }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerQuit(PlayerQuitEvent e){ Player player = e.getPlayer(); AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); double baseValue = attribute.getBaseValue(); if (baseValue != 4){ //If basevalue is not 1.9 default, set it back attribute.setBaseValue(4); player.saveData(); } }
/** * Sets the provided attribute up with a modifier by the given name (overwriting one if it exists) * for the given amount. * <b>This is done</b> under the {@link AttributeModifier.Operation#ADD_SCALAR} operation! */ public static void setAttributeModifier(AttributeInstance attribute, String name, double amt) { Collection<AttributeModifier> mods = attribute.getModifiers(); for (AttributeModifier mod : mods) { if (mod.getName().equals(name)) { attribute.removeModifier(mod); break; } } attribute.addModifier(new AttributeModifier(name, amt, AttributeModifier.Operation.ADD_SCALAR)); }
/** * Gives an increased max health reward to a player. * * @param player * @param amount * @return the reward text to display to the player */ @SuppressWarnings("deprecation") private String rewardMaxHealth(Player player, int amount) { if (plugin.getServerVersion() >= 9) { AttributeInstance playerAttribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); playerAttribute.setBaseValue(playerAttribute.getBaseValue() + amount); } else { player.setMaxHealth(player.getMaxHealth() + amount); } return ChatColor.translateAlternateColorCodes('&', StringUtils.replaceOnce(langIncreaseMaxHealthRewardReceived, "AMOUNT", Integer.toString(amount))); }
public static void onEntityTargetPlayer(EntityTargetLivingEntityEvent event) { if (event.getTarget() instanceof Player) { Player player = (Player) event.getTarget(); if (event.getEntity() instanceof LivingEntity) { LivingEntity attacker = (LivingEntity) event.getEntity(); if ((event.getEntity().getCustomName() != null) && (player.getName() != null)) { if (event.getEntity().getCustomName().startsWith(player.getName())) { //we are attacking our creator if (attacker.getHealth() < (player.getLevel() + 1.0f) * player.getHealth() * 0.05f) { event.setCancelled(true); } //make minions not harm their creators if the creators are tough enough //level 20 will do it for normal 20 heart mobs. Assumes you're not injured. } else { //we're attacking a player that's not our creator AttributeInstance speedAttribute = attacker.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); if (speedAttribute.getValue() > Math.sqrt(player.getLevel())) { event.setCancelled(true); } //ultra hyper mobs are seeking high level players if ((attacker.getHealth()) > ((player.getLevel() + 1.0f) * player.getHealth())) { event.setCancelled(true); }//mobs try to get you down to level*health is less than their health. //If you're level 0, almost any damage ought to make them relent //If you're over level 20, you'll be dead before they trust you. } } else { if ((attacker.getHealth()) > ((player.getLevel() + 1.0f) * player.getHealth())) { event.setCancelled(true); }//mobs try to get you down to level*health is less than their health. //If you're level 0, almost any damage ought to make them relent //If you're over level 20, you'll be dead before they trust you. } } } }
@Override public AttributeInstance getAttribute(Attribute attribute) { Preconditions.checkArgument(attribute != null, "attribute"); net.minecraft.server.AttributeInstance nms = handle.a(toMinecraft(attribute.name())); return (nms == null) ? null : new CraftAttributeInstance(nms, attribute); }
public AttributeType(AttributeInstance instance) { this.instance = instance; set("baseValue", instance.getBaseValue()); //newFunction(new SetBaseValue(instance)); autoFunc(this, AttributeType.class); }
public SetBaseValue(AttributeInstance instance) { this.instance = instance; }
public static void removeModifier(Attributable attributable, AttributeModifier modifier) { for(Attribute attribute : Attribute.values()) { final AttributeInstance instance = attributable.getAttribute(attribute); if(instance != null) instance.removeModifier(modifier); } }
public static void removeAllModifiers(AttributeInstance attributeInstance) { attributeInstance.getModifiers().forEach(attributeInstance::removeModifier); }
public static void removeAllModifiers(Attributable attributable, Attribute attribute) { final AttributeInstance instance = attributable.getAttribute(attribute); if(instance != null) removeAllModifiers(instance); }
@Override public AttributeInstance getAttribute(Attribute attribute) { return implementation.getAttribute(attribute); }
@Override public AttributeInstance getAttribute( Attribute attribute ) { return null; }
@Override public AttributeInstance getAttribute(Attribute attribute) { return player.getAttribute(attribute); }
@Override public AttributeInstance getAttribute(Attribute attribute) { return null; }
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length < 1) {//Tell them about available commands PluginDescriptionFile pdf = plugin.getDescription(); Chatter.send(sender, ChatColor.DARK_GRAY + Chatter.HORIZONTAL_BAR); Chatter.send(sender, "&6&lOldCombatMechanics&e by &cgvlfm78&e and &cRayzr522&e version &6%s", pdf.getVersion()); Chatter.send(sender, "&eYou can use &c/ocm reload&e to reload the config file"); if (plugin.getConfig().getBoolean("enableIndividualToggle") && sender.hasPermission("oldcombatmechanics.toggle") && sender instanceof Player) { Chatter.send(sender, "&eYou can use &c/ocm toggle&e to turn your attack cooldown on/off"); } Chatter.send(sender, ChatColor.DARK_GRAY + Chatter.HORIZONTAL_BAR); // Check for updates Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> new UpdateChecker(plugin, pluginFile).sendUpdateMessages(sender)); return true; } // Get the sub-command String sub = args[0].toLowerCase(); if (sub.equals("reload")) {// Reloads config if (!sender.hasPermission("oldcombatmechanics.reload")) { Chatter.send(sender, NO_PERMISSION, "oldcombatmechanics.reload"); return true; } Config.reload(); Chatter.send(sender, "&6&lOldCombatMechanics&e config file reloaded"); return true; } else if (sub.equals("toggle") && plugin.getConfig().getBoolean("enableIndividualToggle") && sender instanceof Player) { if (!sender.hasPermission("oldcombatmechanics.toggle")) { Chatter.send(sender, NO_PERMISSION, "oldcombatmechanics.toggle"); return true; } // Toggle their cooldown Player p = (Player) sender; double GAS = plugin.getConfig().getDouble("disable-attack-cooldown.generic-attack-speed"); AttributeInstance attribute = p.getAttribute(Attribute.GENERIC_ATTACK_SPEED); double baseValue = attribute.getBaseValue(); String message = "&1[OCM] &aAttack cooldown "; if (baseValue == GAS) { // Toggle GAS = 4; message += "enabled"; } else { message += "disabled"; } attribute.setBaseValue(GAS); p.saveData(); Chatter.send(p, message); return true; } return false; }
public static void reload() { if (plugin.doesConfigymlExist()) { plugin.reloadConfig(); config = plugin.getConfig(); } else plugin.upgradeConfig(); if (checkConfigVersion()) { // checkConfigVersion will call #reload() again anyways return; } //plugin.restartTask(); //Restart no-collision check plugin.restartSweepTask(); //Restart sword sweep check Messenger.DEBUG_ENABLED = config.getBoolean("debug.enabled"); if (Config.moduleEnabled("old-tool-damage")) WeaponDamages.Initialise(plugin); //Reload weapon damages from config //if(Config.moduleEnabled("old-armour-strength")) ArmourValues.Initialise(plugin); //Reload armour values from config //Setting correct attack speed and armour values for online players for (World world : Bukkit.getWorlds()) { List<Player> players = world.getPlayers(); double GAS = plugin.getConfig().getDouble("disable-attack-cooldown.generic-attack-speed"); if (!Config.moduleEnabled("disable-attack-cooldown", world)) GAS = 4; //If module is disabled, set attack speed to 1.9 default boolean isArmourEnabled = Config.moduleEnabled("old-armour-strength", world); for (Player player : players) { //Setting attack speed AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); double baseValue = attribute.getBaseValue(); if (baseValue != GAS) { attribute.setBaseValue(GAS); player.saveData(); } //Setting armour values ModuleOldArmourStrength.setArmourAccordingly(player, isArmourEnabled); } } ModuleLoader.ToggleModules(); if (Config.moduleEnabled("disable-offhand")) ModuleDisableOffHand.INSTANCE.reloadList(); if (Config.moduleEnabled("old-golden-apples")) { ModuleGoldenApple.INSTANCE.reloadRecipes(); ModuleGoldenApple.INSTANCE.registerCrafting(); } if (Config.moduleEnabled("sword-blocking") || Config.moduleEnabled("disable-elytra")) reloadInteractiveBlocks(); if (Config.moduleEnabled("sword-blocking")) ModuleSwordBlocking.INSTANCE.reload(); if (moduleEnabled("disable-crafting")) ModuleDisableCrafting.INSTANCE.reload(); }
@EventHandler public void onJoin(final PlayerJoinEvent e) { if (e.getPlayer().isBanned()) { e.getPlayer().kickPlayer(NationZ.title + "\n" + NationZ.line(ChatColor.AQUA) + "\n" + ChatColor.RED + " " + "\n" + ChatColor.DARK_RED + "You were banned!" + "\n" + ChatColor.RED + " " + "\n" + ChatColor.RED + "You didn't stick to the Server-Rules and now received your punishment!" + "\n" + ChatColor.RED + " " + "\n" + ChatColor.RED + "There is no chance for unbanning since Players who don't stick to the rules," + "\n" + ChatColor.RED + "ruin the game, the fun and the Server." + "\n" + ChatColor.RED + " " + "\n" + NationZ.line(ChatColor.AQUA)); notWhitelisted = true; return; } else if (!e.getPlayer().isWhitelisted()) { e.getPlayer().kickPlayer(NationZ.title + "\n" + NationZ.line(ChatColor.AQUA) + "\n" + ChatColor.RED + " " + "\n" + ChatColor.DARK_RED + "You are not whitelisted!" + "\n" + ChatColor.RED + " " + "\n" + ChatColor.RED + "Please buy a " + NationZ.title + ChatColor.RED + "-Pass to join the Server." + "\n" + ChatColor.RED + "You can buy passes here: " + ChatColor.YELLOW + FC.getMainCfg().getString("link.pass") + "\n" + ChatColor.RED + " " + "\n" + ChatColor.DARK_RED + "You" + ChatColor.WHITE + "Tuber" + ChatColor.RED + " and more than 10.000 Subscribers?" + "\n" + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-->" + ChatColor.YELLOW + " " + FC.getMainCfg().getString("link.pass") + "\n" + ChatColor.RED + " " + "\n" + NationZ.line(ChatColor.AQUA)); notWhitelisted = true; return; } AttributeInstance instance = e.getPlayer().getAttribute(Attribute.GENERIC_ATTACK_SPEED); if (instance != null) { instance.setBaseValue(16); } NZPlayer nz = NZPlayer.getNZPlayer(e.getPlayer()); if (nz.getNation() != null) { nz.getNation().reAddToNation(e.getPlayer()); } if (nz.getJob() != null) { nz.getJob().reAddToJob(e.getPlayer(), nz.getJobLevel()); } if (nz.getLastName() == null) { nz.addName(e.getPlayer().getName()); } else { if (!(nz.getLastName().equals(e.getPlayer().getName()))) { nz.addName(e.getPlayer().getName()); } } AsyncPlayerChatListener.checkForChat(e.getPlayer(), false); e.setJoinMessage(null); e.getPlayer().getInventory().setItem(8, MainMenuInventory.item()); e.getPlayer().setOp(nz.hasRank(Rank.DEVELOPER)); PacketContainer tablist = NationZ.protocolManager.createPacket(PacketType.Play.Server.PLAYER_LIST_HEADER_FOOTER); tablist.getChatComponents().write(0, WrappedChatComponent.fromText(NationZ.title + ChatColor.DARK_GRAY + " - " + ChatColor.GOLD + "A unique Hardcore-Clan-Survival Experience.")); tablist.getChatComponents().write(1, WrappedChatComponent.fromText(nz.getJob().getDisplayname() + ChatColor.DARK_GRAY + " (" + ChatColor.DARK_GREEN + nz.getJobLevel() + ChatColor.DARK_GRAY + ") - " + nz.getNation().getDisplayname())); try { NationZ.protocolManager.sendServerPacket(e.getPlayer(), tablist); } catch (InvocationTargetException e1) { e1.printStackTrace(); } }
public AttributeInstance getAttribute(Attribute attribute) { if (entity instanceof Attributable) { return ((Attributable)entity).getAttribute(attribute); } return null; }
@Override public AttributeInstance getAttribute(Attribute attribute) { throw Pokkit.unsupported(); }
@Override public AttributeInstance getAttribute(Attribute arg0) { throw Pokkit.unsupported(); }
@Override public AttributeInstance getAttribute(Attribute attribute) { throw new UnsupportedOperationException(); }
@Override public AttributeInstance getAttribute(Attribute attribute) { return getHandle().craftAttributes.getAttribute(attribute); }
public CraftAttributeInstance(net.minecraft.server.AttributeInstance handle, Attribute attribute) { this.handle = handle; this.attribute = attribute; }