mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-01-30 19:31:31 +01:00
Re-Added IslandPreview after disappearing
This commit is contained in:
parent
d25678ec5b
commit
cc3b641798
@ -0,0 +1,98 @@
|
||||
package com.songoda.skyblock.command.commands.island;
|
||||
|
||||
import com.songoda.skyblock.command.SubCommand;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.confirmation.Confirmation;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.playerdata.PlayerData;
|
||||
import com.songoda.skyblock.structure.Structure;
|
||||
import com.songoda.skyblock.utils.version.Sounds;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class PreviewCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void onCommandByPlayer(Player player, String[] args) {
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
FileManager.Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
FileConfiguration configLang = config.getFileConfiguration();
|
||||
|
||||
if(args.length != 1) {
|
||||
skyblock.getMessageManager().sendMessage(player, configLang.getString("Command.Island.Preview.Argument.Count.Message"));
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerData data = skyblock.getPlayerDataManager().getPlayerData(player);
|
||||
Island island = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(player.getUniqueId()));
|
||||
|
||||
if (args[0].equals("confirm")) {
|
||||
if(data.getConfirmation() == Confirmation.Preview && data.getConfirmationTime() > 0) {
|
||||
Structure islandStructure = skyblock.getStructureManager().getStructure(island.getStructure());
|
||||
|
||||
if(skyblock.getIslandManager().deleteIsland(island, true)) {
|
||||
island.setDeleted(true);
|
||||
data.setPreview(false);
|
||||
if(player.getGameMode() == GameMode.SPECTATOR) {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(skyblock, () -> {
|
||||
if(skyblock.getIslandManager().createIsland(player, islandStructure)) {
|
||||
skyblock.getMessageManager().sendMessage(player, configLang.getString("Island.Creator.Selector.Created.Message"));
|
||||
skyblock.getSoundManager().playSound(player, Sounds.NOTE_PLING.bukkitSound(), 1.0F, 1.0F);
|
||||
}
|
||||
}, 30L);
|
||||
}
|
||||
}
|
||||
} else if (args[0].equals("cancel")) {
|
||||
if(data.getConfirmation() == Confirmation.Preview && data.getConfirmationTime() > 0) {
|
||||
if(skyblock.getIslandManager().deleteIsland(island, true)) {
|
||||
island.setDeleted(true);
|
||||
data.setPreview(false);
|
||||
if (player.getGameMode() == GameMode.SPECTATOR) {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Structure structure = skyblock.getStructureManager().getStructure(args[0]);
|
||||
if(structure == null) {
|
||||
skyblock.getMessageManager().sendMessage(player, configLang.getString("Island.Creator.File.Message"));
|
||||
return;
|
||||
}
|
||||
skyblock.getIslandManager().previewIsland(player, skyblock.getStructureManager().getStructure(args[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommandByConsole(ConsoleCommandSender sender, String[] args) {
|
||||
sender.sendMessage("SkyBlock | Error: You must be a player to perform that command.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "preview";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfoMessagePath() {
|
||||
return "Command.Island.Preview.Info.Message";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getArguments() {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
@ -2,6 +2,6 @@ package com.songoda.skyblock.confirmation;
|
||||
|
||||
public enum Confirmation {
|
||||
|
||||
Ownership, Reset, Deletion
|
||||
Ownership, Reset, Deletion, Preview
|
||||
|
||||
}
|
||||
|
@ -1,34 +1,5 @@
|
||||
package com.songoda.skyblock.island;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.ChunkSnapshot;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.IllegalPluginAccessException;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.api.event.island.*;
|
||||
@ -50,6 +21,7 @@ import com.songoda.skyblock.structure.Structure;
|
||||
import com.songoda.skyblock.structure.StructureManager;
|
||||
import com.songoda.skyblock.upgrade.Upgrade;
|
||||
import com.songoda.skyblock.upgrade.UpgradeManager;
|
||||
import com.songoda.skyblock.utils.ChatComponent;
|
||||
import com.songoda.skyblock.utils.player.OfflinePlayer;
|
||||
import com.songoda.skyblock.utils.player.PlayerUtil;
|
||||
import com.songoda.skyblock.utils.structure.SchematicUtil;
|
||||
@ -63,10 +35,6 @@ import com.songoda.skyblock.utils.world.WorldBorder;
|
||||
import com.songoda.skyblock.utils.world.block.BlockDegreesType;
|
||||
import com.songoda.skyblock.visit.VisitManager;
|
||||
import com.songoda.skyblock.world.WorldManager;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
@ -75,6 +43,17 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.IllegalPluginAccessException;
|
||||
import com.songoda.skyblock.confirmation.Confirmation;
|
||||
import com.songoda.skyblock.utils.ChatComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class IslandManager {
|
||||
|
||||
@ -314,6 +293,118 @@ public class IslandManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean previewIsland(Player player, Structure structure) {
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
|
||||
PlayerData data = skyblock.getPlayerDataManager().getPlayerData(player);
|
||||
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
FileConfiguration configLang = config.getFileConfiguration();
|
||||
config = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"));
|
||||
FileConfiguration configMain = config.getFileConfiguration();
|
||||
|
||||
|
||||
if (data != null) {
|
||||
final int highest = PlayerUtil.getNumberFromPermission(player, "fabledskyblock.limit.create", true, 2);
|
||||
|
||||
if ((data.getIslandCreationCount()) >= highest) {
|
||||
skyblock.getMessageManager().sendMessage(player, fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Creator.Error.MaxCreationMessage"));
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (fileManager.getConfig(new File(skyblock.getDataFolder(), "locations.yml")).getFileConfiguration().getString("Location.Spawn") == null) {
|
||||
skyblock.getMessageManager().sendMessage(player, configLang.getString("Island.Creator.Error.Message"));
|
||||
skyblock.getSoundManager().playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Island island = new Island(player);
|
||||
island.setStructure(structure.getName());
|
||||
islandStorage.put(player.getUniqueId(), island);
|
||||
|
||||
data.setPreview(true);
|
||||
|
||||
for (IslandWorld worldList : IslandWorld.getIslandWorlds())
|
||||
prepareIsland(island, worldList);
|
||||
|
||||
|
||||
Bukkit.getScheduler().callSyncMethod(SkyBlock.getInstance(), () -> {
|
||||
player.teleport(island.getLocation(IslandWorld.Normal, IslandEnvironment.Island));
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
return true;
|
||||
});
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(skyblock, () -> {
|
||||
if(data.isPreview()) {
|
||||
Location spawn = fileManager.getLocation(fileManager.getConfig(new File(skyblock.getDataFolder(), "locations.yml")), "Location.Spawn", true);
|
||||
player.teleport(spawn);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
data.setIsland(null);
|
||||
islandStorage.remove(player.getUniqueId(), island);
|
||||
deleteIsland(island, true);
|
||||
skyblock.getMessageManager().sendMessage(player, configLang.getString("Island.Preview.Timeout.Message"));
|
||||
data.setPreview(false);
|
||||
}
|
||||
}, configMain.getInt("Island.Preview.Time")*20);
|
||||
|
||||
|
||||
|
||||
String defaultMessage = configLang.getString("Command.Island.Preview.Confirmation.Message")
|
||||
.replaceAll("%time", "" + configMain.get("Island.Preview.Time"));
|
||||
|
||||
defaultMessage = defaultMessage.replace("\\n", "\n");
|
||||
|
||||
for (String message : defaultMessage.split("\n")) {
|
||||
ChatComponent confirmation = null, cancelation = null;
|
||||
|
||||
if(message.contains("%confirm")) {
|
||||
message = message.replace("%confirm", "");
|
||||
confirmation = new ChatComponent(configLang.getString("Command.Island.Preview.Confirmation.Word.Confirm").toUpperCase() + " ",
|
||||
true, net.md_5.bungee.api.ChatColor.GREEN,
|
||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/island preview confirm"),
|
||||
new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new ComponentBuilder(
|
||||
net.md_5.bungee.api.ChatColor.translateAlternateColorCodes(
|
||||
'&',
|
||||
configLang.getString("Command.Island.Preview.Confirmation.Word.TutorialConfirm")))
|
||||
.create()
|
||||
));
|
||||
}
|
||||
|
||||
if(message.contains("%cancel")) {
|
||||
message = message.replace("%cancel", "");
|
||||
cancelation = new ChatComponent(configLang.getString("Command.Island.Preview.Confirmation.Word.Cancel").toUpperCase(),
|
||||
true, net.md_5.bungee.api.ChatColor.GREEN,
|
||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/island preview cancel"),
|
||||
new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new ComponentBuilder(
|
||||
net.md_5.bungee.api.ChatColor.translateAlternateColorCodes(
|
||||
'&',
|
||||
configLang.getString("Command.Island.Preview.Confirmation.Word.TutorialCancel")))
|
||||
.create()
|
||||
));
|
||||
}
|
||||
|
||||
TextComponent confirmationMessage = new TextComponent(net.md_5.bungee.api.ChatColor.translateAlternateColorCodes('&', message));
|
||||
if(confirmation != null) {
|
||||
confirmationMessage.addExtra(confirmation.getTextComponent());
|
||||
}
|
||||
if(cancelation != null) {
|
||||
confirmationMessage.addExtra(cancelation.getTextComponent());
|
||||
}
|
||||
|
||||
player.spigot().sendMessage(confirmationMessage);
|
||||
|
||||
}
|
||||
|
||||
data.setConfirmation(Confirmation.Preview);
|
||||
data.setConfirmationTime(configMain.getInt("Island.Preview.Time"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void giveOwnership(Island island, org.bukkit.OfflinePlayer player) {
|
||||
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
|
||||
CooldownManager cooldownManager = skyblock.getCooldownManager();
|
||||
|
@ -191,10 +191,18 @@ public class Creator {
|
||||
return;
|
||||
}
|
||||
|
||||
if (islandManager.createIsland(player, structureList)) {
|
||||
messageManager.sendMessage(player,
|
||||
configLoad.getString("Island.Creator.Selector.Created.Message"));
|
||||
soundManager.playSound(player, Sounds.NOTE_PLING.bukkitSound(), 1.0F, 1.0F);
|
||||
if(event.getClick().isLeftClick()) {
|
||||
if (islandManager.createIsland(player, structureList)) {
|
||||
messageManager.sendMessage(player,
|
||||
configLoad.getString("Island.Creator.Selector.Created.Message"));
|
||||
soundManager.playSound(player, Sounds.NOTE_PLING.bukkitSound(), 1.0F, 1.0F);
|
||||
}
|
||||
} else if(event.getClick().isRightClick()) {
|
||||
if (islandManager.previewIsland(player, structureList)) {
|
||||
messageManager.sendMessage(player,
|
||||
configLoad.getString("Island.Creator.Selector.Preview.Message"));
|
||||
soundManager.playSound(player, Sounds.NOTE_PLING.bukkitSound(), 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -32,6 +32,7 @@ public class PlayerData {
|
||||
private Area area;
|
||||
|
||||
private boolean chat;
|
||||
private boolean preview;
|
||||
|
||||
private Object viewer;
|
||||
|
||||
@ -46,6 +47,7 @@ public class PlayerData {
|
||||
area = new Area();
|
||||
|
||||
chat = false;
|
||||
preview = false;
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
@ -116,6 +118,15 @@ public class PlayerData {
|
||||
this.playTime = playTime;
|
||||
}
|
||||
|
||||
public boolean isPreview() {
|
||||
return preview;
|
||||
}
|
||||
|
||||
public void setPreview(boolean preview) {
|
||||
this.preview = preview;
|
||||
}
|
||||
|
||||
|
||||
public int getVisitTime() {
|
||||
return visitTime;
|
||||
}
|
||||
|
@ -111,6 +111,8 @@ Island:
|
||||
# If disabled, any islands the player has been banned from will be removed when they
|
||||
# open the Island Visit menu.
|
||||
Bans: false
|
||||
Preview:
|
||||
Time: 10
|
||||
Visitor:
|
||||
# When an Island is unloaded if enabled players won't be able to visit the Island
|
||||
# even if it's open.
|
||||
|
@ -955,6 +955,19 @@ Command:
|
||||
Message: '&f&oOpens the Leaderboard menu of the top 10 Islands.'
|
||||
Invalid:
|
||||
Message: '&bSkyBlock &8| &cError&8: &eInvalid: /island leaderboard [<Level|Bank|Votes>]'
|
||||
Preview:
|
||||
Info:
|
||||
Message: '&f&oAllows you to preview island before choosing'
|
||||
Argument:
|
||||
Count:
|
||||
Message: '&bSkyBlock &8| &cError&8: &eThis command should have atleast 1 argument.'
|
||||
Confirmation:
|
||||
Message: '&bSkyBlock &8| &aInfo&8: &eYou are now previewing the Island. You have &c%time &eseconds to confirm or cancel.\n %confirm %cancel'
|
||||
Word:
|
||||
Confirm: 'Confirm'
|
||||
TutorialConfirm: '&7Click to &f&oconfirm &r&7Island creation!'
|
||||
Cancel: 'Cancel'
|
||||
TutorialCancel: '&7Click to &f&ocancel &r&7Island creation!'
|
||||
PermissionDenied:
|
||||
Admin:
|
||||
Message: '&bSkyBlock &8| &cError&8: &eYou don''t have permission to perform that command.'
|
||||
@ -3107,6 +3120,7 @@ Menu:
|
||||
- '%description'
|
||||
- ''
|
||||
- '&eClick to create Island!'
|
||||
- '&eRight-Click to create Island!'
|
||||
Placeholder:
|
||||
fabledskyblock_leaderboard_votes:
|
||||
Empty:
|
||||
@ -3499,6 +3513,9 @@ Island:
|
||||
Message: '&bSkyBlock &8| &cError&8: &eYou don''t have permission to use that feature.'
|
||||
Permission:
|
||||
Message: '&bSkyBlock &8| &cError&8: &eYou do not have the right to do that on this Island.'
|
||||
Preview:
|
||||
Timeout:
|
||||
Message: '&bSkyBlock &8| &aInfo&8: &eYour time to preview island has expired'
|
||||
Hologram:
|
||||
Leaderboard:
|
||||
Votes:
|
||||
|
Loading…
Reference in New Issue
Block a user