Completed marry command

This commit is contained in:
Lennart ten Wolde 2014-11-13 10:54:23 +01:00
parent b6eeaf8cb9
commit 0c4ccfb93e
8 changed files with 91 additions and 34 deletions

View file

@ -13,6 +13,21 @@ public interface MPlayer {
*/
UUID getUniqueId();
/**
* Request marriage with this player by another.
*
* @param from Player who requested the marriage.
*/
void requestMarriage(UUID from);
/**
* Check if marriage with this player is requested by another.
*
* @param from Marriage requester.
* @return Whether or not marriage is requested by the player.
*/
boolean isMarriageRequested(UUID from);
/**
* Get the player's gender.
*

View file

@ -10,14 +10,13 @@ import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
import com.lenis0012.bukkit.marriage2.misc.BConfig;
public interface Marriage {
/**
* Return a {@link com.lenis0012.bukkit.marriage2.misc.BConfig} from a YAML file.
*
* @param file File name.
* @return Bukkit configuration instance.
*/
public BConfig getBukkitConfig(String file);
BConfig getBukkitConfig(String file);
/**
* Return a {@link com.lenis0012.bukkit.marriage2.MPlayer} instance of a player.
@ -25,33 +24,41 @@ public interface Marriage {
* @param uuid Unique user id of the wanted player.
* @return {@link com.lenis0012.bukkit.marriage2.MPlayer} of the wanted player.
*/
public MPlayer getMPlayer(UUID uuid);
MPlayer getMPlayer(UUID uuid);
/**
* Marry 2 players to eachother.
*
* @param player1 Player 1
* @param player2 Player 2
*/
void marry(MPlayer player1, MPlayer player2);
/**
* Register a {@link org.bukkit.event.Listener} to this plugin.
*
* @param listener Listener to be registered.
*/
public void register(Listener listener);
void register(Listener listener);
/**
* Register a subcommand to the /marry command.
*
* @param commandClass Class of the sub command to be registered.
*/
public void register(Class<? extends Command> commandClass);
void register(Class<? extends Command> commandClass);
/**
* Get the plugin logger instance.
*
* @return Plugin logger.
*/
public Logger getLogger();
Logger getLogger();
/**
* Get the plugin instance.
*
* @return Plugin instance.
*/
public MarriagePlugin getPlugin();
MarriagePlugin getPlugin();
}

View file

@ -5,9 +5,11 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.lang.Message;
public abstract class Command {
protected final Marriage marriage;
private final String[] aliases;
private String description = "No description available";
private String usage = "";
@ -19,7 +21,8 @@ public abstract class Command {
protected Player player;
private String[] args;
public Command(String... aliases) {
public Command(Marriage marriage, String... aliases) {
this.marriage = marriage;
this.aliases = aliases;
}
@ -66,15 +69,39 @@ public abstract class Command {
}
}
/**
* Reply to the command sender with a specified formatted message.
*
* @param message Message to send.
* @param args Formatting arguments
*/
protected void reply(Message message, Object... args) {
reply(message.toString(), args);
}
/**
* Reply to the command sender with a formatted message.
*
* @param message Message to send.
* @param args Formatting arguments
* @deprecated Use the {@link Command#reply(Message, Object...) reply} method
*/
@Deprecated
protected void reply(String message, Object... args) {
message = ChatColor.translateAlternateColorCodes('&', String.format(message, args));
sender.sendMessage(message);
}
protected void broadcast(Message message, Object... args) {
broadcast(message.toString(), args);
}
@Deprecated
protected void broadcast(String message, Object... args) {
message = ChatColor.translateAlternateColorCodes('&', String.format(message, args));
sender.sendMessage(message);
}
public String getPermission() {
return permission;
}

View file

@ -1,13 +1,16 @@
package com.lenis0012.bukkit.marriage2.commands;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.lenis0012.bukkit.marriage2.MPlayer;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.lang.Message;
public class CommandMarry extends Command {
public CommandMarry(){
super("marry");
public CommandMarry(Marriage marriage) {
super(marriage, "marry");
setDescription("Request a marriage with another player.");
setUsage("<player>");
@ -19,11 +22,22 @@ public class CommandMarry extends Command {
public void execute() {
Player target = getArgAsPlayer(-1);
if(target != null) {
if(System.out != null) { //TODO: Check if married
//TODO: Handle command delay
//TODO: Send marry request
MPlayer mPlayer = marriage.getMPlayer(player.getUniqueId());
if(!mPlayer.isMarried()) {
MPlayer mTarget = marriage.getMPlayer(target.getUniqueId());
if(!mTarget.isMarried()) {
if(mPlayer.isMarriageRequested(target.getUniqueId())) {
marriage.marry(mPlayer, mTarget);
broadcast(Message.MARRIED, player.getName(), target.getName());
} else {
mTarget.requestMarriage(player.getUniqueId());
target.sendMessage(ChatColor.translateAlternateColorCodes('&', String.format(Message.MARRIAGE_REQUESTED.toString(), player.getName(), player.getName())));
}
} else {
reply(Message.TARGET_ALREADY_MARRIED, getArg(-1));
}
} else {
reply(Message.ALREADY_MARRIED, getArg(-1));
reply(Message.ALREADY_MARRIED);
}
} else {
reply(Message.PLAYER_NOT_FOUND, getArg(-1));

View file

@ -1,15 +0,0 @@
package com.lenis0012.bukkit.marriage2.commands;
public class CommandTest extends Command {
public CommandTest() {
super("test");
setDescription("A test command");
setPermission("marry.command.test");
}
@Override
public void execute() {
reply("&aThis is a test command :D");
}
}

View file

@ -10,6 +10,7 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.commands.Command;
public class MarriageCommandExecutor implements CommandExecutor {
@ -49,7 +50,7 @@ public class MarriageCommandExecutor implements CommandExecutor {
public void regster(Class<? extends Command> commandClass) {
try {
Command command = commandClass.newInstance();
Command command = commandClass.getConstructor(Marriage.class).newInstance(core);
for(String alias : command.getAliases()) {
commands.put(alias.toLowerCase(), command);
}

View file

@ -3,7 +3,7 @@ package com.lenis0012.bukkit.marriage2.internal;
import java.util.UUID;
import com.lenis0012.bukkit.marriage2.MPlayer;
import com.lenis0012.bukkit.marriage2.commands.CommandTest;
import com.lenis0012.bukkit.marriage2.commands.CommandMarry;
import com.lenis0012.bukkit.marriage2.lang.Message;
public class MarriageCore extends MarriageBase {
@ -14,7 +14,7 @@ public class MarriageCore extends MarriageBase {
@Register(name = "commands", type = Register.Type.ENABLE)
public void registerCommands() {
register(CommandTest.class);
register(CommandMarry.class);
}
@Register(name = "messages", type = Register.Type.ENABLE, priority = 1)
@ -24,7 +24,12 @@ public class MarriageCore extends MarriageBase {
@Override
public MPlayer getMPlayer(UUID uuid) {
//TODO: Everything...
// TODO: Everything...
return null;
}
@Override
public void marry(MPlayer player1, MPlayer player2) {
// TODO: Marry player1 with player2
}
}

View file

@ -5,7 +5,10 @@ import com.lenis0012.bukkit.marriage2.misc.BConfig;
public enum Message {
PLAYER_NOT_FOUND("&cNo player named %s was found!"),
ALREADY_MARRIED("&cPlayers %s is already married to someone!");
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.");
private final String defaultMessage;
private String message;