Skip to content

Commit

Permalink
Rest of the cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
mattboy9921 committed Aug 21, 2023
1 parent 6d23ceb commit b45cc15
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 175 deletions.
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- For ACF -->
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-paper</artifactId>
<version>0.5.1-SNAPSHOT</version>
</dependency>
<!-- For Configurate -->
<dependency>
<groupId>org.spongepowered</groupId>
Expand Down Expand Up @@ -135,7 +129,7 @@
<dependency>
<groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit-v1.20</artifactId>
<version>3.16.0</version>
<version>3.19.1</version>
<scope>test</scope>
</dependency>
<!-- For Cloud -->
Expand All @@ -144,6 +138,11 @@
<artifactId>cloud-paper</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-minecraft-extras</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>me.lucko</groupId>
<artifactId>commodore</artifactId>
Expand Down
43 changes: 22 additions & 21 deletions src/main/java/net/mattlabs/skipnight/SkipNight.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package net.mattlabs.skipnight;

import cloud.commandframework.CommandTree;
import cloud.commandframework.bukkit.CloudBukkitCapabilities;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.execution.FilteringCommandSuggestionProcessor;
import co.aikar.commands.PaperCommandManager;
import cloud.commandframework.minecraft.extras.MinecraftExceptionHandler;
import io.leangen.geantyref.TypeToken;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.mattlabs.skipnight.commands.SkipDayCommand;
Expand All @@ -30,16 +28,15 @@
public class SkipNight extends JavaPlugin {

public Vote vote;
private PaperCommandManager paperCommandManagerOld;
private cloud.commandframework.paper.PaperCommandManager<CommandSender> paperCommandManager;
private cloud.commandframework.paper.PaperCommandManager<CommandSender> commandManager;
private ConfigurateManager configurateManager;
private Config config;
private Messages messages;
private static SkipNight instance;
private BukkitAudiences platform;
private String version;

static boolean testEnabled = false;
public static boolean testEnabled = false;

public void onEnable() {
instance = this;
Expand Down Expand Up @@ -95,12 +92,9 @@ public void onEnable() {
// Register Listeners
getServer().getPluginManager().registerEvents(vote, this);

// Register ACF
//paperCommandManagerOld = new PaperCommandManager(this);

// Register Cloud
try {
paperCommandManager = new cloud.commandframework.paper.PaperCommandManager<>(
commandManager = new cloud.commandframework.paper.PaperCommandManager<>(
this,
AsynchronousCommandExecutionCoordinator.<CommandSender>builder().build(),
Function.identity(),
Expand All @@ -111,24 +105,27 @@ public void onEnable() {
Bukkit.getPluginManager().disablePlugin(this);
}
// Use contains filter for suggestions
paperCommandManager.commandSuggestionProcessor(new FilteringCommandSuggestionProcessor<>(
commandManager.commandSuggestionProcessor(new FilteringCommandSuggestionProcessor<>(
FilteringCommandSuggestionProcessor.Filter.<CommandSender>contains(true).andTrimBeforeLastSpace()
));
// Register Brigadier
if (paperCommandManager.hasCapability(CloudBukkitCapabilities.BRIGADIER)) paperCommandManager.registerBrigadier();
if (commandManager.hasCapability(CloudBukkitCapabilities.BRIGADIER)) commandManager.registerBrigadier();
// Register asynchronous completions
if (paperCommandManager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) paperCommandManager.registerAsynchronousCompletions();
if (commandManager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) commandManager.registerAsynchronousCompletions();
// Override exception handlers
new MinecraftExceptionHandler<CommandSender>()
.withInvalidSyntaxHandler()
.withInvalidSenderHandler()
.withHandler(MinecraftExceptionHandler.ExceptionType.NO_PERMISSION, component -> messages.general().noPerm())
.withArgumentParsingHandler()
.withCommandExecutionHandler()
.withDecorator(component -> Messages.voteHeader().append(component))
.apply(commandManager, platform::sender);
// Create Commands
if (config.isSkipNight() || testEnabled)
new SkipNightCommand(paperCommandManager, this);
new SkipNightCommand(commandManager, this);
if (config.isSkipDay() || testEnabled)
new SkipDayCommand(paperCommandManager, this);

// Register Commands with ACF
// if (config.isSkipNight() || testEnabled)
// paperCommandManagerOld.registerCommand(new SkipNightCommand(this));
// if (config.isSkipDay() || testEnabled)
// paperCommandManagerOld.registerCommand(new SkipDayCommand(this));
new SkipDayCommand(commandManager, this);

// bStats
if (!testEnabled) new Metrics(this, 5796);
Expand Down Expand Up @@ -163,6 +160,10 @@ public Config getConfiguration() {
return config;
}

public cloud.commandframework.paper.PaperCommandManager<CommandSender> getCommandManager() {
return commandManager;
}

public boolean hasPlayerActivity() {
return getServer().getPluginManager().getPlugin("PlayerActivity") != null;
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/net/mattlabs/skipnight/Vote.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class Vote implements Runnable, Listener {

private enum Timer {
enum Timer {
INIT,
OPERATION,
INTERRUPT,
Expand All @@ -30,7 +30,7 @@ private enum Timer {
OFF
}

private Timer timer;
Timer timer;
private VoteType voteType;
private int yes, no, playerCount, countDown, countDownInit, away, idle;
private BossBar bar;
Expand Down Expand Up @@ -68,6 +68,7 @@ public void onLogoff(PlayerQuitEvent event) {
@EventHandler
public void onBedEnter(PlayerBedEnterEvent event) {
Player player = event.getPlayer();
// TODO fix so players clicking on bed during day don't get message
// Player has permission and isn't the only one in the world
if (player.hasPermission("skipnight.vote.night") && player.getWorld().getPlayers().size() > 1 && timer == Timer.OFF) {
platform.player(player).sendMessage(messages.beforeVote().inBedNoVoteInProg());
Expand Down Expand Up @@ -387,8 +388,11 @@ private void updateAll(Component message) {

if (message != null) messageList.add(message);

// TODO move this so not in overworld gets messages too
// Send messages
for (Component messageToSend : messageList) platform.player(player).sendMessage(messageToSend);
for (Component messageToSend : messageList) {
SkipNight.getInstance().getPlatform().player(player).sendMessage(messageToSend);
}
}
// Not in Overworld
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.paper.PaperCommandManager;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import net.mattlabs.skipnight.SkipNight;
import net.mattlabs.skipnight.Vote;
import net.mattlabs.skipnight.util.VoteType;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import static org.bukkit.Bukkit.getLogger;

@CommandAlias("skipday|sd")
@CommandPermission("skipnight.vote.day")
public class SkipDayCommand extends BaseCommand {
public class SkipDayCommand {

PaperCommandManager<CommandSender> commandManager;
Vote vote;
Expand Down Expand Up @@ -66,40 +60,4 @@ private void yes(CommandContext<CommandSender> context) {
private void no(CommandContext<CommandSender> context) {
this.vote.addNo((Player) context.getSender(), VoteType.DAY);
}

@Default
@Description("Starts a vote to skip the day.")
public void onSkipNight(CommandSender sender) {
if (!(sender instanceof Player)) {
getLogger().info("Vote can't be started from console.");
}
else {
Player player = (Player) sender;
this.vote.start(player, VoteType.DAY);
}
}

@Subcommand("yes")
@Description("Votes yes for current vote.")
public void onYes(CommandSender sender) {
if (!(sender instanceof Player)) {
getLogger().info("Vote not allowed from console.");
}
else {
Player player = (Player) sender;
this.vote.addYes(player, VoteType.DAY);
}
}

@Subcommand("no")
@Description("Votes no for current vote.")
public void onNo(CommandSender sender) {
if (!(sender instanceof Player)) {
getLogger().info("Vote not allowed from console.");
}
else {
Player player = (Player) sender;
this.vote.addNo(player, VoteType.DAY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.paper.PaperCommandManager;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.CommandContexts;
import co.aikar.commands.annotation.*;
import net.mattlabs.skipnight.SkipNight;
import net.mattlabs.skipnight.Vote;
import net.mattlabs.skipnight.util.VoteType;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import static org.bukkit.Bukkit.getLogger;

@CommandAlias("skipnight|sn")
@CommandPermission("skipnight.vote.night")
public class SkipNightCommand extends BaseCommand {
public class SkipNightCommand {

PaperCommandManager<CommandSender> commandManager;
Vote vote;
Expand Down Expand Up @@ -67,40 +60,4 @@ private void yes(CommandContext<CommandSender> context) {
private void no(CommandContext<CommandSender> context) {
this.vote.addNo((Player) context.getSender(), VoteType.NIGHT);
}

@Default
@Description("Starts a vote to skip the night.")
public void onSkipNight(CommandSender sender) {
if (!(sender instanceof Player)) {
getLogger().info("Vote can't be started from console.");
}
else {
Player player = (Player) sender;
this.vote.start(player, VoteType.NIGHT);
}
}

@Subcommand("yes")
@Description("Votes yes for current vote.")
public void onYes(CommandSender sender) {
if (!(sender instanceof Player)) {
getLogger().info("Vote not allowed from console.");
}
else {
Player player = (Player) sender;
this.vote.addYes(player, VoteType.NIGHT);
}
}

@Subcommand("no")
@Description("Votes no for current vote.")
public void onNo(CommandSender sender) {
if (!(sender instanceof Player)) {
getLogger().info("Vote not allowed from console.");
}
else {
Player player = (Player) sender;
this.vote.addNo(player, VoteType.NIGHT);
}
}
}
4 changes: 0 additions & 4 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ author: mattboy9921 ([email protected])
website: https://www.spigotmc.org/resources/skipnight.48334/
softdepend: [PlayerActivity]
main: net.mattlabs.skipnight.SkipNight
commands:
skipnight:
description: SkipNight command(s).
usage: /skipnight [yes|no]
permissions:
skipnight.vote.night:
description: Allows player to vote to skip the night.
Expand Down
8 changes: 5 additions & 3 deletions src/test/java/net/mattlabs/skipnight/DayVoteTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package net.mattlabs.skipnight;

import net.mattlabs.skipnight.util.VoteType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@SuppressWarnings("ConstantConditions")
public class DayVoteTest extends VoteTest {

@Override
String voteType() {
return "day";
VoteType voteType() {
return VoteType.DAY;
}

@Override
Expand All @@ -28,7 +30,7 @@ public void voteDuringNight() {
world.setTime(16000);

// Player starts vote
server.execute("skip" + voteType, player1).assertSucceeded();
vote.start(player1, voteType);
Assertions.assertEquals(
plain.serialize(plugin.getMessages().beforeVote().canOnlyVoteAtDay()),
plain.serialize(player1.nextComponentMessage())
Expand Down
Loading

0 comments on commit b45cc15

Please sign in to comment.