Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sh0inx committed May 17, 2024
1 parent 5451142 commit 457c62a
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 87 deletions.
35 changes: 18 additions & 17 deletions src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

@Getter
public class IridiumSkyblock extends IridiumTeams<Island, User> {

@Getter
private static IridiumSkyblock instance;

private Configuration configuration;
Expand All @@ -65,6 +67,8 @@ public class IridiumSkyblock extends IridiumTeams<Island, User> {
private UserPlaceholderBuilder userPlaceholderBuilder;
private TeamChatPlaceholderBuilder teamChatPlaceholderBuilder;

@Getter
private ProtocolManager protocolManager;
private IslandManager teamManager;
private UserManager userManager;
private CommandManager commandManager;
Expand All @@ -87,9 +91,7 @@ public IridiumSkyblock(JavaPluginLoader loader, PluginDescriptionFile descriptio
instance = this;
}

public IridiumSkyblock() {
instance = this;
}
public IridiumSkyblock() { instance = this; }

@Override
public void onLoad() {
Expand Down Expand Up @@ -138,6 +140,7 @@ public void onEnable() {
this.teamManager.createWorld(World.Environment.NETHER, configuration.worldName + "_nether");
this.teamManager.createWorld(World.Environment.THE_END, configuration.worldName + "_the_end");

setProtocolManager();
this.schematicManager = new SchematicManager();
this.userManager = new UserManager();
this.commandManager = new CommandManager("iridiumskyblock");
Expand Down Expand Up @@ -192,16 +195,6 @@ public void registerListeners() {
Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(), this);
Bukkit.getPluginManager().registerEvents(new EntityDamageListener(), this);
if(!XMaterial.supports(15)) Bukkit.getPluginManager().registerEvents(new PortalCreateListener(), this);

if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
try {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
protocolManager.addPacketListener(new IridiumPacketAdapter(this, ListenerPriority.HIGH, PacketType.Play.Server.LOGIN));
protocolManager.addPacketListener(new IridiumPacketAdapter(this, ListenerPriority.HIGH, PacketType.Play.Server.RESPAWN));
} catch (NoClassDefFoundError ignored) {
if (configuration.fixHorizon) getLogger().info("ProtocolLib is not installed.");
}
}
}

@Override
Expand Down Expand Up @@ -348,6 +341,18 @@ private void setMcVersion() {
this.mcVersion = version;
}

private void setProtocolManager() {
if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
try {
this.protocolManager = ProtocolLibrary.getProtocolManager();
protocolManager.addPacketListener(new IridiumPacketAdapter(this, ListenerPriority.HIGH, PacketType.Play.Server.LOGIN));
protocolManager.addPacketListener(new IridiumPacketAdapter(this, ListenerPriority.HIGH, PacketType.Play.Server.RESPAWN));
} catch (NoClassDefFoundError ignored) {
if (configuration.fixHorizon) getLogger().warning("ProtocolLib is not installed - features will be limited.");
}
}
}

@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
return this.chunkGenerator;
Expand All @@ -356,8 +361,4 @@ public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
public IslandManager getIslandManager() {
return teamManager;
}

public static IridiumSkyblock getInstance() {
return instance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public class FlatGenerator extends ChunkGenerator {
);

// Generate stone layer
for (int y = LocationUtils.getMinHeight(world) + 1; y < floorHeight - 5; y++) {
for (int y = LocationUtils.getMinHeight(world) + 1; y < floorHeight - 4; y++) {
chunkData.setBlock(x, y, z,
Objects.requireNonNull(getFlatGenerator(world.getEnvironment()).mantle.parseMaterial())
);
}

// Generate dirt layer
for (int y = floorHeight - 5; y < floorHeight; y++) {
for (int y = floorHeight - 4; y < floorHeight; y++) {
chunkData.setBlock(x, y, z,
Objects.requireNonNull(getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial())
);
Expand Down Expand Up @@ -75,7 +75,7 @@ public void generateFlatland(World world, int x, int z) {
}

// Generate stone layer
for (int y = minFloorHeight + 1; y < floorHeight - 5; y++) {
for (int y = minFloorHeight + 1; y < floorHeight - 4; y++) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() != getFlatGenerator(world.getEnvironment()).mantle.parseMaterial()
&& getFlatGenerator(world.getEnvironment()).mantle.parseMaterial() != null) {
Expand All @@ -88,7 +88,7 @@ && getFlatGenerator(world.getEnvironment()).mantle.parseMaterial() != null) {
}

// Generate dirt layer
for (int y = floorHeight - 5; y < floorHeight; y++) {
for (int y = floorHeight - 4; y < floorHeight; y++) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() != getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial()
&& getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.configs.Generators;
import com.iridium.iridiumskyblock.utils.LocationUtils;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.generator.WorldInfo;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Random;

Expand All @@ -34,14 +36,14 @@ public class FlatGeneratorLegacy extends ChunkGenerator {
);

// Generate stone layer
for (int y = LocationUtils.getMinHeight(world) + 1; y < floorHeight - 5; y++) {
for (int y = LocationUtils.getMinHeight(world) + 1; y < floorHeight - 4; y++) {
chunkData.setBlock(x, y, z,
Objects.requireNonNull(getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial())
);
}

// Generate dirt layer
for (int y = floorHeight - 5; y < floorHeight; y++) {
for (int y = floorHeight - 4; y < floorHeight; y++) {
chunkData.setBlock(x, y, z,
Objects.requireNonNull(getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial())
);
Expand Down Expand Up @@ -75,7 +77,7 @@ public void generateFlatland(World world, int x, int z) {
}

// Generate stone layer
for (int y = minFloorHeight + 1; y < floorHeight - 5; y++) {
for (int y = minFloorHeight + 1; y < floorHeight - 4; y++) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() != getFlatGenerator(world.getEnvironment()).mantle.parseMaterial()
&& getFlatGenerator(world.getEnvironment()).mantle.parseMaterial() != null) {
Expand All @@ -88,7 +90,7 @@ && getFlatGenerator(world.getEnvironment()).mantle.parseMaterial() != null) {
}

// Generate dirt layer
for (int y = floorHeight - 5; y < floorHeight; y++) {
for (int y = floorHeight - 4; y < floorHeight; y++) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() != getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial()
&& getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial() != null) {
Expand Down Expand Up @@ -123,26 +125,8 @@ && getFlatGenerator(world.getEnvironment()).floor.parseMaterial() != null) {
}
}

shouldGenerateCaves(world, random, x, z);
shouldGenerateStructures(world, random, x, z);

// Generate lakes, trees, grass, mineral deposits, etc.
shouldGenerateDecorations(world, random, x, z);
}

@Override
public boolean shouldGenerateStructures(WorldInfo world, Random random, int x, int z) {
return getFlatGenerator(world.getEnvironment()).generateStructures;
}

@Override
public boolean shouldGenerateCaves(WorldInfo world, Random random, int x, int z) {
return getFlatGenerator(world.getEnvironment()).generateCaves;
}

@Override
public boolean shouldGenerateDecorations(WorldInfo world, Random random, int x, int y) {
return getFlatGenerator(world.getEnvironment()).decorate;
if (getFlatGenerator(world.getEnvironment()).decorate) shouldGenerateDecorations();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public class OceanGenerator extends ChunkGenerator {
);

// Generate stone layer
for (int y = LocationUtils.getMinHeight(world) + 1; y < currentFloorHeight - 5; y++) {
for (int y = LocationUtils.getMinHeight(world) + 1; y < currentFloorHeight - 4; y++) {
chunkData.setBlock(x, y, z,
Objects.requireNonNull(getOceanGenerator(world.getEnvironment()).mantle.parseMaterial())
);
}

// Generate gravel layer
for (int y = currentFloorHeight - 5; y < currentFloorHeight; y++) {
for (int y = currentFloorHeight - 4; y < currentFloorHeight; y++) {
chunkData.setBlock(x, y, z,
Objects.requireNonNull(getOceanGenerator(world.getEnvironment()).underFloor.parseMaterial())
);
Expand Down Expand Up @@ -93,7 +93,7 @@ public void generateOcean(World world, int x, int z) {
}

// Generate stone layer
for (int y = minHeightWorld + 1; y < currentFloorHeight - 5; y++) {
for (int y = minHeightWorld + 1; y < currentFloorHeight - 4; y++) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() != getOceanGenerator(world.getEnvironment()).mantle.parseMaterial()
&& getOceanGenerator(world.getEnvironment()).mantle.parseMaterial() != null) {
Expand All @@ -106,7 +106,7 @@ && getOceanGenerator(world.getEnvironment()).mantle.parseMaterial() != null) {
}

// Generate gravel on top of stone
for (int y = currentFloorHeight -5; y < currentFloorHeight; y++) {
for (int y = currentFloorHeight - 4; y < currentFloorHeight; y++) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() != getOceanGenerator(world.getEnvironment()).underFloor.parseMaterial()
&& getOceanGenerator(world.getEnvironment()).underFloor.parseMaterial() != null) {
Expand All @@ -126,12 +126,11 @@ && getOceanGenerator(world.getEnvironment()).floor.parseMaterial() != null) {
((InventoryHolder) world.getBlockAt(x, currentFloorHeight, z).getState()).getInventory().clear();
}

for(int y = currentFloorHeight; y < currentFloorHeight + 5; y++) {
for(int y = currentFloorHeight; y < currentFloorHeight + 4; y++) {
world.getBlockAt(x, currentFloorHeight, z)
.setType(Objects.requireNonNull(getOceanGenerator(world.getEnvironment()).floor.parseMaterial()), false);
currentFloorHeight++;
}

}

// Generate water or lava on top of the floor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,14 @@ && getOceanGenerator(world.getEnvironment()).floor.parseMaterial() != null) {

}

shouldGenerateCaves();

// Generate water or lava on top of the floor
for (int y = currentFloorHeight + 1; y <= getOceanGenerator(world.getEnvironment()).liquidHeight; y++) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() != getOceanGenerator(world.getEnvironment()).liquidType.parseMaterial() && getOceanGenerator(world.getEnvironment()).liquidType.parseMaterial() != null) {
if (block.getState() instanceof InventoryHolder) {
((InventoryHolder) block.getState()).getInventory().clear();
}
block.setType(getOceanGenerator(world.getEnvironment()).liquidType.parseMaterial(), true);
block.setType(getOceanGenerator(world.getEnvironment()).liquidType.parseMaterial(), false);
}
}

Expand All @@ -159,26 +157,8 @@ && getOceanGenerator(world.getEnvironment()).floor.parseMaterial() != null) {
}
}

// Generate structures
shouldGenerateStructures(world, random, x, z);

// Generate kelp, ores, mineral deposits, etc.
shouldGenerateDecorations(world, random , x, z);
}

@Override
public boolean shouldGenerateStructures(WorldInfo world, Random random, int x, int z) {
return getOceanGenerator(world.getEnvironment()).generateStructures;
}

@Override
public boolean shouldGenerateCaves(WorldInfo world, Random random, int x, int z) {
return getOceanGenerator(world.getEnvironment()).generateCaves;
}

@Override
public boolean shouldGenerateDecorations(WorldInfo world, Random random, int x, int y) {
return getOceanGenerator(world.getEnvironment()).decorate;
if(getOceanGenerator(world.getEnvironment()).decorate) shouldGenerateDecorations();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -115,12 +116,8 @@ public void createCacheWorld(World world) {

if (Bukkit.getWorld(getCacheWorldName(world)) == null) {

WorldCreator worldCreator = new WorldCreator(getCacheWorldName(world))
.generator(IridiumSkyblock.getInstance().getDefaultWorldGenerator(world.getName(), null))
.environment(world.getEnvironment())
.seed(world.getSeed());

worldCreator.createWorld();
WorldCreator worldCreator = new WorldCreator(getCacheWorldName(world));
worldCreator.copy(world).createWorld();
}

if (Bukkit.getWorld(getCacheWorldName(world)).getSeed() != Bukkit.getWorld(world.getName()).getSeed()) {
Expand Down Expand Up @@ -407,10 +404,10 @@ public void regenerateTerrain (Island island, World world, int y, CompletableFut

for (int x = pos1.getBlockX(); x <= pos2.getBlockX(); x++) {
for (int z = pos1.getBlockZ(); z <= pos2.getBlockZ(); z++) {
Block blockA = regenWorld.getBlockAt(x, y, z);
BlockData blockA = regenWorld.getBlockData(x, y, z);
Block blockB = world.getBlockAt(x, y, z);

blockB.setType(blockA.getType(), false);
blockB.setBlockData(blockA, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,43 @@ private void sendLowerHorizon(PacketEvent event) {
World world = event.getPlayer().getWorld();
if (!IridiumSkyblock.getInstance().getIslandManager().isInSkyblockWorld(world) && world.getEnvironment() != World.Environment.NORMAL) return;

IridiumSkyblock.getInstance().getLogger().info("[DEBUG] Version: " + Bukkit.getBukkitVersion() + " (" + IridiumSkyblock.getInstance().getMcVersion() + ")");
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] " + IridiumSkyblock.getInstance().getMcVersion());
editPacketForHorizon(event, IridiumSkyblock.getInstance().getMcVersion() < 16);
}

private void editPacketForHorizon(PacketEvent packetEvent, boolean fallback) {

PacketContainer packet = packetEvent.getPacket().deepClone();
PacketContainer packet = packetEvent.getPacket(); //packetEvent.getPacket().deepClone();
PacketType packetType = packet.getType();

if (!fallback) {

StructureModifier<Boolean> booleans = packet.getBooleans();

if (packetType == PacketType.Play.Server.LOGIN) booleans.write(4, true);
else if (packetType == PacketType.Play.Server.RESPAWN) booleans.write(1, true);
// login
// b - [0] hardcore (false)
// g -
// h -
// i -

int flatWorldIndex = 0;

if(packetType == PacketType.Play.Server.LOGIN) flatWorldIndex = 4;
if(packetType == PacketType.Play.Server.RESPAWN) flatWorldIndex = 1;

IridiumSkyblock.getInstance().getLogger().info("[DEBUG] =+=+=+=+=+=+=+=+=+=+=+=+=");
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] PACKET TYPE: " + packetType);
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] PACKET STRUCTURES: " + packet.getStructures());
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] PACKET FIELDS: " + packet.getStructures().getFields());
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] PACKET BOOLEANS: " + booleans);
for(int i = 0; i < booleans.size(); i++) {
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] MAPPED TO: " + booleans.getField(i).getName());
}
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] PRE-MUTATION VALUES: " + booleans.getValues());
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] TESTED PACKET FIELD: " + booleans.getField(flatWorldIndex).getName());
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] TESTED PACKET VALUE: TRUE");
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] =+=+=+=+=+=+=+=+=+=+=+=+=");

booleans.write(flatWorldIndex, true);

} else {

Expand Down

0 comments on commit 457c62a

Please sign in to comment.