Skip to content

Commit

Permalink
Merge pull request #378 from Lapzupi/feature/java-17
Browse files Browse the repository at this point in the history
Java 17
  • Loading branch information
sarhatabaot authored Jul 14, 2024
2 parents d5ce53e + 58e3e43 commit 83094aa
Show file tree
Hide file tree
Showing 35 changed files with 378 additions and 502 deletions.
3 changes: 2 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ plugins {
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
}
repositories {
// Use the plugin portal to apply community plugins in convention plugins.
gradlePluginPortal()
mavenCentral()
}
2 changes: 2 additions & 0 deletions even-more-fish-addons-j17/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies {
compileOnly(libs.ecoitems.eco)
compileOnly(libs.denizen.api)
compileOnly(libs.commons.lang3)
compileOnly(libs.itemsadder.api)
compileOnly(libs.headdatabase.api)
compileOnly(project(":even-more-fish-api"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import com.denizenscript.denizen.objects.ItemTag;
import com.oheers.fish.api.addons.ItemAddon;
import org.apache.commons.lang3.JavaVersion;
import org.bukkit.inventory.ItemStack;

public class DenizenItemAddon extends ItemAddon {
Expand Down Expand Up @@ -33,8 +32,4 @@ public ItemStack getItemStack(String id) {
return itemTag.getItemStack();
}

@Override
public JavaVersion getRequiredJavaVersion() {
return JavaVersion.JAVA_17;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.oheers.fish.api.addons.ItemAddon;
import com.willfp.ecoitems.items.EcoItem;
import com.willfp.ecoitems.items.EcoItems;
import org.apache.commons.lang3.JavaVersion;
import org.bukkit.inventory.ItemStack;

public class EcoItemsItemAddon extends ItemAddon {
Expand Down Expand Up @@ -34,8 +33,4 @@ public ItemStack getItemStack(String id) {
return item.getItemStack();
}

@Override
public JavaVersion getRequiredJavaVersion() {
return JavaVersion.JAVA_17;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.oheers.fish.api.addons.ItemAddon;
import io.th0rgal.oraxen.api.OraxenItems;
import io.th0rgal.oraxen.items.ItemBuilder;
import org.apache.commons.lang3.JavaVersion;
import org.bukkit.inventory.ItemStack;

public class OraxenItemAddon extends ItemAddon {
Expand Down Expand Up @@ -34,8 +33,4 @@ public ItemStack getItemStack(String id) {
return item.build();
}

@Override
public JavaVersion getRequiredJavaVersion() {
return JavaVersion.JAVA_17;
}
}
21 changes: 0 additions & 21 deletions even-more-fish-addons-j8/build.gradle.kts

This file was deleted.

2 changes: 1 addition & 1 deletion even-more-fish-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies {

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
languageVersion.set(JavaLanguageVersion.of(17))
vendor.set(JvmVendorSpec.ADOPTIUM)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface Addon {


/**
* Can this addon be registered.
* This should check if the addon can be registered. I.e., required java version + required plugin.
*/
default boolean canRegister() throws JavaVersionException, RequiredPluginException {
final boolean hasRequiredPlugin = Bukkit.getPluginManager().getPlugin(getPluginName()) != null;
Expand All @@ -44,7 +44,7 @@ default boolean canRegister() throws JavaVersionException, RequiredPluginExcepti
String getAuthor();

default JavaVersion getRequiredJavaVersion() {
return JavaVersion.JAVA_1_8;
return JavaVersion.JAVA_17;
}

default Logger getLogger() {
Expand Down
18 changes: 7 additions & 11 deletions even-more-fish-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import net.minecrell.pluginyml.bukkit.BukkitPluginDescription

plugins {
`java-library`
id("maven-publish")
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
id("com.github.johnrengelman.shadow") version "8.1.1"

`maven-publish`
alias(libs.plugins.bukkit.yml)
alias(libs.plugins.shadow)
alias(libs.plugins.grgit)
}

group = "com.oheers.evenmorefish"
version = "1.7.2"
version = "1.7.3"

description = "A fishing extension bringing an exciting new experience to fishing."

Expand Down Expand Up @@ -88,9 +87,7 @@ dependencies {
implementation(libs.universalscheduler)
implementation(libs.acf)
implementation(libs.inventorygui)
implementation(libs.adventure.api)
implementation(libs.adventure.minimessage)
implementation(libs.adventure.legacy)
implementation(libs.bundles.adventure)

library(libs.friendlyid)
library(libs.flyway.core)
Expand Down Expand Up @@ -253,14 +250,13 @@ tasks {
compileJava {
options.compilerArgs.add("-parameters")
options.isFork = true


options.encoding = "UTF-8"
}
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
languageVersion.set(JavaLanguageVersion.of(17))
vendor.set(JvmVendorSpec.ADOPTIUM)
}
}
Expand Down
48 changes: 19 additions & 29 deletions even-more-fish-plugin/src/main/java/com/oheers/fish/Economy.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,43 +96,33 @@ public boolean withdraw(@NotNull OfflinePlayer player, double amount) {
}

public boolean has(@NotNull OfflinePlayer player, double amount) {
switch (economyType) {
case VAULT:
return vaultEconomy.has(player, amount);
case PLAYER_POINTS:
return switch (economyType) {
case VAULT -> vaultEconomy.has(player, amount);
case PLAYER_POINTS ->
// PlayerPoints doesn't seem to have a method to check this
return playerPointsEconomy.look(player.getUniqueId()) >= amount;
case GRIEF_PREVENTION:
return griefPreventionEconomy.dataStore.getPlayerData(player.getUniqueId()).getBonusClaimBlocks() >= amount;
default:
return true;
}
playerPointsEconomy.look(player.getUniqueId()) >= amount;
case GRIEF_PREVENTION -> griefPreventionEconomy.dataStore.getPlayerData(player.getUniqueId()).getBonusClaimBlocks() >= amount;
default -> true;
};
}

public double get(@NotNull OfflinePlayer player) {
switch (economyType) {
case VAULT:
return vaultEconomy.getBalance(player);
case PLAYER_POINTS:
return switch (economyType) {
case VAULT -> vaultEconomy.getBalance(player);
case PLAYER_POINTS ->
// PlayerPoints doesn't seem to have a method to check this
return playerPointsEconomy.look(player.getUniqueId());
case GRIEF_PREVENTION:
return griefPreventionEconomy.dataStore.getPlayerData(player.getUniqueId()).getBonusClaimBlocks();
default:
return 0;
}
playerPointsEconomy.look(player.getUniqueId());
case GRIEF_PREVENTION -> griefPreventionEconomy.dataStore.getPlayerData(player.getUniqueId()).getBonusClaimBlocks();
default -> 0;
};
}

public static double prepareValue(double value) {
switch (economyType) {
case VAULT:
return value;
case PLAYER_POINTS:
case GRIEF_PREVENTION:
return Math.floor(value);
default:
return 0;
}
return switch (economyType) {
case VAULT -> value;
case PLAYER_POINTS, GRIEF_PREVENTION -> Math.floor(value);
default -> 0;
};
}

public enum EconomyType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.oheers.fish.fishing.items.Names;
import com.oheers.fish.fishing.items.Rarity;
import com.oheers.fish.gui.FillerStyle;
import com.oheers.fish.gui.SellGUI;
import com.oheers.fish.utils.AntiCraft;
import com.oheers.fish.utils.HeadDBIntegration;
import com.oheers.fish.utils.ItemFactory;
Expand Down Expand Up @@ -262,7 +261,7 @@ private void saveAdditionalDefaultAddons() {

for (final String fileName : Arrays.stream(DefaultAddons.values())
.map(DefaultAddons::getFullFileName)
.collect(Collectors.toList())) {
.toList()) {
final File addonFile = new File(getDataFolder(), "addons/" + fileName);
final File jarFile = new File(getDataFolder(), "addons/" + fileName.replace(".addon", ".jar"));
if (!jarFile.exists()) {
Expand Down Expand Up @@ -418,7 +417,7 @@ private void loadCommandManager() {
Optional<Rarity> potentialRarity = EvenMoreFish.getInstance().getFishCollection().keySet().stream()
.filter(rarity -> rarity.getValue().equalsIgnoreCase(rarityId))
.findFirst();
if (!potentialRarity.isPresent()) {
if (potentialRarity.isEmpty()) {
throw new InvalidCommandArgument("No such rarity: " + rarityId);
}

Expand All @@ -431,7 +430,7 @@ private void loadCommandManager() {
.filter(f -> f.getName().equalsIgnoreCase(fishId.replace("_", " ")) || f.getName().equalsIgnoreCase(fishId))
.findFirst();

if (!potentialFish.isPresent()) {
if (potentialFish.isEmpty()) {
throw new InvalidCommandArgument("No such fish: " + fishId);
}

Expand Down Expand Up @@ -853,8 +852,7 @@ public List<Player> getOnlinePlayersExcludingVanish() {
// Check Essentials
if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
Plugin plugin = Bukkit.getPluginManager().getPlugin("Essentials");
if (plugin instanceof Essentials) {
Essentials essentials = (Essentials) plugin;
if (plugin instanceof Essentials essentials) {
players = players.stream().filter(player -> !essentials.getUser(player).isVanished()).collect(Collectors.toList());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
import org.bukkit.block.Skull;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.profile.PlayerProfile;
import org.bukkit.profile.PlayerTextures;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.UUID;
Expand All @@ -44,7 +40,7 @@
public class FishUtils {

private static final Pattern HEX_PATTERN = Pattern.compile("&#" + "([A-Fa-f0-9]{6})");
private static final char COLOR_CHAR = '\u00A7';
private static final char COLOR_CHAR = '§';

// checks for the "emf-fish-name" nbt tag, to determine if this ItemStack is a fish or not.
public static boolean isFish(ItemStack item) {
Expand Down Expand Up @@ -270,7 +266,7 @@ public static String translateColorCodes(String message) {
}

Matcher matcher = HEX_PATTERN.matcher(message);
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
StringBuilder buffer = new StringBuilder(message.length() + 4 * 8);
while (matcher.find()) {
String group = matcher.group(1);
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import java.util.stream.Collectors;

public class AddonManager {
private static final String ADDON_FOLDER = "addons";
Expand Down Expand Up @@ -53,10 +52,9 @@ public ItemStack getItemStack(final String prefix, final String id) throws NoPre
}

final Addon addon = addonMap.get(prefix);
if (!(addon instanceof ItemAddon)) {
if (!(addon instanceof ItemAddon itemAddon)) {
return new ItemStack(Material.AIR);
}
ItemAddon itemAddon = (ItemAddon) addon;
return itemAddon.getItemStack(id);
}

Expand All @@ -76,8 +74,7 @@ public boolean registerAddon(final @NotNull Addon addon) {

this.loadingMap.put(prefix, false);
this.addonMap.put(prefix, addon);
if (addon instanceof Listener) {
Listener listener = (Listener) addon;
if (addon instanceof Listener listener) {
Bukkit.getPluginManager().registerEvents(listener, plugin);
}
return true;
Expand Down Expand Up @@ -107,8 +104,7 @@ public Optional<Addon> registerAddon(final @NotNull Class<? extends Addon> addon
return Optional.empty();
}

if (addonInstance instanceof Listener) {
final Listener listener = (Listener) addonInstance;
if (addonInstance instanceof Listener listener) {
Bukkit.getPluginManager().registerEvents(listener, plugin);
}

Expand Down Expand Up @@ -174,7 +170,7 @@ private void registerAll() {
.map(this::registerAddon)
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
.toList();


final String message = String.format("%s new addons registered! (%s total)", registered.size(), addonMap.keySet().size());
Expand All @@ -190,8 +186,7 @@ public void load() {
registerAll();

for (Map.Entry<String, Addon> entry : addonMap.entrySet()) {
if (entry.getValue() instanceof Listener) {
final Listener listener = (Listener) entry.getValue();
if (entry.getValue() instanceof Listener listener) {
Bukkit.getPluginManager().registerEvents(listener, plugin);
}
}
Expand Down
Loading

0 comments on commit 83094aa

Please sign in to comment.