Initial Commit

This commit is contained in:
Aubri Seebauer committed 2023-04-20 22:58:37 -04:00
commit d97d25e7c6
5 files changed
+401

No files matched your search

+113
View File
@@ -0,0 +1,113 @@
# User-specific stuff
.idea/
*.iml
*.ipr
*.iws
# IntelliJ
out/
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml
# Common working directory
run/
+74
View File
@@ -0,0 +1,74 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.aubrithehuman</groupId>
<artifactId>EntityBingo</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>EntityBingo</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,177 @@
package org.aubrithehuman.entitybingo;
import org.bukkit.Bukkit;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
/**
* Manages file IO & Deletion for other data classes.
*/
public class DataManager {
private static DumperOptions options;
private static EntityBingo plugin;
public static void init() {
plugin = EntityBingo.getInstance();
createFolders();
genDefaultFiles();
}
private static String dataFolder = "plugins" + File.separator + "EntityBingo" + File.separator + "data";
/**
* Saves data into a .yml format
* @param filePath - File's path after <PLUGIN>/Data/
* @param map - Map to be saved
*/
public static void saveData(String filePath, HashMap<String,Object> map) {
File file = getFile(filePath);
PrintWriter writer = null;
try {
writer = new PrintWriter(file);
} catch (FileNotFoundException e) {
Bukkit.getLogger().info("Encountered error when creating PrintWriter for " + filePath);
return;
}
if (options == null) {
options = new DumperOptions();
options.setIndent(2);
options.setPrettyFlow(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
}
Yaml yaml = new Yaml(options);
yaml.dump(map, writer);
writer.close();
}
/**
* Gets the data back as a HashMap
* @param filePath - FilePath of data
* @return HashMap of data or null
*/
public static HashMap<String,Object> getData(String filePath) {
File file = getFile(filePath);
return getData(file);
}
/**
* Gets the data back as a HashMap
* @param file - Data file
* @return HashMap of data or null
*/
public static HashMap<String,Object> getData(File file) {
if (!file.exists()) {
Bukkit.getLogger().info("Attempted to retrieve non-existant file: " + file.getPath());
return null;
}
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
Bukkit.getLogger().info("Encountered error when creating FileInputStream for " + file.getPath());
return null;
}
Yaml yaml = new Yaml();
HashMap<String, Object> data = yaml.load(inputStream);
try {
inputStream.close();
} catch (IOException e) {
Bukkit.getLogger().info(e.getMessage());
}
return data;
}
/**
* Deletes the specified file
* @param filePath - FilePath of deletion
* @return Boolean of success
*/
public static boolean deleteFile(String filePath) {
File file = getFile(filePath);
if (!file.exists()) {
Bukkit.getLogger().info("Attempted to retrieve non-existant file: " + filePath + ".yml");
return false;
}
try {
return Files.deleteIfExists(file.toPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
/**
* Converts filePath into File
* @param path - File's path within data folder
* @return File or null
*/
private static File getFile(String path) {
path = dataFolder + File.separator + path;
File file = new File(path);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
Bukkit.getLogger().info("Encountered error when creating file - " + path);
return null;
}
}
return file;
}
/**
* Creates Default Files
*/
private static void genDefaultFiles() {
List<String> paths = Arrays.asList(
"scoreboard.yml"
);
for (String path : paths) {
File file = new File(dataFolder + File.separator + path);
if (!file.exists()) {
HashMap<String, Object> data = new HashMap<>();
data.put("players", new ArrayList<String>());
saveData(path, data);
EntityBingo.getInstance().getLogger().info("Couldn't find file \"" + path + "\", generated default.");
} else {
EntityBingo.getInstance().getLogger().info("Found existing scoreboard file at " + dataFolder + File.separator + path);
}
}
}
/**
* Initial creation of all needed folders
*/
private static void createFolders() {
List<String> paths = Arrays.asList(
"plugins" + File.separator + "EconomyTracker" + File.separator + "data"
);
for (String path : paths) {
File file = new File(path);
if (!file.exists()) {
file.mkdirs();
Bukkit.getLogger().info("Couldn't find folder \"" + path + "\", generated default.");
}
}
}
}
@@ -0,0 +1,33 @@
package org.aubrithehuman.entitybingo;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import javax.swing.text.html.parser.Entity;
public final class EntityBingo extends JavaPlugin implements Listener {
static EntityBingo instance;
@Override
public void onEnable() {
instance = this;
this.saveDefaultConfig();
this.getServer().getPluginManager().registerEvents(this, this);
DataManager.init();
this.getLogger().info("EntityBingo loaded");
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
public static EntityBingo getInstance() {
return instance;
}
}
+4
View File
@@ -0,0 +1,4 @@
name: EntityBingo
version: '${project.version}'
main: org.aubrithehuman.entitybingo.EntityBingo
api-version: 1.19