Skip to content

Commit f08a080

Browse files
committed
fixaros
1 parent ca55d33 commit f08a080

File tree

13 files changed

+28
-70
lines changed

13 files changed

+28
-70
lines changed

dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>me.Joshb</groupId>
55
<artifactId>DiscordBotAPI</artifactId>
6-
<version>1.0.8</version>
6+
<version>1.1.0</version>
77
<build>
88
<sourceDirectory>src/main/java</sourceDirectory>
99
<resources>

pom.xml

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

77
<groupId>me.Joshb</groupId>
88
<artifactId>DiscordBotAPI</artifactId>
9-
<version>1.0.8</version>
9+
<version>1.1.0</version>
1010

1111
<build>
1212
<sourceDirectory>src/main/java</sourceDirectory>

src/main/java/me/joshb/discordbotapi/bungee/DiscordBotAPI.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class DiscordBotAPI extends Plugin {
2121

2222
public DiscordMessageReceived discordMessageReceived;
2323

24-
public void onEnable(){
24+
public void onLoad(){
2525
plugin = this;
2626

2727
Config.getInstance().initialize();
@@ -48,6 +48,10 @@ public void onEnable(){
4848
} catch (LoginException e) {
4949
getLogger().severe("Plugin Disabled. The bot token is invalid. Reason: " + e.getMessage());
5050
}
51+
}
52+
53+
public void onEnable(){
54+
5155
discordMessageReceived = new DiscordMessageReceived();
5256
registerEvent(this, discordMessageReceived);
5357
}

src/main/java/me/joshb/discordbotapi/server/DiscordBotAPI.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package me.joshb.discordbotapi.server;
22

3+
import me.joshb.discordbotapi.server.command.CommandManager;
34
import me.joshb.discordbotapi.server.config.Config;
45
import me.joshb.discordbotapi.server.config.LinkedAccounts;
56
import me.joshb.discordbotapi.server.config.Messages;
6-
import me.joshb.discordbotapi.server.command.CommandManager;
77
import me.joshb.discordbotapi.server.listener.DiscordMessageReceived;
88
import net.dv8tion.jda.api.JDA;
99
import net.dv8tion.jda.api.JDABuilder;
@@ -22,15 +22,17 @@ public class DiscordBotAPI extends JavaPlugin {
2222

2323
public DiscordMessageReceived discordMessageReceived;
2424

25-
public void onEnable() {
25+
public void onEnable(){
2626
plugin = this;
2727

2828
Config.getInstance().initialize();
2929
Messages.getInstance().initialize();
3030
LinkedAccounts.getInstance().initialize();
3131

3232
CommandManager cm = new CommandManager();
33+
Bukkit.broadcastMessage(cm.toString());
3334
cm.initializeSubCommands();
35+
3436
getCommand("discord").setExecutor(cm);
3537

3638
if (Config.getInstance().getConfig().getString("Bot.Token").equals("token_here")) {

src/main/java/me/joshb/discordbotapi/server/config/Config.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
import org.bukkit.configuration.file.YamlConfiguration;
66

77
import java.io.File;
8-
import java.io.FileOutputStream;
9-
import java.io.InputStream;
10-
import java.io.OutputStream;
118
import java.util.Arrays;
129

1310
public class Config {
@@ -32,7 +29,7 @@ public void save(){
3229
try {
3330
ConfigUpdater.update(DiscordBotAPI.plugin, fileName + ".yml", file, Arrays.asList());
3431
} catch (Exception e){
35-
System.out.println("COULD NOT SAVE FILE: " +fileName);
32+
System.out.println("COULD NOT SAVE FILE: " + fileName);
3633
e.printStackTrace();
3734
}
3835
}
@@ -55,25 +52,10 @@ public void initialize(){
5552

5653
if(!file.exists()){
5754
file.getParentFile().mkdirs();
58-
copy(DiscordBotAPI.plugin.getResource(fileName + ".yml"), file);
55+
DiscordBotAPI.plugin.saveResource(fileName + ".yml", false);
5956
}
6057
config = YamlConfiguration.loadConfiguration(file);
6158
save();
6259
reload();
6360
}
64-
65-
private void copy(InputStream in, File file) {
66-
try {
67-
OutputStream out = new FileOutputStream(file);
68-
byte[] buf = new byte[1024];
69-
int len;
70-
while ((len = in.read(buf)) > 0) {
71-
out.write(buf, 0, len);
72-
}
73-
out.close();
74-
in.close();
75-
} catch (Exception e) {
76-
e.printStackTrace();
77-
}
78-
}
7961
}

src/main/java/me/joshb/discordbotapi/server/config/ConfigUpdater.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,8 @@
1212
import java.util.*;
1313
import java.util.stream.Collectors;
1414

15-
/**
16-
* A class to update/add new sections/keys to your config while keeping your current values and keeping your comments
17-
* Algorithm:
18-
* Read the new file and scan for comments and ignored sections, if ignored section is found it is treated as a comment.
19-
* Read and write each line of the new config, if the old config has value for the given key it writes that value in the new config.
20-
* If a key has an attached comment above it, it is written first.
21-
* @author tchristofferson
22-
* @Editor Joshb_ for UTF_8 Support
23-
*/
2415
public class ConfigUpdater {
2516

26-
/**
27-
* Update a yaml file from a resource inside your plugin jar
28-
* @param plugin You plugin
29-
* @param resourceName The yaml file name to update from, typically Config.yml
30-
* @param toUpdate The yaml file to update
31-
* @param ignoredSections List of sections to ignore and copy from the current config
32-
* @throws IOException If an IOException occurs
33-
*/
3417
public static void update(Plugin plugin, String resourceName, File toUpdate, List<String> ignoredSections) throws IOException {
3518
BufferedReader newReader = new BufferedReader(new InputStreamReader(plugin.getResource(resourceName), StandardCharsets.UTF_8));
3619
List<String> newLines = newReader.lines().collect(Collectors.toList());
@@ -147,12 +130,15 @@ private static String getListAsString(List list, String actualKey, String prefix
147130
for (int i = 0; i < list.size(); i++) {
148131
Object o = list.get(i);
149132

150-
if (o instanceof String || o instanceof Character) {
151-
builder.append(prefixSpaces).append("- '").append(o).append("'");
133+
if (o instanceof String) {
134+
String s = String.valueOf(o);
135+
builder.append(prefixSpaces).append(" - \"").append(s).append("\"");
136+
} else if(o instanceof Character){
137+
builder.append(prefixSpaces).append(" - '").append(o).append("'");
152138
} else if (o instanceof List) {
153-
builder.append(prefixSpaces).append("- ").append(yaml.dump(o));
139+
builder.append(prefixSpaces).append(" - ").append(yaml.dump(o));
154140
} else {
155-
builder.append(prefixSpaces).append("- ").append(o);
141+
builder.append(prefixSpaces).append(" - ").append(o);
156142
}
157143

158144
if (i != list.size()) {

src/main/java/me/joshb/discordbotapi/server/config/Messages.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,9 @@ public void initialize(){
5555

5656
if(!file.exists()){
5757
file.getParentFile().mkdirs();
58-
copy(DiscordBotAPI.plugin.getResource(fileName + ".yml"), file);
58+
DiscordBotAPI.plugin.saveResource(fileName + ".yml", false);
5959
}
6060
config = YamlConfiguration.loadConfiguration(file);
6161
reload();
6262
}
63-
64-
private void copy(InputStream in, File file) {
65-
try {
66-
OutputStream out = new FileOutputStream(file);
67-
byte[] buf = new byte[1024];
68-
int len;
69-
while ((len = in.read(buf)) > 0) {
70-
out.write(buf, 0, len);
71-
}
72-
out.close();
73-
in.close();
74-
} catch (Exception e) {
75-
e.printStackTrace();
76-
}
77-
}
7863
}

src/main/resources/Config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Bot:
2-
Token: 'token_here'
3-
Command-Prefix: '!ticketgui'
2+
Token: "token_here"
3+
Command-Prefix: "!ticketgui"

target/classes/Config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Bot:
2-
Token: 'token_here'
3-
Command-Prefix: '!ticketgui'
2+
Token: "token_here"
3+
Command-Prefix: "!ticketgui"

target/classes/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: DiscordBotAPI
2-
version: 1.0.8
2+
version: 1.1.0
33
main: me.joshb.discordbotapi.server.DiscordBotAPI
44
author: Joshb_
55
commands:

0 commit comments

Comments
 (0)