Initial commit
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package net.crankedpvp.envoys;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
|
||||
import lombok.Getter;
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import net.crankedpvp.crankedutils.utils.serializer.location.LocationSerializerDeserializer;
|
||||
import net.crankedpvp.envoys.commands.AdminEnvoyCommand;
|
||||
import net.crankedpvp.envoys.commands.EnvoyCommand;
|
||||
import net.crankedpvp.envoys.language.LanguageHandler;
|
||||
import net.crankedpvp.envoys.listeners.AddCrateLocationListener;
|
||||
import net.crankedpvp.envoys.listeners.EnvoySummonerListener;
|
||||
import net.crankedpvp.envoys.listeners.OpenEnvoyCrateListener;
|
||||
import net.crankedpvp.envoys.struct.EnvoyManager;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class EnvoyPlugin extends JavaPlugin {
|
||||
|
||||
@Getter
|
||||
private static EnvoyPlugin instance;
|
||||
|
||||
@Getter
|
||||
private EnvoyManager envoyManager;
|
||||
|
||||
@Getter
|
||||
private CommandManager commandManager;
|
||||
|
||||
@Getter
|
||||
private LanguageHandler languageHandler;
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
this.languageHandler = new LanguageHandler(this);
|
||||
this.languageHandler.load();
|
||||
this.registerListeners(this.getServer().getPluginManager());
|
||||
this.commandManager = new CommandManager(this);
|
||||
this.commandManager.register(new EnvoyCommand(this));
|
||||
this.commandManager.register(new AdminEnvoyCommand(this));
|
||||
this.envoyManager = new EnvoyManager(this);
|
||||
this.registerLocationsFromConfig();
|
||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
||||
this.envoyManager.startEnvoyEvent();
|
||||
}, 20L * 60L * 30L, 20L * 60L * 20L);
|
||||
HologramsAPI.registerPlaceholder(EnvoyPlugin.getInstance(), "{envoy_time}", 1, this.getEnvoyManager());
|
||||
|
||||
}
|
||||
|
||||
private void registerListeners(PluginManager pluginManager) {
|
||||
pluginManager.registerEvents(new AddCrateLocationListener(this), this);
|
||||
pluginManager.registerEvents(new OpenEnvoyCrateListener(this), this);
|
||||
pluginManager.registerEvents(new EnvoySummonerListener(this), this);
|
||||
}
|
||||
|
||||
|
||||
private void registerLocationsFromConfig() {
|
||||
FileConfiguration yamlConfiguration = this.getConfig();
|
||||
if (yamlConfiguration.contains("locations")) {
|
||||
for (String string : yamlConfiguration.getStringList("locations")) {
|
||||
this.envoyManager.getLocations().add(LocationSerializerDeserializer.deserialize(string));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.envoyManager.handleCrateRemoving();
|
||||
this.envoyManager.setActive(false);
|
||||
this.envoyManager.setRemainingCrates(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package net.crankedpvp.envoys.commands;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.Hologram;
|
||||
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
|
||||
import com.gmail.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer;
|
||||
import me.mattstudios.mf.annotations.*;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.CustomItemUtils;
|
||||
import net.crankedpvp.crankedutils.utils.PlayerUtils;
|
||||
import net.crankedpvp.crankedutils.utils.SoundUtils;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import net.crankedpvp.envoys.EnvoyPlugin;
|
||||
import net.crankedpvp.envoys.language.Language;
|
||||
import net.crankedpvp.envoys.struct.EnvoyManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Command("aenvoy")
|
||||
public class AdminEnvoyCommand extends CommandBase {
|
||||
|
||||
private final EnvoyPlugin plugin;
|
||||
public AdminEnvoyCommand(EnvoyPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Default
|
||||
@Permission("cranked.admin")
|
||||
public void defaultCommand(CommandSender commandSender) {
|
||||
sendHelpMessage(commandSender);
|
||||
}
|
||||
|
||||
@SubCommand("setup")
|
||||
@Permission("cranked.admin")
|
||||
public void setupCommand(final CommandSender commandSender) {
|
||||
if(!(commandSender instanceof Player)) {
|
||||
commandSender.sendMessage(CC.translate("&cYou must be a player to execute this command"));
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = ((Player) commandSender);
|
||||
final ItemBuilder itemBuilder = new ItemBuilder(Material.CHEST, "&b&lEnvoy Setup Chest",
|
||||
"&7Place this down to set the blocks placed",
|
||||
"&7location to a envoy location");
|
||||
player.getInventory().addItem(CustomItemUtils.setCrankedCustomItem(itemBuilder.colorize().build(), "envoySetupChest"));
|
||||
player.sendMessage(CC.translate("&aYou have been given a crate to edit crate locations"));
|
||||
}
|
||||
|
||||
@SubCommand("reload")
|
||||
@WrongUsage("&cUsage: /aenvoy reload")
|
||||
@Permission("cranked.admin")
|
||||
public void reloadCommand(Player sender) {
|
||||
Language.ADMIN_RELOADING.send(sender);
|
||||
long then = System.currentTimeMillis();
|
||||
|
||||
EnvoyPlugin.getInstance().getLanguageHandler().load();
|
||||
|
||||
long diff = System.currentTimeMillis() - then;
|
||||
Language.ADMIN_RELOADED.send(sender, str -> str.replace("%took%", String.valueOf(diff)));
|
||||
}
|
||||
|
||||
@SubCommand("summoner")
|
||||
@Permission("cranked.admin")
|
||||
public void summonerCommand(final CommandSender commandSender, @Optional @Completion("#players") Player player) {
|
||||
if(player == null) player = (Player)commandSender;
|
||||
ItemBuilder itemBuilder = new ItemBuilder(Material.TORCH, "&f&ki&r&e✦&f&ki&r &6&lEnvoy Summoner &f&ki&e✦&f&ki&r",
|
||||
"&7Right-Click this summoner to",
|
||||
"&7forcefully begin a envoy event",
|
||||
"",
|
||||
"&7The event will not start if",
|
||||
"&7another envoy event is ongoing");
|
||||
itemBuilder.setGlowing();
|
||||
PlayerUtils.giveOrDropProtectedItem(player, CustomItemUtils.setCrankedCustomItem(itemBuilder.colorize().build(), "envoySummoner"), 15);
|
||||
}
|
||||
|
||||
@SubCommand("forcestart")
|
||||
@Permission("cranked.admin")
|
||||
public void forceStartCommand(final CommandSender commandSender) {
|
||||
if(this.plugin.getEnvoyManager().isActive()) {
|
||||
commandSender.sendMessage(CC.translate(EnvoyManager.prefix + "&cThere is already an active envoy event"));
|
||||
SoundUtils.tryPlayErrorSound(commandSender);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
this.plugin.getServer().getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(Objects::nonNull) //TODO filter people with envoy messages enabled
|
||||
.forEach(player -> player.sendMessage(CC.translate(EnvoyManager.prefix + "&aAn envoy event has just started")));
|
||||
|
||||
*/
|
||||
this.plugin.getEnvoyManager().startEnvoyEvent();
|
||||
}
|
||||
|
||||
@SubCommand("forceend")
|
||||
@Permission("cranked.admin")
|
||||
public void forceEndCommand(final CommandSender commandSender) {
|
||||
if(!this.plugin.getEnvoyManager().isActive()) {
|
||||
commandSender.sendMessage(CC.translate(EnvoyManager.prefix + "&cThere is no ongoing envoy event"));
|
||||
SoundUtils.tryPlayErrorSound(commandSender);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
this.plugin.getServer().getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(Objects::nonNull) //TODO filter people with envoy messages enabled
|
||||
.forEach(player -> player.sendMessage(CC.translate(EnvoyManager.prefix + "&cThe envoy event has ended")));
|
||||
|
||||
*/
|
||||
this.plugin.getEnvoyManager().endEnvoyEvent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void sendHelpMessage(CommandSender commandSender) {
|
||||
commandSender.sendMessage("/aenvoy forceend");
|
||||
commandSender.sendMessage("/aenvoy forcestart");
|
||||
commandSender.sendMessage("/aenvoy setup");
|
||||
commandSender.sendMessage("/aenvoy summoner");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.crankedpvp.envoys.commands;
|
||||
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.envoys.EnvoyPlugin;
|
||||
import net.crankedpvp.envoys.inventory.EnvoyInventory;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import static net.crankedpvp.envoys.struct.EnvoyManager.prefix;
|
||||
|
||||
@Command("envoy")
|
||||
public class EnvoyCommand extends CommandBase {
|
||||
|
||||
private final EnvoyPlugin plugin;
|
||||
public EnvoyCommand(EnvoyPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void defaultCommand(final CommandSender commandSender) {
|
||||
if(commandSender instanceof Player) {
|
||||
final Player player = (Player)commandSender;
|
||||
final EnvoyInventory envoyInventory = new EnvoyInventory();
|
||||
envoyInventory.getUI().open(player);
|
||||
player.playSound(player.getLocation(), Sound.CHEST_OPEN, 2.0F, 2.0F);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand("time")
|
||||
public void timeCommand(final CommandSender commandSender) {
|
||||
commandSender.sendMessage(CC.translate(prefix + "&7The next envoy is in &f" + plugin.getEnvoyManager().formatedTimeUntilNextEnvoy() + "&7."));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package net.crankedpvp.envoys.inventory;
|
||||
|
||||
import dev.triumphteam.gui.components.GuiType;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import net.crankedpvp.envoys.EnvoyPlugin;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class EnvoyInventory {
|
||||
private final Gui envoyInventory;
|
||||
|
||||
public Gui getUI() {
|
||||
return this.envoyInventory;
|
||||
}
|
||||
|
||||
public EnvoyInventory() {
|
||||
this.envoyInventory = new Gui(GuiType.HOPPER, "Cranked Envoys");
|
||||
this.envoyInventory.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
this.envoyInventory.setItem(1, new GuiItem(createInformationItem()));
|
||||
this.envoyInventory.setItem(3, new GuiItem(createPreviewLootItem(), event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
LootPreviewInventory lootPreviewInventory = new LootPreviewInventory();
|
||||
lootPreviewInventory.getUI().open(event.getWhoClicked());
|
||||
}));
|
||||
//this.envoyInventory.setItem(Arrays.asList(0, 4), new GuiItem(createExitItem(), event -> event.getWhoClicked().closeInventory()));
|
||||
this.envoyInventory.setItem(Arrays.asList(2, 0, 4), new GuiItem(createFillerItem()));
|
||||
|
||||
}
|
||||
|
||||
private ItemStack createPreviewLootItem() {
|
||||
final ItemBuilder itemBuilder = new ItemBuilder(Material.CHEST, "&c&lEnvoy Loot");
|
||||
itemBuilder.setLore(Arrays.asList("&7Click to view the contents of",
|
||||
"&7the envoy event rewards"));
|
||||
return itemBuilder.colorize().build();
|
||||
|
||||
}
|
||||
|
||||
private ItemStack createInformationItem() {
|
||||
final ItemBuilder itemBuilder = new ItemBuilder(Material.PAPER, "&e&lEnvoy Information");
|
||||
String active = EnvoyPlugin.getInstance().getEnvoyManager().isActive() ? "&a&lACTIVE" : "&c&lINACTIVE";
|
||||
itemBuilder.setLore(Arrays.asList(
|
||||
"&7Envoys are &fpassive &7events where",
|
||||
"&7players roam the &cwarzone &7to find",
|
||||
"&7and destroy &fcrates&7, which are filled",
|
||||
"&7with &euseful &7loot to begin your",
|
||||
"&7journey.",
|
||||
"",
|
||||
"&7While searching for &eenvoy &7crates,",
|
||||
"&7it is possible for you to be attacked",
|
||||
"&7by &cenemy &7players who are also searching",
|
||||
"&7for &eenvoy &7crates. Be aware, and &agood &7luck.",
|
||||
"",
|
||||
"&7Envoys occur every &f25-35 minutes",
|
||||
"",
|
||||
"&fEnvoy Status: " + active));
|
||||
return itemBuilder.colorize().build();
|
||||
}
|
||||
|
||||
private ItemStack createExitItem() {
|
||||
final ItemStack item = new ItemStack(Material.REDSTONE);
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(CC.translate("&cExit envoy inventory"));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
private ItemStack createFillerItem() {
|
||||
final ItemStack item = new ItemStack(Material.STAINED_GLASS_PANE, 1, DyeColor.GRAY.getWoolData());
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(CC.translate("&cCranked&fPvP"));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package net.crankedpvp.envoys.inventory;
|
||||
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import dev.triumphteam.gui.guis.PaginatedGui;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import net.crankedpvp.loottable.LootTableAPI;
|
||||
import net.crankedpvp.loottable.struct.LootTableType;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class LootPreviewInventory {
|
||||
|
||||
private final PaginatedGui envoyLootPreviewInventory;
|
||||
|
||||
public PaginatedGui getUI() {
|
||||
return this.envoyLootPreviewInventory;
|
||||
}
|
||||
|
||||
|
||||
public LootPreviewInventory() {
|
||||
|
||||
this.envoyLootPreviewInventory = new PaginatedGui(6, 28, "Envoy Loot");
|
||||
this.envoyLootPreviewInventory.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
this.envoyLootPreviewInventory.getFiller().fillBorder(new GuiItem(createFillerItem()));
|
||||
ItemStack prevPage = new ItemBuilder(Material.ARROW, "&c<- Previous Page", "&7Right-Click&7 to go to the previous page.").colorize().build();
|
||||
ItemStack nextPage = new ItemBuilder(Material.ARROW, "&aNext Page ->", "&7Right-Click&7 to go to the next page.").colorize().build();
|
||||
this.envoyLootPreviewInventory.setItem(6, 1, new GuiItem(prevPage, event -> {
|
||||
this.envoyLootPreviewInventory.previous();
|
||||
event.setCancelled(true);
|
||||
}));
|
||||
this.envoyLootPreviewInventory.setItem(6, 9, new GuiItem(nextPage, event -> {
|
||||
this.envoyLootPreviewInventory.next();
|
||||
event.setCancelled(true);
|
||||
}));
|
||||
|
||||
|
||||
this.envoyLootPreviewInventory.updateItem(6, 5, new GuiItem(new ItemBuilder(Material.BED, "&cReturn to Slot Bot").colorize().build(), event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
EnvoyInventory envoyInventory = new EnvoyInventory();
|
||||
envoyInventory.getUI().open(event.getWhoClicked());
|
||||
}));
|
||||
|
||||
|
||||
LootTableAPI.getAllLootFromLootTable(LootTableType.ENVOY).stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(ItemStack::hasItemMeta)
|
||||
.forEach(itemStack -> this.envoyLootPreviewInventory.addItem(new GuiItem(itemStack, event -> {
|
||||
if(event.getWhoClicked().hasPermission("cranked.admin")) event.getWhoClicked().getInventory().addItem(itemStack);
|
||||
})));
|
||||
;
|
||||
}
|
||||
|
||||
private ItemStack createFillerItem() {
|
||||
ItemStack item = new ItemStack(Material.STAINED_GLASS_PANE, 1, DyeColor.GRAY.getData());
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(CC.translate("&cCranked&fPvP"));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package net.crankedpvp.envoys.language;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public enum Language {
|
||||
|
||||
ENVOY_STARTED,
|
||||
ADMIN_RELOADING,
|
||||
ADMIN_RELOADED,
|
||||
|
||||
|
||||
;
|
||||
|
||||
private String value;
|
||||
private ImmutableList<String> valueList;
|
||||
|
||||
public String getValue() {
|
||||
return this.value != null ? this.value : this.name();
|
||||
}
|
||||
|
||||
public String getValue(UnaryOperator<String> function) {
|
||||
return this.value != null ? function.apply(this.value) : this.name();
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
public List<String> getValuesAsList() {
|
||||
return this.valueList;
|
||||
}
|
||||
|
||||
public List<String> getValuesAsList(String oldString, String newString) {
|
||||
List<String> list = new ArrayList<>(this.valueList);
|
||||
list.replaceAll(s -> s.replace(oldString, newString));
|
||||
return list;
|
||||
}
|
||||
|
||||
void setValue(String value) {
|
||||
this.value = CC.translate(value);
|
||||
|
||||
List<String> tempList = Arrays.stream(StringUtils.split(value, System.lineSeparator()))
|
||||
.map(CC::translate)
|
||||
.collect(Collectors.toList());
|
||||
this.valueList = ImmutableList.copyOf(tempList);
|
||||
}
|
||||
|
||||
void setValue(List<String> valueList) {
|
||||
this.value = CC.translate(valueList.parallelStream().collect(Collectors.joining(System.lineSeparator())));
|
||||
|
||||
List<String> tempList = valueList.stream()
|
||||
.map(CC::translate)
|
||||
.collect(Collectors.toList());
|
||||
this.valueList = ImmutableList.copyOf(tempList);
|
||||
}
|
||||
|
||||
public void send(CommandSender sender, UnaryOperator<String> function) {
|
||||
sender.sendMessage(CC.translate(this.getValue(function)));
|
||||
}
|
||||
|
||||
public void send(CommandSender sender) {
|
||||
sender.sendMessage(CC.translate(this.getValue()));
|
||||
}
|
||||
|
||||
|
||||
public void send(List<CommandSender> senders, UnaryOperator<String> function) {
|
||||
String msg = CC.translate(this.getValue(function));
|
||||
senders.forEach(sender -> sender.sendMessage(msg));
|
||||
}
|
||||
|
||||
public void sendPlayers(List<Player> senders, UnaryOperator<String> function) {
|
||||
String msg = CC.translate(this.getValue(function));
|
||||
senders.forEach(sender -> sender.sendMessage(msg));
|
||||
}
|
||||
|
||||
public void send(CommandSender ...senders) {
|
||||
String msg = CC.translate(this.getValue());
|
||||
Arrays.asList(senders).forEach(sender -> sender.sendMessage(msg));
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return CC.translate(this.getValue());
|
||||
}
|
||||
|
||||
public String getMessage(UnaryOperator<String> function) {
|
||||
return CC.translate(this.getValue(function));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package net.crankedpvp.envoys.language;
|
||||
|
||||
import net.crankedpvp.envoys.EnvoyPlugin;
|
||||
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.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public final class LanguageHandler {
|
||||
|
||||
private final File file;
|
||||
private final FileConfiguration config;
|
||||
private final String path;
|
||||
private final EnvoyPlugin plugin;
|
||||
|
||||
public LanguageHandler(EnvoyPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.path = "language.yml";
|
||||
file = new File(plugin.getDataFolder(), path);
|
||||
config = new YamlConfiguration();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
this.saveDefaultConfig();
|
||||
|
||||
this.loadConfigFromDisk();
|
||||
this.copyDefaults();
|
||||
this.save();
|
||||
|
||||
this.loadConfigFromDisk();
|
||||
|
||||
this.loadLangMessages();
|
||||
}
|
||||
|
||||
private void loadLangMessages() {
|
||||
for (Language entry : Language.values()) {
|
||||
String path = entry.getPath();
|
||||
if (config.isList(path)) {
|
||||
entry.setValue(config.getStringList(path));
|
||||
continue;
|
||||
}
|
||||
entry.setValue(config.getString(path));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfigFromDisk() {
|
||||
try {
|
||||
config.load(file);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Could not save config file for " + file.getPath() + "!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void copyDefaults() {
|
||||
InputStream defConfig = plugin.getResource(this.path);
|
||||
if (defConfig != null) {
|
||||
config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfig)));
|
||||
}
|
||||
config.options().copyDefaults(true);
|
||||
}
|
||||
|
||||
private void saveDefaultConfig() {
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
plugin.saveResource(file.getName(),false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.crankedpvp.envoys.listeners;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.CustomItemUtils;
|
||||
import net.crankedpvp.crankedutils.utils.serializer.location.LocationSerializerDeserializer;
|
||||
import net.crankedpvp.envoys.EnvoyPlugin;
|
||||
import net.crankedpvp.envoys.struct.EnvoyManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AddCrateLocationListener implements Listener {
|
||||
|
||||
private final EnvoyPlugin plugin;
|
||||
public AddCrateLocationListener(EnvoyPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void placeCrateEvent(final BlockPlaceEvent event) {
|
||||
if(event.getItemInHand() == null || event.getItemInHand().getType() != Material.CHEST) return;
|
||||
if(!CustomItemUtils.getCrankedCustomItem(event.getItemInHand()).equals("envoySetupChest")) return;
|
||||
event.setCancelled(true);
|
||||
Player player = event.getPlayer();
|
||||
Location location = event.getBlockPlaced().getLocation();
|
||||
this.plugin.getEnvoyManager().getLocations().add(location);
|
||||
player.sendMessage(CC.translate(EnvoyManager.prefix + "&aAdded crate location at: &7" + LocationSerializerDeserializer.serialize(location)));
|
||||
player.playSound(player.getLocation(), Sound.SUCCESSFUL_HIT, 2.0F, 2.0F);
|
||||
|
||||
|
||||
FileConfiguration yamlConfiguration = this.plugin.getConfig();
|
||||
List<String> serializedLocations = new ArrayList<>();
|
||||
String base64Location = LocationSerializerDeserializer.serialize(location);
|
||||
if(yamlConfiguration.contains("locations")) serializedLocations.addAll(yamlConfiguration.getStringList("locations"));
|
||||
serializedLocations.add(base64Location);
|
||||
yamlConfiguration.set("locations", serializedLocations);
|
||||
this.plugin.saveConfig();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.crankedpvp.envoys.listeners;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.CustomItemUtils;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemUtils;
|
||||
import net.crankedpvp.envoys.EnvoyPlugin;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EnvoySummonerListener implements Listener {
|
||||
|
||||
private final EnvoyPlugin plugin;
|
||||
public EnvoySummonerListener(EnvoyPlugin envoyPlugin) {
|
||||
this.plugin = envoyPlugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void useItem(PlayerInteractEvent event) {
|
||||
if(event.getPlayer() == null) return;
|
||||
if(event.getPlayer().getItemInHand() == null) return;
|
||||
ItemStack itemStack = event.getPlayer().getItemInHand();
|
||||
if(!CustomItemUtils.isCrankedCustomItem(itemStack)) return;
|
||||
if(!CustomItemUtils.getCrankedCustomItem(itemStack).equals("envoySummoner")) return;
|
||||
if(!this.plugin.getEnvoyManager().isActive() || this.plugin.getEnvoyManager().canSpawnEnvoy()) {
|
||||
event.getPlayer().setItemInHand(ItemUtils.decreaseItemStackAmountByOne(itemStack));
|
||||
this.plugin.getEnvoyManager().startEnvoyEvent();
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(CC.translate("&c&l(!) &cThere is already an active envoy event"));
|
||||
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package net.crankedpvp.envoys.listeners;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.PlayerUtils;
|
||||
import net.crankedpvp.envoys.EnvoyPlugin;
|
||||
import net.crankedpvp.leaderboards.LeaderboardsAPI;
|
||||
import net.crankedpvp.loottable.LootTableAPI;
|
||||
import net.crankedpvp.loottable.struct.LootTableType;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
public class OpenEnvoyCrateListener implements Listener {
|
||||
|
||||
private final EnvoyPlugin plugin;
|
||||
public OpenEnvoyCrateListener(EnvoyPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void openEnvoyCrate(PlayerInteractEvent event) {
|
||||
if(event.getAction() != Action.LEFT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
if(event.getClickedBlock().getType() != Material.CHEST) return;
|
||||
Location clickedBlockLocation = event.getClickedBlock().getLocation();
|
||||
if(!this.plugin.getEnvoyManager().isActive() || !this.plugin.getEnvoyManager().getCurrentChests().contains(clickedBlockLocation)) return;
|
||||
event.setCancelled(true);
|
||||
this.plugin.getEnvoyManager().removeCrateAt(clickedBlockLocation);
|
||||
this.plugin.getEnvoyManager().setRemainingCrates(this.plugin.getEnvoyManager().getRemainingCrates() - 1);
|
||||
Player player = event.getPlayer();
|
||||
player.playSound(player.getLocation(), Sound.FIZZ, 2.0F, 2.0F);
|
||||
LeaderboardsAPI.getPlayerStats(player.getUniqueId()).incrementEnvoysOpened();
|
||||
PlayerUtils.dropProtectedItem(player, clickedBlockLocation, LootTableAPI.getRandomLootItem(LootTableType.ENVOY), 15);
|
||||
PlayerUtils.dropProtectedItem(player, clickedBlockLocation, LootTableAPI.getRandomLootItem(LootTableType.ENVOY), 15);
|
||||
PlayerUtils.dropProtectedItem(player, clickedBlockLocation, LootTableAPI.getRandomLootItem(LootTableType.ENVOY), 15);
|
||||
if(this.plugin.getEnvoyManager().getRemainingCrates() <= 0) {
|
||||
this.plugin.getEnvoyManager().endEnvoyEvent();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package net.crankedpvp.envoys.struct;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.crankedpvp.crankedutils.utils.BlockUtil;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.TimeUtils;
|
||||
import net.crankedpvp.envoys.EnvoyPlugin;
|
||||
import net.crankedpvp.envoys.language.Language;
|
||||
import net.crankedpvp.envoys.tasks.FireworkTask;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EnvoyManager implements PlaceholderReplacer {
|
||||
|
||||
public static String prefix = "&d&lEnvoys &8➥ ";
|
||||
|
||||
private final EnvoyPlugin plugin;
|
||||
|
||||
@Getter
|
||||
private long lastEnvoyTime;
|
||||
|
||||
@Getter @Setter
|
||||
private int remainingCrates = 0;
|
||||
|
||||
@Getter @Setter
|
||||
private boolean active;
|
||||
|
||||
private FireworkTask fireworkTask;
|
||||
|
||||
@Getter @Setter
|
||||
private List<Location> locations = new ArrayList<>();
|
||||
|
||||
@Getter @Setter
|
||||
private List<Location> currentChests = new ArrayList<>();
|
||||
|
||||
public EnvoyManager(EnvoyPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.active = false;
|
||||
this.updateLastEnvoyTime();
|
||||
}
|
||||
|
||||
public void handleCrateSpawning() {
|
||||
List<Location> availableLocations = this.locations.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(location -> location.getWorld() != null)
|
||||
.map(location -> location.getBlock().getLocation())
|
||||
.filter(location -> location.getBlock().getType() == Material.AIR)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
this.currentChests.clear();
|
||||
this.remainingCrates = 0;
|
||||
int crates = Bukkit.getOnlinePlayers().size() > 15 ? Bukkit.getOnlinePlayers().size() / 3 : 7;
|
||||
int cratesToSpawn = Math.min(crates, availableLocations.size());
|
||||
for (int i = 0; i < cratesToSpawn; i++) {
|
||||
Location crateLocation = availableLocations.remove(ThreadLocalRandom.current().nextInt(availableLocations.size()));
|
||||
BlockUtil.setBlockFast(crateLocation.getBlock(), Material.CHEST.getId(), (byte) 0, false);
|
||||
this.currentChests.add(crateLocation);
|
||||
this.remainingCrates++;
|
||||
ArmorStand armorStand = (ArmorStand) crateLocation.getWorld().spawnEntity(crateLocation.clone().add(0.5D, 0.1D, 0.5D), EntityType.ARMOR_STAND);
|
||||
armorStand.setCustomName(CC.translate("&6✧ &e&lEnvoy Crate &6✧"));
|
||||
armorStand.setCustomNameVisible(true);
|
||||
armorStand.setGravity(false);
|
||||
armorStand.setVisible(false);
|
||||
armorStand.setSmall(true);
|
||||
Firework firework = crateLocation.getWorld().spawn(crateLocation.clone().add(0.5D, 0.0D, 0.5D), Firework.class);
|
||||
FireworkMeta fireworkMeta = firework.getFireworkMeta();
|
||||
fireworkMeta.addEffect(FireworkEffect.builder().withColor(Color.YELLOW).withFade(Color.WHITE)
|
||||
.with(FireworkEffect.Type.BALL_LARGE).flicker(true).withTrail().build());
|
||||
firework.setFireworkMeta(fireworkMeta);
|
||||
fireworkMeta.setPower(5);
|
||||
Bukkit.getScheduler().runTaskLater(EnvoyPlugin.getInstance(), firework::detonate, 20L);
|
||||
}
|
||||
if (this.remainingCrates == 0) return;
|
||||
this.fireworkTask = new FireworkTask();
|
||||
fireworkTask.runTaskTimer(plugin, 0, 5*20);
|
||||
}
|
||||
|
||||
public void handleCrateRemoving() {
|
||||
new ArrayList<>(this.currentChests).stream()
|
||||
.filter(location -> location.getBlock().getType() == Material.CHEST)
|
||||
.forEach(this::removeCrateAt);
|
||||
this.currentChests.clear();
|
||||
}
|
||||
|
||||
public void removeCrateAt(Location location) {
|
||||
//location.getBlock().setType(Material.AIR);
|
||||
BlockUtil.setAir(location.getBlock(), false);
|
||||
removeNearbyHologram(location);
|
||||
this.currentChests.remove(location);
|
||||
}
|
||||
|
||||
public void removeNearbyHologram(Location location) {
|
||||
for (Entity entity : location.getWorld().getNearbyEntities(location, 0.3D, 0.6D, 0.3D)) {
|
||||
if (!(entity instanceof ArmorStand))
|
||||
continue;
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public void endEnvoyEvent() {
|
||||
this.setActive(false);
|
||||
this.plugin.getServer().getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(Objects::nonNull) //TODO filter people with envoy messages enabled
|
||||
.forEach(player -> player.sendMessage(CC.translate(EnvoyManager.prefix + "&cThe previous envoy event has ended")));
|
||||
this.handleCrateRemoving();
|
||||
this.remainingCrates = 0;
|
||||
if (this.fireworkTask != null) {
|
||||
this.fireworkTask.cancel();
|
||||
this.fireworkTask = null;
|
||||
}
|
||||
//this.plugin.getServer().getScheduler().runTaskLater(this.plugin, this::startEnvoyEvent, 20L * 60 * ThreadLocalRandom.current().nextInt(25, 35));
|
||||
}
|
||||
|
||||
public void startEnvoyEvent() {
|
||||
if(this.isActive()) {
|
||||
System.out.println("[Envoy] Stopping previous envoy to start a new one");
|
||||
endEnvoyEvent();
|
||||
}
|
||||
|
||||
this.handleCrateSpawning();
|
||||
if (this.remainingCrates == 0) {
|
||||
this.plugin.getLogger().warning("Cannot start envoy: no configured crate locations are available in loaded worlds with air blocks");
|
||||
return;
|
||||
}
|
||||
this.updateLastEnvoyTime();
|
||||
this.setActive(true);
|
||||
this.plugin.getServer().getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(Objects::nonNull) //TODO filter people with envoy messages enabled
|
||||
.forEach(player -> sendEnvoyStartMessage(player, this.remainingCrates));
|
||||
}
|
||||
|
||||
private void sendEnvoyStartMessage(Player player, int chests) {
|
||||
for (String line : Language.ENVOY_STARTED.getValuesAsList()) {
|
||||
line = line.replace("{chests}", String.valueOf(chests));
|
||||
player.sendMessage(CC.translate(line));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canSpawnEnvoy() {
|
||||
return (this.getLastEnvoyTime() + (300 * 1000)) < System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public long secondsUntilNextEnvoy() {
|
||||
return (this.getLastEnvoyTime() + (1000 * 60 * 30) - System.currentTimeMillis()) / 1000;
|
||||
}
|
||||
|
||||
public String formatedTimeUntilNextEnvoy() {
|
||||
return TimeUtils.formatSeconds(this.secondsUntilNextEnvoy());
|
||||
}
|
||||
|
||||
public void updateLastEnvoyTime() {
|
||||
this.lastEnvoyTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String update() {
|
||||
return formatedTimeUntilNextEnvoy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.crankedpvp.envoys.tasks;
|
||||
|
||||
import net.crankedpvp.envoys.EnvoyPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FireworkTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < EnvoyPlugin.getInstance().getEnvoyManager().getCurrentChests().size(); i++) {
|
||||
|
||||
Location location = EnvoyPlugin.getInstance().getEnvoyManager().getCurrentChests().get(i);
|
||||
Firework firework = location.getWorld().spawn(location.clone().add(0.5D, 0.0D, 0.5D), Firework.class);
|
||||
FireworkMeta fireworkMeta = firework.getFireworkMeta();
|
||||
fireworkMeta.addEffect(FireworkEffect.builder().withColor(Color.YELLOW).withFade(Color.WHITE)
|
||||
.with(FireworkEffect.Type.BALL_LARGE).flicker(true).withTrail().build());
|
||||
firework.setFireworkMeta(fireworkMeta);
|
||||
fireworkMeta.setPower(5);
|
||||
Bukkit.getScheduler().runTaskLater(EnvoyPlugin.getInstance(), firework::detonate, 20L);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
ADMIN_RELOADING: "&a&lEnvoy &8➥ &7Reloading configs now..."
|
||||
ADMIN_RELOADED: "&a&lEnvoy &8➥ &7Reloaded configs and other cool stuff. Took &d%took%ms&7."
|
||||
ENVOY_STARTED:
|
||||
- ""
|
||||
- "&6&l*** &e&lAN ENVOY EVENT HAS JUST STARTED &6&l***"
|
||||
- "&7&o(( A total of &f&n{chests}&r &7&ohave been spawned around the /spawn warzone! ))"
|
||||
- ""
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
name: CrankedEnvoys
|
||||
main: net.crankedpvp.envoys.EnvoyPlugin
|
||||
version: ${git.total.commit.count}.0
|
||||
description: "§fCommit ID: §a${git.commit.id.abbrev}"
|
||||
website: https://crankedpvp.net/
|
||||
depend:
|
||||
- CrankedUtils
|
||||
|
||||
Reference in New Issue
Block a user