Skip to content

Commit 0c083a1

Browse files
authored
Update 1.5.7
1.5.7
2 parents b05c308 + 02cdc78 commit 0c083a1

File tree

10 files changed

+250
-207
lines changed

10 files changed

+250
-207
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A minecraft (**java**) plugin that lets you **run repetitive tasks** with **delay** and a lot more ! Configurable by UI or chat ! learn more with the **links 🔗** bellow !
44

5-
Already **950 downloads ⏬**, **THANK YOU** !
5+
Already **990 downloads ⏬**, **THANK YOU** !
66

77
## Spigot 🔗
88
>Download the ressource via spigot page :
@@ -15,3 +15,45 @@ https://www.spigotmc.org/resources/acmd-%E2%8F%B0-%E2%8F%B3-autocommands-1-13-1-
1515
## wiki 🔗
1616

1717
>https://github.com/AutoPluginsDev/Documentation/wiki/AutoCommands-%5BACMD%5D
18+
19+
## Future Refactoring
20+
21+
Use two config files, one to adresse template commands, and one to adresse state of the command
22+
23+
> (why not using a DB for the state of the command ?)
24+
25+
### config file
26+
27+
register the command data that are not changing, like the commands registered, for the acmd, the delay etc...
28+
29+
30+
#### Example
31+
32+
**commandTemplates.yml**
33+
```yml
34+
35+
example2:
36+
active: false # CA TEJ
37+
TaskParameters:
38+
name: AcmdExample2
39+
cycle: 6000
40+
delay: 200
41+
repetition: -1
42+
commands:
43+
- say Dont forget to join our Discord !
44+
message: ''
45+
running: false # CA TEJ
46+
DailySchedulerParameters:
47+
time: ''
48+
```
49+
50+
**commandStates.yml**
51+
```yml
52+
1:
53+
template: example2
54+
running: false
55+
active: false
56+
executor: server
57+
58+
```
59+

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>fr</groupId>
88
<artifactId>AutoCommands_ACMD</artifactId>
9-
<version>1.5.3</version>
9+
<version>1.5.7</version>
1010
<packaging>jar</packaging>
1111

1212
<repositories>

src/main/java/fr/lumi/Commandes/CommandRunnerHelp.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.lumi.Commandes;
22

33
import fr.lumi.Main;
4+
import org.bukkit.ChatColor;
45
import org.bukkit.command.Command;
56
import org.bukkit.command.CommandExecutor;
67
import org.bukkit.command.CommandSender;
@@ -38,9 +39,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
3839
Player player = (Player) sender;
3940

4041
String message =
41-
4242
"§e-----------§aAutoCommands-Help§e--------------\n"
43-
+"§6ACMD Version : 1.0\n"
43+
+"§6" + ChatColor.translateAlternateColorCodes('&',plugin.VerifyPluginVersion())+"\n"
44+
+"§6ACMD Version : "+ plugin.getDescription().getVersion()+"\n"
4445
+"§6/acmd -> §7The main command of the plugin\n"
4546
+"§6/acmd list [page]-> §7Displays the list of the AutoCommands\n"
4647
+"§6/acmdreload -> §7reload the plugin and the autocomands\n"

src/main/java/fr/lumi/Main.java

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package fr.lumi;
22

3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonElement;
5+
import com.google.gson.JsonObject;
36
import fr.lumi.Commandes.CommandRunnerCommand;
47
import fr.lumi.Commandes.CommandRunnerEditor;
58
import fr.lumi.Commandes.CommandRunnerHelp;
@@ -15,6 +18,18 @@
1518
import org.bukkit.Bukkit;
1619

