diff --git a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpAcceptAnyCommand.java b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpAcceptAnyCommand.java index 8ef1ded52..089c2db72 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpAcceptAnyCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpAcceptAnyCommand.java @@ -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; } } diff --git a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpAcceptCommand.java b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpAcceptCommand.java index cdcd87b92..7c5c6d72a 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpAcceptCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpAcceptCommand.java @@ -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; diff --git a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java index b2dc25627..f713be6f4 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java @@ -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; } diff --git a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpToggleCommand.java b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpToggleCommand.java index 6e8d48083..b404e1fc1 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpToggleCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpToggleCommand.java @@ -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; } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/party/PartyTeleportRecord.java b/src/main/java/com/gmail/nossr50/datatypes/party/PartyTeleportRecord.java new file mode 100644 index 000000000..c0f327666 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/datatypes/party/PartyTeleportRecord.java @@ -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); + } +} diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index fd170b40b..3382cebdb 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -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) { diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index 0bca6c15c..b6ab69d62 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -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) {