From c85fc6afc24245046e326cf858529acd10f21603 Mon Sep 17 00:00:00 2001 From: Aviortheking <2bazert@gmail.com> Date: Wed, 22 Mar 2017 01:04:44 +0100 Subject: [PATCH] Rework in progress --- .../Minecraft/Marriage/Commands/CmdGen.java | 21 +++ .../Minecraft/Marriage/Custom/Config.java | 122 +++++++++++++++++ .../DeltaWings/Minecraft/Marriage/Main.java | 126 ++++++++++++++++++ 3 files changed, 269 insertions(+) create mode 100644 src/main/java/net/DeltaWings/Minecraft/Marriage/Commands/CmdGen.java create mode 100644 src/main/java/net/DeltaWings/Minecraft/Marriage/Custom/Config.java diff --git a/src/main/java/net/DeltaWings/Minecraft/Marriage/Commands/CmdGen.java b/src/main/java/net/DeltaWings/Minecraft/Marriage/Commands/CmdGen.java new file mode 100644 index 0000000..b3fdf1c --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/Marriage/Commands/CmdGen.java @@ -0,0 +1,21 @@ +package net.DeltaWings.Minecraft.Marriage.Commands; + +import net.DeltaWings.Minecraft.Marriage.Custom.Config; +import org.bukkit.entity.Player; + +/** + * Created by Delta Wings on 22/03/2017 at.00:52 + */ +public class CmdGen { + private Config c = new Config("", "config"); + private Config d = new Config("", "data"); + + + public void sendMessage(Player Player, String Message) { + Player.sendMessage((c.getString("prefix") + Message).replace("&", "ยง")); + } + + public Boolean isMarried(String Player1, String Player2) { + return d.getString(Player1 + ".marry").equalsIgnoreCase(Player2); + } +} diff --git a/src/main/java/net/DeltaWings/Minecraft/Marriage/Custom/Config.java b/src/main/java/net/DeltaWings/Minecraft/Marriage/Custom/Config.java new file mode 100644 index 0000000..5fc05d9 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/Marriage/Custom/Config.java @@ -0,0 +1,122 @@ +package net.DeltaWings.Minecraft.Marriage.Custom; + +import net.DeltaWings.Minecraft.Marriage.Main; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Config { + private final FileConfiguration config; + private final File root = Main.getInstance().getDataFolder(); + private final File folder; + private final File file; + private final String version = "1.0.0"; + + public Config(String folder, String file) { + this.folder = new File(folder); + this.file = new File(root.toString() + File.separator + this.folder.toString() + File.separator + file + ".yml"); + config = YamlConfiguration.loadConfiguration(this.file); + } + + public Boolean exist() { + return file.exists(); + } + + public void set(String path, Object value) { + config.set(path, value); + } + + public void set(String path) { + config.createSection(path); + } + + public void header(String header) { + config.options().header(header); + } + + public int getInt(String path, Integer def) { + return config.getInt(path, def); + } + + public int getInt(String path) { + return config.getInt(path); + } + + public Double getDouble(String path, Double def) { + return config.getDouble(path, def); + } + + public Double getDouble(String path) { + return config.getDouble(path); + } + + public String getString(String path, String def) { + return config.getString(path, def); + } + + public String getString(String path) { + return config.getString(path); + } + + public Long getLong(String path) { + return config.getLong(path); + } + + public Long getLong(String path, Long def) { + return config.getLong(path, def); + } + + public void save() { + try { + config.save(file); + } catch ( IOException e ) { + e.printStackTrace(); + } + } + + public ArrayList getSection(String path) { + return new ArrayList<>(config.getConfigurationSection(path).getKeys(false)); + } + + public List getStringList(String path) { + return config.getStringList(path); + } + + public void create() { + if(!exist()) { + if(!root.exists()) root.mkdirs(); + File rfolder = new File(root.toString() + File.separator + folder.toString()); + if(!rfolder.exists()) rfolder.mkdirs(); + try { + file.createNewFile(); + } catch ( IOException e ) { + e.printStackTrace(); + } + } + } + + public boolean isSet(String path) { + return config.isSet(path); + } + + public boolean getBoolean(String path, Boolean def) { + return config.getBoolean(path, def); + } + + public boolean getBoolean(String path) { + return config.getBoolean(path); + } + + public void delete() { + file.delete(); + } + + public String version() { + return version; + } +} \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/Marriage/Main.java b/src/main/java/net/DeltaWings/Minecraft/Marriage/Main.java index ea87164..d16224c 100644 --- a/src/main/java/net/DeltaWings/Minecraft/Marriage/Main.java +++ b/src/main/java/net/DeltaWings/Minecraft/Marriage/Main.java @@ -1,5 +1,6 @@ package net.DeltaWings.Minecraft.Marriage; +import net.DeltaWings.Minecraft.Marriage.Custom.Config; import net.DeltaWings.Minecraft.Marriage.Events.PlayerJoin; import org.bukkit.command.Command; import org.bukkit.entity.Player; @@ -13,8 +14,15 @@ import java.util.List; public final class Main extends JavaPlugin { + public static Main getInstance() { + return instance; + } + + private static Main instance; + @Override public void onEnable() { + instance = this; // Plugin startup logic getCommand("Marry").setExecutor(new Marry(this)); getCommand("Partner").setExecutor(new Partner(this)); @@ -25,6 +33,8 @@ public final class Main extends JavaPlugin { saveConfig(); PluginManager pm = getServer().getPluginManager(); pm.registerEvents(new PlayerJoin(this), this); + + config(); } @Override @@ -32,6 +42,14 @@ public final class Main extends JavaPlugin { // Plugin shutdown logic } + private void config() { + Config c = new Config("", "config"); + if(!c.exist()) { + c.create(); + c.set("prefix", "&8[&bMarriage&8]&f"); + } + } + public Boolean hasPermission(Command command, String[] arguments, Player player) { List perms = new ArrayList<>(); perms.add("deltawings.marriage.all"); @@ -55,3 +73,111 @@ public final class Main extends JavaPlugin { return true; } } +/* +couples.yml + +Aviortheking: + marry: LePhoenixArdent + home: + world: + x: + y: + z: + requests: + tepenny: blocked + seb23100: {time remaining} + +fonctionnement: +/marry <(i)invite (a)accept or (h)help or null> +/partner + +/divorce + +/divorce help || /divorce +send message to sender message config.intro +send message to sender message (desc of /marry fonctions) +send message to sneder message config.outro + +/divorce player +if sender.marry != player + send message to sender your are not married with player +else + set home to null + set marry to null + if player is online + send message to player sender have divorced with you + send message to sender you have divorced with player + + + +/marry invite player +if player.marry == null + if player.requests.sender is blocked + send message to sender you are blocked + else if player.requests.sender have remaining remaining + send message to sender time is remaining before you can re ask + else + send message to sender you have invited player + send message to player you have been invited by sender + set player.invitations.sender time + 60s +else + send message to sender you are already married + + + +/marry accept player +if sender.invitations.player < time && sender.married == none + set sender.marry to player + set sender.requests to null + set player.marry to sender + set player.requests to null + send message to player message you and sender are now married + send message to sender message you and player are now married + if config.broadcast + send message to server message sender and player are now married +else + send message to sender you don't answered in time or didn't received any request + +/marry help || /marry +send message to sender message config.intro +send message to sender message (desc of /marry fonctions) +send message to sender message config.outro + +/partner || /partner help +send message to sender message config.intro +send message to sender message (desc of /partner fonctions) +send message to sneder message config.outro + +/partner sethome +if sender.home.y is not set + sender.home.world = sender.world + sender.home.x = sender.x + sender.home.y = sender.y + sender.home.z = sender.z + etc etc + sender.marry.home.world = sender.world + sender.marry.home.x = sender.x + sender.marry.home.y = sender.y + sender.marry.home.z = sender.z + send message to sender && sender.marry your home has been set +else + send message to sender you already have a home + +/partner home +if sender.home is set + sender.teleport to sender.home + send message to sender you have been teleported to your home + +/partner delhome +if sender.home.y is set + set sender.home to null + send message to sender && sender.marry your home has been deleted +else + send message to sender you don't have any homes + +/partner tp +if sender.marry is online + sender.teleport to sender.marry +else + send message to sender your partner isn't online + */