mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-01 08:09:39 +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.CommandExecutor;
|
||||
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.util.Permissions;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
@ -18,17 +17,16 @@ public class PtpAcceptAnyCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
PartyTeleportRecord ptpRecord = UserManager.getPlayer(sender.getName()).getPartyTeleportRecord();
|
||||
|
||||
if (mcMMOPlayer.getPtpConfirmRequired()) {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
|
||||
if (ptpRecord.isConfirmRequired()) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Enabled"));
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Enabled"));
|
||||
}
|
||||
|
||||
mcMMOPlayer.togglePtpConfirmRequired();
|
||||
ptpRecord.toggleConfirmRequired();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
@ -22,21 +22,21 @@ public class PtpAcceptCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
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"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((mcMMOPlayer.getPtpTimeout() + Config.getInstance().getPTPCommandTimeout()) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) {
|
||||
mcMMOPlayer.removePtpRequest();
|
||||
if ((ptpRecord.getTimeout() + Config.getInstance().getPTPCommandTimeout()) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) {
|
||||
ptpRecord.removeRequest();
|
||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.RequestExpired"));
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = mcMMOPlayer.getPtpRequest();
|
||||
mcMMOPlayer.removePtpRequest();
|
||||
Player target = ptpRecord.getRequestor();
|
||||
ptpRecord.removeRequest();
|
||||
|
||||
if (!PtpCommand.canTeleport(sender, player, target.getName())) {
|
||||
return true;
|
||||
|
@ -13,6 +13,7 @@ import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
@ -77,7 +78,7 @@ public class PtpCommand implements TabExecutor {
|
||||
}
|
||||
|
||||
int ptpCooldown = Config.getInstance().getPTPCommandCooldown();
|
||||
long ptpLastUse = mcMMOPlayer.getPtpLastUse();
|
||||
long ptpLastUse = mcMMOPlayer.getPartyTeleportRecord().getLastUse();
|
||||
|
||||
if (ptpCooldown > 0) {
|
||||
int timeRemaining = SkillUtils.calculateTimeLeft(ptpLastUse * Misc.TIME_CONVERSION_FACTOR, ptpCooldown, player);
|
||||
@ -118,13 +119,15 @@ public class PtpCommand implements TabExecutor {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mcMMOTarget.getPtpConfirmRequired()) {
|
||||
PartyTeleportRecord ptpRecord = mcMMOTarget.getPartyTeleportRecord();
|
||||
|
||||
if (!ptpRecord.isConfirmRequired()) {
|
||||
handleTeleportWarmup(player, target);
|
||||
return;
|
||||
}
|
||||
|
||||
mcMMOTarget.setPtpRequest(player);
|
||||
mcMMOTarget.actualizePtpTimeout();
|
||||
ptpRecord.setRequestor(player);
|
||||
ptpRecord.actualizeTimeout();
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
|
||||
|
||||
@ -151,7 +154,7 @@ public class PtpCommand implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mcMMOTarget.getPtpEnabled()) {
|
||||
if (!mcMMOTarget.getPartyTeleportRecord().isEnabled()) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", targetName));
|
||||
return false;
|
||||
}
|
||||
|
@ -3,9 +3,8 @@ package com.gmail.nossr50.commands.party.teleport;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
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.util.Permissions;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
@ -18,17 +17,16 @@ public class PtpToggleCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
PartyTeleportRecord ptpRecord = UserManager.getPlayer(sender.getName()).getPartyTeleportRecord();
|
||||
|
||||
if (mcMMOPlayer.getPtpEnabled()) {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
|
||||
if (ptpRecord.isEnabled()) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.Enabled"));
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.ptp.Enabled"));
|
||||
}
|
||||
|
||||
mcMMOPlayer.togglePtpUse();
|
||||
ptpRecord.toggleEnabled();
|
||||
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.datatypes.mods.CustomTool;
|
||||
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.SkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.ToolType;
|
||||
@ -69,11 +70,7 @@ public class McMMOPlayer {
|
||||
private Party invite;
|
||||
private int itemShareModifier;
|
||||
|
||||
private Player ptpRequest;
|
||||
private boolean ptpEnabled = true;
|
||||
private boolean ptpConfirmRequired = Config.getInstance().getPTPCommandConfirmRequired();
|
||||
private long ptpTimeout;
|
||||
private int ptpLastUse;
|
||||
private PartyTeleportRecord ptpRecord;
|
||||
|
||||
private boolean partyChatMode;
|
||||
private boolean adminChatMode;
|
||||
@ -109,6 +106,7 @@ public class McMMOPlayer {
|
||||
this.player = player;
|
||||
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, true);
|
||||
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),
|
||||
@ -708,53 +706,57 @@ public class McMMOPlayer {
|
||||
invite = null;
|
||||
}
|
||||
|
||||
public boolean getPtpEnabled() {
|
||||
return ptpEnabled;
|
||||
public PartyTeleportRecord getPartyTeleportRecord() {
|
||||
return ptpRecord;
|
||||
}
|
||||
|
||||
public void togglePtpUse() {
|
||||
ptpEnabled = !ptpEnabled;
|
||||
}
|
||||
|
||||
public Player getPtpRequest() {
|
||||
return ptpRequest;
|
||||
}
|
||||
|
||||
public void setPtpRequest(Player ptpRequest) {
|
||||
this.ptpRequest = ptpRequest;
|
||||
}
|
||||
|
||||
public boolean hasPtpRequest() {
|
||||
return (ptpRequest != null);
|
||||
}
|
||||
|
||||
public void removePtpRequest() {
|
||||
ptpRequest = null;
|
||||
}
|
||||
|
||||
public boolean getPtpConfirmRequired() {
|
||||
return ptpConfirmRequired;
|
||||
}
|
||||
|
||||
public void togglePtpConfirmRequired() {
|
||||
ptpConfirmRequired = !ptpConfirmRequired;
|
||||
}
|
||||
|
||||
public int getPtpLastUse() {
|
||||
return ptpLastUse;
|
||||
}
|
||||
|
||||
public void actualizePtpLastUse() {
|
||||
ptpLastUse = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||
}
|
||||
|
||||
public long getPtpTimeout() {
|
||||
return ptpTimeout;
|
||||
}
|
||||
|
||||
public void actualizePtpTimeout() {
|
||||
ptpTimeout = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||
}
|
||||
// public boolean getPtpEnabled() {
|
||||
// return ptpEnabled;
|
||||
// }
|
||||
//
|
||||
// public void togglePtpUse() {
|
||||
// ptpEnabled = !ptpEnabled;
|
||||
// }
|
||||
//
|
||||
// public Player getPtpRequest() {
|
||||
// return ptpRequest;
|
||||
// }
|
||||
//
|
||||
// public void setPtpRequest(Player ptpRequest) {
|
||||
// this.ptpRequest = ptpRequest;
|
||||
// }
|
||||
//
|
||||
// public boolean hasPtpRequest() {
|
||||
// return (ptpRequest != null);
|
||||
// }
|
||||
//
|
||||
// public void removePtpRequest() {
|
||||
// ptpRequest = null;
|
||||
// }
|
||||
//
|
||||
// public boolean getPtpConfirmRequired() {
|
||||
// return ptpConfirmRequired;
|
||||
// }
|
||||
//
|
||||
// public void togglePtpConfirmRequired() {
|
||||
// ptpConfirmRequired = !ptpConfirmRequired;
|
||||
// }
|
||||
//
|
||||
// public int getPtpLastUse() {
|
||||
// return ptpLastUse;
|
||||
// }
|
||||
//
|
||||
// public void actualizePtpLastUse() {
|
||||
// ptpLastUse = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||
// }
|
||||
//
|
||||
// public long getPtpTimeout() {
|
||||
// return ptpTimeout;
|
||||
// }
|
||||
//
|
||||
// public void actualizePtpTimeout() {
|
||||
// ptpTimeout = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||
// }
|
||||
|
||||
public int getItemShareModifier() {
|
||||
if (itemShareModifier < 10) {
|
||||
|
@ -105,7 +105,7 @@ public class EventUtils {
|
||||
teleportingPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Player", targetPlayer.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) {
|
||||
|
Loading…
Reference in New Issue
Block a user