Skip to content

Commit

Permalink
Cleaned up code y agregué /back, lo programé como me salió del orto
Browse files Browse the repository at this point in the history
Así que me chupa la pija haber instanciado y accesado un HM desde un comando
  • Loading branch information
Elb1to committed Jan 11, 2021
1 parent 894e1c6 commit 6f5e09b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 23 deletions.
6 changes: 1 addition & 5 deletions 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.0-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>LunarClientUtils</name>
Expand All @@ -23,10 +23,6 @@
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>lunarclient-public</id>
<url>https://maven.moonsworth.com/repository/lunarclient-public/</url>
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/club/frozed/lunarutils/LunarClientUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package club.frozed.lunarutils;

import club.frozed.lunarutils.commands.BackCommand;
import club.frozed.lunarutils.commands.LunarClientCommand;
import club.frozed.lunarutils.player.PlayerListener;
import club.frozed.lunarutils.utils.command.CommandFramework;
Expand All @@ -8,15 +9,9 @@
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

/**
* The type Lunar client utils.
*/
@Getter @Setter
public final class LunarClientUtils extends JavaPlugin {

/**
* The constant instance.
*/
@Getter public static LunarClientUtils instance;
private CommandFramework commandFramework;

Expand All @@ -25,6 +20,7 @@ public void onEnable() {
instance = this;

commandFramework = new CommandFramework(this);
commandFramework.registerCommands(new BackCommand());
commandFramework.registerCommands(new LunarClientCommand());

Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/club/frozed/lunarutils/commands/BackCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package club.frozed.lunarutils.commands;

import club.frozed.lunarutils.utils.CC;
import club.frozed.lunarutils.utils.command.BaseCommand;
import club.frozed.lunarutils.utils.command.Command;
import club.frozed.lunarutils.utils.command.CommandArgs;
import org.bukkit.Location;
import org.bukkit.entity.Player;

import java.util.HashMap;

/**
* Created by Elb1to
* Project: LunarClientUtils
* Date: 1/11/2021 @ 12:45 PM
*/
public class BackCommand extends BaseCommand {

public static HashMap<Player, 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."));
}
}
15 changes: 15 additions & 0 deletions src/main/java/club/frozed/lunarutils/player/PlayerListener.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package club.frozed.lunarutils.player;

import club.frozed.lunarutils.commands.BackCommand;
import club.frozed.lunarutils.utils.CC;
import com.lunarclient.bukkitapi.LunarClientAPI;
import com.lunarclient.bukkitapi.object.LCNotification;
import com.lunarclient.bukkitapi.object.TitleType;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;

import java.time.Duration;
import java.util.UUID;

/**
* Created by Elb1to
Expand Down Expand Up @@ -58,4 +64,13 @@ public void onPlayerJoin(PlayerJoinEvent event) {
}
}
}

@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
Player player = Bukkit.getPlayer(event.getEntity().getUniqueId());
if (event.getEntity() == player) {
BackCommand.playerLocation.put(player, player.getLocation());
}
player.sendMessage(CC.translate("&cYou died, your last death location has been saved! &7&oUse /back to go back to it."));
}
}
12 changes: 0 additions & 12 deletions src/main/java/club/frozed/lunarutils/utils/CC.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,10 @@
import java.util.ArrayList;
import java.util.List;

/**
* The type Cc.
*/
public class CC {

/**
* The constant MENU_BAR.
*/
public static final String MENU_BAR = ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH.toString() + "------------------------";
/**
* The constant CHAT_BAR.
*/
public static final String CHAT_BAR = ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH.toString() + "------------------------------------------------";
/**
* The constant SB_BAR.
*/
public static final String SB_BAR = ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH.toString() + "----------------------";

/**
Expand Down

0 comments on commit 6f5e09b

Please sign in to comment.