diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a98b458 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.classpath +.project +.settings/* +bin/* \ No newline at end of file diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..ff4a46e --- /dev/null +++ b/plugin.yml @@ -0,0 +1,80 @@ +name: RealEstate +main: me.EtienneDx.RealEstate +version: 0.1 +authors: [EtienneDx] +depend: [GriefPrevention, Vault] + +commands: + re: + description: Access to the GriefProtection_RealEstate informations. + usage: / ? + aliases: [realestate] + permission: realestate.info + permission-message: You do not have access to that command! + +permissions: + realestate.*: + description: Gives access to all Real Estate permissions + default: op + children: + realestate.info: true + realestate.admin: true + realestate.claim.buy: true + realestate.claim.sell: true + realestate.claim.rent: true + realestate.claim.lease: true + realestate.subclaim.buy: true + realestate.subclaim.sell: true + realestate.subclaim.rent: true + realestate.subclaim.lease: true + realestate.ignore.limit: true + realestate.claim.*: + description: Allows the player full access over claims + default: op + children: + realestate.claim.buy: true + realestate.claim.sell: true + realestate.claim.rent: true + realestate.claim.lease: true + realestate.subclaim.*: + description: Allows the player full access over subclaims + default: op + children: + realestate.subclaim.buy: true + realestate.subclaim.sell: true + realestate.subclaim.rent: true + realestate.subclaim.lease: true + realestate.admin: + description: Allows the player to have access to Real Estate informations + default: op + realestate.info: + description: Allow the player to get informations about the claim + default: true + realestate.claim.buy: + description: Allows the player to buy claims + default: true + realestate.claim.sell: + description: Allows the player to sell claims + default: true + realestate.claim.rent: + description: Allows the player to rent claims + default: true + realestate.claim.lease: + description: Allows the player to lease claims + default: true + realestate.subclaim.buy: + description: Allows the player to buy subclaims + default: true + realestate.subclaim.sell: + description: Allows the player to sell subclaims + default: true + realestate.subclaim.rent: + description: Allows the player to rent subclaims + default: true + realestate.subclaim.lease: + description: Allows the player to lease subclaims + default: true + realestate.ignore.limit: + description: Allows the player to buy bigger claims than his available claim size + default: false + \ No newline at end of file diff --git a/src/me/EtienneDx/GPRE/DataStore.java b/src/me/EtienneDx/GPRE/DataStore.java new file mode 100644 index 0000000..2f5afcb --- /dev/null +++ b/src/me/EtienneDx/GPRE/DataStore.java @@ -0,0 +1,65 @@ +package me.EtienneDx.GPRE; + +import java.io.File; +import java.util.Arrays; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.PluginDescriptionFile; + +public class DataStore +{ + RealEstate plugin; + public PluginDescriptionFile pdf; + + public final String pluginDirPath = "plugins" + File.separator + "GriefProtection_RealEstate" + File.separator; + public final String configFilePath = this.pluginDirPath + "config.yml"; + public final String logFilePath = this.pluginDirPath + "GriefProtection_RealEstate.log"; + public final String chatPrefix = "[" + ChatColor.GOLD + "RealEstate" + ChatColor.WHITE + "] "; + + public List cfgSigns; + + public List cfgSellKeywords; + public List cfgLeaseKeywords; + + public String cfgReplaceSell; + public String cfgReplaceLease; + + public boolean cfgEnableLease; + public boolean cfgEnableRent; + + public boolean cfgTransferClaimBlocks; + + public boolean cfgMessageOwner; + public boolean cfgBrodcastSell; + + public DataStore(RealEstate plugin) + { + this.plugin = plugin; + this.pdf = this.plugin.getDescription(); + } + + public String getString(List li) + { + return String.join(";", li); + } + + public List getList(String str) + { + return Arrays.asList(str.split(";")); + } + + List getConfigList(YamlConfiguration config, String path, List defVal) + { + config.addDefault(path, defVal); + return config.getStringList(path); + } + + public void loadConfig(YamlConfiguration config) + { + this.cfgSigns = getConfigList(config, "RealEstate.Keywords.Signs", Arrays.asList("re", "realestate")); + + this.cfgSigns = getConfigList(config, "RealEstate.Keywords.Signs", Arrays.asList("re", "realestate")); + } +} diff --git a/src/me/EtienneDx/GPRE/RealEstate.java b/src/me/EtienneDx/GPRE/RealEstate.java new file mode 100644 index 0000000..f5a6b38 --- /dev/null +++ b/src/me/EtienneDx/GPRE/RealEstate.java @@ -0,0 +1,117 @@ +package me.EtienneDx.GPRE; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.logging.Logger; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; + +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.permission.Permission; + +public class RealEstate extends JavaPlugin +{ + Logger log; + DataStore dataStore; + public static boolean vaultPresent = false; + public static Economy econ = null; + public static Permission perms = null; + + public void onEnable() + { + this.log = getLogger(); + + if (checkVault()) + { + this.log.info("Vault has been detected and enabled."); + if (setupEconomy()) + { + this.log.info("Vault is using " + econ.getName() + " as the economy plugin."); + } + else + { + this.log.warning("No compatible economy plugin detected [Vault]."); + this.log.warning("Disabling plugin."); + getPluginLoader().disablePlugin(this); + return; + } + if (setupPermissions()) + { + this.log.info("Vault is using " + perms.getName() + " for the permissions."); + } + else + { + this.log.warning("No compatible permissions plugin detected [Vault]."); + this.log.warning("Disabling plugin."); + getPluginLoader().disablePlugin(this); + return; + } + } + loadConfig(false); + } + + private void loadConfig(boolean reload) + { + FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.dataStore.configFilePath)); + FileConfiguration outConfig = new YamlConfiguration(); + + + try + { + outConfig.save(this.dataStore.configFilePath); + } + catch (IOException exception) + { + this.log.info("Unable to write to the configuration file at \"" + this.dataStore.configFilePath + "\""); + } + } + + public void addLogEntry(String entry) + { + try + { + File logFile = new File(this.dataStore.logFilePath); + if (!logFile.exists()) { + logFile.createNewFile(); + } + FileWriter fw = new FileWriter(logFile, true); + PrintWriter pw = new PrintWriter(fw); + + pw.println(entry); + pw.flush(); + pw.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + private boolean checkVault() + { + vaultPresent = getServer().getPluginManager().getPlugin("Vault") != null; + return vaultPresent; + } + + private boolean setupEconomy() + { + RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); + if (rsp == null) { + return false; + } + econ = (Economy)rsp.getProvider(); + return econ != null; + } + + private boolean setupPermissions() + { + RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Permission.class); + perms = (Permission)rsp.getProvider(); + return perms != null; + } +}