Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
更新1.2.7-alpha-3
Browse files Browse the repository at this point in the history
  • Loading branch information
Aruvelut-123 committed Jul 19, 2024
1 parent 6bc279a commit a5ea4d3
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 55 deletions.
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>idk</groupId>
<artifactId>IDK</artifactId>
<name>IDK</name>
<version>1.2.7-alpha-2</version>
<version>1.2.7-alpha-3</version>
<build>
<resources>
<resource>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>idk</groupId>
<artifactId>IDK</artifactId>
<version>1.2.7-alpha-2</version>
<version>1.2.7-alpha-3</version>
<packaging>jar</packaging>

<name>IDK</name>
Expand Down
77 changes: 68 additions & 9 deletions src/main/java/idk/team/IDK.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package idk.team;

import idk.team.plugin.IDKPluginManagement;
import org.apache.logging.log4j.LogManager;
import org.bukkit.Bukkit;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.MemoryConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.*;
import java.io.*;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Objects;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Logger;

public final class IDK extends JavaPlugin {
Expand All @@ -17,26 +27,71 @@ protected void finalize() throws Throwable {
}
};
public Logger logger = Bukkit.getLogger();
public static Logger log = Bukkit.getLogger();
public static IDK idk;
public boolean test_build = false;
public boolean beta_build = false;
public boolean alpha_build = true;
public boolean debug = true;
public String prefix = messages.getString("prefix");
int config_ver = 3;
int config_ver = 4;
String plugins = null;

public static void unzipJar(String destinationDir, String jarPath) throws IOException {
File file = new File(jarPath);
JarFile jar = new JarFile(file);

// fist get all directories,
// then make those directory on the destination Path
for (Enumeration<JarEntry> enums = jar.entries(); enums.hasMoreElements();) {
JarEntry entry = (JarEntry) enums.nextElement();

String fileName = destinationDir + File.separator + entry.getName();
File f = new File(fileName);

if (fileName.endsWith("/")) {
f.mkdirs();
}

}

//now create all files
for (Enumeration<JarEntry> enums = jar.entries(); enums.hasMoreElements();) {
JarEntry entry = (JarEntry) enums.nextElement();

String fileName = destinationDir + File.separator + entry.getName();
File f = new File(fileName);

if (!fileName.endsWith("/")) {
InputStream is = jar.getInputStream(entry);
FileOutputStream fos = new FileOutputStream(f);

// write contents of 'is' to 'fos'
while (is.available() > 0) {
fos.write(is.read());
}

fos.close();
is.close();
}
}
}

@Override
public void onLoad() {
this.plugins = Arrays.toString(Bukkit.getPluginManager().getPlugins());
Configuration defaults = new MemoryConfiguration();
defaults.set("config-version", 3);
defaults.set("config-version", 4);
defaults.set("plugin-management", true);
defaults.set("debug", true);
defaults.set("download-source", "papermc");
defaults.set("lang", "en");
defaults.set("test-notify", "true");
this.getConfig().setDefaults(defaults);
}

private boolean notfirsttime = false;

