Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
Signed-off-by: CasieBarie <[email protected]>
  • Loading branch information
CasieBarie committed Oct 8, 2023
1 parent 5f3f042 commit 48f1920
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 126 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
# KeesLib
<p><a href="https://github.com/CasieBarieDev/KeesLib/releases/latest"><img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/CasieBarieDev/KeesLib?label=Release&logo=github"></a> <img alt="GitHub code size in bytes" src="https://img.shields.io/github/languages/code-size/CasieBarieDev/KeesLib?color=red&label=Size&logo=Github"> <a href="https://github.com/CasieBarieDev/KeesLib/blob/main/LICENSE"><img alt="GitHub" src="https://img.shields.io/github/license/CasieBarieDev/KeesLib?label=License&logo=Github"></a> <a href="https://jitpack.io/#dev.casiebarie/keeslib"><img alt="JitPack" src="https://img.shields.io/jitpack/version/dev.casiebarie/keeslib?color=lime&label=JitPack&logo=azurepipelines"></a></p>
<p><a href="https://www.casiebarie.dev/Plugins/KeesLib"><img alt="Website" src="https://img.shields.io/static/v1?label=Website&message=KeesLib&color=yellow&logo=dev.to"></a> <a href="https://github.com/CasieBarieDev/KeesLib/releases/latest"><img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/CasieBarieDev/KeesLib?label=Release&logo=github"></a> <img alt="GitHub code size in bytes" src="https://img.shields.io/github/languages/code-size/CasieBarieDev/KeesLib?color=red&label=Size&logo=Github"> <a href="https://github.com/CasieBarieDev/KeesLib/blob/main/LICENSE"><img alt="GitHub" src="https://img.shields.io/github/license/CasieBarieDev/KeesLib?label=License&logo=Github"></a> <a href="https://jitpack.io/#dev.casiebarie/keeslib"><img alt="JitPack" src="https://img.shields.io/jitpack/version/dev.casiebarie/keeslib?color=lime&label=JitPack&logo=azurepipelines"></a></p>
<br/>

