Performs a lot of various changes

Adds some new command classes
Adds support for several languages
Adds README
Updates Java and Spigot versions
Adds command info and additional permission info to plugin.yml
Implements manual sign creation request cancelling
This commit is contained in:
2022-01-09 12:12:55 +01:00
parent d210b45ad5
commit 2917905b23
19 changed files with 502 additions and 52 deletions

View File

@ -1,9 +1,14 @@
package net.knarcraft.permissionsigns;
import net.knarcraft.permissionsigns.command.PermissionSignsCommand;
import net.knarcraft.permissionsigns.command.PermissionSignsTabCompleter;
import net.knarcraft.permissionsigns.container.PermissionSign;
import net.knarcraft.permissionsigns.container.SignCreationRequest;
import net.knarcraft.permissionsigns.thread.SignCreationRequestTimeoutThread;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
@ -14,12 +19,32 @@ import java.util.UUID;
import java.util.stream.Stream;
public final class PermissionSigns extends JavaPlugin {
private static Queue<SignCreationRequest> signCreationRequests = new PriorityQueue<>();
private static final Queue<SignCreationRequest> signCreationRequests = new PriorityQueue<>();
private static String pluginVersion;
/**
* Gets the version of this plugin
*
* @return <p>This plugin's version</p>
*/
public static String getPluginVersion() {
return pluginVersion;
}
/**
* Adds a new sign creation request
*
* @param player <p>The player that initiated the sign creation</p>
* @param sign <p>The sign the player is about to create</p>
*/
public static void addSignCreationRequest(Player player, PermissionSign sign) {
signCreationRequests.add(new SignCreationRequest(sign, player, System.currentTimeMillis()));
}
/**
* Gets the sign creation request for the player with the given UUID
*
*
* @param uuid <p>The UUID to get a sign creation request for</p>
* @return <p>A sign creation request, or null if the UUID is not found</p>
*/
@ -34,10 +59,25 @@ public final class PermissionSigns extends JavaPlugin {
}
}
/**
* Cancels the sign creation request triggered by the user
*
* @param uuid <p>The UUID of the player to cancel the request for</p>
*/
public static void cancelSignCreationRequest(UUID uuid) {
Stream<SignCreationRequest> matchingRequests = signCreationRequests.stream().filter(
(item) -> item.getPlayer().getUniqueId().equals(uuid));
List<SignCreationRequest> requestList = matchingRequests.toList();
signCreationRequests.remove(requestList.get(0));
}
@Override
public void onEnable() {
PluginDescriptionFile pluginDescriptionFile = this.getDescription();
pluginVersion = pluginDescriptionFile.getVersion();
// Plugin startup logic
//TODO: Add commands create, add and remove
// /ps create, /ps add, and /ps remove
// create initiates the creation, and add adds properties
@ -53,7 +93,7 @@ public final class PermissionSigns extends JavaPlugin {
// /ps cancel to cancel the sing creation
// Break the sign to remove it, check for permission first
// The name thing is probably useless, as the sign's location works as its id
//TODO: Display and register the permission-sign
// Start with [PermSign] in red
// Next line is the permission node. Last child, upper-cased
@ -61,23 +101,36 @@ public final class PermissionSigns extends JavaPlugin {
// Last line is the cost, including the unit
// Need to store any temporary permissions in a list/queue and have a thread which searches for expired
// permissions to de-register them
//Not persistent, but might work as things shouldn't persist anyway
//player.addAttachment(this, "essentials.fly", true, seconds * 20);
//Vault probably has some API to add permissions
//TODO: Start sign creation when the create command is used and save the data until an empty sign is right-clicked
//TODO: Check for existence of old permission signs when clicked and register them as new permission signs. If
// it has the permissionSigns header and a name matching contents in signdata.yml, add it.
registerCommands();
BukkitScheduler scheduler = Bukkit.getScheduler();
scheduler.runTaskTimer(this, new SignCreationRequestTimeoutThread(signCreationRequests), 0L, 100L);
}
/**
* Registers a command for this plugin
*/
private void registerCommands() {
PluginCommand stargateCommand = this.getCommand("permissionsigns");
if (stargateCommand != null) {
stargateCommand.setExecutor(new PermissionSignsCommand());
stargateCommand.setTabCompleter(new PermissionSignsTabCompleter());
}
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
}