13
0
Add TNT
Add Motion
Dieser Commit ist enthalten in:
jojo 2020-08-22 18:02:24 +02:00
Ursprung 1a1bd8fb54
Commit d5910ea7b2
4 geänderte Dateien mit 84 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -2,12 +2,14 @@ package de.steamwar.spectatesystem;
import de.steamwar.spectatesystem.elements.REntity;
import de.steamwar.spectatesystem.elements.RPlayer;
import de.steamwar.spectatesystem.elements.RTnT;
import de.steamwar.sql.SteamwarUser;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import net.minecraft.server.v1_15_R1.Block;
import org.bukkit.Bukkit;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
@ -66,6 +68,24 @@ class PacketProcessor {
REntity.getEntity(entityId).animation(animation);
}
private void tntSpawn() throws IOException {
int entityId = source.rInt();
new RTnT(entityId);
}
private void entityVelocity() throws IOException {
int entityId = source.rInt();
double dX = source.rDouble();
double dY = source.rDouble();
double dZ = source.rDouble();
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
REntity.getEntity(entityId).setMotion(dX, dY, dZ);
});
}
private void send(ChatMessageType type) throws IOException {
String message = source.rString();
@ -73,25 +93,36 @@ class PacketProcessor {
Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(type, text));
}
private World world = null;
private static final World world = Bukkit.getWorlds().get(0);
private void block() throws IOException {
if (world == null) {
world = Bukkit.getWorlds().get(0);
}
int x = source.rInt();
byte y = source.rByte();
int z = source.rInt();
int blockState = source.rInt();
if (Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) {
blockState = Config.ObfuscateWith;
}
CraftBlockData craftBlockData = CraftBlockData.fromData(Block.REGISTRY_ID.fromId(blockState));
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
world.getBlockAt(x, y, z).setBlockData(craftBlockData);
});
}
private void particle() throws IOException {
double x = source.rDouble();
double y = source.rDouble();
double z = source.rDouble();
String particleName = source.rString();
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
world.spawnParticle(Particle.valueOf(particleName), x, y, z, 1);
});
}
private void process(){
try{
while(!source.isClosed()){
@ -111,9 +142,18 @@ class PacketProcessor {
case 0x04:
entityAnimation();
break;
case 0x05:
tntSpawn();
break;
case 0x06:
entityVelocity();
break;
case 0x30:
block();
break;
case 0x31:
particle();
break;
case (byte) 0xA0:
send(ChatMessageType.CHAT);
break;

Datei anzeigen

@ -58,12 +58,12 @@ public abstract class REntity {
}
public void sneak(boolean sneaking) {
entity.setSneaking(sneaking);
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(0, entity.getDataWatcher(), sneaking);
/*entity.setSneaking(sneaking);
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(7, entity.getDataWatcher(), sneaking);
for(Player player : Bukkit.getOnlinePlayers()){
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
connection.sendPacket(packet);
}
}*/
}
public void animation(byte animation) {
@ -74,6 +74,10 @@ public abstract class REntity {
}
}
public void setMotion(double dX, double dY, double dZ) {
entity.setMot(dX, dY, dZ);
}
private void sendToPlayer(Player player){
spawnEntity(((CraftPlayer)player).getHandle().playerConnection);
}

Datei anzeigen

@ -3,5 +3,7 @@ package de.steamwar.spectatesystem.elements;
public class RParticle {
public RParticle() {
}
}

Datei anzeigen

@ -0,0 +1,29 @@
package de.steamwar.spectatesystem.elements;
import net.minecraft.server.v1_15_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
public class RTnT extends REntity {
private static World world = null;
public RTnT(int internalId) {
super(internalId, createTnT());
}
@Override
protected void spawnEntity(PlayerConnection connection) {
connection.sendPacket(new PacketPlayOutSpawnEntity(entity));
}
private static EntityTNTPrimed createTnT() {
if (world == null) {
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
}
return new EntityTNTPrimed(world, 0, 0, 0, null);
}
}