3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Merge pull request #275 from HugoDaBosss/apiv2

Fix for block place sounds
Dieser Commit ist enthalten in:
Myles 2016-03-26 14:51:55 +00:00
Commit 7807e6d9c4
6 geänderte Dateien mit 92 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -28,7 +28,7 @@ public class BaseProtocol extends Protocol {
@Override @Override
protected void registerPackets() { protected void registerPackets() {
/* Outgoing Packets */ /* Outgoing Packets */
registerOutgoing(State.STATUS, 0x00, 0x00, new PacketRemapper() { registerOutgoing(State.STATUS, 0x00, 0x00, new PacketRemapper() { // Status Response Packet
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.STRING); map(Type.STRING);
@ -59,7 +59,8 @@ public class BaseProtocol extends Protocol {
} }
}); });
} }
}); // Status Response Packet });
registerOutgoing(State.STATUS, 0x01, 0x01); // Status Pong Packet registerOutgoing(State.STATUS, 0x01, 0x01); // Status Pong Packet
registerOutgoing(State.LOGIN, 0x00, 0x00); // Login Disconnect Packet registerOutgoing(State.LOGIN, 0x00, 0x00); // Login Disconnect Packet

Datei anzeigen

@ -15,6 +15,7 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.ArmorListener; import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.ArmorListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.BlockListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.CommandBlockListener; import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.CommandBlockListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*; import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
@ -96,6 +97,7 @@ public class Protocol1_9TO1_8 extends Protocol {
ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion"); ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
Bukkit.getPluginManager().registerEvents(new ArmorListener(plugin), plugin); Bukkit.getPluginManager().registerEvents(new ArmorListener(plugin), plugin);
Bukkit.getPluginManager().registerEvents(new CommandBlockListener(plugin), plugin); Bukkit.getPluginManager().registerEvents(new CommandBlockListener(plugin), plugin);
Bukkit.getPluginManager().registerEvents(new BlockListener(plugin), plugin);
} }
@Override @Override

Datei anzeigen

@ -0,0 +1,30 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
import lombok.RequiredArgsConstructor;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
@RequiredArgsConstructor
public class BlockListener implements Listener {
private final ViaVersionPlugin plugin;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void placeBlock(BlockPlaceEvent e) {
if(plugin.isPorted(e.getPlayer())) {
UserConnection c = plugin.getConnection(e.getPlayer());
if (!c.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return;
Block b = e.getBlockPlaced();
plugin.getConnection(e.getPlayer()).get(EntityTracker.class).addBlockInteraction(new Position((long) b.getX(), (long) b.getY(), (long) b.getZ()));
}
}
}

Datei anzeigen

@ -74,15 +74,21 @@ public class WorldPackets {
int catid = 0; int catid = 0;
String newname = name; String newname = name;
if (effect != null) { if (effect != null) {
if (effect.isBreaksound()) {
wrapper.cancel();
return;
}
catid = effect.getCategory().getId(); catid = effect.getCategory().getId();
newname = effect.getNewName(); newname = effect.getNewName();
} }
wrapper.set(Type.STRING, 0, newname); wrapper.set(Type.STRING, 0, newname);
wrapper.write(Type.VAR_INT, catid); // Write Category ID wrapper.write(Type.VAR_INT, catid); // Write Category ID
if(effect != null && effect.isBreaksound()) {
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
int x = wrapper.passthrough(Type.INT); //Position X
int y = wrapper.passthrough(Type.INT); //Position Y
int z = wrapper.passthrough(Type.INT); //Position Z
if(tracker.interactedBlockRecently((int)Math.floor(x/8.0),(int)Math.floor(y/8.0),(int)Math.floor(z/8.0))) {
wrapper.cancel();
return;
}
}
} }
}); });
} }
@ -323,6 +329,28 @@ public class WorldPackets {
} }
}); });
//Register block place to fix sounds
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int face = wrapper.get(Type.BYTE,0);
if(face == 255)
return;
Position p = wrapper.get(Type.POSITION, 0);
long x = p.getX(); long y = p.getY(); long z = p.getZ();
switch(face) {
case 0: y--; break;
case 1: y++; break;
case 2: z--; break;
case 3: z++; break;
case 4: x--; break;
case 5: x++; break;
}
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.addBlockInteraction(new Position(x,y,z));
}
});
} }
}); });
} }

