|
| 1 | +/** |
| 2 | + * The MIT License |
| 3 | + * Copyright (c) 2015 Techcable |
| 4 | + * |
| 5 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | + * of this software and associated documentation files (the "Software"), to deal |
| 7 | + * in the Software without restriction, including without limitation the rights |
| 8 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | + * copies of the Software, and to permit persons to whom the Software is |
| 10 | + * furnished to do so, subject to the following conditions: |
| 11 | + * |
| 12 | + * The above copyright notice and this permission notice shall be included in |
| 13 | + * all copies or substantial portions of the Software. |
| 14 | + * |
| 15 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | + * THE SOFTWARE. |
| 22 | + */ |
| 23 | +package net.techcable.spawnshield.nms.versions.v1_8_R1; |
| 24 | + |
| 25 | + |
| 26 | +import net.minecraft.server.v1_8_R1.*; |
| 27 | +import net.techcable.spawnshield.compat.ChunkPos; |
| 28 | +import net.techcable.spawnshield.nms.BlockChange; |
| 29 | +import net.techcable.spawnshield.nms.NMS; |
| 30 | +import net.techcable.techutils.Reflection; |
| 31 | +import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; |
| 32 | +import org.bukkit.entity.Player; |
| 33 | + |
| 34 | +import java.lang.reflect.Field; |
| 35 | +import java.util.Collection; |
| 36 | + |
| 37 | +public class NMSImpl implements NMS { |
| 38 | + |
| 39 | + private final Field chunkCoordField = PacketPlayOutMultiBlockChange.class.getDeclaredFields()[0]; |
| 40 | + private final Field dataArray = PacketPlayOutMultiBlockChange.class.getDeclaredFields()[1]; |
| 41 | + @Override |
| 42 | + public void sendMultiBlockChange(Player player, ChunkPos chunkPos, Collection<BlockChange> changes) { |
| 43 | + PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(); |
| 44 | + MultiBlockChangeInfo[] changeArray = new MultiBlockChangeInfo[changes.size()]; |
| 45 | + int i = 0; |
| 46 | + for (BlockChange change : changes) { |
| 47 | + IBlockData data = Block.getById(change.getNewMaterial().getId()).fromLegacyData(change.getNewData()); |
| 48 | + MultiBlockChangeInfo info = new MultiBlockChangeInfo(packet, change.encodePos(), data); |
| 49 | + changeArray[i] = info; |
| 50 | + i++; |
| 51 | + } |
| 52 | + ChunkCoordIntPair chunkCoord = new ChunkCoordIntPair(chunkPos.getX(), chunkPos.getZ()); |
| 53 | + Reflection.setField(chunkCoordField, packet, chunkCoord); |
| 54 | + Reflection.setField(dataArray, packet, changeArray); |
| 55 | + EntityPlayer handle = ((CraftPlayer)player).getHandle(); |
| 56 | + handle.playerConnection.sendPacket(packet); |
| 57 | + } |
| 58 | +} |
0 commit comments