-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
348 additions
and
0 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,70 @@ | ||
*.class | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
# ========================= | ||
# Operating System Files | ||
# ========================= | ||
|
||
# OSX | ||
# ========================= | ||
|
||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear on external disk | ||
.Spotlight-V100 | ||
.Trashes | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
# Windows | ||
# ========================= | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
# ZEINTELLIJ | ||
.idea | ||
*.iml | ||
workspace.xml | ||
tasks.xml | ||
.idea/libraries | ||
.idea/copyright | ||
out/ | ||
target/ | ||
*.MF | ||
*.name |
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,80 @@ | ||
<?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>com.robomwm</groupId> | ||
<artifactId>GrandioseAPI</artifactId> | ||
<version>1.0</version> | ||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
<repositories> | ||
<repository> | ||
<id>destroystokyo-repo</id> | ||
<url>https://repo.destroystokyo.com/repository/maven-public/</url> | ||
</repository> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
<build> | ||
<finalName>${project.name}</finalName> | ||
<resources> | ||
<resource> | ||
<directory>${basedir}/src/main/resources</directory> | ||
<filtering>true</filtering> | ||
<includes> | ||
<include>plugin.yml</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>2.3</version> | ||
<configuration> | ||
<artifactSet> | ||
<includes> | ||
<include>com.github.RoboMWM:UsefulUtil</include> | ||
</includes> | ||
</artifactSet> | ||
<relocations> | ||
<relocation> | ||
<pattern>me.robomwm.usefulutil</pattern> | ||
<shadedPattern>com.robomwm.grandioseapi</shadedPattern> | ||
</relocation> | ||
</relocations> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.destroystokyo.paper</groupId> | ||
<artifactId>paper-api</artifactId> | ||
<version>1.12.2-R0.1-SNAPSHOT</version> | ||
<type>jar</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.RoboMWM</groupId> | ||
<artifactId>UsefulUtil</artifactId> | ||
<version>1.23</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
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,39 @@ | ||
package com.robomwm.grandioseapi; | ||
|
||
import com.robomwm.grandioseapi.player.GrandPlayerManager; | ||
import me.robomwm.usefulutil.UsefulUtil; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
/** | ||
* Created on 3/8/2018. | ||
* | ||
* Welcome to the GrandioseAPI, which is mostly a collection of persistent wrappers for plugins to share. | ||
* | ||
* Feel free to PR whatever you want. | ||
* However, if your contribution doesn't require any persistence, you might be better off contributing to UsefulUtil. | ||
* UsefulUtil is currently located at https://github.com/RoboMWM/UsefulUtil | ||
* | ||
* @author RoboMWM | ||
*/ | ||
public class GrandioseAPI extends JavaPlugin | ||
{ | ||
private GrandPlayerManager grandPlayerManager; | ||
|
||
public GrandPlayerManager getGrandPlayerManager() | ||
{ | ||
return grandPlayerManager; | ||
} | ||
|
||
public void onEnable() | ||
{ | ||
saveConfig(); //Ensure directory is created | ||
|
||
//Add your classes here | ||
grandPlayerManager = new GrandPlayerManager(this); | ||
} | ||
|
||
public void onDisable() | ||
{ | ||
grandPlayerManager.onDisable(); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/main/java/com/robomwm/grandioseapi/player/GrandPlayer.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,91 @@ | ||
package com.robomwm.grandioseapi.player; | ||
|
||
import me.robomwm.usefulutil.UsefulUtil; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.io.File; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Created on 3/8/2018. | ||
* | ||
* Primarily for holding "persistent metadata" for a Player | ||
* Which means just sharing a YamlConfiguration, lol. | ||
* | ||
* @author RoboMWM | ||
*/ | ||
public class GrandPlayer | ||
{ | ||
private JavaPlugin plugin; | ||
private OfflinePlayer offlinePlayer; | ||
private YamlConfiguration yaml; | ||
|
||
GrandPlayer(JavaPlugin plugin, OfflinePlayer offlinePlayer) | ||
{ | ||
this.offlinePlayer = offlinePlayer; | ||
yaml = UsefulUtil.loadOrCreateYamlFile(plugin, "grandPlayers" + File.separator + offlinePlayer.getUniqueId().toString()); | ||
} | ||
|
||
public OfflinePlayer getOfflinePlayer() | ||
{ | ||
return offlinePlayer; | ||
} | ||
|
||
public YamlConfiguration getYaml() | ||
{ | ||
return yaml; | ||
} | ||
|
||
public void saveYaml() | ||
{ | ||
UsefulUtil.saveYamlFileDelayed(plugin, "grandPlayers" + File.separator + offlinePlayer.getUniqueId().toString(), yaml); | ||
} | ||
|
||
public boolean saveYamlNow() | ||
{ | ||
return UsefulUtil.saveYamlFile(plugin, "grandPlayers" + File.separator + offlinePlayer.getUniqueId().toString(), yaml); | ||
} | ||
|
||
/** | ||
* Gets the color of the player's name | ||
* @return the stored color, or a random one determined from the player's UUID. | ||
*/ | ||
public ChatColor getNameColor() | ||
{ | ||
String color = yaml.getString("nameColor"); | ||
if (color == null) | ||
{ | ||
//Get hash code of player's UUID | ||
int colorCode = offlinePlayer.getUniqueId().hashCode(); | ||
//Ensure number is positive | ||
colorCode = Math.abs(colorCode); | ||
|
||
String[] acceptableColors = "2,3,4,5,6,9,a,b,c,d,e".split(","); | ||
//Divide hash code by length of acceptableColors, and use remainder | ||
//to determine which index to use (like a hashtable/map/whatever) | ||
colorCode = (colorCode % acceptableColors.length); | ||
return ChatColor.getByChar(acceptableColors[colorCode]); | ||
} | ||
return ChatColor.valueOf(color); | ||
} | ||
|
||
public void setNameColor(ChatColor color) | ||
{ | ||
yaml.set("nameColor", color.name()); | ||
saveYaml(); | ||
} | ||
|
||
//Convenience (basically useless other than minimizing the amount of chars in a call so feel free to do this busywork if you wanna | ||
public Object get(String key) | ||
{ | ||
return yaml.get(key); | ||
} | ||
|
||
public String getString(String key) | ||
{ | ||
return yaml.getString(key); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/robomwm/grandioseapi/player/GrandPlayerManager.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,62 @@ | ||
package com.robomwm.grandioseapi.player; | ||
|
||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created on 3/8/2018. | ||
* | ||
* @author RoboMWM | ||
*/ | ||
public class GrandPlayerManager | ||
{ | ||
private JavaPlugin plugin; | ||
private long autoSaveInterval; | ||
private Map<OfflinePlayer, GrandPlayer> grandPlayers = new HashMap<>(); | ||
|
||
public GrandPlayerManager(JavaPlugin plugin) | ||
{ | ||
FileConfiguration config = plugin.getConfig(); | ||
|
||
ConfigurationSection grandSection = config.getConfigurationSection("grandPlayer"); | ||
if (grandSection == null) | ||
grandSection = config.createSection("grandPlayer"); | ||
|
||
grandSection.addDefault("autoSaveInterval", 0); | ||
|
||
config.options().copyDefaults(); | ||
|
||
autoSaveInterval = grandSection.getInt("autoSaveInterval"); | ||
|
||
if (autoSaveInterval < 1) | ||
return; | ||
new BukkitRunnable() | ||
{ | ||
@Override | ||
public void run() | ||
{ | ||
for (GrandPlayer grandPlayer : grandPlayers.values()) | ||
grandPlayer.saveYamlNow(); | ||
} | ||
}.runTaskTimer(plugin, autoSaveInterval, autoSaveInterval); | ||
} | ||
|
||
public void onDisable() | ||
{ | ||
for (GrandPlayer grandPlayer : grandPlayers.values()) | ||
grandPlayer.saveYamlNow(); | ||
} | ||
|
||
public GrandPlayer getGrandPlayer(OfflinePlayer player) | ||
{ | ||
if (!grandPlayers.containsKey(player)) | ||
grandPlayers.put(player, new GrandPlayer(plugin, player)); | ||
return grandPlayers.get(player); | ||
} | ||
} |
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,6 @@ | ||
name: GrandioseAPI | ||
main: com.robomwm.grandioseapi.GrandioseAPI | ||
version: ${project.version} | ||
author: RoboMWM | ||
description: A fat, grand API that really desires you to PR your API desires. | ||
website: https://github.com/MLG-Fortress/GrandioseAPI |