Initial commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>ProjectCranked</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Events</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>aikar</id>
|
||||
<url>https://repo.aikar.co/content/groups/aikar/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
|
||||
<artifactId>holographicdisplays-api</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.astropvp</groupId>
|
||||
<artifactId>FactionsKore</artifactId>
|
||||
<version>0.1</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/../.lib/FactionsKore-1.3.431.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>DeadMansChest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.massivecraft</groupId>
|
||||
<artifactId>Factions</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>PvPTop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Bosses</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>StorageUtilsShaded</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/../StorageUtils/target/StorageUtils-1.0-shaded.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,204 @@
|
||||
package net.crankedpvp.events;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import lombok.Getter;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import net.crankedpvp.events.commands.*;
|
||||
import net.crankedpvp.events.game.MiniGameManager;
|
||||
import net.crankedpvp.events.game.MiniGameRegister;
|
||||
import net.crankedpvp.events.inventories.CerberusInventory;
|
||||
import net.crankedpvp.events.inventories.CitadelInventory;
|
||||
import net.crankedpvp.events.inventories.EventsInventory;
|
||||
import net.crankedpvp.events.inventories.WarpKothInventory;
|
||||
import net.crankedpvp.events.listeners.CerberusDeathListener;
|
||||
import net.crankedpvp.events.listeners.KothStateChangeListener;
|
||||
import net.crankedpvp.events.listeners.PlayerDeathListener;
|
||||
import net.crankedpvp.events.listeners.PlayerTeleportListener;
|
||||
import net.crankedpvp.events.managers.CerberusManager;
|
||||
import net.crankedpvp.events.managers.CitadelManager;
|
||||
import net.crankedpvp.events.managers.WarpKothManager;
|
||||
import net.crankedpvp.events.tasks.UpdateNextCerberusTimerTask;
|
||||
import net.crankedpvp.events.tasks.UpdateNextCitadelTimerTask;
|
||||
import net.crankedpvp.events.tasks.UpdateNextWarpKothTimerTask;
|
||||
import net.crankedpvp.events.utils.configuration.ConfigManager;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@Getter
|
||||
public class EventsPlugin extends JavaPlugin {
|
||||
|
||||
public final static String WARP_KOTH_WORLD_NAME = "world_the_end";
|
||||
|
||||
@Getter
|
||||
private static EventsPlugin instance;
|
||||
|
||||
private ConfigManager configManager;
|
||||
private MiniGameRegister miniGameRegister;
|
||||
private MiniGameManager miniGameManager;
|
||||
private CommandManager commandManager;
|
||||
private List<CommandBase> commands;
|
||||
|
||||
private EventsInventory eventsInventory;
|
||||
|
||||
private WarpKothInventory warpKothInventory;
|
||||
private CitadelInventory citadelInventory;
|
||||
private CerberusInventory cerberusInventory;
|
||||
|
||||
private CitadelManager citadelManager;
|
||||
private WarpKothManager warpKothManager;
|
||||
private CerberusManager cerberusManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
saveDefaultConfig();
|
||||
|
||||
this.configManager = new ConfigManager(this);
|
||||
this.configManager.setupFiles();
|
||||
|
||||
this.miniGameRegister = new MiniGameRegister(this);
|
||||
this.miniGameRegister.initialize();
|
||||
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
this.miniGameManager = new MiniGameManager(this);
|
||||
// this.miniGameManager.startAutoMiniGameTask();
|
||||
|
||||
this.registerCommands();
|
||||
this.registerListeners();
|
||||
|
||||
this.setupSavagesEvents();
|
||||
|
||||
}
|
||||
|
||||
private void setupSavagesEvents() {
|
||||
|
||||
this.citadelManager = new CitadelManager(this);
|
||||
this.warpKothManager = new WarpKothManager(this);
|
||||
this.cerberusManager = new CerberusManager(this);
|
||||
|
||||
this.citadelInventory = new CitadelInventory(this);
|
||||
this.warpKothInventory = new WarpKothInventory(this);
|
||||
this.cerberusInventory = new CerberusInventory(this);
|
||||
|
||||
this.eventsInventory = new EventsInventory(this);
|
||||
|
||||
this.citadelManager.setLastFactionCaptured(Factions.getInstance().getFactionById(this.getConfig().getString("CITADEL_LAST_WON")));
|
||||
this.warpKothManager.setLastFactionCaptured(Factions.getInstance().getFactionById(this.getConfig().getString("WARP_KOTH_LAST_WON")));
|
||||
this.cerberusManager.setLastFactionCaptured(Factions.getInstance().getFactionById(this.getConfig().getString("CERBERUS_LAST_WON")));
|
||||
|
||||
new UpdateNextCitadelTimerTask(this).runTaskTimer(this, 40L, 20L);
|
||||
new UpdateNextWarpKothTimerTask(this).runTaskTimer(this, 40L, 20L);
|
||||
new UpdateNextCerberusTimerTask(this).runTaskTimer(this, 40L, 20L);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
instance = null;
|
||||
this.getMiniGameRegister().unregisterAll();
|
||||
|
||||
this.getConfig().set("CITADEL_LAST_WON", this.citadelManager.getLastFactionCaptured().getId());
|
||||
this.getConfig().set("WARP_KOTH_LAST_WON", this.warpKothManager.getLastFactionCaptured().getId());
|
||||
this.getConfig().set("CERBERUS_LAST_WON", this.cerberusManager.getLastFactionCaptured().getId());
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
this.initNewCommands();
|
||||
this.commands.forEach(command -> this.commandManager.register(command));
|
||||
}
|
||||
|
||||
public void initNewCommands() {
|
||||
this.commands = Arrays.asList(
|
||||
new AdminEventsCommand(this),
|
||||
new ParkourEventCommand(this),
|
||||
new SumoEventCommand(this),
|
||||
new EventsCommand(this),
|
||||
new CitadelCommand(this),
|
||||
new WarpKothCommand(this),
|
||||
new CerberusCommand(this)
|
||||
);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
PluginManager pluginManager = this.getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new KothStateChangeListener(this), this);
|
||||
pluginManager.registerEvents(new PlayerDeathListener(this), this);
|
||||
pluginManager.registerEvents(new PlayerTeleportListener(this), this);
|
||||
pluginManager.registerEvents(new CerberusDeathListener(this), this);
|
||||
}
|
||||
|
||||
|
||||
public long getTimeUntilNextCitadel() {
|
||||
return (getNextCitadel() - System.currentTimeMillis()) - 1000;
|
||||
}
|
||||
|
||||
public long getTimeUntilNextWarpKoth() {
|
||||
return (getNextWarpKoth() - System.currentTimeMillis()) - 1000;
|
||||
}
|
||||
|
||||
public long getTimeUntilNextCerberus() {
|
||||
return (getNextCerberus() - System.currentTimeMillis()) - 1000;
|
||||
}
|
||||
|
||||
private long getNextCitadel() {
|
||||
Calendar nextCitadel = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"));
|
||||
nextCitadel.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
|
||||
nextCitadel.set(Calendar.HOUR_OF_DAY, 16);
|
||||
Calendar now = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"));
|
||||
if((now.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY && now.get(Calendar.HOUR_OF_DAY) > 16)) {
|
||||
nextCitadel.add(Calendar.DAY_OF_WEEK, 7);
|
||||
}
|
||||
nextCitadel.set(Calendar.MINUTE, 0);
|
||||
nextCitadel.set(Calendar.SECOND, 0);
|
||||
return nextCitadel.getTimeInMillis();
|
||||
}
|
||||
|
||||
private long getNextWarpKoth() {
|
||||
Calendar nextCitadel = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"));
|
||||
nextCitadel.set(Calendar.MINUTE, 0);
|
||||
nextCitadel.set(Calendar.SECOND, 0);
|
||||
|
||||
Calendar current = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"));
|
||||
if(current.get(Calendar.HOUR_OF_DAY) < 6) {
|
||||
nextCitadel.set(Calendar.HOUR_OF_DAY, 6);
|
||||
} else if(current.get(Calendar.HOUR_OF_DAY) < 12) {
|
||||
nextCitadel.set(Calendar.HOUR_OF_DAY, 12);
|
||||
} else if(current.get(Calendar.HOUR_OF_DAY) < 18) {
|
||||
nextCitadel.set(Calendar.HOUR_OF_DAY, 18);
|
||||
} else {
|
||||
nextCitadel.add(Calendar.DAY_OF_MONTH, 1);
|
||||
nextCitadel.set(Calendar.HOUR_OF_DAY, 0);
|
||||
}
|
||||
return nextCitadel.getTimeInMillis();
|
||||
}
|
||||
|
||||
private long getNextCerberus() {
|
||||
Calendar nextCerberus = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"));
|
||||
nextCerberus.set(Calendar.MINUTE, 0);
|
||||
nextCerberus.set(Calendar.SECOND, 0);
|
||||
|
||||
Calendar current = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"));
|
||||
if(current.get(Calendar.HOUR_OF_DAY) < 3) {
|
||||
nextCerberus.set(Calendar.HOUR_OF_DAY, 3);
|
||||
} else if(current.get(Calendar.HOUR_OF_DAY) < 9) {
|
||||
nextCerberus.set(Calendar.HOUR_OF_DAY, 9);
|
||||
} else if(current.get(Calendar.HOUR_OF_DAY) < 15) {
|
||||
nextCerberus.set(Calendar.HOUR_OF_DAY, 15);
|
||||
} else if(current.get(Calendar.HOUR_OF_DAY) <= 21) {
|
||||
nextCerberus.set(Calendar.HOUR_OF_DAY, 21);
|
||||
} else {
|
||||
nextCerberus.set(Calendar.HOUR_OF_DAY, 21);
|
||||
return ( nextCerberus.getTimeInMillis() + (21600*1000));
|
||||
}
|
||||
return nextCerberus.getTimeInMillis();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package net.crankedpvp.events.commands;
|
||||
|
||||
|
||||
import me.mattstudios.mf.annotations.*;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.game.MiniGame;
|
||||
import net.crankedpvp.events.game.MiniGameRegister;
|
||||
import net.crankedpvp.events.game.MiniGameType;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import net.crankedpvp.events.utils.configuration.ConfigManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@Command("aevent")
|
||||
@Alias({"aevents", "adminevent", "adminevents"})
|
||||
public class AdminEventsCommand extends CommandBase {
|
||||
|
||||
private final MiniGameRegister miniGameRegister;
|
||||
private final ConfigManager languageFile;
|
||||
private final EventsPlugin plugin;
|
||||
|
||||
public AdminEventsCommand(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.miniGameRegister = plugin.getMiniGameRegister();
|
||||
this.languageFile = plugin.getConfigManager();
|
||||
}
|
||||
|
||||
@SubCommand("start")
|
||||
@Permission("cranked.admin")
|
||||
public void startEvent(CommandSender sender, String eventName) {
|
||||
if (Arrays.stream(MiniGameType.values()).noneMatch(miniGameType -> miniGameType.name().equals(eventName.toUpperCase(Locale.ROOT)))) {
|
||||
sender.sendMessage(Utils.color(languageFile.getConfig(ConfigManager.ConfigFile.LANGUAGE).getString("messages.invalid-event-name")));
|
||||
return;
|
||||
}
|
||||
|
||||
MiniGameType miniGameType = MiniGameType.valueOf(eventName.toUpperCase(Locale.ROOT));
|
||||
MiniGame<?> miniGame = this.miniGameRegister.getMiniGame(miniGameType);
|
||||
if (miniGame == null) {
|
||||
sender.sendMessage(Utils.color("&cThat event is unavailable because its world is not loaded."));
|
||||
return;
|
||||
}
|
||||
miniGame.startMiniGameCountDown();
|
||||
}
|
||||
|
||||
@SubCommand("stop")
|
||||
@Permission("cranked.admin")
|
||||
public void stopEvent(CommandSender sender, String eventName) {
|
||||
if (Arrays.stream(MiniGameType.values()).noneMatch(miniGameType -> miniGameType.name().equals(eventName.toUpperCase(Locale.ROOT)))) {
|
||||
sender.sendMessage(Utils.color(languageFile.getConfig(ConfigManager.ConfigFile.LANGUAGE).getString("messages.invalid-event-name")));
|
||||
return;
|
||||
}
|
||||
|
||||
MiniGameType miniGameType = MiniGameType.valueOf(eventName.toUpperCase(Locale.ROOT));
|
||||
MiniGame<?> miniGame = miniGameRegister.getMiniGame(miniGameType);
|
||||
if (miniGame == null) {
|
||||
sender.sendMessage(Utils.color("&cThat event is unavailable because its world is not loaded."));
|
||||
return;
|
||||
}
|
||||
miniGame.stopMiniGame();
|
||||
}
|
||||
|
||||
@SubCommand("list")
|
||||
@Permission("cranked.admin")
|
||||
public void listEvent(CommandSender sender) {
|
||||
sender.sendMessage(Utils.color(languageFile.getConfig(ConfigManager.ConfigFile.LANGUAGE).getString("messages.event.list-header")));
|
||||
|
||||
Arrays.stream(MiniGameType.values()).forEach(game -> {
|
||||
sender.sendMessage(Utils.color(languageFile.getConfig(ConfigManager.ConfigFile.LANGUAGE).getString("messages.event.list-format").replace("{event}", Utils.toNiceString(game.name()))));
|
||||
});
|
||||
}
|
||||
|
||||
@SubCommand("info")
|
||||
@Permission("cranked.admin")
|
||||
public void eventInformation(CommandSender sender, String eventName) {
|
||||
if (Arrays.stream(MiniGameType.values()).noneMatch(miniGameType -> miniGameType.name().equals(eventName.toUpperCase(Locale.ROOT)))) {
|
||||
sender.sendMessage(Utils.color(languageFile.getConfig(ConfigManager.ConfigFile.LANGUAGE).getString("messages.invalid-event-name")));
|
||||
return;
|
||||
}
|
||||
|
||||
MiniGameType miniGameType = MiniGameType.valueOf(eventName.toUpperCase(Locale.ROOT));
|
||||
MiniGame<?> miniGame = miniGameRegister.getMiniGame(miniGameType);
|
||||
if (miniGame == null) {
|
||||
sender.sendMessage(Utils.color("&cThat event is unavailable because its world is not loaded."));
|
||||
return;
|
||||
}
|
||||
Location spawnLocation = miniGame.getSpawnLocation();
|
||||
sender.sendMessage(Utils.color(
|
||||
"\n" +
|
||||
"&a* &7Minigame &8- &a" + Utils.toNiceString(miniGameType.name()) + "\n" +
|
||||
"&a* &7World name: &a" + miniGame.getGameWorld().getName() + "\n" +
|
||||
"&a* &7Spawn location: &7X: &a" + spawnLocation.getX() + " &7Y: &a" + spawnLocation.getY() + " &7Z: &a" + spawnLocation.getZ() + "\n" +
|
||||
"&a* &7Event state: &a" + Utils.toNiceString(miniGame.getMiniGameState().name()) + "\n" +
|
||||
"&a* &7Min/Max players: &a" + miniGame.getMinPlayers() + "&8/&a" + miniGame.getMaxPlayers() + "\n" +
|
||||
"&a* &7Amount of participants: &a" + miniGame.getParticipants().size() + "\n"
|
||||
));
|
||||
}
|
||||
|
||||
@SubCommand("reload")
|
||||
@Permission("cranked.admin")
|
||||
public void reloadEvent(CommandSender sender) {
|
||||
this.plugin.getConfigManager().reloadFiles();
|
||||
this.miniGameRegister.reloadMiniGames();
|
||||
/*this.plugin.getCommands().forEach(baseCommand -> this.plugin.getCommandManager().(baseCommand));
|
||||
this.plugin.initNewCommands();
|
||||
this.plugin.getCommands().forEach(baseCommand -> this.plugin.getCommandManager().registerCommand(baseCommand));*/
|
||||
sender.sendMessage(Utils.color("&aReload Successful"));
|
||||
sender.sendMessage(Utils.color("&cWarning: &7Reloading the events will interrupt any ongoing events"));
|
||||
}
|
||||
|
||||
@Default
|
||||
@Permission("cranked.admin")
|
||||
public void doHelp(CommandSender sender) {
|
||||
List<String> helpMessageList = languageFile.getConfig(ConfigManager.ConfigFile.LANGUAGE).getStringList("messages.events-help-message");
|
||||
String[] helpMessage = new String[helpMessageList.size()];
|
||||
helpMessage = Utils.color(helpMessageList.toArray(helpMessage));
|
||||
sender.sendMessage(helpMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.crankedpvp.events.commands;
|
||||
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Command("cerberus")
|
||||
public class CerberusCommand extends CommandBase {
|
||||
|
||||
private final EventsPlugin plugin;
|
||||
public CerberusCommand(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void defaultCommand(final Player player) {
|
||||
this.plugin.getCerberusInventory().getUI().open(player);
|
||||
}
|
||||
|
||||
@SubCommand("start")
|
||||
@Permission("events.start")
|
||||
public void startCommand(final CommandSender commandSender) {
|
||||
this.plugin.getCerberusManager().startEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.crankedpvp.events.commands;
|
||||
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Command("citadel")
|
||||
public class CitadelCommand extends CommandBase {
|
||||
|
||||
private final EventsPlugin plugin;
|
||||
public CitadelCommand(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void defaultCommand(final Player player) {
|
||||
this.plugin.getCitadelInventory().getUI().open(player);
|
||||
}
|
||||
|
||||
@SubCommand("start")
|
||||
@Permission("events.start")
|
||||
public void startCommand(final CommandSender commandSender) {
|
||||
this.plugin.getCitadelManager().startEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.crankedpvp.events.commands;
|
||||
|
||||
import me.mattstudios.mf.annotations.Alias;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.inventories.MainEventsUI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Command("event")
|
||||
@Alias("events")
|
||||
public class EventsCommand extends CommandBase {
|
||||
|
||||
private final EventsPlugin plugin;
|
||||
|
||||
public EventsCommand(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void baseCommand(Player sender) {
|
||||
this.plugin.getEventsInventory().getNewEventsUI().open(sender);
|
||||
/*
|
||||
MainEventsUI mainEventsUI = new MainEventsUI(plugin, sender);
|
||||
mainEventsUI.getEventsUI().open(sender);
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package net.crankedpvp.events.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.events.EventsPlugin;
|
||||
import net.crankedpvp.events.game.MiniGameRegister;
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import net.crankedpvp.events.game.MiniGameType;
|
||||
import net.crankedpvp.events.game.games.ParkourMiniGame;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import net.crankedpvp.events.utils.configuration.ConfigManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Command("parkour")
|
||||
public class ParkourEventCommand extends CommandBase {
|
||||
|
||||
private final MiniGameRegister miniGameRegister;
|
||||
private final FileConfiguration languageFile;
|
||||
|
||||
public ParkourEventCommand(EventsPlugin plugin) {
|
||||
this.miniGameRegister = plugin.getMiniGameRegister();
|
||||
this.languageFile = plugin.getConfigManager()
|
||||
.getConfig(ConfigManager.ConfigFile.LANGUAGE);
|
||||
}
|
||||
|
||||
|
||||
@SubCommand("join")
|
||||
public void joinParkour(Player sender) {
|
||||
|
||||
if (miniGameRegister.getMiniGame(MiniGameType.PARKOUR) == null) return;
|
||||
|
||||
ParkourMiniGame parkourMiniGame = (ParkourMiniGame) miniGameRegister.getMiniGame(MiniGameType.PARKOUR);
|
||||
|
||||
if (parkourMiniGame.getMiniGameState() == MiniGameState.IN_PROGRESS) {
|
||||
sender.sendMessage(Utils.color(languageFile.getString("messages.event.already-in-progress").replace("{game}", "Parkour")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (parkourMiniGame.getMiniGameState() == MiniGameState.NOT_STARTED) {
|
||||
sender.sendMessage(Utils.color(languageFile.getString("messages.event.not-started").replace("{game}", "Parkour")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (parkourMiniGame.isFull()) {
|
||||
sender.sendMessage(Utils.color(languageFile.getString("messages.event.full").replace("{game}", "Parkour")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Utils.isInventoryEmpty(sender)) {
|
||||
sender.sendMessage(Utils.color(languageFile.getString("messages.event.inventory-empty")));
|
||||
return;
|
||||
}
|
||||
|
||||
parkourMiniGame.joinMiniGame(sender);
|
||||
parkourMiniGame.sendMessageToAllParticipants(languageFile.getString("messages.event.player-joined")
|
||||
.replace("{game}", "Parkour")
|
||||
.replace("{player}", sender.getName())
|
||||
.replace("{amount}", String.valueOf(parkourMiniGame.getParticipants().size()))
|
||||
.replace("{max}", String.valueOf(parkourMiniGame.getMaxPlayers()))
|
||||
);
|
||||
}
|
||||
|
||||
@SubCommand("leave")
|
||||
public void leaveParkour(Player sender) {
|
||||
if (miniGameRegister.getMiniGame(MiniGameType.PARKOUR) == null) return;
|
||||
|
||||
ParkourMiniGame parkourMiniGame = (ParkourMiniGame) miniGameRegister.getMiniGame(MiniGameType.PARKOUR);
|
||||
|
||||
if (!parkourMiniGame.isParticipant(sender)) {
|
||||
sender.sendMessage(Utils.color(languageFile.getString("messages.event.not-participant").replace("{game}", "Parkour")));
|
||||
return;
|
||||
}
|
||||
|
||||
parkourMiniGame.leaveMiniGame(sender);
|
||||
parkourMiniGame.sendMessageToAllParticipants(languageFile.getString("messages.event.player-left")
|
||||
.replace("{game}", "Parkour")
|
||||
.replace("{player}", sender.getName())
|
||||
.replace("{amount}", String.valueOf(parkourMiniGame.getParticipants().size()))
|
||||
.replace("{max}", String.valueOf(parkourMiniGame.getMaxPlayers()))
|
||||
);
|
||||
}
|
||||
|
||||
@SubCommand("checkpoint")
|
||||
public void checkpointParkour(Player sender) {
|
||||
if (miniGameRegister.getMiniGame(MiniGameType.PARKOUR) == null) return;
|
||||
|
||||
ParkourMiniGame parkourMiniGame = (ParkourMiniGame) miniGameRegister.getMiniGame(MiniGameType.PARKOUR);
|
||||
|
||||
if (!parkourMiniGame.isParticipant(sender)) {
|
||||
sender.sendMessage(Utils.color(languageFile.getString("messages.event.not-participant").replace("{game}", "Parkour")));
|
||||
return;
|
||||
}
|
||||
|
||||
parkourMiniGame.teleportParticipantToCheckpoint(sender);
|
||||
}
|
||||
|
||||
@Default
|
||||
public void doHelp(CommandSender sender) {
|
||||
List<String> helpMessageList = languageFile.getStringList("messages.parkour-help-message");
|
||||
String[] helpMessage = new String[helpMessageList.size()];
|
||||
helpMessage = Utils.color(helpMessageList.toArray(helpMessage));
|
||||
sender.sendMessage(helpMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package net.crankedpvp.events.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.events.EventsPlugin;
|
||||
import net.crankedpvp.events.game.MiniGameRegister;
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import net.crankedpvp.events.game.MiniGameType;
|
||||
import net.crankedpvp.events.game.games.SumoMiniGame;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import net.crankedpvp.events.utils.configuration.ConfigManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Command("sumo")
|
||||
public class SumoEventCommand extends CommandBase {
|
||||
|
||||
private final MiniGameRegister miniGameRegister;
|
||||
private final FileConfiguration languageFile;
|
||||
|
||||
public SumoEventCommand(EventsPlugin plugin) {
|
||||
this.miniGameRegister = plugin.getMiniGameRegister();
|
||||
this.languageFile = plugin.getConfigManager()
|
||||
.getConfig(ConfigManager.ConfigFile.LANGUAGE);
|
||||
}
|
||||
|
||||
|
||||
@SubCommand("join")
|
||||
public void joinSumo(Player sender) {
|
||||
|
||||
if (miniGameRegister.getMiniGame(MiniGameType.SUMO) == null) return;
|
||||
|
||||
SumoMiniGame sumoMiniGame = (SumoMiniGame) miniGameRegister.getMiniGame(MiniGameType.SUMO);
|
||||
|
||||
if (sumoMiniGame.getMiniGameState() == MiniGameState.IN_PROGRESS) {
|
||||
sender.sendMessage(Utils.color(languageFile.getString("messages.event.already-in-progress").replace("{game}", "Sumo")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (sumoMiniGame.getMiniGameState() == MiniGameState.NOT_STARTED) {
|
||||
sender.sendMessage(Utils.color(languageFile.getString("messages.event.not-started").replace("{game}", "Sumo")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (sumoMiniGame.isFull()) {
|
||||
sender.sendMessage(Utils.color(languageFile.getString("messages.event.full").replace("{game}", "Sumo")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Utils.isInventoryEmpty(sender)) {
|
||||
sender.sendMessage(Utils.color(languageFile.getString("messages.event.inventory-empty")));
|
||||
return;
|
||||
}
|
||||
|
||||
sumoMiniGame.joinMiniGame(sender);
|
||||
sumoMiniGame.sendMessageToAllParticipants(languageFile.getString("messages.event.player-joined")
|
||||
.replace("{game}", "Sumo")
|
||||
.replace("{player}", sender.getName())
|
||||
.replace("{amount}", String.valueOf(sumoMiniGame.getParticipants().size()))
|
||||
.replace("{max}", String.valueOf(sumoMiniGame.getMaxPlayers()))
|
||||
);
|
||||
}
|
||||
|
||||
@SubCommand("leave")
|
||||
public void leaveSumo(Player sender) {
|
||||
if (miniGameRegister.getMiniGame(MiniGameType.SUMO) == null) return;
|
||||
|
||||
SumoMiniGame sumoMiniGame = (SumoMiniGame) miniGameRegister.getMiniGame(MiniGameType.SUMO);
|
||||
|
||||
if (!sumoMiniGame.isParticipant(sender) && !sumoMiniGame.isSpectator(sender)) {
|
||||
sender.sendMessage(Utils.color(languageFile.getString("messages.event.not-participant").replace("{game}", "Sumo")));
|
||||
return;
|
||||
}
|
||||
|
||||
sumoMiniGame.leaveMiniGame(sender);
|
||||
sumoMiniGame.sendMessageToAllParticipants(languageFile.getString("messages.event.player-left")
|
||||
.replace("{game}", "Sumo")
|
||||
.replace("{player}", sender.getName())
|
||||
.replace("{amount}", String.valueOf(sumoMiniGame.getParticipants().size()))
|
||||
.replace("{max}", String.valueOf(sumoMiniGame.getMaxPlayers()))
|
||||
);
|
||||
}
|
||||
|
||||
@Default
|
||||
public void doHelp(CommandSender sender) {
|
||||
List<String> helpMessageList = languageFile.getStringList("messages.sumo-help-message");
|
||||
String[] helpMessage = new String[helpMessageList.size()];
|
||||
helpMessage = Utils.color(helpMessageList.toArray(helpMessage));
|
||||
sender.sendMessage(helpMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.crankedpvp.events.commands;
|
||||
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Command("warpkoth")
|
||||
public class WarpKothCommand extends CommandBase {
|
||||
|
||||
private final EventsPlugin plugin;
|
||||
public WarpKothCommand(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void defaultCommand(final Player player) {
|
||||
this.plugin.getWarpKothInventory().getUI().open(player);
|
||||
}
|
||||
|
||||
@SubCommand("start")
|
||||
@Permission("events.start")
|
||||
public void startCommand(final CommandSender commandSender) {
|
||||
this.plugin.getWarpKothManager().startEvent();
|
||||
if (!this.plugin.getWarpKothManager().isActive()) {
|
||||
commandSender.sendMessage(CC.translate("&cWarp KOTH could not start. Check WARP_KOTH_NAME and the FactionsKore KOTH arena configuration; see the console for details."));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
package net.crankedpvp.events.game;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.SneakyThrows;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import net.crankedpvp.events.utils.configuration.AbstractConfig;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
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.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
@Getter
|
||||
public abstract class MiniGame<T extends MiniGamePlayer> implements Listener {
|
||||
|
||||
private final byte minPlayers;
|
||||
private final byte maxPlayers;
|
||||
private final Location spawnLocation;
|
||||
private final AbstractConfig abstractConfig;
|
||||
private final ConfigurationSection configuration;
|
||||
private final Map<UUID, T> participants;
|
||||
private final MiniGameType miniGameType;
|
||||
private final String countdownMessage;
|
||||
private final World gameWorld;
|
||||
private final MiniGameOptions miniGamesOptions;
|
||||
private final int countdownTime;
|
||||
private final List<String> rewardCommands;
|
||||
private final Set<T> spectators;
|
||||
private final Material guiMaterial;
|
||||
|
||||
@Setter
|
||||
private MiniGameState miniGameState;
|
||||
|
||||
@SneakyThrows
|
||||
protected MiniGame(EventsPlugin plugin, MiniGameType miniGameType, Map<UUID, T> participantsMap, MiniGameOptions miniGamesOptions, Material guiMaterial) {
|
||||
this.miniGameType = miniGameType;
|
||||
this.miniGameState = MiniGameState.NOT_STARTED;
|
||||
this.miniGamesOptions = miniGamesOptions;
|
||||
this.participants = participantsMap;
|
||||
this.spectators = new HashSet<>();
|
||||
this.abstractConfig = plugin.getConfigManager().getAbstractConfig(miniGameType.getConfigFile());
|
||||
|
||||
this.configuration = abstractConfig.getConfig().getConfigurationSection("minigame");
|
||||
this.gameWorld = Bukkit.getWorld(this.configuration.getString("world"));
|
||||
this.countdownMessage = Utils.color(this.configuration.getString("countdown-message"));
|
||||
this.minPlayers = (byte) this.configuration.getInt("min-players");
|
||||
this.maxPlayers = (byte) this.configuration.getInt("max-players");
|
||||
this.countdownTime = this.configuration.getInt("countdown-time");
|
||||
|
||||
this.spawnLocation = this.getLocationFromConfig(configuration.getConfigurationSection("spawn-location"));
|
||||
this.rewardCommands = this.configuration.getStringList("rewards");
|
||||
this.guiMaterial = guiMaterial;
|
||||
|
||||
}
|
||||
|
||||
protected MiniGame(EventsPlugin plugin, MiniGameType miniGameType) {
|
||||
this(plugin, miniGameType, new HashMap<>(), MiniGameOptions.builder().build(), Material.STONE);
|
||||
}
|
||||
|
||||
public void addParticipant(T participant) {
|
||||
this.participants.put(participant.getUUID(), participant);
|
||||
}
|
||||
|
||||
protected void removeParticipant(Player player) {
|
||||
this.participants.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
protected void removeParticipant(T participant) {
|
||||
this.participants.remove(participant.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
protected void clearParticipants() {
|
||||
this.participants.clear();
|
||||
}
|
||||
|
||||
public boolean isParticipant(Player player) {
|
||||
return this.participants.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public T getParticipant(Player player) {
|
||||
return this.getParticipants().get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return this.maxPlayers <= this.participants.size();
|
||||
}
|
||||
|
||||
public abstract void startMiniGame();
|
||||
public abstract void startMiniGameCountDown();
|
||||
public abstract void stopMiniGame();
|
||||
public abstract void joinMiniGame(Player player);
|
||||
public abstract void leaveMiniGame(Player player);
|
||||
|
||||
public void leaveMiniGame(T miniGamePlayer) {
|
||||
this.leaveMiniGame(miniGamePlayer.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
if (!isParticipant(event.getPlayer()) && !isSpectator(event.getPlayer())) return;
|
||||
leaveMiniGame(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFoodLossWhileInGame(FoodLevelChangeEvent event) {
|
||||
if (!isValidParticipant(event.getEntity())) return;
|
||||
if (miniGamesOptions.isFoodLoss()) return;
|
||||
((Player) event.getEntity()).setFoodLevel(20);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPickUpWhileInGame(PlayerPickupItemEvent event) {
|
||||
if (!isValidParticipant(event.getPlayer())) return;
|
||||
if (miniGamesOptions.isItemPickUp()) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlaceWhileInGame(BlockPlaceEvent event) {
|
||||
if (!isValidParticipant(event.getPlayer())) return;
|
||||
if (miniGamesOptions.isBlockPlace()) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreakWhileInGame(BlockBreakEvent event) {
|
||||
if (!isValidParticipant(event.getPlayer())) return;
|
||||
if (miniGamesOptions.isBlockBreak()) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPickUpWhileInGame(PlayerDropItemEvent event) {
|
||||
if (!isValidParticipant(event.getPlayer())) return;
|
||||
if (miniGamesOptions.isItemDrop()) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFallDamageToPlayerWhileInGame(EntityDamageEvent event) {
|
||||
if (!isValidParticipant(event.getEntity())) return;
|
||||
if (miniGamesOptions.isFallDamage()) return;
|
||||
if (event.getCause() != EntityDamageEvent.DamageCause.FALL) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryInteract(InventoryClickEvent event) {
|
||||
if (!isValidParticipant(event.getWhoClicked())) return;
|
||||
if (miniGamesOptions.isInventoryInteract()) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onCommandWhileInGame(PlayerCommandPreprocessEvent event) {
|
||||
if (!isValidParticipant(event.getPlayer())) return;
|
||||
|
||||
if (!miniGamesOptions.isBlockCommands()) return;
|
||||
|
||||
String command = event.getMessage().replace("/", "").toLowerCase(Locale.ROOT);
|
||||
|
||||
if (Arrays.stream(this.miniGamesOptions.getExcludedBlockedCommands()).noneMatch(command::startsWith))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private boolean isValidParticipant(Player player) {
|
||||
if (!this.isParticipant(player) && !this.isSpectator(player)) return false;
|
||||
if (player.isOp()) return false;
|
||||
return !player.hasPermission("astro.admin");
|
||||
}
|
||||
|
||||
private boolean isValidParticipant(Entity entity) {
|
||||
if (!(entity instanceof Player)) return false;
|
||||
return isValidParticipant((Player) entity);
|
||||
}
|
||||
|
||||
public void giveWinnerRewards(Player player) {
|
||||
this.getRewardCommands().forEach(command -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("{player}", player.getName())));
|
||||
}
|
||||
|
||||
public void giveWinnerRewards(T miniGamePlayer) {
|
||||
this.giveWinnerRewards(miniGamePlayer.getPlayer());
|
||||
}
|
||||
|
||||
protected void clearInventory(Player player){
|
||||
player.getInventory().setHelmet(null);
|
||||
player.getInventory().setChestplate(null);
|
||||
player.getInventory().setLeggings(null);
|
||||
player.getInventory().setBoots(null);
|
||||
player.getInventory().clear();
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
protected void clearPotionEffects(Player player){
|
||||
for(PotionEffect effect:player.getActivePotionEffects()){
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void addSpectator(T player) {
|
||||
if (player == null) return;
|
||||
this.spectators.add(player);
|
||||
if (this.isParticipant(player.getPlayer())) this.removeParticipant(player);
|
||||
player.getPlayer().teleport(this.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
player.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
|
||||
protected Optional<T> getSpectator(Player player) {
|
||||
return this.spectators.stream().filter(spectator -> spectator.getPlayer().equals(player)).findFirst();
|
||||
}
|
||||
|
||||
public boolean isSpectator(Player player) {
|
||||
if (player == null) return false;
|
||||
return this.spectators.stream().anyMatch(spectator -> spectator.getPlayer().equals(player));
|
||||
}
|
||||
|
||||
public void sendMessageToAllParticipants(String message) {
|
||||
this.getParticipants().forEach((uuid, player) -> player.sendMessage(message));
|
||||
}
|
||||
|
||||
public boolean isSpectator(T sumoPlayer) {
|
||||
return this.spectators.contains(sumoPlayer);
|
||||
}
|
||||
|
||||
protected void clearSpectators() {
|
||||
this.spectators.clear();
|
||||
}
|
||||
|
||||
protected void removeSpectator(T player) {
|
||||
this.spectators.remove(player);
|
||||
}
|
||||
|
||||
protected void removeSpectator(Player player) {
|
||||
this.spectators.removeIf(spectator -> spectator.getPlayer().equals(player));
|
||||
}
|
||||
|
||||
protected Location getLocationFromConfig(ConfigurationSection configSection) {
|
||||
double x = configSection.getDouble("x");
|
||||
double y = configSection.getDouble("y");
|
||||
double z = configSection.getDouble("z");
|
||||
float yaw = Utils.defaultIfNull((float) configSection.getDouble("yaw"), (float) 0.0);
|
||||
float pitch = Utils.defaultIfNull((float) configSection.getDouble("pitch"), (float) 0.0);
|
||||
return new Location(this.gameWorld, x, y, z, yaw, pitch);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package net.crankedpvp.events.game;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.game.tasks.AutoMiniGameTask;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class MiniGameManager {
|
||||
|
||||
private static final long TIME_BETWEEN_EVENTS_IN_SECS = 7200;
|
||||
|
||||
private long lastMiniGameTime;
|
||||
private final MiniGameRegister miniGameRegister;
|
||||
private final EventsPlugin plugin;
|
||||
private AutoMiniGameTask autoMiniGameTask;
|
||||
private MiniGameType previousMiniGame;
|
||||
|
||||
public MiniGameManager(EventsPlugin plugin) {
|
||||
this.miniGameRegister = plugin.getMiniGameRegister();
|
||||
this.previousMiniGame = MiniGameType.SUMO;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void startAutoMiniGameTask() {
|
||||
this.autoMiniGameTask = new AutoMiniGameTask(this, this.miniGameRegister);
|
||||
this.autoMiniGameTask.runTaskTimer(plugin, TIME_BETWEEN_EVENTS_IN_SECS * 20, TIME_BETWEEN_EVENTS_IN_SECS * 20);
|
||||
this.lastMiniGameTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public MiniGameType getNextMiniGame() {
|
||||
return previousMiniGame == MiniGameType.PARKOUR ? MiniGameType.SUMO : MiniGameType.PARKOUR;
|
||||
}
|
||||
|
||||
public long getTimeInMsUntilNextMiniGame() {
|
||||
return (lastMiniGameTime + TIME_BETWEEN_EVENTS_IN_SECS * 1000) - System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public String getTimeUntilNextMiniGame() {
|
||||
return Utils.getSecondsAsString(this.getTimeInMsUntilNextMiniGame() / 1000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.crankedpvp.events.game;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class MiniGameOptions {
|
||||
|
||||
@Builder.Default
|
||||
private final boolean foodLoss = false;
|
||||
@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 String[] excludedBlockedCommands = {"parkour"};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.crankedpvp.events.game;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.crankedpvp.events.utils.PlayerInventoryContents;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public class MiniGamePlayer {
|
||||
|
||||
private final Player player;
|
||||
@Setter
|
||||
private long joinGameTime;
|
||||
private final PlayerInventoryContents playerInventoryContents;
|
||||
@Setter
|
||||
private boolean damageEnabled;
|
||||
|
||||
public MiniGamePlayer(Player player) {
|
||||
this.player = player;
|
||||
this.joinGameTime = System.currentTimeMillis();
|
||||
this.playerInventoryContents = new PlayerInventoryContents(player.getInventory().getContents().clone(), player.getInventory().getArmorContents().clone());
|
||||
this.damageEnabled = false;
|
||||
}
|
||||
|
||||
public void sendMessage(String text) {
|
||||
this.player.sendMessage(Utils.color(text));
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return this.player.getUniqueId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package net.crankedpvp.events.game;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.game.games.ParkourMiniGame;
|
||||
import net.crankedpvp.events.game.games.SumoMiniGame;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MiniGameRegister {
|
||||
|
||||
private final EventsPlugin plugin;
|
||||
@Getter
|
||||
private final Map<MiniGameType, MiniGame<?>> miniGames;
|
||||
|
||||
public MiniGameRegister(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.miniGames = new HashMap<>();
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
this.registerAll(new ParkourMiniGame(plugin), new SumoMiniGame(plugin));
|
||||
}
|
||||
|
||||
private void registerAll(MiniGame<?>... miniGames) {
|
||||
for (MiniGame<?> miniGame : miniGames) {
|
||||
register(miniGame);
|
||||
}
|
||||
}
|
||||
|
||||
private void register(MiniGame<?> miniGame) {
|
||||
try {
|
||||
if (miniGame.getGameWorld() == null) {
|
||||
plugin.getLogger().warning("Skipping " + miniGame.getMiniGameType().name()
|
||||
+ " minigame because world '" + miniGame.getConfiguration().getString("world")
|
||||
+ "' is not loaded.");
|
||||
return;
|
||||
}
|
||||
this.miniGames.put(miniGame.getMiniGameType(), miniGame);
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(miniGame, plugin);
|
||||
|
||||
} catch (Exception exception) {
|
||||
System.err.println("Failed to register minigame: " + miniGame.getMiniGameType().name());
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterAll() {
|
||||
this.miniGames.forEach(((miniGameType, miniGame) -> {
|
||||
miniGame.stopMiniGame();
|
||||
HandlerList.unregisterAll(miniGame);
|
||||
}));
|
||||
this.miniGames.clear();
|
||||
}
|
||||
|
||||
private void unregister(MiniGame<?> miniGame) {
|
||||
miniGame.stopMiniGame();
|
||||
HandlerList.unregisterAll(miniGame);
|
||||
this.miniGames.remove(miniGame.getMiniGameType());
|
||||
}
|
||||
|
||||
public void reloadMiniGames() {
|
||||
this.unregisterAll();
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
public MiniGame<?> getMiniGame(MiniGameType miniGameType) {
|
||||
return this.miniGames.get(miniGameType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.crankedpvp.events.game;
|
||||
|
||||
public enum MiniGameState {
|
||||
|
||||
NOT_STARTED(),
|
||||
STARTING(),
|
||||
IN_PROGRESS()
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.crankedpvp.events.game;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.events.utils.configuration.ConfigManager;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum MiniGameType {
|
||||
|
||||
PARKOUR(ConfigManager.ConfigFile.PARKOUR),
|
||||
SUMO(ConfigManager.ConfigFile.SUMO),
|
||||
SPLEEF(ConfigManager.ConfigFile.SPLEEF)
|
||||
;
|
||||
|
||||
private final ConfigManager.ConfigFile configFile;
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
package net.crankedpvp.events.game.games;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.Hologram;
|
||||
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.game.MiniGame;
|
||||
import net.crankedpvp.events.game.MiniGameOptions;
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import net.crankedpvp.events.game.MiniGameType;
|
||||
import net.crankedpvp.events.game.players.ParkourPlayer;
|
||||
import net.crankedpvp.events.game.tasks.MiniGameCountDown;
|
||||
import net.crankedpvp.events.game.tasks.MiniGameFlyDisableTask;
|
||||
import net.crankedpvp.events.game.tasks.ParkourTimeTask;
|
||||
import net.crankedpvp.events.utils.Clickable;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import net.crankedpvp.events.utils.configuration.ConfigParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ParkourMiniGame extends MiniGame<ParkourPlayer> {
|
||||
|
||||
@Getter
|
||||
private long startTime;
|
||||
private final BiMap<Location, Byte> parkourCheckpoints;
|
||||
private final Map<Byte, Float> parkourYawCheckpoints;
|
||||
private final EventsPlugin plugin;
|
||||
private final Location endLocation;
|
||||
@Getter
|
||||
private final String parkourTimeMessage;
|
||||
private final ItemStack checkpointItem;
|
||||
private final ItemStack leaveItem;
|
||||
private boolean checkpointsLoaded;
|
||||
|
||||
public ParkourMiniGame(EventsPlugin plugin) {
|
||||
super(plugin, MiniGameType.PARKOUR, new HashMap<>(), MiniGameOptions.builder().excludedBlockedCommands(new String[]{"parkour"}).build(), Material.FEATHER);
|
||||
this.plugin = plugin;
|
||||
|
||||
this.startTime = 0;
|
||||
this.parkourCheckpoints = HashBiMap.create();
|
||||
this.parkourYawCheckpoints = new HashMap<>();
|
||||
|
||||
ConfigurationSection checkpointsConfigSection = super.getConfiguration().getConfigurationSection("checkpoints");
|
||||
|
||||
checkpointsConfigSection.getKeys(false).forEach((s -> {
|
||||
ConfigurationSection checkpointSection = checkpointsConfigSection.getConfigurationSection(s);
|
||||
Location location = super.getLocationFromConfig(checkpointSection);
|
||||
Byte number = Byte.parseByte(s);
|
||||
this.parkourYawCheckpoints.put(number, location.getYaw());
|
||||
location.setYaw((float) 0.0);
|
||||
parkourCheckpoints.put(location, Byte.parseByte(s));
|
||||
}));
|
||||
|
||||
this.endLocation = super.getLocationFromConfig(super.getConfiguration().getConfigurationSection("end-location"));
|
||||
this.parkourTimeMessage = Utils.color(this.getConfiguration().getString("parkour-time-message"));
|
||||
this.leaveItem = ConfigParser.parseItem(super.getConfiguration().getConfigurationSection("items.leave-item"));
|
||||
this.checkpointItem = ConfigParser.parseItem(super.getConfiguration().getConfigurationSection("items.checkpoint-item"));
|
||||
}
|
||||
|
||||
public Byte getCheckPoint(Location location) {
|
||||
return this.parkourCheckpoints.get(location);
|
||||
|
||||
}
|
||||
|
||||
public boolean isCheckPoint(Location location) {
|
||||
return this.getCheckpoints().containsKey(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMiniGame() {
|
||||
this.startTime = System.currentTimeMillis();
|
||||
super.setMiniGameState(MiniGameState.IN_PROGRESS);
|
||||
super.getParticipants().forEach((playerUUID, participant) -> {
|
||||
Player player = participant.getPlayer();
|
||||
player.getInventory().setItem(3, this.getCheckpointItem());
|
||||
player.getInventory().setItem(5, this.getLeaveItem());
|
||||
if (this.getCheckpoints().inverse().containsKey((byte) 0))
|
||||
player.teleport(this.getCheckpoints().inverse().get((byte) 0), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
});
|
||||
new ParkourTimeTask(this).runTaskTimer(plugin, 0L, 20L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMiniGameCountDown() {
|
||||
this.loadCheckpoints();
|
||||
super.setMiniGameState(MiniGameState.STARTING);
|
||||
new MiniGameCountDown(this).runTaskTimer(plugin, 0L, 20L);
|
||||
new MiniGameFlyDisableTask(this).runTaskTimer(plugin, 0L, 10L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMiniGame() {
|
||||
this.unLoadCheckpoints();
|
||||
super.getParticipants().forEach((player, participant) -> {
|
||||
this.leaveMiniGame(participant.getPlayer(), true);
|
||||
});
|
||||
super.clearParticipants();
|
||||
super.setMiniGameState(MiniGameState.NOT_STARTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinMiniGame(Player player) {
|
||||
if (isParticipant(player)) return;
|
||||
super.addParticipant(new ParkourPlayer(player));
|
||||
player.teleport(super.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
player.setHealth(20);
|
||||
player.setFoodLevel(20);
|
||||
player.setAllowFlight(false);
|
||||
player.setFlying(false);
|
||||
super.clearPotionEffects(player);
|
||||
super.clearInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leaveMiniGame(Player player) {
|
||||
if (this.getParticipants().size() <= 1 && this.getMiniGameState() == MiniGameState.IN_PROGRESS) {
|
||||
this.stopMiniGame();
|
||||
return;
|
||||
}
|
||||
this.leaveMiniGame(player, false);
|
||||
}
|
||||
|
||||
private void leaveMiniGame(Player player, boolean stopMiniGame) {
|
||||
if (!isParticipant(player)) return;
|
||||
player.teleport(Bukkit.getWorld("world").getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
super.clearInventory(player);
|
||||
super.clearPotionEffects(player);
|
||||
super.getParticipant(player).getPlayerInventoryContents().restore(player);
|
||||
if (stopMiniGame) return;
|
||||
super.removeParticipant(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamageWhileInParkour(EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) return;
|
||||
if (!super.isParticipant((Player) event.getEntity())) return;
|
||||
|
||||
if (event.getCause() == EntityDamageEvent.DamageCause.VOID) {
|
||||
teleportParticipantToCheckpoint((Player) event.getEntity());
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void checkpointCross(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.PHYSICAL) return;
|
||||
if (!super.isParticipant(event.getPlayer())) return;
|
||||
|
||||
Location location = event.getClickedBlock().getLocation();
|
||||
ParkourPlayer parkourPlayer = super.getParticipant(event.getPlayer());
|
||||
|
||||
if (this.endLocation.equals(location)) {
|
||||
this.announceWinner(event.getPlayer());
|
||||
this.stopMiniGame();
|
||||
super.giveWinnerRewards(event.getPlayer());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isCheckPoint(location)) return;
|
||||
|
||||
Byte locationCheckpoint = this.getCheckPoint(location);
|
||||
|
||||
if (parkourPlayer.getCurrentCheckpoint() >= locationCheckpoint) return;
|
||||
|
||||
parkourPlayer.sendMessage(super.getConfiguration().getString("checkpoint-reached-message").replace("{number}", String.valueOf(locationCheckpoint)));
|
||||
parkourPlayer.setCurrentCheckpoint(locationCheckpoint);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void parkourItemClick(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK ) return;
|
||||
if (!super.isParticipant(event.getPlayer())) return;
|
||||
if (event.getItem() == null) return;
|
||||
|
||||
if (event.getItem().getType() == this.checkpointItem.getType()) {
|
||||
teleportParticipantToCheckpoint(event.getPlayer());
|
||||
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ITEM_PICKUP, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
if (event.getItem().getType() == this.leaveItem.getType()) {
|
||||
Clickable parkourLeaveClickable = new Clickable("");
|
||||
parkourLeaveClickable.add(Utils.color(super.getConfiguration().getString("parkour-confirm-leave-message")), Utils.color("&7click to confirm"), "/parkour leave");
|
||||
parkourLeaveClickable.sendToPlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
public void announceWinner(Player player) {
|
||||
String time = Utils.getTimeFromSecsToMins((System.currentTimeMillis() - this.getStartTime()) / 1000);
|
||||
Bukkit.broadcastMessage(Utils.color(super.getConfiguration().getString("win-message").replace("{player}", player.getName()).replace("{time}", time)));
|
||||
}
|
||||
|
||||
public void teleportParticipantToCheckpoint(Player player) {
|
||||
Byte checkpoint = super.getParticipant(player).getCurrentCheckpoint();
|
||||
Location location = this.getCheckpoints().inverse().get(checkpoint);
|
||||
|
||||
if (location != null) {
|
||||
location = location.clone();
|
||||
location.add(0.5, 0.0, 0.5);
|
||||
location.setYaw(parkourYawCheckpoints.get(checkpoint));
|
||||
}
|
||||
|
||||
player.teleport(Utils.defaultIfNull(location, getSpawnLocation()), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
}
|
||||
|
||||
private void createCheckpointHolo(byte number, Location location) {
|
||||
location.getBlock().setType(Material.GOLD_PLATE);
|
||||
Hologram hologram = HologramsAPI.createHologram(plugin, location.add(0.5, 2.0, 0.5));
|
||||
hologram.appendTextLine(Utils.color("&aCheckpoint #" + number));
|
||||
|
||||
}
|
||||
|
||||
private void createEndCheckpoint() {
|
||||
this.endLocation.getBlock().setType(Material.GOLD_PLATE);
|
||||
Hologram hologram = HologramsAPI.createHologram(plugin, this.endLocation.clone().add(0.5, 2.0, 0.5));
|
||||
hologram.appendTextLine(Utils.color("&aParkour End"));
|
||||
}
|
||||
|
||||
private void loadCheckpoints() {
|
||||
if (checkpointsLoaded) return;
|
||||
this.getCheckpoints().forEach(((location, number) -> {
|
||||
this.createCheckpointHolo(number, location.clone());
|
||||
}));
|
||||
createEndCheckpoint();
|
||||
checkpointsLoaded = true;
|
||||
}
|
||||
|
||||
private void unLoadCheckpoints() {
|
||||
if (!checkpointsLoaded) return;
|
||||
checkpointsLoaded = false;
|
||||
World gameWorld = super.getGameWorld();
|
||||
if (gameWorld == null || Bukkit.getWorld(gameWorld.getName()) == null) return;
|
||||
this.getCheckpoints().forEach(((location, number) -> {
|
||||
location.getBlock().setType(Material.AIR);
|
||||
}));
|
||||
|
||||
this.endLocation.getBlock().setType(Material.AIR);
|
||||
|
||||
for (Hologram hologram : HologramsAPI.getHolograms(plugin)) {
|
||||
if (!gameWorld.equals(hologram.getWorld())) continue;
|
||||
//if (!parkourCheckpoints.containsKey(hologram.getLocation().add(0.5, 3.0, 0.5))) return;
|
||||
hologram.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public ImmutableBiMap<Location, Byte> getCheckpoints() {
|
||||
return ImmutableBiMap.copyOf(this.parkourCheckpoints);
|
||||
}
|
||||
|
||||
private ItemStack getCheckpointItem() {
|
||||
return this.checkpointItem;
|
||||
}
|
||||
|
||||
private ItemStack getLeaveItem() {
|
||||
return this.leaveItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package net.crankedpvp.events.game.games;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.game.MiniGame;
|
||||
import net.crankedpvp.events.game.MiniGameOptions;
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import net.crankedpvp.events.game.MiniGameType;
|
||||
import net.crankedpvp.events.game.players.SpleefPlayer;
|
||||
import net.crankedpvp.events.game.tasks.MiniGameCountDown;
|
||||
import net.crankedpvp.events.game.tasks.MiniGameFlyDisableTask;
|
||||
import net.crankedpvp.events.utils.BlockUtil;
|
||||
import net.crankedpvp.events.utils.Pair;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class SpleefMiniGame extends MiniGame<SpleefPlayer> {
|
||||
|
||||
private final EventsPlugin plugin;
|
||||
private final List<Pair<Location, Location>> platformCorners;
|
||||
|
||||
protected SpleefMiniGame(EventsPlugin plugin) {
|
||||
super(plugin,
|
||||
MiniGameType.SPLEEF,
|
||||
new HashMap<>(),
|
||||
MiniGameOptions.builder()
|
||||
.blockBreak(true)
|
||||
.itemPickUp(true)
|
||||
.build(),
|
||||
Material.SNOW_BALL
|
||||
);
|
||||
this.plugin = plugin;
|
||||
this.platformCorners = new ArrayList<>();
|
||||
|
||||
ConfigurationSection platformCornersConfigSection = this.getConfiguration().getConfigurationSection("minigame.platform-corners");
|
||||
|
||||
platformCornersConfigSection.getKeys(false).forEach(str -> {
|
||||
Location cornerOne = super.getLocationFromConfig(platformCornersConfigSection.getConfigurationSection(str + ".corner-one"));
|
||||
Location cornerTwo = super.getLocationFromConfig(platformCornersConfigSection.getConfigurationSection(str + ".corner-two"));
|
||||
Pair<Location, Location> corners = new Pair<>(cornerOne, cornerTwo);
|
||||
this.platformCorners.add(corners);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMiniGame() {
|
||||
super.setMiniGameState(MiniGameState.IN_PROGRESS);
|
||||
|
||||
super.getParticipants().forEach(((uuid, spleefPlayer) -> {
|
||||
Utils.sendTitle(spleefPlayer.getPlayer(), CC.Aqua + "Start!", "", 10, 40, 10);
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMiniGameCountDown() {
|
||||
super.setMiniGameState(MiniGameState.STARTING);
|
||||
new MiniGameCountDown(this).runTaskTimer(plugin, 0L, 20L);
|
||||
new MiniGameFlyDisableTask(this).runTaskTimer(plugin, 0L, 10L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMiniGame() {
|
||||
super.getParticipants().forEach((player, participant) -> {
|
||||
this.leaveMiniGame(participant.getPlayer(), true);
|
||||
});
|
||||
|
||||
super.clearParticipants();
|
||||
super.setMiniGameState(MiniGameState.NOT_STARTED);
|
||||
this.fixAllPlatforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinMiniGame(Player player) {
|
||||
if (isParticipant(player)) return;
|
||||
super.addParticipant(new SpleefPlayer(player));
|
||||
player.teleport(super.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
player.setHealth(20);
|
||||
player.setFoodLevel(20);
|
||||
super.clearPotionEffects(player);
|
||||
super.clearInventory(player);
|
||||
player.setAllowFlight(false);
|
||||
player.setFlying(false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void leaveMiniGame(Player player) {
|
||||
if (this.getParticipants().size() <= 1 && this.getMiniGameState() == MiniGameState.IN_PROGRESS) {
|
||||
this.stopMiniGame();
|
||||
return;
|
||||
}
|
||||
|
||||
this.leaveMiniGame(player, false);
|
||||
}
|
||||
|
||||
private void leaveMiniGame(Player player, boolean stopMiniGame) {
|
||||
if (!isParticipant(player) && !isSpectator(player)) return;
|
||||
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.teleport(Bukkit.getWorld("world").getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
player.setWalkSpeed((float) 0.2);
|
||||
super.clearInventory(player);
|
||||
super.clearPotionEffects(player);
|
||||
|
||||
if (super.isParticipant(player)) {
|
||||
super.getParticipant(player).getPlayerInventoryContents().restore(player);
|
||||
}
|
||||
|
||||
if (stopMiniGame) return;
|
||||
|
||||
if (isParticipant(player)) {
|
||||
super.removeParticipant(player);
|
||||
}
|
||||
|
||||
//TODO: finish spleef, choose winner
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamageWhileInSpleef(EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) return;
|
||||
if (!super.isParticipant((Player) event.getEntity())) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreakWhileSpleefIsStarting(BlockBreakEvent event) {
|
||||
if (!super.isParticipant(event.getPlayer())) return;
|
||||
if (super.getMiniGameState() != MiniGameState.IN_PROGRESS) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private void fixAllPlatforms() {
|
||||
for (Pair<Location, Location> locationPair : this.platformCorners) {
|
||||
this.fixPlatform(locationPair.getLeft(), locationPair.getRight());
|
||||
}
|
||||
}
|
||||
|
||||
private void fixPlatform(Location cornerOne, Location cornerTwo) {
|
||||
final int y = (int) cornerOne.getY();
|
||||
|
||||
for (int i = (int) cornerOne.getX(); i < cornerTwo.getX(); i++) {
|
||||
for (int j = (int) cornerOne.getZ(); j < cornerTwo.getZ(); j++) {
|
||||
BlockUtil.setBlockFast(this.getGameWorld(), i, y, j, 80, (byte) 0, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
package net.crankedpvp.events.game.games;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.game.MiniGame;
|
||||
import net.crankedpvp.events.game.MiniGameOptions;
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import net.crankedpvp.events.game.MiniGameType;
|
||||
import net.crankedpvp.events.game.players.SumoPlayer;
|
||||
import net.crankedpvp.events.utils.Pair;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import net.crankedpvp.events.game.tasks.*;
|
||||
import org.apache.commons.collections4.map.LinkedMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class SumoMiniGame extends MiniGame<SumoPlayer> {
|
||||
|
||||
@Getter
|
||||
private final Location fightLocationOne;
|
||||
@Getter
|
||||
private final Location fightLocationTwo;
|
||||
private final EventsPlugin plugin;
|
||||
@Getter
|
||||
private final Pair<SumoPlayer, SumoPlayer> duelPlayers;
|
||||
private final Map<UUID, SumoPlayer> tempMap;
|
||||
|
||||
public SumoMiniGame(EventsPlugin plugin) {
|
||||
super(plugin, MiniGameType.SUMO, new LinkedMap<>(), MiniGameOptions.builder().excludedBlockedCommands(new String[]{"sumo"}).build(), Material.STICK);
|
||||
this.plugin = plugin;
|
||||
this.duelPlayers = new Pair<>(null, null);
|
||||
this.tempMap = new HashMap<>();
|
||||
|
||||
ConfigurationSection fightLocationOneSection = super.getConfiguration().getConfigurationSection("fight-location-one");
|
||||
Optional<Location> possibleFightLocationOne = Optional.of(super.getLocationFromConfig(fightLocationOneSection));
|
||||
|
||||
this.fightLocationOne = possibleFightLocationOne.orElseThrow(() -> new IllegalArgumentException("Invalid fight one location"));
|
||||
|
||||
ConfigurationSection fightLocationTwoSection = super.getConfiguration().getConfigurationSection("fight-location-two");
|
||||
Optional<Location> possibleFightLocationTwo = Optional.of(super.getLocationFromConfig(fightLocationTwoSection));
|
||||
|
||||
this.fightLocationTwo = possibleFightLocationTwo.orElseThrow(() -> new IllegalArgumentException("Invalid fight two location"));;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMiniGame() {
|
||||
super.setMiniGameState(MiniGameState.IN_PROGRESS);
|
||||
this.fight();
|
||||
new SumoDeathCheckTask(this).runTaskTimer(plugin, 0L, 20L);
|
||||
new SpectatorTeleportBackTask(this).runTaskTimer(plugin, 0L, 20L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMiniGameCountDown() {
|
||||
super.setMiniGameState(MiniGameState.STARTING);
|
||||
new MiniGameCountDown(this).runTaskTimer(plugin, 0L, 20L);
|
||||
new MiniGameFlyDisableTask(this).runTaskTimer(plugin, 0L, 10L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMiniGame() {
|
||||
super.getParticipants().forEach((player, participant) -> {
|
||||
this.leaveMiniGame(participant.getPlayer(), true);
|
||||
});
|
||||
|
||||
super.getSpectators().forEach(spectator -> {
|
||||
this.leaveMiniGame(spectator.getPlayer(), true);
|
||||
});
|
||||
|
||||
super.clearParticipants();
|
||||
super.clearSpectators();
|
||||
super.setMiniGameState(MiniGameState.NOT_STARTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinMiniGame(Player player) {
|
||||
if (isParticipant(player)) return;
|
||||
super.addParticipant(new SumoPlayer(player));
|
||||
player.teleport(super.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
player.setHealth(20);
|
||||
player.setFoodLevel(20);
|
||||
super.clearPotionEffects(player);
|
||||
super.clearInventory(player);
|
||||
player.setAllowFlight(false);
|
||||
player.setFlying(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leaveMiniGame(Player player) {
|
||||
if (this.getParticipants().size() <= 1 && this.getMiniGameState() == MiniGameState.IN_PROGRESS) {
|
||||
this.stopMiniGame();
|
||||
return;
|
||||
}
|
||||
this.leaveMiniGame(player, false);
|
||||
}
|
||||
|
||||
private void leaveMiniGame(Player player, boolean stopMiniGame) {
|
||||
if (!isParticipant(player) && !isSpectator(player)) return;
|
||||
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.teleport(Bukkit.getWorld("world").getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
player.setWalkSpeed((float) 0.2);
|
||||
super.clearInventory(player);
|
||||
super.clearPotionEffects(player);
|
||||
|
||||
if (super.isParticipant(player)) {
|
||||
super.getParticipant(player).getPlayerInventoryContents().restore(player);
|
||||
}
|
||||
|
||||
if (super.isSpectator(player)) {
|
||||
Optional<SumoPlayer> sumoPlayer = super.getSpectator(player);
|
||||
sumoPlayer.ifPresent(participant -> participant.getPlayerInventoryContents().restore(player));
|
||||
}
|
||||
|
||||
if (stopMiniGame) return;
|
||||
|
||||
if (isParticipant(player)) {
|
||||
super.removeParticipant(player);
|
||||
}
|
||||
|
||||
if (isSpectator(player)) {
|
||||
super.removeSpectator(player);
|
||||
}
|
||||
|
||||
if (this.isInDuel(player)) {
|
||||
this.choseWinner(this.getOpposingPlayer(player).getPlayer(), player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamageWhileInGame(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) return;
|
||||
if (!(event.getDamager() instanceof Player)) return;
|
||||
if (!isParticipant((Player) event.getEntity())) return;
|
||||
if (!isParticipant((Player) event.getDamager())) return;
|
||||
|
||||
if (super.getMiniGameState() == MiniGameState.STARTING) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (super.getMiniGameState() == MiniGameState.IN_PROGRESS) {
|
||||
event.setDamage(0.0);
|
||||
}
|
||||
|
||||
if (!this.isInDuel(super.getParticipant((Player) event.getEntity()))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void choseWinner(Player winner, Player loser) {
|
||||
this.getDuelPlayers().clear();
|
||||
|
||||
if (loser.isOnline()) {
|
||||
SumoPlayer sumoPlayer = super.getParticipant(loser);
|
||||
this.addSpectator(sumoPlayer);
|
||||
}
|
||||
|
||||
if (this.getParticipants().size() <= 1) {
|
||||
this.stopMiniGame();
|
||||
this.giveWinnerRewards(winner);
|
||||
Bukkit.broadcastMessage(Utils.color(super.getConfiguration().getString("win-message").replace("{player}", winner.getName())));
|
||||
return;
|
||||
}
|
||||
|
||||
winner.teleport(this.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
|
||||
this.nextFight();
|
||||
}
|
||||
|
||||
public void fight() {
|
||||
this.duelPlayers.setLeft(this.getParticipantsQueue().getValue(0));
|
||||
this.duelPlayers.setRight(this.getParticipantsQueue().getValue(1));
|
||||
|
||||
this.duelPlayers.getLeft().getPlayer().setAllowFlight(false);
|
||||
this.duelPlayers.getLeft().getPlayer().setFlying(false);
|
||||
|
||||
this.duelPlayers.getRight().getPlayer().setAllowFlight(false);
|
||||
this.duelPlayers.getRight().getPlayer().setFlying(false);
|
||||
|
||||
this.duelPlayers.getLeft().getPlayer().teleport(fightLocationOne, PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
this.duelPlayers.getRight().getPlayer().teleport(fightLocationTwo, PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
new SumoStartDuelTask(this).runTaskTimer(plugin, 10, 10);
|
||||
}
|
||||
|
||||
public void nextFight() {
|
||||
this.moveToEndOfQueue();
|
||||
this.moveToEndOfQueue();
|
||||
|
||||
this.fight();
|
||||
}
|
||||
|
||||
public void moveToEndOfQueue() {
|
||||
this.tempMap.put(this.getParticipantsQueue().get(0), this.getParticipantsQueue().getValue(0));
|
||||
this.getParticipantsQueue().remove(0);
|
||||
this.getParticipants().putAll(this.tempMap);
|
||||
this.tempMap.clear();
|
||||
}
|
||||
|
||||
public boolean isInDuel(SumoPlayer sumoPlayer) {
|
||||
return this.duelPlayers.contains(sumoPlayer);
|
||||
}
|
||||
|
||||
public SumoPlayer getOpposingPlayer(SumoPlayer sumoPlayer) {
|
||||
return this.getOpposingPlayer(sumoPlayer.getPlayer());
|
||||
}
|
||||
|
||||
public SumoPlayer getOpposingPlayer(Player player) {
|
||||
if (!this.isInDuel(player)) return null;
|
||||
return player.equals(this.duelPlayers.getLeft().getPlayer()) ? this.duelPlayers.getRight() : this.duelPlayers.getLeft();
|
||||
}
|
||||
|
||||
public boolean isInDuel(Player sumoPlayer) {
|
||||
if (this.duelPlayers.getLeft() == null) return false;
|
||||
if (this.duelPlayers.getRight() == null) return false;
|
||||
return this.duelPlayers.getLeft().getPlayer().equals(sumoPlayer) || this.duelPlayers.getRight().getPlayer().equals(sumoPlayer);
|
||||
}
|
||||
|
||||
public LinkedMap<UUID, SumoPlayer> getParticipantsQueue() {
|
||||
return ((LinkedMap<UUID, SumoPlayer>) super.getParticipants());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.crankedpvp.events.game.players;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.crankedpvp.events.game.MiniGamePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Getter
|
||||
public class ParkourPlayer extends MiniGamePlayer {
|
||||
|
||||
@Setter
|
||||
private Byte currentCheckpoint;
|
||||
|
||||
public ParkourPlayer(Player player) {
|
||||
super(player);
|
||||
this.currentCheckpoint = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.crankedpvp.events.game.players;
|
||||
|
||||
import net.crankedpvp.events.game.MiniGamePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SpleefPlayer extends MiniGamePlayer {
|
||||
public SpleefPlayer(Player player) {
|
||||
super(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.crankedpvp.events.game.players;
|
||||
|
||||
import net.crankedpvp.events.game.MiniGamePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SumoPlayer extends MiniGamePlayer {
|
||||
public SumoPlayer(Player player) {
|
||||
super(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.crankedpvp.events.game.tasks;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.crankedpvp.events.game.MiniGameManager;
|
||||
import net.crankedpvp.events.game.MiniGameRegister;
|
||||
import net.crankedpvp.events.game.MiniGameType;
|
||||
import net.crankedpvp.events.game.MiniGame;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class AutoMiniGameTask extends BukkitRunnable {
|
||||
|
||||
private final MiniGameManager miniGameManager;
|
||||
private final MiniGameRegister miniGameRegister;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (Bukkit.getOnlinePlayers().size() == 0) {
|
||||
Bukkit.getConsoleSender().sendMessage("&6[AstroEvents] Not enough online players to start the event");
|
||||
this.miniGameManager.setLastMiniGameTime(System.currentTimeMillis());
|
||||
return;
|
||||
}
|
||||
|
||||
MiniGameType nextMiniGame = this.miniGameManager.getNextMiniGame();
|
||||
MiniGame<?> miniGame = this.miniGameRegister.getMiniGame(nextMiniGame);
|
||||
if (miniGame == null) {
|
||||
this.miniGameManager.setLastMiniGameTime(System.currentTimeMillis());
|
||||
return;
|
||||
}
|
||||
miniGame.startMiniGameCountDown();
|
||||
this.miniGameManager.setLastMiniGameTime(System.currentTimeMillis());
|
||||
this.miniGameManager.setPreviousMiniGame(nextMiniGame);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package net.crankedpvp.events.game.tasks;
|
||||
|
||||
import net.crankedpvp.events.game.MiniGame;
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class MiniGameCountDown extends BukkitRunnable {
|
||||
|
||||
private final MiniGame<?> miniGame;
|
||||
private int countdown;
|
||||
private int disableCountdown;
|
||||
|
||||
public MiniGameCountDown(MiniGame<?> miniGame) {
|
||||
this.miniGame = miniGame;
|
||||
this.countdown = miniGame.getCountdownTime();
|
||||
this.disableCountdown = 300;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (miniGame.getMiniGameState() != MiniGameState.STARTING) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (disableCountdown <= 0) {
|
||||
this.miniGame.stopMiniGame();
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (countdown == this.miniGame.getCountdownTime() || countdown == 120 || countdown == 60 || countdown == 45 || countdown == 30 || countdown == 15 || countdown == 10 || countdown == 5 || countdown == 3 || countdown == 2 || countdown == 1)
|
||||
Bukkit.broadcastMessage(this.miniGame.getCountdownMessage().replace("{time}", countdown + "s"));
|
||||
|
||||
if (countdown == 1) {
|
||||
if (this.miniGame.getParticipants().size() >= this.miniGame.getMinPlayers()) {
|
||||
this.miniGame.startMiniGame();
|
||||
this.cancel();
|
||||
return;
|
||||
} else {
|
||||
countdown = this.miniGame.getCountdownTime() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
countdown--;
|
||||
disableCountdown--;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.crankedpvp.events.game.tasks;
|
||||
|
||||
import net.crankedpvp.events.game.MiniGame;
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class MiniGameFlyDisableTask extends BukkitRunnable {
|
||||
|
||||
private final MiniGame<?> miniGame;
|
||||
|
||||
public MiniGameFlyDisableTask(MiniGame<?> miniGame) {
|
||||
this.miniGame = miniGame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.miniGame.getMiniGameState() == MiniGameState.NOT_STARTED) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
this.miniGame.getParticipants().forEach((uuid, t) -> {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player.getAllowFlight() && !player.isOp()) {
|
||||
player.setAllowFlight(false);
|
||||
}
|
||||
if (player.isFlying() && !player.isOp()) {
|
||||
player.setFlying(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.crankedpvp.events.game.tasks;
|
||||
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import net.crankedpvp.events.game.games.ParkourMiniGame;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class ParkourTimeTask extends BukkitRunnable {
|
||||
|
||||
private final ParkourMiniGame miniGame;
|
||||
|
||||
public ParkourTimeTask(ParkourMiniGame miniGame) {
|
||||
this.miniGame = miniGame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (miniGame.getMiniGameState() != MiniGameState.IN_PROGRESS || miniGame.getParticipants().isEmpty()) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
String time = Utils.getTimeFromSecsToMins((System.currentTimeMillis() - miniGame.getStartTime()) / 1000);
|
||||
|
||||
miniGame.getParticipants().forEach((player, parkourPlayer) -> {
|
||||
Utils.sendActionBarMessage(parkourPlayer.getPlayer(), Utils.color(miniGame.getParkourTimeMessage().replace("{time}", time)));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.crankedpvp.events.game.tasks;
|
||||
|
||||
import net.crankedpvp.events.game.MiniGame;
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class SpectatorTeleportBackTask extends BukkitRunnable {
|
||||
|
||||
private final MiniGame<?> game;
|
||||
|
||||
public SpectatorTeleportBackTask(MiniGame<?> game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.game.getMiniGameState() == MiniGameState.NOT_STARTED) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
this.game.getSpectators().forEach(spectator -> {
|
||||
if (spectator.getPlayer() == null) {
|
||||
return;
|
||||
}
|
||||
if (!spectator.getPlayer().getWorld().getName().equals(this.game.getGameWorld().getName())) return;
|
||||
if (this.game.getSpawnLocation().distance(spectator.getPlayer().getLocation()) > 200)
|
||||
spectator.getPlayer().teleport(this.game.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.crankedpvp.events.game.tasks;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import net.crankedpvp.events.game.games.SpleefMiniGame;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class SpleefDeathCheckTask extends BukkitRunnable {
|
||||
|
||||
private final SpleefMiniGame miniGame;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.miniGame.getMiniGameState() != MiniGameState.IN_PROGRESS) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
this.miniGame.getParticipants().forEach((uuid, spleefPlayer) -> {
|
||||
if (isPlayerInWater(spleefPlayer.getPlayer())) {
|
||||
this.miniGame.leaveMiniGame(spleefPlayer.getPlayer());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isPlayerInWater(Player spleefPlayer) {
|
||||
Material material = spleefPlayer.getLocation().getBlock().getType();
|
||||
return material == Material.WATER || material == Material.STATIONARY_WATER;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.crankedpvp.events.game.tasks;
|
||||
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import net.crankedpvp.events.game.games.SumoMiniGame;
|
||||
import net.crankedpvp.events.game.players.SumoPlayer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class SumoDeathCheckTask extends BukkitRunnable {
|
||||
|
||||
private final SumoMiniGame miniGame;
|
||||
|
||||
public SumoDeathCheckTask(SumoMiniGame miniGame) {
|
||||
this.miniGame = miniGame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.miniGame.getMiniGameState() != MiniGameState.IN_PROGRESS) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.miniGame.getDuelPlayers().getLeft() == null || miniGame.getDuelPlayers().getRight() == null) return;
|
||||
if (this.miniGame.getDuelPlayers().getLeft().getPlayer() == null || miniGame.getDuelPlayers().getRight().getPlayer() == null) return;
|
||||
if (!this.miniGame.getDuelPlayers().getLeft().getPlayer().isOnline() || !this.miniGame.getDuelPlayers().getLeft().getPlayer().isOnline()) return;
|
||||
|
||||
if (this.isPlayerInWater(this.miniGame.getDuelPlayers().getLeft())) {
|
||||
this.miniGame.choseWinner(this.miniGame.getDuelPlayers().getRight().getPlayer(), this.miniGame.getDuelPlayers().getLeft().getPlayer());
|
||||
}
|
||||
|
||||
if (this.isPlayerInWater(this.miniGame.getDuelPlayers().getRight())) {
|
||||
this.miniGame.choseWinner(this.miniGame.getDuelPlayers().getLeft().getPlayer(), this.miniGame.getDuelPlayers().getRight().getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPlayerInWater(SumoPlayer sumoPlayer) {
|
||||
Material material = sumoPlayer.getPlayer().getLocation().getBlock().getType();
|
||||
return material == Material.WATER || material == Material.STATIONARY_WATER;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.crankedpvp.events.game.tasks;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import net.crankedpvp.events.game.games.SumoMiniGame;
|
||||
import net.crankedpvp.events.game.players.SumoPlayer;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class SumoStartDuelTask extends BukkitRunnable {
|
||||
|
||||
private final SumoMiniGame miniGame;
|
||||
private int countdown;
|
||||
private final SumoPlayer left;
|
||||
private final SumoPlayer right;
|
||||
|
||||
public SumoStartDuelTask(SumoMiniGame miniGame) {
|
||||
this.miniGame = miniGame;
|
||||
this.countdown = 5;
|
||||
this.left = this.miniGame.getDuelPlayers().getLeft();
|
||||
this.right = this.miniGame.getDuelPlayers().getRight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.miniGame.getMiniGameState() != MiniGameState.IN_PROGRESS) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.miniGame.getDuelPlayers().getLeft() == null || miniGame.getDuelPlayers().getRight() == null) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.countdown <= 0) {
|
||||
Utils.sendTitle(left.getPlayer(), CC.YellowB + "GO!", "", 10, 40, 10);
|
||||
Utils.sendTitle(right.getPlayer(), CC.YellowB + "GO!", "", 10, 40, 10);
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
left.getPlayer().teleport(this.miniGame.getFightLocationOne(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
right.getPlayer().teleport(this.miniGame.getFightLocationTwo(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
|
||||
String color = countdown >= 4 ? CC.GreenB : CC.RedB;
|
||||
|
||||
Utils.sendTitle(left.getPlayer(), color + countdown, "", 10, 40, 10);
|
||||
Utils.sendTitle(right.getPlayer(), color + countdown, "", 10, 40, 10);
|
||||
|
||||
this.countdown--;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package net.crankedpvp.events.inventories;
|
||||
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.utils.TimeUtils;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.pvptop.data.FactionData;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CerberusInventory {
|
||||
|
||||
|
||||
@Getter
|
||||
private ItemStack cerberusItemStack;
|
||||
|
||||
@Getter
|
||||
private final EventsPlugin plugin;
|
||||
|
||||
private final Gui cerberusInventory;
|
||||
|
||||
public Gui getUI() {
|
||||
return this.cerberusInventory;
|
||||
}
|
||||
|
||||
public CerberusInventory(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.cerberusInventory = new Gui(3, "Cerberus");
|
||||
this.cerberusInventory.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
|
||||
this.buildCerberusItem();
|
||||
|
||||
ItemStack howToPlay = new ItemBuilder(Material.SIGN, "&b&lHow to Play?",
|
||||
""
|
||||
).colorize().build();
|
||||
|
||||
|
||||
ItemStack viewAllEvents = new ItemBuilder(Material.ARROW, "&d&lAll Events",
|
||||
"&fClick here to view all of the",
|
||||
"&fevents currently active on Cranked"
|
||||
).colorize().build();
|
||||
this.cerberusInventory.setItem(2, 5, new GuiItem(this.getCerberusItemStack()));
|
||||
this.cerberusInventory.setItem(2, 3, new GuiItem(howToPlay));
|
||||
this.cerberusInventory.setItem(2, 7, new GuiItem(viewAllEvents, event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
if(event.getWhoClicked() instanceof Player) {
|
||||
((Player)event.getWhoClicked()).performCommand("events");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private String getNextCerberusString() {
|
||||
return this.plugin.getCerberusManager().isActive() ? "Now" : TimeUtils.formatMillisecondsInFull(this.plugin.getTimeUntilNextCerberus());
|
||||
}
|
||||
|
||||
private String getActiveString() {
|
||||
return this.plugin.getCerberusManager().isActive() ? "&a&lACTIVE" : "&c&lINACTIVE";
|
||||
}
|
||||
|
||||
|
||||
public void updateInformationItem() {
|
||||
this.buildCerberusItem();
|
||||
this.cerberusInventory.updateItem(2, 5, new GuiItem(this.getCerberusItemStack()));
|
||||
}
|
||||
|
||||
public void buildCerberusItem() {
|
||||
this.cerberusItemStack = new ItemBuilder(Material.MONSTER_EGG, "&6&lCerberus &7(Information)",
|
||||
"&fThe Cerberus is the most challenging",
|
||||
"&fboss on Cranked. Group up with your",
|
||||
"&ffaction to take it on. It is difficult!",
|
||||
"",
|
||||
"&6Information:",
|
||||
" &f• Located in the &6Warzone",
|
||||
" &f• Cerberus has &61,000 HP",
|
||||
"",
|
||||
"&6Rewards &7(Upon capture)",
|
||||
" &f• 3x Cerberus Lootbags",
|
||||
" &f• Gain &6+" + FactionData.Points.CERBERUS_KILLED.getPoints() + " &fFaction Points",
|
||||
"",
|
||||
"&6Cerberus:",
|
||||
" &f• Event Status: " + this.getActiveString(),
|
||||
" &f• Next Event: &a" + this.getNextCerberusString(),
|
||||
" &f• Killed Last: &6" + this.getLastFactionWon()
|
||||
).colorize().build();
|
||||
}
|
||||
|
||||
private String getLastFactionWon() {
|
||||
return (this.plugin.getCerberusManager().getLastFactionCaptured() == null || !this.plugin.getCerberusManager().getLastFactionCaptured().isNormal()) ? "None" : this.plugin.getCerberusManager().getLastFactionCaptured().getTag();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package net.crankedpvp.events.inventories;
|
||||
|
||||
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.utils.TimeUtils;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.pvptop.data.FactionData;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CitadelInventory {
|
||||
|
||||
@Getter
|
||||
private ItemStack citadelItemStack;
|
||||
|
||||
@Getter
|
||||
private final EventsPlugin plugin;
|
||||
|
||||
private final Gui citadelInventory;
|
||||
|
||||
public Gui getUI() {
|
||||
return this.citadelInventory;
|
||||
}
|
||||
|
||||
public CitadelInventory(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.citadelInventory = new Gui(3, "Citadel");
|
||||
this.citadelInventory.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
|
||||
this.buildCitadelItem();
|
||||
|
||||
ItemStack howToPlay = new ItemBuilder(Material.SIGN, "&b&lHow to Play?",
|
||||
"&fThis is a competitive event which will",
|
||||
"&fstart twice per day, where factions compete",
|
||||
"&fto control, and destroy the chest",
|
||||
"",
|
||||
"&fThe objective is to destroy the chest,",
|
||||
"&fhowever you can &c&lONLY &fbreak the",
|
||||
"&fchest if your faction is the only faction",
|
||||
"&finside of the capture zone which surrounds",
|
||||
"&fthe dead mans chest.",
|
||||
"",
|
||||
"&fYour faction must work together to clear",
|
||||
"&fenemy players from the capture zone before",
|
||||
"&fyou can attempt to break the chest."
|
||||
).colorize().build();
|
||||
|
||||
|
||||
ItemStack viewAllEvents = new ItemBuilder(Material.ARROW, "&d&lAll Events",
|
||||
"&fClick here to view all of the",
|
||||
"&fevents currently active on Cranked"
|
||||
).colorize().build();
|
||||
this.citadelInventory.setItem(2, 5, new GuiItem(this.getCitadelItemStack()));
|
||||
this.citadelInventory.setItem(2, 3, new GuiItem(howToPlay));
|
||||
this.citadelInventory.setItem(2, 7, new GuiItem(viewAllEvents, event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
if(event.getWhoClicked() instanceof Player) {
|
||||
((Player)event.getWhoClicked()).performCommand("events");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private String getNextCitadelString() {
|
||||
return this.plugin.getCitadelManager().isActive() ? "Now" : TimeUtils.formatMillisecondsInFull(this.plugin.getTimeUntilNextCitadel());
|
||||
}
|
||||
|
||||
private String getActiveString() {
|
||||
return this.plugin.getCitadelManager().isActive() ? "&a&lACTIVE" : "&c&lINACTIVE";
|
||||
}
|
||||
|
||||
|
||||
public void updateInformationItem() {
|
||||
this.buildCitadelItem();
|
||||
this.citadelInventory.updateItem(2, 5, new GuiItem(this.getCitadelItemStack()));
|
||||
}
|
||||
|
||||
public void buildCitadelItem() {
|
||||
this.citadelItemStack = new ItemBuilder(Material.BEACON, "&e&lCitadel &7(Information)",
|
||||
"&fOne of the most competitive events on",
|
||||
"&fCranked. Similar to a KOTH, team up with",
|
||||
"&fyour faction to take control of the capture",
|
||||
"&fzone located at /warp citadel.",
|
||||
"",
|
||||
"&eInformation:",
|
||||
" &f• Located at &e/warp citadel",
|
||||
" &f• Capture Time is &e10 Minutes",
|
||||
" &f• Ender Pearls are &cdisabled &fat this event",
|
||||
" &f• Enchants are &cdisabled &fat this event",
|
||||
" &f• Masks are &cdisabled &fat this event",
|
||||
" &f• Pets are &cdisabled &fat this event",
|
||||
" &f• Star Items are &cdisabled &fat this event",
|
||||
" &f• Armor Sets are &cdisabled &fat this event",
|
||||
" &f• Bard Sets are &aenabled &fat this event",
|
||||
"",
|
||||
"&eRewards &7(Upon capture)",
|
||||
" &f• 5x Citadel Lootbags",
|
||||
" &f• Gain &e+" + FactionData.Points.CITADEL_CAPTURE.getPoints() + " &fFaction Points",
|
||||
"",
|
||||
"&eRewards &7(Until next capture)",
|
||||
" &f• Grinding EXP Multiplier &7(2.25x)",
|
||||
" &f• Underworld EXP Multiplier &7(1.25x)",
|
||||
" &f• Underworld Chest Loot Multiplier &7(1.25x)",
|
||||
"",
|
||||
"&eCitadel:",
|
||||
" &f• Event Status: " + this.getActiveString(),
|
||||
" &f• Next Event: &a" + this.getNextCitadelString(),
|
||||
" &f• Captured Last: &e" + this.getLastFactionWon()
|
||||
).colorize().build();
|
||||
}
|
||||
|
||||
private String getLastFactionWon() {
|
||||
return (this.plugin.getCitadelManager().getLastFactionCaptured() == null || !this.plugin.getCitadelManager().getLastFactionCaptured().isNormal()) ? "None" : this.plugin.getCitadelManager().getLastFactionCaptured().getTag();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package net.crankedpvp.events.inventories;
|
||||
|
||||
import com.golfing8.kore.FactionsKore;
|
||||
import com.golfing8.kore.feature.KothFeature;
|
||||
import com.golfing8.kore.object.Koth;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.deadmanschest.DeadmansChestPlugin;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.utils.item.ItemBuilder;
|
||||
import net.crankedpvp.pvptop.data.FactionData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EventsInventory {
|
||||
|
||||
private EventsPlugin plugin;
|
||||
|
||||
@Getter
|
||||
private final Gui newEventsUI;
|
||||
|
||||
public EventsInventory(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.newEventsUI = new Gui(1, "Cranked Events");
|
||||
this.newEventsUI.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
|
||||
this.addAndScheduleCerberusItemStack();
|
||||
this.addAndScheduleWarpKothItemStack();
|
||||
this.addAndScheduleCitadelItemStack();
|
||||
this.addAndScheduleDeadMansChestItemStack();
|
||||
this.addKothItemStack();
|
||||
|
||||
}
|
||||
|
||||
private void addAndScheduleDeadMansChestItemStack() {
|
||||
this.newEventsUI.setItem(1, 3, new GuiItem(DeadmansChestPlugin.getInstance().getDeadmansChestInventory().getDeadMansChestItemStack(), event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
DeadmansChestPlugin.getInstance().getDeadmansChestInventory().getUI().open(event.getWhoClicked());
|
||||
}));
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> this.newEventsUI.updateItem(1, 3, new GuiItem(DeadmansChestPlugin.getInstance().getDeadmansChestInventory().getDeadMansChestItemStack(), event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
DeadmansChestPlugin.getInstance().getDeadmansChestInventory().getUI().open(event.getWhoClicked());
|
||||
})), 20L, 20L);
|
||||
}
|
||||
|
||||
private void addAndScheduleCitadelItemStack() {
|
||||
this.newEventsUI.setItem(1, 5, new GuiItem(EventsPlugin.getInstance().getCitadelInventory().getCitadelItemStack(), event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
EventsPlugin.getInstance().getCitadelInventory().getUI().open(event.getWhoClicked());
|
||||
}));
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> this.newEventsUI.updateItem(1, 5, new GuiItem(EventsPlugin.getInstance().getCitadelInventory().getCitadelItemStack(), event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
EventsPlugin.getInstance().getCitadelInventory().getUI().open(event.getWhoClicked());
|
||||
})), 20L, 20L);
|
||||
}
|
||||
|
||||
private void addAndScheduleWarpKothItemStack() {
|
||||
this.newEventsUI.setItem(1, 1, new GuiItem(EventsPlugin.getInstance().getWarpKothInventory().getWarpKothItemstack(), event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
EventsPlugin.getInstance().getWarpKothInventory().getUI().open(event.getWhoClicked());
|
||||
}));
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> this.newEventsUI.updateItem(1, 1, new GuiItem(EventsPlugin.getInstance().getWarpKothInventory().getWarpKothItemstack(), event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
EventsPlugin.getInstance().getWarpKothInventory().getUI().open(event.getWhoClicked());
|
||||
})), 20L, 20L);
|
||||
}
|
||||
|
||||
private void addAndScheduleCerberusItemStack() {
|
||||
this.newEventsUI.setItem(1, 7, new GuiItem(EventsPlugin.getInstance().getCerberusInventory().getCerberusItemStack(), event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
EventsPlugin.getInstance().getCerberusInventory().getUI().open(event.getWhoClicked());
|
||||
}));
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> this.newEventsUI.updateItem(1, 7, new GuiItem(EventsPlugin.getInstance().getCerberusInventory().getCerberusItemStack(), event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
EventsPlugin.getInstance().getCerberusInventory().getUI().open(event.getWhoClicked());
|
||||
})), 20L, 20L);
|
||||
}
|
||||
|
||||
private void addKothItemStack() {
|
||||
this.newEventsUI.setItem(1, 9, new GuiItem(this.buildKothItemStack(), event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
if(event.getWhoClicked() instanceof Player) {
|
||||
((Player)event.getWhoClicked()).performCommand("koth gui");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void updateKothItem() {
|
||||
this.newEventsUI.updateItem(1, 9, new GuiItem(this.buildKothItemStack(), event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
if(event.getWhoClicked() instanceof Player) {
|
||||
((Player)event.getWhoClicked()).performCommand("koth gui");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private ItemStack buildKothItemStack() {
|
||||
return new ItemBuilder(Material.WOOL, 1, DyeColor.RED.getWoolData(), "&c&lKing of the Hill",
|
||||
"&fCapture a zone for a certain amount of",
|
||||
"&ftime without leaving the zone to become",
|
||||
"&fthe King of the Hill with your team.",
|
||||
"",
|
||||
"&cInformation:",
|
||||
" &f• First player on the &cZone &fis the Capper",
|
||||
" &f• Capper leaving the Zone &cresets &fprogress",
|
||||
" &f• Multiple &cKOTH &flocations.",
|
||||
"",
|
||||
"&cRewards:",
|
||||
" &f• 1x KOTH Lootbag",
|
||||
" &f• 1x Random KOTH Piece",
|
||||
" &f• 1x Gain &c+" + FactionData.Points.KOTH_CAPTURE.getPoints() + " &fFaction Points",
|
||||
"",
|
||||
"&cKoth Event",
|
||||
" &f• Status: " + getKothIsActive(),
|
||||
" &f• Koth Schedule: &cEvery 2 Hours"
|
||||
).colorize().build();
|
||||
}
|
||||
|
||||
private String getKothIsActive() {
|
||||
for(Koth koth : FactionsKore.get().getFeature(KothFeature.class).getKoths()) {
|
||||
if(koth.isActive()) return "&a&lACTIVE &7(" + koth.getName() + "&7)";
|
||||
}
|
||||
return "&c&lINACTIVE";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.crankedpvp.events.inventories;
|
||||
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import dev.triumphteam.gui.guis.PaginatedGui;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.game.MiniGame;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import net.crankedpvp.events.utils.item.ItemBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class LootPreviewUI {
|
||||
@Getter
|
||||
private final PaginatedGui eventsUI;
|
||||
|
||||
@SneakyThrows
|
||||
public LootPreviewUI(EventsPlugin plugin, Player player, MiniGame miniGame) {
|
||||
this.eventsUI = new PaginatedGui(1, 9, Utils.toNiceString(miniGame.getMiniGameType().name()) + " Loot Preview");
|
||||
|
||||
this.eventsUI.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
/*Optional<ItemStack> mysteryChest = Optional.of(miniGame.getMysteryChest().createClaimableItem(false)) ;
|
||||
this.eventsUI.setItem(4, new GuiItem(mysteryChest.orElseThrow(() -> new Exception("Mystery Chest has not been found"))));*/
|
||||
|
||||
ItemStack homePage = new ItemBuilder(Material.BED).setName("&c&lMain Menu").addLore("&7Click to return to the main menu.").colorize().build();
|
||||
eventsUI.setItem(1, 1, new GuiItem(homePage, event -> {
|
||||
MainEventsUI teamListGUI = new MainEventsUI(plugin, player);
|
||||
teamListGUI.getEventsUI().open(player);
|
||||
}));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package net.crankedpvp.events.inventories;
|
||||
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import dev.triumphteam.gui.guis.PaginatedGui;
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.game.MiniGameState;
|
||||
import net.crankedpvp.events.game.MiniGameType;
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class MainEventsUI {
|
||||
|
||||
|
||||
|
||||
@Getter
|
||||
private final PaginatedGui eventsUI;
|
||||
|
||||
public MainEventsUI(EventsPlugin plugin, Player player) {
|
||||
this.eventsUI = new PaginatedGui(3, 27, "Events Menu");
|
||||
this.eventsUI.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
|
||||
BukkitTask runnable = Bukkit.getScheduler().runTaskTimer(plugin, () -> eventsUI.updateItem(4, new GuiItem(
|
||||
new ItemBuilder(Material.CHEST)
|
||||
.setName("&6&lAstro Events Menu")
|
||||
.addLore(
|
||||
"&7In this menu you can find out when the next event",
|
||||
"&7will happen as well as which event is currently active",
|
||||
"",
|
||||
"&6* &7Next event: &6" + Utils.toNiceString(plugin.getMiniGameManager().getNextMiniGame().name()),
|
||||
"&6* &7Next event will happen in &6" + plugin.getMiniGameManager().getTimeUntilNextMiniGame()
|
||||
)
|
||||
.colorize()
|
||||
.build())), 20L, 20L);
|
||||
|
||||
this.eventsUI.setCloseGuiAction(event -> runnable.cancel());
|
||||
|
||||
plugin.getMiniGameRegister().getMiniGames().forEach(((miniGameType, miniGame) -> {
|
||||
|
||||
ItemStack itemStack;
|
||||
if (miniGame.getMiniGameState() != MiniGameState.NOT_STARTED) {
|
||||
|
||||
itemStack = new ItemBuilder(miniGame.getGuiMaterial())
|
||||
.setName("&a&l" + Utils.toNiceString(miniGameType.name() + " Event"))
|
||||
.addLore("&a* &7Event state: &a\"" + Utils.toNiceString(miniGame.getMiniGameState().name()),
|
||||
"&a* &7Min/Max players: &a" + miniGame.getMinPlayers() + "&8/&a" + miniGame.getMaxPlayers(),
|
||||
"&a* &7Amount of participants: &a" + miniGame.getParticipants().size(),
|
||||
"",
|
||||
"&7&nLeft-Click&7 to join the " + Utils.toNiceString(miniGameType.name() + " Minigame!"),
|
||||
"&7&nRight-Click&7 to preview the loot.")
|
||||
.colorize()
|
||||
.build();
|
||||
|
||||
|
||||
} else {
|
||||
itemStack = new ItemBuilder(Material.BARRIER)
|
||||
.setName("&a&l" + Utils.toNiceString(miniGameType.name() + " Event"))
|
||||
.addLore("&cThis event is currently not running.",
|
||||
"&cJoin the /discord and react to #events",
|
||||
"&cto stay updated when we do event like these.",
|
||||
"",
|
||||
"&7&nRight-Click&7 to preview the loot.")
|
||||
.colorize()
|
||||
.build();
|
||||
}
|
||||
|
||||
this.eventsUI.setItem(4, new GuiItem(
|
||||
new ItemBuilder(Material.CHEST)
|
||||
.setName("&6&lAstro Events Menu")
|
||||
.addLore(
|
||||
"&7In this menu you can find out when the next event",
|
||||
"&7will happen as well as which event is currently active",
|
||||
"",
|
||||
"&6* &7Next event: &6" + Utils.toNiceString(plugin.getMiniGameManager().getNextMiniGame().name()),
|
||||
"&6* &7Next event will happen in &6" + plugin.getMiniGameManager().getTimeUntilNextMiniGame()
|
||||
)
|
||||
.colorize()
|
||||
.build()
|
||||
));
|
||||
|
||||
if (miniGameType == MiniGameType.PARKOUR) {
|
||||
this.eventsUI.setItem(23, new GuiItem(itemStack, event -> {
|
||||
if (event.isLeftClick()) {
|
||||
if (miniGame.getMiniGameState() == MiniGameState.STARTING)
|
||||
miniGame.joinMiniGame(player);
|
||||
} else {
|
||||
LootPreviewUI lootPreviewUI = new LootPreviewUI(plugin, player, miniGame);
|
||||
lootPreviewUI.getEventsUI().open(player);
|
||||
player.playSound(player.getLocation(), Sound.CHEST_OPEN, 2, 2);
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
this.eventsUI.setItem(21, new GuiItem(itemStack, event -> {
|
||||
if (event.isLeftClick()) {
|
||||
if (miniGame.getMiniGameState() == MiniGameState.STARTING)
|
||||
miniGame.joinMiniGame(player);
|
||||
} else {
|
||||
LootPreviewUI lootPreviewUI = new LootPreviewUI(plugin, player, miniGame);
|
||||
lootPreviewUI.getEventsUI().open(player);
|
||||
player.playSound(player.getLocation(), Sound.CHEST_OPEN, 2, 2);
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package net.crankedpvp.events.inventories;
|
||||
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.utils.TimeUtils;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.pvptop.data.FactionData;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class WarpKothInventory {
|
||||
|
||||
@Getter
|
||||
private ItemStack warpKothItemstack;
|
||||
|
||||
@Getter
|
||||
private final EventsPlugin plugin;
|
||||
|
||||
private final Gui warpKothInventory;
|
||||
|
||||
public Gui getUI() {
|
||||
return this.warpKothInventory;
|
||||
}
|
||||
|
||||
public WarpKothInventory(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.warpKothInventory = new Gui(3, "Warp Koth");
|
||||
this.warpKothInventory.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
|
||||
this.buildWarpKothItem();
|
||||
|
||||
ItemStack howToPlay = new ItemBuilder(Material.SIGN, "&b&lHow to Play?",
|
||||
"&fThis is a competitive event where",
|
||||
"&fplayers all meet at &c/warp koth &fin",
|
||||
"&fattempt to control the point.",
|
||||
"",
|
||||
"&fThe objective is to take control of",
|
||||
"&fthe capture zone for the required amount",
|
||||
"&fof time. However, there are extra rules",
|
||||
"&fat the /warp koth.",
|
||||
"",
|
||||
"&fFor example, you will only get one life.",
|
||||
"&fIf you die at /warp koth, you cannot return",
|
||||
"&fto the warp until the next /warp koth starts.",
|
||||
"&fHowever, if you die, you will not lose any items."
|
||||
).colorize().build();
|
||||
|
||||
|
||||
ItemStack viewAllEvents = new ItemBuilder(Material.ARROW, "&d&lAll Events",
|
||||
"&fClick here to view all of the",
|
||||
"&fevents currently active on Cranked"
|
||||
).colorize().build();
|
||||
this.warpKothInventory.setItem(2, 5, new GuiItem(this.getWarpKothItemstack()));
|
||||
this.warpKothInventory.setItem(2, 3, new GuiItem(howToPlay));
|
||||
this.warpKothInventory.setItem(2, 7, new GuiItem(viewAllEvents, event -> {
|
||||
event.getWhoClicked().closeInventory();
|
||||
if(event.getWhoClicked() instanceof Player) {
|
||||
((Player)event.getWhoClicked()).performCommand("events");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private String getNextWarpKothString() {
|
||||
return this.plugin.getWarpKothManager().isActive() ? "Now" : TimeUtils.formatMillisecondsInFull(this.plugin.getTimeUntilNextWarpKoth());
|
||||
}
|
||||
|
||||
private String getActiveString() {
|
||||
return this.plugin.getWarpKothManager().isActive() ? "&a&lACTIVE" : "&c&lINACTIVE";
|
||||
}
|
||||
|
||||
|
||||
public void updateInformationItem() {
|
||||
this.buildWarpKothItem();
|
||||
this.warpKothInventory.updateItem(2, 5, new GuiItem(this.getWarpKothItemstack()));
|
||||
}
|
||||
|
||||
public void buildWarpKothItem() {
|
||||
this.warpKothItemstack = new ItemBuilder(Material.ENDER_PORTAL_FRAME, "&5&lWarp Koth &7(Information)",
|
||||
"&fThis is a KOTH that runs in an alternate",
|
||||
"&fworld. Keep inventory is enabled, but if",
|
||||
"&fyou die, you cannot return until the next koth",
|
||||
"",
|
||||
"&5Information:",
|
||||
" &f• Located at &5/warp koth",
|
||||
" &f• Limited to &51 Life",
|
||||
" &f• Keep Inventory Enabled",
|
||||
"",
|
||||
"&5Rewards &7(Upon capture)",
|
||||
" &f• 1x Warp Koth Lootbag",
|
||||
" &f• Gain &5+" + FactionData.Points.WARP_KOTH_CAPTURE.getPoints() + " &fFaction Points",
|
||||
"",
|
||||
"&5Warp Koth:",
|
||||
" &f• Event Status: " + this.getActiveString(),
|
||||
" &f• Next Event: &a" + this.getNextWarpKothString(),
|
||||
" &f• Captured Last: &5" + this.getLastFactionWon()
|
||||
).colorize().build();
|
||||
}
|
||||
|
||||
private String getLastFactionWon() {
|
||||
return (this.plugin.getWarpKothManager().getLastFactionCaptured() == null || !this.plugin.getWarpKothManager().getLastFactionCaptured().isNormal()) ? "None" : this.plugin.getWarpKothManager().getLastFactionCaptured().getTag();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.crankedpvp.events.listeners;
|
||||
|
||||
import com.massivecraft.factions.Faction;
|
||||
import net.crankedpvp.bosses.bosses.Cerberus;
|
||||
import net.crankedpvp.bosses.events.BossDeathEvent;
|
||||
import net.crankedpvp.bosses.struct.Boss;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.FactionUtils;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.pvptop.PvPTopAPI;
|
||||
import net.crankedpvp.pvptop.data.FactionData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class CerberusDeathListener implements Listener {
|
||||
|
||||
private final EventsPlugin plugin;
|
||||
public CerberusDeathListener(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBossDeath(BossDeathEvent event) {
|
||||
if(event.getEntity() == null) return;
|
||||
|
||||
Boss boss = event.getBoss();
|
||||
if(!(boss instanceof Cerberus)) return;
|
||||
|
||||
if(event.getKiller() == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Player killer = event.getKiller();
|
||||
Faction killerFaction = FactionUtils.getFaction(killer);
|
||||
this.plugin.getCerberusManager().setLastFactionCaptured(killerFaction);
|
||||
this.plugin.getCerberusManager().setActive(false);
|
||||
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
onlinePlayer.playSound(onlinePlayer.getLocation(), Sound.ZOMBIE_DEATH, 3.0f, 2.0f);
|
||||
onlinePlayer.sendMessage(CC.translate(""));
|
||||
onlinePlayer.sendMessage(CC.translate("&6&lCerberus has been Slain"));
|
||||
onlinePlayer.sendMessage(CC.translate(" &f• Slain By: &6" + killer.getName()));
|
||||
onlinePlayer.sendMessage(CC.translate(" &f• Killers Faction: &6" + killerFaction.getTag()));
|
||||
onlinePlayer.sendMessage(CC.translate(" &f• Faction Points: &6" + FactionData.Points.CERBERUS_KILLED.getPoints() + " Gained"));
|
||||
onlinePlayer.sendMessage(CC.translate(""));
|
||||
}
|
||||
PvPTopAPI.getFactionData(killer).addPoint(FactionData.Points.CERBERUS_KILLED);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package net.crankedpvp.events.listeners;
|
||||
|
||||
import com.golfing8.kore.event.KothCaptureEvent;
|
||||
import com.golfing8.kore.event.KothEndEvent;
|
||||
import com.golfing8.kore.event.KothStartEvent;
|
||||
import com.golfing8.kore.object.Koth;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import net.crankedpvp.crankedutils.utils.FactionUtils;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.pvptop.data.FactionData;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class KothStateChangeListener implements Listener {
|
||||
|
||||
private final EventsPlugin plugin;
|
||||
public KothStateChangeListener(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void checkKothStart(KothStartEvent event) {
|
||||
if(event.getKoth() == null) return;
|
||||
if(event.getKoth().getName().equals("Citadel")) {
|
||||
this.plugin.getCitadelManager().setActive(true);
|
||||
return;
|
||||
}
|
||||
if(this.plugin.getWarpKothManager().isWarpKoth(event.getKoth())) {
|
||||
// FactionsKore marks the KOTH active after firing its start event.
|
||||
this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> {
|
||||
boolean active = event.getKoth().isActive();
|
||||
if (this.plugin.getWarpKothManager().isActive() != active) {
|
||||
this.plugin.getWarpKothManager().setActive(active);
|
||||
}
|
||||
}, 1L);
|
||||
return;
|
||||
}
|
||||
this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> this.plugin.getEventsInventory().updateKothItem(), 5L);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void checkKothEnd(KothEndEvent event) {
|
||||
if(event.getKoth() == null) return;
|
||||
if(event.getKoth().getName().equals("Citadel")) {
|
||||
this.plugin.getCitadelManager().setActive(false);
|
||||
return;
|
||||
}
|
||||
if(this.plugin.getWarpKothManager().isWarpKoth(event.getKoth())) {
|
||||
this.plugin.getWarpKothManager().setActive(false);
|
||||
return;
|
||||
}
|
||||
this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> this.plugin.getEventsInventory().updateKothItem(), 5L);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onKothCapture(KothCaptureEvent event) {
|
||||
if(event.getPlayerCapper() == null) return;
|
||||
Faction faction = FactionUtils.getFaction(event.getPlayerCapper());
|
||||
if(this.plugin.getWarpKothManager().isWarpKoth(event.getKoth())) {
|
||||
this.plugin.getWarpKothManager().setLastFactionCaptured(faction);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.crankedpvp.events.listeners;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.Arrow;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
|
||||
public class PlayerDeathListener implements Listener {
|
||||
|
||||
private final EventsPlugin plugin;
|
||||
public PlayerDeathListener(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerDeath(PlayerDeathEvent event) {
|
||||
if(event.getEntity() == null) return;
|
||||
if(!event.getEntity().getWorld().getName().equals(EventsPlugin.WARP_KOTH_WORLD_NAME)) return;
|
||||
event.getEntity().sendMessage(CC.translate("&5&lWarp Koth &8" + Arrow.arrow() + " &cYou have been death banned from /warp koth until the next event"));
|
||||
this.plugin.getWarpKothManager().getRecentlyDied().add(event.getEntity());
|
||||
this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> this.plugin.getWarpKothManager().getRecentlyDied().remove(event.getEntity()), 3 * 20L);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void playerTakeDamageFromVoid(EntityDamageEvent event) {
|
||||
if(event.getEntity() == null || !(event.getEntity() instanceof Player)) return;
|
||||
Player player = (Player) event.getEntity();
|
||||
if(!player.getWorld().equals(Bukkit.getWorld(EventsPlugin.WARP_KOTH_WORLD_NAME))) return;
|
||||
if(!event.getCause().equals(EntityDamageEvent.DamageCause.VOID)) return;
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(CC.translate("&5&lWarp Koth &8" + Arrow.arrow() + " &cYou have been death banned from /warp koth until the next event"));
|
||||
this.plugin.getWarpKothManager().getRecentlyDied().add(player);
|
||||
this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> this.plugin.getWarpKothManager().getRecentlyDied().remove(player), 3 * 20L);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package net.crankedpvp.events.listeners;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.Arrow;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
public class PlayerTeleportListener implements Listener {
|
||||
|
||||
private final EventsPlugin plugin;
|
||||
public PlayerTeleportListener(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerTeleport(PlayerTeleportEvent event) {
|
||||
if(event.getFrom() == null || event.getTo() == null) return;
|
||||
if(event.getCause().equals(PlayerTeleportEvent.TeleportCause.ENDER_PEARL)) return;
|
||||
|
||||
|
||||
if(!event.getFrom().getWorld().getName().equals(EventsPlugin.WARP_KOTH_WORLD_NAME) && event.getTo().getWorld().getName().equals(EventsPlugin.WARP_KOTH_WORLD_NAME)) {
|
||||
|
||||
if(!this.plugin.getWarpKothManager().isActive()) {
|
||||
if(!event.getPlayer().isOp()) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(CC.translate("&5&lWarp Koth &8" + Arrow.arrow() + " &cThis koth is not currently active"));
|
||||
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ANVIL_LAND, 1.0f, 1.0f);
|
||||
} else {
|
||||
event.getPlayer().sendMessage(CC.translate("&5&lWarp Koth &8" + Arrow.arrow() + " &cKoth is not active, but OPs bypass!"));
|
||||
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.LEVEL_UP, 1.0f, 1.0f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.plugin.getWarpKothManager().isPlayerBannedFromWarpKoth(event.getPlayer())) {
|
||||
if(!event.getPlayer().isOp()) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(CC.translate("&5&lWarp Koth &8" + Arrow.arrow() + " &cYou are currently death banned from this warp!"));
|
||||
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ANVIL_LAND, 1.0f, 1.0f);
|
||||
} else {
|
||||
event.getPlayer().sendMessage(CC.translate("&5&lWarp Koth &8" + Arrow.arrow() + " &cYou are deathbanned, but OPs bypass!"));
|
||||
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.LEVEL_UP, 1.0f, 1.0f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.plugin.getWarpKothManager().banPlayerFromWarpKoth(event.getPlayer());
|
||||
return;
|
||||
}
|
||||
|
||||
if(event.getFrom().getWorld().getName().equals(EventsPlugin.WARP_KOTH_WORLD_NAME) && !event.getTo().getWorld().getName().equals(EventsPlugin.WARP_KOTH_WORLD_NAME)) {
|
||||
if(this.plugin.getWarpKothManager().getRecentlyDied().contains(event.getPlayer())) return;
|
||||
this.plugin.getWarpKothManager().unbanPlayerFromWarpKoth(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package net.crankedpvp.events.managers;
|
||||
|
||||
import com.massivecraft.factions.Faction;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.crankedpvp.bosses.BossPlugin;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CerberusManager {
|
||||
|
||||
private final static Location spawnLocation = new Location(Bukkit.getWorld("world_nether"), -8, 36, -124);
|
||||
private final EventsPlugin plugin;
|
||||
public CerberusManager(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.active = false;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Faction lastFactionCaptured;
|
||||
|
||||
@Getter @Setter
|
||||
private boolean active;
|
||||
|
||||
|
||||
public void startEvent() {
|
||||
if(this.isActive()) return;
|
||||
BossPlugin.getInstance().getBossRegister().getBossFromID("cerberus").spawnBoss(spawnLocation);
|
||||
this.setActive(true);
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
onlinePlayer.playSound(onlinePlayer.getLocation(), Sound.ENDERDRAGON_GROWL, 2.0f, 2.0f);
|
||||
onlinePlayer.sendMessage(CC.translate(""));
|
||||
onlinePlayer.sendMessage(CC.translate("&6&lCerberus Boss"));
|
||||
onlinePlayer.sendMessage(CC.translate("&fThe &6Cerberus &fhas just spawned"));
|
||||
onlinePlayer.sendMessage(CC.translate("&fin the &6Nether &fat &6x: -8, y: 36, z: -124"));
|
||||
onlinePlayer.sendMessage(CC.translate(""));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.crankedpvp.events.managers;
|
||||
|
||||
import com.massivecraft.factions.Faction;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.crankedpvp.bosses.BossPlugin;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CitadelManager {
|
||||
|
||||
private final EventsPlugin plugin;
|
||||
public CitadelManager(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.active = false;
|
||||
}
|
||||
|
||||
@Getter @Setter
|
||||
private Faction lastFactionCaptured;
|
||||
|
||||
@Getter @Setter
|
||||
private boolean active;
|
||||
|
||||
public void startEvent() {
|
||||
if(this.isActive()) return;
|
||||
//KothFeature kothFeature = FactionsKore.get().getFeature(KothFeature.class);
|
||||
//kothFeature.startKoth(kothFeature.getKoth("Citadel"));
|
||||
//this.setActive(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package net.crankedpvp.events.managers;
|
||||
|
||||
import com.golfing8.kore.FactionsKore;
|
||||
import com.golfing8.kore.feature.KothFeature;
|
||||
import com.golfing8.kore.object.Koth;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WarpKothManager {
|
||||
|
||||
private final EventsPlugin plugin;
|
||||
public WarpKothManager(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.active = false;
|
||||
this.blockedIPs = new ArrayList<>();
|
||||
this.blockedPlayers = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final List<Player> recentlyDied = new ArrayList<>();
|
||||
|
||||
private final List<String> blockedIPs;
|
||||
private final List<UUID> blockedPlayers;
|
||||
|
||||
public void banPlayerFromWarpKoth(Player player) {
|
||||
this.blockedIPs.add(player.getAddress().getAddress().getHostAddress());
|
||||
this.blockedPlayers.add(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void unbanPlayerFromWarpKoth(Player player) {
|
||||
this.blockedIPs.remove(player.getAddress().getAddress().getHostAddress());
|
||||
this.blockedPlayers.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean isPlayerBannedFromWarpKoth(Player player) {
|
||||
return blockedIPs.contains(player.getAddress().getAddress().getHostAddress()) || blockedPlayers.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Getter @Setter
|
||||
private Faction lastFactionCaptured;
|
||||
|
||||
@Getter
|
||||
private boolean active;
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
this.blockedIPs.clear();
|
||||
}
|
||||
|
||||
|
||||
public void startEvent() {
|
||||
if(this.isActive()) return;
|
||||
FactionsKore kore = FactionsKore.get();
|
||||
KothFeature kothFeature = kore == null ? null : kore.getFeature(KothFeature.class);
|
||||
if (kothFeature == null || !kothFeature.isOn()) {
|
||||
this.plugin.getLogger().warning("Cannot start Warp KOTH: the FactionsKore KOTH feature is unavailable or disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
String kothName = this.getKothName();
|
||||
Koth koth = kothFeature.getKoth(kothName);
|
||||
if (koth == null) {
|
||||
koth = kothFeature.getKoths().stream()
|
||||
.filter(this::isWarpKoth)
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
if (koth == null) {
|
||||
String available = kothFeature.getKoths().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(Koth::getName)
|
||||
.collect(Collectors.joining(", "));
|
||||
this.plugin.getLogger().warning("Cannot start Warp KOTH: no FactionsKore KOTH named '" + kothName
|
||||
+ "'. Set WARP_KOTH_NAME in CrankedEvents/config.yml to your warp KOTH's name. Available KOTHs: "
|
||||
+ (available.isEmpty() ? "none" : available));
|
||||
return;
|
||||
}
|
||||
|
||||
Location first = koth.getAnchorOne();
|
||||
Location second = koth.getAnchorTwo();
|
||||
if (first == null || second == null || first.getWorld() == null || second.getWorld() == null
|
||||
|| !first.getWorld().equals(second.getWorld())
|
||||
|| !first.getWorld().equals(Bukkit.getWorld(first.getWorld().getName()))) {
|
||||
this.plugin.getLogger().warning("Cannot start Warp KOTH '" + koth.getName()
|
||||
+ "': configure both arena corners in the same loaded world in FactionsKore.");
|
||||
return;
|
||||
}
|
||||
if (koth.isActive()) {
|
||||
this.setActive(true);
|
||||
return;
|
||||
}
|
||||
|
||||
kothFeature.startKoth(koth);
|
||||
if (!koth.isActive()) {
|
||||
this.setActive(false);
|
||||
this.plugin.getLogger().warning("Warp KOTH '" + koth.getName() + "' did not start; its start may have been cancelled.");
|
||||
return;
|
||||
}
|
||||
this.setActive(true);
|
||||
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
onlinePlayer.playSound(onlinePlayer.getLocation(), Sound.ENDERDRAGON_GROWL, 2.0f, 2.0f);
|
||||
onlinePlayer.sendMessage(CC.translate(""));
|
||||
onlinePlayer.sendMessage(CC.translate("&5&lWarp Koth Event"));
|
||||
onlinePlayer.sendMessage(CC.translate("&fA koth event has just started at"));
|
||||
onlinePlayer.sendMessage(CC.translate("&5/warp koth&f. In this world, you"));
|
||||
onlinePlayer.sendMessage(CC.translate("&fonly get &51 life&f, but you do not"));
|
||||
onlinePlayer.sendMessage(CC.translate("&flose any items when you die!"));
|
||||
onlinePlayer.sendMessage(CC.translate(""));
|
||||
}
|
||||
}
|
||||
|
||||
public String getKothName() {
|
||||
return this.plugin.getConfig().getString("WARP_KOTH_NAME", "End").trim();
|
||||
}
|
||||
|
||||
public boolean isWarpKoth(Koth koth) {
|
||||
return koth != null && this.getKothName().equalsIgnoreCase(koth.getName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package net.crankedpvp.events.tasks;
|
||||
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.inventories.CerberusInventory;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class UpdateNextCerberusTimerTask extends BukkitRunnable {
|
||||
|
||||
private final CerberusInventory cerberusInventory;
|
||||
private final EventsPlugin plugin;
|
||||
|
||||
public UpdateNextCerberusTimerTask(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.cerberusInventory = plugin.getCerberusInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(this.plugin.getTimeUntilNextCerberus() < -1000L) return;
|
||||
if(this.plugin.getTimeUntilNextCerberus() <= 0L) {
|
||||
this.plugin.getCerberusManager().startEvent();
|
||||
}
|
||||
cerberusInventory.updateInformationItem();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package net.crankedpvp.events.tasks;
|
||||
|
||||
import com.golfing8.kore.FactionsKore;
|
||||
import com.golfing8.kore.feature.KothFeature;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.inventories.CitadelInventory;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class UpdateNextCitadelTimerTask extends BukkitRunnable {
|
||||
|
||||
private final CitadelInventory citadelInventory;
|
||||
private final EventsPlugin plugin;
|
||||
|
||||
public UpdateNextCitadelTimerTask(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.citadelInventory = plugin.getCitadelInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(this.plugin.getTimeUntilNextCitadel() < -1000L) return;
|
||||
if(this.plugin.getTimeUntilNextCitadel() <= 0L) {
|
||||
this.plugin.getCitadelManager().startEvent();
|
||||
}
|
||||
citadelInventory.updateInformationItem();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.crankedpvp.events.tasks;
|
||||
|
||||
import com.golfing8.kore.FactionsKore;
|
||||
import com.golfing8.kore.feature.KothFeature;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.events.EventsPlugin;
|
||||
import net.crankedpvp.events.inventories.WarpKothInventory;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class UpdateNextWarpKothTimerTask extends BukkitRunnable {
|
||||
|
||||
private final WarpKothInventory warpKothInventory;
|
||||
private final EventsPlugin plugin;
|
||||
|
||||
public UpdateNextWarpKothTimerTask(EventsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.warpKothInventory = plugin.getWarpKothInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(this.plugin.getTimeUntilNextWarpKoth() < -1000L) return;
|
||||
if(this.plugin.getTimeUntilNextWarpKoth() <= 0L) {
|
||||
this.plugin.getWarpKothManager().startEvent();
|
||||
}
|
||||
warpKothInventory.updateInformationItem();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.crankedpvp.events.utils;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R3.Blocks;
|
||||
import net.minecraft.server.v1_8_R3.IBlockData;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
|
||||
public final class BlockUtil {
|
||||
|
||||
private final static IBlockData AIR = Blocks.AIR.getBlockData();
|
||||
|
||||
public static void setBlockFast(Block b, int blockId, byte data, boolean physics) {
|
||||
setBlockFast(b.getWorld(), b.getX(), b.getY(), b.getZ(), blockId, data, physics);
|
||||
}
|
||||
|
||||
public static void setBlockFast(org.bukkit.World world, int x, int y, int z, int blockId, byte data, boolean physics) {
|
||||
net.minecraft.server.v1_8_R3.World w = ((CraftWorld) world).getHandle();
|
||||
BlockPosition bp = new BlockPosition(x, y, z);
|
||||
IBlockData ibd = net.minecraft.server.v1_8_R3.Block.getByCombinedId(blockId + (data << 12));
|
||||
w.setTypeAndData(bp, ibd, physics ? 3 : 2);
|
||||
(w.getChunkAt(x >> 4, z >> 4)).a(bp, ibd);
|
||||
}
|
||||
|
||||
public static void setAir(Block b, boolean physics) {
|
||||
setAir(b.getWorld(), b.getX(), b.getY(), b.getZ(), physics);
|
||||
}
|
||||
|
||||
public static void setAir(org.bukkit.World world, int x, int y, int z, boolean physics) {
|
||||
BlockPosition position = new BlockPosition(x, y, z);
|
||||
((CraftWorld) world).getHandle().setTypeAndData(position, AIR, physics ? 3 : 2);
|
||||
}
|
||||
|
||||
public static void updatePhysics(org.bukkit.World world, int x, int y, int z) {
|
||||
net.minecraft.server.v1_8_R3.World w = ((CraftWorld) world).getHandle();
|
||||
BlockPosition bp = new BlockPosition(x, y, z);
|
||||
w.applyPhysics(bp, w.getType(bp).getBlock());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.crankedpvp.events.utils;
|
||||
|
||||
|
||||
import net.md_5.bungee.api.chat.*;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Clickable {
|
||||
private final List<TextComponent> components = new ArrayList<>();
|
||||
|
||||
public Clickable(String msg) {
|
||||
TextComponent message = new TextComponent(msg);
|
||||
this.components.add(message);
|
||||
}
|
||||
|
||||
public Clickable(String msg, String hoverMsg) {
|
||||
this(msg, hoverMsg, "");
|
||||
}
|
||||
|
||||
public Clickable(String msg, String hoverMsg, String clickString) {
|
||||
add(msg, hoverMsg, clickString);
|
||||
}
|
||||
|
||||
public TextComponent add(String msg, String hoverMsg) {
|
||||
return add(msg, hoverMsg, "");
|
||||
}
|
||||
|
||||
public TextComponent add(String msg, String hoverMsg, String clickString) {
|
||||
TextComponent message = new TextComponent(Utils.color(msg));
|
||||
if (hoverMsg != null && !hoverMsg.isEmpty())
|
||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, (new ComponentBuilder(Utils.color(hoverMsg))).create()));
|
||||
if (clickString != null && !clickString.isEmpty())
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, clickString));
|
||||
this.components.add(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
public void add(String message) {
|
||||
this.components.add(new TextComponent(Utils.color(message)));
|
||||
}
|
||||
|
||||
public void sendToPlayer(Player player) {
|
||||
player.spigot().sendMessage(this.asComponents());
|
||||
}
|
||||
|
||||
public TextComponent[] asComponents() {
|
||||
return this.components.toArray(new TextComponent[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.crankedpvp.events.utils;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class Pair<L, R> {
|
||||
|
||||
private L left;
|
||||
private R right;
|
||||
|
||||
public boolean contains(L value) {
|
||||
return left.equals(value) || right.equals(value);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.setLeft(null);
|
||||
this.setRight(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.crankedpvp.events.utils;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class PlayerInventoryContents {
|
||||
|
||||
public ItemStack[] inventoryContents;
|
||||
public ItemStack[] armorContents;
|
||||
|
||||
public void restoreInventory(Player player) {
|
||||
player.getInventory().setContents(inventoryContents);
|
||||
}
|
||||
|
||||
public void restoreArmor(Player player) {
|
||||
player.getInventory().setArmorContents(armorContents);
|
||||
}
|
||||
|
||||
public void restore(Player player) {
|
||||
restoreInventory(player);
|
||||
restoreArmor(player);
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package net.crankedpvp.events.utils;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static String color(String string) {
|
||||
char[] b = string.toCharArray();
|
||||
|
||||
for (int i = 0; i < b.length - 1; ++i) {
|
||||
if (b[i] == '&' && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1) {
|
||||
b[i] = 167;
|
||||
b[i + 1] = Character.toLowerCase(b[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
return new String(b);
|
||||
}
|
||||
|
||||
public static List<String> color(List<String> stringList) {
|
||||
stringList.replaceAll(Utils::color);
|
||||
return stringList;
|
||||
}
|
||||
|
||||
public static String[] color(String[] stringArray) {
|
||||
for (int i = 0; i < stringArray.length; i++) {
|
||||
stringArray[i] = color(stringArray[i]);
|
||||
}
|
||||
return stringArray;
|
||||
}
|
||||
|
||||
public static <T> T defaultIfNull(T val, T def) {
|
||||
return val != null ? val : def;
|
||||
}
|
||||
|
||||
public static String defaultIfEmpty(String val, String def) {
|
||||
return !val.isEmpty() ? val : def;
|
||||
}
|
||||
|
||||
public static String getTimeFromSecsToMins(long seconds) {
|
||||
int mins = (int) seconds / 60;
|
||||
int remainder = (int) seconds - mins * 60;
|
||||
return mins + "m " + remainder + "s ";
|
||||
}
|
||||
|
||||
public static void sendActionBarMessage(Player player, String text) {
|
||||
PacketPlayOutChat packet = new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + text + "\"}"), (byte)2);
|
||||
(((CraftPlayer)player).getHandle()).playerConnection.sendPacket(packet);
|
||||
}
|
||||
|
||||
public static String toNiceString(String string) {
|
||||
string = ChatColor.stripColor(string).replace('_', ' ').toLowerCase();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < string.toCharArray().length; ++i) {
|
||||
char c = string.toCharArray()[i];
|
||||
if (i > 0) {
|
||||
char prev = string.toCharArray()[i - 1];
|
||||
if ((prev == ' ' || prev == '[' || prev == '(') && (i == string.toCharArray().length - 1 || c != 'x' || !Character.isDigit(string.toCharArray()[i + 1]))) {
|
||||
c = Character.toUpperCase(c);
|
||||
}
|
||||
} else if (c != 'x' || !Character.isDigit(string.toCharArray()[i + 1])) {
|
||||
c = Character.toUpperCase(c);
|
||||
}
|
||||
|
||||
sb.append(c);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void sendTitle(Player player, String title, String subtitle, int fadeInTime, int showTime, int fadeOutTime) {
|
||||
try {
|
||||
Object chatTitle = Objects.requireNonNull(getNMSClass("IChatBaseComponent")).getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, "{\"text\": \"" + title + "\"}");
|
||||
Constructor<?> titleConstructor = Objects.requireNonNull(getNMSClass("PacketPlayOutTitle")).getConstructor(Objects.requireNonNull(getNMSClass("PacketPlayOutTitle")).getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"),
|
||||
int.class, int.class, int.class);
|
||||
Object packet = titleConstructor.newInstance(Objects.requireNonNull(getNMSClass("PacketPlayOutTitle")).getDeclaredClasses()[0].getField("TITLE").get(null), chatTitle,
|
||||
fadeInTime, showTime, fadeOutTime);
|
||||
Object chatsTitle = Objects.requireNonNull(getNMSClass("IChatBaseComponent")).getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, "{\"text\": \"" + subtitle + "\"}");
|
||||
Constructor<?> timingTitleConstructor = Objects.requireNonNull(getNMSClass("PacketPlayOutTitle")).getConstructor(Objects.requireNonNull(getNMSClass("PacketPlayOutTitle")).getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"),
|
||||
int.class, int.class, int.class);
|
||||
Object timingPacket = timingTitleConstructor.newInstance(Objects.requireNonNull(getNMSClass("PacketPlayOutTitle")).getDeclaredClasses()[0].getField("SUBTITLE").get(null), chatsTitle,
|
||||
fadeInTime, showTime, fadeOutTime);
|
||||
sendPacket(player, packet);
|
||||
sendPacket(player, timingPacket);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, Object packet) {
|
||||
try {
|
||||
Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player);
|
||||
Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
|
||||
playerConnection.getClass().getMethod("sendPacket", new Class[] { getNMSClass("Packet") }).invoke(playerConnection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> getNMSClass(String name) {
|
||||
try {
|
||||
return Class.forName("net.minecraft.server." +
|
||||
Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + "." + name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isInventoryEmpty(Player player) {
|
||||
return Stream.of(player.getInventory().getContents()).allMatch(itemStack -> itemStack == null || itemStack.getType() == Material.AIR) &&
|
||||
Stream.of(player.getInventory().getArmorContents()).allMatch(itemStack -> itemStack == null || itemStack.getType() == Material.AIR);
|
||||
}
|
||||
|
||||
public static String getSecondsAsString(long seconds) {
|
||||
int day = (int)TimeUnit.SECONDS.toDays(seconds);
|
||||
long hours = TimeUnit.SECONDS.toHours(seconds) - (day * 24L);
|
||||
long minute = TimeUnit.SECONDS.toMinutes(seconds) - TimeUnit.SECONDS.toHours(seconds) * 60L;
|
||||
long second = TimeUnit.SECONDS.toSeconds(seconds) - TimeUnit.SECONDS.toMinutes(seconds) * 60L;
|
||||
if (day > 0) {
|
||||
return day + "d " + hours + "h " + minute + "m " + second + "s";
|
||||
}
|
||||
if (hours > 0L) {
|
||||
return hours + "h " + minute + "m " + second + "s";
|
||||
}
|
||||
if (minute > 0L) {
|
||||
return minute + "m " + second + "s";
|
||||
}
|
||||
return second + "s";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package net.crankedpvp.events.utils.configuration;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class AbstractConfig {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private final String path;
|
||||
private FileConfiguration config;
|
||||
private final File configFile;
|
||||
|
||||
public AbstractConfig(JavaPlugin plugin, String path) {
|
||||
this.plugin = plugin;
|
||||
this.path = path;
|
||||
this.configFile = new File(plugin.getDataFolder(), path);
|
||||
}
|
||||
|
||||
public void setupConfigFile() {
|
||||
boolean copyDefaults = !configFile.exists();
|
||||
|
||||
this.saveDefaultConfig();
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
if (copyDefaults) this.copyDefaults();
|
||||
|
||||
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 saveDefaultConfig() {
|
||||
if (!configFile.exists()) {
|
||||
InputStream defConfig = plugin.getResource(path);
|
||||
if (defConfig != null) {
|
||||
plugin.saveResource(path,false);
|
||||
} else {
|
||||
try {
|
||||
configFile.getParentFile().mkdirs();
|
||||
configFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Could not create config file for " + path);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean reloadConfig() {
|
||||
boolean copyDefaults = !configFile.exists();
|
||||
|
||||
this.saveDefaultConfig();
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
if (copyDefaults) this.copyDefaults();
|
||||
|
||||
this.saveConfig();
|
||||
return this.loadConfigFromDisk();
|
||||
}
|
||||
|
||||
public boolean loadConfigFromDisk() {
|
||||
try {
|
||||
config.load(configFile);
|
||||
return true;
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
plugin.getLogger().severe("Could not load config for " + path);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void copyDefaults() {
|
||||
InputStream defConfig = plugin.getResource(path);
|
||||
if (defConfig != null) {
|
||||
config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfig)));
|
||||
}
|
||||
config.options().copyDefaults(true);
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.crankedpvp.events.utils.configuration;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
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 {
|
||||
PARKOUR("events/parkour.yml"),
|
||||
SUMO("events/sumo.yml"),
|
||||
SPLEEF("events/spleef.yml"),
|
||||
LANGUAGE("language.yml")
|
||||
;
|
||||
|
||||
private final String fileName;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package net.crankedpvp.events.utils.configuration;
|
||||
|
||||
import net.crankedpvp.events.utils.item.ItemBuilder;
|
||||
import net.crankedpvp.events.utils.item.SkullUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class ConfigParser {
|
||||
|
||||
public static ItemStack parseItem(ConfigurationSection itemSection) {
|
||||
Material itemType = Material.matchMaterial(itemSection.getString("type"));
|
||||
short data = (short) itemSection.getInt("data");
|
||||
ItemBuilder itemBuilder = new ItemBuilder(itemType, itemSection.getInt("amount", 1), data);
|
||||
|
||||
if (itemSection.contains("name")) {
|
||||
itemBuilder.setName(itemSection.getString("name"));
|
||||
}
|
||||
|
||||
if (itemSection.contains("lore")) {
|
||||
itemBuilder.setLore(itemSection.getStringList("lore"));
|
||||
}
|
||||
|
||||
itemBuilder.addUnsafeEnchantments(parseEnchants(itemSection.getStringList("enchants")));
|
||||
itemBuilder.addItemFlags(itemSection.getStringList("flags"));
|
||||
|
||||
if (itemSection.getBoolean("glowing")) {
|
||||
itemBuilder.setGlowing();
|
||||
}
|
||||
|
||||
if (itemSection.getBoolean("unbreakable")) {
|
||||
itemBuilder.setUnbreakable(true);
|
||||
}
|
||||
|
||||
ItemStack item = itemBuilder.colorize().build();
|
||||
|
||||
if (itemSection.contains("skull-texture") && itemType == Material.SKULL_ITEM && data == 3) {
|
||||
item = SkullUtils.getSkull(item, itemSection.getString("skull-texture"));
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public static Map<Enchantment, Integer> parseEnchants(List<String> toParse) {
|
||||
Map<Enchantment, Integer> enchantments = new HashMap<>();
|
||||
for (String line : toParse) {
|
||||
String[] separation = line.split(":");
|
||||
if (separation.length == 0) continue;
|
||||
Enchantment enchant = Enchantment.getByName(separation[0].toUpperCase());
|
||||
if (enchant == null) {
|
||||
Bukkit.getLogger().warning(separation[0] + " is an invalid enchantment. Here are the options: " + Arrays.stream(Enchantment.values()).map(Enchantment::getName).collect(Collectors.joining(", ")));
|
||||
continue;
|
||||
}
|
||||
|
||||
int level = separation.length > 1 ? NumberUtils.toInt(separation[1], 1) : 1;
|
||||
enchantments.put(enchant, level);
|
||||
}
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
package net.crankedpvp.events.utils.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.crankedpvp.events.utils.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
public class ItemBuilder {
|
||||
|
||||
private ItemMeta itemMeta;
|
||||
private final ItemStack itemStack;
|
||||
|
||||
public ItemBuilder(String material) {
|
||||
this(Material.valueOf(material));
|
||||
}
|
||||
|
||||
public ItemBuilder(Material material) {
|
||||
this(material,1);
|
||||
}
|
||||
|
||||
public ItemBuilder(Material material, int amount) {
|
||||
this(new ItemStack(material, amount));
|
||||
}
|
||||
|
||||
public ItemBuilder(Material material, String name, String... lore) {
|
||||
this(material, 1, (short) 0, name, lore);
|
||||
}
|
||||
|
||||
public ItemBuilder(Material material, String name, List<String> lore) {
|
||||
this(material, 1, (short) 0, name);
|
||||
setLore(lore);
|
||||
}
|
||||
|
||||
public ItemBuilder(Material material, int amount, short durability) {
|
||||
this(new ItemStack(material, amount, durability));
|
||||
}
|
||||
|
||||
public ItemBuilder(Material material, int amount, short durability, String name, String... lore) {
|
||||
this(new ItemStack(material, amount, durability));
|
||||
setName(name);
|
||||
setLore(lore);
|
||||
}
|
||||
|
||||
public ItemBuilder(ItemBuilder itemBuilder) {
|
||||
this.itemStack = itemBuilder.itemStack;
|
||||
this.itemMeta = itemBuilder.itemMeta;
|
||||
}
|
||||
|
||||
public ItemBuilder(ConfigurationSection section) {
|
||||
this(new ItemBuilder(section.getString("name"))
|
||||
.setLore(section.getStringList("lore"))
|
||||
.setDurability((short) section.getInt("damage"))
|
||||
.setUnbreakable(section.getBoolean("unbreakable"))
|
||||
);
|
||||
}
|
||||
|
||||
public ItemBuilder(ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
this.itemMeta = itemStack.getItemMeta();
|
||||
}
|
||||
|
||||
public ItemBuilder clone() {
|
||||
return new ItemBuilder(build());
|
||||
}
|
||||
|
||||
public ItemBuilder setMaterial(String material) {
|
||||
itemStack.setType(Material.valueOf(material));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setMaterial(Material material) {
|
||||
itemStack.setType(material);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setDurability(short durability) {
|
||||
itemStack.setDurability(durability);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setName(String name) {
|
||||
itemMeta.setDisplayName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addUnsafeEnchantment(Enchantment enchantment, int level) {
|
||||
itemMeta.addEnchant(enchantment, level, true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addUnsafeEnchantments(Map<Enchantment, Integer> enchantments) {
|
||||
enchantments.forEach((enchantment, level) -> itemMeta.addEnchant(enchantment, level, true));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addEnchantment(Enchantment enchantment, int level) {
|
||||
itemMeta.addEnchant(enchantment, level,false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addEnchantments(Map<Enchantment, Integer> enchantments) {
|
||||
enchantments.forEach((enchantment, level) -> itemMeta.addEnchant(enchantment, level, false));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder removeEnchantment(Enchantment enchantment) {
|
||||
itemMeta.removeEnchant(enchantment);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder removeEnchantments(Collection<Enchantment> enchantments) {
|
||||
enchantments.forEach(itemMeta::removeEnchant);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setGlowing() {
|
||||
if (!itemMeta.hasEnchants()) {
|
||||
itemMeta.addEnchant(Enchantment.DURABILITY,1,true);
|
||||
}
|
||||
return addItemFlag(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
|
||||
public ItemBuilder colorize() {
|
||||
colorizeName();
|
||||
return colorizeLore();
|
||||
}
|
||||
|
||||
public ItemBuilder colorizeLore() {
|
||||
if (itemMeta.hasLore()) {
|
||||
List<String> lore = getItemMeta().getLore();
|
||||
lore.replaceAll(Utils::color);
|
||||
return setLore(lore);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder colorizeName() {
|
||||
if (itemMeta.hasDisplayName()) setName(Utils.color(getItemMeta().getDisplayName()));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setUnbreakable(boolean unbreakable) {
|
||||
itemMeta.spigot().setUnbreakable(unbreakable);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getLore() {
|
||||
return itemMeta.getLore();
|
||||
}
|
||||
|
||||
public ItemBuilder setLore(String... lore) {
|
||||
return setLore(Arrays.asList(lore));
|
||||
}
|
||||
|
||||
public ItemBuilder setLore(List<String> lore) {
|
||||
itemMeta.setLore(lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder removeLoreLine(String line) {
|
||||
List<String> lore = new ArrayList<>(itemMeta.getLore());
|
||||
lore.remove(line);
|
||||
itemMeta.setLore(lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder removeLoreLine(int index) {
|
||||
if (index < 0) return this;
|
||||
List<String> lore = new ArrayList<>(itemMeta.getLore());
|
||||
if (index > lore.size()) return this;
|
||||
lore.remove(index);
|
||||
itemMeta.setLore(lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addLore(String ...lore) {
|
||||
return addLore(Arrays.asList(lore));
|
||||
}
|
||||
|
||||
public ItemBuilder addLore(List<String> lore) {
|
||||
lore.forEach(this::addLoreLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addLoreLine(String line) {
|
||||
List<String> lore = itemMeta.hasLore() ? new ArrayList<>(itemMeta.getLore()) : new ArrayList<>();
|
||||
lore.add(line);
|
||||
itemMeta.setLore(lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addLoreLine(String line, int pos) {
|
||||
List<String> lore = new ArrayList<>(itemMeta.getLore());
|
||||
if (pos >= lore.size()) return this;
|
||||
lore.set(pos, line);
|
||||
itemMeta.setLore(lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addItemFlags(List<String> itemFlags) {
|
||||
for (String itemFlagStr : itemFlags) {
|
||||
try {
|
||||
ItemFlag itemFlag = ItemFlag.valueOf(itemFlagStr);
|
||||
addItemFlag(itemFlag);
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setItemFlags(List<ItemFlag> itemFlags) {
|
||||
itemMeta.addItemFlags(itemFlags.toArray(new ItemFlag[0]));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addItemFlag(ItemFlag itemFlag) {
|
||||
itemMeta.addItemFlags(itemFlag);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public ItemBuilder setColor(DyeColor color) {
|
||||
itemStack.setDurability(color.getData());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setLeatherArmorColor(Color color) {
|
||||
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemMeta;
|
||||
if (Bukkit.getItemFactory().isApplicable(leatherArmorMeta, itemStack)) {
|
||||
leatherArmorMeta.setColor(color);
|
||||
itemMeta = leatherArmorMeta;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setSkullOwner(String owner) {
|
||||
SkullMeta skullMeta = (SkullMeta) itemMeta;
|
||||
if (Bukkit.getItemFactory().isApplicable(skullMeta, itemStack)) {
|
||||
skullMeta.setOwner(owner);
|
||||
itemMeta = skullMeta;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemMeta getItemMeta() {
|
||||
return itemMeta;
|
||||
}
|
||||
|
||||
public ItemStack build() {
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package net.crankedpvp.events.utils.item;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import de.tr7zw.nbtapi.NBTCompound;
|
||||
import de.tr7zw.nbtapi.NBTItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SkullUtils {
|
||||
|
||||
private final static ItemStack DEFAULT_SKULL = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
|
||||
|
||||
public static ItemStack getSkullFromSkin(String skinURL) {
|
||||
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
|
||||
if (skinURL == null || skinURL.isEmpty())
|
||||
return skull;
|
||||
SkullMeta skullMeta = (SkullMeta)skull.getItemMeta();
|
||||
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
|
||||
profile.getProperties().put("textures", new Property("textures", Base64Coder.encodeString("{textures:{SKIN:{\"url\":\"http://textures.minecraft.net/texture/" + skinURL + "\"}}}")));
|
||||
Field profileField;
|
||||
try {
|
||||
profileField = skullMeta.getClass().getDeclaredField("profile");
|
||||
} catch (NoSuchFieldException|SecurityException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
profileField.setAccessible(true);
|
||||
try {
|
||||
profileField.set(skullMeta, profile);
|
||||
} catch (IllegalArgumentException|IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
skull.setItemMeta(skullMeta);
|
||||
return skull;
|
||||
}
|
||||
|
||||
public static ItemStack getSkull(ItemStack item, String skullTexture) {
|
||||
if (skullTexture == null) throw new IllegalStateException("Skull Texture cannot be null!");
|
||||
|
||||
NBTItem nbtItem = new NBTItem(item);
|
||||
|
||||
NBTCompound skullOwnerCompound = nbtItem.addCompound("SkullOwner");
|
||||
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
skullOwnerCompound.setString("Id", uuid);
|
||||
|
||||
skullOwnerCompound.addCompound("Properties").getCompoundList("textures").addCompound().setString("Value", skullTexture);
|
||||
|
||||
return nbtItem.getItem();
|
||||
}
|
||||
|
||||
public static ItemStack getSkull(String skullTexture) {
|
||||
if (skullTexture == null) throw new IllegalStateException("Skull Texture cannot be null!");
|
||||
|
||||
return getSkull(DEFAULT_SKULL, skullTexture);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
CITADEL_LAST_WON: 0
|
||||
WARP_KOTH_LAST_WON: 0
|
||||
# FactionsKore KOTH used for Warp KOTH events; capitalization is ignored.
|
||||
WARP_KOTH_NAME: End
|
||||
CERBERUS_LAST_WON: 0
|
||||
@@ -0,0 +1,67 @@
|
||||
minigame:
|
||||
countdown-message: '&8(&4!&8) &7Parkour event starts in &4{time}'
|
||||
checkpoint-reached-message: '&8(&4!&8) &7You have reached checkpoint &a#{number}'
|
||||
win-message: '&8(&4!&8) &4{player}&4 has won the parkour event in &4{time}'
|
||||
parkour-time-message: '&8(&a!&8) &7Parkour time: &a{time}'
|
||||
parkour-confirm-leave-message: '&7Click to &a&lCONFIRM &7you would like to leave'
|
||||
min-players: 1
|
||||
max-players: 16
|
||||
countdown-time: 60
|
||||
world: events_world
|
||||
checkpoints:
|
||||
'1':
|
||||
x: 126.0
|
||||
y: 33.0
|
||||
z: 812.0
|
||||
yaw: 90.0
|
||||
pitch: 0.0
|
||||
'2':
|
||||
x: 48.0
|
||||
y: 37.0
|
||||
z: 781.0
|
||||
yaw: 120.0
|
||||
pitch: 0.0
|
||||
'3':
|
||||
x: 74.0
|
||||
y: 58.0
|
||||
z: 702.0
|
||||
yaw: -160.0
|
||||
pitch: 0.0
|
||||
'4':
|
||||
x: 160.0
|
||||
y: 73.0
|
||||
z: 738.0
|
||||
yaw: 0.0
|
||||
pitch: 0.0
|
||||
'5':
|
||||
x: 94.0
|
||||
y: 82.0
|
||||
z: 789.0
|
||||
yaw: 130.0
|
||||
pitch: 0.0
|
||||
spawn-location:
|
||||
x: 168.5
|
||||
y: 18.0
|
||||
z: 755.5
|
||||
yaw: 48.0
|
||||
pitch: 0.0
|
||||
end-location:
|
||||
x: 126.0
|
||||
y: 119.0
|
||||
z: 767.0
|
||||
rewards:
|
||||
- 'give {player} stone 1'
|
||||
- 'eco give {player} 10'
|
||||
items:
|
||||
checkpoint-item:
|
||||
type: GOLD_PLATE
|
||||
name: '&aTeleport to Last Checkpoint'
|
||||
lore:
|
||||
- ''
|
||||
- '&7&oClick this to be sent to your, &7&omost recent checkpoint'
|
||||
leave-item:
|
||||
type: BARRIER
|
||||
name: '&aLeave Parkour Event'
|
||||
lore:
|
||||
- ''
|
||||
- '&7&oClick this to be sent to, &7&othe server spawn'
|
||||
@@ -0,0 +1,44 @@
|
||||
minigame:
|
||||
countdown-message: '&8(&4!&8) &7Spleef event starts in &4{time}'
|
||||
win-message: '&8(&4!&8) &4{player}&4 has won the spleef event'
|
||||
min-players: 2
|
||||
max-players: 16
|
||||
countdown-time: 60
|
||||
world: events_world
|
||||
spawn-location:
|
||||
x: 0.5
|
||||
y: 100.0
|
||||
z: 0.5
|
||||
yaw: 48.0
|
||||
pitch: 0.0
|
||||
platform-corners:
|
||||
1:
|
||||
corner-one:
|
||||
x: 0.5
|
||||
y: 100.0
|
||||
z: 0.5
|
||||
corner-two:
|
||||
x: 0.5
|
||||
y: 100.0
|
||||
z: 0.5
|
||||
2:
|
||||
corner-one:
|
||||
x: 0.5
|
||||
y: 100.0
|
||||
z: 0.5
|
||||
corner-two:
|
||||
x: 0.5
|
||||
y: 100.0
|
||||
z: 0.5
|
||||
3:
|
||||
corner-one:
|
||||
x: 0.5
|
||||
y: 100.0
|
||||
z: 0.5
|
||||
corner-two:
|
||||
x: 0.5
|
||||
y: 100.0
|
||||
z: 0.5
|
||||
rewards:
|
||||
- 'give {player} stone 1'
|
||||
- 'eco give {player} 10'
|
||||
@@ -0,0 +1,28 @@
|
||||
minigame:
|
||||
countdown-message: '&8(&4!&8) &7Sumo event starts in &4{time}'
|
||||
win-message: '&8(&4!&8) &4{player}&4 has won the sumo event'
|
||||
min-players: 2
|
||||
max-players: 16
|
||||
countdown-time: 60
|
||||
world: events_world
|
||||
spawn-location:
|
||||
x: 0.5
|
||||
y: 100.0
|
||||
z: 0.5
|
||||
yaw: 48.0
|
||||
pitch: 0.0
|
||||
fight-location-one:
|
||||
x: 0.5
|
||||
y: 100.0
|
||||
z: 0.5
|
||||
yaw: 48.0
|
||||
pitch: 0.0
|
||||
fight-location-two:
|
||||
x: 0.5
|
||||
y: 100.0
|
||||
z: 0.5
|
||||
yaw: 48.0
|
||||
pitch: 0.0
|
||||
rewards:
|
||||
- 'give {player} stone 1'
|
||||
- 'eco give {player} 10'
|
||||
@@ -0,0 +1,27 @@
|
||||
messages:
|
||||
invalid-event-name: '&cInvalid event name'
|
||||
events-help-message:
|
||||
- '&7-- &aAstro Events &7--'
|
||||
- '&astart &7<event> &8- &7starts an event'
|
||||
- '&astop &7<event> &8- &7stops an event'
|
||||
- '&alist &8- &7list of events'
|
||||
parkour-help-message:
|
||||
- '&7-- &aAstro Events &7--'
|
||||
- '&aparkour join &8- &7teleport to the starting point'
|
||||
- '&aparkour leave &8- &7leave the parkour event'
|
||||
sumo-help-message:
|
||||
- '&7-- &aAstro Events &7--'
|
||||
- '&asumo join &8- &7teleport to the starting point'
|
||||
- '&asumo leave &8- &7leave the sumo event'
|
||||
event:
|
||||
player-joined: '&6{player} &7Joined the {game} Event &8(&6{amount}&7/&6{max}&8)'
|
||||
player-left: '&6{player} &7Left the {game} Event &8(&6{amount}&7/&6{max}&8)'
|
||||
inventory-empty: '&8(&c!&8) &7You have to empty your inventory before joining
|
||||
this event'
|
||||
not-participant: '&8(&c!&8) &7You aren''t currently participating in this {game}
|
||||
event'
|
||||
full: '&8(&c!&8) &7The {game} event is currently full'
|
||||
already-in-progress: '&8(&c!&8) &7The {game} event is already in progress'
|
||||
not-started: '&8(&c!&8) &7The {game} event has not yet started'
|
||||
list-header: '&8(&a!&8) &7Minigame List'
|
||||
list-format: '&a* &7{event}'
|
||||
@@ -0,0 +1,12 @@
|
||||
name: CrankedEvents
|
||||
main: net.crankedpvp.events.EventsPlugin
|
||||
version: ${git.total.commit.count}.0
|
||||
description: "§fCommit ID: §a${git.commit.id.abbrev}"
|
||||
website: https://crankedpvp.net/
|
||||
depend:
|
||||
- CrankedUtils
|
||||
- HolographicDisplays
|
||||
- FactionsKore
|
||||
- CrankedDeadMansChest
|
||||
- CrankedPvPTop
|
||||
- CrankedBosses
|
||||
Reference in New Issue
Block a user