Skip to content

Commit

Permalink
Merge pull request #77 from Braekpo1nt/dev
Browse files Browse the repository at this point in the history
Merge v0.2.0-alpha
  • Loading branch information
Braekpo1nt authored Mar 31, 2023
2 parents f6bb0e8 + fe11c69 commit a463f6a
Show file tree
Hide file tree
Showing 15 changed files with 1,182 additions and 192 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Dependencies
Dependencies that are require to run this plugin

## Data Packs
As of release `v0.1.1-alpha`, this plugin expects the following data packs in the server's `world/datapacks/` directory:
- [mctdatapack](https://github.com/Braekpo1nt/mctdatapack)

## Plugins
- This plugin depends on [Multiverse-Core v4.3.1](https://github.com/Multiverse/Multiverse-Core/releases/tag/v4.3.1)

This plugin depends on [Multiverse-Core v4.3.1](https://github.com/Multiverse/Multiverse-Core/releases/tag/v4.3.1)

# Running the event

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'org.braekpo1nt'
version = 'v0.1.1-alpha'
version = '0.2.0-alpha'

repositories {
mavenCentral()
Expand Down
61 changes: 26 additions & 35 deletions src/main/java/org/braekpo1nt/mctmanager/Main.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
package org.braekpo1nt.mctmanager;

import com.onarandombox.MultiverseCore.MultiverseCore;
import fr.mrmicky.fastboard.FastBoard;
import org.braekpo1nt.mctmanager.commands.MCTCommand;
import org.braekpo1nt.mctmanager.commands.MCTDebugCommand;
import org.braekpo1nt.mctmanager.games.GameManager;
import org.braekpo1nt.mctmanager.hub.HubManager;
import org.braekpo1nt.mctmanager.listeners.BlockEffectsListener;
import org.braekpo1nt.mctmanager.listeners.HubBoundaryListener;
import org.braekpo1nt.mctmanager.hub.HubBoundaryListener;
import org.braekpo1nt.mctmanager.listeners.PlayerJoinListener;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.Scoreboard;

import java.io.File;
import java.io.IOException;

public final class Main extends JavaPlugin {

public static MultiverseCore multiverseCore;

private final static PotionEffect RESISTANCE = new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 1000000, 200, true, false, false);
private final static PotionEffect REGENERATION = new PotionEffect(PotionEffectType.REGENERATION, 1000000, 200, true, false, false);
private final static PotionEffect NIGHT_VISION = new PotionEffect(PotionEffectType.NIGHT_VISION, 1000000, 3, true, false, false);
private final static PotionEffect FIRE_RESISTANCE = new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 1000000, 1, true, false, false);
private final static PotionEffect SATURATION = new PotionEffect(PotionEffectType.SATURATION, 1000000, 250, true, false, false);
private Scoreboard mctScoreboard;
private GameManager gameManager;
private boolean saveGameStateOnDisable = true;
public final static PotionEffect NIGHT_VISION = new PotionEffect(PotionEffectType.NIGHT_VISION, 300, 3, true, false, false);

@Override
public void onEnable() {
Expand All @@ -42,10 +36,12 @@ public void onEnable() {
return;
}
Main.multiverseCore = ((MultiverseCore) multiversePlugin);

Scoreboard mctScoreboard = Bukkit.getScoreboardManager().getNewScoreboard();

HubManager hubManager = new HubManager(this);

mctScoreboard = Bukkit.getScoreboardManager().getNewScoreboard();

gameManager = new GameManager(this, mctScoreboard);
gameManager = new GameManager(this, mctScoreboard, hubManager);
try {
gameManager.loadGameState();
} catch (IOException e) {
Expand All @@ -63,16 +59,30 @@ public void onEnable() {
// Commands
new MCTDebugCommand(this);
new MCTCommand(this, gameManager, hubBoundaryListener, blockEffectsListener);

File dataFolder = getDataFolder();
initializeStatusEffectScheduler();

alwaysGiveNightVision();
}

private void alwaysGiveNightVision() {
Bukkit.getLogger().info("[MCTManager] Night vision activated");
new BukkitRunnable() {
@Override
public void run() {
for (Player player : Bukkit.getOnlinePlayers()) {
player.addPotionEffect(NIGHT_VISION);
}
}
}.runTaskTimer(this, 0L, 60L);
}

@Override
public void onDisable() {
if (saveGameStateOnDisable && gameManager != null) {
try {
gameManager.saveGameState();
if (gameManager.gameIsRunning()) {
gameManager.manuallyStopGame(false);
}
} catch (IOException e) {
Bukkit.getLogger().severe("[MCTManager] Could not save game state. Printing stack trace below.");
e.printStackTrace();
Expand All @@ -81,23 +91,4 @@ public void onDisable() {
Bukkit.getLogger().info("[MCTManager] Skipping save game state.");
}
}

public static void giveAmbientStatusEffects(Player player) {
player.addPotionEffect(RESISTANCE);
player.addPotionEffect(REGENERATION);
player.addPotionEffect(NIGHT_VISION);
player.addPotionEffect(FIRE_RESISTANCE);
player.addPotionEffect(SATURATION);
}

private void initializeStatusEffectScheduler() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
@Override
public void run() {
for (Player player : Bukkit.getOnlinePlayers()) {
giveAmbientStatusEffects(player);
}
}
}, 0L, 60L);
}
}
57 changes: 36 additions & 21 deletions src/main/java/org/braekpo1nt/mctmanager/color/ColorMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,56 @@
import java.util.Map;
import java.util.HashMap;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Color;

public class ColorMap {

private static final Map<String, NamedTextColor> COLOR_MAP = new HashMap<>();
private static final Map<String, NamedTextColor> NAMED_TEXT_COLOR_MAP = new HashMap<>();
static {
NAMED_TEXT_COLOR_MAP.put("black", NamedTextColor.BLACK);
NAMED_TEXT_COLOR_MAP.put("dark_blue", NamedTextColor.DARK_BLUE);
NAMED_TEXT_COLOR_MAP.put("dark_green", NamedTextColor.DARK_GREEN);
NAMED_TEXT_COLOR_MAP.put("dark_aqua", NamedTextColor.DARK_AQUA);
NAMED_TEXT_COLOR_MAP.put("dark_red", NamedTextColor.DARK_RED);
NAMED_TEXT_COLOR_MAP.put("dark_purple", NamedTextColor.DARK_PURPLE);
NAMED_TEXT_COLOR_MAP.put("gold", NamedTextColor.GOLD);
NAMED_TEXT_COLOR_MAP.put("gray", NamedTextColor.GRAY);
NAMED_TEXT_COLOR_MAP.put("dark_gray", NamedTextColor.DARK_GRAY);
NAMED_TEXT_COLOR_MAP.put("blue", NamedTextColor.BLUE);
NAMED_TEXT_COLOR_MAP.put("green", NamedTextColor.GREEN);
NAMED_TEXT_COLOR_MAP.put("aqua", NamedTextColor.AQUA);
NAMED_TEXT_COLOR_MAP.put("red", NamedTextColor.RED);
NAMED_TEXT_COLOR_MAP.put("light_purple", NamedTextColor.LIGHT_PURPLE);
NAMED_TEXT_COLOR_MAP.put("yellow", NamedTextColor.YELLOW);
NAMED_TEXT_COLOR_MAP.put("white", NamedTextColor.WHITE);
}

private static final Map<String, Color> COLOR_MAP = new HashMap<>();

static {
COLOR_MAP.put("black", NamedTextColor.BLACK);
COLOR_MAP.put("dark_blue", NamedTextColor.DARK_BLUE);
COLOR_MAP.put("dark_green", NamedTextColor.DARK_GREEN);
COLOR_MAP.put("dark_aqua", NamedTextColor.DARK_AQUA);
COLOR_MAP.put("dark_red", NamedTextColor.DARK_RED);
COLOR_MAP.put("dark_purple", NamedTextColor.DARK_PURPLE);
COLOR_MAP.put("gold", NamedTextColor.GOLD);
COLOR_MAP.put("gray", NamedTextColor.GRAY);
COLOR_MAP.put("dark_gray", NamedTextColor.DARK_GRAY);
COLOR_MAP.put("blue", NamedTextColor.BLUE);
COLOR_MAP.put("green", NamedTextColor.GREEN);
COLOR_MAP.put("aqua", NamedTextColor.AQUA);
COLOR_MAP.put("red", NamedTextColor.RED);
COLOR_MAP.put("light_purple", NamedTextColor.LIGHT_PURPLE);
COLOR_MAP.put("yellow", NamedTextColor.YELLOW);
COLOR_MAP.put("white", NamedTextColor.WHITE);
for (Map.Entry<String, NamedTextColor> entry : NAMED_TEXT_COLOR_MAP.entrySet()) {
NamedTextColor namedTextColor = entry.getValue();
Color bukkitColor = Color.fromBGR(namedTextColor.blue(), namedTextColor.green(), namedTextColor.red());
COLOR_MAP.put(entry.getKey(), bukkitColor);
}
}

public static NamedTextColor getColor(String colorString) {
NamedTextColor color = COLOR_MAP.get(colorString.toLowerCase());
public static NamedTextColor getNamedTextColor(String colorString) {
NamedTextColor color = NAMED_TEXT_COLOR_MAP.get(colorString.toLowerCase());
return color != null ? color : NamedTextColor.WHITE;
}

public static Color getColor(String colorString) {
Color color = COLOR_MAP.get(colorString);
return color != null ? color : Color.WHITE;
}

public static boolean hasColor(String colorString) {
return COLOR_MAP.containsKey(colorString);
return NAMED_TEXT_COLOR_MAP.containsKey(colorString);
}

public static List<String> getPartiallyMatchingColorStrings(String colorString) {
return COLOR_MAP.keySet().stream()
return NAMED_TEXT_COLOR_MAP.keySet().stream()
.filter(color -> color.startsWith(colorString))
.sorted()
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.braekpo1nt.mctmanager.commands.team.TeamSubCommand;
import org.braekpo1nt.mctmanager.games.GameManager;
import org.braekpo1nt.mctmanager.listeners.BlockEffectsListener;
import org.braekpo1nt.mctmanager.listeners.HubBoundaryListener;
import org.braekpo1nt.mctmanager.hub.HubBoundaryListener;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand Down
101 changes: 94 additions & 7 deletions src/main/java/org/braekpo1nt/mctmanager/commands/MCTDebugCommand.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
package org.braekpo1nt.mctmanager.commands;

import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.title.Title;
import org.braekpo1nt.mctmanager.Main;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.structure.Mirror;
import org.bukkit.block.structure.StructureRotation;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.loot.LootTable;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.structure.Structure;
import org.jetbrains.annotations.NotNull;

import java.time.Duration;
import java.util.Random;

/**
* A utility command for testing various things, so I don't have to create a new command.
*/
public class MCTDebugCommand implements CommandExecutor {

private final Main plugin;
private int boarderShrinkingTaskId;
private final WorldBorder worldBorder;

public MCTDebugCommand(Main plugin) {
this.plugin = plugin;
plugin.getCommand("mctdebug").setExecutor(this);
MVWorldManager worldManager = Main.multiverseCore.getMVWorldManager();
World mechaWorld = worldManager.getMVWorld("FT").getCBWorld();
this.worldBorder = mechaWorld.getWorldBorder();
}

@Override
Expand All @@ -29,15 +46,85 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
sender.sendMessage("This command can only be run by a player.");
return true;
}
Player player = ((Player) sender).getPlayer();
// Player player = ((Player) sender).getPlayer();
if (args.length < 1) {
sender.sendMessage("usage: /mctdebug [on|off]");
return true;
}

Component mainTitle = Component.text("Main title");
Component subTitle = Component.text("Subtitle");

Title.Times times = Title.Times.times(Duration.ofMillis(500), Duration.ofSeconds(3), Duration.ofMillis(500));
Title title = Title.title(mainTitle, subTitle, times);
sender.showTitle(title);
switch (args[0]) {
case "on":
worldBorder.setCenter(0, 0);
worldBorder.setSize(248);
kickOffBoarderShrinking();
return true;
case "off":
Bukkit.getScheduler().cancelTask(boarderShrinkingTaskId);
worldBorder.reset();
return true;
default:
sender.sendMessage("Not recognized option: " + args[0]);
}

// Component mainTitle = Component.text("Main title");
// Component subTitle = Component.text("Subtitle");
//
// Title.Times times = Title.Times.times(Duration.ofMillis(500), Duration.ofSeconds(3), Duration.ofMillis(500));
// Title title = Title.title(mainTitle, subTitle, times);
// sender.showTitle(title);

return true;
}

private void kickOffBoarderShrinking() {
// int[] sizes = new int[]{180, 150, 100, 50, 25, 2};
// int[] delays = new int[]{90, 70, 60, 80, 60, 30};
// int[] durations = new int[]{25,0, 100, 50, 25, 2};
int[] sizes = new int[]{180, 150, 100};
int[] delays = new int[]{11, 10, 9};
int[] durations = new int[]{15, 10, 5};
this.boarderShrinkingTaskId = new BukkitRunnable() {
int delay = 0;
int duration = 0;
boolean onDelay = false;
boolean onDuration = false;
int sceneIndex = 0;
@Override
public void run() {
if (onDelay) {
Bukkit.getLogger().info(String.format("Delaying %d/%d", delay, delays[sceneIndex]));
if (delay <= 0) {
onDelay = false;
onDuration = true;
duration = durations[sceneIndex];
int size = sizes[sceneIndex];
worldBorder.setSize(size, duration);
return;
}
delay--;
} else if (onDuration) {
Bukkit.getLogger().info(String.format("Shrinking to %d, %d/%d", sizes[sceneIndex], duration, durations[sceneIndex]));
if (duration <= 0) {
onDuration = false;
onDelay = true;
sceneIndex++;
if (sceneIndex >= delays.length) {
Bukkit.getLogger().info("Boarder is done shrinking");
this.cancel();
return;
}
delay = delays[sceneIndex];
return;
}
duration--;
} else {
//initialize
onDelay = true;
delay = delays[0];
}
}
}.runTaskTimer(plugin, 0L, 20L).getTaskId();
}


}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.braekpo1nt.mctmanager.commands;

import org.braekpo1nt.mctmanager.listeners.BlockEffectsListener;
import org.braekpo1nt.mctmanager.listeners.HubBoundaryListener;
import org.braekpo1nt.mctmanager.hub.HubBoundaryListener;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
Expand Down
Loading

0 comments on commit a463f6a

Please sign in to comment.