Added custom name tag fix for mobs for 1.8 players
Worked on boss bar display. Bug with <=50% hp.
This commit is contained in:
parent
e6bc048179
commit
b28fc8ee6b
@ -1,4 +1,4 @@
|
||||
package mineplex.core.disguise.disguises;
|
||||
package mineplex.core.common;
|
||||
|
||||
import net.minecraft.server.v1_7_R4.Entity;
|
||||
import net.minecraft.server.v1_7_R4.NBTTagCompound;
|
@ -3,6 +3,7 @@ package mineplex.core.common.util;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
|
||||
import mineplex.core.common.DummyEntity;
|
||||
import net.minecraft.server.v1_7_R4.DataWatcher;
|
||||
import net.minecraft.server.v1_7_R4.EntityPlayer;
|
||||
import net.minecraft.server.v1_7_R4.MathHelper;
|
||||
@ -12,6 +13,8 @@ import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -20,7 +23,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class UtilDisplay
|
||||
{
|
||||
public static final int ENTITY_ID = 1234;
|
||||
public static final int ENTITY_ID = 777777;
|
||||
|
||||
private static HashMap<String, Boolean> hasHealthBar = new HashMap<String, Boolean>();
|
||||
|
||||
@ -35,9 +38,9 @@ public class UtilDisplay
|
||||
PacketPlayOutSpawnEntityLiving mobPacket = new PacketPlayOutSpawnEntityLiving();
|
||||
|
||||
mobPacket.a = (int) ENTITY_ID; //Entity ID
|
||||
mobPacket.b = (byte) EntityType.ENDER_DRAGON.getTypeId(); //Mob type (ID: 64)
|
||||
mobPacket.b = (byte) EntityType.WITHER.getTypeId(); //Mob type (ID: 64)
|
||||
mobPacket.c = (int) Math.floor(loc.getBlockX() * 32.0D); //X position
|
||||
mobPacket.d = (int) MathHelper.floor(-200 * 32.0D); //Y position
|
||||
mobPacket.d = (int) MathHelper.floor(loc.getBlockY() * 32.0D); //Y position
|
||||
mobPacket.e = (int) Math.floor(loc.getBlockZ() * 32.0D); //Z position
|
||||
mobPacket.f = (byte) 0; //Pitch
|
||||
mobPacket.g = (byte) 0; //Head Pitch
|
||||
@ -46,7 +49,7 @@ public class UtilDisplay
|
||||
mobPacket.j = (short) 0; //Y velocity
|
||||
mobPacket.k = (short) 0; //Z velocity
|
||||
|
||||
DataWatcher watcher = getWatcher(text, healthPercent * 200);
|
||||
DataWatcher watcher = getWatcher(text, healthPercent * 200, loc.getWorld());
|
||||
|
||||
mobPacket.l = watcher;
|
||||
|
||||
@ -76,14 +79,22 @@ public class UtilDisplay
|
||||
return metaPacket;
|
||||
}
|
||||
|
||||
public static DataWatcher getWatcher(String text, double health){
|
||||
DataWatcher watcher = new DataWatcher(null);
|
||||
public static DataWatcher getWatcher(String text, double health, World world)
|
||||
{
|
||||
DataWatcher watcher = new DataWatcher(new DummyEntity(((CraftWorld)world).getHandle()));
|
||||
|
||||
watcher.a(0, (Byte) (byte) 32); //Flags, 0x20 = invisible
|
||||
watcher.a(0, (Byte) (byte) 0); //Flags, 0x20 = invisible
|
||||
watcher.a(6, (Float) (float) health);
|
||||
watcher.a(2, (String) text); //Entity name
|
||||
watcher.a(10, (String) text); //Entity name
|
||||
watcher.a(11, (Byte) (byte) 1); //Show name, 1 = show, 0 = don't show
|
||||
watcher.a(3, (Byte) (byte) 0); //Show name, 1 = show, 0 = don't show
|
||||
watcher.a(11, (Byte) (byte) 0); //Show name, 1 = show, 0 = don't show
|
||||
watcher.a(16, (Integer) (int) health); //Wither health, 200 = full health
|
||||
watcher.a(20, (Integer) (int) 0); //Wither invuln, 200 = full health
|
||||
|
||||
int i1 = watcher.getInt(0);
|
||||
watcher.watch(0, Byte.valueOf((byte)(i1 | 1 << 5)));
|
||||
watcher.watch(20, 0);
|
||||
|
||||
return watcher;
|
||||
}
|
||||
@ -91,7 +102,11 @@ public class UtilDisplay
|
||||
//Other methods
|
||||
public static void displayTextBar(JavaPlugin plugin, final Player player, double healthPercent, String text)
|
||||
{
|
||||
PacketPlayOutSpawnEntityLiving mobPacket = getMobPacket(text, healthPercent, player.getLocation());
|
||||
PacketPlayOutEntityDestroy destroyEntityPacket = getDestroyEntityPacket();
|
||||
|
||||
sendPacket(player, destroyEntityPacket);
|
||||
|
||||
PacketPlayOutSpawnEntityLiving mobPacket = getMobPacket(text, healthPercent, player.getEyeLocation().getDirection().multiply(24).toLocation(player.getWorld()).add(player.getLocation()));
|
||||
|
||||
sendPacket(player, mobPacket);
|
||||
hasHealthBar.put(player.getName(), true);
|
||||
@ -108,7 +123,10 @@ public class UtilDisplay
|
||||
}
|
||||
|
||||
public static void displayLoadingBar(final String text, final String completeText, final Player player, final int healthAdd, final long delay, final boolean loadUp, final JavaPlugin plugin){
|
||||
PacketPlayOutSpawnEntityLiving mobPacket = getMobPacket(text, 0, player.getLocation());
|
||||
PacketPlayOutEntityDestroy destroyEntityPacket = getDestroyEntityPacket();
|
||||
|
||||
sendPacket(player, destroyEntityPacket);
|
||||
PacketPlayOutSpawnEntityLiving mobPacket = getMobPacket(text, 0, player.getEyeLocation().getDirection().multiply(24).toLocation(player.getWorld()).add(player.getLocation()));
|
||||
|
||||
sendPacket(player, mobPacket);
|
||||
hasHealthBar.put(player.getName(), true);
|
||||
@ -119,7 +137,7 @@ public class UtilDisplay
|
||||
@Override
|
||||
public void run(){
|
||||
if((loadUp ? health < 200 : health > 0)){
|
||||
DataWatcher watcher = getWatcher(text, health);
|
||||
DataWatcher watcher = getWatcher(text, health, player.getWorld());
|
||||
PacketPlayOutEntityMetadata metaPacket = getMetadataPacket(watcher);
|
||||
|
||||
sendPacket(player, metaPacket);
|
||||
@ -130,7 +148,7 @@ public class UtilDisplay
|
||||
health -= healthAdd;
|
||||
}
|
||||
} else {
|
||||
DataWatcher watcher = getWatcher(text, (loadUp ? 200 : 0));
|
||||
DataWatcher watcher = getWatcher(text, (loadUp ? 200 : 0), player.getWorld());
|
||||
PacketPlayOutEntityMetadata metaPacket = getMetadataPacket(watcher);
|
||||
PacketPlayOutEntityDestroy destroyEntityPacket = getDestroyEntityPacket();
|
||||
|
||||
@ -144,7 +162,7 @@ public class UtilDisplay
|
||||
sendPacket(player, mobPacket);
|
||||
hasHealthBar.put(player.getName(), true);
|
||||
|
||||
DataWatcher watcher2 = getWatcher(completeText, 200);
|
||||
DataWatcher watcher2 = getWatcher(completeText, 200, player.getWorld());
|
||||
PacketPlayOutEntityMetadata metaPacket2 = getMetadataPacket(watcher2);
|
||||
|
||||
sendPacket(player, metaPacket2);
|
||||
|
186
Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java
Normal file
186
Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java
Normal file
@ -0,0 +1,186 @@
|
||||
package mineplex.core;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import mineplex.core.common.DummyEntity;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.packethandler.IPacketRunnable;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.packethandler.PacketVerifier;
|
||||
import net.minecraft.server.v1_7_R4.DataWatcher;
|
||||
import net.minecraft.server.v1_7_R4.EnumEntitySize;
|
||||
import net.minecraft.server.v1_7_R4.MathHelper;
|
||||
import net.minecraft.server.v1_7_R4.Packet;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutAttachEntity;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
|
||||
import net.minecraft.server.v1_7_R4.WatchableObject;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class CustomTagFix extends MiniPlugin implements IPacketRunnable
|
||||
{
|
||||
private static int _fakeIdCounter = 455000;
|
||||
private NautHashMap<Integer, Integer> _entityMap = new NautHashMap<Integer, Integer>();
|
||||
|
||||
private Field _destroyId;
|
||||
|
||||
public CustomTagFix(JavaPlugin plugin, PacketHandler packetHandler)
|
||||
{
|
||||
super("Custom Tag Fix", plugin);
|
||||
|
||||
packetHandler.AddPacketRunnable(this);
|
||||
|
||||
try
|
||||
{
|
||||
_destroyId = PacketPlayOutEntityDestroy.class.getDeclaredField("a");
|
||||
_destroyId.setAccessible(true);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
System.out.println("Field exception in CustomTagFix : ");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run(Packet packet, final Player owner, final PacketVerifier packetList)
|
||||
{
|
||||
if (((CraftPlayer)owner).getHandle().playerConnection.networkManager.getVersion() >= 47)
|
||||
{
|
||||
if (packet instanceof PacketPlayOutSpawnEntityLiving)
|
||||
{
|
||||
PacketPlayOutSpawnEntityLiving spawnPacket = (PacketPlayOutSpawnEntityLiving)packet;
|
||||
|
||||
final int entityId = spawnPacket.a;
|
||||
final String entityName = spawnPacket.l.getString(10);
|
||||
|
||||
if (spawnPacket.l.getByte(11) == 1 || spawnPacket.l.getByte(3) == 1)
|
||||
{
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
final PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving();
|
||||
packet.a = _fakeIdCounter++;
|
||||
packet.b = (byte) 30;
|
||||
packet.c = (int)EnumEntitySize.SIZE_2.a(100);
|
||||
packet.d = (int)MathHelper.floor(64 * 32.0D);
|
||||
packet.e = (int)EnumEntitySize.SIZE_2.a(100);
|
||||
packet.i = (byte) ((int) (0 * 256.0F / 360.0F));
|
||||
packet.j = (byte) ((int) (0 * 256.0F / 360.0F));
|
||||
packet.k = (byte) ((int) (0 * 256.0F / 360.0F));
|
||||
|
||||
double var2 = 3.9D;
|
||||
double var4 = 0;
|
||||
double var6 = 0;
|
||||
double var8 = 0;
|
||||
|
||||
if (var4 < -var2)
|
||||
{
|
||||
var4 = -var2;
|
||||
}
|
||||
|
||||
if (var6 < -var2)
|
||||
{
|
||||
var6 = -var2;
|
||||
}
|
||||
|
||||
if (var8 < -var2)
|
||||
{
|
||||
var8 = -var2;
|
||||
}
|
||||
|
||||
if (var4 > var2)
|
||||
{
|
||||
var4 = var2;
|
||||
}
|
||||
|
||||
if (var6 > var2)
|
||||
{
|
||||
var6 = var2;
|
||||
}
|
||||
|
||||
if (var8 > var2)
|
||||
{
|
||||
var8 = var2;
|
||||
}
|
||||
|
||||
packet.f = (int)(var4 * 8000.0D);
|
||||
packet.g = (int)(var6 * 8000.0D);
|
||||
packet.h = (int)(var8 * 8000.0D);
|
||||
|
||||
final DataWatcher watcher = new DataWatcher(new DummyEntity(((CraftWorld)owner.getWorld()).getHandle()));
|
||||
|
||||
watcher.a(0, Byte.valueOf((byte)0));
|
||||
watcher.a(1, Short.valueOf((short)300));
|
||||
watcher.a(2, "");
|
||||
watcher.a(3, Byte.valueOf((byte) 0));
|
||||
watcher.a(4, Byte.valueOf((byte)0));
|
||||
watcher.a(7, Integer.valueOf(0));
|
||||
watcher.a(8, Byte.valueOf((byte)0));
|
||||
watcher.a(9, Byte.valueOf((byte)0));
|
||||
watcher.a(6, Float.valueOf(1.0F));
|
||||
watcher.a(10, Byte.valueOf((byte)0));
|
||||
|
||||
// Set invisible
|
||||
int i1 = watcher.getInt(0);
|
||||
watcher.watch(0, Byte.valueOf((byte)(i1 | 1 << 5)));
|
||||
|
||||
// Set small
|
||||
byte b1 = watcher.getByte(10);
|
||||
b1 = (byte)(b1 | 0x1);
|
||||
|
||||
watcher.watch(10, Byte.valueOf(b1));
|
||||
|
||||
watcher.watch(2, entityName);
|
||||
watcher.watch(3, Byte.valueOf((byte)1));
|
||||
|
||||
packet.l = watcher;
|
||||
|
||||
packetList.forceProcess(packet);
|
||||
|
||||
PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity();
|
||||
vehiclePacket.a = 0;
|
||||
vehiclePacket.b = packet.a;
|
||||
vehiclePacket.c = entityId;
|
||||
|
||||
packetList.forceProcess(vehiclePacket);
|
||||
|
||||
_entityMap.put(entityId, packet.a);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (packet instanceof PacketPlayOutEntityDestroy)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int id : (int[])_destroyId.get(packet))
|
||||
{
|
||||
if (_entityMap.containsKey(id))
|
||||
{
|
||||
packetList.forceProcess(new PacketPlayOutEntityDestroy(_entityMap.get(id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package mineplex.core.disguise.disguises;
|
||||
|
||||
import mineplex.core.common.*;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
|
||||
@ -9,6 +10,7 @@ import net.minecraft.server.v1_7_R4.DataWatcher;
|
||||
import net.minecraft.server.v1_7_R4.Entity;
|
||||
import net.minecraft.server.v1_7_R4.Packet;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata;
|
||||
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
public abstract class DisguiseBase
|
||||
|
@ -5,6 +5,7 @@ import net.minecraft.server.v1_7_R4.MinecraftServer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.CustomTagFix;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.antihack.AntiHack;
|
||||
import mineplex.core.antistack.AntiStack;
|
||||
@ -106,6 +107,7 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
new Chat(this, clientManager, preferenceManager, serverStatusManager.getCurrentServerName());
|
||||
new MemoryFix(this);
|
||||
new FileUpdater(this, portal);
|
||||
new CustomTagFix(this, packetHandler);
|
||||
|
||||
CombatManager combatManager = new CombatManager(this);
|
||||
BlockRestore blockRestore = new BlockRestore(this);
|
||||
|
@ -310,7 +310,7 @@ public class Draw extends SoloGame
|
||||
if (!IsLive())
|
||||
return;
|
||||
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
if (event.getType() != UpdateType.FAST)
|
||||
return;
|
||||
|
||||
if (_round == null)
|
||||
|
Loading…
Reference in New Issue
Block a user