Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise java version to 17 #7401

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/CONTRIBUTING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ If you do not agree with the terms of our license, do not contribute to the Town
> Towny uses an [.editorconfig](https://editorconfig.org) file. IDEs that have [native EditorConfig support](https://editorconfig.org/#pre-installed) will automatically follow these rules.

1. You must use tabs for indentation.
2. Keep your environment in Java 16-17. The code will automatically be converted into code compatible with Java 8 by [Jabel](https://github.com/bsideup/jabel).[^jabel-warning]
2. Keep your environment in Java 17.
3. Do not use wildcard imports.
4. Do not make unnecessary changes.[^changes]
- All IDEs are different, we do this to keep consistency in the codebase.
Expand Down Expand Up @@ -54,8 +54,6 @@ All translation on the core Towny plugin is done via [Crowdin](https://crowdin.c

Strings are formatted using [Java's `java.util.Formatter`](https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/util/Formatter.html) allowing specification of variable order, and more. This means that if you find that a line has multiple variables which would be in a different order in your language, you can change them to `%NUMBER$s` (replacing `NUMBER` with the variable index) to change their order.

[^jabel-warning]: Keep in mind that, while you will be able to use modern language features that way (like patterns), some standard library methods added after JDK 8 will not work **even after being processed** and cause "Cannot find symbol" errors when building (like `String#isBlank`).

[^changes]: This includes formatting and whitespace changes.

[^nms]: The `net.minecraft.server` is the Minecraft server source package. While this allows for "lower-level" coding, it's also pretty hard to maintain due to its obfuscation, no cross-version compatibility, and possibility to corrupt data.
39 changes: 2 additions & 37 deletions Towny/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
</organization>

<properties>
<java.version>17</java.version>
<project.bukkitAPIVersion>1.16</project.bukkitAPIVersion>
<skipTests>true</skipTests>
</properties>
Expand Down Expand Up @@ -170,12 +169,6 @@
<version>5.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.bsideup.jabel</groupId>
<artifactId>jabel-javac-plugin</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>solar.squares</groupId>
<artifactId>pixel-width-core</artifactId>
Expand Down Expand Up @@ -259,12 +252,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>8</release>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgs>
<arg>-Xplugin:jabel</arg>
</compilerArgs>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
Expand All @@ -288,7 +276,7 @@
</execution>
</executions>
<configuration>
<source>16</source>
<source>${java.version}</source>
<doclint>all,-missing</doclint>
<doctitle>Towny - ${project.version}</doctitle>
<groups>
Expand Down Expand Up @@ -466,28 +454,5 @@
<skipTests>false</skipTests>
</properties>
</profile>

<profile>
<id>intellij-idea-only</id>
<activation>
<property>
<name>idea.maven.embedder.version</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>${java.version}</release>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.palmergames.bukkit.towny;

import com.github.bsideup.jabel.Desugar;
import com.palmergames.bukkit.config.CommentedConfiguration;
import com.palmergames.bukkit.config.ConfigNodes;
import com.palmergames.bukkit.towny.db.DatabaseConfig;
Expand Down Expand Up @@ -63,7 +62,6 @@
public class TownySettings {

// Town Level
@Desugar
public record TownLevel(
String namePrefix,
String namePostfix,
Expand All @@ -80,7 +78,6 @@ public record TownLevel(
Map<String, Integer> townBlockTypeLimits) {}

// Nation Level
@Desugar
public record NationLevel(
String namePrefix,
String namePostfix,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.palmergames.bukkit.towny.confirmations;

import com.github.bsideup.jabel.Desugar;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.TownyEconomyHandler;
import com.palmergames.bukkit.towny.TownyMessaging;
Expand Down Expand Up @@ -30,7 +29,6 @@ public class ConfirmationHandler {
private final static Towny plugin = Towny.getPlugin();
private final static Map<CommandSender, ConfirmationContext> confirmations = new ConcurrentHashMap<>();

@Desugar
private record ConfirmationContext(Confirmation confirmation, ScheduledTask task) {}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.palmergames.bukkit.towny.db;

import com.github.bsideup.jabel.Desugar;
import com.palmergames.bukkit.towny.TownyMessaging;
import com.palmergames.bukkit.towny.TownySettings;
import com.palmergames.bukkit.towny.db.TownySQLSource.TownyDBTableType;
Expand Down Expand Up @@ -402,7 +401,6 @@ private static void dropColumn(Connection cntx, String table, String column) {
}
}

@Desugar
private record ColumnUpdate(String table, String column) {
private static ColumnUpdate update(String table, String column) {
return new ColumnUpdate(SQLSchema.TABLE_PREFIX + table, column);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2525,7 +2525,6 @@ public CompletableFuture<Optional<Long>> getHibernatedResidentRegistered(UUID uu
});
}

@SuppressWarnings("ReadWriteStringCanBeUsed")
@Override
public boolean loadCooldowns() {
final Path cooldownsFile = Paths.get(dataFolderPath).resolve("cooldowns.json");
Expand All @@ -2534,7 +2533,7 @@ public boolean loadCooldowns() {

final String data;
try {
data = new String(Files.readAllBytes(cooldownsFile), StandardCharsets.UTF_8);
data = Files.readString(cooldownsFile);
} catch (IOException e) {
plugin.getLogger().log(Level.WARNING, "An exception occurred when reading cooldowns.json", e);
return true;
Expand All @@ -2549,7 +2548,6 @@ public boolean loadCooldowns() {
return true;
}

@SuppressWarnings("ReadWriteStringCanBeUsed")
@Override
public boolean saveCooldowns() {
final JsonObject object = new JsonObject();
Expand All @@ -2559,7 +2557,7 @@ public boolean saveCooldowns() {

this.queryQueue.add(() -> {
try {
Files.write(Paths.get(dataFolderPath).resolve("cooldowns.json"), new GsonBuilder().setPrettyPrinting().create().toJson(object).getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
Files.writeString(Paths.get(dataFolderPath).resolve("cooldowns.json"), new GsonBuilder().setPrettyPrinting().create().toJson(object), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException e) {
plugin.getLogger().log(Level.WARNING, "An exception occurred when writing cooldowns.json", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ public void finishTasks() {
* @return true if we successfully connected to the db.
* @deprecated as of 0.99.1.2, use {@link #getConnection()} to obtain a connection instead.
*/
@Deprecated
@SuppressWarnings("RedundantScheduledForRemovalAnnotation") // The forRemoval = true attribute did not exist in java 8
@ApiStatus.ScheduledForRemoval
@Deprecated(forRemoval = true)
public boolean getContext() {
return isReady();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.palmergames.bukkit.towny.hooks;

import com.github.bsideup.jabel.Desugar;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.TownySettings;
Expand Down Expand Up @@ -107,6 +106,5 @@ public ContextSet estimatePotentialContexts() {
return builder.build();
}

@Desugar
private record Calculator(String context, Function<Resident, Iterable<String>> function, Supplier<Iterable<String>> suggestions) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -920,15 +920,14 @@ private boolean entityProtectedFromExplosiveDamageHere(Entity entity, DamageCaus
map.put("damage_resistance", "resistance");
});

@SuppressWarnings("SimplifyStreamApiCallChains")
private boolean hasDetrimentalEffects(Collection<PotionEffect> effects) {
if (effects.isEmpty())
return false;

/*
* List of potion effects blocked from PvP.
*/
final List<String> detrimentalPotions = TownySettings.getPotionTypes().stream().map(type -> type.toLowerCase(Locale.ROOT)).collect(Collectors.toList());
final List<String> detrimentalPotions = TownySettings.getPotionTypes().stream().map(type -> type.toLowerCase(Locale.ROOT)).toList();

return effects.stream()
.map(effect -> BukkitTools.potionEffectName(effect.getType()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;
import java.util.Map;

import com.github.bsideup.jabel.Desugar;
import com.palmergames.bukkit.towny.TownyCommandAddonAPI.CommandType;

import com.palmergames.util.StringMgmt;
Expand Down Expand Up @@ -116,7 +115,6 @@ public List<String> getTabCompletion(CommandSender sender, String[] args) {
return tabCompleter.onTabComplete(sender, this, this.name, StringMgmt.remFirstArg(args));
}

@Desugar
private record LegacyTabCompleter(AddonCommand command) implements TabCompleter {
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.github.bsideup.jabel.Desugar;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.TownySettings;
import com.palmergames.bukkit.towny.utils.BorderUtil;
Expand All @@ -30,7 +29,6 @@ public static CellSurface getCellSurface(WorldCoord worldCoord) {
return new CellSurface(worldCoord);
}

@Desugar
private record BlockPos(int x, int z) {}

public void runClaimingParticleOverSurfaceAtPlayer(Player player) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.palmergames.bukkit.towny.object;

import com.github.bsideup.jabel.Desugar;

import java.util.Collection;

/**
Expand All @@ -13,5 +11,4 @@
* @param nextVersionIndex The line index of where the first version changelog for the first version after the last version starts.
* @param totalSize The total line count of the changelog.
*/
@Desugar
public record ChangelogResult(Collection<String> lines, boolean successful, boolean limitReached, int nextVersionIndex, int totalSize) {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import com.github.bsideup.jabel.Desugar;
import org.bukkit.Location;
import org.bukkit.Particle;

Expand Down Expand Up @@ -104,7 +103,6 @@ public enum SpawnPointType {
JAIL_SPAWN
}

@Desugar
private record RingCoord(double x, double z) {
private static RingCoord offset(double a, double b) {
return new RingCoord(a, b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.bukkit.Particle;
import org.bukkit.World;

import com.github.bsideup.jabel.Desugar;
import com.palmergames.bukkit.towny.Towny;

public class TeleportWarmupParticle {
Expand Down Expand Up @@ -55,7 +54,6 @@ private static List<RingCoord> createRingOffsets() {
return ring;
}

@Desugar
private record RingCoord(double x, double z) {
private static RingCoord offset(double a, double b) {
return new RingCoord(a, b);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.palmergames.bukkit.towny.object;

import com.github.bsideup.jabel.Desugar;
import com.palmergames.bukkit.config.CommentedConfiguration;
import com.palmergames.bukkit.config.ConfigNodes;
import com.palmergames.bukkit.towny.Towny;
Expand Down Expand Up @@ -241,7 +240,6 @@ public static void migrate() {
migrations.clear();
}

@Desugar
private record Migration(String type, String key, Object value) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private void saveReferenceFile(String lang, String defaultLangContent, String co
if (defaultLangContent == null || lang.equals("en-US")) {
try (Stream<String> lines = Files.lines(langPath)) {
if (!content.equals(lines.collect(Collectors.joining("\n"))))
FileMgmt.writeString(langPath, content);
Files.writeString(langPath, content);
}

return;
Expand Down Expand Up @@ -270,7 +270,7 @@ private void saveReferenceFile(String lang, String defaultLangContent, String co
}
}

FileMgmt.writeString(langPath, String.join("\n", list));
Files.writeString(langPath, String.join("\n", list));
} catch (IOException e) {
plugin.getLogger().log(Level.WARNING, "Failed to copy " + "'/lang/" + lang + ".yml'" + " from the JAR to '" + langPath.toAbsolutePath() + "' during a reference language file update.", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.palmergames.bukkit.towny.utils;

import com.github.bsideup.jabel.Desugar;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.CellBorder;
import com.palmergames.bukkit.towny.object.Resident;
Expand Down Expand Up @@ -257,7 +256,6 @@ public static boolean allowedMove(Block block, Block blockTo, @Nullable Player p
return FloodfillResult.success(valid);
}

@Desugar
public record FloodfillResult(@NotNull Type type, @Nullable Translatable feedback, @NotNull Collection<WorldCoord> coords) {
public enum Type {
SUCCESS,
Expand Down
Loading
Loading