-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScavengerhunt.java
99 lines (85 loc) · 3.34 KB
/
Scavengerhunt.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package me.bretmounet.scavengerhunt;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public final class Scavengerhunt extends JavaPlugin {
public String host, database, username, password;
public int port;
public static Connection connection;
public static int maxteamsize;
private File customConfigFile;
private FileConfiguration customConfig;
@Override
public void onEnable() {
createCustomConfig("mysql.yml");
host = getCustomConfig().getString("host");
port = getCustomConfig().getInt("port");
database = getCustomConfig().getString("database");
username = getCustomConfig().getString("username");
password = getCustomConfig().getString("password");
createCustomConfig("teamconfig.yml");
maxteamsize = getCustomConfig().getInt("maxteamsize");
try {
openConnection();
TeamManager.getTeamNames();
TeamManager.createTeams();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
Bukkit.getPluginManager().registerEvents(new playerJoin(),this);
Bukkit.getPluginManager().registerEvents(new PlayerCommandExecuted(),this);
this.getCommand("sc").setExecutor(new ScavengerHuntCommand());
this.getCommand("join").setExecutor(new JoinTeamCommand());
this.getCommand("create").setExecutor(new teamCreateCommand());
this.getCommand("leave").setExecutor(new LeaveTeamCommand());
this.getCommand("delete").setExecutor(new DeleteTeamCommand());
this.getCommand("random").setExecutor(new joinRandomTeamCommand());
new spigotExpansion().register();
}
@Override
public void onDisable() {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void openConnection() throws SQLException,ClassNotFoundException{
if (connection != null && !connection.isClosed()) {
return;
}
synchronized (this) {
if (connection != null && !connection.isClosed()) {
return;
}
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
}
}
public FileConfiguration getCustomConfig() {
return this.customConfig;
}
private void createCustomConfig(String fileName) {
customConfigFile = new File(getDataFolder(), fileName);
if (!customConfigFile.exists()) {
customConfigFile.getParentFile().mkdirs();
saveResource(fileName, false);
}
customConfig= new YamlConfiguration();
try {
customConfig.load(customConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
}