Starting to get things in place
This commit is contained in:
parent
162eff537d
commit
72833734d8
@ -1,65 +0,0 @@
|
|||||||
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<String> cfgSigns;
|
|
||||||
|
|
||||||
public List<String> cfgSellKeywords;
|
|
||||||
public List<String> 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<String> li)
|
|
||||||
{
|
|
||||||
return String.join(";", li);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getList(String str)
|
|
||||||
{
|
|
||||||
return Arrays.asList(str.split(";"));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> getConfigList(YamlConfiguration config, String path, List<String> 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"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
42
src/me/EtienneDx/RealEstate/ClaimSell.java
Normal file
42
src/me/EtienneDx/RealEstate/ClaimSell.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package me.EtienneDx.RealEstate;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
|
||||||
|
public class ClaimSell implements ConfigurationSerializable
|
||||||
|
{
|
||||||
|
private long claimId;
|
||||||
|
private UUID owner = null;
|
||||||
|
private double price;
|
||||||
|
private Sign sign = null;
|
||||||
|
|
||||||
|
public ClaimSell(Map<String, Object> map)
|
||||||
|
{
|
||||||
|
this.claimId = (long) map.get("claimId");
|
||||||
|
if(map.get("owner") != null)
|
||||||
|
this.owner = UUID.fromString((String) map.get("owner"));
|
||||||
|
this.price = (double) map.get("price");
|
||||||
|
if(map.get("signLocation") != null)
|
||||||
|
this.sign = (Sign)((Location)map.get("signLocation")).getBlock().getState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> serialize()
|
||||||
|
{
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
|
||||||
|
map.put("claimId", this.claimId);
|
||||||
|
if(owner != null)
|
||||||
|
map.put("owner", owner.toString());
|
||||||
|
map.put("price", this.price);
|
||||||
|
if(sign != null)
|
||||||
|
map.put("signLocation", sign.getLocation());
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
||||||
120
src/me/EtienneDx/RealEstate/DataStore.java
Normal file
120
src/me/EtienneDx/RealEstate/DataStore.java
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
package me.EtienneDx.RealEstate;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
|
||||||
|
public class DataStore
|
||||||
|
{
|
||||||
|
public PluginDescriptionFile pdf;
|
||||||
|
|
||||||
|
public final String configFilePath = RealEstate.pluginDirPath + "config.yml";
|
||||||
|
public final String logFilePath = RealEstate.pluginDirPath + "GriefProtection_RealEstate.log";
|
||||||
|
public final String chatPrefix = "[" + ChatColor.GOLD + "RealEstate" + ChatColor.WHITE + "] ";
|
||||||
|
|
||||||
|
public List<String> cfgSigns;
|
||||||
|
|
||||||
|
public List<String> cfgSellKeywords;
|
||||||
|
public List<String> cfgLeaseKeywords;
|
||||||
|
|
||||||
|
public String cfgReplaceSell;
|
||||||
|
public String cfgReplaceLease;
|
||||||
|
|
||||||
|
public boolean cfgEnableSell;
|
||||||
|
public boolean cfgEnableLease;
|
||||||
|
|
||||||
|
public boolean cfgTransferClaimBlocks;
|
||||||
|
|
||||||
|
public boolean cfgMessageOwner;
|
||||||
|
public boolean cfgBroadcastSell;
|
||||||
|
|
||||||
|
public double cfgPriceSellPerBlock;
|
||||||
|
public double cfgPriceLeasePerBlock;
|
||||||
|
|
||||||
|
public DataStore()
|
||||||
|
{
|
||||||
|
this.pdf = RealEstate.instance.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(List<String> li)
|
||||||
|
{
|
||||||
|
return String.join(";", li);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getList(String str)
|
||||||
|
{
|
||||||
|
return Arrays.asList(str.split(";"));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> getConfigList(YamlConfiguration config, String path, List<String> 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.cfgSellKeywords = getConfigList(config, "RealEstate.Keywords.Sell", Arrays.asList("sell", "selling", "for sale"));
|
||||||
|
this.cfgLeaseKeywords = getConfigList(config, "RealEstate.Keywords.Lease", Arrays.asList("rent", "renting", "for rent", "lease", "for lease"));
|
||||||
|
|
||||||
|
this.cfgReplaceSell = config.getString("RealEstate.Keywords.Replace.Sell", "FOR SALE");
|
||||||
|
this.cfgReplaceLease = config.getString("RealEstate.Keywords.Replace.Lease", "FOR LEASE");
|
||||||
|
|
||||||
|
this.cfgEnableSell = config.getBoolean("RealEstate.Rules.Sell", true);
|
||||||
|
this.cfgEnableLease = config.getBoolean("RealEstate.Rules.Lease", true);
|
||||||
|
|
||||||
|
this.cfgTransferClaimBlocks = config.getBoolean("RealEstate.Rules.TransferClaimBlocks", true);
|
||||||
|
|
||||||
|
this.cfgMessageOwner = config.getBoolean("RealEstate.Messaging.MessageOwner", true);
|
||||||
|
this.cfgBroadcastSell = config.getBoolean("RealEstate.Messaging.BroadcastSell", true);
|
||||||
|
|
||||||
|
this.cfgPriceSellPerBlock = config.getDouble("RealEstate.DefaultPricesPerBlock.Sell", 5.0);
|
||||||
|
this.cfgPriceLeasePerBlock = config.getDouble("RealEstate.DefaultPricesPerBlock.Lease", 2.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadConfig()
|
||||||
|
{
|
||||||
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(new File(this.configFilePath));
|
||||||
|
this.loadConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveConfig()
|
||||||
|
{
|
||||||
|
FileConfiguration outConfig = new YamlConfiguration();
|
||||||
|
outConfig.set("RealEstate.Keywords.Signs", this.cfgSigns);
|
||||||
|
|
||||||
|
outConfig.set("RealEstate.Keywords.Sell", this.cfgSellKeywords);
|
||||||
|
outConfig.set("RealEstate.Keywords.Lease", this.cfgLeaseKeywords);
|
||||||
|
|
||||||
|
outConfig.set("RealEstate.Keywords.Replace.Sell", this.cfgReplaceSell);
|
||||||
|
outConfig.set("RealEstate.Keywords.Replace.Lease", this.cfgReplaceLease);
|
||||||
|
|
||||||
|
outConfig.set("RealEstate.Rules.Sell", this.cfgEnableSell);
|
||||||
|
outConfig.set("RealEstate.Rules.Lease", this.cfgEnableLease);
|
||||||
|
|
||||||
|
outConfig.set("RealEstate.Rules.TransferClaimBlocks", this.cfgTransferClaimBlocks);
|
||||||
|
|
||||||
|
outConfig.set("RealEstate.Messaging.MessageOwner", this.cfgMessageOwner);
|
||||||
|
outConfig.set("RealEstate.Messaging.BroadcastSell", this.cfgBroadcastSell);
|
||||||
|
|
||||||
|
outConfig.set("RealEstate.DefaultPricePerBlock.Sell", this.cfgPriceSellPerBlock);
|
||||||
|
outConfig.set("RealEstate.DefaultPricePerBlock.Lease", this.cfgPriceLeasePerBlock);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
outConfig.save(this.configFilePath);
|
||||||
|
}
|
||||||
|
catch (IOException exception)
|
||||||
|
{
|
||||||
|
RealEstate.instance.log.info("Unable to write to the configuration file at \"" + this.configFilePath + "\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/me/EtienneDx/RealEstate/REListener.java
Normal file
14
src/me/EtienneDx/RealEstate/REListener.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package me.EtienneDx.RealEstate;
|
||||||
|
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
|
||||||
|
public class REListener implements Listener
|
||||||
|
{
|
||||||
|
void registerEvents()
|
||||||
|
{
|
||||||
|
PluginManager pm = RealEstate.instance.getServer().getPluginManager();
|
||||||
|
|
||||||
|
pm.registerEvents(this, RealEstate.instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package me.EtienneDx.GPRE;
|
package me.EtienneDx.RealEstate;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
@ -6,8 +6,7 @@ import java.io.IOException;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -18,12 +17,18 @@ public class RealEstate extends JavaPlugin
|
|||||||
{
|
{
|
||||||
Logger log;
|
Logger log;
|
||||||
DataStore dataStore;
|
DataStore dataStore;
|
||||||
|
public final static String pluginDirPath = "plugins" + File.separator + "GriefProtection_RealEstate" + File.separator;
|
||||||
public static boolean vaultPresent = false;
|
public static boolean vaultPresent = false;
|
||||||
public static Economy econ = null;
|
public static Economy econ = null;
|
||||||
public static Permission perms = null;
|
public static Permission perms = null;
|
||||||
|
|
||||||
|
public static RealEstate instance = null;
|
||||||
|
|
||||||
|
public static TransactionsStore transactionsStore = null;
|
||||||
|
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
|
RealEstate.instance = this;
|
||||||
this.log = getLogger();
|
this.log = getLogger();
|
||||||
|
|
||||||
if (checkVault())
|
if (checkVault())
|
||||||
@ -52,23 +57,12 @@ public class RealEstate extends JavaPlugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadConfig(false);
|
this.dataStore.loadConfig();// loads config or default
|
||||||
}
|
this.dataStore.saveConfig();// save eventual default
|
||||||
|
|
||||||
private void loadConfig(boolean reload)
|
ConfigurationSerialization.registerClass(ClaimSell.class);
|
||||||
{
|
|
||||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.dataStore.configFilePath));
|
|
||||||
FileConfiguration outConfig = new YamlConfiguration();
|
|
||||||
|
|
||||||
|
this.transactionsStore = new TransactionsStore();
|
||||||
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)
|
public void addLogEntry(String entry)
|
||||||
31
src/me/EtienneDx/RealEstate/TransactionsStore.java
Normal file
31
src/me/EtienneDx/RealEstate/TransactionsStore.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package me.EtienneDx.RealEstate;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
public class TransactionsStore
|
||||||
|
{
|
||||||
|
public final String dataFilePath = RealEstate.pluginDirPath + "transactions.data";
|
||||||
|
|
||||||
|
public ArrayList<ClaimSell> claimSell;
|
||||||
|
|
||||||
|
public TransactionsStore()
|
||||||
|
{
|
||||||
|
claimSell = new ArrayList<>();
|
||||||
|
|
||||||
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.dataFilePath));
|
||||||
|
for(String key : config.getKeys(false))
|
||||||
|
{
|
||||||
|
if(key.startsWith("Sell."))
|
||||||
|
{
|
||||||
|
ClaimSell cs = (ClaimSell)config.get(key);
|
||||||
|
claimSell.add(cs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user