Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.demkom58.core;
- import com.comphenix.protocol.PacketType;
- import com.comphenix.protocol.ProtocolLibrary;
- import com.comphenix.protocol.ProtocolManager;
- import com.comphenix.protocol.events.PacketAdapter;
- import com.comphenix.protocol.events.PacketContainer;
- import com.comphenix.protocol.events.PacketEvent;
- import com.comphenix.protocol.reflect.StructureModifier;
- import com.comphenix.protocol.wrappers.WrappedAttribute;
- import com.comphenix.protocol.wrappers.WrappedAttribute.Builder;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.Plugin;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
- public class ActionHealth {
- Main plugin;
- private static ProtocolManager protocolManager;
- public void onEnable(Plugin cplugin) {
- plugin = (Main) cplugin;
- Set packets = new HashSet();
- packets.add(PacketType.Play.Server.UPDATE_HEALTH);
- packets.add(PacketType.Play.Server.UPDATE_ATTRIBUTES);
- ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(plugin, packets) {
- @Override
- public void onPacketSending(PacketEvent event) {
- if (event.getPlayer() instanceof Player ) {
- PacketContainer packet = event.getPacket();
- PacketType type = packet.getType();
- Player p = event.getPlayer();
- if (type == PacketType.Play.Server.UPDATE_HEALTH) {
- float hp = (float) (p.getHealth() * 20 / p.getMaxHealth());
- p.sendMessage(Methods.toColor("&7Твой % здоровья: &f"+hp+"&c❤"));
- p.sendMessage(Methods.toColor("&7Твое здоровье: &f"+Math.round(p.getHealth()) +"&7/&f" +p.getMaxHealth() +"&c❤"));
- packet.getFloat().write(0, hp);
- }
- if (type == PacketType.Play.Server.UPDATE_ATTRIBUTES) {
- Builder builder;
- List<WrappedAttribute> attributes = new ArrayList<>();
- builder = WrappedAttribute.newBuilder();
- builder.attributeKey("generic.maxHealth");
- builder.baseValue(20);
- builder.packet(packet);
- attributes.add(builder.build());
- packet.getAttributeCollectionModifier().write(0, attributes);
- }
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment