Skip to content

Commit

Permalink
Made it so that the plugin still works without ProtocolLib (and other…
Browse files Browse the repository at this point in the history
… stuff)
  • Loading branch information
sh0inx committed May 21, 2024
1 parent 693171b commit 7495200
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 31 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ dependencies {
implementation("org.jetbrains:annotations:24.1.0")
implementation("com.j256.ormlite:ormlite-core:6.1")
implementation("com.j256.ormlite:ormlite-jdbc:6.1")
implementation("com.iridium:IridiumTeams:2.4.4")
//implementation("com.iridium:IridiumTeams:2.4.4")
implementation(files("build/depend/IridiumTeams-2.4.4.jar"))

// Other dependencies that are not required or already available at runtime
compileOnly("org.projectlombok:lombok:1.18.32")
Expand Down
23 changes: 4 additions & 19 deletions src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.iridium.iridiumskyblock;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLib;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.iridium.iridiumcore.dependencies.xseries.XMaterial;
import com.iridium.iridiumskyblock.configs.*;
import com.iridium.iridiumskyblock.database.Island;
Expand All @@ -25,7 +22,6 @@
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.event.Listener;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.RegisteredServiceProvider;
Expand Down Expand Up @@ -67,8 +63,6 @@ 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 Down Expand Up @@ -140,7 +134,6 @@ 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 @@ -195,6 +188,10 @@ 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")) {
new ProtocolLibPacketListener().registerListeners();
} else if (IridiumSkyblock.getInstance().getConfiguration().fixHorizon) IridiumSkyblock.getInstance().getLogger().warning("ProtocolLib is not installed - features will be limited.");
}

@Override
Expand Down Expand Up @@ -341,18 +338,6 @@ 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class FlatGenerator extends ChunkGenerator {

// Generate dirt layer
for (int y = floorHeight - 4; y < floorHeight; y++) {
if(chunkData.getType(x, y, z) == Material.BEDROCK) continue;
chunkData.setBlock(x, y, z,
Objects.requireNonNull(getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class FlatGeneratorLegacy extends ChunkGenerator {

// Generate dirt layer
for (int y = floorHeight - 4; y < floorHeight; y++) {
if(chunkData.getType(x, y, z) == Material.BEDROCK) continue;
chunkData.setBlock(x, y, z,
Objects.requireNonNull(getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial())
);
Expand Down Expand Up @@ -126,15 +127,17 @@ && getFlatGenerator(world.getEnvironment()).floor.parseMaterial() != null) {
}

// Generate lakes, trees, grass, mineral deposits, etc.
if (getFlatGenerator(world.getEnvironment()).decorate) shouldGenerateDecorations();
if (getFlatGenerator(world.getEnvironment()).decorate) {

}
}

@Override
public boolean canSpawn(@NotNull World world, int x, int z) {
return getFlatGenerator(world.getEnvironment()).canSpawnEntities;
}

private Generators.FlatGeneratorWorld getFlatGenerator(Environment environment) {
public Generators.FlatGeneratorWorld getFlatGenerator(Environment environment) {
switch (environment) {
case NETHER: {
return IridiumSkyblock.getInstance().getGenerators().flatGenerator.nether;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.iridium.iridiumskyblock.listeners;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.ListenerPriority;
import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.utils.ProtocolLibUtils.IridiumPacketAdapter;

public class ProtocolLibPacketListener {

public void registerListeners() {
try {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
protocolManager.addPacketListener(new IridiumPacketAdapter(IridiumSkyblock.getInstance(), ListenerPriority.HIGH, PacketType.Play.Server.LOGIN));
protocolManager.addPacketListener(new IridiumPacketAdapter(IridiumSkyblock.getInstance(), ListenerPriority.HIGH, PacketType.Play.Server.RESPAWN));
} catch (NoClassDefFoundError e) {
IridiumSkyblock.getInstance().getLogger().severe(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.iridium.iridiumskyblock.managers;

import com.iridium.iridiumcore.dependencies.nbtapi.NBT;
import com.iridium.iridiumcore.dependencies.nbtapi.NBTCompound;
import com.iridium.iridiumcore.dependencies.nbtapi.NBTFile;
import com.iridium.iridiumcore.dependencies.nbtapi.NBTItem;
Expand Down Expand Up @@ -404,10 +405,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++) {
BlockData blockA = regenWorld.getBlockData(x, y, z);
Block blockA = regenWorld.getBlockAt(x, y ,z);
Block blockB = world.getBlockAt(x, y, z);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.iridium.iridiumskyblock.IridiumSkyblock;
import org.bukkit.World;
import org.bukkit.WorldType;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import java.lang.reflect.Field;
import java.util.List;

public class IridiumPacketAdapter extends PacketAdapter {
Expand Down Expand Up @@ -81,7 +80,7 @@ private void editPacketForHorizon(PacketEvent packetEvent, boolean fallback) {
if(packetType == PacketType.Play.Server.LOGIN) flatWorldIndex = 4;
if(packetType == PacketType.Play.Server.RESPAWN) flatWorldIndex = 1;

StructureModifier<Object> commonPlayerSpawnInfo = packet.getModifier();
Field commonPlayerSpawnInfo = packet.getModifier().getField(9);

int getCommonPlayerSpawnInfoIndex = 0;
if(packetType == PacketType.Play.Server.LOGIN) getCommonPlayerSpawnInfoIndex = 9;
Expand All @@ -93,10 +92,7 @@ private void editPacketForHorizon(PacketEvent packetEvent, boolean fallback) {
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] PACKET FIELDS: " + packet.getStructures().getFields());
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] =+=+=+=+=+=+=+=+=+=+=+=+=");
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] PACKET OBJECT: " + commonPlayerSpawnInfo);
for(int i = 0; i < commonPlayerSpawnInfo.size(); i++) {
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] MAPPED TO: " + commonPlayerSpawnInfo.getField(i).getName());
}
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] PRE-MUTATION VALUES: " + commonPlayerSpawnInfo.getValues());
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] PRE-MUTATION VALUES: " + commonPlayerSpawnInfo.toString());
IridiumSkyblock.getInstance().getLogger().info("[DEBUG] =+=+=+=+=+=+=+=+=+=+=+=+=");

//booleans.write(flatWorldIndex, true);
Expand Down

0 comments on commit 7495200

Please sign in to comment.