Major update - 1.4 (#8)

* Update gradle

* testing

* Major update - 1.4

* Update README.md

* Resolve merge conflicts
This commit is contained in:
NotAlexNoyle authored and GitHub committed 2024-07-17 21:31:57 -04:00
1 parent a66c1e008b
commit a204510516
33 files changed
+1696 -830

No files matched your search

+13
View File
@@ -1,3 +1,16 @@
**1.4:**
- Added TrueOG Message API (supports modern + legacy formatting in the same message, &* for rainbow, and MiniPlaceholder expansion).
- Added TrueOG MiniPlaceholderAPI (currently supports expansion. Creation coming later.)
- Added MiniPlaceholder <player_display_name> (LuckPerms colors coming later.)
- Added mock Bamboo Planks.
- Mock Bamboo Wood is now crafted from 2x2 mock Bamboo Planks.
- Added permissions for every command.
- Major Refactoring.
- Improved error handling.
- Improved documentation.
- Improved config file.
**1.3.3:**
- Update gradle build.
+72 -27
View File
@@ -1,54 +1,99 @@
# Utilities-OG
A collection of utilities and APIs used by [TrueOG Network](https://true-og.net/). Developed by christianniehaus & NotAlexNoyle.
Current Target: Purpur 1.19.4
Authors: Barny1094875.
<h3>To build:</h3>
## Building:
./gradlew build
The resulting .jar file will be in build/libs
This plugin houses various little tweaks used by the TrueOG Minecraft server.
At the moment, any config change requires a server restart to take effect.
*Current Features*
## Features:
- Phantom Toggle
* **Mock Bamboo:** Enables crafting mock bamboo planks from 2x2 bamboo and mock bamboo wood from 2x2 mock bamboo planks.
* **Chain Armor:** Enables crafting chain armor from chains.
* **Color Codes:** Displays information to players about Bukkit's chat color codes and their syntax.
* **MiniPlaceholderAPI:** Enables a custom, easy-to-use MiniPlaceholders API (**Note:** May require additional configuration for specific placeholders).
* **NoFlippy:** Prevents trapdoors from being flipped in WorldGuard regions where the "can-flippy" flag is set to DENY (Requires WorldGuard plugin).
* **TogglePhantoms:** Allows players to use the `/togglephantoms` command to turn phantom spawning on or off for themselves.
* **Ping:** Provides two commands: `/ping` (displays real player ping) and `/bing` (replicates vanilla /ping functionality).
* **Ranks Menu:** Displays information to players about available ranks at the [TrueOG Network Store](https://store.true-og.net).
Use /utilites togglephantoms to disable phantom spawning. Use it again to enable phantom spawning.
*Requires utilities.togglephantoms permission.*
**Warning:**
- Entity Cramming Disable
* **DisableEntityCramming (Default: false):** Disables entity cramming damage server-wide. This can cause lag if no other plugin manages entity limits. Enable this Module only if you have a separate plugin managing entity limitations.
Use /utilites togglecramming to disable entity cramming. use it again to enable entity cramming.
*Requires utilities.togglecramming permission.*
## Permissions:
- Ranks Menu
* **`utilities.about`**
* **Description:** Allows players to use the base `/utilities` command to get information about the plugin.
* **Default:** `op` (Server Operator)
* **`utilities.colorcodes`**
* **Description:** Grants permission to use the `/colorcodes` command to view Bukkit chat color code information.
* **Default:** `op` (Server Operator)
* **`utilities.togglephantoms`**
* **Description:** Allows players to use the `/togglephantoms` command to enable or disable phantom spawning for themselves.
* **Default:** `op` (Server Operator)
* **`utilities.togglecramming`**
* **Description:** Grants permission to use the `/togglecramming` command (if enabled) to manage entity cramming damage.
* **Default:** `op` (Server Operator)
* **`utilities.ranks`**
* **Description:** Allows players to use the `/ranks` command to view information about available ranks on the TrueOG Network Store.
* **Default:** `op` (Server Operator)
* **`utilities.ping`**
* **Description:** Grants permission to use the `/ping` (real ping) and `/bing` (mimics vanilla ping) commands.
* **Default:** `op` (Server Operator)
Use /utilities ranks to show the TrueOG store menu.
*Requires utilities.ranks permission.*
**Please note:** These permissions can be modified in the Utilities-OG configuration file config.yml.
- Ping Menu
### API Documentation:
Use /utilities ping to show your own ping, or /utilities ping <player> to show someone else's.
Also includes /bing which replicates the functionality of the default /ping in minecraft.
*Requires utilities.ping permission.*
**1. trueogSendMessage(Player player, String message)**
- Bamboo Wood
Send a message to the player with TrueOG formatting (supports legacy and modern formatting).
Allows crafting of bamboo wood prior to 1.20
```java
Player targetPlayer = Bukkit.getPlayer("USERNAME");
UtilitiesOG.trueogSendMessage(targetPlayer, "&6This is a &*message with <green>True&4OG <bold>formatting!");
```
- Chainmail Armour
**2. trueogExpandMiniPlaceholders(Player player, String input)**
Allows the crafting of chainmail armour with chains
Expands MiniPlaceholders within a string for the given player. (**Note:** Requires MiniPlaceholdersAPI to be enabled in the config).
- NoFlippy
```java
Player targetPlayer = Bukkit.getPlayer("SomePlayer");
String message = "Welcome back, <player_display_name>!";
TextComponent expandedMessage = UtilitiesOG.trueogExpandMiniPlaceholders(targetPlayer, message);
UtilitiesOG.trueogSendMessage(targetPlayer, expandedMessage);
```
Plugin made by NotAlexNoyle that has been merged in here. Prevents trapdoors being flipped in certain regions by certain groups
**3. ranksCommand():**
- ColorCodes
Returns a new instance of the RanksCommand class, allowing you to potentially customize its behavior in the future.
Another of NotAlexNoyle's plugins merged here. Reveals bukkit's color codes for chat formatting
```java
RanksCommand ranksCommand = UtilitiesOG.ranksCommand();
// Future configuration here.
```
**4. pingCommand():**
Returns a new instance of the PingCommand class, allowing you to potentially customize its behavior in the future.
```java
PingCommand pingCommand = UtilitiesOG.pingCommand();
// Future configuration here.
```
## TODO:
- LuckPerms colors for <player_display_name>.
- trueOGCreateMiniPlaceholderAPI.
- Customization options for the Ranks and Ping APIs.
+15 -13
View File
@@ -1,6 +1,6 @@
plugins {
java // Tell gradle this is a java project.
id("io.github.goooler.shadow") version "8.1.8"
id("io.github.goooler.shadow") version "8.1.8" // Import shadow plugin for dependency shading.
eclipse // Import eclipse plugin for IDE integration.
kotlin("jvm") version "1.9.23" // Import kotlin jvm plugin for kotlin/java integration.
}
@@ -11,7 +11,8 @@ java {
}
group = "me.barny1094875" // Declare bundle identifier.
version = "1.3.3" // Declare plugin version (will be in .jar).
version = "1.4" // Declare plugin version (will be in .jar).
val apiVersion = "1.19" // Declare minecraft server target version.
tasks.named<ProcessResources>("processResources") {
@@ -31,18 +32,18 @@ repositories {
mavenCentral()
maven {
url = uri("https://repo.purpurmc.org/snapshots")
url = uri("https://repo.purpurmc.org/snapshots") // Import the PurpurMC Maven Repository.
}
maven {
url = uri("https://repo.codemc.io/repository/maven-public/")
url = uri("https://repo.codemc.io/repository/maven-public/") // Import the CodeMC Maven Repository.
}
maven {
url = uri("https://maven.enginehub.org/repo/")
url = uri("https://maven.enginehub.org/repo/") // Import the EngineHub Maven Repository.
}
}
@@ -52,9 +53,10 @@ dependencies {
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.8") // Import WorldGuard API.
compileOnly("de.tr7zw:item-nbt-api-plugin:2.11.2") // Import NBT API.
compileOnly("io.github.miniplaceholders:miniplaceholders-api:2.2.3") // Import MiniPlaceholders API.
compileOnly("io.github.miniplaceholders:miniplaceholders-kotlin-ext:2.2.3") // Import MiniPlaceholders API helper.
}
tasks.withType<AbstractArchiveTask>().configureEach {
tasks.withType<AbstractArchiveTask>().configureEach { // Ensure reproducible builds.
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
@@ -71,28 +73,28 @@ tasks.jar {
tasks.shadowJar {
archiveClassifier.set("") // Use empty string instead of null
from("LICENSE") {
into("/")
from("LICENSE") { // Copies license file.
into("/") // Sets destination for license file within the completed .jar.
}
}
tasks.jar {
dependsOn("shadowJar")
dependsOn("shadowJar") // Ensures shadowJar gets run.
}
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.add("-parameters")
options.encoding = "UTF-8"
options.encoding = "UTF-8" // Use UTF-8 encoding universally.
options.isFork = true
}
kotlin {
jvmToolchain(17)
jvmToolchain(17) // Declare kotlin jvm toolchain version.
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
vendor = JvmVendorSpec.GRAAL_VM
languageVersion = JavaLanguageVersion.of(17) // Declare JDK version.
vendor = JvmVendorSpec.GRAAL_VM // Declare JDK distribution.
}
}
@@ -2,6 +2,7 @@
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.Listeners;
// Import libraries.
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
@@ -10,7 +11,8 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
// Import required libraries.
import me.barny1094875.utilitiesog.UtilitiesOG;
public class DisableEntityCramming implements Listener {
// Declare the EntityCrammingToggle Module with Bukkit Listeners.
public class DisableEntityCrammingListener implements Listener {
// Listen for entities being damaged.
@EventHandler
@@ -19,9 +21,10 @@ public class DisableEntityCramming implements Listener {
// If the damage is caused by entity cramming, do this...
if(event.getCause().equals(DamageCause.CRAMMING)) {
// If disabling entity cramming is set to "true" in config.yml, do this...
if(UtilitiesOG.config().getBoolean("disableEntityCramming")) {
// If the Disable Entity Cramming Module is enabled in config.yml, do this...
if(UtilitiesOG.config().getBoolean("EntityCrammingDisable") == true) {
// Cancel damage from entity cramming.
event.setCancelled(true);
}
@@ -1,36 +0,0 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.Listeners;
import me.barny1094875.utilitiesog.UtilitiesOG;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
public class DisablePhantomSpawns implements Listener {
// Listen for mob spawning events.
@EventHandler
public void disablePhantomSpawns(CreatureSpawnEvent event) {
// If the mob that spawned is a phantom, do this...
if (event.getEntityType().equals(EntityType.PHANTOM)) {
// Store the contents of phantomDisabledUsers.yml file as a YAML object.
YamlConfiguration phantomsAreDisabled = UtilitiesOG.getPhantomPreferences();
// get every player currently on the server in the world that the phantom spawned
for (Player player : Bukkit.getServer().getOnlinePlayers()
.stream()
.filter(p -> p.getWorld().equals(event.getEntity().getWorld()))
.filter(p -> phantomsAreDisabled.getBoolean(p.getUniqueId().toString()))
.toArray(Player[]::new)) {
// Check if the phantom is close enough to the player to count as their spawn.
if (event.getEntity().getLocation().distance(player.getLocation()) < 48) {
event.setCancelled(true);
}
}
}
}
}
@@ -0,0 +1,151 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.Listeners;
// Import libraries.
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import me.barny1094875.utilitiesog.UtilitiesOG;
import me.barny1094875.utilitiesog.internal.FlagRegistrationException;
// Declare the NoFlippy Module with Bukkit Listeners.
public class NoFlippyListener implements Listener {
// Declare instance of class as static so multiple players can use it.
private static NoFlippyListener instance;
// Return instance of class as static so multiple players can use it.
public static NoFlippyListener getInstance() {
// Pass back Listeners to main.
return instance;
}
// Listen for a player interacting with a trap-door.
@EventHandler
public void onInteract(PlayerInteractEvent event) {
// Get the nature of the interaction and store it.
Action action = event.getAction();
// Get the block that was interacted with and store it.
Block blockClicked = event.getClickedBlock();
// Get the player who interacted and store them.
Player player = event.getPlayer();
// Declare a container for the block type for null checking.
String blockContainerAsString = null;
try {
// Try storing the block type as a string. Throws NullPointerException if not applicable.
blockContainerAsString = blockClicked.getType().toString();
}
// If the block type was null, do this...
catch (NullPointerException error) {
// Do nothing.
return;
}
// If the interaction was with a trap door, do this...
if (blockContainerAsString.contains("TRAPDOOR")) {
// If the interaction was a right click, do this...
if (action.isRightClick()) {
// If the player does not have permission to flip trap doors, do this...
if (! player.hasPermission("noflippy.bypass")) {
// Get the location of the block the player tried to flip.
Location blockLocation = BukkitAdapter.adapt(blockClicked.getLocation());
// Instantiate a WorldGuard Region Container.
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
// Instantiate a WorldGuard Region Query.
RegionQuery query = container.createQuery();
// Get all regions at the location of the block.
ApplicableRegionSet set = query.getApplicableRegions(blockLocation);
// If the can-flippy WorldGuard Flag is set to DENY, for any region in the set, do this...
if (! set.testState(null, UtilitiesOG.getFlippyFlag())) {
// Cancel the trapdoor flip event.
event.setCancelled(true);
}
}
}
}
}
// Registers the WorldGuard Flag "can-flippy". Throws a custom exception in case of error.
public static StateFlag registerNoFlippyWorldGuardFlag(StateFlag FlippyFlags) throws FlagRegistrationException {
// Add the WorldGuard flag for an area where NoFlippy is active.
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
try {
// Create a flag with the name "my-custom-flag", defaulting to true.
StateFlag flag = new StateFlag("can-flippy", true);
// Register the new flag with WorldGuard.
registry.register(flag);
// Only return the flag if there was no error.
return flag;
}
// If there was a WorldGuard Flag conflict, do this...
catch (FlagConflictException error) {
// Log the WorldGuard Flag conflict to the server console.
UtilitiesOG.getPlugin().getLogger().severe("ERROR: can-flippy of the NoFlippy Module has a WorldGuard Flag conflict! " + error.getMessage());
// Pulls the WorldGuard Flag from the registry that some other plugin registered by the same name.
// Developer Note: You CAN use the existing flag, but this may cause conflicts - be sure to check type.
Flag<?> existing = registry.get("can-flippy");
// If the existing WorldGuard Flag is a StateFlag, do this...
if (existing instanceof StateFlag) {
// Return the existing WorldGuard Flag.
return (StateFlag) existing;
}
// If the existing WorldGuard Flag is not a StateFlag, do this...
else {
// Throw a custom exception that displays details about the issues with flag registration in the server console.
throw new FlagRegistrationException("Failed to register can-flippy flag due to conflict.", error);
}
}
}
}
@@ -0,0 +1,49 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.Listeners;
// Import libraries.
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import me.barny1094875.utilitiesog.UtilitiesOG;
// Declare the DisablePhantomSpawns Module with Bukkit Listeners.
public class TogglePhantomsListener implements Listener {
// Listen for mob spawning events.
@EventHandler
public void disablePhantomSpawns(CreatureSpawnEvent event) {
// If the mob that spawned is a phantom, do this...
if (event.getEntityType().equals(EntityType.PHANTOM)) {
// Store the contents of phantomDisabledUsers.yml file as a YAML object.
YamlConfiguration phantomsAreDisabled = UtilitiesOG.getPhantomPreferences();
// Get every player currently on the server in the world where the phantom spawned.
for (Player player : Bukkit.getServer().getOnlinePlayers().stream()
.filter(p -> p.getWorld().equals(event.getEntity().getWorld()))
.filter(p -> phantomsAreDisabled.getBoolean(p.getUniqueId().toString()))
.toArray(Player[]::new)) {
// Check if the phantom is close enough to the player to count as being their spawn.
if (event.getEntity().getLocation().distance(player.getLocation()) < 48) {
// Prevent the phantom from spawning.
event.setCancelled(true);
}
}
}
}
}
@@ -2,190 +2,313 @@
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
import me.barny1094875.utilitiesog.Listeners.DisableEntityCramming;
import me.barny1094875.utilitiesog.Listeners.DisablePhantomSpawns;
import me.barny1094875.utilitiesog.modules.*;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
// Import libraries.
import java.io.File;
import java.io.IOException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import com.sk89q.worldguard.protection.flags.StateFlag;
import me.barny1094875.utilitiesog.Listeners.DisableEntityCrammingListener;
import me.barny1094875.utilitiesog.Listeners.NoFlippyListener;
import me.barny1094875.utilitiesog.Listeners.TogglePhantomsListener;
import me.barny1094875.utilitiesog.commands.AboutCommand;
import me.barny1094875.utilitiesog.commands.BingCommand;
import me.barny1094875.utilitiesog.commands.ColorCodesCommand;
import me.barny1094875.utilitiesog.commands.PingCommand;
import me.barny1094875.utilitiesog.commands.RanksCommand;
import me.barny1094875.utilitiesog.commands.ToggleCrammingCommand;
import me.barny1094875.utilitiesog.commands.TogglePhantomsCommand;
import me.barny1094875.utilitiesog.internal.FlagRegistrationException;
import me.barny1094875.utilitiesog.internal.MiniPlaceholderAPI;
import me.barny1094875.utilitiesog.internal.Utils;
import me.barny1094875.utilitiesog.modules.ChainArmorModule;
import me.barny1094875.utilitiesog.modules.MockBambooModule;
import net.kyori.adventure.text.TextComponent;
// Declare main plugin class.
public final class UtilitiesOG extends JavaPlugin {
private File file;
private static UtilitiesOG plugin;
private static final MiniMessage mm = MiniMessage.miniMessage();
private static FileConfiguration config;
private static File phantomPreferencesFile;
private static YamlConfiguration phantomPreferences;
private static StateFlag FlippyFlag;
// Declare empty fields for use later.
private File file;
private static UtilitiesOG plugin;
private static FileConfiguration config;
private static File phantomPreferencesFile;
private static YamlConfiguration phantomPreferences;
private static StateFlag FlippyFlag;
@Override
public void onEnable() {
// When the plugin is enabled, do this...
@Override
public void onEnable() {
plugin = this;
// Populate the main class getter getPlugin().
plugin = this;
this.file = new File(this.getDataFolder(), "config.yml");
if (!this.file.exists()) {
this.saveDefaultConfig();
}
// Attempt to populate the file object with the config file.
this.file = new File(this.getDataFolder(), "config.yml");
config = this.getConfig();
// If the config file was not found, do this...
if (! this.file.exists()) {
phantomPreferencesFile = new File(this.getDataFolder(), "phantomDisabledUsers.yml");
try {
if (!phantomPreferencesFile.exists()) {
// Create the config file in the filesystem using the one in the assembled plugin .jar.
this.saveDefaultConfig();
phantomPreferencesFile.createNewFile();
}
}
} catch (IOException e) {
// Cast the config file from a File to a FileConfiguration.
config = this.getConfig();
this.getLogger().severe("Something went wrong when creating the phantom toggle cache file!");
// Attempt to populate the file object with the phantom toggle cache file.
phantomPreferencesFile = new File(this.getDataFolder(), "phantomDisabledUsers.yml");
}
try {
phantomPreferences = YamlConfiguration.loadConfiguration(phantomPreferencesFile);
// If the phantom toggle cache file was not found, do this...
if (! phantomPreferencesFile.exists()) {
// Set up each feature here, using the config to enable only that which is desired,
// be sure to label, using comments, what each block is enabling.
// Create the phantom toggle cache file in the filesystem using the one in the assembled plugin .jar.
phantomPreferencesFile.createNewFile();
// Enable the Phantom Toggle Module.
if (this.getConfig().getBoolean("PhantomToggle")) {
// Activate the Phantom Toggle Listener.
getServer().getPluginManager().registerEvents(new DisablePhantomSpawns(), this);
// Activate the Phantom Toggle Command.
this.getCommand("togglephantoms").setExecutor(new PhantomToggleModule());
}
// Enable the Entity Cramming Toggle Module.
if (this.getConfig().getBoolean("EntityCrammingDisable")) {
// Activate the Entity Cramming Toggle Listener.
getServer().getPluginManager().registerEvents(new DisableEntityCramming(), this);
// Activate the Entity Cramming Toggle Command.
this.getCommand("togglecramming").setExecutor(new EntityCrammingToggleModule());
}
// Enable the Ranks Module.
if (this.getConfig().getBoolean("RanksMenu")) {
// Activate the Ranks Command.
this.getCommand("ranks").setExecutor(new RanksModule());
}
// Enable the Ping Module.
if (this.getConfig().getBoolean("Ping")) {
// Enable the Ping command.
this.getCommand("ping").setExecutor(new PingModule());
// Enable the Bing command (replicates old /ping functionality).
this.getCommand("bing").setExecutor(new BingModule());
}
// Enable bamboo wood module
if (this.getConfig().getBoolean("BambooWood")) {
BambooWood.Enable();
}
// Enable chain armour module
if (this.getConfig().getBoolean("ChainArmour")) {
ChainArmour.Enable();
}
// Enable the ColorCodes module
if (this.getConfig().getBoolean("ColorCodes")) {
this.getCommand("colorcodes").setExecutor(new ColorCodes());
}
// Enable the NoFlippy module
if (this.getConfig().getBoolean("NoFlippy")) {
// check that WorldGuard is installed
if (getServer().getPluginManager().getPlugin("WorldGuard") == null) {
this.getLogger().severe("WorldGuard is not installed! Disabling NoFlippy...");
} else {
// Activate the NoFlippy Listener.
getServer().getPluginManager().registerEvents(new NoFlippy(), this);
}
}
}
// Register the primary /utilities command.
this.getCommand("utilities").setExecutor(new AboutModule());
}
// If there is a file IO error, do this...
catch (IOException error) {
}
// Log the problem with creating the phantom toggle cache file to the server console.
this.getLogger().severe("ERROR: Failed to create the phantom toggle cache file! " + error.getMessage());
@Override
public void onLoad() {
}
// Add the WorldGuard flag for an area where NoFlippy is active.
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
try {
// Cast the phantom toggle cache file from a File to a YamlConfiguration.
phantomPreferences = YamlConfiguration.loadConfiguration(phantomPreferencesFile);
// Create a flag with the name "my-custom-flag", defaulting to true.
StateFlag flag = new StateFlag("can-flippy", true);
// TrueOG Network Contributors: set up each feature below, using the config file to enable only that which is desirable by default.
// Be sure to label, using comments, which feature(s) each block is enabling.
// Register the new flag with WorldGuard.
registry.register(flag);
// FEATURE: Enable crafting chain armor using chains.
// If the Chain Armor Module is enabled in the config file, do this...
if (this.getConfig().getBoolean("ChainArmor")) {
// Only set the field if there was no error.
FlippyFlag = flag;
// Enable the Chain Armor Module.
ChainArmorModule.Enable();
} catch (FlagConflictException e) {
}
// Some other plugin registered a flag by the same name already.
// You can use the existing flag, but this may cause conflicts - be sure to check type.
Flag<?> existing = registry.get("can-flippy");
if (existing instanceof StateFlag) {
// FEATURE: Display information to the player about the syntax for bukkit's color codes.
// If the Color Codes Module is enabled in the config file, do this...
if (this.getConfig().getBoolean("ColorCodes")) {
FlippyFlag = (StateFlag) existing;
// If the Color Codes Module is enabled in the config file, do this...
this.getCommand("colorcodes").setExecutor(new ColorCodesCommand());
}
}
}
// FEATURE: Disable entity cramming server-wide. Entity cramming is when mobs pile up and cause damage to each other.
// WARNING: Make sure there is another plugin that establishes entity limits if this module is enabled. Otherwise the server will lag.
// If the Entity Cramming Toggle Module is enabled in the config file, do this...
if (this.getConfig().getBoolean("DisableEntityCramming")) {
}
// Activate the Entity Cramming Toggle Listener.
getServer().getPluginManager().registerEvents(new DisableEntityCrammingListener(), this);
// Activate the Entity Cramming Toggle Command.
this.getCommand("togglecramming").setExecutor(new ToggleCrammingCommand());
// Rank menu API.
public RanksModule ranksCommand() {
return new RanksModule();
}
}
// Ping API.
public PingModule pingCommand() {
return new PingModule();
}
// FEATURE: A custom, easy to use MiniPlaceholders API.
// If the MiniPlaceholdersAPI Module is enabled in the config file, do this...
if (this.getConfig().getBoolean("MiniPlaceholderAPI")) {
public static UtilitiesOG getPlugin() {
return plugin;
}
// Enable the TrueOG MiniPlaceholdersAPI Module.
MiniPlaceholderAPI miniPlaceholders = new MiniPlaceholderAPI();
public static FileConfiguration config() {
return config;
}
// Register our custom MiniPlaceholdersAPI Module with MiniPlaceholders.
miniPlaceholders.register();
public static MiniMessage getMM() {
return mm;
}
}
public static YamlConfiguration getPhantomPreferences() {
return phantomPreferences;
}
// FEATURE: Pre-1.20 Mock Bamboo Wood. Makes Bamboo craft into Oak Planks called "Bamboo Wood".
// If the Bamboo Wood Module is enabled in the config file, do this...
if (this.getConfig().getBoolean("MockBamboo")) {
public static File getPhantomDisabledPlayersFile() {
return phantomPreferencesFile;
}
// Enable the Bamboo Wood Module.
MockBambooModule.Enable();
// Share FlippyFlag with Listeners.
public static StateFlag getFlippyFlag() {
return FlippyFlag;
}
}
// Runs plugin asynchronously so multiple players can use it at once efficiently.
public BukkitTask runTaskAsynchronously(final Runnable run) {
// FEATURE: Prevent trap doors from being flipped in any WorldGuard regions with the "can-flippy" flag set to DENY.
// If the NoFlippy Module is enabled in the config file, do this...
if (this.getConfig().getBoolean("NoFlippy")) {
// Schedule Processes.
return this.getServer().getScheduler().runTaskAsynchronously(this, run);
// If WorldGuard is installed, do this...
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
}
// Activate the NoFlippy Listener.
getServer().getPluginManager().registerEvents(new NoFlippyListener(), this);
}
}
// If WorldGuard is not installed, do this...
else {
// Log WorldGuard not being found to the server console.
this.getLogger().severe("WorldGuard is not installed! Disabling NoFlippy...");
}
}
// FEATURE: A /ping command that returns a player's real ping.
// FEATURE: A /bing command that replicates the functionality of the default /ping command.
// If the Ping Module is enabled in the config file, do this...
if (this.getConfig().getBoolean("Ping")) {
// Enable the Ping command.
this.getCommand("ping").setExecutor(new PingCommand());
// Enable the Bing command.
this.getCommand("bing").setExecutor(new BingCommand());
}
// FEATURE: Display information to the player about the ranks available at the TrueOG Network Store (https://store.true-og.net/).
// If the Ranks Menu Module is enabled in the config file, do this...
if (this.getConfig().getBoolean("RanksMenu")) {
// Activate the Ranks Command.
this.getCommand("ranks").setExecutor(new RanksCommand());
}
// FEATURE: Enable individual players to toggle phantom spawning on or off with the command /togglephantoms.
// If the Phantom Toggle Module is enabled in the config file, do this...
if (this.getConfig().getBoolean("TogglePhantoms")) {
// Activate the Phantom Toggle Listener.
getServer().getPluginManager().registerEvents(new TogglePhantomsListener(), this);
// Activate the Phantom Toggle Command.
this.getCommand("togglephantoms").setExecutor(new TogglePhantomsCommand());
}
// FEATURE: Display meta-information about Utilities-OG. Always enabled.
// Enable the root /utilities command to display information about the plugin to the player.
this.getCommand("utilities").setExecutor(new AboutCommand());
}
// After the server loads, do this...
@Override
public void onLoad() {
try {
// Register the Flag "can-flippy" with WorldGuard, and make the it retrievable.
FlippyFlag = NoFlippyListener.registerNoFlippyWorldGuardFlag(FlippyFlag);
}
// If the WorldGuard Flag registration failed, do this...
catch (FlagRegistrationException error) {
// Log the WorldGuard Flag registration error to the server console.
this.getLogger().severe("ERROR: Failed to register the can-flippy Flag with WorldGuard. " + error.getMessage());
}
}
// Getter/API for TrueOG message formatting. Supports legacy Bukkit color codes. Case insensitive.
public static void trueogSendMessage(Player player, String message) {
// Forward the message to the server.
Utils.trueogMessage(player, message);
}
// API for TrueOG MiniPlaceholderAPI creation.
public static void trueogCreateMiniPlaceholder() {
// TODO: Implement the trueogCreateMiniPlaceholder API.
}
// Getter/API for TrueOG MiniPlaceholderAPI expansion.
public static TextComponent trueogExpandMiniPlaceholders(Player player, String input) {
// Expand all the MiniPlaceholders in a given String.
return MiniPlaceholderAPI.expandPlayerMiniPlaceholders(player, input);
}
// Getter/API for the Ranks Module.
public static RanksCommand ranksCommand() {
// Return a fresh Ranks Module.
return new RanksCommand();
}
// Getter/API for the Ping Module.
public static PingCommand pingCommand() {
// Return a fresh Ping Module.
return new PingCommand();
}
// Getter/API for Utilities-OG.
public static UtilitiesOG getPlugin() {
// Return the current Utilities-OG instance.
return plugin;
}
// Getter for the config file.
public static FileConfiguration config() {
// Return the config file in FileConfiguration form.
return config;
}
// Getter/API for the phantom toggle cache file.
public static File getPhantomDisabledPlayersFile() {
// Return the phantom toggle cache file.
return phantomPreferencesFile;
}
// Getter/API for the phantom toggle cache file in YAML form.
public static YamlConfiguration getPhantomPreferences() {
// Return the phantom toggle cache file in YAML form.
return phantomPreferences;
}
// Getter for the FlippyFlag state.
public static StateFlag getFlippyFlag() {
// Return the FlippyFlag for WorldGuard.
return FlippyFlag;
}
// Runs plugin asynchronously so multiple players can use it at once efficiently.
public BukkitTask runTaskAsynchronously(final Runnable run) {
// Schedule processes.
return this.getServer().getScheduler().runTaskAsynchronously(this, run);
}
}
@@ -0,0 +1,58 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.commands;
// Import libraries.
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.barny1094875.utilitiesog.internal.Utils;
// Declare the About Module with Bukkit Commands.
public class AboutCommand implements CommandExecutor {
// Command execution event handler using Bukkit's CommandManager.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// Store the required permission for the "about" (root /utilities) command for later reference.
String aboutPermission = "utilities.about";
// If the command was sent by an in-game player, do this...
if (sender instanceof Player) {
// Get the player object from the sender.
Player player = (Player) sender;
// If the player has permission to use /about, do this...
if (player.hasPermission(aboutPermission)) {
// Send a formatted about message to the player using the TrueOG Message API.
Utils.trueogMessage(player, "<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#FFAA00>A collection of utilities and APIs used by <#00AA00>True<#AA0000>OG<#FFAA00> <#FFFF55>Network<#FFAA00>. Developed by <#FFFF55>christianniehaus <#FFAA00>& <#FFFF55>NotAlexNoyle<#FFAA00>.");
}
// If the player does not have permission to use /about, do this...
else {
// Send a detailed, formatted permissions error message to the player.
Utils.permissionsErrorMessage(player, cmd.getName(), aboutPermission);
}
}
// If the command was sent by the server console, do this...
else {
// Send a detailed error message to the server console.
Utils.consoleUseErrorMessage(sender, cmd.getName(), aboutPermission);
}
// Healthy exit status.
return true;
}
}
@@ -0,0 +1,58 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.commands;
// Import libraries.
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.barny1094875.utilitiesog.internal.Utils;
// Declare the /bing command in the Ping Module with Bukkit Commands.
public class BingCommand implements CommandExecutor {
// Command execution event handler using Bukkit's CommandManager.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// Store the required permission for the /ping command for later reference.
String pingPermission = "utilities.ping";
// If the command was sent by an in-game player, do this...
if (sender instanceof Player) {
// Get the player object from the sender.
Player player = (Player) sender;
// If the player has permission to use the Ping Module, do this...
if (player.hasPermission(pingPermission)) {
// Send player a connection confirmation message with formatting using the TrueOG Message API.
Utils.trueogMessage(player, "<#FFFFFF> Bong!");
}
// If the player does not have permission to use the Ping Module, do this...
else {
// Send a detailed, formatted permissions error message to the player.
Utils.permissionsErrorMessage(player, cmd.getName(), pingPermission);
}
}
// If the command was sent by the server console, do this...
else {
// Send a detailed error message to the server console.
Utils.consoleUseErrorMessage(sender, cmd.getName(), pingPermission);
}
// Healthy exit status.
return true;
}
}
@@ -0,0 +1,81 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.commands;
// Import libraries.
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.barny1094875.utilitiesog.internal.Utils;
import net.kyori.adventure.text.minimessage.MiniMessage;
// Declare the ColorCodes Module with Bukkit Commands.
public class ColorCodesCommand implements CommandExecutor {
// Create an instance of the class for command runner.
private static ColorCodesCommand instance;
// Constructor for main class that returns itself.
public static ColorCodesCommand getInstance() {
// Forwards the class instance to the caller.
return instance;
}
// Command execution event handler using Bukkit's CommandManager.
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// Store the required permission for the /colorcodes command for later reference.
String colorCodesPermission = "utilities.colorcodes";
// If the command was sent by an in-game player, do this...
if (sender instanceof Player) {
// Cast the sender to a player object safely.
Player player = (Player) sender;
// If the player has permission to use /colorcodes, do this...
if (player.hasPermission(colorCodesPermission)) {
// Send the color code cheat sheet to the player.
// Uses MiniMessage directly so that the legacy color codes in the key are not processed.
player.sendMessage(MiniMessage.miniMessage().deserialize("<dark_aqua><bold>-=-=-=-=- <dark_purple>C<dark_aqua>o<green>l<yellow>o<red>r <aqua>C<light_purple>o<white>d<light_purple>e<aqua>s: -=-=-=-=-"));
player.sendMessage(MiniMessage.miniMessage().deserialize("&0 = <black>Black <reset> &1 = <dark_blue>Dark Blue"));
player.sendMessage(MiniMessage.miniMessage().deserialize("&2 = <dark_green>Dark Green <reset> &3 = <dark_aqua>Dark Aqua"));
player.sendMessage(MiniMessage.miniMessage().deserialize("&4 = <dark_red>Dark Red <reset> &5 = <dark_purple>Dark Purple"));
player.sendMessage(MiniMessage.miniMessage().deserialize("&6 = <gold>Gold <reset> &7 = <gray>Grey"));
player.sendMessage(MiniMessage.miniMessage().deserialize("&8 = <dark_gray>Dark Grey <reset> &9 = <blue>Blue"));
player.sendMessage(MiniMessage.miniMessage().deserialize("&a = <green>Green <reset> &b = <aqua>Aqua"));
player.sendMessage(MiniMessage.miniMessage().deserialize("&c = <red>Red <reset> &d = <light_purple>Light Purple"));
player.sendMessage(MiniMessage.miniMessage().deserialize("&e = <yellow>Yellow <reset> &f = <white>White"));
player.sendMessage(MiniMessage.miniMessage().deserialize("&k = <obfuscated>Magic <reset> &l = <bold>Bold"));
player.sendMessage(MiniMessage.miniMessage().deserialize("&m = <strikethrough>Strikethrough <reset> &n = <underlined>Underline"));
player.sendMessage(MiniMessage.miniMessage().deserialize("&o = <italic>Italic <reset> &r = Reset"));
}
// If the player does not have permission to use /colorcodes, do this...
else {
// Send a detailed, formatted permissions error message to the player.
Utils.permissionsErrorMessage(player, cmd.getName(), colorCodesPermission);
}
}
// If the command was sent by the server console, do this...
else {
// Send a detailed error message to the server console.
Utils.consoleUseErrorMessage(sender, cmd.getName(), colorCodesPermission);
}
// Healthy exit status.
return true;
}
}
@@ -0,0 +1,93 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.commands;
// Import libraries.
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.barny1094875.utilitiesog.internal.Utils;
// Declare the /ping command in the Ping Module with Bukkit Commands.
public class PingCommand implements CommandExecutor {
// Command execution event handler using Bukkit's CommandManager.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// Store the required permission for the /ping command for later reference.
String pingPermission = "utilities.ping";
// If the command was sent by an in-game player, do this...
if (sender instanceof Player) {
// Get the player object from the sender.
Player player = (Player) sender;
// If the player has permission to use /ping, do this...
if (player.hasPermission(pingPermission)) {
// If the player did not provide any arguments, do this...
if(args.length == 0) {
// Send player their own ping with formatting using the TrueOG Message API.
Utils.trueogMessage(player, ("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#00AA00>Your current ping is: <#FFAA00>" + player.getPing() + "<#00AA00>."));
}
// If the player provided one or more arguments, do this...
else if(args.length == 1) {
// Try to get the player that was specified.
Player target = Bukkit.getPlayer(args[0]);
// If the provided argument was a valid player, do this...
if(target != null) {
// Send player their specified player's ping with formatting using the TrueOG Message API.
Utils.trueogMessage(player, ("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#00AA00>" + target.getName() + "'s current ping is: <#FFAA00>" + target.getPing() + "<#00AA00>."));
}
// If the provided argument was not a valid player, do this...
else {
// Send a "player not found" error message with formatting using the TrueOG Message API.
Utils.trueogMessage(player, ("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#AA0000> ERROR: The player " + args[0] + " was not found!"));
}
}
// If there is more than one provided argument, do this...
else {
// Send a "too many arguments" error message with formatting using the TrueOG Message API.
Utils.trueogMessage(player, ("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#AA0000> ERROR: Too many arguments provided. Syntax: <#FFFF55>/ping <player>"));
}
}
// If the player does not have permission to use /ping, do this...
else {
// Send a detailed, formatted permissions error message to the player.
Utils.permissionsErrorMessage(player, cmd.getName(), pingPermission);
}
}
// If the command was sent by the server console, do this...
else {
// Send a detailed error message to the server console.
Utils.consoleUseErrorMessage(sender, cmd.getName(), pingPermission);
}
// Healthy exit status.
return true;
}
}
@@ -0,0 +1,150 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.barny1094875.utilitiesog.internal.Utils;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.minimessage.MiniMessage;
// Declare the Ranks Module with Bukkit Commands.
public class RanksCommand implements CommandExecutor {
// Command execution event handler using Bukkit's CommandManager.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// Store the required permission for the /ranks command for later reference.
String ranksPermission = "utilities.ranks";
// If the command was sent by an in-game player, do this...
if (sender instanceof Player) {
// Get the player object from the sender.
Player player = (Player) sender;
// If the player has permission to use /ranks, do this...
if (player.hasPermission(ranksPermission)) {
// If the player did not provide any arguments, do this...
if (args.length == 0) {
// Send the available ranks to the player, with clickable menus to get more information about each rank.
Utils.trueogMessage(player, "<bold><dark_purple>-=-=-=-=- <dark_green>True<dark_red>OG <aqua>Donation Store: <dark_purple>-=-=-=-=-");
Utils.trueogMessage(player, "");
Utils.trueogMessage(player, "Each donor rank requires the rank before it.");
Utils.trueogMessage(player, "");
Utils.trueogMessage(player, "<green>Rank Overview: <dark_aqua><underlined>https://shop.true-og.net");
Utils.trueogMessage(player, "");
Utils.trueogMessage(player, "<white>[OG] <gray>(<dark_green>$10 Once<gray>) <dark_aqua><underlined>https://true-og.net/og");
sendClickableMessage(player, "/ranks og");
Utils.trueogMessage(player, "");
Utils.trueogMessage(player,"<red>[OG Pro] <gray>(<dark_green>$50 Once<gray>) <dark_aqua><underlined>https://true-og.net/og-pro");
sendClickableMessage(player, "/ranks og-pro");
Utils.trueogMessage(player, "");
Utils.trueogMessage(player, "<dark_red><bold>[OG Master] <gray>(<gold>$10 Monthly<gray>) <dark_aqua><underlined>https://true-og.net/og-master");
sendClickableMessage(player, "/ranks og-master");
}
// If the player provided one or more arguments, do this...
else if (args.length == 1) {
// If the "OG" message was clicked, do this...
if (args[0].equalsIgnoreCase("og")) {
// Share "OG" benefits with the player with formatting using the TrueOG Message API.
Utils.trueogMessage(player, "<dark_purple><bold>-=-=-=-=- <dark_green>True<dark_red>OG <white>OG Rank: <dark_purple>-=-=-=-=-");
Utils.trueogMessage(player, "- Use /afk for an unlimited amount of time.");
Utils.trueogMessage(player, "- Prominent white chat prefix");
Utils.trueogMessage(player, "- Create unions with /union create.");
Utils.trueogMessage(player, "- Invite people to unions with /union invite.");
Utils.trueogMessage(player, "- Access to #donor-chat on Discord.");
Utils.trueogMessage(player, "- 6 homes (temporary benefit until the implementation of our in-game home earning plugin).");
Utils.trueogMessage(player, "- &lMore TBA&r.");
}
// If the "OG Pro" message was clicked, do this...
else if (args[0].equalsIgnoreCase("og-pro")) {
// Share "OG Pro" benefits with the player with formatting using the TrueOG Message API.
Utils.trueogMessage(player, "<dark_purple><bold>-=-=-=-=- <dark_green>True&<dark_red>OG <red>OG Pro Rank: <dark_purple>-=-=-=-=-");
Utils.trueogMessage(player, "- &lAll OG Benefits&r.");
Utils.trueogMessage(player, "- Rent up to 2 shops at the player market.");
Utils.trueogMessage(player, "- Special chat formatting (bold, italics, magic, etc).");
Utils.trueogMessage(player, "- Use color codes in chat, mail, unions, signs, anvils, and book titles.");
Utils.trueogMessage(player, "- Edit written books with /book.");
Utils.trueogMessage(player, "- Edit signs with /editsign.");
Utils.trueogMessage(player, "- Wear hats with /hat.");
Utils.trueogMessage(player, "- Sit anywhere with /sit.");
Utils.trueogMessage(player, "- Access your ender chest anywhere with /echest.");
Utils.trueogMessage(player, "- Use 9 exclusive particle cosmetics with /cosmetics (up to 3 at once).");
Utils.trueogMessage(player, "- &lMore TBA&r.");
}
// If the "OG Master" message was clicked, do this...
else if (args[0].equalsIgnoreCase("og-master")) {
// Share "OG Master" benefits with the player with formatting using the TrueOG Message API.
Utils.trueogMessage(player, "<dark_purple><bold>-=-=-=-=- <dark_green>True<dark_red>OG <dark_red>OG Master Rank: <dark_purple>-=-=-=-=-");
Utils.trueogMessage(player, "- &lAll OG and OG Pro Benefits&r.");
Utils.trueogMessage(player, "- Rent up to 3 shops at the player market.");
Utils.trueogMessage(player, "- &lWorld inspection &rwith /co inspect.");
Utils.trueogMessage(player, "- Return to last teleport destination with /back.");
Utils.trueogMessage(player, "- Toggle your death coordinates in chat with /tdc.");
Utils.trueogMessage(player, "- Special mail, sign, and anvil formatting (strike-through, italics, magic, etc).");
Utils.trueogMessage(player, "- &lMore TBA&r.");
}
}
// If the player specified too many command arguments, do this...
else {
// Send the player a formatted error message using the TrueOG Message API.
Utils.trueogMessage(player, "<gray>[<dark_green>True<dark_red>OG<gray>] <red>ERROR: Too many arguments! <gold>Syntax: <yellow>/ranks");
}
}
// If the player does not have permission to use /ranks, do this...
else {
// Send a detailed, formatted permissions error message to the player.
Utils.permissionsErrorMessage(player, cmd.getName(), ranksPermission);
}
}
// If the command was sent by the server console, do this...
else {
// Send a detailed error message to the server console.
Utils.consoleUseErrorMessage(sender, cmd.getName(), ranksPermission);
}
// Healthy exit status.
return true;
}
// Turns chat text into a command button.
public static void sendClickableMessage(Player player, String command) {
// Declare a TextComponent with pre-formatted contents using standard MiniMessage APi.
TextComponent clickableText = (TextComponent) MiniMessage.miniMessage().deserialize("<aqua><bold>Click here to see the benefits!");
// Create a click event on the chat text.
clickableText = clickableText.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, command));
// Send the clickable text to the player.
player.sendMessage(clickableText);
}
}
@@ -0,0 +1,65 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.commands;
// Import libraries.
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import me.barny1094875.utilitiesog.UtilitiesOG;
import me.barny1094875.utilitiesog.internal.Utils;
// Declare the /togglecramming command in the DisableEntityCramming Module with Bukkit Commands.
public class ToggleCrammingCommand implements CommandExecutor {
// Command execution event handler using Bukkit's CommandManager.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// Store the required permission for the /togglecramming command for later reference.
String toggleCrammingPermission = "utilities.togglecramming";
// If the command executor is a player, do this...
if (sender instanceof Player) {
// Get the player object from the sender.
Player player = (Player) sender;
// If the command runner has permission to toggle entity cramming, do this...
if (player.hasPermission(toggleCrammingPermission)) {
// Fetch config file from data folder.
FileConfiguration config = UtilitiesOG.getPlugin().getConfig();
// Flip the true/false value to the opposite of what it currently is.
config.set("doEntityCramming", ! config.getBoolean("doEntityCramming"));
// Send confirmation message with formatting using the TrueOG Message API.
Utils.trueogMessage(player, ("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#FFAA00>Entity cramming has been set to <#FFFF55>" + config.getBoolean("doEntityCramming") + "<#FFAA00>."));
}
// If the player does not have permission to use /togglecramming, do this...
else {
// Send a detailed, formatted permissions error message to the player.
Utils.permissionsErrorMessage(player, cmd.getName(), toggleCrammingPermission);
}
}
// If the command was sent by the server console, do this...
else {
// Send a detailed error message to the server console.
Utils.consoleUseErrorMessage(sender, cmd.getName(), toggleCrammingPermission);
}
// Healthy exit status.
return true;
}
}
@@ -0,0 +1,96 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.commands;
// Import libraries.
import java.io.IOException;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import me.barny1094875.utilitiesog.UtilitiesOG;
import me.barny1094875.utilitiesog.internal.Utils;
//Declare the /togglephantoms command in the Ping Module with Bukkit Commands.
public class TogglePhantomsCommand implements CommandExecutor {
// Command execution event handler using Bukkit's CommandManager.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// Store the required permission for the /togglephantoms command for later reference.
String togglePhantomsPermission = "utilities.togglephantoms";
// If the command was sent by an in-game player, do this...
if (sender instanceof Player) {
// Get the player object from the sender.
Player player = (Player) sender;
// If the player has permission to use /togglephantoms, do this...
if (player.hasPermission(togglePhantomsPermission)) {
// Store the contents of phantomDisabledUsers.yml file as a YAML object.
YamlConfiguration phantomPreferences = UtilitiesOG.getPhantomPreferences();
// Cherry pick the command runner's phantom status from the YAML data set.
boolean phantomToggleState = phantomPreferences.getBoolean(player.getUniqueId().toString());
// Flip the true/false value to the opposite of what it currently is.
phantomPreferences.set(player.getUniqueId().toString(), ! phantomToggleState);
// If the player's phantom spawning is turned on, do this...
if (phantomToggleState) {
// Send a formatted "true" message with formatting using the TrueOG Message API.
Utils.trueogMessage(player, "<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#55FF55>Phantom spawning turned <#00AA00>ON<#55FF55>.");
}
// If the command sender's phantom spawning is turned off, do this...
else {
// Send a formatted "false" message with formatting using the TrueOG Message API.
Utils.trueogMessage(player, "<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#FFAA00>Phantom spawning turned <#FF5555>OFF<#FFAA00>.");
}
try {
// Save changes to YAML data to disk.
phantomPreferences.save(UtilitiesOG.getPhantomDisabledPlayersFile());
}
catch (IOException error) {
// Throw a runtime error if the YAML data could not be saved to disk.
throw new RuntimeException(error);
}
}
// If the player does not have permission to use /togglephantoms, do this...
else {
// Send a detailed, formatted permissions error message to the player.
Utils.permissionsErrorMessage(player, cmd.getName(), togglePhantomsPermission);
}
}
// If the command was sent by the server console, do this...
else {
// Send a detailed error message to the server console.
Utils.consoleUseErrorMessage(sender, cmd.getName(), togglePhantomsPermission);
}
// Healthy exit status.
return true;
}
}
@@ -0,0 +1,111 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.internal;
// Import libraries.
import java.util.HashMap;
import java.util.Map;
// Declare a Class to help convert back and forth between legacy Bukkit color / formatting codes and modern MiniMessage color / formatting codes.
public class ColorCodeMap {
// Declare a HashMap to store legacy codes as keys and modern codes as values.
private static final Map<Character, String> CODE_MAP = new HashMap<>();
// Make this entire section static.
static {
// Pass through the ampersand itself.
CODE_MAP.put('&', "&");
// Black text.
CODE_MAP.put('0', "<color:black>");
// Dark Blue text.
CODE_MAP.put('1', "<color:dark_blue>");
// Dark Green text.
CODE_MAP.put('2', "<color:dark_green>");
// Dark Aqua text.
CODE_MAP.put('3', "<color:dark_aqua>");
// Dark Red text.
CODE_MAP.put('4', "<color:dark_red>");
// Dark Purple text.
CODE_MAP.put('5', "<color:dark_purple>");
// Gold text.
CODE_MAP.put('6', "<color:gold>");
// Gray text.
CODE_MAP.put('7', "<color:gray>");
// Dark Gray text.
CODE_MAP.put('8', "<color:dark_gray>");
// Blue text.
CODE_MAP.put('9', "<color:blue>");
// Green text.
CODE_MAP.put('a', "<color:green>");
// Aqua text.
CODE_MAP.put('b', "<color:aqua>");
// Red text.
CODE_MAP.put('c', "<color:red>");
// Purple text.
CODE_MAP.put('d', "<color:light_purple>");
// Yellow text.
CODE_MAP.put('e', "<color:yellow>");
// White text.
CODE_MAP.put('f', "<color:white>");
// Obfuscated text.
CODE_MAP.put('k', "<obf>");
// Bold text.
CODE_MAP.put('l', "<b>");
// Strikethrough text.
CODE_MAP.put('m', "<st>");
// Underlined text.
CODE_MAP.put('n', "<u>");
// Italic text.
CODE_MAP.put('o', "<i>");
// Rainbow text.
CODE_MAP.put('*', "<rainbow>");
// Reset all formatting.
CODE_MAP.put('r', "<reset>");
}
// Convert any lowercase Bukkit color / formatting code to a modern MiniMessage color / formatting code.
public static String toMiniMessage(char legacyCode) {
// Use the Bukkit color / formatting code as a key to get the modern MiniMessage color / formatting code from the Hash Map.
String miniMessageCode = CODE_MAP.get(legacyCode);
// If the Bukkit color code is not in the Hash Map, do this...
if(miniMessageCode == null) {
// Cause a NullPointerExceptionError for the caller to handle.
throw new NullPointerException();
}
// If the Bukkit color code is in the Hash Map, do this...
return miniMessageCode;
}
}
@@ -0,0 +1,27 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.internal;
// Declare a custom exception for the case where a WorldGuard Flag fails to register for internal use by Utilities-OG.
public class FlagRegistrationException extends Exception {
// This ID is used when the exception is serialized (converted to a byte stream), for example when it's sent over a network.
private static final long serialVersionUID = 1L;
// Constructor to handle sending an error message.
public FlagRegistrationException(String message) {
// Pass the basic message to the base Exception class.
super(message);
}
// Constructor to handle sending an error message and a cause.
public FlagRegistrationException(String message, Throwable cause) {
// Pass the more informative message to the base Exception class.
super(message, cause);
}
}
@@ -0,0 +1,92 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.internal;
// Import libraries.
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import io.github.miniplaceholders.api.Expansion;
import io.github.miniplaceholders.api.MiniPlaceholders;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
// Declare the TrueOG MiniPlaceholderAPI Module.
public class MiniPlaceholderAPI {
// Easy to call function to run all the code in this Module.
public void register() {
// Construct the MiniPlaceholder Expansion "player_display_name".
Expansion expansion = Expansion.builder("player_display").filter(Player.class)
.audiencePlaceholder("name", (audience, ctx, queue) -> {
// Get the player who is seeing the MiniPlaceholder expansion.
Player player = (Player) audience;
// Create a MiniMessage component.
Component formattedName = MiniMessage.miniMessage().deserialize("<dark_purple>" + player.getName() + "</dark_purple>");
// Convert the component back to a MiniMessage String.
String miniMessageString = MiniMessage.miniMessage().serialize(formattedName);
// Create a Tag from the MiniMessage String.
Tag miniMessageTag = Tag.inserting(MiniMessage.miniMessage().deserialize(miniMessageString));
// Pass off the formatted Tag.
return miniMessageTag;
// Construct the MiniPlaceholder expansion into a module.
}).build();
try {
// Register the MiniPlaceholder expansion with MiniPlaceholders.
expansion.register();
// Print a success message to the console if the MiniPlaceholder expansion registration was successful.
Bukkit.getLogger().info("MiniPlaceholdersAPI expansion 'player_name' registered successfully.");
}
// If the MiniPlaceholder expansion registration failed, do this...
catch (Exception error) {
// Print a detailed error message to the server console.
Bukkit.getLogger().severe("Failed to register MiniPlaceholdersAPI expansion: " + error.getMessage());
}
}
// Replace MiniPlaceholders in a given String with their content from MiniPlaceholderAPI.
public static TextComponent expandPlayerMiniPlaceholders(Player player, String message) {
try {
// Get the MiniPlaceholder content that is relevant for the specific player who is seeing the message.
TagResolver placeholders = MiniPlaceholders.getAudiencePlaceholders(player);
// Replace the MiniPlaceholders with the audience placeholder content and the modern color codes with actual colors.
Component expandedMessage = MiniMessage.miniMessage().deserialize(message, placeholders);
// Put the message back into a TextComponent and send it on.
return (TextComponent) expandedMessage;
}
// If any MiniPlaceholders could not be expanded, do this...
catch (Exception error) {
// Construct a detailed error message.
TextComponent formattedErrorMessage = Utils.serializerAnyCase(player, ("\"Error formatting MiniPlaceholdersAPI message for player: \" + player.getName() + \"Error: \" + error.getMessage()"));
// Pass on the formatted error message.
return formattedErrorMessage;
}
}
}
@@ -0,0 +1,146 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.internal;
import org.bukkit.command.CommandSender;
// Import libraries.
import org.bukkit.entity.Player;
import net.kyori.adventure.text.TextComponent;
// Declare a Class to hold miscellaneous utilities for internal use by Utilities-OG.
public class Utils {
// Sends a formatted message to the player.
public static void trueogMessage(Player player, String message) {
// Sends a message using legacy Bukkit color codes in any case with built-in MiniPlaceholder expansion using the TrueOG MiniPlaceholderAPI.
player.sendMessage(serializerAnyCase(player, message));
}
// Converts all Bukkit color codes in the message to lowercase so the case-sensitive MiniMessage legacy color code translator works.
public static TextComponent serializerAnyCase(Player player, String subject) {
// Keeps track of the ampersand count in the loop.
int count = 0;
// Count the number of ampersand characters to determine how many there are for lowercase conversion.
for (char c : subject.toCharArray()) {
// If the character is an ampersand, do this...
if (c == '&') {
// Increase the ampersand count by 1.
count++;
}
}
// Keeps track of the positions of '&' characters in the subject String.
int[] positions = new int[count];
// Keep track of the position of the metaphorical cursor in the subject String.
int index = 0;
// Iterates through the subject String to find the positions of '&' characters for lowercase conversion.
for (int i = 0; i < subject.length(); i++) {
// If the character is an ampersand, do this...
if (subject.charAt(i) == '&') {
// If the character directly after the ampersand is a valid uppercase Bukkit color code, do this...
if (isUpperBukkitCode(subject.charAt(i + 1))) {
// Replace the valid uppercase Bukkit color code with the equivalent lowercase one.
subject = replaceAtIndex(subject, (i + 1), Character.toString(Character.toLowerCase(subject.charAt(i + 1))));
}
try {
// Convert the newly uniform legacy Bukkit color codes into modern MiniMessage color / formatting codes.
subject = replaceAtIndex(subject, (i + 1), ColorCodeMap.toMiniMessage(subject.charAt(i + 1)));
// Delete the leftover ampersand.
subject = replaceAtIndex(subject, i, "");
}
// If the character after an ampersand is not a Bukkit color / formatting code, do this...
catch(NullPointerException error) {
// Do nothing, ampersand is intended to be in the message.
}
// Move the metaphorical cursor forward by one.
positions[index++] = i;
}
}
// Process the newly uniform modern color codes via MiniMessage, including MiniPlaceholder expansion.
TextComponent finalComponent = MiniPlaceholderAPI.expandPlayerMiniPlaceholders(player, subject);
// Pass on the final message.
return finalComponent;
}
// Detects if a Bukkit color code is uppercase.
private static boolean isUpperBukkitCode(char input) {
// An array of all potential uppercase Bukkit color code characters.
char[] bukkitColorCodes = {'A', 'B', 'C', 'D', 'E', 'F', 'K', 'L', 'M', 'N', 'O', 'R'};
// Keeps track of found uppercase Bukkit color codes.
boolean match = false;
// Loop through each character in the array.
for (char c : bukkitColorCodes) {
// Check if the current character in the array is equal to the input character.
if (c == input) {
// A match was found.
match = true;
}
}
// Return whether or not the character is an uppercase Bukkit color code.
return match;
}
// Replaces a character in a String at a given index with a new String.
private static String replaceAtIndex(String original, int index, String newString) {
// Check if the index is valid.
if (index >= 0 && index < original.length()) {
// Create a new string with the replacement.
return original.substring(0, index) + newString + original.substring(index + 1);
}
// If the index is invalid, return the original string. Soft error.
return original;
}
// Sends an error message to the player if they don't have permission to run a given command.
public static void permissionsErrorMessage(Player player, String command, String permission) {
// Send a formatted error message using the TrueOG Message API.
trueogMessage(player, ("&cERROR: You do not have permission to run the /" + command + " command! &6Required permission: &e" + permission + "&6."));
}
// Sends an error message to the console if the command which was run is only applicable to players.
public static void consoleUseErrorMessage(CommandSender sender, String command, String permission) {
// Send an unformatted error message directly to the console.
sender.sendMessage(("ERROR: The server console cannot execute the command: " + command + "! To run it in-game, ensure you have the permission: " + permission + "."));
}
}
@@ -1,36 +0,0 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.modules;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import me.barny1094875.utilitiesog.UtilitiesOG;
import net.kyori.adventure.text.Component;
public class AboutModule implements CommandExecutor
{
// Command execution event handler extending bukkit's CommandManager.
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args)
{
if (sender instanceof Player)
{
// Get the player object from the sender.
Player player = (Player) sender;
// Send formatted about message using MiniMessage API.
Component parsed = UtilitiesOG.getMM().deserialize("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#FFAA00>A collection of small utilities used by <#00AA00>True<#AA0000>OG<#FFAA00> <#FFFF55>Network<#FFAA00>. Developed by <#FFFF55>christianniehaus <#FFAA00>& <#FFFF55>NotAlexNoyle<#FFAA00>.");
player.sendMessage(parsed);
}
else
{
sender.sendMessage("ERROR: The console cannot execute this command! Join the server in-game and try again.");
}
// Healthy exit status.
return true;
}
}
@@ -1,27 +0,0 @@
package me.barny1094875.utilitiesog.modules;
import me.barny1094875.utilitiesog.UtilitiesOG;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
public class BambooWood {
public static void Enable() {
ItemStack bambooWood = new ItemStack(Material.OAK_PLANKS);
ItemMeta bambooWoodMeta = bambooWood.getItemMeta();
bambooWoodMeta.displayName(UtilitiesOG.getMM().deserialize("Bamboo Wood").decoration(TextDecoration.ITALIC, false));
bambooWood.setItemMeta(bambooWoodMeta);
ShapedRecipe BambooWood = new ShapedRecipe(new NamespacedKey(UtilitiesOG.getPlugin(), "Bamboo_Wood"),
bambooWood)
.shape("bb", "bb")
.setIngredient('b', Material.BAMBOO);
Bukkit.addRecipe(BambooWood);
}
}
@@ -1,34 +0,0 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.modules;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import me.barny1094875.utilitiesog.UtilitiesOG;
import net.kyori.adventure.text.Component;
// Initialize command manager class.
public class BingModule implements CommandExecutor
{
// Command execution event handler extending bukkit's CommandManager.
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args)
{
if (sender instanceof Player)
{
// Get the player object from the sender.
Player player = (Player) sender;
// Send player a connection confirmation message.
Component parsed = UtilitiesOG.getMM().deserialize("<#FFFFFF> Bong!");
player.sendMessage(parsed);
}
// Healthy exit status.
return true;
}
}
@@ -0,0 +1,52 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.modules;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
// Import libraries.
import me.barny1094875.utilitiesog.UtilitiesOG;
// Declare the Chain Armor Module.
public class ChainArmorModule {
// Easy to call function to run all the code in this Module.
public static void Enable() {
// Defines a crafting recipe for Chainmail Helmet from Chains.
ShapedRecipe ChainHelmet = new ShapedRecipe(new NamespacedKey(UtilitiesOG.getPlugin(), "Chainmail_Helmet1"),
new ItemStack(Material.CHAINMAIL_HELMET))
.shape("ccc", "c c")
.setIngredient('c', Material.CHAIN);
// Defines a crafting recipe for Chainmail Chestplate from Chains.
ShapedRecipe ChainChestPlate = new ShapedRecipe(new NamespacedKey(UtilitiesOG.getPlugin(), "Chainmail_Chestplate"),
new ItemStack(Material.CHAINMAIL_CHESTPLATE))
.shape("c c", "ccc", "ccc")
.setIngredient('c', Material.CHAIN);
// Defines a crafting recipe for Chainmail Leggings from Chains.
ShapedRecipe ChainLeggings = new ShapedRecipe(new NamespacedKey(UtilitiesOG.getPlugin(), "Chainmail_Leggings"),
new ItemStack(Material.CHAINMAIL_LEGGINGS))
.shape("ccc", "c c", "c c")
.setIngredient('c', Material.CHAIN);
// Defines a crafting recipe for Chainmail Boots from Chains.
ShapedRecipe ChainBoots = new ShapedRecipe(new NamespacedKey(UtilitiesOG.getPlugin(), "Chainmail_Boots1"),
new ItemStack(Material.CHAINMAIL_BOOTS))
.shape("c c", "c c")
.setIngredient('c', Material.CHAIN);
// Add the Chainmail Armor crafting recipes to the server.
Bukkit.addRecipe(ChainHelmet);
Bukkit.addRecipe(ChainChestPlate);
Bukkit.addRecipe(ChainLeggings);
Bukkit.addRecipe(ChainBoots);
}
}
@@ -1,41 +0,0 @@
package me.barny1094875.utilitiesog.modules;
import me.barny1094875.utilitiesog.UtilitiesOG;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
public class ChainArmour {
public static void Enable() {
ShapedRecipe ChainHelmet = new ShapedRecipe(new NamespacedKey(UtilitiesOG.getPlugin(), "Chainmail_Helmet1"),
new ItemStack(Material.CHAINMAIL_HELMET))
.shape("ccc", "c c")
.setIngredient('c', Material.CHAIN);
Bukkit.addRecipe(ChainHelmet);
// recipe for chain chestplate
ShapedRecipe ChainChestPlate = new ShapedRecipe(new NamespacedKey(UtilitiesOG.getPlugin(), "Chainmail_Chestplate"),
new ItemStack(Material.CHAINMAIL_CHESTPLATE))
.shape("c c", "ccc", "ccc")
.setIngredient('c', Material.CHAIN);
Bukkit.addRecipe(ChainChestPlate);
// recipe for chain leggings
ShapedRecipe ChainLeggings = new ShapedRecipe(new NamespacedKey(UtilitiesOG.getPlugin(), "Chainmail_Leggings"),
new ItemStack(Material.CHAINMAIL_LEGGINGS))
.shape("ccc", "c c", "c c")
.setIngredient('c', Material.CHAIN);
Bukkit.addRecipe(ChainLeggings);
// recipe for chain boots
ShapedRecipe ChainBoots = new ShapedRecipe(new NamespacedKey(UtilitiesOG.getPlugin(), "Chainmail_Boots1"),
new ItemStack(Material.CHAINMAIL_BOOTS))
.shape("c c", "c c")
.setIngredient('c', Material.CHAIN);
Bukkit.addRecipe(ChainBoots);
}
}
@@ -1,61 +0,0 @@
package me.barny1094875.utilitiesog.modules;
import me.barny1094875.utilitiesog.UtilitiesOG;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ColorCodes implements CommandExecutor {
// Create instance of class for command runner.
private static ColorCodes instance;
// Constructor for main class to get instance from.
public static ColorCodes getInstance() {
return instance;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// If the command matches our criteria, do this...
if (cmd.getName().equalsIgnoreCase("colorcodes")) {
// If the command executor is a player, do this...
if (sender instanceof Player) {
// Cast the sender to a player object safely.
Player player = (Player) sender;
// Send the color code cheat sheet to the player.
player.sendMessage(UtilitiesOG.getMM().deserialize("<dark_aqua><bold>-=-=-=-=- <dark_purple>C<dark_aqua>o<green>l<yellow>o<red>r <aqua>C<light_purple>o<white>d<light_purple>e<aqua>s: -=-=-=-=-"));
player.sendMessage(UtilitiesOG.getMM().deserialize("&0 = <black>Black <reset> &1 = <dark_blue>Dark Blue"));
player.sendMessage(UtilitiesOG.getMM().deserialize("&2 = <dark_green>Dark Green <reset> &3 = <dark_aqua>Dark Aqua"));
player.sendMessage(UtilitiesOG.getMM().deserialize("&4 = <dark_red>Dark Red <reset> &5 = <dark_purple>Dark Purple"));
player.sendMessage(UtilitiesOG.getMM().deserialize("&6 = <gold>Gold <reset> &7 = <gray>Grey"));
player.sendMessage(UtilitiesOG.getMM().deserialize("&8 = <dark_gray>Dark Grey <reset> &9 = <blue>Blue"));
player.sendMessage(UtilitiesOG.getMM().deserialize("&a = <green>Green <reset> &b = <aqua>Aqua"));
player.sendMessage(UtilitiesOG.getMM().deserialize("&c = <red>Red <reset> &d = <light_purple>Light Purple"));
player.sendMessage(UtilitiesOG.getMM().deserialize("&e = <yellow>Yellow <reset> &f = <white>White"));
player.sendMessage(UtilitiesOG.getMM().deserialize("&k = <obfuscated>Magic <reset> &l = <bold>Bold"));
player.sendMessage(UtilitiesOG.getMM().deserialize("&m = <strikethrough>Strikethrough <reset> &n = <underlined>Underline"));
player.sendMessage(UtilitiesOG.getMM().deserialize("&o = <italic>Italic <reset> &r = Reset"));
}
// If the command executor is not a player, do this...
else {
// Deny console executions.
sender.sendMessage("ERROR: The console cannot execute this command!");
}
}
// Healthy exit status.
return true;
}
}
@@ -1,42 +0,0 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.modules;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
//Import required libraries.
import me.barny1094875.utilitiesog.UtilitiesOG;
import net.kyori.adventure.text.Component;
public class EntityCrammingToggleModule implements CommandExecutor
{
// Command execution event handler extending bukkit's CommandManager.
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args)
{
if (sender instanceof Player)
{
// Get the player object from the sender.
Player player = (Player) sender;
// If the command runner has permission to toggle entity cramming, do this...
if (player.hasPermission("utilities.togglecramming"))
{
// Fetch config file from data folder.
FileConfiguration config = UtilitiesOG.getPlugin().getConfig();
// Flip the true/false value to the opposite of what it currently is.
config.set("doEntityCramming", ! config.getBoolean("doEntityCramming"));
// Send formatted confirmation message using MiniMessage API.
Component parsed = UtilitiesOG.getMM().deserialize("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#FFAA00>Entity cramming has been set to <#FFFF55>" + config.getBoolean("doEntityCramming") + "<#FFAA00>.");
player.sendMessage(parsed);
}
}
return true;
}
}
@@ -0,0 +1,67 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.modules;
// Import libraries.
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import me.barny1094875.utilitiesog.UtilitiesOG;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
// Declare the Mock Bamboo Wood Module.
public class MockBambooModule {
// Easy to call function to run all the code in this Module.
public static void Enable() {
// Create a novel item, Bamboo Planks, based on Oak Planks.
ItemStack bambooPlanks = new ItemStack(Material.OAK_PLANKS);
// Fetch the meta of the mock Bamboo Planks for editing.
ItemMeta bambooPlanksMeta = bambooPlanks.getItemMeta();
// Gives the mock Bamboo Planks a formatted title.
bambooPlanksMeta.displayName(MiniMessage.miniMessage().deserialize("<green>Bamboo Planks").decoration(TextDecoration.ITALIC, false));
// Applies the custom display name to the item.
bambooPlanks.setItemMeta(bambooPlanksMeta);
// Defines a crafting recipe for Bamboo Planks.
ShapedRecipe BambooPlanks = new ShapedRecipe(new NamespacedKey(UtilitiesOG.getPlugin(), "Bamboo_Planks"),
bambooPlanks).shape("bb", "bb")
// Use Bamboo as the base ingredient.
.setIngredient('b', Material.BAMBOO);
// Adds the crafting recipe for Bamboo Planks to the server.
Bukkit.addRecipe(BambooPlanks);
// Create a novel item, Bamboo Wood, based on Birch Wood.
ItemStack imitationBambooWood = new ItemStack(Material.BIRCH_WOOD);
// Fetch the meta of the mock Bamboo Wood for editing.
ItemMeta imitationBambooWoodMeta = imitationBambooWood.getItemMeta();
// Gives the mock Bamboo Wood a formatted title.
imitationBambooWoodMeta.displayName(MiniMessage.miniMessage().deserialize("<green>Bamboo Wood").decoration(TextDecoration.ITALIC, false));
// Applies the display name to the mock Bamboo Wood.
imitationBambooWood.setItemMeta(imitationBambooWoodMeta);
// Define a crafting recipe for mock Bamboo Wood.
ShapedRecipe imitationBambooWoodRecipe = new ShapedRecipe(new NamespacedKey(UtilitiesOG.getPlugin(), "Imitation_Bamboo_Wood"),
imitationBambooWood).shape("bb", "bb")
// Use the previously created bamboo planks as the base ingredient.
.setIngredient('b', bambooPlanks);
// Add the crafting recipe for mock Bamboo Wood to the server.
Bukkit.addRecipe(imitationBambooWoodRecipe);
}
}
@@ -1,86 +0,0 @@
package me.barny1094875.utilitiesog.modules;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import me.barny1094875.utilitiesog.UtilitiesOG;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
public class NoFlippy implements Listener {
// Declare instance of class as static so multiple players can use it.
private static NoFlippy instance;
// Return instance of class as static so multiple players can use it.
public static NoFlippy getInstance() {
// Pass back Listeners to main.
return instance;
}
// Listen for a player interacting with a trapdoor.
@EventHandler
public void onInteract(PlayerInteractEvent event) {
// Get the nature of the interaction and store it.
Action action = event.getAction();
// Get the block that was interacted with and store it.
Block blockClicked = event.getClickedBlock();
// Get the player who interacted and store them.
Player player = event.getPlayer();
// Declare a container for the block type for null checking.
String blockContainerAsString = null;
try {
// Try storing the block type as a string. Throws NullPointerException if not applicable.
blockContainerAsString = blockClicked.getType().toString();
} catch (NullPointerException error) {
// Do nothing if block type is null.
return;
}
// If the interaction was with a trap door, do this...
if (blockContainerAsString.contains("TRAPDOOR")) {
// If the interaction was a right click, do this...
if (action.isRightClick()) ;
{
// If the player does not have permission to flip trap doors, do this...
if (!player.hasPermission("noflippy.bypass")) {
Location blockLocation = BukkitAdapter.adapt(blockClicked.getLocation());
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
ApplicableRegionSet set = query.getApplicableRegions(blockLocation);
// If the Flippy Flag is set to DENY, cancel the event.
if (!set.testState(null, UtilitiesOG.getFlippyFlag())) {
// Cancel the trapdoor flip.
event.setCancelled(true);
}
}
}
}
}
}
@@ -1,72 +0,0 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.modules;
import java.io.IOException;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
// Import required libraries.
import me.barny1094875.utilitiesog.UtilitiesOG;
import net.kyori.adventure.text.Component;
public class PhantomToggleModule implements CommandExecutor
{
// Command execution event handler extending bukkit's CommandManager.
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args)
{
if (sender instanceof Player)
{
// Get the player object from the sender.
Player player = (Player) sender;
if (player.hasPermission("utilities.togglephantoms"))
{
// Store the contents of phantomDisabledUsers.yml file as a YAML object.
YamlConfiguration phantomPreferences = UtilitiesOG.getPhantomPreferences();
// Cherry pick the command runner's phantom status from the YAML data set.
boolean phantomToggleState = phantomPreferences.getBoolean(player.getUniqueId().toString());
// Flip the true/false value to the opposite of what it currently is.
phantomPreferences.set(player.getUniqueId().toString(), ! phantomToggleState);
// If the command sender's phantom spawning is turned on, do this...
if (phantomToggleState)
{
// Send formatted "true" message using MiniMessage API.
Component parsed = UtilitiesOG.getMM().deserialize("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#55FF55>Phantom spawning turned <#00AA00>ON<#55FF55>.");
player.sendMessage(parsed);
}
// If the command sender's phantom spawning is turned off, do this...
else
{
// Send formatted "false" message using MiniMessage API.
Component parsed = UtilitiesOG.getMM().deserialize("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#FFAA00>Phantom spawning turned <#FF5555>OFF<#FFAA00>.");
player.sendMessage(parsed);
}
try
{
// Save changes to YAML data to disk.
phantomPreferences.save(UtilitiesOG.getPhantomDisabledPlayersFile());
}
catch (IOException error)
{
// Throw a runtime error if the YAML data could not be saved to disk.
throw new RuntimeException(error);
}
}
}
else {
sender.sendMessage("ERROR: The console cannot execute this command! Join the server in-game and try again.");
}
return true;
}
}
@@ -1,82 +0,0 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.modules;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import me.barny1094875.utilitiesog.UtilitiesOG;
import net.kyori.adventure.text.Component;
// Initialize command manager class.
public class PingModule implements CommandExecutor
{
// Command execution event handler extending bukkit's CommandManager.
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args)
{
if (sender instanceof Player)
{
// Get the player object from the sender.
Player player = (Player) sender;
if (player.hasPermission("utilities.ping"))
{
// If the player did not provide any arguments, do this...
if(args.length == 0) {
// Send player their own ping using a formatted message with the MiniMessage API.
Component parsed = UtilitiesOG.getMM().deserialize("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#00AA00>Your current ping is: <#FFAA00>" + player.getPing() + "<#00AA00>.");
player.sendMessage(parsed);
}
// If the player provided one or more arguments, do this...
else if(args.length == 1) {
// Try to get the player that was specified.
Player target = Bukkit.getPlayer(args[0]);
// If the provided argument was a valid player, do this...
if(target != null) {
// Send player their specified player's ping using formatting with the MiniMessage API.
Component parsed = UtilitiesOG.getMM().deserialize("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#00AA00>" + target.getName() + "'s current ping is: <#FFAA00>" + target.getPing() + "<#00AA00>.");
player.sendMessage(parsed);
}
// If the provided argument was not a valid player, do this...
else {
// Send a "player not found" error message using formatting with the MiniMessage API.
Component parsed = UtilitiesOG.getMM().deserialize("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#AA0000> ERROR: The player " + args[0] + " was not found!");
player.sendMessage(parsed);
}
}
// If there is more than one provided argument, do this...
else {
// Send a "too many arguments" error message using formatting with the MiniMessage API.
Component parsed = UtilitiesOG.getMM().deserialize("<#AAAAAA>[<#00AA00>Utilities<#AA0000>-OG<#AAAAAA>] <#AA0000> ERROR: Too many arguments provided. Syntax: <#FFFF55>/ping <player>");
player.sendMessage(parsed);
}
}
}
// Healthy exit status.
return true;
}
}
@@ -1,110 +0,0 @@
// This is free and unencumbered software released into the public domain.
// Authors: christianniehaus, NotAlexNoyle.
package me.barny1094875.utilitiesog.modules;
import me.barny1094875.utilitiesog.UtilitiesOG;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
// Initialize command manager class.
public class RanksModule implements CommandExecutor {
// Command execution event handler extending bukkit's CommandManager.
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
// Get the player object from the sender.
Player player = (Player) sender;
if (sender instanceof Player) {
if (player.hasPermission("utilities.ranks")) {
// If the player did not provide any arguments, do this...
if (args.length == 0) {
// Send the available ranks to the user.
player.sendMessage(UtilitiesOG.getMM().deserialize("<bold><dark_purple>-=-=-=-=- <dark_green>True<dark_red>OG <aqua>Donation Store: <dark_purple>-=-=-=-=-"));
player.sendMessage("");
player.sendMessage("Each donor rank requires the rank before it.");
player.sendMessage("");
player.sendMessage(UtilitiesOG.getMM().deserialize("<green>Rank Overview: <dark_aqua><underlined>https://shop.true-og.net"));
player.sendMessage("");
player.sendMessage(UtilitiesOG.getMM().deserialize("<white>[OG] <gray>(<dark_green>$10 Once<gray>) <dark_aqua><underlined>https://true-og.net/og"));
sendClickableMessage(player, "/ranks og");
player.sendMessage("");
player.sendMessage(UtilitiesOG.getMM().deserialize("<red>[OG Pro] <gray>(<dark_green>$50 Once<gray>) <dark_aqua><underlined>https://true-og.net/og-pro"));
sendClickableMessage(player, "/ranks og-pro");
player.sendMessage("");
player.sendMessage(UtilitiesOG.getMM().deserialize("<dark_red><bold>[OG Master] <gray>(<gold>$10 Monthly<gray>) <dark_aqua><underlined>https://true-og.net/og-master"));
sendClickableMessage(player, "/ranks og-master");
}
// If the player provided one or more arguments, do this...
else if (args.length == 1) {
// If the OG text was clicked, do this...
if (args[0].equalsIgnoreCase("og")) {
// Share the OG benefits with the user.
player.sendMessage(UtilitiesOG.getMM().deserialize("<dark_purple><bold>-=-=-=-=- <dark_green>True<dark_red>OG <white>OG Rank: <dark_purple>-=-=-=-=-"));
player.sendMessage("- Use /afk for an unlimited amount of time.");
player.sendMessage("- Prominent white chat prefix");
player.sendMessage("- Create unions with /union create.");
player.sendMessage("- Invite people to unions with /union invite.");
player.sendMessage("- Access to #donor-chat on Discord.");
player.sendMessage("- 6 homes (temporary benefit until the implementation of our in-game home earning plugin).");
player.sendMessage("- More TBA.");
}
// If the OG Pro text was clicked, do this...
else if (args[0].equalsIgnoreCase("og-pro")) {
// Share the OG Pro benefits with the user.
player.sendMessage(UtilitiesOG.getMM().deserialize("<dark_purple><bold>-=-=-=-=- <dark_green>True&<dark_red>OG <red>OG Pro Rank: <dark_purple>-=-=-=-=-"));
player.sendMessage("- All OG Benefits.");
player.sendMessage("- Rent up to 2 shops at the player market.");
player.sendMessage("- Special chat formatting (bold, italics, magic, etc).");
player.sendMessage("- Use color codes in chat, mail, unions, signs, anvils, and book titles.");
player.sendMessage("- Edit written books with /book.");
player.sendMessage("- Edit signs with /editsign.");
player.sendMessage("- Wear hats with /hat.");
player.sendMessage("- Sit anywhere with /sit.");
player.sendMessage("- Access your ender chest anywhere with /echest.");
player.sendMessage("- Use 9 exclusive particle cosmetics with /cosmetics (up to 3 at once).");
player.sendMessage("- More TBA.");
}
// If the OG Master text was clicked, do this...
else if (args[0].equalsIgnoreCase("og-master")) {
// Share the OG Master benefits to the user.
player.sendMessage(UtilitiesOG.getMM().deserialize("<dark_purple><bold>-=-=-=-=- <dark_green>True<dark_red>OG <dark_red>OG Master Rank: <dark_purple>-=-=-=-=-"));
player.sendMessage("- All OG and OG Pro Benefits.");
player.sendMessage("- Rent up to 3 shops at the player market.");
player.sendMessage("- World inspection with /co inspect.");
player.sendMessage("- Return to last teleport destination with /back.");
player.sendMessage("- Toggle your death coordinates in chat with /tdc.");
player.sendMessage("- Special mail, sign, and anvil formatting (strike-through, italics, magic, etc).");
player.sendMessage("- More TBA.");
}
} else {
// Send the player an error message if they typed too many command arguments.
player.sendMessage(UtilitiesOG.getMM().deserialize("<gray>[<dark_green>True<dark_red>OG<gray>] <red>ERROR: Too many arguments! <gold>Syntax: <yellow>/ranks"));
}
}
}
// Healthy exit status.
return true;
}
// Turns chat text into a command button.
public static void sendClickableMessage(Player player, String command) {
// Declare a TextComponent with contents.
TextComponent clickableText = (TextComponent) UtilitiesOG.getMM().deserialize("<aqua><bold>Click here to see the benefits!");
// Create a click event on the chat text.
clickableText = clickableText.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, command));
// Send the clickable text to the player.
player.sendMessage(clickableText);
}
}
+17 -12
View File
@@ -1,14 +1,19 @@
# area for all of the feature enabling/disabling
PhantomToggle: true
EntityCrammingDisable: false
RanksMenu: true
Ping: true
BuyMenu: true
BambooWood: true
ChainArmour: true
# Pre-1.20 Mock Bamboo Planks and Bamboo Wood. Mock Bamboo Planks are crafted from 2x2 Bamboo. Mock Bamboo Wood is crafted from 2x2 mock Bamboo Planks. Default: true.
MockBamboo: true
# Crafting chain armor using chains. Default: true.
ChainArmor: true
# Displays information to the player about the syntax for bukkit's color codes. Default: true.
ColorCodes: true
# Turn off entity cramming damage server-wide. Entity cramming is when mobs pile up and cause damage to each other. Default: false.
# WARNING: Make sure there is another plugin that establishes entity limits if this module is enabled. Otherwise the server will lag.
DisableEntityCramming: false
# A custom, easy to use MiniPlaceholders API. Default: true.
MiniPlaceholderAPI: true
# Prevents trap doors from being flipped in any WorldGuard regions with the "can-flippy" flag set to DENY. Default: true.
NoFlippy: true
# all of the below are config used by the plugin
# whether to disable entity cramming or not
doEntityCramming: false
# Empowers individual players to toggle phantom spawning on or off with the command /togglephantoms. Default: true.
TogglePhantoms: true
# A /ping command that returns a player's real ping, in addition to a /bing command that replicates the functionality of the default /ping command. Default: true.
Ping: true
# Displays information to the player about the ranks available at the TrueOG Network Store (https://store.true-og.net/). Default: true.
RanksMenu: true
+10 -4
View File
@@ -1,9 +1,9 @@
name: Utilities-OG
authors: [ christianniehaus, NotAlexNoyle ]
version: '2.1.2'
version: '${version}'
api-version: '${apiVersion}'
main: me.barny1094875.utilitiesog.UtilitiesOG
api-version: 1.19
depend: [ WorldGuard ]
softdepend: [ WorldGuard ]
commands:
utilities:
usage: /utilites
@@ -21,6 +21,12 @@ commands:
usage: /colorcodes
permissions:
utilities.about:
description: Permission to use the base /utilities command.
default: op
utilities.colorcodes:
description: Permission to use the /colorcodes command.
default: op
utilities.togglephantoms:
description: Permission to use the /togglephantoms command.
default: op
@@ -32,4 +38,4 @@ permissions:
default: op
utilities.ping:
description: Permission to use the /ping and /bing commands.
default: op
default: op