Skip to content

Commit 2d36de9

Browse files
committed
Initial release of plugin
Signed-off-by: applenick <[email protected]>
0 parents  commit 2d36de9

File tree

9 files changed

+404
-0
lines changed

9 files changed

+404
-0
lines changed

.gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
target/
2+
pom.xml.tag
3+
pom.xml.releaseBackup
4+
pom.xml.versionsBackup
5+
pom.xml.next
6+
release.properties
7+
dependency-reduced-pom.xml
8+
buildNumber.properties
9+
.mvn/timing.properties
10+
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
11+
.mvn/wrapper/maven-wrapper.jar
12+
bin/
13+
*.class
14+
*.log
15+
*.ctxt
16+
*.jar
17+
*.war
18+
*.nar
19+
*.ear
20+
*.zip
21+
*.tar.gz
22+
*.rar
23+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24+
hs_err_pid*
25+
# IntelliJ files
26+
.idea
27+
*.iml
28+
# Eclipse
29+
.classpath
30+
.project
31+
.settings

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 applenick / Overcast Community
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.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Environment
2+
3+
A Bukkit plugin for Minecraft which facilitates effortless sharing of variables among various plugins. It features a straightforward API that enables the setting and retrieval of variables.

pom.xml

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>tc.oc.occ</groupId>
4+
<artifactId>Environment</artifactId>
5+
<version>1.0.0-SNAPSHOT</version>
6+
<name>Environment</name>
7+
<description>An environment variable API plugin for Minecraft</description>
8+
9+
<properties>
10+
<maven.compiler.source>1.8</maven.compiler.source>
11+
<maven.compiler.target>1.8</maven.compiler.target>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<project.bukkit.main>tc.oc.occ.environment.Environment</project.bukkit.main>
14+
<project.author>applenick</project.author>
15+
</properties>
16+
17+
<distributionManagement>
18+
<repository>
19+
<id>pgm-repo-snapshots</id>
20+
<url>https://repo.pgm.fyi/snapshots</url>
21+
</repository>
22+
</distributionManagement>
23+
24+
<repositories>
25+
<repository>
26+
<id>pgm-repo-snapshots</id>
27+
<name>PGM Repository</name>
28+
<url>https://repo.pgm.fyi/snapshots</url>
29+
</repository>
30+
<repository>
31+
<id>spigot-repo</id>
32+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
33+
</repository>
34+
</repositories>
35+
36+
<dependencies>
37+
<!-- SportPaper 1.8 -->
38+
<dependency>
39+
<groupId>app.ashcon</groupId>
40+
<artifactId>sportpaper</artifactId>
41+
<version>1.8.8-R0.1-SNAPSHOT</version>
42+
<scope>provided</scope>
43+
</dependency>
44+
45+
<!-- Command Framework -->
46+
<dependency>
47+
<groupId>co.aikar</groupId>
48+
<artifactId>acf-bukkit</artifactId>
49+
<version>0.5.0-SNAPSHOT</version>
50+
</dependency>
51+
</dependencies>
52+
53+
<build>
54+
<resources>
55+
<!-- Include the required plugin.yml and config.yml for Bukkit -->
56+
<resource>
57+
<directory>${basedir}/src/main/resources</directory>
58+
<filtering>true</filtering>
59+
</resource>
60+
</resources>
61+
62+
<plugins>
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-compiler-plugin</artifactId>
66+
<version>3.8.1</version>
67+
<configuration>
68+
<compilerArgs>
69+
<arg>-parameters</arg> <!-- Required for aikar/commands to auto generate syntax -->
70+
</compilerArgs>
71+
</configuration>
72+
</plugin>
73+
74+
<plugin>
75+
<groupId>org.apache.maven.plugins</groupId>
76+
<artifactId>maven-shade-plugin</artifactId>
77+
<version>3.2.3</version>
78+
<configuration>
79+
<relocations>
80+
<relocation>
81+
<pattern>co.aikar.commands</pattern>
82+
<shadedPattern>tc.oc.occ.environment.lib.acf</shadedPattern>
83+
</relocation>
84+
</relocations>
85+
<createDependencyReducedPom>false</createDependencyReducedPom>
86+
<minimizeJar>true</minimizeJar>
87+
<artifactSet>
88+
<includes>
89+
<include>co.aikar:*</include>
90+
</includes>
91+
</artifactSet>
92+
<filters>
93+
<filter>
94+
<artifact>*:*</artifact>
95+
<excludes>
96+
<exclude>META-INF/**</exclude>
97+
</excludes>
98+
</filter>
99+
</filters>
100+
</configuration>
101+
<executions>
102+
<execution>
103+
<phase>package</phase>
104+
<goals>
105+
<goal>shade</goal>
106+
</goals>
107+
</execution>
108+
</executions>
109+
</plugin>
110+
111+
<!-- Validates that code is properly formatted with Google's code style -->
112+
<plugin>
113+
<groupId>com.coveo</groupId>
114+
<artifactId>fmt-maven-plugin</artifactId>
115+
<version>2.9</version>
116+
<configuration>
117+
<style>google</style>
118+
</configuration>
119+
<executions>
120+
<execution>
121+
<goals>
122+
<goal>check</goal>
123+
</goals>
124+
</execution>
125+
</executions>
126+
</plugin>
127+
</plugins>
128+
</build>
129+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package tc.oc.occ.environment;
2+
3+
import co.aikar.commands.BukkitCommandManager;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
import java.util.Set;
7+
import org.bukkit.plugin.java.JavaPlugin;
8+
9+
public class Environment extends JavaPlugin {
10+
11+
private static Environment plugin;
12+
13+
private EnvironmentConfig config;
14+
private BukkitCommandManager commands;
15+
16+
private Map<String, Object> envVariables = new HashMap<>();
17+
18+
@Override
19+
public void onEnable() {
20+
plugin = this;
21+
22+
this.saveDefaultConfig();
23+
this.reloadConfig();
24+
25+
this.config = new EnvironmentConfig(getConfig());
26+
this.envVariables.putAll(config.getStoredEnvs());
27+
getLogger().info("Set " + envVariables.size() + " env variables from the config");
28+
29+
this.commands = new BukkitCommandManager(this);
30+
this.commands.getCommandCompletions().registerCompletion("keys", c -> envVariables.keySet());
31+
this.commands.registerCommand(new EnvironmentCommand());
32+
}
33+
34+
public static Environment get() {
35+
return plugin;
36+
}
37+
38+
public void setEnv(String key, Object value) {
39+
envVariables.put(key, value);
40+
}
41+
42+
public Object getEnv(String key) {
43+
return envVariables.get(key);
44+
}
45+
46+
public boolean deleteEnv(String key) {
47+
return envVariables.remove(key) != null;
48+
}
49+
50+
public Set<String> getKeys() {
51+
return envVariables.keySet();
52+
}
53+
54+
public String getString(String key) {
55+
Object value = getEnv(key);
56+
return (value instanceof String) ? (String) value : null;
57+
}
58+
59+
public Long getLong(String key) {
60+
Object value = getEnv(key);
61+
return (value instanceof Long) ? (Long) value : null;
62+
}
63+
64+
public Integer getInt(String key) {
65+
Object value = getEnv(key);
66+
return (value instanceof Integer) ? (Integer) value : null;
67+
}
68+
69+
public Double getDouble(String key) {
70+
Object value = getEnv(key);
71+
return (value instanceof Double) ? (Double) value : null;
72+
}
73+
74+
public Boolean getBoolean(String key) {
75+
Object value = getEnv(key);
76+
return (value instanceof Boolean) ? (Boolean) value : null;
77+
}
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package tc.oc.occ.environment;
2+
3+
import co.aikar.commands.BaseCommand;
4+
import co.aikar.commands.annotation.CommandAlias;
5+
import co.aikar.commands.annotation.CommandCompletion;
6+
import co.aikar.commands.annotation.CommandPermission;
7+
import co.aikar.commands.annotation.Default;
8+
import co.aikar.commands.annotation.Dependency;
9+
import co.aikar.commands.annotation.Subcommand;
10+
import java.util.Set;
11+
import net.md_5.bungee.api.ChatColor;
12+
import org.bukkit.command.CommandSender;
13+
14+
@CommandAlias("env")
15+
@CommandPermission("env.admin")
16+
public class EnvironmentCommand extends BaseCommand {
17+
18+
private static final String NOT_SET = ChatColor.DARK_RED + "☒ Not Set";
19+
20+
@Dependency private Environment plugin;
21+
22+
@Subcommand("get")
23+
@CommandCompletion("@keys")
24+
public void getEnv(CommandSender sender, String key) {
25+
Object value = plugin.getEnv(key);
26+
sender.sendMessage(
27+
formatKey(key) + ChatColor.GRAY + ": " + (value == null ? NOT_SET : formatValue(value)));
28+
}
29+
30+
@Subcommand("set")
31+
@CommandCompletion("@keys *")
32+
public void set(CommandSender sender, String key, String value) {
33+
Object existing = plugin.getEnv(key);
34+
plugin.setEnv(key, value);
35+
36+
if (existing != null) {
37+
sender.sendMessage(
38+
formatKey(key)
39+
+ ChatColor.GRAY
40+
+ " updated from "
41+
+ formatValue(existing)
42+
+ ChatColor.GRAY
43+
+ " to "
44+
+ formatValue(value));
45+
return;
46+
}
47+
48+
sender.sendMessage(formatKey(key) + ChatColor.GRAY + " set to " + formatValue(value));
49+
}
50+
51+
@Subcommand("del")
52+
@CommandCompletion("@keys")
53+
public void delete(CommandSender sender, String key) {
54+
boolean deleted = plugin.deleteEnv(key);
55+
56+
if (!deleted) {
57+
sender.sendMessage(formatKey(key) + ChatColor.RED + " has not been set!");
58+
return;
59+
}
60+
61+
sender.sendMessage(formatKey(key) + ChatColor.GREEN + " has been deleted");
62+
}
63+
64+
@Default
65+
@Subcommand("list|ls")
66+
public void list(CommandSender sender) {
67+
Set<String> keys = plugin.getKeys();
68+
69+
if (keys.isEmpty()) {
70+
sender.sendMessage(ChatColor.RED + "No environment variables set!");
71+
return;
72+
}
73+
74+
sender.sendMessage(
75+
ChatColor.GOLD
76+
+ ChatColor.BOLD.toString()
77+
+ "Environment Variables"
78+
+ ChatColor.GRAY
79+
+ ChatColor.BOLD.toString()
80+
+ ": ("
81+
+ ChatColor.DARK_GREEN
82+
+ ChatColor.BOLD.toString()
83+
+ keys.size()
84+
+ ChatColor.GRAY
85+
+ ChatColor.BOLD.toString()
86+
+ ")");
87+
88+
for (String key : keys) {
89+
Object value = plugin.getEnv(key);
90+
String formattedValue = formatValue(value);
91+
92+
sender.sendMessage(
93+
ChatColor.GOLD + " ● " + formatKey(key) + ChatColor.GRAY + ": " + formattedValue);
94+
}
95+
}
96+
97+
private String formatValue(Object value) {
98+
return ChatColor.GREEN + value.toString();
99+
}
100+
101+
private String formatKey(String key) {
102+
return ChatColor.YELLOW + key;
103+
}
104+
}

0 commit comments

Comments
 (0)