Forgot that I wasn't on master

This commit is contained in:
Norbi Peti 2016-12-04 20:30:18 +01:00
commit 55ac426554
7 changed files with 51 additions and 111 deletions

10
pom.xml
View file

@ -75,6 +75,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
</repositories>
<dependencies>
<dependency>
@ -100,6 +104,12 @@
<artifactId>Towny</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.milkbowl</groupId> <!-- net.milkbowl.vault -->
<artifactId>VaultAPI</artifactId>
<version>master-SNAPSHOT</version> <!-- 1.6 -->
<scope>provided</scope>
</dependency>
</dependencies>
<organization>
<name>TBMCPlugins</name>

View file

@ -4,19 +4,17 @@ 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.RegisteredServiceProvider;
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;
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;
@ -27,29 +25,10 @@ public class MainPlugin extends JavaPlugin {
Instance = this;
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());*/
setupPermissions();
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() {
@ -59,4 +38,13 @@ public class MainPlugin extends JavaPlugin {
}
logger.info("Player data saved.");
}
private boolean setupPermissions() {
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager()
.getRegistration(Permission.class);
if (permissionProvider != null) {
permission = permissionProvider.getProvider();
}
return (permission != null);
}
}

View file

@ -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;
}
}

View file

@ -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();
}

View file

@ -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<String> cmds = new ArrayList<String>();
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());
}
}

View file

@ -1,7 +0,0 @@
package buttondevteam.lib.db;
import java.util.UUID;
public interface CData {
public UUID getChromaID();
}

View file

@ -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 extends CData> T load(Class<T> cl, UUID id) {
return database.find(cl, id);
}
public static <T extends CData> void save(T obj) {
database.save(obj);
}
}