From f10ed5443a84ad9a0f6b25b933f04dbcd6051a6c Mon Sep 17 00:00:00 2001
From: Aviortheking <2bazert@gmail.com>
Date: Mon, 2 Jan 2017 23:59:07 +0100
Subject: [PATCH] WIP
---
.idea/artifacts/Marriage.xml | 10 ++++
.idea/libraries/ressources.xml | 13 +++++
Mariage/Mariage.iml | 5 +-
Mariage/src/config.yml | 23 ++++----
.../DeltaWings/Minecraft/Marriage/Main.java | 4 ++
.../DeltaWings/Minecraft/Marriage/Marry.java | 31 ++++++++---
.../Minecraft/Marriage/Partner.java | 55 +++++++++++++++++++
.../Minecraft/Marriage/PlayerJoin.java | 40 ++++++++++++++
8 files changed, 163 insertions(+), 18 deletions(-)
create mode 100644 .idea/artifacts/Marriage.xml
create mode 100644 .idea/libraries/ressources.xml
create mode 100644 Mariage/src/net/DeltaWings/Minecraft/Marriage/Partner.java
create mode 100644 Mariage/src/net/DeltaWings/Minecraft/Marriage/PlayerJoin.java
diff --git a/.idea/artifacts/Marriage.xml b/.idea/artifacts/Marriage.xml
new file mode 100644
index 0000000..42933f1
--- /dev/null
+++ b/.idea/artifacts/Marriage.xml
@@ -0,0 +1,10 @@
+
+
+ $PROJECT_DIR$/Mariage/tests/plugins
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/ressources.xml b/.idea/libraries/ressources.xml
new file mode 100644
index 0000000..3a9647b
--- /dev/null
+++ b/.idea/libraries/ressources.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Mariage/Mariage.iml b/Mariage/Mariage.iml
index bd3d5d8..e927a22 100644
--- a/Mariage/Mariage.iml
+++ b/Mariage/Mariage.iml
@@ -1,6 +1,8 @@
-
+
+
+
@@ -9,5 +11,6 @@
+
\ No newline at end of file
diff --git a/Mariage/src/config.yml b/Mariage/src/config.yml
index b9e19d2..3ad1265 100644
--- a/Mariage/src/config.yml
+++ b/Mariage/src/config.yml
@@ -1,22 +1,25 @@
config:
#time to let the player answer
timeout: 60
+ isbroadcasted: true
messages:
- proposition: "Dear %receiver%, \nWould you like to marry me ? \nFrom %sender%. \n(You have %time% seconds to send your answer !) \n(use '/marry accept %player%' to accept the proposition)"
+ miss-spell: "&cYou have miss-spelled somethings !"
+ no-proposition: "&cThe &8%player% &chasn't sended a proposition"
+ accepted: you have accepted the proposition !
+ broadcast: "&c %p1% has been married with %p2% !"
+ already-married: "&cSorry, but you are already married with someone."
+ proposition: Dear %receiver%, \nWould you like to marry me ? \nFrom %sender%. \n\(You have %time% seconds to send your answer !\) \n\(use '/marry accept %player%' to accept the proposition\)
# don't touch under this !!!
partners: #each players have the sames infos !
player:
- married: false #is the player married ?
- who: Aviortheking #name of the partner
+ who: none #name of the partner
+ propositions:
+ otherplayer:
+ isblocked: true
+ timeout: 60
home: # coords of the home
x: 0
y: 0
z: 0
- world: world
- propositions:
- otherplayer: #other player name
- isblocked: true #if blocked the player won't receive a proposition !
- timeout: 60 # time before the proposition stop while at 0 the other player can reinvite if not blocked
-
-
+ world: world
\ No newline at end of file
diff --git a/Mariage/src/net/DeltaWings/Minecraft/Marriage/Main.java b/Mariage/src/net/DeltaWings/Minecraft/Marriage/Main.java
index 3c84768..c573310 100644
--- a/Mariage/src/net/DeltaWings/Minecraft/Marriage/Main.java
+++ b/Mariage/src/net/DeltaWings/Minecraft/Marriage/Main.java
@@ -1,6 +1,7 @@
package net.DeltaWings.Minecraft.Marriage;
import org.bukkit.event.Listener;
+import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
/**
@@ -10,10 +11,13 @@ public class Main extends JavaPlugin implements Listener{
public void onEnable(){
getCommand("Marry").setExecutor(new Marry(this));
+ getCommand("Partner").setExecutor(new Partner(this));
//load the config
getConfig().options().copyDefaults(true);
saveConfig();
+ PluginManager pm = getServer().getPluginManager();
+ pm.registerEvents(new PlayerJoin(this), this);
}
public void onDisable() {
diff --git a/Mariage/src/net/DeltaWings/Minecraft/Marriage/Marry.java b/Mariage/src/net/DeltaWings/Minecraft/Marriage/Marry.java
index e1e24ec..7108875 100644
--- a/Mariage/src/net/DeltaWings/Minecraft/Marriage/Marry.java
+++ b/Mariage/src/net/DeltaWings/Minecraft/Marriage/Marry.java
@@ -14,10 +14,12 @@ import net.DeltaWings.Minecraft.Marriage.Main;
*/
public class Marry implements CommandExecutor {
+ private Main pl;
private FileConfiguration config;
Marry(Main main) {
- this.config = main.getConfig();
+ this.pl = main;
+ this.config = pl.getConfig();
}
@Override
@@ -25,6 +27,7 @@ public class Marry implements CommandExecutor {
if(sender instanceof Player) {
Player p = (Player)sender;
if(cmd.getName().equalsIgnoreCase("marry")) {
+ // /marry to ask a player to marry him/her
if(args.length == 1 && !args[0].equalsIgnoreCase("accept")) {
Boolean found = false;
for(Player player : Bukkit.getServer().getOnlinePlayers()) {
@@ -40,16 +43,30 @@ public class Marry implements CommandExecutor {
//send message "Player isn't online or is not correctly typed"
p.sendMessage(args[0]+" isn't online or you haven't correctly typed his/her name !");
}
+ // /marry accept
} else if (args.length == 2 && args[0].equalsIgnoreCase("accept")) {
- if(config.getInt("partners."+p.getName()+".propositions."+args[1]+".timeout", 0) > 0) {
- //message you have accepted the proposition
- //bd %couple has been married !
- } else {
- //message the other player haven't send a proposition or the proposition is timed out !
- }
+ if (!config.getString("partners." + p.getName() + ".who").equalsIgnoreCase("none"))
+ p.sendMessage((config.getString("messages.already-married").replace("&", "§")));
+ else if (config.getConfigurationSection("partners." + p.getName() + ".propositions").contains(args[1])) {
+ String conf = "partners." + p.getName() + ".";
+ config.set(conf + "who", args[1]);
+ config.set(conf + "propositions", null);
+ p.sendMessage(config.getString("messages.accepted"));
+ if (config.getBoolean("config.isbroadcasted"))
+ Bukkit.broadcastMessage(config.getString("messages.broadcast").replace("&", "§").replace("%p1%", p.getName()).replace("%p2%", args[1]));
+ } else p.sendMessage(config.getString("messages.no-proposition").replace("%player%", args[1]).replace("&", "§"));
+ //check si marrié
+ //msg t'es déjà marrié sale con !
+ //sinon check si le joueur lui a proposée
+ //message you have accepted the proposition
+ //bd %p1 and %p2 has been married !
+ //sinon message le joueur ne t'a pas proposée de te marrié avc lui/elle
+ } else {
+ p.sendMessage(config.getString("messages.miss-spell").replace("&", "§"));
}
}
}
+ pl.saveConfig();
return true;
}
}
diff --git a/Mariage/src/net/DeltaWings/Minecraft/Marriage/Partner.java b/Mariage/src/net/DeltaWings/Minecraft/Marriage/Partner.java
new file mode 100644
index 0000000..5d783e8
--- /dev/null
+++ b/Mariage/src/net/DeltaWings/Minecraft/Marriage/Partner.java
@@ -0,0 +1,55 @@
+package net.DeltaWings.Minecraft.Marriage;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.entity.Player;
+
+/**
+ * Created by Delta Wings on 02/01/2017 at.23:35
+ */
+public class Partner implements CommandExecutor {
+
+ private Main pl;
+ private FileConfiguration config;
+
+ Partner(Main main) {
+ this.pl = main;
+ this.config = pl.getConfig();
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+ if(sender instanceof Player) {
+ Player p = (Player) sender;
+ if (cmd.getName().equalsIgnoreCase("partner")) {
+ /**
+ * infos/info
+ * join
+ * sethome/shome
+ * home
+ * delhome/dhome
+ * message/msg
+ * sendgift/gift
+ */
+ if (args.length == 1 && (args[0].equalsIgnoreCase("infos") || args[0].equalsIgnoreCase("info"))) {
+ // /partner infos
+ } else if (args.length == 1 && args[0].equalsIgnoreCase("join")) {
+ // /partner join
+ } else if (args.length == 1 && (args[0].equalsIgnoreCase("sethome") || args[0].equalsIgnoreCase("shome"))) {
+ // /partner sethome/shome
+ } else if (args.length == 1 && (args[0].equalsIgnoreCase("home"))) {
+ // /partner home
+ } else if (args.length == 1 && (args[0].equalsIgnoreCase("delhome") || args[0].equalsIgnoreCase("dhome"))) {
+ // /partner delhome/dhome
+ } else if (args.length == 1 && (args[0].equalsIgnoreCase("message") || args[0].equalsIgnoreCase("msg"))) {
+ // /partner message/msg
+ } else if (args.length == 1 && (args[0].equalsIgnoreCase("sendgift") || args[0].equalsIgnoreCase("gift"))) {
+ // /partner sendgift/gift
+ }
+ }
+ }
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/Mariage/src/net/DeltaWings/Minecraft/Marriage/PlayerJoin.java b/Mariage/src/net/DeltaWings/Minecraft/Marriage/PlayerJoin.java
new file mode 100644
index 0000000..6036f3e
--- /dev/null
+++ b/Mariage/src/net/DeltaWings/Minecraft/Marriage/PlayerJoin.java
@@ -0,0 +1,40 @@
+package net.DeltaWings.Minecraft.Marriage;
+
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerJoinEvent;
+
+/**
+ * Created by Delta Wings on 02/01/2017 at.20:37
+ */
+public class PlayerJoin implements Listener {
+
+ private Main pl;
+ private FileConfiguration config;
+
+ PlayerJoin(Main main) {
+ this.pl = main;
+ this.config = pl.getConfig();
+ }
+
+ @EventHandler
+ public void onPlayerJoinEvent(PlayerJoinEvent e) {
+ Player p = e.getPlayer();
+ String Base = "partners."+p.getName();
+ if(!p.hasPlayedBefore()) {
+ config.createSection(Base);
+ config.createSection(Base+".who");
+ config.set(Base+".who", "none");
+ config.createSection(Base+".propositions");
+
+ } else if (!config.isSet(Base)) {
+ config.createSection(Base);
+ config.createSection(Base+".who");
+ config.set(Base+".who", "none");
+ config.createSection(Base+".propositions");
+ }
+ pl.saveConfig();
+ }
+}