mirror of
https://github.com/TotalFreedomMC/TF-Marriage.git
synced 2024-12-27 02:24:39 +00:00
Add plotsquared & heal
This commit is contained in:
parent
d3b25411b1
commit
b753f4cb51
14 changed files with 338 additions and 17 deletions
BIN
lib/PlotSquared.jar
Normal file
BIN
lib/PlotSquared.jar
Normal file
Binary file not shown.
BIN
lib/spigot.jar
BIN
lib/spigot.jar
Binary file not shown.
16
pom.xml
16
pom.xml
|
@ -4,7 +4,7 @@
|
|||
|
||||
<groupId>com.lenis0012.bukkit</groupId>
|
||||
<artifactId>marriage2</artifactId>
|
||||
<version>2.0.11</version>
|
||||
<version>2.0.12-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Marriage</name>
|
||||
<url>http://dev.bukkit.org/server-mods/marriage-reloaded/</url>
|
||||
|
@ -42,13 +42,13 @@
|
|||
<version>1.9-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.spigotmc</groupId>-->
|
||||
<!--<artifactId>spigot</artifactId>-->
|
||||
<!--<version>1.9-R0.1-SNAPSHOT</version>-->
|
||||
<!--<scope>system</scope>-->
|
||||
<!--<systemPath>${project.basedir}/lib/spigot.jar</systemPath>-->
|
||||
<!--</dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.plotsquared.bukkit</groupId>
|
||||
<artifactId>PlotSquared</artifactId>
|
||||
<version>3.3.3</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/PlotSquared.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lenis0012.bukkit</groupId>
|
||||
<artifactId>lenisutils</artifactId>
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.lenis0012.bukkit.marriage2.commands.Command;
|
|||
import com.lenis0012.bukkit.marriage2.internal.Dependencies;
|
||||
import com.lenis0012.bukkit.marriage2.misc.BConfig;
|
||||
import com.lenis0012.bukkit.marriage2.misc.ListQuery;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
@ -38,13 +39,23 @@ public interface Marriage {
|
|||
ListQuery getMarriageList(int scale, int page);
|
||||
|
||||
/**
|
||||
* Marry 2 players with eachother.
|
||||
* Marry 2 players with each other.
|
||||
*
|
||||
* @param player1 Player 1
|
||||
* @param player2 Player 2
|
||||
* @return The marriage data
|
||||
* @return The marriage data, null if cancelled via {@link com.lenis0012.bukkit.marriage2.events.PlayerMarryEvent PlayerMarryEvent}
|
||||
*/
|
||||
MData marry(MPlayer player1, MPlayer player2);
|
||||
|
||||
/**
|
||||
* Marry 2 players with each other.
|
||||
*
|
||||
* @param player1 Player 1
|
||||
* @param player2 Player 2
|
||||
* @param priest Priest that married the players
|
||||
* @return Marriage data, null if cancelled via {@link com.lenis0012.bukkit.marriage2.events.PlayerMarryEvent PlayerMarryEvent}
|
||||
*/
|
||||
MData marry(MPlayer player1, MPlayer player2, MPlayer priest);
|
||||
|
||||
/**
|
||||
* Register a {@link org.bukkit.event.Listener} to this plugin.
|
||||
|
|
|
@ -6,6 +6,13 @@ import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
|
|||
* Marriage API.
|
||||
*
|
||||
* <b>Changelog:</b>
|
||||
* 1.02:
|
||||
* <ul>
|
||||
* <li>Added {@link com.lenis0012.bukkit.marriage2.events.PlayerMarryEvent PlayerMarryEvent}</li>
|
||||
* <li>Added {@link com.lenis0012.bukkit.marriage2.events.PlayerDivorceEvent PlayerDivorceEvent}</li>
|
||||
* <li>Added {@link Marriage#marry(MPlayer, MPlayer, MPlayer) marry(p1, p2, priest)}</li>
|
||||
* </ul>
|
||||
*
|
||||
* 1.01:
|
||||
* <ul>
|
||||
* <li>Added chat spy mode</li>
|
||||
|
@ -17,7 +24,7 @@ import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
|
|||
* </ul>
|
||||
*/
|
||||
public class MarriageAPI {
|
||||
private static final int API_VERSION = 101;
|
||||
private static final int API_VERSION = 102;
|
||||
|
||||
/**
|
||||
* Get the API main instance.
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package com.lenis0012.bukkit.marriage2.commands;
|
||||
|
||||
import com.lenis0012.bukkit.marriage2.MData;
|
||||
import com.lenis0012.bukkit.marriage2.MPlayer;
|
||||
import com.lenis0012.bukkit.marriage2.Marriage;
|
||||
import com.lenis0012.bukkit.marriage2.config.Message;
|
||||
import com.lenis0012.bukkit.marriage2.config.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandHeal extends Command {
|
||||
public CommandHeal(Marriage marriage) {
|
||||
super(marriage, "heal");
|
||||
setExecutionFee(Settings.PRICE_HEAL);
|
||||
setDescription(Message.COMMAND_HEAL.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
MPlayer mPlayer = marriage.getMPlayer(player.getUniqueId());
|
||||
MData marriage = mPlayer.getMarriage();
|
||||
|
||||
// Check if marries
|
||||
if(marriage == null) {
|
||||
reply(Message.NOT_MARRIED);
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify partner online
|
||||
Player partner = Bukkit.getPlayer(marriage.getOtherPlayer(player.getUniqueId()));
|
||||
if(partner == null) {
|
||||
reply(Message.PARTNER_NOT_ONLINE);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check health
|
||||
if(player.getHealth() < 1.0) {
|
||||
reply(Message.NO_HEALTH);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check health of partner
|
||||
double give = Math.min(partner.getMaxHealth() - partner.getHealth(), player.getHealth() - 0.5);
|
||||
if(give == 0.0) {
|
||||
reply(Message.NO_HEALTH);
|
||||
return;
|
||||
}
|
||||
|
||||
// Transfer health
|
||||
player.setHealth(player.getHealth() - give);
|
||||
partner.setHealth(partner.getHealth() + give);
|
||||
|
||||
// Notify both parties
|
||||
int hearts = (int) Math.round(give / 0.5);
|
||||
reply(Message.HEALTH_GIVEN, hearts);
|
||||
reply(partner, Message.HEALTH_TAKEN, hearts);
|
||||
}
|
||||
}
|
|
@ -44,6 +44,10 @@ public enum Message {
|
|||
CHAT_DISABLED("&aYou are no longer in marriage chat mode!"),
|
||||
CHAT_SPY_ENABLED("&aNow spying on marriage private chat!"),
|
||||
CHAT_SPY_DISABLED("&aNo longer spying on marriage chat!"),
|
||||
NO_HEALTH("&cYou don't have enough health to share!"),
|
||||
FULL_HEALTH("&cYour partner already has full health!"),
|
||||
HEALTH_GIVEN("&aYou healed your partner by %s hearts!"),
|
||||
HEALTH_TAKEN("&aYou were healed by your partner with %s hearts!"),
|
||||
|
||||
// COMMANDS
|
||||
COMMAND_MARRY("Request a marriage with another player"),
|
||||
|
@ -57,6 +61,7 @@ public enum Message {
|
|||
COMMAND_SEEN("Check when your partner last logged in"),
|
||||
COMMAND_SETHOME("Set a home for you a your partner"),
|
||||
COMMAND_TELEPORT("Teleport to your partner"),
|
||||
COMMAND_HEAL("Send your health to your partner"),
|
||||
|
||||
// WORDS
|
||||
STATUS("&aStatus: %s"),
|
||||
|
|
|
@ -53,6 +53,9 @@ public class Settings {
|
|||
public static final ConfigOption<Integer> KISSES_AMOUNT_MIN = new ConfigOption<>("kisses.amount-min", 5);
|
||||
public static final ConfigOption<Integer> KISSES_AMOUNT_MAX = new ConfigOption<>("kisses.amount-max", 10);
|
||||
|
||||
@ConfigHeader("Automatically trust married players to each others plot.")
|
||||
public static final ConfigOption<Boolean> PLOTSQUARED_AUTO_TRUST = new ConfigOption<>("support.plotsquared-auto-trust", true);
|
||||
|
||||
/**
|
||||
* Economy
|
||||
*/
|
||||
|
@ -62,6 +65,7 @@ public class Settings {
|
|||
public static final ConfigOption<Double> PRICE_MARRY = new ConfigOption<>("economy.marriage-price", 100.0);
|
||||
public static final ConfigOption<Double> PRICE_TELEPORT = new ConfigOption<>("economy.teleport-price", 0.0);
|
||||
public static final ConfigOption<Double> PRICE_SETHOME = new ConfigOption<>("economy.sethome-price", 0.0);
|
||||
public static final ConfigOption<Double> PRICE_HEAL = new ConfigOption<>("economy.heal-price", 0.0);
|
||||
public static final ConfigOption<Double> PRICE_DIVORCE = new ConfigOption<>("economy.divorce-price", 0.0);
|
||||
|
||||
/**
|
||||
|
@ -79,5 +83,5 @@ public class Settings {
|
|||
* Lists
|
||||
*/
|
||||
@ConfigHeader("List of commands that no one can use, for instance 'gift'.")
|
||||
public static final ConfigOption<List<String>> DISABLED_COMMANDS = new ConfigOption<>("disabled-commands", Arrays.asList("commandhere", "anothercommand"));
|
||||
public static final ConfigOption<List<String>> DISABLED_COMMANDS = new ConfigOption<>("disabled-commands", Arrays.asList("command1", "command2"));
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.lenis0012.bukkit.marriage2.events;
|
||||
|
||||
import com.lenis0012.bukkit.marriage2.MData;
|
||||
import com.lenis0012.bukkit.marriage2.MPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Player divorce event.
|
||||
*
|
||||
* Called when two players are about to divorce.
|
||||
*/
|
||||
public class PlayerDivorceEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlerList = new HandlerList();
|
||||
|
||||
private MPlayer player;
|
||||
private MData marriage;
|
||||
|
||||
public PlayerDivorceEvent(MPlayer player, MData marriage) {
|
||||
super(false);
|
||||
this.player = player;
|
||||
this.marriage = marriage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player that initiated the divorce.
|
||||
*
|
||||
* @return Divorcing player
|
||||
*/
|
||||
public MPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the marriage that is about to end.
|
||||
*
|
||||
* @return Marriage
|
||||
*/
|
||||
public MData getMarriage() {
|
||||
return marriage;
|
||||
}
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlerList;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package com.lenis0012.bukkit.marriage2.events;
|
||||
|
||||
import com.lenis0012.bukkit.marriage2.MPlayer;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* MPlayerMarryEvent.
|
||||
*
|
||||
* Called when two players are about to get married.
|
||||
*/
|
||||
public class PlayerMarryEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlerList = new HandlerList();
|
||||
|
||||
private MPlayer requesing;
|
||||
private MPlayer requested;
|
||||
private MPlayer priest;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public PlayerMarryEvent(MPlayer requesing, MPlayer requested, MPlayer priest) {
|
||||
super(false);
|
||||
this.requesing = requesing;
|
||||
this.requested = requested;
|
||||
this.priest = priest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player that requested to marry the other player.
|
||||
*
|
||||
* @return Requesting player
|
||||
*/
|
||||
public MPlayer getRequesing() {
|
||||
return requesing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player that was requested to be married.
|
||||
*
|
||||
* @return Requested player
|
||||
*/
|
||||
public MPlayer getRequested() {
|
||||
return requested;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get priest that created/initiated the marriage.
|
||||
* Note: null if {@link #isFromPriest() isFromPriest} false.
|
||||
*
|
||||
* @return True is performed by priest, false otherwise
|
||||
*/
|
||||
public MPlayer getPriest() {
|
||||
return priest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not this marriage was created by a priest.
|
||||
*
|
||||
* @return Created/initiated by a priest
|
||||
*/
|
||||
public boolean isFromPriest() {
|
||||
return priest != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlerList;
|
||||
}
|
||||
}
|
|
@ -6,11 +6,13 @@ import com.lenis0012.bukkit.marriage2.commands.Command;
|
|||
import com.lenis0012.bukkit.marriage2.config.Message;
|
||||
import com.lenis0012.bukkit.marriage2.config.Permissions;
|
||||
import com.lenis0012.bukkit.marriage2.config.Settings;
|
||||
import com.lenis0012.bukkit.marriage2.events.PlayerMarryEvent;
|
||||
import com.lenis0012.bukkit.marriage2.internal.Register.Type;
|
||||
import com.lenis0012.bukkit.marriage2.internal.data.DataConverter;
|
||||
import com.lenis0012.bukkit.marriage2.internal.data.DataManager;
|
||||
import com.lenis0012.bukkit.marriage2.internal.data.MarriageData;
|
||||
import com.lenis0012.bukkit.marriage2.internal.data.MarriagePlayer;
|
||||
import com.lenis0012.bukkit.marriage2.listeners.*;
|
||||
import com.lenis0012.bukkit.marriage2.misc.ListQuery;
|
||||
import com.lenis0012.pluginutils.modules.configuration.ConfigurationModule;
|
||||
import com.lenis0012.updater.api.ReleaseType;
|
||||
|
@ -19,6 +21,7 @@ import com.lenis0012.updater.api.UpdaterFactory;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -79,8 +82,14 @@ public class MarriageCore extends MarriageBase {
|
|||
|
||||
@Register(name = "listeners", type = Register.Type.ENABLE)
|
||||
public void registerListeners() {
|
||||
for(Listener listener : findObjects("com.lenis0012.bukkit.marriage2.listeners", Listener.class, this)) {
|
||||
register(listener);
|
||||
register(new ChatListener(this));
|
||||
register(new DatabaseListener(this));
|
||||
register(new KissListener(this));
|
||||
register(new UpdateListener(this));
|
||||
if(Settings.PLOTSQUARED_AUTO_TRUST.value() && Bukkit.getPluginManager().isPluginEnabled("PlotSquared")) {
|
||||
Plugin plotSquared = Bukkit.getPluginManager().getPlugin("PlotSquared");
|
||||
getLogger().log(Level.INFO, "Hooking with PlotSquared v" + plotSquared.getDescription().getVersion());
|
||||
register(new PlotSquaredListener());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,11 +134,21 @@ public class MarriageCore extends MarriageBase {
|
|||
|
||||
@Override
|
||||
public MData marry(MPlayer player1, MPlayer player2) {
|
||||
return marry(player1, player2, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MData marry(MPlayer player1, MPlayer player2, MPlayer priest) {
|
||||
PlayerMarryEvent event = new PlayerMarryEvent(player1, player2, priest);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MarriageData mdata = new MarriageData(dataManager, player1.getUniqueId(), player2.getUniqueId());
|
||||
mdata.saveAsync();
|
||||
mdata.saveAsync();
|
||||
((MarriagePlayer) player1).addMarriage(mdata);
|
||||
((MarriagePlayer) player2).addMarriage(mdata);
|
||||
dataManager.savePlayer((MarriagePlayer) player1);
|
||||
return mdata;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,11 @@ import com.lenis0012.bukkit.marriage2.MData;
|
|||
import com.lenis0012.bukkit.marriage2.MPlayer;
|
||||
import com.lenis0012.bukkit.marriage2.Marriage;
|
||||
import com.lenis0012.bukkit.marriage2.config.Settings;
|
||||
import com.lenis0012.bukkit.marriage2.events.PlayerDivorceEvent;
|
||||
import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
|
||||
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
|
||||
import com.lenis0012.bukkit.marriage2.misc.Cooldown;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
@ -121,6 +123,12 @@ public class MarriagePlayer implements MPlayer {
|
|||
return;
|
||||
}
|
||||
|
||||
PlayerDivorceEvent event = new PlayerDivorceEvent(this, marriage);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
((MarriageCore) MarriagePlugin.getCore()).removeMarriage(marriage);
|
||||
MarriagePlayer partner = (MarriagePlayer) getPartner();
|
||||
partner.marriage = null;
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package com.lenis0012.bukkit.marriage2.listeners;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.lenis0012.bukkit.marriage2.MData;
|
||||
import com.lenis0012.bukkit.marriage2.events.PlayerDivorceEvent;
|
||||
import com.lenis0012.bukkit.marriage2.events.PlayerMarryEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlotSquaredListener implements Listener {
|
||||
private final PS plotSquared;
|
||||
|
||||
public PlotSquaredListener() {
|
||||
this.plotSquared = PS.get();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerMarry(PlayerMarryEvent event) {
|
||||
final UUID player = event.getRequesing().getUniqueId();
|
||||
final UUID partner = event.getRequested().getUniqueId();
|
||||
|
||||
for(Plot plot : plotSquared.getPlots(player)) {
|
||||
if(plot.getTrusted().contains(partner)) {
|
||||
continue;
|
||||
}
|
||||
plot.addTrusted(partner);
|
||||
}
|
||||
|
||||
for(Plot plot : plotSquared.getPlots(partner)) {
|
||||
if(plot.getTrusted().contains(player)) {
|
||||
continue;
|
||||
}
|
||||
plot.addTrusted(player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerDivorce(PlayerDivorceEvent event) {
|
||||
final MData marriage = event.getMarriage();
|
||||
final UUID player = marriage.getPlayer1Id();
|
||||
final UUID partner = marriage.getPllayer2Id();
|
||||
|
||||
for(Plot plot : plotSquared.getPlots(player)) {
|
||||
if(!plot.getTrusted().contains(partner)) {
|
||||
continue;
|
||||
}
|
||||
plot.removeTrusted(partner);
|
||||
}
|
||||
|
||||
for(Plot plot : plotSquared.getPlots(partner)) {
|
||||
if(!plot.getTrusted().contains(player)) {
|
||||
continue;
|
||||
}
|
||||
plot.removeTrusted(player);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ main: com.lenis0012.bukkit.marriage2.internal.MarriagePlugin
|
|||
author: lenis0012
|
||||
description: A plugin wich provides the function to start a relationship in minecraft.
|
||||
dev-url: http://dev.bukkit.org/bukkit-mods/marriage-reloaded/
|
||||
softdepend: [Vault]
|
||||
softdepend: [Vault, PlotSquared]
|
||||
commands:
|
||||
marry:
|
||||
description: Marriage main command.
|
||||
|
|
Loading…
Reference in a new issue