From 1e4c0df93d040aa96bb58d8b1ac46e8ec918bb2a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 3 Dec 2016 00:50:09 +0100 Subject: [PATCH 1/2] Started a better player storage Too tired rn. --- .../java/buttondevteam/core/MainPlugin.java | 24 ----------- src/main/java/buttondevteam/lib/CPlayer.java | 42 ------------------- .../buttondevteam/lib/TBMCPlayerBase.java | 15 +++++++ src/main/java/buttondevteam/lib/db/CData.java | 7 ---- .../buttondevteam/lib/db/DataManager.java | 34 --------------- 5 files changed, 15 insertions(+), 107 deletions(-) delete mode 100644 src/main/java/buttondevteam/lib/CPlayer.java create mode 100644 src/main/java/buttondevteam/lib/TBMCPlayerBase.java delete mode 100644 src/main/java/buttondevteam/lib/db/CData.java delete mode 100644 src/main/java/buttondevteam/lib/db/DataManager.java diff --git a/src/main/java/buttondevteam/core/MainPlugin.java b/src/main/java/buttondevteam/core/MainPlugin.java index 7de842c..5455e6e 100644 --- a/src/main/java/buttondevteam/core/MainPlugin.java +++ b/src/main/java/buttondevteam/core/MainPlugin.java @@ -4,16 +4,11 @@ import java.util.Map.Entry; import java.util.UUID; import java.util.logging.Logger; -import javax.persistence.PersistenceException; - import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; -import buttondevteam.lib.CPlayer; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCPlayer; -import buttondevteam.lib.db.CData; -import buttondevteam.lib.db.DataManager; public class MainPlugin extends JavaPlugin { public static MainPlugin Instance; @@ -28,28 +23,9 @@ public class MainPlugin extends JavaPlugin { pdfFile = getDescription(); logger = getLogger(); - setupDatabase(); - DataManager.setDatabase(getDatabase()); - final UUID cid = UUID.randomUUID(); - final UUID mcid = UUID.randomUUID(); - System.out.println(cid); - System.out.println(mcid); - System.out.println("----"); - DataManager.save(new CPlayer(cid, mcid)); - System.out.println("----"); - System.out.println(DataManager.load(CPlayer.class, cid).getMinecraftID()); logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ")."); TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this); } - - private void setupDatabase() { - try { - getDatabase().find(CPlayer.class).findRowCount(); - } catch (PersistenceException ex) { - System.out.println("Installing database for ButtonCore due to first time usage"); - installDDL(); - } - } @Override public void onDisable() { diff --git a/src/main/java/buttondevteam/lib/CPlayer.java b/src/main/java/buttondevteam/lib/CPlayer.java deleted file mode 100644 index a0efd60..0000000 --- a/src/main/java/buttondevteam/lib/CPlayer.java +++ /dev/null @@ -1,42 +0,0 @@ -package buttondevteam.lib; - -import java.util.UUID; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import buttondevteam.lib.db.CData; - -@Entity -public class CPlayer implements CData { - public CPlayer() { - } - - public CPlayer(UUID chromaid, UUID mcid) { - id = chromaid; - this.mcid = mcid; - } - - @Id - private UUID id; - @Column(unique = true) - private UUID mcid; - - @Override - public UUID getChromaID() { - return id; - } - - public void setChromaID(UUID id) { - this.id = id; - } - - public UUID getMinecraftID() { - return mcid; - } - - public void setMinecraftID(UUID mcid) { - this.mcid = mcid; - } - -} diff --git a/src/main/java/buttondevteam/lib/TBMCPlayerBase.java b/src/main/java/buttondevteam/lib/TBMCPlayerBase.java new file mode 100644 index 0000000..cac3068 --- /dev/null +++ b/src/main/java/buttondevteam/lib/TBMCPlayerBase.java @@ -0,0 +1,15 @@ +package buttondevteam.lib; + +public abstract class TBMCPlayerBase { + /** + * This method returns the filename for this player data. For example, for Minecraft-related data, use MC UUIDs, for Discord data, use Discord IDs, etc. + */ + public abstract String getFileName(); + + /** + * This method returns the folder the file is in. For example, for Minecraft data, this should be "minecraft", for Discord, "discord", etc. + */ + public abstract String getFolder(); + + +} diff --git a/src/main/java/buttondevteam/lib/db/CData.java b/src/main/java/buttondevteam/lib/db/CData.java deleted file mode 100644 index 53f1c1e..0000000 --- a/src/main/java/buttondevteam/lib/db/CData.java +++ /dev/null @@ -1,7 +0,0 @@ -package buttondevteam.lib.db; - -import java.util.UUID; - -public interface CData { - public UUID getChromaID(); -} diff --git a/src/main/java/buttondevteam/lib/db/DataManager.java b/src/main/java/buttondevteam/lib/db/DataManager.java deleted file mode 100644 index e40b7ec..0000000 --- a/src/main/java/buttondevteam/lib/db/DataManager.java +++ /dev/null @@ -1,34 +0,0 @@ -package buttondevteam.lib.db; - -import java.util.UUID; - -import javax.persistence.PersistenceException; - -import org.bukkit.plugin.java.JavaPlugin; - -import com.avaje.ebean.EbeanServer; - -import buttondevteam.core.MainPlugin; - -public final class DataManager { - private static EbeanServer database; - - /** - * Can be only used once and is used by {@link MainPlugin} - * - * @param database - * The database to set - */ - public static void setDatabase(EbeanServer database) { - DataManager.database = database; - } - - public static T load(Class cl, UUID id) { - return database.find(cl, id); - } - - public static void save(T obj) { - database.save(obj); - } - -} From 773bb668081f13351bdc6ec62b19a57d8b178828 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 4 Dec 2016 19:17:14 +0100 Subject: [PATCH 2/2] Now one won't see subcmds they don't have access to --- pom.xml | 10 ++++++++++ src/main/java/buttondevteam/core/MainPlugin.java | 14 +++++++++++++- .../java/buttondevteam/lib/chat/TBMCChatAPI.java | 16 +++++++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index b856f78..2be4132 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,10 @@ jitpack.io https://jitpack.io/ + + vault-repo + http://nexus.hc.to/content/repositories/pub_releases + @@ -100,6 +104,12 @@ Towny master-SNAPSHOT + + com.github.milkbowl + VaultAPI + master-SNAPSHOT + provided + TBMCPlugins diff --git a/src/main/java/buttondevteam/core/MainPlugin.java b/src/main/java/buttondevteam/core/MainPlugin.java index 5455e6e..5525da6 100644 --- a/src/main/java/buttondevteam/core/MainPlugin.java +++ b/src/main/java/buttondevteam/core/MainPlugin.java @@ -5,13 +5,16 @@ import java.util.UUID; import java.util.logging.Logger; import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCPlayer; +import net.milkbowl.vault.permission.Permission; public class MainPlugin extends JavaPlugin { public static MainPlugin Instance; + public static Permission permission; private PluginDescriptionFile pdfFile; private Logger logger; @@ -22,7 +25,7 @@ public class MainPlugin extends JavaPlugin { Instance = this; pdfFile = getDescription(); logger = getLogger(); - + setupPermissions(); logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ")."); TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this); } @@ -35,4 +38,13 @@ public class MainPlugin extends JavaPlugin { } logger.info("Player data saved."); } + + private boolean setupPermissions() { + RegisteredServiceProvider permissionProvider = getServer().getServicesManager() + .getRegistration(Permission.class); + if (permissionProvider != null) { + permission = permissionProvider.getProvider(); + } + return (permission != null); + } } diff --git a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index 3a62ef6..0d81794 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -8,12 +8,14 @@ import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.reflections.Reflections; import org.reflections.scanners.SubTypesScanner; import org.reflections.util.ClasspathHelper; import org.reflections.util.ConfigurationBuilder; +import buttondevteam.core.MainPlugin; import buttondevteam.lib.TBMCChatEvent; import buttondevteam.lib.TBMCCoreAPI; @@ -30,10 +32,12 @@ public class TBMCChatAPI { * * @param command * The command which we want the subcommands of + * @param sender + * The sender for permissions * @return The subcommands */ - public static String[] GetSubCommands(TBMCCommandBase command) { - return GetSubCommands(command.GetCommandPath()); + public static String[] GetSubCommands(TBMCCommandBase command, CommandSender sender) { + return GetSubCommands(command.GetCommandPath(), sender); } /** @@ -41,9 +45,11 @@ public class TBMCChatAPI { * * @param command * The command which we want the subcommands of + * @param sender + * The sender for permissions * @return The subcommands */ - public static String[] GetSubCommands(String command) { + public static String[] GetSubCommands(String command, CommandSender sender) { ArrayList cmds = new ArrayList(); cmds.add("ยง6---- Subcommands ----"); for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) { @@ -51,6 +57,10 @@ public class TBMCChatAPI { int ind = cmd.GetCommandPath().indexOf(' ', command.length() + 2); if (ind >= 0) continue; + if (cmd.GetPlayerOnly() && !(sender instanceof Player)) + continue; + if (cmd.GetModOnly() && !MainPlugin.permission.has(sender, "tbmc.admin")) + continue; cmds.add("/" + cmd.GetCommandPath()); } }