Skip to content

Commit

Permalink
Decided to store the Player UUID instead of the Player Object
Browse files Browse the repository at this point in the history
Since it's more reasonable and better to work with when handling data.
Also, the command can only be used one time per death.
  • Loading branch information
Elb1to committed Jan 11, 2021
1 parent 6f5e09b commit 01a70ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>club.frozed.lunarapi</groupId>
<artifactId>LunarClientUtils</artifactId>
<version>1.1-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>LunarClientUtils</name>
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/club/frozed/lunarutils/commands/BackCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.entity.Player;

import java.util.HashMap;
import java.util.UUID;

/**
* Created by Elb1to
Expand All @@ -16,15 +17,21 @@
*/
public class BackCommand extends BaseCommand {

public static HashMap<Player, Location> playerLocation = new HashMap<>();
public static HashMap<UUID, Location> playerLocation = new HashMap<>();

@Command(name = "back", aliases = {"backpos", "goback"})

@Override
public void onCommand(CommandArgs cmd) {
Player player = cmd.getPlayer();

player.teleport(playerLocation.get(player));
player.sendMessage(CC.translate("&aSending you back to your previous death location."));
if (playerLocation.containsKey(player.getUniqueId())) {
player.teleport(playerLocation.get(player.getUniqueId()));
player.sendMessage(CC.translate("&aSending you back to your previous death location."));
} else {
player.sendMessage(CC.translate("&cYou have already used the /back command."));
}

playerLocation.remove(player.getUniqueId());
}
}
15 changes: 8 additions & 7 deletions src/main/java/club/frozed/lunarutils/player/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public class PlayerListener implements Listener {

private final LunarClientAPI lunarClientAPI = LunarClientAPI.getInstance();

/**
* On player join.
*
* @param event the event
*/
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
Expand Down Expand Up @@ -69,8 +64,14 @@ public void onPlayerJoin(PlayerJoinEvent event) {
public void onPlayerDeath(PlayerDeathEvent event) {
Player player = Bukkit.getPlayer(event.getEntity().getUniqueId());
if (event.getEntity() == player) {
BackCommand.playerLocation.put(player, player.getLocation());
BackCommand.playerLocation.put(player.getUniqueId(), player.getLocation());
}
player.sendMessage(CC.translate("&cYou died, your last death location has been saved! &7&oUse /back to go back to it."));

player.sendMessage(CC.CHAT_BAR);
player.sendMessage(CC.translate("&4&lTe moriste pete XdxdxDXDXdXDxDXd."));
player.sendMessage(CC.translate(" "));
player.sendMessage(CC.translate("&cYou can only use the &o/back &ccommand &lONCE."));
player.sendMessage(CC.translate("&cThis will teleport you back to your death location."));
player.sendMessage(CC.CHAT_BAR);
}
}

0 comments on commit 01a70ee

Please sign in to comment.