Datei anzeigen

@ -155,7 +155,7 @@ public enum SoundEffect {
MOB_CAT_HISS("mob.cat.hiss", "entity.cat.hiss", SoundCategory.NEUTRAL), MOB_CAT_HISS("mob.cat.hiss", "entity.cat.hiss", SoundCategory.NEUTRAL),
NOTE_BD("note.bd", "block.note.basedrum", SoundCategory.RECORD), NOTE_BD("note.bd", "block.note.basedrum", SoundCategory.RECORD),
MOB_SPIDER_SAY("mob.spider.say", "entity.spider.hurt", SoundCategory.HOSTILE), MOB_SPIDER_SAY("mob.spider.say", "entity.spider.hurt", SoundCategory.HOSTILE),
STEP_STONE("step.stone", "block.anvil.hit", SoundCategory.NEUTRAL), STEP_STONE("step.stone", "block.anvil.hit", SoundCategory.NEUTRAL, true), //Is used for glass placement sound
RANDOM_LEVELUP("random.levelup", "entity.player.levelup", SoundCategory.PLAYER), RANDOM_LEVELUP("random.levelup", "entity.player.levelup", SoundCategory.PLAYER),
LIQUID_LAVAPOP("liquid.lavapop", "block.lava.pop", SoundCategory.BLOCK), LIQUID_LAVAPOP("liquid.lavapop", "block.lava.pop", SoundCategory.BLOCK),
MOB_SHEEP_SAY("mob.sheep.say", "entity.sheep.ambient", SoundCategory.NEUTRAL), MOB_SHEEP_SAY("mob.sheep.say", "entity.sheep.ambient", SoundCategory.NEUTRAL),

Datei anzeigen

@ -1,9 +1,12 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage; package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.ViaVersionPlugin;
@ -14,12 +17,14 @@ import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossStyle; import us.myles.ViaVersion.api.boss.BossStyle;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
@Getter @Getter
public class EntityTracker extends StoredObject { public class EntityTracker extends StoredObject {
@ -29,6 +34,7 @@ public class EntityTracker extends StoredObject {
private final Map<Integer, BossBar> bossBarMap = new HashMap<>(); private final Map<Integer, BossBar> bossBarMap = new HashMap<>();
private final Set<Integer> validBlocking = new HashSet<>(); private final Set<Integer> validBlocking = new HashSet<>();
private final Set<Integer> knownHolograms = new HashSet<>(); private final Set<Integer> knownHolograms = new HashSet<>();
private final Cache<Position, Material> blockInteractions = CacheBuilder.newBuilder().maximumSize(10).expireAfterAccess(250, TimeUnit.MILLISECONDS).build();
@Setter @Setter
private boolean blocking = false; private boolean blocking = false;
@Setter @Setter
@ -82,6 +88,24 @@ public class EntityTracker extends StoredObject {
} }
} }
public boolean interactedBlockRecently(int x, int y, int z) {
if(blockInteractions.size() == 0)
return false;
Iterator<Position> it = blockInteractions.asMap().keySet().iterator();
while(it.hasNext()) {
Position p = it.next();
if(p.getX() == x)
if(p.getY() == y)
if(p.getZ() == z)
return true;
}
return false;
}
public void addBlockInteraction(Position p) {
blockInteractions.put(p,Material.AIR);
}
public void handleMetadata(int entityID, List<Metadata> metadataList) { public void handleMetadata(int entityID, List<Metadata> metadataList) {
if (!clientEntityTypes.containsKey(entityID)) return; if (!clientEntityTypes.containsKey(entityID)) return;