use of thpmc.vanilla_source.api.world.parallel.ParallelUniverse in project VanillaSource by TheHollowPlanetMC.
the class BlockChangePacketHandler method rewrite.
@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
ParallelUniverse universe = EnginePlayer.getUniverse();
if (universe == null)
return packet;
String worldName = EnginePlayer.getBukkitPlayer().getWorld().getName();
ParallelWorld parallelWorld = universe.getWorld(worldName);
try {
PacketPlayOutBlockChange blockChange = (PacketPlayOutBlockChange) packet;
BlockPosition bp = (BlockPosition) a.get(blockChange);
BlockData blockData = parallelWorld.getBlockData(bp.getX(), bp.getY(), bp.getZ());
if (blockData == null)
return packet;
PacketPlayOutBlockChange newPacket = new PacketPlayOutBlockChange();
a.set(newPacket, bp);
newPacket.block = ((CraftBlockData) blockData).getState();
return newPacket;
} catch (Exception e) {
e.printStackTrace();
}
return packet;
}
use of thpmc.vanilla_source.api.world.parallel.ParallelUniverse in project VanillaSource by TheHollowPlanetMC.
the class LightUpdatePacketHandler method rewrite.
@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
ParallelUniverse universe = EnginePlayer.getUniverse();
if (universe == null)
return packet;
World world = EnginePlayer.getBukkitPlayer().getWorld();
String worldName = world.getName();
ParallelWorld parallelWorld = universe.getWorld(worldName);
try {
int chunkX = a.getInt(packet);
int chunkZ = b.getInt(packet);
boolean iFlag = i.getBoolean(packet);
ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
if (parallelChunk == null)
return packet;
Object cachedPacket = parallelChunk.getCachedLightUpdatePacket();
if (cachedPacket != null)
return cachedPacket;
int cValue = c.getInt(packet);
int dValue = d.getInt(packet);
int eValue = e.getInt(packet);
int fValue = f.getInt(packet);
Deque<byte[]> gValue = new ArrayDeque<>((List<byte[]>) g.get(packet));
Deque<byte[]> hValue = new ArrayDeque<>((List<byte[]>) h.get(packet));
int newC = 0;
int newD = 0;
int newE = 0;
int newF = 0;
List<byte[]> newG = new ArrayList<>();
List<byte[]> newH = new ArrayList<>();
boolean edited = false;
for (int index = 0; index < 18; index++) {
int sectionIndex = index - 1;
int cSectionBit = cValue & (1 << index);
newC |= cSectionBit;
newE |= eValue & (1 << index);
int dSectionBit = dValue & (1 << index);
newD |= dSectionBit;
newF |= fValue & (1 << index);
if (index == 0 || index == 17) {
if (cSectionBit != 0) {
newG.add(gValue.removeFirst());
}
if (dSectionBit != 0) {
newH.add(hValue.removeFirst());
}
continue;
}
SectionLevelArray skyLevelArray = parallelChunk.getSkyLightSectionLevelArray(sectionIndex);
SectionLevelArray blockLevelArray = parallelChunk.getBlockLightSectionLevelArray(sectionIndex);
if (skyLevelArray == null) {
if (cSectionBit != 0) {
newG.add(gValue.removeFirst());
}
} else {
if (cSectionBit == 0) {
NibbleArray nibbleArray = new NibbleArray();
boolean notEmpty = skyLevelArray.threadsafeIteration(nibbleArray::a);
if (notEmpty)
edited = true;
newG.add(nibbleArray.asBytes());
if (notEmpty) {
newC |= 1 << index;
newE &= ~(1 << index);
} else {
newE |= 1 << index;
}
} else {
NibbleArray nibbleArray = new NibbleArray(gValue.removeFirst().clone());
boolean notEmpty = skyLevelArray.threadsafeIteration(nibbleArray::a);
if (notEmpty)
edited = true;
newG.add(nibbleArray.asBytes());
if (notEmpty) {
newE &= ~(1 << index);
}
}
}
if (blockLevelArray == null) {
if (dSectionBit != 0) {
newH.add(hValue.removeFirst());
}
} else {
if (dSectionBit == 0) {
NibbleArray nibbleArray = new NibbleArray();
boolean notEmpty = blockLevelArray.threadsafeIteration(nibbleArray::a);
if (notEmpty)
edited = true;
newH.add(nibbleArray.asBytes());
if (notEmpty) {
newD |= 1 << index;
newF &= ~(1 << index);
} else {
newF |= 1 << index;
}
} else {
NibbleArray nibbleArray = new NibbleArray(hValue.removeFirst().clone());
boolean notEmpty = blockLevelArray.threadsafeIteration(nibbleArray::a);
if (notEmpty)
edited = true;
newH.add(nibbleArray.asBytes());
if (notEmpty) {
newF &= ~(1 << index);
}
}
}
}
if (!edited)
return packet;
PacketPlayOutLightUpdate newPacket = new PacketPlayOutLightUpdate();
a.set(newPacket, chunkX);
b.set(newPacket, chunkZ);
c.set(newPacket, newC);
d.set(newPacket, newD);
e.set(newPacket, newE);
f.set(newPacket, newF);
g.set(newPacket, newG);
h.set(newPacket, newH);
i.set(newPacket, iFlag);
if (cacheSetting)
parallelChunk.setLightUpdatePacketCache(newPacket);
return newPacket;
} catch (Exception e) {
e.printStackTrace();
}
return packet;
}
use of thpmc.vanilla_source.api.world.parallel.ParallelUniverse in project VanillaSource by TheHollowPlanetMC.
the class LightUpdatePacketHandler method rewrite.
@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
ParallelUniverse universe = EnginePlayer.getUniverse();
if (universe == null)
return packet;
World world = EnginePlayer.getBukkitPlayer().getWorld();
String worldName = world.getName();
ParallelWorld parallelWorld = universe.getWorld(worldName);
try {
int chunkX = a.getInt(packet);
int chunkZ = b.getInt(packet);
ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
if (parallelChunk == null)
return packet;
Object cachedPacket = parallelChunk.getCachedLightUpdatePacket();
if (cachedPacket != null)
return cachedPacket;
int cValue = c.getInt(packet);
int dValue = d.getInt(packet);
int eValue = e.getInt(packet);
int fValue = f.getInt(packet);
Deque<byte[]> gValue = new ArrayDeque<>((List<byte[]>) g.get(packet));
Deque<byte[]> hValue = new ArrayDeque<>((List<byte[]>) h.get(packet));
int newC = 0;
int newD = 0;
int newE = 0;
int newF = 0;
List<byte[]> newG = new ArrayList<>();
List<byte[]> newH = new ArrayList<>();
boolean edited = false;
for (int index = 0; index < 18; index++) {
int sectionIndex = index - 1;
int cSectionBit = cValue & (1 << index);
newC |= cSectionBit;
newE |= eValue & (1 << index);
int dSectionBit = dValue & (1 << index);
newD |= dSectionBit;
newF |= fValue & (1 << index);
if (index == 0 || index == 17) {
if (cSectionBit != 0) {
newG.add(gValue.removeFirst());
}
if (dSectionBit != 0) {
newH.add(hValue.removeFirst());
}
continue;
}
SectionLevelArray skyLevelArray = parallelChunk.getSkyLightSectionLevelArray(sectionIndex);
SectionLevelArray blockLevelArray = parallelChunk.getBlockLightSectionLevelArray(sectionIndex);
if (skyLevelArray == null) {
if (cSectionBit != 0) {
newG.add(gValue.removeFirst());
}
} else {
if (cSectionBit == 0) {
NibbleArray nibbleArray = new NibbleArray();
boolean notEmpty = skyLevelArray.threadsafeIteration(nibbleArray::a);
if (notEmpty)
edited = true;
newG.add(nibbleArray.asBytes());
if (notEmpty) {
newC |= 1 << index;
newE &= ~(1 << index);
} else {
newE |= 1 << index;
}
} else {
NibbleArray nibbleArray = new NibbleArray(gValue.removeFirst().clone());
boolean notEmpty = skyLevelArray.threadsafeIteration(nibbleArray::a);
if (notEmpty)
edited = true;
newG.add(nibbleArray.asBytes());
if (notEmpty) {
newE &= ~(1 << index);
}
}
}
if (blockLevelArray == null) {
if (dSectionBit != 0) {
newH.add(hValue.removeFirst());
}
} else {
if (dSectionBit == 0) {
NibbleArray nibbleArray = new NibbleArray();
boolean notEmpty = blockLevelArray.threadsafeIteration(nibbleArray::a);
if (notEmpty)
edited = true;
newH.add(nibbleArray.asBytes());
if (notEmpty) {
newD |= 1 << index;
newF &= ~(1 << index);
} else {
newF |= 1 << index;
}
} else {
NibbleArray nibbleArray = new NibbleArray(hValue.removeFirst().clone());
boolean notEmpty = blockLevelArray.threadsafeIteration(nibbleArray::a);
if (notEmpty)
edited = true;
newH.add(nibbleArray.asBytes());
if (notEmpty) {
newF &= ~(1 << index);
}
}
}
}
if (!edited)
return packet;
PacketPlayOutLightUpdate newPacket = new PacketPlayOutLightUpdate();
a.set(newPacket, chunkX);
b.set(newPacket, chunkZ);
c.set(newPacket, newC);
d.set(newPacket, newD);
e.set(newPacket, newE);
f.set(newPacket, newF);
g.set(newPacket, newG);
h.set(newPacket, newH);
if (cacheSetting)
parallelChunk.setLightUpdatePacketCache(newPacket);
return newPacket;
} catch (Exception e) {
e.printStackTrace();
}
return packet;
}
use of thpmc.vanilla_source.api.world.parallel.ParallelUniverse in project VanillaSource by TheHollowPlanetMC.
the class MultiBlockChangePacketHandler method rewrite.
@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
ParallelUniverse universe = EnginePlayer.getUniverse();
if (universe == null)
return packet;
String worldName = EnginePlayer.getBukkitPlayer().getWorld().getName();
ParallelWorld parallelWorld = universe.getWorld(worldName);
try {
ChunkCoordIntPair aValue = (ChunkCoordIntPair) a.get(packet);
PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] bValue = (PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[]) b.get(packet);
int chunkX = aValue.x;
int chunkZ = aValue.z;
ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
if (parallelChunk == null)
return packet;
PacketPlayOutMultiBlockChange newPacket = new PacketPlayOutMultiBlockChange();
a.set(newPacket, aValue);
int length = bValue.length;
PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] newInfo = new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[length];
for (int index = 0; index < length; index++) {
PacketPlayOutMultiBlockChange.MultiBlockChangeInfo info = bValue[index];
BlockPosition bp = info.a();
BlockData blockData = parallelChunk.getBlockData(bp.getX(), bp.getY(), bp.getZ());
if (blockData == null) {
newInfo[index] = info;
} else {
newInfo[index] = newPacket.new MultiBlockChangeInfo(info.b(), ((CraftBlockData) blockData).getState());
}
}
b.set(newPacket, newInfo);
return newPacket;
} catch (Exception e) {
e.printStackTrace();
}
return packet;
}
use of thpmc.vanilla_source.api.world.parallel.ParallelUniverse in project VanillaSource by TheHollowPlanetMC.
the class parallelCommandExecutor method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (args == null)
return false;
if (args.length == 0)
return false;
if (args[0].equals("structure")) {
if (args.length < 3) {
return false;
}
// parallel structure set-data [structure-name] [data-name] [player]
if (args[1].equals("set-data")) {
if (args.length < 5) {
return false;
}
ParallelStructure parallelStructure = ParallelStructure.getParallelStructure(args[2]);
if (parallelStructure == null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造体は存在しません。");
return true;
}
ImplStructureData implStructureData = (ImplStructureData) ImplStructureData.getStructureData(args[3]);
if (implStructureData == null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造データは存在しません。");
return true;
}
Player player = Bukkit.getPlayer(args[4]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "指定されたプレイヤーが見つかりませんでした。");
return true;
}
parallelStructure.setStructureData(player, implStructureData);
sender.sendMessage(ChatColor.GREEN + "適用しました。");
return true;
}
// parallel structure remove-data [structure-name] [player]
if (args[1].equals("remove-data")) {
if (args.length < 4) {
return false;
}
ParallelStructure parallelStructure = ParallelStructure.getParallelStructure(args[2]);
if (parallelStructure == null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造体は存在しません。");
return true;
}
Player player = Bukkit.getPlayer(args[3]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "指定されたプレイヤーが見つかりませんでした。");
return true;
}
parallelStructure.clearStructureData(player, true);
sender.sendMessage(ChatColor.GREEN + "適用しました。");
return true;
}
}
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "このコマンドはコンソールから実行できません。");
return true;
}
if (args[0].equals("menu")) {
Player player = (Player) sender;
UniverseGUI.openUniverseGUI(player);
return true;
}
if (args[0].equals("join-universe")) {
if (args.length != 2)
return false;
String universeName = args[1];
ParallelUniverse universe = VanillaSourceAPI.getInstance().getUniverse(universeName);
if (universe == null) {
sender.sendMessage("§aThe universe is not found.");
return true;
}
EnginePlayer enginePlayer = EnginePlayer.getParallelPlayer((Player) sender);
if (enginePlayer == null)
return false;
enginePlayer.setUniverse(universe);
enginePlayer.getBukkitPlayer().sendMessage("§7Switched to §r" + universe.getName());
}
if (args[0].equals("leave-universe")) {
EnginePlayer enginePlayer = EnginePlayer.getParallelPlayer((Player) sender);
if (enginePlayer == null)
return false;
enginePlayer.setUniverse(null);
}
// parallel structure-data create [name]
if (args[0].equals("structure-data")) {
if (args.length < 3) {
return false;
}
if (args[1].equals("create")) {
Player player = (Player) sender;
com.sk89q.worldedit.entity.Player wePlayer = BukkitAdapter.adapt(player);
SessionManager sessionManager = WorldEdit.getInstance().getSessionManager();
LocalSession localSession = sessionManager.get(wePlayer);
com.sk89q.worldedit.world.World selectionWorld = localSession.getSelectionWorld();
Region region;
try {
if (selectionWorld == null)
throw new IncompleteRegionException();
region = localSession.getSelection(selectionWorld);
} catch (IncompleteRegionException ex) {
sender.sendMessage(ChatColor.GREEN + "範囲が選択されていません。");
return true;
}
BlockVector3 max = region.getMaximumPoint();
BlockVector3 min = region.getMinimumPoint();
World world = BukkitAdapter.adapt(region.getWorld());
Vector maxLocation = new Vector(max.getX(), max.getY(), max.getZ());
Vector minLocation = new Vector(min.getX(), min.getY(), min.getZ());
RegionBlocks regionBlocks = new RegionBlocks(minLocation.toLocation(world), maxLocation.toLocation(world));
ImplStructureData implStructureData = (ImplStructureData) StructureData.getStructureData(args[2]);
if (implStructureData != null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造データは既に存在しています。");
return true;
}
implStructureData = new ImplStructureData(args[2]);
implStructureData.setBlockData(minLocation.toLocation(world), regionBlocks.getBlocks());
sender.sendMessage(ChatColor.GREEN + "作成しました。");
return true;
}
if (args[1].equals("save")) {
ImplStructureData implStructureData = (ImplStructureData) ImplStructureData.getStructureData(args[2]);
if (implStructureData == null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造データは存在しません。");
return true;
}
implStructureData.saveData();
sender.sendMessage(ChatColor.GREEN + "保存しました。");
return true;
}
}
if (args[0].equals("structure")) {
if (args.length < 3) {
return false;
}
// parallel structure create [name]
if (args[1].equals("create")) {
Player player = (Player) sender;
com.sk89q.worldedit.entity.Player wePlayer = BukkitAdapter.adapt(player);
SessionManager sessionManager = WorldEdit.getInstance().getSessionManager();
LocalSession localSession = sessionManager.get(wePlayer);
com.sk89q.worldedit.world.World selectionWorld = localSession.getSelectionWorld();
Region region;
try {
if (selectionWorld == null)
throw new IncompleteRegionException();
region = localSession.getSelection(selectionWorld);
} catch (IncompleteRegionException ex) {
sender.sendMessage(ChatColor.GREEN + "範囲が選択されていません。");
return true;
}
BlockVector3 min = region.getMinimumPoint();
World world = BukkitAdapter.adapt(region.getWorld());
Vector minLocation = new Vector(min.getX(), min.getY(), min.getZ());
ParallelStructure parallelStructure = ParallelStructure.getParallelStructure(args[2]);
if (parallelStructure != null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造体は既に存在しています。");
return true;
}
parallelStructure = new ParallelStructure(args[2]);
parallelStructure.setBaseLocation(minLocation.toLocation(world));
sender.sendMessage(ChatColor.GREEN + "作成しました。");
return true;
}
// parallel structure save [name]
if (args[1].equals("save")) {
ParallelStructure parallelStructure = ParallelStructure.getParallelStructure(args[2]);
if (parallelStructure == null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造体は存在しません。");
return true;
}
parallelStructure.saveData();
sender.sendMessage(ChatColor.GREEN + "保存しました。");
return true;
}
}
return true;
}
Aggregations