Skip to content

Commit 28ee627

Browse files
committed
New version check changelog
1 parent d6abdf2 commit 28ee627

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/main/java/us/thezircon/play/autopickup/listeners/PlayerJoinEventListener.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package us.thezircon.play.autopickup.listeners;
22

3+
import me.clip.placeholderapi.expansion.Version;
34
import net.md_5.bungee.api.chat.ClickEvent;
45
import net.md_5.bungee.api.chat.ComponentBuilder;
56
import net.md_5.bungee.api.chat.HoverEvent;
@@ -12,6 +13,7 @@
1213
import org.bukkit.event.player.PlayerJoinEvent;
1314
import us.thezircon.play.autopickup.AutoPickup;
1415
import us.thezircon.play.autopickup.utils.PickupPlayer;
16+
import us.thezircon.play.autopickup.utils.VersionChk;
1517

1618
public class PlayerJoinEventListener implements Listener{
1719

@@ -31,6 +33,11 @@ public void onJoin(PlayerJoinEvent e) {
3133
message.setClickEvent( new ClickEvent( ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/autopickup-1-16-support.70157/" ) );
3234
message.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "Click to open on spigot!" ).create() ) );
3335
player.spigot().sendMessage( message );
36+
for (String s : VersionChk.changelog) {
37+
if (s.isEmpty())
38+
continue;
39+
player.sendMessage(PLUGIN.getMsg().getPrefix() + ChatColor.YELLOW + " - " + s);
40+
}
3441
}
3542

3643
boolean doAutoEnableMSG = PLUGIN.getConfig().getBoolean("doAutoEnableMSG");

src/main/java/us/thezircon/play/autopickup/utils/VersionChk.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ public class VersionChk {
2020

2121
private static final Logger log = Logger.getLogger("Minecraft");
2222

23+
public static String[] changelog;
24+
2325
public static void checkVersion(String name, int id) throws Exception { //https://api.spigotmc.org/legacy/update.php?resource=76103"
2426

2527
//https://api.github.com/repos/MrButtersDEV/AutoPickup/releases/latest
2628
String url = "https://api.spigotmc.org/legacy/update.php?resource="+id;
29+
String url2 = "https://raw.githubusercontent.com/MrButtersDEV/AutoPickup/master/update-info.txt";
2730

2831
URL obj = new URL(url);
2932
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
@@ -37,8 +40,7 @@ public static void checkVersion(String name, int id) throws Exception { //https:
3740
int responseCode = con.getResponseCode();
3841
PLUGIN.getServer().getConsoleSender().sendMessage(PLUGIN.getMsg().getPrefix() + ChatColor.RESET +" Checking for new verison...");
3942

40-
BufferedReader in = new BufferedReader(
41-
new InputStreamReader(con.getInputStream()));
43+
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
4244
String inputLine;
4345
StringBuffer response = new StringBuffer();
4446

@@ -47,6 +49,28 @@ public static void checkVersion(String name, int id) throws Exception { //https:
4749
}
4850
in.close();
4951

52+
URL obj2 = new URL(url2);
53+
HttpURLConnection con2 = (HttpURLConnection) obj2.openConnection();
54+
55+
// optional default is GET
56+
con2.setRequestMethod("GET");
57+
58+
//add request header
59+
con2.setRequestProperty("User-Agent", USER_AGENT);
60+
61+
int responseCode2 = con2.getResponseCode();
62+
63+
BufferedReader in2 = new BufferedReader(new InputStreamReader(con2.getInputStream()));
64+
String inputLine2;
65+
StringBuffer response2 = new StringBuffer();
66+
67+
while ((inputLine2 = in2.readLine()) != null) {
68+
response2.append(inputLine2);
69+
}
70+
in2.close();
71+
72+
changelog = response2.toString().split("- ");
73+
5074
//print result
5175
String spigotVerison = response.toString();
5276
String ver = Bukkit.getServer().getPluginManager().getPlugin(name).getDescription().getVersion();
@@ -56,6 +80,11 @@ public static void checkVersion(String name, int id) throws Exception { //https:
5680
PLUGIN.getServer().getConsoleSender().sendMessage(PLUGIN.getMsg().getPrefix() + ChatColor.RED + " UPDATE FOUND: " + ChatColor.GREEN + "https://www.spigotmc.org/resources/"+id+"/");
5781
PLUGIN.getServer().getConsoleSender().sendMessage(PLUGIN.getMsg().getPrefix() + ChatColor.GOLD + " Version: " + ChatColor.GREEN + response.toString() + ChatColor.AQUA + " Using Version: " + ChatColor.DARK_AQUA + ver);
5882
PLUGIN.UP2Date = false;
83+
for (String s : changelog) {
84+
if (s.isEmpty())
85+
continue;
86+
PLUGIN.getServer().getConsoleSender().sendMessage(PLUGIN.getMsg().getPrefix() + ChatColor.YELLOW + " - " + s);
87+
}
5988
}
6089

6190
// Config Version:

0 commit comments

Comments
 (0)