Skip to content

Commit

Permalink
Release 2.4.0 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs authored Dec 21, 2023
2 parents 011813d + ec67c10 commit 6ed41e6
Show file tree
Hide file tree
Showing 32 changed files with 500 additions and 400 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4
- name: Set up JDK 8
uses: actions/setup-java@v2
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 8
java-version: 11
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew --build-cache shadowJar
- name: Test with Gradle
run: ./gradlew test
run: ./gradlew test
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.gradle
**/build/
!src/**/build/
gradle.properties

# Ignore Gradle GUI configuration
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# User-specific stuff
.idea/
*.iml

# CMake
cmake-build-*/

# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
7 changes: 2 additions & 5 deletions LandLordMap-bluemap/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
plugins {
id("biz.princeps.java-conventions")
id("com.github.johnrengelman.shadow") version "7.0.0"
id("com.github.johnrengelman.shadow") version "8.1.1"
}

dependencies {
implementation(project(":LandLordMap-core"))
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
compileOnly("biz.princeps:landlord-core:4.360")
compileOnly("de.eldoria:eldo-util:1.11.0-DEV")
compileOnly("com.github.BlueMap-Minecraft:BlueMapAPI:v1.7.0")
}

Expand Down Expand Up @@ -40,4 +37,4 @@ tasks {
events("passed", "skipped", "failed")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,39 @@

public class LLBlueMap extends JavaPlugin {

ILandLord landLordAPI;
Configuration configuration;
BlueMapIntegration blueMapIntegration;
private ILandLord landLordAPI;
private Configuration configuration;
private BlueMapIntegration blueMapIntegration;

@Override
public void onEnable() {
logToConsole(Level.INFO, "Loading configuration...");
getLogger().info( "Loading configuration...");
saveDefaultConfig();
configuration = new Configuration(this);

blueMapIntegration = new BlueMapIntegration(this);

final PluginManager pluginManager = Bukkit.getPluginManager();
logToConsole(Level.INFO, "Loading listeners...");
PluginManager pluginManager = getServer().getPluginManager();
getLogger().info("Loading listeners...");
pluginManager.registerEvents(new LandlordListener(this, blueMapIntegration), this);

logToConsole(Level.INFO, "Loading commands...");
getLogger().info( "Loading commands...");
PrincepsLib.getCommandManager().registerCommand(new Commands(this));

logToConsole(Level.INFO, "Loading APIs...");
getLogger().info( "Loading APIs...");
landLordAPI = (ILandLord) pluginManager.getPlugin("Landlord");

BlueMapAPI.onEnable(blueMapAPI -> {
logToConsole(Level.INFO, "BlueMap integration is initializing...");
getLogger().info( "BlueMap integration is initializing...");
blueMapIntegration.hookBlueMap(blueMapAPI);
logToConsole(Level.INFO, "BlueMap integration has been successfully enabled/reloaded!");
getLogger().info( "BlueMap integration has been successfully enabled/reloaded!");
});
}

@Override
public void onDisable() {
BlueMapAPI.getInstance().ifPresent(blueMapAPI -> blueMapIntegration.unhookBlueMap(blueMapAPI));
logToConsole(Level.INFO, "Thank you :)");
}

public void logToConsole(Level level, String message) {
Bukkit.getLogger().log(level, "[" + getName() + "] " + message);
getLogger().info("Thank you :)");
}

public Configuration getConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void onCommand(Properties properties, Arguments arguments) {
plugin.reloadConfig();
plugin.getConfiguration().load();

final Optional<BlueMapAPI> optionalBlueMapAPI = BlueMapAPI.getInstance();
Optional<BlueMapAPI> optionalBlueMapAPI = BlueMapAPI.getInstance();
if (optionalBlueMapAPI.isPresent()) {
plugin.getBlueMapIntegration().hookBlueMap(optionalBlueMapAPI.get());
properties.sendMessage("§aConfig successfully reloaded!");
Expand All @@ -35,4 +35,4 @@ public void onCommand(Properties properties, Arguments arguments) {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public Commands(LLBlueMap plugin) {
plugin.getConfig().getStringList("CommandSettings.Main.aliases").toArray(new String[]{}));
this.plugin = plugin;

this.addSubcommand(new CommandReload(plugin));
addSubcommand(new CommandReload(plugin));
}

@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
final List<String> completions = new ArrayList<>();
List<String> completions = new ArrayList<>();

if (args.length == 1) {
subCommandMap.forEach((name, subCommand) -> {
Expand All @@ -45,4 +45,4 @@ public List<String> tabComplete(CommandSender sender, String alias, String[] arg
public void onCommand(Properties properties, Arguments arguments) {
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Configuration(LLBlueMap plugin) {
}

public void load() {
final FileConfiguration config = plugin.getConfig();
FileConfiguration config = plugin.getConfig();

updateTaskFrequency = config.getLong("update-task-frequency");
maxProcessedPerUpdate = config.getInt("max-processed-per-update");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class BlueMapIntegration {

public BlueMapIntegration(LLBlueMap plugin) {
this.plugin = plugin;
this.config = plugin.getConfiguration();
config = plugin.getConfiguration();

this.queue = new ConcurrentHashMap<>();
queue = new ConcurrentHashMap<>();
}

private MarkerSet buildMarkerSet(MarkerAPI markerAPI) {
Expand All @@ -42,51 +42,51 @@ private MarkerSet buildMarkerSet(MarkerAPI markerAPI) {
public void hookBlueMap(BlueMapAPI blueMapAPI) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, bukkitTask -> {
try {
final MarkerAPI markerAPI = blueMapAPI.getMarkerAPI();
plugin.logToConsole(Level.INFO, "Loading Landlord markers...");
MarkerAPI markerAPI = blueMapAPI.getMarkerAPI();
plugin.getLogger().info("Loading Landlord markers...");

final MarkerSet markerSet = buildMarkerSet(markerAPI);
final int size = markerSet.getMarkers().size();
MarkerSet markerSet = buildMarkerSet(markerAPI);
int size = markerSet.getMarkers().size();

plugin.logToConsole(Level.INFO, "Updating Landlord markers...");
plugin.getLogger().info("Updating Landlord markers...");
markerSet.setLabel(config.getMarkerSetLabel());
markerSet.setDefaultHidden(config.isMarkerSetDefaultHidden());
markerSet.setToggleable(config.isMarkerSetToggleable());

if (size == 0) {
plugin.logToConsole(Level.WARNING, "Landlord markers not found!");
plugin.getLogger().warning("Landlord markers not found!");
importLands(blueMapAPI, markerAPI, markerSet);
} else {
plugin.logToConsole(Level.INFO, size + " Landlord markers found!");
plugin.getLogger().info(size + " Landlord markers found!");
markerAPI.save();
}
plugin.logToConsole(Level.INFO, "Loading update task...");
plugin.getLogger().info("Loading update task...");
initUpdateTask();
} catch (IOException e) {
e.printStackTrace();
plugin.getLogger().log(Level.SEVERE, "Could not retrieve marker api", e);
}
});
}

public void unhookBlueMap(BlueMapAPI blueMapAPI) {
try {
updateTask.cancel();
final MarkerAPI markerAPI = blueMapAPI.getMarkerAPI();
MarkerAPI markerAPI = blueMapAPI.getMarkerAPI();

final Set<IOwnedLand> ownedLands = plugin.getLandLordAPI().getWGManager().getRegions();
plugin.logToConsole(Level.WARNING, "Checking " + ownedLands.size() + " lands and processing " + queue.size() + " remaining updates, this could take a while...");
Set<IOwnedLand> ownedLands = plugin.getLandLordAPI().getWGManager().getRegions();
plugin.getLogger().warning("Checking " + ownedLands.size() + " lands and processing " + queue.size() + " remaining updates, this could take a while...");

for (IOwnedLand ownedLand : plugin.getLandLordAPI().getWGManager().getRegions()) {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(ownedLand.getOwner());
final Instant lastPlayed = Instant.ofEpochMilli(offlinePlayer.getLastPlayed());
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(ownedLand.getOwner());
Instant lastPlayed = Instant.ofEpochMilli(offlinePlayer.getLastPlayed());

if (lastPlayed.isBefore(Instant.now().minus(config.getMarkerSetLifetime(), ChronoUnit.DAYS))) {
enqueueLand(ownedLand, UpdateReason.UNCLAIM);
}
}
processQueue(blueMapAPI, markerAPI, buildMarkerSet(markerAPI), Integer.MAX_VALUE);
} catch (IOException e) {
e.printStackTrace();
plugin.getLogger().log(Level.SEVERE, "Could not retrieve marker api", e);
}
}

Expand All @@ -97,17 +97,17 @@ public void initUpdateTask() {
updateTask = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () ->
BlueMapAPI.getInstance().ifPresent(blueMapAPI -> {
try {
final MarkerAPI markerAPI = blueMapAPI.getMarkerAPI();
MarkerAPI markerAPI = blueMapAPI.getMarkerAPI();
processQueue(blueMapAPI, markerAPI, buildMarkerSet(markerAPI), config.getMaxProcessedPerUpdate());
} catch (IOException e) {
e.printStackTrace();
plugin.getLogger().log(Level.SEVERE, "Could not retrieve marker api", e);
}
}), config.getUpdateTaskFrequency(), config.getUpdateTaskFrequency());
}

private void importLands(BlueMapAPI blueMapAPI, MarkerAPI markerAPI, MarkerSet markerSet) {
final Set<IOwnedLand> ownedLands = plugin.getLandLordAPI().getWGManager().getRegions();
plugin.logToConsole(Level.WARNING, "Importing " + ownedLands.size() + " lands, this could take a while...");
Set<IOwnedLand> ownedLands = plugin.getLandLordAPI().getWGManager().getRegions();
plugin.getLogger().warning("Importing " + ownedLands.size() + " lands, this could take a while...");

// final BlueMapIsland blueMapIsland = new BlueMapIsland(plugin, plugin.getLandLordAPI().getWGManager().getRegion("world_1429_-2113"));
//
Expand Down Expand Up @@ -145,8 +145,8 @@ private void importLands(BlueMapAPI blueMapAPI, MarkerAPI markerAPI, MarkerSet m
// }

for (IOwnedLand ownedLand : plugin.getLandLordAPI().getWGManager().getRegions()) {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(ownedLand.getOwner());
final Instant lastPlayed = Instant.ofEpochMilli(offlinePlayer.getLastPlayed());
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(ownedLand.getOwner());
Instant lastPlayed = Instant.ofEpochMilli(offlinePlayer.getLastPlayed());

if (lastPlayed.isAfter(Instant.now().minus(config.getMarkerSetLifetime(), ChronoUnit.DAYS))) {
enqueueLand(ownedLand, UpdateReason.CLAIM);
Expand All @@ -157,20 +157,15 @@ private void importLands(BlueMapAPI blueMapAPI, MarkerAPI markerAPI, MarkerSet m
}

public void enqueueLand(IOwnedLand ownedLand, UpdateReason updateReason) {
if (ownedLand == null || ownedLand.getOwner() == null)
return;
if (ownedLand == null || ownedLand.getOwner() == null) return;

queue.compute(ownedLand, (queuedOwnedLand, queuedUpdateReason) -> {
if (queuedUpdateReason == null) {
return updateReason;
}
if (queuedUpdateReason == null) return updateReason;

switch (queuedUpdateReason) {
case CLAIM:
case UNCLAIM:
if (updateReason == UpdateReason.MANAGE) {
return queuedUpdateReason;
}
if (updateReason == UpdateReason.MANAGE) return queuedUpdateReason;
default:
return updateReason;
}
Expand All @@ -181,21 +176,21 @@ private void processQueue(BlueMapAPI blueMapAPI, MarkerAPI markerAPI, MarkerSet
int iterations = 0;

for (Iterator<Map.Entry<IOwnedLand, UpdateReason>> iterator = queue.entrySet().iterator(); iterator.hasNext() && iterations < limit; ) {
final Map.Entry<IOwnedLand, UpdateReason> entry = iterator.next();
Map.Entry<IOwnedLand, UpdateReason> entry = iterator.next();

new BlueMapLand(plugin, entry.getKey()).process(blueMapAPI, markerSet, entry.getValue());

iterator.remove();
iterations++;
}

if (iterations == 0)
return;
if (iterations == 0) return;

try {
markerAPI.save();
} catch (IOException e) {
e.printStackTrace();
plugin.getLogger().log(Level.SEVERE, "Could not save to marker api", e);
}
}

}
}
Loading

0 comments on commit 6ed41e6

Please sign in to comment.