mirror of
https://github.com/TotalFreedomMC/TF-Marriage.git
synced 2024-12-31 20:42:18 +00:00
Add divorce command
This commit is contained in:
parent
811e84034c
commit
06ce7d6d88
7 changed files with 72 additions and 11 deletions
|
@ -45,7 +45,7 @@ public class Marriage extends JavaPlugin {
|
|||
private Map<String, MPlayer> players = new WeakHashMap<String, MPlayer>();
|
||||
private Updater updater;
|
||||
|
||||
public static String COMPAT_VERSION = "v1_7_R4";
|
||||
public static String COMPAT_VERSION = "v1_8_R1";
|
||||
public static boolean IS_COMPATIBLE = true;
|
||||
public Map<String, PlayerConfig> configs = new HashMap<String, PlayerConfig>();
|
||||
|
||||
|
|
|
@ -3,16 +3,16 @@ package com.lenis0012.bukkit.marriage.util;
|
|||
import java.lang.reflect.Field;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.server.v1_7_R4.DataWatcher;
|
||||
import net.minecraft.server.v1_7_R4.EntityPlayer;
|
||||
import net.minecraft.server.v1_7_R4.MathHelper;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityStatus;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutWorldParticles;
|
||||
import net.minecraft.server.v1_8_R1.DataWatcher;
|
||||
import net.minecraft.server.v1_8_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R1.MathHelper;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutEntityStatus;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutSpawnEntityLiving;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutWorldParticles;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PacketUtil {
|
||||
|
|
|
@ -70,4 +70,16 @@ public interface MPlayer {
|
|||
* @param inChat Whether or not the player is in marry chat-mode.
|
||||
*/
|
||||
void setInChat(boolean inChat);
|
||||
|
||||
/**
|
||||
* Get the current player's partner
|
||||
*
|
||||
* @return Current partner of the player
|
||||
*/
|
||||
MPlayer getPartner();
|
||||
|
||||
/**
|
||||
* Divorce with the current player's partner
|
||||
*/
|
||||
void divorce();
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.lenis0012.bukkit.marriage2.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.lenis0012.bukkit.marriage2.MPlayer;
|
||||
import com.lenis0012.bukkit.marriage2.Marriage;
|
||||
import com.lenis0012.bukkit.marriage2.config.Message;
|
||||
|
||||
public class CommandDivorce extends Command {
|
||||
|
||||
public CommandDivorce(Marriage marriage, String[] aliases) {
|
||||
super(marriage, "divorce");
|
||||
setDescription("Divorce your current partner");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
MPlayer mPlayer = marriage.getMPlayer(player.getUniqueId());
|
||||
MPlayer partner = mPlayer.getPartner();
|
||||
if(partner != null) {
|
||||
mPlayer.divorce();
|
||||
broadcast(Message.DIVORCED, player.getName(), Bukkit.getOfflinePlayer(partner.getUniqueId()).getName());
|
||||
} else {
|
||||
reply(Message.NOT_MARRIED);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,7 +8,9 @@ public enum Message {
|
|||
TARGET_ALREADY_MARRIED("&cPlayers %s is already married to someone!"),
|
||||
ALREADY_MARRIED("&cYou are already married to someone!"),
|
||||
MARRIED("&a&lPlayer %s and %s are now officially married!"),
|
||||
MARRIAGE_REQUESTED("&aPlayer %s has requested you to marry with them, use &e/marry %s &ato accept it.");
|
||||
MARRIAGE_REQUESTED("&aPlayer %s has requested you to marry with them, use &e/marry %s &ato accept it."),
|
||||
NOT_MARRIED("&cYou are currently not married with someone!"),
|
||||
DIVORCED("&aPlayer %s and %s have divorced!");
|
||||
|
||||
private final String defaultMessage;
|
||||
private String message;
|
||||
|
|
|
@ -11,6 +11,8 @@ import net.minecraft.util.com.google.common.collect.Lists;
|
|||
import com.lenis0012.bukkit.marriage2.Gender;
|
||||
import com.lenis0012.bukkit.marriage2.MData;
|
||||
import com.lenis0012.bukkit.marriage2.MPlayer;
|
||||
import com.lenis0012.bukkit.marriage2.Marriage;
|
||||
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
|
||||
|
||||
public class MarriagePlayer implements MPlayer {
|
||||
private final List<UUID> requests = Lists.newArrayList();
|
||||
|
@ -80,4 +82,22 @@ public class MarriagePlayer implements MPlayer {
|
|||
public void setInChat(boolean inChat) {
|
||||
this.inChat = inChat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPlayer getPartner() {
|
||||
Marriage core = MarriagePlugin.getInstance();
|
||||
UUID id = null;
|
||||
if(marriage != null) {
|
||||
id = uuid.equals(marriage.getPlayer1Id()) ? marriage.getPllayer2Id() : marriage.getPlayer1Id();
|
||||
}
|
||||
|
||||
return core.getMPlayer(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void divorce() {
|
||||
MarriagePlayer partner = (MarriagePlayer) getPartner();
|
||||
partner.marriage = null;
|
||||
this.marriage = null;
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ public class DatabaseListener implements Listener {
|
|||
if(event.getLoginResult() == Result.ALLOWED) {
|
||||
core.getMPlayer(event.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
|
|
Loading…
Reference in a new issue