Initial commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ProjectCranked</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>Voyages</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>LootTable</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,75 @@
|
||||
package net.crankedpvp.voyages;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import me.mattstudios.mf.base.components.TypeResult;
|
||||
import net.crankedpvp.crankedutils.utils.PluginUtils;
|
||||
import net.crankedpvp.voyages.commands.VoyageCommand;
|
||||
import net.crankedpvp.voyages.listeners.PortalListeners;
|
||||
import net.crankedpvp.voyages.struct.config.ConfigManager;
|
||||
import net.crankedpvp.voyages.struct.config.RoomConfigManager;
|
||||
import net.crankedpvp.voyages.struct.room.Room;
|
||||
import net.crankedpvp.voyages.struct.voyage.Voyage;
|
||||
import net.crankedpvp.voyages.struct.voyage.VoyageLootManager;
|
||||
import net.crankedpvp.voyages.struct.voyage.VoyageManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
|
||||
public class VoyagePlugin extends JavaPlugin {
|
||||
|
||||
@Getter
|
||||
private static VoyagePlugin instance;
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private CommandManager commandManager;
|
||||
private VoyageManager voyageManager;
|
||||
private RoomConfigManager roomConfigManager;
|
||||
private ConfigManager configManager;
|
||||
private VoyageLootManager voyageLootManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
this.voyageManager = new VoyageManager(this);
|
||||
|
||||
this.roomConfigManager = new RoomConfigManager(this);
|
||||
this.roomConfigManager.loadRoomsFromFiles();
|
||||
|
||||
this.configManager = new ConfigManager(this);
|
||||
this.configManager.setupFiles();
|
||||
|
||||
this.voyageLootManager = new VoyageLootManager(this);
|
||||
|
||||
PluginUtils.registerListeners(this, new PortalListeners(this));
|
||||
|
||||
this.commandManager = new CommandManager(this);
|
||||
this.registerCommandCompletion();
|
||||
this.registerCommandParameters();
|
||||
this.commandManager.register(new VoyageCommand(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
for (Voyage activeVoyage : this.voyageManager.getActiveVoyages()) {
|
||||
activeVoyage.getPortal().delete();
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommandParameters() {
|
||||
this.commandManager.getParameterHandler().register(Room.class, argument -> {
|
||||
Room room = Room.valueOf(String.valueOf(argument));
|
||||
return new TypeResult(room, argument);
|
||||
});
|
||||
}
|
||||
|
||||
private void registerCommandCompletion() {
|
||||
this.commandManager.getCompletionHandler().register("#rooms", input -> Arrays.stream(Room.values()).map(Enum::name).collect(Collectors.toList()));
|
||||
this.commandManager.getCompletionHandler().register("#boolean", input -> Arrays.asList("true", "false"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package net.crankedpvp.voyages.commands;
|
||||
|
||||
import me.mattstudios.mf.annotations.*;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.crankedutils.utils.InventoryUtils;
|
||||
import net.crankedpvp.voyages.VoyagePlugin;
|
||||
import net.crankedpvp.voyages.struct.config.RoomConfigManager;
|
||||
import net.crankedpvp.voyages.struct.items.PortalSummoner;
|
||||
import net.crankedpvp.voyages.struct.room.Room;
|
||||
import net.crankedpvp.voyages.struct.room.VoyageRoom;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Command("voyage")
|
||||
public class VoyageCommand extends CommandBase {
|
||||
|
||||
private final RoomConfigManager roomConfigManager;
|
||||
|
||||
public VoyageCommand(VoyagePlugin plugin) {
|
||||
this.roomConfigManager = plugin.getRoomConfigManager();
|
||||
}
|
||||
|
||||
@Default
|
||||
public void defaultCommand(final CommandSender commandSender) {
|
||||
|
||||
}
|
||||
|
||||
@SubCommand("reload")
|
||||
@Permission("cranked.admin")
|
||||
public void reloadCommand(final CommandSender commandSender) {
|
||||
|
||||
}
|
||||
|
||||
@SubCommand("rooms")
|
||||
@Permission("cranked.admin")
|
||||
public void roomsCommand(final CommandSender commandSender) {
|
||||
|
||||
}
|
||||
|
||||
@SubCommand("register")
|
||||
@Permission("cranked.admin")
|
||||
public void registerCommand(final Player sender, @Completion("#rooms") Room room) {
|
||||
Location location = sender.getLocation();
|
||||
|
||||
Location spawnLocation = new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
|
||||
VoyageRoom<?> voyageRoom = room.createNewRoom.apply(spawnLocation);
|
||||
this.roomConfigManager.addRoom(voyageRoom);
|
||||
}
|
||||
|
||||
@SubCommand("giveup")
|
||||
@Alias("leave")
|
||||
@Permission("cranked.admin")
|
||||
public void leaveRoomCommand(final CommandSender commandSender) {
|
||||
|
||||
}
|
||||
|
||||
@SubCommand("summoner")
|
||||
@Permission("cranked.admin")
|
||||
public void summonerCommand(final CommandSender sender, @Optional Player player) {
|
||||
if (player != null) {
|
||||
player.getInventory().addItem(PortalSummoner.getItem());
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender instanceof Player) {
|
||||
InventoryUtils.giveItemToPlayer(((Player) sender), PortalSummoner.getItem());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package net.crankedpvp.voyages.inventories;
|
||||
|
||||
public class ActiveVoyagesGUI {
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package net.crankedpvp.voyages.inventories;
|
||||
|
||||
import dev.triumphteam.gui.components.GuiAction;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.utils.InventoryUtils;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import net.crankedpvp.voyages.struct.voyage.Voyage;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SelectLootUI {
|
||||
|
||||
private final Voyage voyage;
|
||||
@Getter
|
||||
private final Gui selectLootUI;
|
||||
private final List<ItemStack> loot;
|
||||
|
||||
private final static ItemStack GREEN_WOOL = new ItemBuilder(Material.WOOL, "&a&lCONTINUE", "")
|
||||
.colorize()
|
||||
.setColor(DyeColor.GREEN)
|
||||
.build();
|
||||
|
||||
private final static ItemStack RED_WOOL = new ItemBuilder(Material.WOOL, "&c&lLEAVE", "")
|
||||
.colorize()
|
||||
.setColor(DyeColor.RED)
|
||||
.build();
|
||||
|
||||
public SelectLootUI(Voyage voyage) {
|
||||
this.voyage = voyage;
|
||||
this.loot = this.voyage.getLoot();
|
||||
this.selectLootUI = Gui.gui()
|
||||
.disableAllInteractions()
|
||||
.title(Component.text("Voyage Loot"))
|
||||
.rows(3)
|
||||
.create();
|
||||
|
||||
this.selectLootUI.setItem(0, new GuiItem(RED_WOOL, this.getRedWoolAction()));
|
||||
|
||||
this.selectLootUI.setItem(1, new GuiItem(RED_WOOL, this.getRedWoolAction()));
|
||||
this.selectLootUI.setItem(9, new GuiItem(RED_WOOL, this.getRedWoolAction()));
|
||||
this.selectLootUI.setItem(10, new GuiItem(RED_WOOL, this.getRedWoolAction()));
|
||||
this.selectLootUI.setItem(18, new GuiItem(RED_WOOL, this.getRedWoolAction()));
|
||||
this.selectLootUI.setItem(19, new GuiItem(RED_WOOL, this.getRedWoolAction()));
|
||||
|
||||
this.selectLootUI.setItem(7, new GuiItem(GREEN_WOOL, this.getGreenWoolAction()));
|
||||
this.selectLootUI.setItem(8, new GuiItem(GREEN_WOOL, this.getGreenWoolAction()));
|
||||
this.selectLootUI.setItem(16, new GuiItem(GREEN_WOOL, this.getGreenWoolAction()));
|
||||
this.selectLootUI.setItem(17, new GuiItem(GREEN_WOOL, this.getGreenWoolAction()));
|
||||
this.selectLootUI.setItem(25, new GuiItem(GREEN_WOOL, this.getGreenWoolAction()));
|
||||
this.selectLootUI.setItem(26, new GuiItem(GREEN_WOOL, this.getGreenWoolAction()));
|
||||
|
||||
this.selectLootUI.setItem(12, new GuiItem(this.loot.get(0)));
|
||||
this.selectLootUI.setItem(13, new GuiItem(this.loot.get(1)));
|
||||
this.selectLootUI.setItem(14, new GuiItem(this.loot.get(2)));
|
||||
}
|
||||
|
||||
private GuiAction<InventoryClickEvent> getRedWoolAction() {
|
||||
return event -> {
|
||||
this.voyage.leaveVoyage((Player) event.getWhoClicked());
|
||||
InventoryUtils.giveItemToPlayer(((Player) event.getWhoClicked()), this.loot);
|
||||
};
|
||||
}
|
||||
|
||||
private GuiAction<InventoryClickEvent> getGreenWoolAction() {
|
||||
return event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package net.crankedpvp.voyages.listeners;
|
||||
|
||||
import net.crankedpvp.voyages.VoyagePlugin;
|
||||
import net.crankedpvp.voyages.struct.config.ConfigManager;
|
||||
import net.crankedpvp.voyages.struct.voyage.Voyage;
|
||||
import net.crankedpvp.voyages.struct.voyage.VoyageManager;
|
||||
import net.crankedpvp.voyages.utils.VoyageUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityPortalEnterEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
public class PortalListeners implements Listener {
|
||||
|
||||
private final VoyageManager voyageManager;
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public PortalListeners(VoyagePlugin plugin) {
|
||||
this.voyageManager = plugin.getVoyageManager();
|
||||
this.configManager = plugin.getConfigManager();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPortalEnter(EntityPortalEnterEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) return;
|
||||
|
||||
Player player = ((Player) event.getEntity());
|
||||
|
||||
for (Voyage activeVoyage : this.voyageManager.getActiveVoyages()) {
|
||||
if (!activeVoyage.getPortal().getLocation().getWorld().equals(event.getLocation().getWorld())) continue;
|
||||
if (activeVoyage.getPortal().getLocation().distance(event.getLocation()) > 2) continue;
|
||||
|
||||
if (activeVoyage.isAlreadyParticipant(player)) {
|
||||
System.out.println("how tf did that happen");
|
||||
return;
|
||||
}
|
||||
|
||||
if (activeVoyage.isFull()) {
|
||||
//TODO: message player that this shit is full
|
||||
return;
|
||||
}
|
||||
|
||||
activeVoyage.addParticipant(player);
|
||||
activeVoyage.warpPlayerToWaitingRoom(player);
|
||||
System.out.println("added to the voyage");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onInteractWithPortalSummoner(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
if (!VoyageUtils.isVoyageSummoner(event.getPlayer().getItemInHand())) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
Location location = event.getClickedBlock().getLocation();
|
||||
|
||||
if (!this.voyageManager.isThereSpaceForPortal(location)) {
|
||||
//TODO: send message
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO: make sure there isn't another portal too close, could fuck with shit
|
||||
|
||||
this.voyageManager.summonPortal(location.add(0, 1, 0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package net.crankedpvp.voyages.rooms;
|
||||
|
||||
import net.crankedpvp.voyages.struct.annotations.ConfigValue;
|
||||
import net.crankedpvp.voyages.struct.player.DropperPlayer;
|
||||
import net.crankedpvp.voyages.struct.room.Room;
|
||||
import net.crankedpvp.voyages.struct.room.RoomOptions;
|
||||
import net.crankedpvp.voyages.struct.room.VoyageRoom;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class DropperRoom extends VoyageRoom<DropperPlayer> {
|
||||
|
||||
@ConfigValue
|
||||
private List<Location> spawnPoints = Collections.singletonList(new Location(Bukkit.getWorld("world_voyage"), 16, 5, -36));
|
||||
|
||||
private Location spawnPointLocation = this.spawnPoints.get(new Random().nextInt(spawnPoints.size()));
|
||||
|
||||
public DropperRoom(final Location spawnLocation) {
|
||||
super(spawnLocation, "Dropper", Room.DROPPER,300, RoomOptions.builder().fallDamage(true).build(), "Reach the bottom of the dropper");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startVoyageRoom() {
|
||||
this.spawnPointLocation = this.spawnPoints.get(new Random().nextInt(spawnPoints.size()));
|
||||
super.teleportParticipantsTo(spawnPointLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopVoyageRoom() {
|
||||
super.nextRoom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParticipant(Player player) {
|
||||
super.addParticipant(new DropperPlayer(player));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void checkReachedBottom(EntityDamageEvent event) {
|
||||
if(event.getEntity() == null) return;
|
||||
if(!(event.getEntity() instanceof Player)) return;
|
||||
if(!this.isParticipant((Player) event.getEntity())) return;
|
||||
if(event.getCause() == EntityDamageEvent.DamageCause.FALL) {
|
||||
event.setCancelled(true);
|
||||
event.getEntity().teleport(this.spawnPointLocation);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.stopVoyageRoom();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.crankedpvp.voyages.rooms;
|
||||
|
||||
import net.crankedpvp.voyages.struct.annotations.ConfigValue;
|
||||
import net.crankedpvp.voyages.struct.player.VoyagePlayer;
|
||||
import net.crankedpvp.voyages.struct.room.Room;
|
||||
import net.crankedpvp.voyages.struct.room.RoomOptions;
|
||||
import net.crankedpvp.voyages.struct.room.VoyageRoom;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class MazeRoom extends VoyageRoom<VoyagePlayer> {
|
||||
|
||||
@ConfigValue
|
||||
private List<Location> spawnPoints = Collections.singletonList(new Location(Bukkit.getWorld("world_voyage"), 16, 5, -36));
|
||||
|
||||
public MazeRoom(final Location spawnLocation) {
|
||||
super(spawnLocation, "Maze", Room.MAZE, 300, RoomOptions.builder().build(), "Get to the end of the maze");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startVoyageRoom() {
|
||||
Location spawnPointLocation = this.spawnPoints.get(new Random().nextInt(spawnPoints.size()));
|
||||
super.teleportParticipantsTo(spawnPointLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopVoyageRoom() {
|
||||
super.nextRoom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParticipant(Player player) {
|
||||
super.addParticipant(new VoyagePlayer(player));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void checkPressurePlate(PlayerInteractEvent event) {
|
||||
if(!this.isParticipant(event.getPlayer())) return;
|
||||
if(event.getPlayer() == null) return;
|
||||
if(event.getAction() != Action.PHYSICAL) return;
|
||||
if(!event.getClickedBlock().getType().equals(Material.GOLD_PLATE)) return;
|
||||
this.stopVoyageRoom();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package net.crankedpvp.voyages.rooms;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.RandomUtils;
|
||||
import net.crankedpvp.voyages.struct.annotations.ConfigValue;
|
||||
import net.crankedpvp.voyages.struct.player.RiddlerPlayer;
|
||||
import net.crankedpvp.voyages.struct.room.Room;
|
||||
import net.crankedpvp.voyages.struct.room.RoomOptions;
|
||||
import net.crankedpvp.voyages.struct.room.VoyageRoom;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class RiddlerRoom extends VoyageRoom<RiddlerPlayer> {
|
||||
|
||||
@ConfigValue
|
||||
private Location spawnPoint = new Location(Bukkit.getWorld("world"), 0, 0, 0);
|
||||
|
||||
@ConfigValue
|
||||
public HashMap<String, List<String>> questionsAndAnswers = new HashMap<String, List<String>>() {{
|
||||
this.put("What has 13 hearts but no organs", Arrays.asList("A deck of cards", "deck of cards", "cards"));
|
||||
}};
|
||||
|
||||
public RiddlerRoom(final Location spawnLocation) {
|
||||
super(spawnLocation, "Riddler", Room.RIDDLER,20, RoomOptions.builder().build(), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startVoyageRoom() {
|
||||
super.teleportParticipantsTo(this.spawnPoint);
|
||||
this.askPlayersQuestions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopVoyageRoom() {
|
||||
super.nextRoom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParticipant(Player participant) {
|
||||
super.addParticipant(new RiddlerPlayer(participant));
|
||||
}
|
||||
|
||||
|
||||
public void askPlayersQuestions() {
|
||||
for (RiddlerPlayer participant : this.getParticipants()) {
|
||||
participant.setQuestion(this.getRandomQuestion());
|
||||
participant.sendMessage("&c&lQUESTION: &7&o" + participant.getQuestion());
|
||||
}
|
||||
}
|
||||
|
||||
public String getRandomQuestion() {
|
||||
return RandomUtils.getRandomSetElement(this.questionsAndAnswers.keySet());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
if (!super.isParticipant(event.getPlayer())) return;
|
||||
|
||||
if (this.questionsAndAnswers.get(this.getParticipant(event.getPlayer()).getQuestion()).contains(event.getMessage())) {
|
||||
this.stopVoyageRoom();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package net.crankedpvp.voyages.rooms;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.RandomUtils;
|
||||
import net.crankedpvp.voyages.struct.annotations.ConfigValue;
|
||||
import net.crankedpvp.voyages.struct.player.TriviaPlayer;
|
||||
import net.crankedpvp.voyages.struct.room.Room;
|
||||
import net.crankedpvp.voyages.struct.room.RoomOptions;
|
||||
import net.crankedpvp.voyages.struct.room.VoyageRoom;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class TriviaRoom extends VoyageRoom<TriviaPlayer> {
|
||||
|
||||
@ConfigValue
|
||||
private Location checkpoint1 = new Location(Bukkit.getWorld("world"), 0, 0, 0);
|
||||
|
||||
public HashMap<String, List<String>> questionsAndAnswers = new HashMap<String, List<String>>() {{
|
||||
this.put("What has 13 hearts but no organs", Arrays.asList("A deck of cards", "deck of cards", "cards"));
|
||||
}};
|
||||
|
||||
public TriviaRoom(final Location spawnLocation) {
|
||||
super(spawnLocation, "Trivia", Room.TRIVIA, 300, RoomOptions.builder().build(), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startVoyageRoom() {
|
||||
super.teleportParticipantsTo(super.getSpawnLocation());
|
||||
this.askPlayersQuestions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopVoyageRoom() {
|
||||
super.nextRoom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParticipant(Player participant) {
|
||||
super.addParticipant(new TriviaPlayer(participant));
|
||||
}
|
||||
|
||||
|
||||
public void askPlayersQuestions() {
|
||||
for (TriviaPlayer participant : this.getParticipants()) {
|
||||
participant.setQuestion(this.getRandomQuestion());
|
||||
participant.sendMessage("&c&lQUESTION: &7&o" + participant.getQuestion());
|
||||
}
|
||||
}
|
||||
|
||||
public String getRandomQuestion() {
|
||||
return RandomUtils.getRandomSetElement(this.questionsAndAnswers.keySet());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
if (!super.isParticipant(event.getPlayer())) return;
|
||||
|
||||
if (this.questionsAndAnswers.get(this.getParticipant(event.getPlayer()).getQuestion()).contains(event.getMessage())) {
|
||||
this.stopVoyageRoom();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.crankedpvp.voyages.struct.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* don't forget to not make the field final when using this annotation
|
||||
*/
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface ConfigValue {
|
||||
|
||||
String path() default "room.";
|
||||
String name() default "";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.crankedpvp.voyages.struct.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.crankedpvp.crankedutils.utils.config.AbstractConfig;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
@Getter
|
||||
private final Map<ConfigFile, AbstractConfig> configs = new HashMap<>();
|
||||
|
||||
public ConfigManager(JavaPlugin plugin) {
|
||||
|
||||
for (ConfigFile configFile : ConfigFile.values()) {
|
||||
AbstractConfig abstractConfig = new AbstractConfig(plugin, configFile.getFileName());
|
||||
configs.put(configFile, abstractConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public void setupFiles() {
|
||||
configs.values().forEach(AbstractConfig::setupConfigFile);
|
||||
}
|
||||
|
||||
public void reloadFiles() {
|
||||
configs.values().forEach(AbstractConfig::reloadConfig);
|
||||
}
|
||||
|
||||
public AbstractConfig getAbstractConfig(ConfigFile configFile) {
|
||||
return configs.get(configFile);
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig(ConfigFile configFile) {
|
||||
return getAbstractConfig(configFile).getConfig();
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum ConfigFile {
|
||||
|
||||
SETTINGS("settings.yml"),
|
||||
TRIVIA("trivia.yml"),
|
||||
;
|
||||
|
||||
private final String fileName;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package net.crankedpvp.voyages.struct.config;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.voyages.VoyagePlugin;
|
||||
import net.crankedpvp.voyages.struct.annotations.ConfigValue;
|
||||
import net.crankedpvp.voyages.struct.room.Reloadable;
|
||||
import net.crankedpvp.voyages.struct.room.VoyageRoom;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@Getter
|
||||
public class RoomConfig {
|
||||
|
||||
@Getter(value = AccessLevel.PRIVATE)
|
||||
private final VoyagePlugin plugin;
|
||||
private final String path;
|
||||
private FileConfiguration config;
|
||||
private final File configFile;
|
||||
private final VoyageRoom<?> voyageRoom;
|
||||
|
||||
public RoomConfig(VoyagePlugin plugin, String path, VoyageRoom<?> voyageRoom) {
|
||||
this.plugin = plugin;
|
||||
this.path = path;
|
||||
this.voyageRoom = voyageRoom;
|
||||
this.configFile = new File(plugin.getDataFolder(), path);
|
||||
}
|
||||
|
||||
public void setupConfigFile() {
|
||||
this.createDefaultFile();
|
||||
this.config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
this.loadVariables();
|
||||
|
||||
boolean result = this.saveConfig();
|
||||
if (result) this.loadConfigFromDisk();
|
||||
|
||||
}
|
||||
|
||||
public boolean saveConfig() {
|
||||
try {
|
||||
config.save(configFile);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Could not save config file for " + path);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void createDefaultFile() {
|
||||
if (!configFile.exists()) {
|
||||
try {
|
||||
configFile.getParentFile().mkdirs();
|
||||
configFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Could not create config file for " + path);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
this.loadVariables();
|
||||
}
|
||||
|
||||
public void loadConfigFromDisk() {
|
||||
try {
|
||||
config.load(configFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
plugin.getLogger().severe("Could not load config for " + path);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void loadVariables() {
|
||||
boolean needSave = false;
|
||||
for (Field field : this.voyageRoom.getClass().getDeclaredFields()) {
|
||||
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
|
||||
if (field.isAnnotationPresent(ConfigValue.class)) {
|
||||
ConfigValue annotationValue = field.getAnnotation(ConfigValue.class);
|
||||
|
||||
String name = annotationValue.name().equals("") ? field.getName() : annotationValue.name();
|
||||
|
||||
String path = annotationValue.path().endsWith(".") ? annotationValue.path() : annotationValue.path() + ".";
|
||||
|
||||
if (!this.config.contains(path + name)) {
|
||||
this.config.set(path + name, field.get(this.voyageRoom));
|
||||
needSave = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
Object configValue = this.config.get(path + name);
|
||||
|
||||
if (configValue instanceof String) {
|
||||
configValue = CC.translate((String) configValue);
|
||||
}
|
||||
|
||||
field.set(this.voyageRoom, configValue);
|
||||
}
|
||||
} catch (IllegalAccessException | NullPointerException | IllegalArgumentException e) {
|
||||
Bukkit.getConsoleSender().sendMessage(CC.translate("&c[Voyages] - Error invalid config value for room " + this.voyageRoom.getName()));
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (this.voyageRoom instanceof Reloadable) {
|
||||
Reloadable reloadableEnchantment = ((Reloadable) this.voyageRoom);
|
||||
reloadableEnchantment.reloadValues();
|
||||
}
|
||||
}
|
||||
if (needSave) {
|
||||
saveConfig();
|
||||
reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.crankedpvp.voyages.struct.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.utils.serializer.location.LocationSerializerDeserializer;
|
||||
import net.crankedpvp.voyages.VoyagePlugin;
|
||||
import net.crankedpvp.voyages.struct.room.Room;
|
||||
import net.crankedpvp.voyages.struct.room.VoyageRoom;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class RoomConfigManager {
|
||||
|
||||
@Getter
|
||||
private final Map<VoyageRoom<?>, RoomConfig> configs = new HashMap<>();
|
||||
private final VoyagePlugin plugin;
|
||||
|
||||
public RoomConfigManager(VoyagePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void addRoom(VoyageRoom<?> room) {
|
||||
RoomConfig roomConfig = new RoomConfig(this.plugin, "rooms/" + room.getID().name().toLowerCase() + "/" + LocationSerializerDeserializer.serialize(room.getSpawnLocation()) + ".yml", room);
|
||||
this.configs.put(room, roomConfig);
|
||||
roomConfig.setupConfigFile();
|
||||
}
|
||||
|
||||
public void loadRoomsFromFiles() {
|
||||
File dataFolder = new File(this.plugin.getDataFolder(), "rooms");
|
||||
File[] directoryListing = dataFolder.listFiles();
|
||||
if (directoryListing != null) {
|
||||
for (File child : directoryListing) {
|
||||
File[] roomFiles = child.listFiles();
|
||||
System.out.println(child.getName());
|
||||
if (roomFiles == null) continue;
|
||||
for (File roomFile : roomFiles) {
|
||||
System.out.println(roomFile.getName());
|
||||
String locationAsString = roomFile.getName().substring(0, roomFile.getName().length() - 4);
|
||||
VoyageRoom<?> room = Room.valueOf(child.getName().toUpperCase()).createNewRoom.apply(LocationSerializerDeserializer.deserialize(locationAsString));
|
||||
this.addRoom(room);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadFiles() {
|
||||
this.configs.values().forEach(RoomConfig::reloadConfig);
|
||||
}
|
||||
|
||||
public RoomConfig getAbstractConfig(VoyageRoom<?> voyageRoom) {
|
||||
return this.configs.get(voyageRoom);
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig(VoyageRoom<?> voyageRoom) {
|
||||
return getAbstractConfig(voyageRoom).getConfig();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.crankedpvp.voyages.struct.items;
|
||||
|
||||
import de.tr7zw.nbtapi.NBTItem;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import static net.crankedpvp.voyages.utils.NbtTags.DATA_STRING;
|
||||
import static net.crankedpvp.voyages.utils.NbtTags.VOYAGE_PORTAL_SUMMONER_STRING;
|
||||
|
||||
public class PortalSummoner {
|
||||
|
||||
public static Material VOYAGE_PORTAL_SUMMONER_MATERIAL = Material.ENDER_PORTAL_FRAME;
|
||||
|
||||
public static ItemStack getItem() {
|
||||
ItemStack item = new ItemBuilder(new ItemStack(VOYAGE_PORTAL_SUMMONER_MATERIAL))
|
||||
.setName("&5Portal Summoner")
|
||||
.setLore(
|
||||
"",
|
||||
""
|
||||
)
|
||||
.colorize()
|
||||
.build();
|
||||
|
||||
NBTItem nbtItem = new NBTItem(item);
|
||||
nbtItem.setString(DATA_STRING, VOYAGE_PORTAL_SUMMONER_STRING);
|
||||
|
||||
return nbtItem.getItem();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.crankedpvp.voyages.struct.player;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DropperPlayer extends VoyagePlayer {
|
||||
|
||||
@Getter @Setter
|
||||
public int deaths;
|
||||
|
||||
public DropperPlayer(Player player) {
|
||||
super(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.crankedpvp.voyages.struct.player;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class RiddlerPlayer extends VoyagePlayer {
|
||||
|
||||
public String question;
|
||||
|
||||
public RiddlerPlayer(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.crankedpvp.voyages.struct.player;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class TriviaPlayer extends VoyagePlayer {
|
||||
|
||||
public String question;
|
||||
|
||||
public TriviaPlayer(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.crankedpvp.voyages.struct.player;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public class VoyagePlayer {
|
||||
|
||||
private final Player player;
|
||||
|
||||
public VoyagePlayer(final Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void sendMessage(String text) {
|
||||
this.player.sendMessage(CC.translate(text));
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return this.player.getUniqueId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.crankedpvp.voyages.struct.portal;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.Hologram;
|
||||
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.TextLine;
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.utils.BlockUtil;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.voyages.VoyagePlugin;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import static net.crankedpvp.voyages.struct.voyage.Voyage.MAX_AMOUNT_OF_PARTICIPANTS;
|
||||
|
||||
|
||||
@Getter
|
||||
public class Portal {
|
||||
|
||||
private final Location location;
|
||||
private int timeUtilPortalCloses;
|
||||
private final Hologram hologram;
|
||||
|
||||
public Portal(Location location) {
|
||||
this.location = location;
|
||||
this.timeUtilPortalCloses = 45;
|
||||
|
||||
this.hologram = HologramsAPI.createHologram(VoyagePlugin.getInstance(), location.clone().add(0.5, 2, 0.5));
|
||||
this.hologram.appendTextLine("");
|
||||
this.hologram.appendTextLine("");
|
||||
}
|
||||
|
||||
public void updateHologram(int amountOfParticipants) {
|
||||
((TextLine) this.hologram.getLine(0)).setText(CC.translate("&c" + amountOfParticipants + "&8/&c" + MAX_AMOUNT_OF_PARTICIPANTS + " &7players" ));
|
||||
((TextLine) this.hologram.getLine(1)).setText(CC.translate("&cClosing in " + this.timeUtilPortalCloses + " seconds."));
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
this.deleteHologram();
|
||||
this.removePortalBlocks();
|
||||
}
|
||||
|
||||
private void deleteHologram() {
|
||||
this.hologram.delete();
|
||||
}
|
||||
|
||||
public void decrementTimeBeforePortalCloses() {
|
||||
this.timeUtilPortalCloses--;
|
||||
}
|
||||
|
||||
private void removePortalBlocks() {
|
||||
for (int i = -2; i <= 2; i++) {
|
||||
for (int j = -2; j <= 2; j++) {
|
||||
BlockUtil.setAir(this.location.getWorld(), this.location.getBlockX() + i, this.location.getBlockY(), this.location.getBlockZ() + j, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.crankedpvp.voyages.struct.portal;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@Getter
|
||||
public class VoyagePortal {
|
||||
|
||||
private final Location portalLocation;
|
||||
|
||||
@Setter
|
||||
private int timeUntilClose;
|
||||
|
||||
public VoyagePortal(Location portalLocation) {
|
||||
this.portalLocation = portalLocation;
|
||||
this.timeUntilClose = 45;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.crankedpvp.voyages.struct.room;
|
||||
|
||||
public interface Reloadable {
|
||||
|
||||
void reloadValues();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.crankedpvp.voyages.struct.room;
|
||||
|
||||
import net.crankedpvp.voyages.rooms.DropperRoom;
|
||||
import net.crankedpvp.voyages.rooms.MazeRoom;
|
||||
import net.crankedpvp.voyages.rooms.RiddlerRoom;
|
||||
import net.crankedpvp.voyages.rooms.TriviaRoom;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public enum Room {
|
||||
|
||||
MAZE(MazeRoom::new),
|
||||
DROPPER(DropperRoom::new),
|
||||
RIDDLER(RiddlerRoom::new),
|
||||
TRIVIA(TriviaRoom::new),
|
||||
;
|
||||
|
||||
public final Function<Location, VoyageRoom<?>> createNewRoom;
|
||||
|
||||
Room(Function<Location, VoyageRoom<?>> createNewRoom) {
|
||||
this.createNewRoom = createNewRoom;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package net.crankedpvp.voyages.struct.room;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class RoomOptions {
|
||||
|
||||
@Builder.Default
|
||||
private final boolean blockPlace = false;
|
||||
@Builder.Default
|
||||
private final boolean blockBreak = false;
|
||||
@Builder.Default
|
||||
private final boolean fallDamage = false;
|
||||
@Builder.Default
|
||||
private final boolean itemPickUp = false;
|
||||
@Builder.Default
|
||||
private final boolean itemDrop = false;
|
||||
@Builder.Default
|
||||
private final boolean blockCommands = true;
|
||||
@Builder.Default
|
||||
private final boolean inventoryInteract = false;
|
||||
@Builder.Default
|
||||
private final boolean pvp = false;
|
||||
@Builder.Default
|
||||
private final String[] excludedBlockedCommands = {""};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package net.crankedpvp.voyages.struct.room;
|
||||
|
||||
public enum RoomStatus {
|
||||
NOT_STARTED, STARTING, IN_PROGRESS, FINISHED
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
package net.crankedpvp.voyages.struct.room;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.TitleUtils;
|
||||
import net.crankedpvp.voyages.VoyagePlugin;
|
||||
import net.crankedpvp.voyages.inventories.SelectLootUI;
|
||||
import net.crankedpvp.voyages.struct.player.VoyagePlayer;
|
||||
import net.crankedpvp.voyages.struct.voyage.Voyage;
|
||||
import net.crankedpvp.voyages.tasks.VoyageRoomTimeLeftTask;
|
||||
import net.crankedpvp.voyages.tasks.VoyageRoomCountdownTask;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public abstract class VoyageRoom<T extends VoyagePlayer> implements Listener {
|
||||
|
||||
private final Location spawnLocation;
|
||||
private final String description;
|
||||
@Setter
|
||||
private RoomStatus roomStatus;
|
||||
@Setter
|
||||
private Voyage voyage;
|
||||
|
||||
private final VoyagePlugin plugin;
|
||||
private final String name;
|
||||
private final Room id;
|
||||
private final Map<UUID, T> voyagePlayers;
|
||||
private final RoomOptions roomOptions;
|
||||
|
||||
private BukkitRunnable voyageRoomTimeLeftTask;
|
||||
|
||||
private final int durationOfRoomInSeconds;
|
||||
|
||||
public VoyageRoom(final Location spawnLocation, final String name, final Room id, final int durationOfRoomInSeconds, final RoomOptions roomOptions, final String description) {
|
||||
this.spawnLocation = spawnLocation;
|
||||
this.description = description;
|
||||
this.plugin = VoyagePlugin.getInstance();
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.durationOfRoomInSeconds = durationOfRoomInSeconds;
|
||||
this.roomOptions = roomOptions;
|
||||
this.voyage = null;
|
||||
this.voyageRoomTimeLeftTask = null;
|
||||
|
||||
this.roomStatus = RoomStatus.NOT_STARTED;
|
||||
this.voyagePlayers = new HashMap<>();
|
||||
}
|
||||
|
||||
protected abstract void startVoyageRoom();
|
||||
|
||||
public abstract void stopVoyageRoom();
|
||||
|
||||
public abstract void addParticipant(Player player);
|
||||
|
||||
public void teleportParticipantsTo(Location location) {
|
||||
for(T participant : this.getParticipants()) {
|
||||
participant.getPlayer().teleport(location);
|
||||
}
|
||||
}
|
||||
public void addPlayersToVoyageParticipants(List<Player> participants) {
|
||||
for (Player participant : participants) {
|
||||
addParticipant(participant);
|
||||
}
|
||||
}
|
||||
public void nextRoom() {
|
||||
if (this.voyageRoomTimeLeftTask != null)
|
||||
this.voyageRoomTimeLeftTask.cancel();
|
||||
|
||||
this.voyage.incrementAmountOfRoomsCompleted();
|
||||
|
||||
for (Player playerParticipant : this.getPlayerParticipants()) {
|
||||
this.voyage.warpPlayerToWaitingRoom(playerParticipant);
|
||||
SelectLootUI selectLootUI = new SelectLootUI(this.voyage);
|
||||
selectLootUI.getSelectLootUI().open(playerParticipant);
|
||||
}
|
||||
|
||||
this.setRoomStatus(RoomStatus.NOT_STARTED);
|
||||
this.clearParticipants();
|
||||
|
||||
this.voyage.startVoyageRoom();
|
||||
|
||||
this.voyage = null;
|
||||
}
|
||||
|
||||
public void kickFromVoyageRoom(Player player) {
|
||||
this.removeParticipant(player);
|
||||
player.getInventory().setContents(new ItemStack[]{});
|
||||
player.getInventory().setArmorContents(new ItemStack[]{});
|
||||
player.teleport(Bukkit.getWorld("world").getSpawnLocation());
|
||||
player.teleport(Bukkit.getWorld("world").getSpawnLocation());
|
||||
}
|
||||
|
||||
public void startCountdown() {
|
||||
this.setRoomStatus(RoomStatus.STARTING);
|
||||
VoyageRoomCountdownTask voyageRoomCountdownTask = new VoyageRoomCountdownTask(this);
|
||||
voyageRoomCountdownTask.runTaskTimer(this.plugin, 20L, 20L);
|
||||
}
|
||||
|
||||
public void finishCountdown() {
|
||||
this.sendTitleToAllParticipants("&a&l" + getName() + " Room Starting", "&7This room is now starting");
|
||||
this.setRoomStatus(RoomStatus.IN_PROGRESS);
|
||||
this.voyageRoomTimeLeftTask = new VoyageRoomTimeLeftTask(this);
|
||||
this.voyageRoomTimeLeftTask.runTaskTimer(this.plugin, 0L, 20L);
|
||||
this.startVoyageRoom();
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return this.roomStatus == RoomStatus.NOT_STARTED;
|
||||
}
|
||||
|
||||
public void kickFromVoyageRoom(T voyagePlayer) {
|
||||
this.kickFromVoyageRoom(voyagePlayer.getPlayer());
|
||||
}
|
||||
|
||||
public void addParticipant(T participant) {
|
||||
this.voyagePlayers.put(participant.getUUID(), participant);
|
||||
}
|
||||
|
||||
protected void removeParticipant(Player player) {
|
||||
this.voyagePlayers.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
protected void removeParticipant(T participant) {
|
||||
this.voyagePlayers.remove(participant.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
public Collection<T> getParticipants() {
|
||||
return this.voyagePlayers.values();
|
||||
}
|
||||
|
||||
public Collection<Player> getPlayerParticipants() {
|
||||
return this.voyagePlayers.values()
|
||||
.stream()
|
||||
.map(VoyagePlayer::getPlayer)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void clearParticipants() {
|
||||
this.voyagePlayers.clear();
|
||||
}
|
||||
|
||||
public boolean isParticipant(Player player) {
|
||||
return this.voyagePlayers.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public T getParticipant(Player player) {
|
||||
return this.voyagePlayers.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void sendMessageToAllParticipants(String message) {
|
||||
this.getVoyagePlayers().forEach((uuid, player) -> player.sendMessage(CC.translate(message)));
|
||||
}
|
||||
|
||||
public void sendTitleToAllParticipants(String title, String subtitle) {
|
||||
this.getVoyagePlayers().forEach((uuid, player) -> TitleUtils.sendTitle(player.getPlayer(), CC.translate(title), CC.translate(subtitle), 1, 3, 1));
|
||||
}
|
||||
|
||||
//TODO: pretty shit name for this, I might wanna rename this
|
||||
private boolean isValidParticipant(Player player) {
|
||||
return this.isParticipant(player);
|
||||
}
|
||||
|
||||
private boolean isValidParticipant(Entity entity) {
|
||||
if (!(entity instanceof Player)) return false;
|
||||
return this.isValidParticipant((Player) entity);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
if (!this.isParticipant(event.getPlayer())) return;
|
||||
this.kickFromVoyageRoom(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPickUpWhileInGame(PlayerPickupItemEvent event) {
|
||||
if (!this.isValidParticipant(event.getPlayer())) return;
|
||||
if (this.roomOptions.isItemPickUp()) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlaceWhileInGame(BlockPlaceEvent event) {
|
||||
if (!this.isValidParticipant(event.getPlayer())) return;
|
||||
if (this.roomOptions.isBlockPlace()) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreakWhileInGame(BlockBreakEvent event) {
|
||||
if (!this.isValidParticipant(event.getPlayer())) return;
|
||||
if (this.roomOptions.isBlockBreak()) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPickUpWhileInGame(PlayerDropItemEvent event) {
|
||||
if (!this.isValidParticipant(event.getPlayer())) return;
|
||||
if (this.roomOptions.isItemDrop()) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFallDamageToPlayerWhileInGame(EntityDamageEvent event) {
|
||||
if (!this.isValidParticipant(event.getEntity())) return;
|
||||
if (this.roomOptions.isFallDamage()) return;
|
||||
if (event.getCause() != EntityDamageEvent.DamageCause.FALL) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryInteract(InventoryClickEvent event) {
|
||||
if (!this.isValidParticipant(event.getWhoClicked())) return;
|
||||
if (this.roomOptions.isInventoryInteract()) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageByEntityEvent event) {
|
||||
if (!this.isValidParticipant(event.getEntity())) return;
|
||||
if (this.roomOptions.isPvp()) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onCommandWhileInGame(PlayerCommandPreprocessEvent event) {
|
||||
if (!this.isValidParticipant(event.getPlayer())) return;
|
||||
|
||||
if (!this.roomOptions.isBlockCommands()) return;
|
||||
|
||||
String command = event.getMessage().replace("/", "").toLowerCase(Locale.ROOT);
|
||||
|
||||
if (Arrays.stream(this.roomOptions.getExcludedBlockedCommands()).noneMatch(command::startsWith))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public Room getID() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package net.crankedpvp.voyages.struct.voyage;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.utils.serializer.location.LocationSerializerDeserializer;
|
||||
import net.crankedpvp.voyages.VoyagePlugin;
|
||||
import net.crankedpvp.voyages.struct.config.ConfigManager;
|
||||
import net.crankedpvp.voyages.struct.portal.Portal;
|
||||
import net.crankedpvp.voyages.struct.room.VoyageRoom;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Voyage {
|
||||
|
||||
public static int MAX_AMOUNT_OF_PARTICIPANTS = 8;
|
||||
|
||||
@Getter
|
||||
private final Portal portal;
|
||||
private final List<Player> participants;
|
||||
private int amountOfRoomsFinished;
|
||||
|
||||
public Voyage(Location portalLocation) {
|
||||
this.portal = new Portal(portalLocation);
|
||||
this.participants = new ArrayList<>(MAX_AMOUNT_OF_PARTICIPANTS);
|
||||
this.amountOfRoomsFinished = 0;
|
||||
}
|
||||
|
||||
public void endVoyage() {
|
||||
|
||||
}
|
||||
|
||||
public void leaveVoyage(Player player) {
|
||||
this.participants.remove(player);
|
||||
player.teleport(Bukkit.getWorld("world").getSpawnLocation());
|
||||
player.teleport(Bukkit.getWorld("world").getSpawnLocation());
|
||||
player.getInventory().clear();
|
||||
player.getInventory().setArmorContents(new ItemStack[]{});
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
public List<ItemStack> getLoot() {
|
||||
return VoyagePlugin.getInstance().getVoyageLootManager().getLootAsItemsFromTier(this.amountOfRoomsFinished);
|
||||
}
|
||||
|
||||
public void addParticipant(Player player) {
|
||||
if (this.participants.size() == MAX_AMOUNT_OF_PARTICIPANTS) return;
|
||||
this.participants.add(player);
|
||||
}
|
||||
|
||||
public int getAmountOfParticipants() {
|
||||
return this.participants.size();
|
||||
}
|
||||
|
||||
public boolean isAlreadyParticipant(Player player) {
|
||||
return this.participants.contains(player);
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return this.participants.size() >= MAX_AMOUNT_OF_PARTICIPANTS;
|
||||
}
|
||||
|
||||
public void startVoyageRoom() {
|
||||
VoyageRoom<?> voyageRoom = this.getRandomRoom();
|
||||
|
||||
assert voyageRoom != null;
|
||||
voyageRoom.setVoyage(this);
|
||||
voyageRoom.addPlayersToVoyageParticipants(this.participants);
|
||||
voyageRoom.startCountdown();
|
||||
}
|
||||
|
||||
public void warpPlayerToWaitingRoom(Player player) {
|
||||
String waitingRoomLocationString = VoyagePlugin.getInstance().getConfigManager().getConfig(ConfigManager.ConfigFile.SETTINGS).getString("settings.waiting-room-location");
|
||||
Location location = LocationSerializerDeserializer.deserialize(waitingRoomLocationString);
|
||||
|
||||
player.teleport(location);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private VoyageRoom<?> getRandomRoom() {
|
||||
// if (this.availableRoms.isEmpty()) {
|
||||
// //this.populateAvailableRoomsList();
|
||||
// }
|
||||
//
|
||||
// List<VoyageRoom<?>> rooms = new ArrayList<>(this.availableRoms);
|
||||
//
|
||||
// System.out.println("all rooms: " + rooms);
|
||||
//
|
||||
//
|
||||
// rooms = rooms.stream()
|
||||
// .filter(VoyageRoom::isAvailable)
|
||||
// .collect(Collectors.toList());
|
||||
//
|
||||
// System.out.println("available rooms: " + rooms);
|
||||
//
|
||||
// if (rooms.isEmpty()) {
|
||||
// System.out.println("no rooms");
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// Random rand = new Random();
|
||||
// VoyageRoom<?> voyageRoom = rooms.get(rand.nextInt(rooms.size()));
|
||||
// this.availableRoms.remove(voyageRoom);
|
||||
//
|
||||
// System.out.println("room: " + voyageRoom.getName());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void incrementAmountOfRoomsCompleted() {
|
||||
this.amountOfRoomsFinished++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.crankedpvp.voyages.struct.voyage;
|
||||
|
||||
import net.crankedpvp.loottable.LootTableAPI;
|
||||
import net.crankedpvp.loottable.struct.LootTableType;
|
||||
import net.crankedpvp.voyages.VoyagePlugin;
|
||||
import net.crankedpvp.voyages.struct.config.ConfigManager;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VoyageLootManager {
|
||||
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public VoyageLootManager(VoyagePlugin plugin) {
|
||||
this.configManager = plugin.getConfigManager();
|
||||
}
|
||||
|
||||
public LootTableType getLootFromTier(final int numberOfCompletedRooms) {
|
||||
List<LootTableType> loot = new ArrayList<>();
|
||||
List<String> lootAsString = this.configManager.getConfig(ConfigManager.ConfigFile.SETTINGS).getStringList("settings.loot");
|
||||
|
||||
for (String s : lootAsString) {
|
||||
loot.add(LootTableType.valueOf(s));
|
||||
}
|
||||
|
||||
return loot.get(numberOfCompletedRooms - 1);
|
||||
}
|
||||
|
||||
public List<ItemStack> getLootAsItemsFromTier(final int numberOfCompletedRooms) {
|
||||
LootTableType lootTableType = this.getLootFromTier(numberOfCompletedRooms);
|
||||
List<ItemStack> loot = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
loot.add(LootTableAPI.getRandomLootItem(lootTableType));
|
||||
}
|
||||
|
||||
return loot;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.crankedpvp.voyages.struct.voyage;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.crankedpvp.voyages.VoyagePlugin;
|
||||
import net.crankedpvp.voyages.tasks.SpawnPortalTask;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VoyageManager {
|
||||
|
||||
private final List<Voyage> activeVoyages;
|
||||
private final VoyagePlugin plugin;
|
||||
|
||||
public VoyageManager(VoyagePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.activeVoyages = new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean isThereSpaceForPortal(Location location) {
|
||||
return true; //TODO: this needs to be done
|
||||
}
|
||||
|
||||
public ImmutableList<Voyage> getActiveVoyages() {
|
||||
return ImmutableList.copyOf(this.activeVoyages).asList();
|
||||
}
|
||||
|
||||
public void summonPortal(Location location) {
|
||||
Voyage voyage = new Voyage(location);
|
||||
SpawnPortalTask spawnPortalTask = new SpawnPortalTask(location, voyage);
|
||||
spawnPortalTask.runTaskTimer(this.plugin, 10, 10);
|
||||
this.activeVoyages.add(voyage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package net.crankedpvp.voyages.tasks;
|
||||
|
||||
import net.crankedpvp.voyages.VoyagePlugin;
|
||||
import net.crankedpvp.voyages.struct.voyage.Voyage;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import xyz.xenondevs.particle.ParticleBuilder;
|
||||
import xyz.xenondevs.particle.ParticleEffect;
|
||||
|
||||
public class SpawnPortalTask extends BukkitRunnable {
|
||||
|
||||
private final Location location;
|
||||
private final Voyage voyage;
|
||||
private boolean finishedPlacingEndPortal;
|
||||
private boolean finishedPlacingEndPortalFrame;
|
||||
private final ParticleBuilder particleBuilder;
|
||||
private final ParticleBuilder finalParticleBuilder;
|
||||
|
||||
private int i;
|
||||
private int y;
|
||||
|
||||
public SpawnPortalTask(Location location, Voyage voyage) {
|
||||
this.location = location;
|
||||
this.voyage = voyage;
|
||||
this.finishedPlacingEndPortal = false;
|
||||
this.finishedPlacingEndPortalFrame = false;
|
||||
this.i = -1;
|
||||
this.y = -1;
|
||||
this.particleBuilder = new ParticleBuilder(ParticleEffect.SPELL_WITCH);
|
||||
this.finalParticleBuilder = new ParticleBuilder(ParticleEffect.FIREWORKS_SPARK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (finishedPlacingEndPortal && finishedPlacingEndPortalFrame) {
|
||||
UpdatePortalTask updatePortalTask = new UpdatePortalTask(this.voyage);
|
||||
updatePortalTask.runTaskTimer(VoyagePlugin.getInstance(), 0L, 20L);
|
||||
this.location.getWorld().playSound(this.location, Sound.PORTAL_TRAVEL, 0.5f, 0.5f);
|
||||
this.finalParticleBuilder.setAmount(100).setSpeed(0.1f).setLocation(this.location.clone().add(0.5, 1, 0.5)).display();
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!finishedPlacingEndPortalFrame) {
|
||||
this.placeEndPortalFrames();
|
||||
return;
|
||||
}
|
||||
|
||||
this.placeEndPortalBlock();
|
||||
}
|
||||
|
||||
public void placeEndPortalBlock() {
|
||||
Location blockSpawnLocation = new Location(this.location.getWorld(), location.getBlockX() + i, location.getBlockY(), location.getBlockZ() + y);
|
||||
blockSpawnLocation.getBlock().setType(Material.ENDER_PORTAL);
|
||||
this.location.getWorld().playSound(blockSpawnLocation, Sound.ENDERMAN_TELEPORT, 1.0f, 1.0f);
|
||||
this.particleBuilder.setAmount(100).setSpeed(0.1f).setLocation(blockSpawnLocation.add(0.5, 1, 0.5)).display();
|
||||
|
||||
if (i == 1 && y == 1) {
|
||||
this.finishedPlacingEndPortal = true;
|
||||
}
|
||||
|
||||
if (i == 1) {
|
||||
this.y++;
|
||||
this.i = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
this.i++;
|
||||
}
|
||||
|
||||
public void placeEndPortalFrames() {
|
||||
this.createSquareWithoutCorners();
|
||||
|
||||
this.finishedPlacingEndPortalFrame = true;
|
||||
}
|
||||
|
||||
public void createSquareWithoutCorners() {
|
||||
new Location(location.getWorld(), location.getX() + 2, location.getY(), location.getZ() + 1).getBlock().setType(Material.ENDER_PORTAL_FRAME);
|
||||
new Location(location.getWorld(), location.getX() + 2, location.getY(), location.getZ()).getBlock().setType(Material.ENDER_PORTAL_FRAME);
|
||||
new Location(location.getWorld(), location.getX() + 2, location.getY(), location.getZ() - 1).getBlock().setType(Material.ENDER_PORTAL_FRAME);
|
||||
|
||||
new Location(location.getWorld(), location.getX() - 2, location.getY(), location.getZ() + 1).getBlock().setType(Material.ENDER_PORTAL_FRAME);
|
||||
new Location(location.getWorld(), location.getX() - 2, location.getY(), location.getZ()).getBlock().setType(Material.ENDER_PORTAL_FRAME);
|
||||
new Location(location.getWorld(), location.getX() - 2, location.getY(), location.getZ() - 1).getBlock().setType(Material.ENDER_PORTAL_FRAME);
|
||||
|
||||
new Location(location.getWorld(), location.getX() + 1, location.getY(), location.getZ() + 2).getBlock().setType(Material.ENDER_PORTAL_FRAME);
|
||||
new Location(location.getWorld(), location.getX(), location.getY(), location.getZ() + 2).getBlock().setType(Material.ENDER_PORTAL_FRAME);
|
||||
new Location(location.getWorld(), location.getX() - 1, location.getY(), location.getZ() + 2).getBlock().setType(Material.ENDER_PORTAL_FRAME);
|
||||
|
||||
new Location(location.getWorld(), location.getX() + 1, location.getY(), location.getZ() - 2).getBlock().setType(Material.ENDER_PORTAL_FRAME);
|
||||
new Location(location.getWorld(), location.getX(), location.getY(), location.getZ() - 2).getBlock().setType(Material.ENDER_PORTAL_FRAME);
|
||||
new Location(location.getWorld(), location.getX() - 1, location.getY(), location.getZ() - 2).getBlock().setType(Material.ENDER_PORTAL_FRAME);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.crankedpvp.voyages.tasks;
|
||||
|
||||
import net.crankedpvp.voyages.struct.portal.Portal;
|
||||
import net.crankedpvp.voyages.struct.voyage.Voyage;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class UpdatePortalTask extends BukkitRunnable {
|
||||
|
||||
private final Voyage voyage;
|
||||
private final Portal portal;
|
||||
|
||||
public UpdatePortalTask(Voyage voyage) {
|
||||
this.voyage = voyage;
|
||||
this.portal = this.voyage.getPortal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.portal.getTimeUtilPortalCloses() <= 0) {
|
||||
this.portal.delete();
|
||||
this.voyage.startVoyageRoom();
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
this.portal.updateHologram(this.voyage.getAmountOfParticipants());
|
||||
this.portal.decrementTimeBeforePortalCloses();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.crankedpvp.voyages.tasks;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.TitleUtils;
|
||||
import net.crankedpvp.voyages.struct.player.VoyagePlayer;
|
||||
import net.crankedpvp.voyages.struct.room.VoyageRoom;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class VoyageRoomCountdownTask extends BukkitRunnable {
|
||||
|
||||
private static final List<Integer> WHEN_TO_DISPLAY_TITLE = Arrays.asList(15, 10, 5, 4, 3, 2, 1);
|
||||
private static final int COUNTDOWN_TIME = 15;
|
||||
|
||||
private final VoyageRoom<?> voyageRoom;
|
||||
private int timeLeft;
|
||||
|
||||
public VoyageRoomCountdownTask(VoyageRoom<?> voyageRoom) {
|
||||
this.voyageRoom = voyageRoom;
|
||||
this.timeLeft = COUNTDOWN_TIME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.timeLeft <= 0) {
|
||||
this.cancel();
|
||||
this.voyageRoom.finishCountdown();
|
||||
return;
|
||||
}
|
||||
|
||||
if (WHEN_TO_DISPLAY_TITLE.contains(this.timeLeft)) {
|
||||
this.voyageRoom.sendTitleToAllParticipants(CC.translate("&c&l" + this.voyageRoom.getName() + " Room"), CC.translate("&7Starting in &n" + this.timeLeft + "&r &7seconds"));
|
||||
}
|
||||
|
||||
this.timeLeft--;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package net.crankedpvp.voyages.tasks;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.TimeUtils;
|
||||
import net.crankedpvp.voyages.struct.room.VoyageRoom;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class VoyageRoomTimeLeftTask extends BukkitRunnable {
|
||||
|
||||
private static final List<Integer> WHEN_TO_DISPLAY_TITLE = Arrays.asList(300, 120, 60, 30, 15, 10, 5, 4, 3, 2, 1);
|
||||
private final VoyageRoom<?> voyageRoom;
|
||||
private int timeLeft;
|
||||
|
||||
public VoyageRoomTimeLeftTask(VoyageRoom<?> voyageRoom) {
|
||||
this.timeLeft = voyageRoom.getDurationOfRoomInSeconds();
|
||||
this.voyageRoom = voyageRoom;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
if (timeLeft == 0) {
|
||||
this.voyageRoom.stopVoyageRoom();
|
||||
this.voyageRoom.nextRoom();
|
||||
return;
|
||||
}
|
||||
|
||||
if (WHEN_TO_DISPLAY_TITLE.contains(timeLeft))
|
||||
this.voyageRoom.sendMessageToAllParticipants("&a&lVoyages &8➥ &7" + TimeUtils.formatSeconds(this.timeLeft) + " left before the end of this room.");
|
||||
|
||||
this.decrementTimeLeft();
|
||||
}
|
||||
|
||||
public void decrementTimeLeft() {
|
||||
this.timeLeft--;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.crankedpvp.voyages.utils;
|
||||
|
||||
public class NbtTags {
|
||||
|
||||
public static final String DATA_STRING = "cosmicData";
|
||||
public static final String VOYAGE_PORTAL_SUMMONER_STRING = "voyagePortalSummoner";
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.crankedpvp.voyages.utils;
|
||||
|
||||
import de.tr7zw.nbtapi.NBTItem;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemUtils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import static net.crankedpvp.voyages.struct.items.PortalSummoner.VOYAGE_PORTAL_SUMMONER_MATERIAL;
|
||||
import static net.crankedpvp.voyages.utils.NbtTags.DATA_STRING;
|
||||
import static net.crankedpvp.voyages.utils.NbtTags.VOYAGE_PORTAL_SUMMONER_STRING;
|
||||
|
||||
public class VoyageUtils {
|
||||
|
||||
public static boolean isVoyageSummoner(ItemStack itemStack) {
|
||||
if (ItemUtils.isAirOrNull(itemStack)) return false;
|
||||
if (itemStack.getType() != VOYAGE_PORTAL_SUMMONER_MATERIAL) return false;
|
||||
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
|
||||
if (!nbtItem.hasKey(DATA_STRING)) return false;
|
||||
return nbtItem.getString(DATA_STRING).equals(VOYAGE_PORTAL_SUMMONER_STRING);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
name: CrankedVoyages
|
||||
main: net.crankedpvp.voyages.VoyagePlugin
|
||||
version: ${git.total.commit.count}.0
|
||||
description: "§fCommit ID: §a${git.commit.id.abbrev}"
|
||||
website: https://crankedpvp.net/
|
||||
depend:
|
||||
- CrankedUtils
|
||||
@@ -0,0 +1,9 @@
|
||||
settings:
|
||||
waiting-room-location: "world:0:100:0"
|
||||
loot:
|
||||
- "VOYAGE_TIER_1"
|
||||
- "VOYAGE_TIER_2"
|
||||
- "VOYAGE_TIER_3"
|
||||
- "VOYAGE_TIER_4"
|
||||
- "VOYAGE_TIER_5"
|
||||
- "VOYAGE_TIER_6"
|
||||
Reference in New Issue
Block a user