Skip to content
This repository was archived by the owner on Feb 15, 2022. It is now read-only.

Commit 108bec4

Browse files
committed
BLC CPS API 1.0
0 parents  commit 108bec4

File tree

14 files changed

+677
-0
lines changed

14 files changed

+677
-0
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.DS_Store
2+
.settings
3+
.project
4+
.classpath
5+
*.class
6+
bin/*
7+
lib/*
8+
include/*
9+
bin/
10+
.idea/
11+
*.iml
12+
out/*
13+
14+
# maven
15+
target/
16+
dependency-reduced-pom.xml

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Turtle Entertainment Online, Inc
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

blccpsapibukkit/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>badlionclientclickspersecondapi</artifactId>
7+
<groupId>net.badlion</groupId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>blccpsapibukkit</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>badlionclientcpsapibukkit</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: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package net.badlion.blccpsapibukkit;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
5+
import net.badlion.blccpsapibukkit.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 BlcCpsApiBukkit 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+
// Only support <= 1.12.2 at the moment, we will add 1.13 support when BLC 1.13 is ready
27+
if (this.getServer().getBukkitVersion().startsWith("1.13")) {
28+
this.getLogger().log(Level.SEVERE, "BLC CPS API is not currently compatible with 1.13 Minecraft. Check back later for updates.");
29+
this.getPluginLoader().disablePlugin(this);
30+
return;
31+
}
32+
33+
if (!this.getDataFolder().exists()) {
34+
if (!this.getDataFolder().mkdir()) {
35+
this.getLogger().log(Level.SEVERE, "Failed to create plugin directory.");
36+
}
37+
}
38+
39+
try {
40+
this.conf = loadConf(new File(this.getDataFolder(), "config.json"));
41+
42+
// Register channel
43+
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BLC|M");
44+
45+
// Only register the listener if the config loads successfully
46+
this.getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
47+
48+
this.getLogger().log(Level.INFO, "Successfully setup BadlionClientCPSAPI plugin.");
49+
} catch (IOException e) {
50+
this.getLogger().log(Level.SEVERE, "Error with config for BadlionClientCPSAPI plugin.");
51+
e.printStackTrace();
52+
}
53+
}
54+
55+
@Override
56+
public void onDisable() {
57+
58+
}
59+
60+
public Conf loadConf(File file) throws IOException {
61+
try {
62+
Reader reader = new BufferedReader(new FileReader(file));
63+
return BlcCpsApiBukkit.GSON_NON_PRETTY.fromJson(reader, Conf.class);
64+
} catch (FileNotFoundException ex) {
65+
this.getLogger().log(Level.INFO,"No Config Found: Saving default...");
66+
Conf conf = new Conf();
67+
this.saveConf(conf, new File(this.getDataFolder(), "config.json"));
68+
return conf;
69+
}
70+
}
71+
72+
private void saveConf(Conf conf, File file) {
73+
try {
74+
FileWriter writer = new FileWriter(file);
75+
BlcCpsApiBukkit.GSON_PRETTY.toJson(conf, writer);
76+
} catch (Exception ex) {
77+
ex.printStackTrace();
78+
}
79+
}
80+
81+
public Conf getConf() {
82+
return this.conf;
83+
}
84+
85+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package net.badlion.blccpsapibukkit;
2+
3+
public class Conf {
4+
5+
private int clicksPerSecondLimit = 20;
6+
7+
8+
public int getClicksPerSecondLimit() {
9+
return clicksPerSecondLimit;
10+
}
11+
12+
}

0 commit comments

Comments
 (0)