mirror of
https://github.com/Artillex-Studios/AxTrade.git
synced 2025-01-04 18:47:51 +01:00
1.6.0
This commit is contained in:
parent
f87014c2f3
commit
46ac53683d
6
pom.xml
6
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.artillexstudios</groupId>
|
||||
<artifactId>AxTrade</artifactId>
|
||||
<version>1.5.1</version>
|
||||
<version>1.6.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>AxTrade</name>
|
||||
@ -112,7 +112,7 @@
|
||||
<dependency>
|
||||
<groupId>com.artillexstudios.axapi</groupId>
|
||||
<artifactId>axapi</artifactId>
|
||||
<version>1.4.242</version>
|
||||
<version>1.4.259</version>
|
||||
<scope>compile</scope>
|
||||
<classifier>all</classifier>
|
||||
</dependency>
|
||||
@ -125,7 +125,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.triumphteam</groupId>
|
||||
<artifactId>triumph-gui</artifactId>
|
||||
<version>3.1.7</version>
|
||||
<version>3.1.10</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -18,6 +18,7 @@ import com.artillexstudios.axtrade.listeners.PlayerInteractEntityListener;
|
||||
import com.artillexstudios.axtrade.listeners.TradeListeners;
|
||||
import com.artillexstudios.axtrade.trade.TradeTicker;
|
||||
import com.artillexstudios.axtrade.utils.NumberUtils;
|
||||
import com.artillexstudios.axtrade.utils.UpdateNotifier;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -73,5 +74,7 @@ public final class AxTrade extends AxPlugin {
|
||||
Commands.registerCommand();
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(StringUtils.formatToString("�FFDD[AxTrade] Loaded plugin!"));
|
||||
|
||||
if (CONFIG.getBoolean("update-notifier.enabled", true)) new UpdateNotifier(this, 5943);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.artillexstudios.axtrade.commands;
|
||||
|
||||
import com.artillexstudios.axapi.nms.NMSHandlers;
|
||||
import com.artillexstudios.axapi.utils.FastFieldAccessor;
|
||||
import com.artillexstudios.axapi.reflection.FastFieldAccessor;
|
||||
import com.artillexstudios.axapi.utils.StringUtils;
|
||||
import com.artillexstudios.axtrade.AxTrade;
|
||||
import com.artillexstudios.axtrade.hooks.HookManager;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.artillexstudios.axtrade.utils;
|
||||
|
||||
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.block.implementation.Section;
|
||||
import com.artillexstudios.axapi.utils.ClassUtils;
|
||||
import com.artillexstudios.axapi.reflection.ClassUtils;
|
||||
import com.artillexstudios.axapi.utils.ItemBuilder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.artillexstudios.axtrade.utils;
|
||||
|
||||
import com.artillexstudios.axapi.utils.ClassUtils;
|
||||
import com.artillexstudios.axapi.reflection.ClassUtils;
|
||||
import org.bukkit.block.Barrel;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -0,0 +1,101 @@
|
||||
package com.artillexstudios.axtrade.utils;
|
||||
|
||||
import com.artillexstudios.axapi.AxPlugin;
|
||||
import com.artillexstudios.axapi.scheduler.Scheduler;
|
||||
import com.artillexstudios.axapi.utils.NumberUtils;
|
||||
import com.artillexstudios.axapi.utils.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static com.artillexstudios.axtrade.AxTrade.CONFIG;
|
||||
import static com.artillexstudios.axtrade.AxTrade.LANG;
|
||||
import static java.time.temporal.ChronoUnit.SECONDS;
|
||||
|
||||
public class UpdateNotifier implements Listener {
|
||||
private final int id;
|
||||
private final String current;
|
||||
private final AxPlugin instance;
|
||||
private String latest = null;
|
||||
private boolean newest = true;
|
||||
|
||||
public UpdateNotifier(AxPlugin instance, int id) {
|
||||
this.id = id;
|
||||
this.current = instance.getDescription().getVersion();
|
||||
this.instance = instance;
|
||||
|
||||
instance.getServer().getPluginManager().registerEvents(this, instance);
|
||||
|
||||
long time = 30L * 60L * 20L;
|
||||
Scheduler.get().runAsyncTimer(t -> {
|
||||
this.latest = readVersion();
|
||||
this.newest = isLatest(current);
|
||||
|
||||
if (latest == null || newest) return;
|
||||
Bukkit.getConsoleSender().sendMessage(getMessage());
|
||||
t.cancel();
|
||||
}, 50L, time);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
if (latest == null || newest) return;
|
||||
if (!CONFIG.getBoolean("update-notifier.on-join", true)) return;
|
||||
if (!event.getPlayer().hasPermission(instance.getName().toLowerCase() + ".update-notify")) return;
|
||||
Scheduler.get().runLaterAsync(t -> {
|
||||
event.getPlayer().sendMessage(getMessage());
|
||||
}, 50L);
|
||||
}
|
||||
|
||||
private String getMessage() {
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("%current%", current);
|
||||
map.put("%latest%", latest);
|
||||
return StringUtils.formatToString(CONFIG.getString("prefix") + LANG.getString("update-notifier"), map);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String readVersion() {
|
||||
try {
|
||||
final HttpClient client = HttpClient.newHttpClient();
|
||||
final HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(new URI("https://api.polymart.org/v1/getResourceInfoSimple/?resource_id=" + id + "&key=version"))
|
||||
.timeout(Duration.of(10, SECONDS))
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
final HttpResponse<?> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return response.body().toString();
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getLatest() {
|
||||
return latest;
|
||||
}
|
||||
|
||||
public boolean isLatest(String current) {
|
||||
return getWeight(latest) <= getWeight(current);
|
||||
}
|
||||
|
||||
private int getWeight(String version) {
|
||||
if (version == null) return 0;
|
||||
String[] s = version.split("\\.");
|
||||
if (!NumberUtils.isInt(s[0]) || !NumberUtils.isInt(s[1]) || !NumberUtils.isInt(s[2])) return 0;
|
||||
int res = 0;
|
||||
res += Integer.parseInt(s[0]) * 1000000;
|
||||
res += Integer.parseInt(s[1]) * 1000;
|
||||
res += Integer.parseInt(s[2]);
|
||||
return res;
|
||||
}
|
||||
}
|
@ -52,5 +52,12 @@ blacklisted-items:
|
||||
material: "barrier"
|
||||
name-contains: "Banned item's name"
|
||||
|
||||
# should be plugin notify you if there is a new update?
|
||||
update-notifier:
|
||||
# if enabled, it will display the message in the console
|
||||
enabled: true
|
||||
# if enabled, it will broadcast the update message to all players who have the <plugin-name>.update-notify permission
|
||||
on-join: true
|
||||
|
||||
# do not change this
|
||||
version: 2
|
||||
version: 3
|
@ -97,5 +97,7 @@ commands:
|
||||
invalid-player: "&#FF0000The player &#BB0000%player% &#FF0000can not be found!"
|
||||
invalid-selector: "&#FF0000You can not use this selector in this command!"
|
||||
|
||||
update-notifier: "&#AAFFCCThere is a new version of the plugin available! &#DDDDDD(&#FFFFFFcurrent: &#FF0000%current% &#DDDDDD| &#FFFFFFlatest: �FF00%latest%&#DDDDDD)"
|
||||
|
||||
# do not change this
|
||||
version: 3
|
||||
version: 4
|
Loading…
Reference in New Issue
Block a user