Skip to content

Commit aca7795

Browse files
committed
Bukkit example plugin completed. Tested against 1.7.10 Craftbukkit, 1.12 Spigot (future proofed).
1 parent 98f2648 commit aca7795

File tree

8 files changed

+409
-18
lines changed

8 files changed

+409
-18
lines changed

blcmodapibukkit/pom.xml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>badlionclientmodapi</artifactId>
7+
<groupId>net.badlion</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>blcmodapibukkit</artifactId>
13+
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
</properties>
17+
18+
<build>
19+
<defaultGoal>clean install</defaultGoal>
20+
<finalName>badlionclientmodapibukkit</finalName>
21+
<sourceDirectory>src/main/java</sourceDirectory>
22+
<resources>
23+
<resource>
24+
<targetPath>.</targetPath>
25+
<filtering>true</filtering>
26+
<directory>src/main/resources/</directory>
27+
<includes>
28+
<include>*.yml</include>
29+
</includes>
30+
</resource>
31+
</resources>
32+
33+
<plugins>
34+
<plugin>
35+
<groupId>org.apache.maven.plugins</groupId>
36+
<artifactId>maven-compiler-plugin</artifactId>
37+
<configuration>
38+
<source>1.6</source>
39+
<target>1.6</target>
40+
</configuration>
41+
</plugin>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-shade-plugin</artifactId>
45+
<version>3.1.0</version>
46+
<executions>
47+
<execution>
48+
<phase>package</phase>
49+
<goals>
50+
<goal>shade</goal>
51+
</goals>
52+
</execution>
53+
</executions>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.bukkit</groupId>
61+
<artifactId>bukkit</artifactId>
62+
<version>1.12.2-R0.1-SNAPSHOT</version>
63+
<scope>provided</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>com.google.code.gson</groupId>
67+
<artifactId>gson</artifactId>
68+
<version>2.6.2</version>
69+
<scope>compile</scope>
70+
</dependency>
71+
</dependencies>
72+
73+
<repositories>
74+
<repository>
75+
<id>spigot-repo</id>
76+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
77+
</repository>
78+
</repositories>
79+
80+
81+
</project>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package net.badlion.blcmodapibukkit;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
5+
import net.badlion.blcmodapibukkit.listener.PlayerListener;
6+
import org.bukkit.plugin.java.JavaPlugin;
7+
8+
import java.io.BufferedReader;
9+
import java.io.File;
10+
import java.io.FileNotFoundException;
11+
import java.io.FileReader;
12+
import java.io.FileWriter;
13+
import java.io.IOException;
14+
import java.io.Reader;
15+
import java.util.logging.Level;
16+
17+
public class BlcModApiBukkit extends JavaPlugin {
18+
19+
public static final Gson GSON_NON_PRETTY = new GsonBuilder().enableComplexMapKeySerialization().disableHtmlEscaping().create();
20+
public static final Gson GSON_PRETTY = new GsonBuilder().enableComplexMapKeySerialization().disableHtmlEscaping().setPrettyPrinting().create();
21+
22+
private Conf conf;
23+
24+
@Override
25+
public void onEnable() {
26+
if (!this.getDataFolder().exists()) {
27+
if (!this.getDataFolder().mkdir()) {
28+
this.getLogger().log(Level.SEVERE, "Failed to create plugin directory.");
29+
}
30+
}
31+
32+
try {
33+
this.conf = loadConf(new File(this.getDataFolder(), "config.json"));
34+
35+
// Register channel
36+
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BLC|M");
37+
38+
// Only register the listener if the config loads successfully
39+
this.getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
40+
41+
this.getLogger().log(Level.INFO, "Successfully setup BadlionClientModAPI plugin.");
42+
} catch (IOException e) {
43+
this.getLogger().log(Level.SEVERE, "Error with config for BadlionClientModAPI plugin.");
44+
e.printStackTrace();
45+
}
46+
}
47+
48+
@Override
49+
public void onDisable() {
50+
51+
}
52+
53+
public Conf loadConf(File file) throws IOException {
54+
try {
55+
Reader reader = new BufferedReader(new FileReader(file));
56+
return BlcModApiBukkit.GSON_NON_PRETTY.fromJson(reader, Conf.class);
57+
} catch (FileNotFoundException ex) {
58+
this.getLogger().log(Level.INFO,"No Config Found: Saving default...");
59+
Conf conf = new Conf();
60+
this.saveConf(conf, new File(this.getDataFolder(), "config.json"));
61+
return conf;
62+
}
63+
}
64+
65+
private void saveConf(Conf conf, File file) {
66+
try {
67+
FileWriter writer = new FileWriter(file);
68+
BlcModApiBukkit.GSON_PRETTY.toJson(conf, writer);
69+
} catch (Exception ex) {
70+
ex.printStackTrace();
71+
}
72+
}
73+
74+
public Conf getConf() {
75+
return this.conf;
76+
}
77+
78+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.badlion.blcmodapibukkit;
2+
3+
import com.google.gson.JsonObject;
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
public class Conf {
9+
10+
private Map<String, DisallowedMods> modsDisallowed = new HashMap<String, DisallowedMods>();
11+
12+
13+
public Map<String, DisallowedMods> getModsDisallowed() {
14+
return this.modsDisallowed;
15+
}
16+
17+
private class DisallowedMods {
18+
19+
private boolean disabled;
20+
private JsonObject extra_data;
21+
22+
}
23+
24+
}

0 commit comments

Comments
 (0)