Implements world-specific permissions
Accounts for world specifiers where necessary Makes the reload command work? Stores the world as part of temporary permissions Fixes sign break protection Allows sign interaction with both right- and left-click Fixes temporary permissions sometimes colliding Cleans the main class a bit Adds a "star" permission Adds missing check for the use permission
This commit is contained in:
@@ -5,6 +5,7 @@ import net.knarcraft.permissionsigns.command.PermissionSignsTabCompleter;
|
||||
import net.knarcraft.permissionsigns.container.PermissionSign;
|
||||
import net.knarcraft.permissionsigns.container.SignCreationRequest;
|
||||
import net.knarcraft.permissionsigns.formatting.Translator;
|
||||
import net.knarcraft.permissionsigns.listener.BlockListener;
|
||||
import net.knarcraft.permissionsigns.listener.PlayerListener;
|
||||
import net.knarcraft.permissionsigns.listener.SignListener;
|
||||
import net.knarcraft.permissionsigns.manager.EconomyManager;
|
||||
@@ -16,8 +17,10 @@ import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicesManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -35,6 +38,7 @@ public final class PermissionSigns extends JavaPlugin {
|
||||
private static final Queue<SignCreationRequest> signCreationRequests = new PriorityQueue<>();
|
||||
private static String pluginVersion;
|
||||
private static PermissionSigns instance;
|
||||
private static boolean perWorldPermissions;
|
||||
|
||||
/**
|
||||
* Instantiates the permission signs class
|
||||
@@ -104,57 +108,74 @@ public final class PermissionSigns extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether permissions should always be set for the world the sign belongs to
|
||||
*
|
||||
* @return <p>Whether permissions should be set for the current world</p>
|
||||
*/
|
||||
public static boolean usePerWorldPermissions() {
|
||||
return perWorldPermissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
super.reloadConfig();
|
||||
FileConfiguration config = this.getConfig();
|
||||
String language = config.getString("language");
|
||||
perWorldPermissions = config.getBoolean("perWorldPermissions");
|
||||
Translator.loadLanguages(language);
|
||||
}
|
||||
|
||||
@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
|
||||
// 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: Store all temporary permissions with the time they were assigned and the time they should be granted.
|
||||
// Set the permissions as permanent and remove when the timer expires? Might cause problems for players that has
|
||||
// the permission inherited, unless we make sure the player does not have the permission before
|
||||
// Alternatively: Manage all permissions ourselves, for temporary permissions, and add permission attachments
|
||||
// on startup I guess.
|
||||
|
||||
//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 signs.yml, add it.
|
||||
|
||||
//TODO: Implement config file
|
||||
//TODO: Account for per-world permissions if enabled (perhaps allow world specification as world:permission?)
|
||||
//TODO: Allow for custom language files. Perhaps just look for strings.yml in the folder
|
||||
|
||||
FileConfiguration config = this.getConfig();
|
||||
config.options().copyDefaults(true);
|
||||
this.saveDefaultConfig();
|
||||
|
||||
String language = config.getString("language");
|
||||
perWorldPermissions = config.getBoolean("perWorldPermissions");
|
||||
|
||||
//Check if vault is loaded
|
||||
setupVault();
|
||||
|
||||
registerListeners();
|
||||
|
||||
Translator.loadLanguages(language);
|
||||
registerCommands();
|
||||
|
||||
runThreads();
|
||||
|
||||
SignManager.loadSigns();
|
||||
PermissionManager.loadTemporaryPermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts all separate threads for executing tasks
|
||||
*/
|
||||
private void runThreads() {
|
||||
BukkitScheduler scheduler = Bukkit.getScheduler();
|
||||
scheduler.runTaskTimer(this, new SignCreationRequestTimeoutThread(signCreationRequests), 0L, 100L);
|
||||
scheduler.runTaskTimer(this, new PermissionTimeoutThread(), 0L, 25L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all necessary listeners
|
||||
*/
|
||||
private void registerListeners() {
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new SignListener(), this);
|
||||
pluginManager.registerEvents(new PlayerListener(), this);
|
||||
pluginManager.registerEvents(new BlockListener(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up Vault by getting plugins from their providers
|
||||
*/
|
||||
private void setupVault() {
|
||||
ServicesManager servicesManager = this.getServer().getServicesManager();
|
||||
RegisteredServiceProvider<Permission> permissionProvider = servicesManager.getRegistration(Permission.class);
|
||||
RegisteredServiceProvider<Economy> economyProvider = servicesManager.getRegistration(Economy.class);
|
||||
@@ -164,16 +185,6 @@ public final class PermissionSigns extends JavaPlugin {
|
||||
} else {
|
||||
throw new IllegalStateException("[PermissionSigns] Error: Vault could not be loaded");
|
||||
}
|
||||
getServer().getPluginManager().registerEvents(new SignListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
|
||||
Translator.loadLanguages("en");
|
||||
registerCommands();
|
||||
BukkitScheduler scheduler = Bukkit.getScheduler();
|
||||
scheduler.runTaskTimer(this, new SignCreationRequestTimeoutThread(signCreationRequests), 0L, 100L);
|
||||
scheduler.runTaskTimer(this, new PermissionTimeoutThread(), 0L, 25L);
|
||||
SignManager.loadSigns();
|
||||
PermissionManager.loadTemporaryPermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user