Skip to content

Commit abe5d0c

Browse files
committed
Add Folia support
Closes #54 Co-authored-by: yLeoft <maehara.leonardo@gmail.com>
1 parent e2a98fd commit abe5d0c

20 files changed

Lines changed: 252 additions & 129 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
java-version: [ 8, 11, 17 ]
15+
java-version: [ 17 ]
1616

1717
steps:
1818
- name: Checkout repository

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ WorldEditSelectionVisualizer (WESV) is essentially the famous [WorldEditCUI](htt
2020
- Compatible with all Minecraft versions starting with 1.7.10
2121
- Support for RGB color codes in messages on Minecraft 1.16 and higher, with the `&#rrggbb` format
2222
- [PlaceholderAPI](https://github.com/PlaceholderAPI/PlaceholderAPI) support (you can use the placeholders `%wesv_toggled_selection%`, `%wesv_toggled_clipboard%`, `%wesv_volume_selection%` and `%wesv_volume_clipboard%`)
23+
- [Folia](https://github.com/PaperMC/Folia) support for better performance
2324

2425
## Downloads
2526

build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
allprojects {
22
group = 'fr.mrmicky'
3-
version = '2.1.8'
3+
version = '2.1.9'
44
}
55

66
subprojects {
@@ -9,6 +9,8 @@ subprojects {
99
java {
1010
sourceCompatibility = JavaVersion.VERSION_1_8
1111
targetCompatibility = JavaVersion.VERSION_1_8
12+
13+
disableAutoTargetJvm()
1214
}
1315

1416
tasks.withType(JavaCompile) {
@@ -18,12 +20,12 @@ subprojects {
1820
repositories {
1921
mavenCentral()
2022

21-
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
22-
maven { url 'https://maven.enginehub.org/repo/' }
23+
maven { url = 'https://repo.papermc.io/repository/maven-public/' }
24+
maven { url = 'https://maven.enginehub.org/repo/' }
2325
}
2426

2527
dependencies {
2628
implementation 'org.jspecify:jspecify:1.0.0'
27-
compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
29+
compileOnly 'dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT'
2830
}
2931
}

compatibility/commons/src/main/java/fr/mrmicky/worldeditselectionvisualizer/math/Vector3d.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.mrmicky.worldeditselectionvisualizer.math;
22

3+
import org.bukkit.Location;
34
import org.bukkit.util.Vector;
45
import org.jspecify.annotations.NullMarked;
56

@@ -12,6 +13,10 @@ public class Vector3d {
1213
private final double y;
1314
private final double z;
1415

16+
public Vector3d(Location loc) {
17+
this(loc.getX(), loc.getY(), loc.getZ());
18+
}
19+
1520
public Vector3d(Vector vec) {
1621
this(vec.getX(), vec.getY(), vec.getZ());
1722
}

plugin/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ plugins {
33
}
44

55
repositories {
6-
maven { url 'https://jitpack.io' }
7-
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
6+
maven { url = 'https://jitpack.io' }
7+
maven { url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
88
}
99

1010
dependencies {

plugin/src/main/java/fr/mrmicky/worldeditselectionvisualizer/WorldEditSelectionVisualizer.java

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.sk89q.worldedit.regions.Region;
44
import fr.mrmicky.worldeditselectionvisualizer.commands.CommandWesv;
55
import fr.mrmicky.worldeditselectionvisualizer.compat.CompatibilityHelper;
6+
import fr.mrmicky.worldeditselectionvisualizer.compat.ScheduledTask;
7+
import fr.mrmicky.worldeditselectionvisualizer.compat.SchedulerAdapter;
68
import fr.mrmicky.worldeditselectionvisualizer.config.ConfigurationManager;
79
import fr.mrmicky.worldeditselectionvisualizer.config.GlobalSelectionConfig;
810
import fr.mrmicky.worldeditselectionvisualizer.display.DisplayType;
@@ -16,47 +18,45 @@
1618
import fr.mrmicky.worldeditselectionvisualizer.utils.ChatUtils;
1719
import org.bukkit.entity.Player;
1820
import org.bukkit.plugin.java.JavaPlugin;
19-
import org.bukkit.scheduler.BukkitTask;
20-
import org.jspecify.annotations.NonNull;
21+
import org.jspecify.annotations.NullMarked;
2122

2223
import java.io.BufferedReader;
23-
import java.io.File;
2424
import java.io.IOException;
2525
import java.io.InputStreamReader;
2626
import java.net.URI;
2727
import java.net.URL;
2828
import java.util.*;
29+
import java.util.concurrent.ConcurrentHashMap;
2930

31+
@NullMarked
3032
public final class WorldEditSelectionVisualizer extends JavaPlugin {
3133

3234
private final Map<SelectionType, GlobalSelectionConfig> configurations = new EnumMap<>(SelectionType.class);
33-
private final Map<UUID, PlayerVisualizerData> players = new HashMap<>();
34-
private final List<BukkitTask> particlesTasks = new ArrayList<>(6);
35+
private final Map<UUID, PlayerVisualizerData> players = new ConcurrentHashMap<>();
36+
private final List<ScheduledTask> particlesTasks = new ArrayList<>(6);
3537

36-
private SelectionManager selectionManager;
37-
private StorageManager storageManager;
38-
private ConfigurationManager configurationManager;
39-
private CompatibilityHelper compatibilityHelper;
38+
private final SelectionManager selectionManager = new SelectionManager(this);
39+
private final StorageManager storageManager = new StorageManager(this);
40+
private final ConfigurationManager configurationManager = new ConfigurationManager(this);
41+
private final CompatibilityHelper compatibilityHelper = new CompatibilityHelper(this);
4042

4143
@Override
4244
public void onEnable() {
4345
saveDefaultConfig();
44-
migrateV1Config();
4546

46-
this.compatibilityHelper = new CompatibilityHelper(this);
47-
this.storageManager = new StorageManager(this);
48-
this.configurationManager = new ConfigurationManager(this);
49-
this.selectionManager = new SelectionManager(this);
47+
this.compatibilityHelper.init();
48+
this.storageManager.init();
49+
this.selectionManager.init();
50+
51+
getLogger().info("Using WorldEdit " + this.compatibilityHelper.getWorldEditVersion() + " api");
52+
getLogger().info("Using " + this.getScheduler().name() + " scheduler");
5053

5154
if (this.compatibilityHelper.getWorldEditVersion() == 7) {
5255
try {
5356
Region.class.getMethod("getVolume");
5457
} catch (NoSuchMethodException e) {
55-
getLogger().severe("**********************************");
56-
getLogger().severe("You are using an unsupported WorldEdit version (7.0.x or 7.1.x)!");
57-
getLogger().severe("WorldEditSelection visualizer doesn't works with outdated WorldEdit version.");
58-
getLogger().severe("You can download the latest WorldEdit version here: https://dev.bukkit.org/projects/worldedit/files");
59-
getLogger().severe("**********************************");
58+
getLogger().severe("You are using an unsupported WorldEdit version (7.0.x or 7.1.x)");
59+
getLogger().severe("Please update WorldEdit: https://dev.bukkit.org/projects/worldedit/files");
6060
getServer().getPluginManager().disablePlugin(this);
6161
return;
6262
}
@@ -74,25 +74,21 @@ public void onEnable() {
7474
}
7575

7676
if (getConfig().getBoolean("check-updates")) {
77-
getServer().getScheduler().runTaskAsynchronously(this, this::checkUpdate);
77+
getScheduler().executeAsync(this::checkUpdate);
7878
}
7979
}
8080

8181
@Override
8282
public void reloadConfig() {
8383
super.reloadConfig();
8484

85-
if (this.configurationManager != null) {
86-
loadConfig();
87-
}
85+
loadConfig();
8886

89-
if (this.compatibilityHelper != null) {
90-
this.compatibilityHelper.init();
91-
}
87+
this.compatibilityHelper.init();
9288
}
9389

9490
private void loadConfig() {
95-
this.particlesTasks.forEach(BukkitTask::cancel);
91+
this.particlesTasks.forEach(ScheduledTask::cancel);
9692
this.particlesTasks.clear();
9793

9894
for (SelectionType type : SelectionType.values()) {
@@ -107,15 +103,11 @@ private void loadConfig() {
107103
}
108104
}
109105

110-
public void updateHoldingSelectionItem(@NonNull PlayerVisualizerData playerData) {
106+
public void updateHoldingSelectionItem(PlayerVisualizerData playerData) {
111107
playerData.setHoldingSelectionItem(this.compatibilityHelper.isHoldingSelectionItem(playerData.getPlayer()));
112108
}
113109

114-
public void loadPlayer(@NonNull Player player) {
115-
if (this.players.containsKey(player.getUniqueId())) {
116-
return;
117-
}
118-
110+
public void loadPlayer(Player player) {
119111
PlayerVisualizerData playerData = new PlayerVisualizerData(player);
120112

121113
for (SelectionType type : SelectionType.values()) {
@@ -125,14 +117,14 @@ public void loadPlayer(@NonNull Player player) {
125117

126118
updateHoldingSelectionItem(playerData);
127119

128-
this.players.put(player.getUniqueId(), playerData);
120+
this.players.putIfAbsent(player.getUniqueId(), playerData);
129121
}
130122

131-
public void unloadPlayer(@NonNull Player player) {
123+
public void unloadPlayer(Player player) {
132124
this.players.remove(player.getUniqueId());
133125
}
134126

135-
public @NonNull PlayerVisualizerData getPlayerData(Player player) {
127+
public PlayerVisualizerData getPlayerData(Player player) {
136128
PlayerVisualizerData playerData = this.players.get(player.getUniqueId());
137129

138130
if (playerData == null) {
@@ -142,11 +134,11 @@ public void unloadPlayer(@NonNull Player player) {
142134
return playerData;
143135
}
144136

145-
public @NonNull Optional<PlayerVisualizerData> getOptionalPlayerData(Player player) {
137+
public Optional<PlayerVisualizerData> getOptionalPlayerData(Player player) {
146138
return Optional.ofNullable(this.players.get(player.getUniqueId()));
147139
}
148140

149-
public @NonNull Collection<PlayerVisualizerData> getPlayers() {
141+
public Collection<PlayerVisualizerData> getPlayers() {
150142
return this.players.values();
151143
}
152144

@@ -170,35 +162,27 @@ public String getMessage(String path) {
170162
return ChatUtils.color(getConfig().getString("messages." + path));
171163
}
172164

165+
public SchedulerAdapter getScheduler() {
166+
return this.compatibilityHelper.getScheduler();
167+
}
168+
169+
@SuppressWarnings("deprecation") // Ignore Paper-specific deprecations (for compatibility)
170+
public String getPluginVersion() {
171+
return getDescription().getVersion();
172+
}
173+
173174
private void checkUpdate() {
174175
try {
175176
URL url = URI.create("https://api.spigotmc.org/legacy/update.php?resource=17311").toURL();
176177
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
177178
String lastVersion = reader.readLine();
178-
if (!getDescription().getVersion().equalsIgnoreCase(lastVersion)) {
179-
getLogger().warning("A new version is available. Last version is " + lastVersion + " and you are on " + getDescription().getVersion());
180-
getLogger().warning("You can download it on " + getDescription().getWebsite());
179+
if (!getPluginVersion().equalsIgnoreCase(lastVersion)) {
180+
getLogger().warning("A new version is available. Last version is " + lastVersion + " and you are on " + getPluginVersion());
181+
getLogger().warning("You can download it on https://www.spigotmc.org/resources/worldeditselectionvisualizer.17311/");
181182
}
182183
}
183184
} catch (IOException e) {
184185
getLogger().warning("Unable to check for updates: " + e.getMessage());
185186
}
186187
}
187-
188-
private void migrateV1Config() {
189-
if (getConfig().get("lang") == null) {
190-
return;
191-
}
192-
193-
// Rename the config from WorldEditSelectionVisualizer v1.x to prevent any issues
194-
File configFile = new File(getDataFolder(), "config.yml");
195-
File configBackupFile = new File(getDataFolder(), "config-old.yml");
196-
197-
if (!configFile.renameTo(configBackupFile)) {
198-
getLogger().warning("Unable to rename old config.yml file.");
199-
}
200-
201-
saveDefaultConfig();
202-
reloadConfig();
203-
}
204188
}

plugin/src/main/java/fr/mrmicky/worldeditselectionvisualizer/commands/CommandWesv.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private void handleLock(Player player, String[] args) {
144144
return;
145145
}
146146

147-
player.teleport(location);
147+
this.plugin.getScheduler().teleport(player, location);
148148
return;
149149
}
150150

@@ -160,7 +160,7 @@ private void handleLock(Player player, String[] args) {
160160
}
161161

162162
private void sendUsage(CommandSender sender) {
163-
String version = this.plugin.getDescription().getVersion();
163+
String version = this.plugin.getPluginVersion();
164164
sender.sendMessage(ChatUtils.color("&6WorldEditSelectionVisualizer v" + version + "&7 by &6MrMicky&7."));
165165

166166
if (sender instanceof Player) {

plugin/src/main/java/fr/mrmicky/worldeditselectionvisualizer/compat/CompatibilityHelper.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class CompatibilityHelper {
3030

3131
private final WorldEditSelectionVisualizer plugin;
3232

33+
private final SchedulerAdapter scheduler;
3334
private final boolean supportOffHand = isOffhandSupported();
3435
private final boolean supportActionBar = isActionBarSupported();
3536
private final boolean worldEdit7 = isWorldEdit7();
@@ -38,10 +39,7 @@ public class CompatibilityHelper {
3839

3940
public CompatibilityHelper(WorldEditSelectionVisualizer plugin) {
4041
this.plugin = plugin;
41-
42-
plugin.getLogger().info("Using WorldEdit " + getWorldEditVersion() + " api");
43-
44-
init();
42+
this.scheduler = SchedulerAdapter.create(this.plugin);
4543
}
4644

4745
public void init() {
@@ -69,6 +67,10 @@ public void init() {
6967
}
7068
}
7169

70+
public SchedulerAdapter getScheduler() {
71+
return this.scheduler;
72+
}
73+
7274
public RegionAdapter adaptRegion(Region region) {
7375
return this.worldEdit7 ? new RegionAdapter7(region) : new RegionAdapter6(region);
7476
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package fr.mrmicky.worldeditselectionvisualizer.compat;
2+
3+
public interface ScheduledTask {
4+
void cancel();
5+
}

0 commit comments

Comments
 (0)