Initial commit

This commit is contained in:
2022-01-08 16:57:12 +01:00
commit d210b45ad5
11 changed files with 631 additions and 0 deletions

View File

@ -0,0 +1,83 @@
package net.knarcraft.permissionsigns;
import net.knarcraft.permissionsigns.container.SignCreationRequest;
import net.knarcraft.permissionsigns.thread.SignCreationRequestTimeoutThread;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.UUID;
import java.util.stream.Stream;
public final class PermissionSigns extends JavaPlugin {
private static Queue<SignCreationRequest> signCreationRequests = new PriorityQueue<>();
/**
* 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>
*/
public static SignCreationRequest getSignCreationRequest(UUID uuid) {
Stream<SignCreationRequest> matchingRequests = signCreationRequests.stream().filter(
(item) -> item.getPlayer().getUniqueId().equals(uuid));
List<SignCreationRequest> requestList = matchingRequests.toList();
if (!requestList.isEmpty()) {
return requestList.get(0);
} else {
return null;
}
}
@Override
public void onEnable() {
// 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
// On creation, write "Creating PermissionSign", first asked for the name
// Then asked for the permission. Allow several comma-separated permissions
// Then asked for duration
// Then asked for cost
// Say "Sign completed! Right-click a sign to enable it."
// Then asked to right-click a sign to create the new permission-sign
// Perhaps ignore the old ways, and just have one command for creating permission signs:
// /ps create <name> <permission> <duration> <cost> to create a new permission-sign
// Right-click a sign to create it
// /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
// Third line is n seconds
// 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.
BukkitScheduler scheduler = Bukkit.getScheduler();
scheduler.runTaskTimer(this, new SignCreationRequestTimeoutThread(signCreationRequests), 0L, 100L);
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
}