1720
import java.io.*;
21+
import java.net.HttpURLConnection;
22+
import java.net.URL;
23+
import java.io.BufferedReader;
24+
import java.io.InputStreamReader;
25+
import java.io.IOException;
26+
import java.net.HttpURLConnection;
27+
import java.net.URL;
28+
import java.util.logging.Level;
29+
import com.google.gson.JsonArray;
30+
import com.google.gson.JsonElement;
31+
import com.google.gson.JsonParser;
32+
import com.google.gson.JsonObject;
1833
import java.util.ArrayList;
1934
import java.util.List;
2035
import java.util.Objects;
@@ -24,7 +39,7 @@ public final class Main extends JavaPlugin {
2439

2540
private String[] Logo ={
2641
"&e&9 &6__ __ &e ",
27-
"&e&9 /\\ &6/ |\\/|| \\&e| &9Auto&6Commands &aVersion &e1.5.3",
42+
"&e&9 /\\ &6/ |\\/|| \\&e| &9Auto&6Commands &aVersion &e" + this.getDescription().getVersion(),
2843
"&e&9/--\\&6\\__| ||__/&e| &8running on bukkit - paper",
2944
""};
3045

@@ -97,7 +112,7 @@ public Utilities getUt(){
97112
return m_ut;
98113
}
99114

100-
115+
// command list, core of the plugin holding current commands
101116
private List<autocommand> commandList = new ArrayList<autocommand>();
102117
public List<autocommand> getcommandList(){
103118
return commandList;
@@ -126,9 +141,69 @@ public void init(){
126141
}
127142

128143

144+
public String callGithubForTag(){
145+
StringBuilder response = new StringBuilder();
146+
try {
147+
// Make HTTP GET request
148+
URL url = new URL("https://api.github.com/repos/lumi-git/AutoCommands/tags");
149+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
150+
connection.setRequestMethod("GET");
151+
connection.setRequestProperty("Accept", "application/json");
152+
153+
// Check response code
154+
if (connection.getResponseCode() != 200) {
155+
throw new IOException("Failed to get response from GitHub API");
156+
}
157+
158+
// Read response
159+
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
160+
161+
String line;
162+
while ((line = reader.readLine()) != null) {
163+
response.append(line);
164+
}
165+
reader.close();
166+
} catch (IOException e) {
167+
getLogger().log(Level.WARNING, "Failed to check for a new version on spigot.", e);
168+
}
169+
return response.toString();
170+
}
171+
172+
public String VerifyPluginVersion() {
173+
String spigotResponse = "";
174+
String currentVersion = this.getDescription().getVersion();
175+
176+
String response = callGithubForTag();
177+
178+
// Parse JSON response
179+
JsonParser parser = new JsonParser();
180+
JsonElement jsonElement = parser.parse(response);
181+
if (jsonElement.isJsonArray()) {
182+
JsonArray jsonArray = jsonElement.getAsJsonArray();
183+
if (jsonArray.size() > 0) {
184+
JsonObject latestTag = jsonArray.get(0).getAsJsonObject();
185+
spigotResponse = latestTag.get("name").getAsString();
186+
}
187+
}
188+
189+
if (spigotResponse.equals("")) {
190+
return "&cFailed to check for a new version on spigot.";
191+
}
192+
193+
if (spigotResponse.equals(currentVersion)) {
194+
return "&aYou are running the latest version of AutoCommands "+ currentVersion +" !";
195+
}
196+
197+
return "&eAutoCommands &a&l" + spigotResponse +" &eis available! &chttps://www.spigotmc.org/resources/acmd-%E2%8F%B0-%E2%8F%B3-autocommands-1-13-1-20-4.100090";
198+
}
199+
129200
@Override
130201
public void onEnable() {
131202

203+
// verify if the plugin is up to date and send a message to the admins
204+
String broadcastMessage = ChatColor.translateAlternateColorCodes('&',getConfig().getString("Prefix")+VerifyPluginVersion());
205+
Bukkit.broadcast(broadcastMessage, "bukkit.broadcast.admin");
206+
132207
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
133208
papiPresent = true;
134209
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&',config.getString("ConsolePrefix")+" &aPlaceholderAPI found"));
@@ -234,17 +309,8 @@ public boolean loadCommandsTimeTable() {
234309
for(String i : getCommandsConfig().getKeys(false)){
235310
autocommand acmd = new autocommand(this);
236311
if(acmd.getInConfig(getCommandsConfig(),this,i)){
237-
/*
238-
int index=0;
239-
while(acmdIdExist(acmd.getID())){
240-
Bukkit.getConsoleSender().sendMessage(acmd.getID());
241-
acmd.setID(acmd.getID() +"_"+index);
242-
index++;
243-
}*/
244-
245312
if(getConfig().getBoolean("DisplayAcmdInConsole"))
246313
acmd.printToConsole();
247-
248314
acmd.addToScheduler();
249315
commandList.add(acmd);
250316
acmd.saveInConfig(commandsConfig,this);

0 commit comments

Comments
 (0)