A simple library for my plugins!
More info soon on my [website](https://www.casiebarie.dev/404).

<br/>

## Patch Notes:
### [v1.1.0](https://github.com/CasieBarieDev/KeesLib/releases/tag/1.0.3)
- **Added** | A new builder for the UpdateChecker.
- **Added** | `createLogger()` - Changes the prefix of the plugin logger to the value 'Prefix:' in the plugin.yml with ChatColor support.
- **Changed** | `isLegacy(Double lowestVerion, Double highestVersion)` - This will no longer use the BukkitVersions enum and no longer shuts down the plugin when the version is too high.
- **Removed** | `BukkitVersions` enum.

### [v1.0.2](https://github.com/CasieBarieDev/KeesLib/releases/tag/1.0.2)
- **Added** | Javadocs

### [v1.0.1](https://github.com/CasieBarieDev/KeesLib/releases/tag/1.0.1)
- **Fix** | Build on Jitpack

### [v1.0.0](https://github.com/CasieBarieDev/KeesLib/releases/tag/1.0.0) _(Initial release)_
- **Added** | `hasPlaceholerAPI()` | Returns true if [PlaceholderAPI](https://www.spigotmc.org/resources/placeholderapi.6245) is installed.
- **Added** | `isLegacy(BukkitVersions lowestVersion, BukkitVersions highestVersion)` | Checks if the server is legacy and disables the plugin if the version is not supported.
- **Added** | `hasVault(Boolean economy, Boolean permissions, Boolean chat)` | Checks if [Vault](https://www.spigotmc.org/resources/vault.34315/) and the servicemanagers are enabled on the server.
- **Added** | `updateChecker(Integer recourceID, ChatColor borderColor, ChatColor textColor, String character, String permission, Double frequencyHours)` | A fancy update checker!
- **Added** | `hex(String msg)` | Translates all the #HEX codes in the message to ChatColor codes.
17 changes: 5 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?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>me.casiebarie.keeslib</groupId>
<groupId>dev.casiebarie.keeslib</groupId>
<artifactId>KeesLib</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>
<url>https://github.com/CasieBarieDev/KeesLib</url>

<!-- SOME INFO ABOUT MY ORGANIZATION -->
<organization>
<name>CasieBarie Development</name>
<url>https://www.casiebariedev.ga/</url>
<url>https://www.casiebarie.dev/</url>
</organization>

<properties>
Expand All @@ -34,16 +34,9 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<version>1.20.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<classifier>javadoc</classifier>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
Expand All @@ -65,7 +58,7 @@
</goals>
</execution>
</executions>
</plugin>
</plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>8</source><target>8</target></configuration></plugin>
</plugins>
</build>
</project>
33 changes: 0 additions & 33 deletions src/main/java/dev/casiebarie/keeslib/BukkitVersions.java

This file was deleted.

105 changes: 74 additions & 31 deletions src/main/java/dev/casiebarie/keeslib/KeesLib.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.casiebarie.keeslib;

import com.google.common.primitives.Doubles;
import net.md_5.bungee.api.ChatColor;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.economy.Economy;
Expand All @@ -10,14 +11,15 @@
import javax.annotation.Nonnull;
import java.security.Permission;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* A simple library for my plugins!
* @author CasieBarie
* @version 1.0.2
* @version 1.1.0
*/
public class KeesLib {
final JavaPlugin plugin;
Expand All @@ -27,34 +29,32 @@ public class KeesLib {
*/
public KeesLib(@Nonnull JavaPlugin plugin) {this.plugin = plugin;}
/**
* @return {@code true} when PlaceholderAPI is enabled in the server.
* @return {@code true} when <a href=https://www.spigotmc.org/resources/placeholderapi.6245/>PlaceholderAPI</a> is enabled in the server.
* @since 1.0.0
*/
public boolean hasPlaceholerAPI() {return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;}
/**
* Checks if the server is legacy and disables the plugin if the version is not supported.
* @param lowestVersion The lowest supported minecraft version.
* @param highestVersion The highest supported minecraft version.
* Checks if the server is legacy and disables the plugin if the lowest version is not supported.
* @param lowestVersion The lowest supported minecraft version (Eg. 1.8)
* @param highestVersion The highest tested minecraft version.
* @return {@code true} if the server has a legacy version.
* @since 1.0.0
*/
public boolean isLegacy2(@Nonnull BukkitVersions lowestVersion, @Nonnull BukkitVersions highestVersion) {
String bukkitVersion = plugin.getServer().getClass().getPackage().getName().replace("org.bukkit.craftbukkit.","");
int lowestVersionIndex = lowestVersion.ordinal();
int highestVersionIndex = highestVersion.ordinal();
BukkitVersions bukkitVersionE = null;
for(BukkitVersions enumVersion : BukkitVersions.values()) {if(enumVersion.name().equals(bukkitVersion)) {bukkitVersionE = enumVersion;}}
if(bukkitVersionE.ordinal() < lowestVersionIndex || bukkitVersionE.ordinal() > highestVersionIndex) {
plugin.getLogger().log(Level.SEVERE, "Unsupported bukkit version! Disabling plugin...");
public boolean isLegacy(@Nonnull Double lowestVersion, Double highestVersion) {
double bukkitVersion = Double.parseDouble(Bukkit.getBukkitVersion().split("-")[0]);
if(bukkitVersion < lowestVersion) {
plugin.getLogger().log(Level.SEVERE, "Unsupported " + Bukkit.getName() + " version! Disabling plugin...");
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
return false;
} return bukkitVersionE.isLegacy;
} if(highestVersion != null) {if(bukkitVersion > highestVersion) {plugin.getLogger().warning("This version of " + Bukkit.getName() + " is not officially supported! Proceed with caution!");}}
double[] legacyVersions = {1.8, 1.9, 1.10, 1.11, 1.12};
return (Doubles.contains(legacyVersions, bukkitVersion));
}
/**
* @param economy Set to {@code true} if you need Economy.
* @param permissions Set to {@code true} if you need Permissions.
* @param chat Set to {@code true} if you need Chat.
* @return {@code true} If <a href="https://www.spigotmc.org/resources/vault.34315/">Vault</a> is enabled and all the servicemanagers are registered.
* @return {@code true} if <a href="https://www.spigotmc.org/resources/vault.34315/">Vault</a> is enabled and all the servicemanagers are registered.
* @since 1.0.0
*/
public boolean hasVault(@Nonnull Boolean economy, @Nonnull Boolean permissions, @Nonnull Boolean chat) {
Expand All @@ -65,20 +65,6 @@ public boolean hasVault(@Nonnull Boolean economy, @Nonnull Boolean permissions,
if(chat) {providers.add(plugin.getServer().getServicesManager().getRegistration(Chat.class));}
return !providers.contains(null);
}
/**
* A fancy UpdateChecker to let server owners know when there is an new update.
* It shows the new update with a download link.
* @param recourceID Spigot recource ID
* @param borderColor Color of the fancy border.
* @param textColor Color of the text.
* @param character Character the border is made of.
* @param permission Players with this permission will receive a message when there is a new update.
* @param frequencyHours Check frequency in hours.
* @since 1.0.0
*/
public void updateChecker(@Nonnull Integer recourceID, @Nonnull ChatColor borderColor, @Nonnull ChatColor textColor, @Nonnull String character, @Nonnull String permission, @Nonnull Double frequencyHours) {
new UpdateChecker(plugin, recourceID, borderColor, textColor, character, permission, frequencyHours).startChecking();
}
/**
* Translates all the {@code #HEX} codes in the message to {@link ChatColor} codes.
* @param msg Message to translate.
Expand All @@ -90,8 +76,65 @@ public String hex(@Nonnull String msg) {
Matcher matcher = pattern.matcher(msg);
while(matcher.find()) {
String color = msg.substring(matcher.start(), matcher.end());
msg = msg.replace(color, ChatColor.of(color) + "");
msg = msg.replace(color, String.valueOf(ChatColor.of(color)));
matcher = pattern.matcher(msg);
} return ChatColor.translateAlternateColorCodes('&', msg);
}
/**
* Changes the prefix of the plugin logger to the value {@code Prefix:} in the {@code plugin.yml} with {@link ChatColor} support.
* @return a new instance of {@link Logger}.
* @since 1.0.3
*/
public Logger createLogger() {return new Log(plugin);}
/**
* Fancy updatechecker.
* @param resourceID Recource ID of Spigot.
* @return the new reference to the {@link UpdateChecker}.
* @since 1.0.0
*/
public UpdateChecker updateChecker(@Nonnull Integer resourceID) {return new UpdateChecker(resourceID);}
public class UpdateChecker {
protected Integer recourceID;
protected ChatColor borderColor = ChatColor.WHITE, textColor = ChatColor.WHITE;
protected Character character = '#';
protected String permission = "";
protected Long frequency = 1L;
protected TimeUnit timeUnit = TimeUnit.HOURS;
/**
* Sets the border color of the message.
* @param color Default: {@code ChatColor.WHITE}.
* @return a reference to this object.
*/
public UpdateChecker setBorderColor(@Nonnull ChatColor color) {borderColor = color; return this;}
/**
* Sets the text color of the message.
* @param color Default: {@code ChatColor.WHITE}.
* @return a reference to this object.
*/
public UpdateChecker setTextColor(@Nonnull ChatColor color) {textColor = color; return this;}
/**
* Sets the bordor character surrounding the message.
* @param character Default: {@code @}.
* @return a reference to this object.
*/
public UpdateChecker setBorderCharacter(@Nonnull Character character) {this.character = character; return this;}
/**
* The permission a player must have to receive the update notice ingame.
* @param permission Default: {@code ""}.
* @return a reference to this object.
*/
public UpdateChecker setPermission(@Nonnull String permission) {this.permission = permission; return this;}
/**
* Sets the frequency of checks.
* @param frequency Default: {@code 1L}.
* @param timeUnit Default: {@code TimeUnit.HOURS}.
* @return a reference to this object.
*/
public UpdateChecker setUpdateFrequency(@Nonnull Long frequency, @Nonnull TimeUnit timeUnit) {this.frequency = frequency; this.timeUnit = timeUnit; return this;}
public UpdateChecker(Integer recourceID) {this.recourceID = recourceID;}
/**
* Starts the checking!
*/
public void startChecking() {new dev.casiebarie.keeslib.UpdateChecker(plugin, this).start();}
}
}
24 changes: 24 additions & 0 deletions src/main/java/dev/casiebarie/keeslib/Log.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.casiebarie.keeslib;

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

public class Log extends Logger {
final String prefix;
public Log(JavaPlugin plugin) {
super(plugin.getName(), null);
prefix = plugin.getDescription().getPrefix();
setParent(plugin.getServer().getLogger());
setLevel(Level.ALL);
}

@Override
public void log(LogRecord record) {
if(!record.getLevel().equals(Level.INFO)) {super.log(record); return;}
Bukkit.getConsoleSender().sendMessage(prefix + "§r " + record.getMessage());
}
}
Loading

0 comments on commit 48f1920

Please sign in to comment.