Merge pull request 'Add Bow Damge and Fire' (#22) from sneaking_like_a_god into master
Reviewed-on: #22 Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
da35cb6f10
@ -305,6 +305,27 @@ class PacketProcessor {
|
|||||||
packetCounter.clear();
|
packetCounter.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void bow() throws IOException {
|
||||||
|
int entityId = source.rInt();
|
||||||
|
boolean drawn = source.rBoolean();
|
||||||
|
int hand = source.rInt();
|
||||||
|
|
||||||
|
execSync(() -> REntity.getEntity(entityId).setBowDrawn(drawn, hand));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void damage() throws IOException {
|
||||||
|
int entityId = source.rInt();
|
||||||
|
|
||||||
|
execSync(() -> REntity.getEntity(entityId).damage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireTick() throws IOException {
|
||||||
|
int entityId = source.rInt();
|
||||||
|
boolean perma = source.rBoolean();
|
||||||
|
|
||||||
|
execSync(() -> REntity.getEntity(entityId).setOnFire(perma));
|
||||||
|
}
|
||||||
|
|
||||||
private void process(){
|
private void process(){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@ -343,6 +364,15 @@ class PacketProcessor {
|
|||||||
case 0x09:
|
case 0x09:
|
||||||
fireballSpawn();
|
fireballSpawn();
|
||||||
break;
|
break;
|
||||||
|
case 0x0A:
|
||||||
|
bow();
|
||||||
|
break;
|
||||||
|
case 0x0B:
|
||||||
|
damage();
|
||||||
|
break;
|
||||||
|
case 0x0C:
|
||||||
|
fireTick();
|
||||||
|
break;
|
||||||
case 0x30:
|
case 0x30:
|
||||||
block();
|
block();
|
||||||
break;
|
break;
|
||||||
@ -388,11 +418,12 @@ class PacketProcessor {
|
|||||||
break;
|
break;
|
||||||
case (byte) 0xFF:
|
case (byte) 0xFF:
|
||||||
//Tick
|
//Tick
|
||||||
|
execSync(() -> REntity.tickFire());
|
||||||
if(!source.async())
|
if(!source.async())
|
||||||
tickFinished = true;
|
tickFinished = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Unknown packet recieved, closing");
|
Bukkit.getLogger().log(Level.SEVERE, "Unknown packet recieved, closing: " + packetType);
|
||||||
source.close();
|
source.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,33 @@ import java.util.Map;
|
|||||||
|
|
||||||
public abstract class REntity {
|
public abstract class REntity {
|
||||||
|
|
||||||
|
public static void tickFire() {
|
||||||
|
getEntities().forEach((integer, entity) -> {
|
||||||
|
if(entity.fireTick > 0) {
|
||||||
|
entity.fireTick--;
|
||||||
|
if(entity.fireTick == 0) {
|
||||||
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
|
|
||||||
|
DataWatcherObject<Byte> dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a);
|
||||||
|
dataWatcher.register(dataWatcherObject, (byte) 0);
|
||||||
|
dataWatcher.markDirty(dataWatcherObject);
|
||||||
|
entity.sendDataWatcher(dataWatcher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected static final WorldServer world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
|
protected static final WorldServer world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
|
||||||
|
|
||||||
private static final Map<Integer, REntity> entities = new HashMap<>();
|
private static final Map<Integer, REntity> entities = new HashMap<>();
|
||||||
|
|
||||||
|
private static Map<Integer, REntity> getEntities() {
|
||||||
|
return entities;
|
||||||
|
}
|
||||||
|
|
||||||
private final int internalId;
|
private final int internalId;
|
||||||
protected final Entity entity;
|
protected final Entity entity;
|
||||||
|
private int fireTick;
|
||||||
|
|
||||||
protected REntity(int internalId, Entity entity){
|
protected REntity(int internalId, Entity entity){
|
||||||
this.internalId = internalId;
|
this.internalId = internalId;
|
||||||
@ -55,6 +76,22 @@ public abstract class REntity {
|
|||||||
for(REntity entity : entities.values()){
|
for(REntity entity : entities.values()){
|
||||||
entity.sendToPlayer(player);
|
entity.sendToPlayer(player);
|
||||||
entity.sendLocation(player);
|
entity.sendLocation(player);
|
||||||
|
if(entity.fireTick != 0) {
|
||||||
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
|
|
||||||
|
DataWatcherObject<Byte> dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a);
|
||||||
|
dataWatcher.register(dataWatcherObject, (byte) 1);
|
||||||
|
dataWatcher.markDirty(dataWatcherObject);
|
||||||
|
entity.sendDataWatcher(dataWatcher);
|
||||||
|
}
|
||||||
|
if(entity.entity.isSneaking()) {
|
||||||
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
|
|
||||||
|
DataWatcherObject<EntityPose> dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s);
|
||||||
|
dataWatcher.register(dataWatcherObject, EntityPose.CROUCHING);
|
||||||
|
dataWatcher.markDirty(dataWatcherObject);
|
||||||
|
entity.sendDataWatcher(dataWatcher);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,13 +141,45 @@ public abstract class REntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sneak(boolean sneaking) {
|
public void sneak(boolean sneaking) {
|
||||||
|
entity.setSneaking(sneaking);
|
||||||
|
|
||||||
DataWatcher dataWatcher = new DataWatcher(null);
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
|
|
||||||
DataWatcherObject<EntityPose> dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s);
|
DataWatcherObject<EntityPose> dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s);
|
||||||
dataWatcher.register(dataWatcherObject, sneaking?EntityPose.CROUCHING:EntityPose.STANDING);
|
dataWatcher.register(dataWatcherObject, sneaking?EntityPose.CROUCHING:EntityPose.STANDING);
|
||||||
dataWatcher.markDirty(dataWatcherObject);
|
dataWatcher.markDirty(dataWatcherObject);
|
||||||
|
|
||||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false);
|
sendDataWatcher(dataWatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnFire(boolean perma) {
|
||||||
|
if(!perma) {
|
||||||
|
fireTick = 21;
|
||||||
|
} else {
|
||||||
|
fireTick = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
|
|
||||||
|
DataWatcherObject<Byte> dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a);
|
||||||
|
dataWatcher.register(dataWatcherObject, (byte) 1);
|
||||||
|
dataWatcher.markDirty(dataWatcherObject);
|
||||||
|
|
||||||
|
sendDataWatcher(dataWatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBowDrawn(boolean drawn, int hand) {
|
||||||
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
|
|
||||||
|
DataWatcherObject<Byte> dataWatcherObject = new DataWatcherObject<>(7, DataWatcherRegistry.a);
|
||||||
|
dataWatcher.register(dataWatcherObject, (byte) ((drawn?1:0) + (hand * 2)));
|
||||||
|
dataWatcher.markDirty(dataWatcherObject);
|
||||||
|
|
||||||
|
sendDataWatcher(dataWatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void damage() {
|
||||||
|
PacketPlayOutEntityStatus packet = new PacketPlayOutEntityStatus(entity, (byte) 2);
|
||||||
|
|
||||||
for(Player player : Bukkit.getOnlinePlayers()){
|
for(Player player : Bukkit.getOnlinePlayers()){
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
@ -145,4 +214,12 @@ public abstract class REntity {
|
|||||||
protected void spawnEntity(PlayerConnection connection){
|
protected void spawnEntity(PlayerConnection connection){
|
||||||
connection.sendPacket(new PacketPlayOutSpawnEntity(entity));
|
connection.sendPacket(new PacketPlayOutSpawnEntity(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendDataWatcher(DataWatcher dataWatcher) {
|
||||||
|
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false);
|
||||||
|
|
||||||
|
for(Player player : Bukkit.getOnlinePlayers()){
|
||||||
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,6 @@ public class RPlayer extends REntity {
|
|||||||
|
|
||||||
public RPlayer(UUID uuid, String name, int internalId){
|
public RPlayer(UUID uuid, String name, int internalId){
|
||||||
super(internalId, createPlayer(uuid, name));
|
super(internalId, createPlayer(uuid, name));
|
||||||
//TODO Damage
|
|
||||||
team.addEntry(entity.getName());
|
team.addEntry(entity.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren