SteamWar/BauSystem2.0
Archiviert
12
0

Fix warp entity sound
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-08-07 17:55:39 +02:00
Ursprung 81b8b5e4af
Commit 36efdd9a5f
5 geänderte Dateien mit 125 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -22,33 +22,34 @@ package de.steamwar.bausystem.entities;
import de.steamwar.bausystem.features.warp.AbstractWarpEntity; import de.steamwar.bausystem.features.warp.AbstractWarpEntity;
import de.steamwar.bausystem.shared.BaseArmorStand15; import de.steamwar.bausystem.shared.BaseArmorStand15;
import net.minecraft.server.v1_15_R1.ChatComponentText; import net.minecraft.server.v1_15_R1.ChatComponentText;
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata;
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_15_R1.PlayerConnection;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class WarpEntity15 extends BaseArmorStand15 implements AbstractWarpEntity { public class WarpEntity15 extends BaseArmorStand15 implements AbstractWarpEntity {
private String name;
public WarpEntity15(World world, Vector position, String name) { public WarpEntity15(World world, Vector position, String name) {
super(world, position); super(world, position);
setInvisible(true); setInvisible(true);
setSmall(true); setSmall(true);
this.name = name; setName(name);
this.setNoGravity(true); this.setNoGravity(true);
this.ticksLived = -12000; this.ticksLived = -12000;
} }
@Override @Override
public void display(Player player) { public void display(Player player) {
this.setCustomNameVisible(true);
this.setCustomName(new ChatComponentText(name));
sendEntity(player); sendEntity(player);
} }
@Override @Override
public void setName(String name) { public void setName(String name) {
this.name = name; this.setCustomNameVisible(true);
this.setCustomName(new ChatComponentText(name));
} }
@Override @Override
@ -57,4 +58,23 @@ public class WarpEntity15 extends BaseArmorStand15 implements AbstractWarpEntity
die(); die();
return true; return true;
} }
@Override
public void sendMetaData(Player player) {
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutEntityMetadata);
}
@Override
public void teleport(Player player, Vector position) {
setPositionRaw(position.getX(), position.getY(), position.getZ());
PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport);
}
@Override
public Vector getPosition() {
return new Vector(locX(), locY(), locZ());
}
} }

Datei anzeigen

@ -22,33 +22,34 @@ package de.steamwar.bausystem.entities;
import de.steamwar.bausystem.features.warp.AbstractWarpEntity; import de.steamwar.bausystem.features.warp.AbstractWarpEntity;
import de.steamwar.bausystem.shared.BaseArmorStand18; import de.steamwar.bausystem.shared.BaseArmorStand18;
import net.minecraft.network.chat.ChatComponentText; import net.minecraft.network.chat.ChatComponentText;
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport;
import net.minecraft.server.network.PlayerConnection;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class WarpEntity18 extends BaseArmorStand18 implements AbstractWarpEntity { public class WarpEntity18 extends BaseArmorStand18 implements AbstractWarpEntity {
private String name;
public WarpEntity18(World world, Vector position, String name) { public WarpEntity18(World world, Vector position, String name) {
super(world, position); super(world, position);
this.j(true); this.j(true);
this.a(true); this.a(true);
this.name = name; setName(name);
this.e(true); this.e(true);
this.S = -12000; this.S = -12000;
} }
@Override @Override
public void display(Player player) { public void display(Player player) {
this.n(true);
this.a(new ChatComponentText(name));
sendEntity(player); sendEntity(player);
} }
@Override @Override
public void setName(String name) { public void setName(String name) {
this.name = name; this.n(true);
this.a(new ChatComponentText(name));
} }
@Override @Override
@ -57,4 +58,23 @@ public class WarpEntity18 extends BaseArmorStand18 implements AbstractWarpEntity
ag(); ag();
return true; return true;
} }
@Override
public void sendMetaData(Player player) {
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(ae(), Y, true);
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b;
playerConnection.a(packetPlayOutEntityMetadata);
}
@Override
public void teleport(Player player, Vector position) {
setPosRaw(position.getX(), position.getY(), position.getZ(), false);
PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this);
((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityTeleport);
}
@Override
public Vector getPosition() {
return new Vector(dc(), de(), di());
}
} }

Datei anzeigen

@ -23,33 +23,34 @@ import de.steamwar.bausystem.features.warp.AbstractWarpEntity;
import de.steamwar.bausystem.shared.BaseArmorStand19; import de.steamwar.bausystem.shared.BaseArmorStand19;
import net.minecraft.network.chat.IChatMutableComponent; import net.minecraft.network.chat.IChatMutableComponent;
import net.minecraft.network.chat.contents.LiteralContents; import net.minecraft.network.chat.contents.LiteralContents;
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport;
import net.minecraft.server.network.PlayerConnection;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class WarpEntity19 extends BaseArmorStand19 implements AbstractWarpEntity { public class WarpEntity19 extends BaseArmorStand19 implements AbstractWarpEntity {
private String name;
public WarpEntity19(World world, Vector position, String name) { public WarpEntity19(World world, Vector position, String name) {
super(world, position); super(world, position);
this.j(true); this.j(true);
this.a(true); this.a(true);
this.name = name; setName(name);
this.e(true); this.e(true);
this.S = -12000; this.S = -12000;
} }
@Override @Override
public void display(Player player) { public void display(Player player) {
this.n(true);
this.b(IChatMutableComponent.a(new LiteralContents(name)));
sendEntity(player); sendEntity(player);
} }
@Override @Override
public void setName(String name) { public void setName(String name) {
this.name = name; this.n(true);
this.b(IChatMutableComponent.a(new LiteralContents(name)));
} }
@Override @Override
@ -58,4 +59,23 @@ public class WarpEntity19 extends BaseArmorStand19 implements AbstractWarpEntity
ag(); ag();
return true; return true;
} }
@Override
public void sendMetaData(Player player) {
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(ae(), Y, true);
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b;
playerConnection.a(packetPlayOutEntityMetadata);
}
@Override
public void teleport(Player player, Vector position) {
setPosRaw(position.getX(), position.getY(), position.getZ(), false);
PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this);
((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityTeleport);
}
@Override
public Vector getPosition() {
return new Vector(df(), dh(), dj());
}
} }

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.warp;
import de.steamwar.bausystem.shared.AbstractEntity; import de.steamwar.bausystem.shared.AbstractEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public interface AbstractWarpEntity extends AbstractEntity { public interface AbstractWarpEntity extends AbstractEntity {
@ -29,4 +30,10 @@ public interface AbstractWarpEntity extends AbstractEntity {
void setName(String name); void setName(String name);
boolean hide(Player player); boolean hide(Player player);
void sendMetaData(Player player);
void teleport(Player player, Vector position);
Vector getPosition();
} }

Datei anzeigen

@ -33,10 +33,8 @@ import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap; import java.util.function.Consumer;
import java.util.List;
import java.util.Map;
@Linked(LinkageType.LISTENER) @Linked(LinkageType.LISTENER)
public class WarpListener implements Listener { public class WarpListener implements Listener {
@ -63,14 +61,41 @@ public class WarpListener implements Listener {
createStuff(event.getPlayer(), event.getPlayer().getInventory().getItemInMainHand().getType(), event.isSneaking()); createStuff(event.getPlayer(), event.getPlayer().getInventory().getItemInMainHand().getType(), event.isSneaking());
} }
private void createStuff(Player p, Material material, boolean sneaking) { private static final class WarpEntityIterator {
if (warpsShown.containsKey(p)) {
warpsShown.get(p).forEach(warp -> { private final List<AbstractWarpEntity> warps;
warp.hide(p);
}); public WarpEntityIterator(List<AbstractWarpEntity> warps) {
warpsShown.remove(p); this.warps = warps == null ? Collections.emptyList() : warps;
} }
public AbstractWarpEntity next(Player p, Vector position, String name) {
if (!warps.isEmpty()) {
AbstractWarpEntity abstractWarpEntity = warps.stream().min(Comparator.comparingDouble(o -> o.getPosition().distanceSquared(position))).get();
warps.remove(abstractWarpEntity);
abstractWarpEntity.teleport(p, position);
abstractWarpEntity.setName(name);
abstractWarpEntity.sendMetaData(p);
return abstractWarpEntity;
} else {
AbstractWarpEntity warp = createEntity(p, position, name);
warp.display(p);
return warp;
}
}
public void forEach(Consumer<AbstractWarpEntity> consumer) {
warps.forEach(consumer);
}
}
private void createStuff(Player p, Material material, boolean sneaking) {
WarpEntityIterator it = new WarpEntityIterator(warpsShown.remove(p));
if (material != Material.COMPASS) { if (material != Material.COMPASS) {
it.forEach(abstractWarpEntity -> {
abstractWarpEntity.teleport(p, new Vector(0, 100000, 0));
abstractWarpEntity.hide(p);
});
return; return;
} }
@ -111,13 +136,14 @@ public class WarpListener implements Listener {
name = "§a§l" + name; name = "§a§l" + name;
selected.computeIfAbsent(p, player -> new ArrayList<>()).add(location); selected.computeIfAbsent(p, player -> new ArrayList<>()).add(location);
} }
warps.add(createEntity(p, position, name)); warps.add(it.next(p, position, name));
}); });
warpsShown.put(p, warps); it.forEach(abstractWarpEntity -> {
warps.forEach(warp -> { abstractWarpEntity.teleport(p, new Vector(0, 100000, 0));
warp.display(p); abstractWarpEntity.hide(p);
}); });
warpsShown.put(p, warps);
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)