2020-05-10 20:25:28 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2020-05-10 20:25:28 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2020-05-10 20:25:28 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2020-05-10 20:25:28 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2020-05-10 20:25:28 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
2020-05-10 20:25:28 +00:00
|
|
|
*/
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
package org.geysermc.geyser.platform.spigot.world;
|
2020-05-10 20:25:28 +00:00
|
|
|
|
|
|
|
import com.nukkitx.math.vector.Vector3f;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.SoundEvent;
|
|
|
|
import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.block.BlockPlaceEvent;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.GeyserImpl;
|
2021-11-21 18:36:42 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSessionImpl;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.level.block.BlockStateValues;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.registry.BlockRegistries;
|
|
|
|
import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotWorldManager;
|
2020-05-10 20:25:28 +00:00
|
|
|
|
|
|
|
@AllArgsConstructor
|
2020-05-26 14:05:25 +00:00
|
|
|
public class GeyserSpigotBlockPlaceListener implements Listener {
|
2021-11-20 21:34:30 +00:00
|
|
|
private final GeyserImpl geyser;
|
2020-11-20 19:56:39 +00:00
|
|
|
private final GeyserSpigotWorldManager worldManager;
|
2020-05-10 20:25:28 +00:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void place(final BlockPlaceEvent event) {
|
2021-11-21 18:36:42 +00:00
|
|
|
GeyserSessionImpl session = geyser.sessionByUuid(event.getPlayer().getUniqueId());
|
2021-11-12 14:02:14 +00:00
|
|
|
if (session == null) {
|
|
|
|
return;
|
2020-05-10 20:25:28 +00:00
|
|
|
}
|
|
|
|
|
2021-11-12 14:02:14 +00:00
|
|
|
LevelSoundEventPacket placeBlockSoundPacket = new LevelSoundEventPacket();
|
|
|
|
placeBlockSoundPacket.setSound(SoundEvent.PLACE);
|
|
|
|
placeBlockSoundPacket.setPosition(Vector3f.from(event.getBlockPlaced().getX(), event.getBlockPlaced().getY(), event.getBlockPlaced().getZ()));
|
|
|
|
placeBlockSoundPacket.setBabySound(false);
|
|
|
|
if (worldManager.isLegacy()) {
|
|
|
|
placeBlockSoundPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(worldManager.getBlockAt(session,
|
|
|
|
event.getBlockPlaced().getX(), event.getBlockPlaced().getY(), event.getBlockPlaced().getZ())));
|
|
|
|
} else {
|
|
|
|
String javaBlockId = event.getBlockPlaced().getBlockData().getAsString();
|
|
|
|
placeBlockSoundPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, BlockStateValues.JAVA_AIR_ID)));
|
|
|
|
}
|
|
|
|
placeBlockSoundPacket.setIdentifier(":");
|
|
|
|
session.sendUpstreamPacket(placeBlockSoundPacket);
|
|
|
|
session.setLastBlockPlacePosition(null);
|
|
|
|
session.setLastBlockPlacedId(null);
|
|
|
|
}
|
2020-05-10 20:25:28 +00:00
|
|
|
}
|