-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up some code and added plugin for 1.17+
- Loading branch information
Showing
10 changed files
with
418 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>badlionclientmodapi</artifactId> | ||
<groupId>net.badlion</groupId> | ||
<version>1.2.3</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>blcmodapibukkit-1.17</artifactId> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<defaultGoal>clean install</defaultGoal> | ||
<finalName>badlionclientmodapibukkit-1.17</finalName> | ||
<sourceDirectory>src/main/java</sourceDirectory> | ||
<resources> | ||
<resource> | ||
<targetPath>.</targetPath> | ||
<filtering>true</filtering> | ||
<directory>src/main/resources/</directory> | ||
<includes> | ||
<include>*.yml</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot-api</artifactId> | ||
<version>1.17-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.6.2</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>spigot-repo</id> | ||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
</repositories> | ||
|
||
|
||
</project> |
76 changes: 76 additions & 0 deletions
76
blcmodapibukkit-1.17/src/main/java/net/badlion/blcmodapibukkit/BlcModApiBukkit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package net.badlion.blcmodapibukkit; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import net.badlion.blcmodapibukkit.listener.PlayerListener; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.util.logging.Level; | ||
|
||
public class BlcModApiBukkit extends JavaPlugin { | ||
|
||
public static final Gson GSON_NON_PRETTY = new GsonBuilder().enableComplexMapKeySerialization().disableHtmlEscaping().create(); | ||
public static final Gson GSON_PRETTY = new GsonBuilder().enableComplexMapKeySerialization().disableHtmlEscaping().setPrettyPrinting().create(); | ||
|
||
private Conf conf; | ||
|
||
@Override | ||
public void onEnable() { | ||
if (!this.getDataFolder().exists()) { | ||
if (!this.getDataFolder().mkdir()) { | ||
this.getLogger().log(Level.SEVERE, "Failed to create plugin directory."); | ||
} | ||
} | ||
|
||
try { | ||
this.conf = this.loadConf(new File(this.getDataFolder(), "config.json")); | ||
|
||
// Register channel | ||
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "badlion:mods"); | ||
|
||
// Only register the listener if the config loads successfully | ||
this.getServer().getPluginManager().registerEvents(new PlayerListener(this), this); | ||
|
||
this.getLogger().log(Level.INFO, "Successfully setup BadlionClientModAPI plugin."); | ||
} catch (IOException e) { | ||
this.getLogger().log(Level.SEVERE, "Error with config for BadlionClientModAPI plugin."); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
|
||
} | ||
|
||
public Conf loadConf(File file) throws IOException { | ||
try (Reader reader = new FileReader(file)) { | ||
return BlcModApiBukkit.GSON_NON_PRETTY.fromJson(reader, Conf.class); | ||
|
||
} catch (FileNotFoundException ex) { | ||
this.getLogger().log(Level.INFO, "No Config Found: Saving default..."); | ||
Conf conf = new Conf(); | ||
this.saveConf(conf, new File(this.getDataFolder(), "config.json")); | ||
return conf; | ||
} | ||
} | ||
|
||
private void saveConf(Conf conf, File file) { | ||
try (FileWriter writer = new FileWriter(file)) { | ||
BlcModApiBukkit.GSON_PRETTY.toJson(conf, writer); | ||
|
||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
public Conf getConf() { | ||
return this.conf; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
blcmodapibukkit-1.17/src/main/java/net/badlion/blcmodapibukkit/Conf.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package net.badlion.blcmodapibukkit; | ||
|
||
import com.google.gson.JsonObject; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Conf { | ||
private Map<String, DisallowedMods> modsDisallowed = new HashMap<String, DisallowedMods>(); | ||
|
||
public Map<String, DisallowedMods> getModsDisallowed() { | ||
return this.modsDisallowed; | ||
} | ||
|
||
private static class DisallowedMods { | ||
private boolean disabled; | ||
private JsonObject extra_data; | ||
private JsonObject settings; | ||
} | ||
} |
Oops, something went wrong.