mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 15:16:45 +01:00
Create wrapper to handle all PTP data.
This commit is contained in:
parent
f64f62492f
commit
60d69e3cc4
@ -3,9 +3,8 @@ package com.gmail.nossr50.commands.party.teleport;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
@ -18,17 +17,16 @@ public class PtpAcceptAnyCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
PartyTeleportRecord ptpRecord = UserManager.getPlayer(sender.getName()).getPartyTeleportRecord();
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
||||||
|
|
||||||
if (mcMMOPlayer.getPtpConfirmRequired()) {
|
if (ptpRecord.isConfirmRequired()) {
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
|
sender.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Enabled"));
|
sender.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Enabled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer.togglePtpConfirmRequired();
|
ptpRecord.toggleConfirmRequired();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
@ -22,21 +22,21 @@ public class PtpAcceptCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
PartyTeleportRecord ptpRecord = UserManager.getPlayer(player).getPartyTeleportRecord();
|
||||||
|
|
||||||
if (!mcMMOPlayer.hasPtpRequest()) {
|
if (!ptpRecord.hasRequest()) {
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.NoRequests"));
|
player.sendMessage(LocaleLoader.getString("Commands.ptp.NoRequests"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mcMMOPlayer.getPtpTimeout() + Config.getInstance().getPTPCommandTimeout()) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) {
|
if ((ptpRecord.getTimeout() + Config.getInstance().getPTPCommandTimeout()) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) {
|
||||||
mcMMOPlayer.removePtpRequest();
|
ptpRecord.removeRequest();
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.RequestExpired"));
|
player.sendMessage(LocaleLoader.getString("Commands.ptp.RequestExpired"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player target = mcMMOPlayer.getPtpRequest();
|
Player target = ptpRecord.getRequestor();
|
||||||
mcMMOPlayer.removePtpRequest();
|
ptpRecord.removeRequest();
|
||||||
|
|
||||||
if (!PtpCommand.canTeleport(sender, player, target.getName())) {
|
if (!PtpCommand.canTeleport(sender, player, target.getName())) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -13,6 +13,7 @@ import org.bukkit.util.StringUtil;
|
|||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
|
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.party.PartyManager;
|
import com.gmail.nossr50.party.PartyManager;
|
||||||
@ -77,7 +78,7 @@ public class PtpCommand implements TabExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ptpCooldown = Config.getInstance().getPTPCommandCooldown();
|
int ptpCooldown = Config.getInstance().getPTPCommandCooldown();
|
||||||
long ptpLastUse = mcMMOPlayer.getPtpLastUse();
|
long ptpLastUse = mcMMOPlayer.getPartyTeleportRecord().getLastUse();
|
||||||
|
|
||||||
if (ptpCooldown > 0) {
|
if (ptpCooldown > 0) {
|
||||||
int timeRemaining = SkillUtils.calculateTimeLeft(ptpLastUse * Misc.TIME_CONVERSION_FACTOR, ptpCooldown, player);
|
int timeRemaining = SkillUtils.calculateTimeLeft(ptpLastUse * Misc.TIME_CONVERSION_FACTOR, ptpCooldown, player);
|
||||||
@ -118,13 +119,15 @@ public class PtpCommand implements TabExecutor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mcMMOTarget.getPtpConfirmRequired()) {
|
PartyTeleportRecord ptpRecord = mcMMOTarget.getPartyTeleportRecord();
|
||||||
|
|
||||||
|
if (!ptpRecord.isConfirmRequired()) {
|
||||||
handleTeleportWarmup(player, target);
|
handleTeleportWarmup(player, target);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOTarget.setPtpRequest(player);
|
ptpRecord.setRequestor(player);
|
||||||
mcMMOTarget.actualizePtpTimeout();
|
ptpRecord.actualizeTimeout();
|
||||||
|
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
|
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
|
||||||
|
|
||||||
@ -151,7 +154,7 @@ public class PtpCommand implements TabExecutor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mcMMOTarget.getPtpEnabled()) {
|
if (!mcMMOTarget.getPartyTeleportRecord().isEnabled()) {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", targetName));
|
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", targetName));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,8 @@ package com.gmail.nossr50.commands.party.teleport;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
@ -18,17 +17,16 @@ public class PtpToggleCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
PartyTeleportRecord ptpRecord = UserManager.getPlayer(sender.getName()).getPartyTeleportRecord();
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
||||||
|
|
||||||
if (mcMMOPlayer.getPtpEnabled()) {
|
if (ptpRecord.isEnabled()) {
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
|
sender.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.Enabled"));
|
sender.sendMessage(LocaleLoader.getString("Commands.ptp.Enabled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer.togglePtpUse();
|
ptpRecord.toggleEnabled();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
package com.gmail.nossr50.datatypes.party;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.config.Config;
|
||||||
|
import com.gmail.nossr50.util.Misc;
|
||||||
|
|
||||||
|
public class PartyTeleportRecord {
|
||||||
|
private Player requestor;
|
||||||
|
private boolean enabled, confirmRequired;
|
||||||
|
private int timeout, lastUse;
|
||||||
|
|
||||||
|
public PartyTeleportRecord() {
|
||||||
|
requestor = null;
|
||||||
|
enabled = true;
|
||||||
|
confirmRequired = Config.getInstance().getPTPCommandConfirmRequired();
|
||||||
|
timeout = 0;
|
||||||
|
lastUse = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleEnabled() {
|
||||||
|
enabled = !enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getRequestor() {
|
||||||
|
return requestor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequestor(Player requestor) {
|
||||||
|
this.requestor = requestor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasRequest() {
|
||||||
|
return (requestor != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeRequest() {
|
||||||
|
requestor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConfirmRequired() {
|
||||||
|
return confirmRequired;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleConfirmRequired() {
|
||||||
|
confirmRequired = !confirmRequired;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastUse() {
|
||||||
|
return lastUse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actualizeLastUse() {
|
||||||
|
lastUse = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTimeout() {
|
||||||
|
return timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actualizeTimeout() {
|
||||||
|
timeout = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,7 @@ import com.gmail.nossr50.config.Config;
|
|||||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||||
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
||||||
import com.gmail.nossr50.datatypes.party.Party;
|
import com.gmail.nossr50.datatypes.party.Party;
|
||||||
|
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
|
||||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
import com.gmail.nossr50.datatypes.skills.ToolType;
|
import com.gmail.nossr50.datatypes.skills.ToolType;
|
||||||
@ -69,11 +70,7 @@ public class McMMOPlayer {
|
|||||||
private Party invite;
|
private Party invite;
|
||||||
private int itemShareModifier;
|
private int itemShareModifier;
|
||||||
|
|
||||||
private Player ptpRequest;
|
private PartyTeleportRecord ptpRecord;
|
||||||
private boolean ptpEnabled = true;
|
|
||||||
private boolean ptpConfirmRequired = Config.getInstance().getPTPCommandConfirmRequired();
|
|
||||||
private long ptpTimeout;
|
|
||||||
private int ptpLastUse;
|
|
||||||
|
|
||||||
private boolean partyChatMode;
|
private boolean partyChatMode;
|
||||||
private boolean adminChatMode;
|
private boolean adminChatMode;
|
||||||
@ -109,6 +106,7 @@ public class McMMOPlayer {
|
|||||||
this.player = player;
|
this.player = player;
|
||||||
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, true);
|
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, true);
|
||||||
party = PartyManager.getPlayerParty(playerName);
|
party = PartyManager.getPlayerParty(playerName);
|
||||||
|
ptpRecord = new PartyTeleportRecord();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* I'm using this method because it makes code shorter and safer (we don't have to add all SkillTypes manually),
|
* I'm using this method because it makes code shorter and safer (we don't have to add all SkillTypes manually),
|
||||||
@ -708,53 +706,57 @@ public class McMMOPlayer {
|
|||||||
invite = null;
|
invite = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getPtpEnabled() {
|
public PartyTeleportRecord getPartyTeleportRecord() {
|
||||||
return ptpEnabled;
|
return ptpRecord;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void togglePtpUse() {
|
// public boolean getPtpEnabled() {
|
||||||
ptpEnabled = !ptpEnabled;
|
// return ptpEnabled;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public Player getPtpRequest() {
|
// public void togglePtpUse() {
|
||||||
return ptpRequest;
|
// ptpEnabled = !ptpEnabled;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setPtpRequest(Player ptpRequest) {
|
// public Player getPtpRequest() {
|
||||||
this.ptpRequest = ptpRequest;
|
// return ptpRequest;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public boolean hasPtpRequest() {
|
// public void setPtpRequest(Player ptpRequest) {
|
||||||
return (ptpRequest != null);
|
// this.ptpRequest = ptpRequest;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void removePtpRequest() {
|
// public boolean hasPtpRequest() {
|
||||||
ptpRequest = null;
|
// return (ptpRequest != null);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public boolean getPtpConfirmRequired() {
|
// public void removePtpRequest() {
|
||||||
return ptpConfirmRequired;
|
// ptpRequest = null;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void togglePtpConfirmRequired() {
|
// public boolean getPtpConfirmRequired() {
|
||||||
ptpConfirmRequired = !ptpConfirmRequired;
|
// return ptpConfirmRequired;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public int getPtpLastUse() {
|
// public void togglePtpConfirmRequired() {
|
||||||
return ptpLastUse;
|
// ptpConfirmRequired = !ptpConfirmRequired;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void actualizePtpLastUse() {
|
// public int getPtpLastUse() {
|
||||||
ptpLastUse = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
// return ptpLastUse;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public long getPtpTimeout() {
|
// public void actualizePtpLastUse() {
|
||||||
return ptpTimeout;
|
// ptpLastUse = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void actualizePtpTimeout() {
|
// public long getPtpTimeout() {
|
||||||
ptpTimeout = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
// return ptpTimeout;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// public void actualizePtpTimeout() {
|
||||||
|
// ptpTimeout = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||||
|
// }
|
||||||
|
|
||||||
public int getItemShareModifier() {
|
public int getItemShareModifier() {
|
||||||
if (itemShareModifier < 10) {
|
if (itemShareModifier < 10) {
|
||||||
|
@ -105,7 +105,7 @@ public class EventUtils {
|
|||||||
teleportingPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Player", targetPlayer.getName()));
|
teleportingPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Player", targetPlayer.getName()));
|
||||||
targetPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Target", teleportingPlayer.getName()));
|
targetPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Target", teleportingPlayer.getName()));
|
||||||
|
|
||||||
mcMMOPlayer.actualizePtpLastUse();
|
mcMMOPlayer.getPartyTeleportRecord().actualizeLastUse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean handleXpGainEvent(Player player, SkillType skill, float xpGained) {
|
public static boolean handleXpGainEvent(Player player, SkillType skill, float xpGained) {
|
||||||
|
Loading…
Reference in New Issue
Block a user