Skip to content

Commit

Permalink
fix: replace usage of core's ServerVersion with new MajorServerVersion
Browse files Browse the repository at this point in the history
I can't be bothered to update 100+ or whatever usages
and conditions.
Too much brain work to re-think all those constraints.
  • Loading branch information
SpraxDev committed Jul 19, 2024
1 parent 1f66573 commit 251f7ab
Show file tree
Hide file tree
Showing 37 changed files with 143 additions and 109 deletions.
17 changes: 8 additions & 9 deletions src/main/java/com/craftaro/skyblock/SkyBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import com.craftaro.core.SongodaCore;
import com.craftaro.core.SongodaPlugin;
import com.craftaro.core.compatibility.MajorServerVersion;
import com.craftaro.core.compatibility.ServerProject;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.configuration.Config;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.core.hooks.HologramManager;
import com.craftaro.core.hooks.LogManager;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.skyblock.api.SkyBlockAPI;
import com.craftaro.skyblock.ban.BanManager;
import com.craftaro.skyblock.bank.BankManager;
Expand Down Expand Up @@ -71,6 +70,7 @@
import com.craftaro.skyblock.visit.VisitManager;
import com.craftaro.skyblock.visit.VisitTask;
import com.craftaro.skyblock.world.WorldManager;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand All @@ -81,9 +81,7 @@
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class SkyBlock extends SongodaPlugin {
private FileManager fileManager;
Expand Down Expand Up @@ -154,17 +152,18 @@ public void onPluginLoad() {

@Override
public void onPluginEnable() {
if (ServerVersion.isServerVersionAbove(ServerVersion.V1_20) || ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
if (MajorServerVersion.isServerVersionAbove(MajorServerVersion.V1_20) || MajorServerVersion.isServerVersionBelow(MajorServerVersion.V1_8)) {
this.getLogger().warning("This Minecraft version is not officially supported.");
}

if (this.paper = ServerProject.isServer(ServerProject.PAPER)) {
this.paper = ServerProject.isServer(ServerProject.PAPER);
if (this.paper) {
try {
Bukkit.spigot().getClass().getMethod("getPaperConfig");
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) {
if (MajorServerVersion.isServerVersionAtLeast(MajorServerVersion.V1_16)) {
this.paperAsync = true;
} else {
this.paperAsync = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) &&
this.paperAsync = MajorServerVersion.isServerVersionAtLeast(MajorServerVersion.V1_13) &&
Bukkit.spigot().getPaperConfig().getBoolean("settings.async-chunks.enable", false);
}
} catch (NoSuchMethodException ignored) {
Expand Down Expand Up @@ -266,7 +265,7 @@ public void onPluginEnable() {
pluginManager.registerEvents(new FallBreakListeners(this), this);
pluginManager.registerEvents(new WorldListeners(this), this);

if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
if (MajorServerVersion.isServerVersionAtLeast(MajorServerVersion.V1_13)) {
pluginManager.registerEvents(new SpongeListeners(this), this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.craftaro.skyblock.blockscanner;

import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.MajorServerVersion;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.skyblock.utils.world.WorldUtil;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
Expand Down Expand Up @@ -272,7 +273,7 @@ private void processCachedChunk(World world, int scanY, CachedChunk shot, Locati
for (int z = initZ; z <= lastZ; z++) {
for (int y = scanY; y < world.getMaxHeight(); y++) {
final Optional<XMaterial> type = CompatibleMaterial.getMaterial(
ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)
MajorServerVersion.isServerVersionAtLeast(MajorServerVersion.V1_13)
? shot.getSnapshot().getBlockType(x, y, z) :
MaterialIDHelper.getLegacyMaterial(getBlockTypeID(shot, x, y, z)));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.craftaro.skyblock.blockscanner;

import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.compatibility.MajorServerVersion;
import org.bukkit.Material;

import java.util.HashMap;
Expand All @@ -15,7 +15,7 @@ private MaterialIDHelper() {
static {
MATERIALS = new HashMap<>();

if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
if (MajorServerVersion.isServerVersionAtLeast(MajorServerVersion.V1_13)) {
for (Material type : Material.values()) {
if (type.isLegacy()) {
MATERIALS.put(type.getId(), type);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.craftaro.skyblock.generator;

import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.MajorServerVersion;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.third_party.com.cryptomorin.xseries.XBlock;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
Expand Down Expand Up @@ -109,7 +110,7 @@ public boolean isGenerator(Block block) {

@SuppressWarnings("deprecation")
private int getLiquidLevel(Block block) {
if (ServerVersion.isServerVersionAbove(ServerVersion.V1_12) && block.getState().getBlockData() instanceof Levelled) {
if (MajorServerVersion.isServerVersionAbove(MajorServerVersion.V1_12) && block.getState().getBlockData() instanceof Levelled) {
Levelled levelled = (Levelled) block.getState().getBlockData();
return levelled.getLevel();
} else {
Expand All @@ -131,7 +132,7 @@ public BlockState generateBlock(Generator generator, Block block) {
this.plugin.getSoundManager().playSound(block.getLocation(), XSound.BLOCK_FIRE_EXTINGUISH, 1, 10);


if (ServerVersion.isServerVersionAbove(ServerVersion.V1_12)) {
if (MajorServerVersion.isServerVersionAbove(MajorServerVersion.V1_12)) {
XBlock.setType(block, materials);
} else {
ItemStack is = materials.parseItem();
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/craftaro/skyblock/island/IslandLevel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.craftaro.skyblock.island;

import com.craftaro.core.compatibility.MajorServerVersion;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.skyblock.SkyBlock;
Expand Down Expand Up @@ -104,7 +105,7 @@ public double getPoints() {
}

public long getMaterialPoints(String material) {
if (ServerVersion.isServerVersion(ServerVersion.V1_8)) {
if (MajorServerVersion.isServerVersion(MajorServerVersion.V1_8)) {
switch (material.toUpperCase()) {
case "DIODE_BLOCK_OFF":
case "DIODE_BLOCK_ON":
Expand Down Expand Up @@ -216,7 +217,7 @@ public void addMaterial(String material, long amount) {
}

public void setMaterialAmount(String material, long amount) {
if (ServerVersion.isServerVersion(ServerVersion.V1_8)) {
if (MajorServerVersion.isServerVersion(MajorServerVersion.V1_8)) {
switch (material.toUpperCase()) {
case "DIODE_BLOCK_OFF":
case "DIODE_BLOCK_ON":
Expand All @@ -232,7 +233,7 @@ public void setMaterialAmount(String material, long amount) {
}

public long getMaterialAmount(String material) {
if (ServerVersion.isServerVersion(ServerVersion.V1_8)) {
if (MajorServerVersion.isServerVersion(MajorServerVersion.V1_8)) {
switch (material.toUpperCase()) {
case "DIODE_BLOCK_OFF":
case "DIODE_BLOCK_ON":
Expand All @@ -244,7 +245,7 @@ public long getMaterialAmount(String material) {
}

public void removeMaterial(String material) {
if (ServerVersion.isServerVersion(ServerVersion.V1_8)) {
if (MajorServerVersion.isServerVersion(MajorServerVersion.V1_8)) {
switch (material.toUpperCase()) {
case "DIODE_BLOCK_OFF":
case "DIODE_BLOCK_ON":
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/craftaro/skyblock/island/IslandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
import com.craftaro.core.compatibility.CompatibleBiome;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.MajorServerVersion;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.nms.Nms;
import com.craftaro.skyblock.SkyBlock;
Expand Down Expand Up @@ -1502,7 +1503,7 @@ public void loadPlayer(Player player) {
updateFlight(player);

if (world == IslandWorld.NETHER) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_13)) {
if (MajorServerVersion.isServerVersionBelow(MajorServerVersion.V1_13)) {
return;
}
}
Expand Down Expand Up @@ -1665,7 +1666,7 @@ public void updateBorder(Island island) {
double increment = island.getSize() % 2 != 0 ? 0.5d : 0.0d;

for (IslandWorld worldList : IslandWorld.getIslandWorlds()) {
if (worldList != IslandWorld.NETHER || ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
if (worldList != IslandWorld.NETHER || MajorServerVersion.isServerVersionAtLeast(MajorServerVersion.V1_13)) {
Bukkit.getScheduler().runTask(this.plugin, () -> {
for (Player all : getPlayersAtIsland(island)) {
Nms.getImplementations().getWorldBorder().send(all, island.getBorderColor(), island.getSize(), island.getLocation(worldManager.getIslandWorld(all.getWorld()), IslandEnvironment.ISLAND).clone().add(increment, 0, increment));
Expand All @@ -1677,7 +1678,7 @@ public void updateBorder(Island island) {
}
} else {
for (IslandWorld worldList : IslandWorld.getIslandWorlds()) {
if (worldList != IslandWorld.NETHER || ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
if (worldList != IslandWorld.NETHER || MajorServerVersion.isServerVersionAtLeast(MajorServerVersion.V1_13)) {
Bukkit.getScheduler().runTask(this.plugin, () -> {
for (Player all : getPlayersAtIsland(island)) {
Nms.getImplementations().getWorldBorder().send(all, null, 1.4999992E7D, new Location(all.getWorld(), 0, 0, 0));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.craftaro.skyblock.levelling;

import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.MajorServerVersion;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.skyblock.SkyBlock;
Expand Down Expand Up @@ -260,7 +261,7 @@ public void updateLevel(Island island, Location location) {
// placed.
// This shouldn't cause any issues besides the task number being increased
// insanely fast.
if (ServerVersion.isServerVersion(ServerVersion.V1_8)) {
if (MajorServerVersion.isServerVersion(MajorServerVersion.V1_8)) {
Bukkit.getScheduler().runTask(this.plugin, () -> {
updateLevelLocation(island, location);
});
Expand All @@ -272,7 +273,7 @@ public void updateLevel(Island island, Location location) {
private void updateLevelLocation(Island island, Location location) {
Block block = location.getBlock();
XMaterial material = null;
if (ServerVersion.isServerVersion(ServerVersion.V1_8)) {
if (MajorServerVersion.isServerVersion(MajorServerVersion.V1_8)) {
switch (block.getType().toString().toUpperCase()) {
case "DIODE_BLOCK_OFF":
case "DIODE_BLOCK_ON":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.craftaro.skyblock.limit.impl;

import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.MajorServerVersion;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.skyblock.SkyBlock;
Expand Down Expand Up @@ -73,7 +74,7 @@ public long getBlockLimit(Player player, Material type) {
}

XMaterial material = null;
if (ServerVersion.isServerVersion(ServerVersion.V1_8)) {
if (MajorServerVersion.isServerVersion(MajorServerVersion.V1_8)) {
switch (type.toString().toUpperCase()) {
case "DIODE_BLOCK_OFF":
case "DIODE_BLOCK_ON":
Expand Down Expand Up @@ -111,7 +112,7 @@ public boolean isBlockLimitExceeded(XMaterial type, Location loc, long limit) {
totalPlaced = island.getLevel().getMaterials().entrySet().stream().filter(x -> x.getKey().contains("SPAWNER")).mapToLong(Map.Entry::getValue).sum();
} else {
XMaterial material = null;
if (ServerVersion.isServerVersion(ServerVersion.V1_8)) {
if (MajorServerVersion.isServerVersion(MajorServerVersion.V1_8)) {
switch (type.toString().toUpperCase()) {
case "DIODE_BLOCK_OFF":
case "DIODE_BLOCK_ON":
Expand Down
Loading

0 comments on commit 251f7ab

Please sign in to comment.