@Override
public void onEnable() {
//插件启用逻辑
Expand All @@ -48,13 +103,17 @@ public void onEnable() {
String debug_warn = messages.getString("debug_warn");
String papermc_warn = messages.getString("papermc_warn");
this.debug = this.getConfig().getBoolean("debug");
if(this.debug) {
logger.warning(prefix+debug_warn);
}
if(Objects.equals(this.getConfig().getString("download-source"), "papermc")) {
logger.warning(prefix+papermc_warn);
if(!notfirsttime) {
if(this.debug) {
logger.warning(prefix+debug_warn);
}
if(Objects.equals(this.getConfig().getString("download-source"), "papermc")) {
logger.warning(prefix+papermc_warn);
}
idk = this;
} else {
notfirsttime = true;
}
idk = this;
}

public void reload() {
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/idk/team/IDKCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,25 @@ protected void finalize() throws Throwable {
String folder = Bukkit.getPluginsFolder().getAbsolutePath();
if(!strings[2].isEmpty()) {
String file_name = strings[2];
String file_path = folder + "\\" + file_name;
String file_path = "";
if (file_name.contains(".jar")) {
file_path = folder + "\\" + file_name;
}
else {
file_path = folder + "\\" + file_name + ".jar";
}
try {
Plugin plugin = Bukkit.getPluginManager().loadPlugin(new File(file_path));
if (plugin != null) {
Bukkit.getPluginManager().enablePlugin(plugin);
player.sendMessage(prefix+"Plugin file " + file_name + " " + "plugin name " + plugin.getName() + " loaded!");
player.sendMessage(prefix+messages.getString("plugin_loaded_a").replace("[name]", plugin.getName()).replace("[file]", file_name));
}
return true;
} catch (InvalidPluginException | InvalidDescriptionException e) {
return true;
}
} else {
player.sendMessage(prefix+"Error!");
player.sendMessage(prefix+messages.getString("error_load"));
return true;
}
}
Expand Down Expand Up @@ -194,7 +200,7 @@ protected void finalize() throws Throwable {
return false;
}
else {
player.sendMessage(prefix+"Plugin management function is not enabled in config.");
player.sendMessage(prefix+messages.getString("plugin_management_not_enable"));
return true;
}
}
Expand Down Expand Up @@ -347,7 +353,7 @@ protected void finalize() throws Throwable {
}
if(strings.length == 1 && strings[0].equals("ping")) {
if(player.hasPermission("IDK.command.IDK.ping")) {
player.sendMessage(prefix+messages.getString("ping") + player.getPing() + "ms!"); //给玩家发送消息
player.sendMessage(prefix+messages.getString("ping").replace("[ping]", String.valueOf(player.getPing()))); //给玩家发送消息
}
return true;
}
Expand Down Expand Up @@ -419,14 +425,14 @@ protected void finalize() throws Throwable {
Plugin plugin = Bukkit.getPluginManager().loadPlugin(new File(file_path));
if (plugin != null) {
Bukkit.getPluginManager().enablePlugin(plugin);
IDK.idk.logger.info(prefix+"Plugin file " + file_name + " " + "plugin name " + plugin.getName() + " loaded!");
IDK.idk.logger.info(prefix+messages.getString("plugin_loaded_a").replace("[name]", plugin.getName()).replace("[file]", file_name));
}
return true;
} catch (InvalidPluginException | InvalidDescriptionException e) {
return true;
}
} else {
IDK.idk.logger.warning(prefix+"Error!");
IDK.idk.logger.warning(prefix+messages.getString("error_load"));
return true;
}
}
Expand Down Expand Up @@ -529,7 +535,7 @@ protected void finalize() throws Throwable {
return false;
}
else {
IDK.idk.logger.warning(prefix+"Plugin management function is not enabled in config.");
IDK.idk.logger.warning(prefix+messages.getString("plugin_management_not_enable"));
return true;
}
}
Expand Down
56 changes: 35 additions & 21 deletions src/main/java/idk/team/IDKListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,42 @@ protected void finalize() throws Throwable {
String warning_title = messages.getString("warning_title");
String warning_test = messages.getString("warning_test");
String warning_beta = messages.getString("warning_beta");
String warning_alpha = messages.getString("warning_alpha");
String warning_2 = messages.getString("warning_2");
if (IDK.idk.test_build) {
player.sendTitle(prefix+warning_title, prefix+warning_test);
Timer timer = new Timer();
TimerTask use_at_own_risks = new TimerTask() {
@Override
public void run() {
player.sendTitle(prefix+warning_title, prefix+warning_2);
}
};
timer.schedule(use_at_own_risks,5000);
}
else if (IDK.idk.beta_build) {
player.sendTitle(prefix+warning_title, warning_beta);
Timer timer = new Timer();
TimerTask use_at_own_risks = new TimerTask() {
@Override
public void run() {
player.sendTitle(prefix+warning_title, warning_2);
}
};
timer.schedule(use_at_own_risks,5000);
if (config.getBoolean("test-notify")) {
if (IDK.idk.test_build) {
player.sendTitle(prefix+warning_title, prefix+warning_test);
Timer timer = new Timer();
TimerTask use_at_own_risks = new TimerTask() {
@Override
public void run() {
player.sendTitle(prefix+warning_title, prefix+warning_2);
}
};
timer.schedule(use_at_own_risks,5000);
}
else if (IDK.idk.alpha_build) {
player.sendTitle(prefix+warning_title, warning_alpha);
Timer timer = new Timer();
TimerTask use_at_own_risks = new TimerTask() {
@Override
public void run() {
player.sendTitle(prefix+warning_title, warning_2);
}
};
timer.schedule(use_at_own_risks,5000);
}
else if (IDK.idk.beta_build) {
player.sendTitle(prefix+warning_title, warning_beta);
Timer timer = new Timer();
TimerTask use_at_own_risks = new TimerTask() {
@Override
public void run() {
player.sendTitle(prefix+warning_title, warning_2);
}
};
timer.schedule(use_at_own_risks,5000);
}
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/main/java/idk/team/IDKMessageConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Objects;

public abstract class IDKMessageConfig {
static int ver = 8;
static int ver = 9;
protected IDK idk;
private File file;
public FileConfiguration config;
Expand All @@ -26,10 +26,10 @@ public IDKMessageConfig(String file_path, String lang) {
}
if (file_path != null && !file_path.isEmpty() && fileName != null && !fileName.isEmpty()) {
file = new File(file_path, fileName);
String str = "message-ver: 8\n" +
"prefix:&" +
String str = "message-ver: 9\n" +
"prefix: '§1'" +
"main:\n" +
" - 'IDK Plugin Version 1.2.5-pre-test'\n" +
" - 'IDK Plugin Version 1.2.7-alpha-3'\n" +
" - 'Made by Baymaxawa'\n" +
"reload: 'Config reloaded!'\n" +
"failed: 'Config reload failed! Check details below!'\n" +
Expand Down Expand Up @@ -143,7 +143,11 @@ public IDKMessageConfig(String file_path, String lang) {
"start_update_idk: 'Checking for updates...'\n" +
"update_idk_complete: 'Update Complete! Needs restart to take effort!'\n" +
"update_idk_failed_p: 'Update Failed! Check the console for details!'\n" +
"update_idk_failed_c: 'Update Failed!'\n";
"update_idk_failed_c: 'Update Failed!'\n" +
"plugin_loaded_a: 'Plugin [name] [file] loaded!'\n" +
"error_load: 'Plugin failed to load with some errors...'.\n" +
"plugin_management_not_enable: 'Plugin management function is not enabled in config.'\n" +
"warning_alpha: 'You are currently using a alpha build of IDK plugin!'\n";
if(Objects.equals(lang, "zh")) {
if(!file.exists()) {
File new_file = new File(file_path, "messages.yml");
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#config version, do not change it!!!
#default: 3
config-version: 3
#default: 4
config-version: 4
#enable plugin management function
#default: true
plugin-management: true
Expand All @@ -18,4 +18,6 @@ download-source: "papermc"
#you can download it here: https://github.com/Aruvelut-123/IDK-plugin/raw/master/src/main/resources/messages_zh.yml
#or extract it from the jar of plugin.
#default: "en"
lang: "en"
lang: "en"
#enable test/beta/alpha build notify
test-notify: true
12 changes: 8 additions & 4 deletions src/main/resources/messages.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
message-ver: 8
prefix: '&'
message-ver: 9
prefix: '§1'
main:
- 'IDK Plugin Version 1.2.7-alpha-2'
- 'IDK Plugin Version 1.2.7-alpha-3'
- 'Made by Baymaxawa'
reload: 'Config reloaded!'
failed: 'Config reload failed! Check details below!'
Expand All @@ -10,7 +10,7 @@ survival: 'You"re now in SURVIVAL!'
creative: 'You"re now in CREATIVE!'
adventure: 'You"re now in ADVENTURE!'
spectator: 'You"re now in SPECTATOR!'
ping: 'Your ping is: '
ping: 'Your ping is: [ping]ms!'
no-console: 'Console not avalible right now.'
available-plugins: 'Available plugins: '
plugin-disable-error: 'Cannot disable this plugin or already disabled!'
Expand Down Expand Up @@ -116,3 +116,7 @@ start_update_idk: 'Checking for updates...'
update_idk_complete: 'Update Complete! Needs restart to take effort!'
update_idk_failed_p: 'Update Failed! Check the console for details!'
update_idk_failed_c: 'Update Failed!'
plugin_loaded_a: 'Plugin [name] [file] loaded!'
error_load: 'Plugin failed to load with some errors...'.
plugin_management_not_enable: 'Plugin management function is not enabled in config.'
warning_alpha: 'You are currently using a alpha build of IDK plugin!'
10 changes: 7 additions & 3 deletions src/main/resources/messages_zh.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
message-ver: 8
prefix: '&'
message-ver: 9
prefix: '§1'
main:
- 'IDK插件,版本1.2.7-alpha-2'
- 'IDK插件,版本1.2.7-alpha-3'
- '由Baymaxawa制作'
reload: '配置文件已重载!'
failed: '配置文件重载失败!请查看下面的详情信息!'
Expand Down Expand Up @@ -114,3 +114,7 @@ start_update_idk: '正在检查更新...'
update_idk_complete: '更新完成!重启后生效!'
update_idk_failed_p: '更新失败!查看控制台了解详情!'
update_idk_failed_c: '更新失败!'
plugin_loaded_a: '插件 [name] [file] 已成功加载!'
error_load: '插件加载失败:('.
plugin_management_not_enable: '插件管理功能未启用。'
warning_alpha: '你正在使用Alpha版的IDK插件!'

0 comments on commit a5ea4d3

Please sign in to comment.