Skip to content

Commit

Permalink
Commande /is home
Browse files Browse the repository at this point in the history
  • Loading branch information
Euphillya committed Jan 15, 2024
1 parent 1aae499 commit c66a7ab
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 29 deletions.
4 changes: 3 additions & 1 deletion .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/sonarlint/securityhotspotstore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public enum SubCommands {
CREATE(new CreateSubCommand()),
DELETE(new DeleteSubCommand()),
DEMOTE(new DemoteSubCommand()),
HOME(new HomeSubCommand()),
INVITE(new InviteSubCommand()),
KICK(new KickSubCommand()),
LEAVE(new LeaveSubCommand()),
PROMOTE(new PromoteSubCommand()),
TELEPORT(new TeleportSubCommand()),
TRANSFER(new TransferSubCommand()),
SETHOME(new SetHomeSubCommand()),
SETWARP(new SetWarpSubCommand());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N
PlayerNMS.setOwnWorldBorder(plugin, player, center, "", island.getSize(), 0, 0);
LanguageToml.sendMessage(plugin, player, LanguageToml.messageIslandCreateFinish);
} else {
TeleportSubCommand.tpHomeIsland(plugin, island, player);
new HomeSubCommand().onCommand(plugin, sender, command, label, args);
}
} catch (Exception e) {
logger.log(Level.FATAL, e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,11 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

public class TeleportSubCommand implements SubCommandInterface {
public class HomeSubCommand implements SubCommandInterface {

private final Logger logger = LogManager.getLogger(TeleportSubCommand.class);
private final Logger logger = LogManager.getLogger(HomeSubCommand.class);

public static void tpHomeIsland(Main plugin, Island island, Player player) {
if (island == null) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerHasNotIsland);
return;
}

WarpIsland warpIsland = island.getWarpByName("home");
Location centerIsland = RegionUtils.getCenterRegion(Bukkit.getWorld(IslandUtils.getSchematic(null).worldName()), island.getPosition().regionX(), island.getPosition().regionZ());
double rayon = island.getSize();
player.getScheduler().run(plugin, scheduledTask1 -> {
Location loc;
if (warpIsland == null) {
loc = centerIsland;
} else {
loc = warpIsland.location();
}
player.teleportAsync(loc);
PlayerNMS.setOwnWorldBorder(plugin, player, centerIsland, "", rayon, 0, 0);
player.setGameMode(GameMode.SURVIVAL);
}, null);
}

@Override
public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Expand All @@ -64,7 +44,25 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N
try {
SkyblockManager skyblockManager = plugin.getInterneAPI().getSkyblockManager();
Island island = skyblockManager.getIslandByOwner(player.getUniqueId()).join();
tpHomeIsland(plugin, island, player);
if (island == null) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerHasNotIsland);
return;
}

WarpIsland warpIsland = island.getWarpByName("home");
double rayon = island.getSize();
player.getScheduler().run(plugin, scheduledTask1 -> {
Location loc;
if (warpIsland == null) {
loc = RegionUtils.getCenterRegion(Bukkit.getWorld(IslandUtils.getWorldConfigs().get(0).name()), island.getPosition().regionX(), island.getPosition().regionZ());
} else {
loc = warpIsland.location();
}
player.teleportAsync(loc);
PlayerNMS.setOwnWorldBorder(plugin, player, RegionUtils.getCenterRegion(loc.getWorld(), island.getPosition().regionX(), island.getPosition().regionZ()), "", rayon, 0, 0);
player.setGameMode(GameMode.SURVIVAL);
LanguageToml.sendMessage(plugin, player, LanguageToml.messageHomeIslandSuccess);
}, null);
} catch (Exception exception) {
logger.log(Level.FATAL, exception.getMessage(), exception);
LanguageToml.sendMessage(plugin, player, "Impossible de se téléporter sur l'ile, vérifier les logs !");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,16 @@ private static void createIslandLanguage() {
messageIslandError = getString("island.create.error", messageIslandError);
}

public static void deleteIslandLanguage() {
private static void deleteIslandLanguage() {
messageOnlyOwnerCanDeleteIsland = getString("island.delete.only-owner", messageOnlyOwnerCanDeleteIsland);
messageIslandDeleteSuccess = getString("island.delete.success", messageIslandDeleteSuccess);
}

public static String messageHomeIslandSuccess = "Vous avez été téléporté sur votre île.";
private static void homeIslandLanguage() {
messageHomeIslandSuccess = getString("island.home.success", messageHomeIslandSuccess);
}

private static void islandGenericLanguage() {
messagePlayerHasNotIsland = getString("island.generic.player.no-island", messagePlayerHasNotIsland);
messageIslandAlreadyExist = getString("island.generic.player.already-exist", messageIslandAlreadyExist);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package fr.euphyllia.skyfolia.utils;

import fr.euphyllia.skyfolia.Main;
import fr.euphyllia.skyfolia.api.skyblock.Island;
import fr.euphyllia.skyfolia.api.skyblock.model.IslandType;
import fr.euphyllia.skyfolia.api.skyblock.model.SchematicWorld;
import fr.euphyllia.skyfolia.api.skyblock.model.WarpIsland;
import fr.euphyllia.skyfolia.configuration.ConfigToml;
import fr.euphyllia.skyfolia.configuration.LanguageToml;
import fr.euphyllia.skyfolia.configuration.section.WorldConfig;
import fr.euphyllia.skyfolia.utils.nms.v1_20_R2.PlayerNMS;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class IslandUtils {

public static @Nullable IslandType getIslandType(String name) {
Expand Down Expand Up @@ -32,6 +44,10 @@ public class IslandUtils {
}

public static boolean isWorldIsland(String worldName) {
return ConfigToml.worldConfigs.stream().anyMatch(wc -> wc.name().equalsIgnoreCase(worldName));
return getWorldConfigs().stream().anyMatch(wc -> wc.name().equalsIgnoreCase(worldName));
}

public static List<WorldConfig> getWorldConfigs() {
return ConfigToml.worldConfigs;
}
}

0 comments on commit c66a7ab

Please sign in to comment.