Skip to content

Commit

Permalink
Merge pull request #265 from Sylfare/feat/1_21
Browse files Browse the repository at this point in the history
feat: 1.21 support
  • Loading branch information
oddlama authored Sep 5, 2024
2 parents c3b3d70 + 4597add commit ef5e23c
Show file tree
Hide file tree
Showing 83 changed files with 1,488 additions and 858 deletions.
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
`java-library`
id("io.papermc.paperweight.userdev") version "1.7.1"
id("io.papermc.paperweight.userdev") version "1.7.2"
id("xyz.jpenilla.run-paper") version "2.3.0" // Adds runServer and runMojangMappedServer tasks for testing
}

dependencies {
paperDevBundle("1.20.6-R0.1-SNAPSHOT")
paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT")
}

java {
Expand Down Expand Up @@ -55,7 +55,7 @@ configure(subprojects.filter {
apply(plugin = "io.papermc.paperweight.userdev")

dependencies {
paperDevBundle("1.20.6-R0.1-SNAPSHOT")
paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT")
}
}

Expand Down Expand Up @@ -92,7 +92,7 @@ configure(subprojects.filter {
}

processResources {
filesMatching("**/plugin.yml") {
filesMatching("**/*plugin.yml") {
expand(project.properties)
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@ configure(subprojects.filter {
listOf("vane-bedtime", "vane-portals", "vane-regions").contains(it.name)
}) {
dependencies {
implementation(group = "us.dynmap", name = "dynmap-api", version = "3.2-SNAPSHOT")
implementation(group = "us.dynmap", name = "DynmapCoreAPI", version = "3.7-beta-6")
implementation(group = "de.bluecolored.bluemap", name = "BlueMapAPI", version = "2.7.2")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ public class AutostopGroup extends ModuleGroup<Admin> {
// Variables
public BukkitTask task = null;
public long start_time = -1;
public long stop_time = -1;

public AutostopGroup(Context<Admin> context) {
super(context, "autostop", "Enable automatic server stop after certain time without online players.");
}

public long remaining() {

if (start_time == -1) {
return -1;
}
return start_time + (config_delay * 1000) - System.currentTimeMillis();

return stop_time - System.currentTimeMillis();

}

public void abort() {
Expand All @@ -59,6 +63,7 @@ public void abort(CommandSender sender) {
task.cancel();
task = null;
start_time = -1;
stop_time = -1;

lang_aborted.send_and_log(sender);
}
Expand All @@ -77,6 +82,7 @@ public void schedule(CommandSender sender, long delay) {
}

start_time = System.currentTimeMillis();
stop_time = start_time + delay;
task =
schedule_task(
() -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package org.oddlama.vane.admin.commands;

import static org.oddlama.vane.util.TimeUtil.parse_time;
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
import static io.papermc.paper.command.brigadier.Commands.argument;
import static io.papermc.paper.command.brigadier.Commands.literal;

import org.bukkit.command.CommandSender;
import org.oddlama.vane.admin.Admin;
import org.oddlama.vane.admin.AutostopGroup;
import org.oddlama.vane.annotation.command.Name;
import org.oddlama.vane.core.command.Command;
import org.oddlama.vane.util.Conversions;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;

import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;

@Name("autostop")
public class Autostop extends Command<Admin> {
Expand All @@ -16,16 +24,20 @@ public class Autostop extends Command<Admin> {
public Autostop(AutostopGroup context) {
super(context);
this.autostop = context;
}

// Add help
params().fixed("help").ignore_case().exec(this::print_help);
// Command parameters
params().exec(this::status);
params().fixed("abort").ignore_case().exec(this::abort);
params().fixed("status").ignore_case().exec(this::status);
var schedule = params().fixed("schedule").ignore_case();
schedule.exec(this::schedule);
schedule.any_string().exec(this::schedule_delay);
@Override
public LiteralArgumentBuilder<CommandSourceStack> get_command_base() {
return super.get_command_base()
.executes(ctx -> { status(ctx.getSource().getSender()); return SINGLE_SUCCESS; })
.then(help())
.then(literal("status").executes(ctx -> { status(ctx.getSource().getSender()); return SINGLE_SUCCESS; }))
.then(literal("abort").executes(ctx -> { abort(ctx.getSource().getSender()); return SINGLE_SUCCESS;}))
.then(literal("schedule")
.executes(ctx -> { schedule(ctx.getSource().getSender()); return SINGLE_SUCCESS; })
.then(argument("time", ArgumentTypes.time())
.executes(ctx -> { schedule_delay(ctx.getSource().getSender(), ctx.getArgument("time", Integer.class)); return SINGLE_SUCCESS;}))
);
}

private void status(CommandSender sender) {
Expand All @@ -40,11 +52,7 @@ private void schedule(CommandSender sender) {
autostop.schedule(sender);
}

private void schedule_delay(CommandSender sender, String delay) {
try {
autostop.schedule(sender, parse_time(delay));
} catch (NumberFormatException e) {
get_module().core.lang_invalid_time_format.send(sender, e.getMessage());
}
private void schedule_delay(CommandSender sender, int delay){
autostop.schedule(sender, Conversions.ticks_to_ms(delay));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.oddlama.vane.admin.commands;

import net.kyori.adventure.text.format.NamedTextColor;
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
import static io.papermc.paper.command.brigadier.Commands.argument;
import static io.papermc.paper.command.brigadier.Commands.literal;

import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -12,6 +15,16 @@
import org.oddlama.vane.core.lang.TranslatedMessage;
import org.oddlama.vane.core.module.Context;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;

import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;

@Name("gamemode")
@Aliases({ "gm" })
public class Gamemode extends Command<Admin> {
Expand All @@ -21,14 +34,35 @@ public class Gamemode extends Command<Admin> {

public Gamemode(Context<Admin> context) {
super(context);
// Add help
params().fixed("help").ignore_case().exec(this::print_help);
// Command parameters
params().exec_player(this::toggle_gamemode_self);
params().choose_online_player().exec(this::toggle_gamemode_player);
var gamemode = params().choose_gamemode();
gamemode.exec_player(this::set_gamemode_self);
gamemode.choose_online_player().exec(this::set_gamemode);
}

@Override
public LiteralArgumentBuilder<CommandSourceStack> get_command_base() {
return super.get_command_base()
.then(help())

.executes(ctx -> {toggle_gamemode_self((Player) ctx.getSource().getSender()); return SINGLE_SUCCESS;})

.then(argument("game_mode", ArgumentTypes.gameMode())
.executes(ctx -> { set_gamemode_self((Player) ctx.getSource().getSender(), ctx.getArgument("game_mode", GameMode.class)); return SINGLE_SUCCESS;})
.then(argument("player", ArgumentTypes.player())
.executes(ctx -> {
set_gamemode(ctx.getSource().getSender(), ctx.getArgument("game_mode", GameMode.class), player(ctx));
return SINGLE_SUCCESS;
})
)
)
.then(argument("player", ArgumentTypes.player())
.executes(ctx -> {
toggle_gamemode_player(ctx.getSource().getSender(), player(ctx));

return SINGLE_SUCCESS;
})
);
}

private Player player(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException{
return ctx.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(ctx.getSource()).get(0);
}

private void toggle_gamemode_self(Player player) {
Expand All @@ -45,6 +79,6 @@ private void set_gamemode_self(Player player, GameMode mode) {

private void set_gamemode(CommandSender sender, GameMode mode, Player player) {
player.setGameMode(mode);
lang_set.send(sender, player.displayName().color(NamedTextColor.AQUA), "§a" + mode.name());
lang_set.send(sender, player.displayName().color(NamedTextColor.AQUA), Component.text(mode.name(), NamedTextColor.GREEN));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.oddlama.vane.admin.commands;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
import static io.papermc.paper.command.brigadier.Commands.literal;

import org.bukkit.entity.Player;
import org.oddlama.vane.admin.Admin;
import org.oddlama.vane.annotation.command.Name;
Expand All @@ -8,6 +11,10 @@
import org.oddlama.vane.core.lang.TranslatedMessage;
import org.oddlama.vane.core.module.Context;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;

import io.papermc.paper.command.brigadier.CommandSourceStack;

@Name("slimechunk")
public class SlimeChunk extends Command<Admin> {

Expand All @@ -19,10 +26,14 @@ public class SlimeChunk extends Command<Admin> {

public SlimeChunk(Context<Admin> context) {
super(context);
// Add help
params().fixed("help").ignore_case().exec(this::print_help);
// Command parameters
params().exec_player(this::is_slimechunk);
}

@Override
public LiteralArgumentBuilder<CommandSourceStack> get_command_base() {
return super.get_command_base()
.requires(stack -> stack.getSender() instanceof Player)
.then(help())
.executes(ctx -> {is_slimechunk((Player) ctx.getSource().getSender()); return SINGLE_SUCCESS;});
}

private void is_slimechunk(final Player player) {
Expand Down
55 changes: 27 additions & 28 deletions vane-admin/src/main/java/org/oddlama/vane/admin/commands/Time.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
package org.oddlama.vane.admin.commands;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
import static io.papermc.paper.command.brigadier.Commands.argument;
import static org.oddlama.vane.util.WorldUtil.change_time_smoothly;

import java.util.List;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.oddlama.vane.admin.Admin;
import org.oddlama.vane.annotation.command.Name;
import org.oddlama.vane.core.command.Command;
import org.oddlama.vane.core.command.argumentType.TimeValueArgumentType;
import org.oddlama.vane.core.command.enums.TimeValue;
import org.oddlama.vane.core.module.Context;

@Name("time")
public class Time extends Command<Admin> {
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;

public enum TimeValue {
dawn(23000),
day(1000),
noon(6000),
afternoon(9000),
dusk(13000),
night(14000),
midnight(18000);
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;

private int ticks;
@Name("time")
public class Time extends Command<Admin> {

private TimeValue(int ticks) {
this.ticks = ticks;
}
public Time(Context<Admin> context) {
super(context);
}

public int ticks() {
return ticks;
}
@Override
public LiteralArgumentBuilder<CommandSourceStack> get_command_base() {
return super.get_command_base()
.then(help())
.then(argument("time", TimeValueArgumentType.timeValue())
.executes(ctx -> { set_time_current_world((Player) ctx.getSource().getSender(), time_value(ctx)); return SINGLE_SUCCESS;})
.then(argument("world", ArgumentTypes.world())
.executes(ctx -> { set_time(time_value(ctx), ctx.getArgument("world", World.class)); return SINGLE_SUCCESS;})
)
)
;
}

public Time(Context<Admin> context) {
super(context);
// Add help
params().fixed("help").ignore_case().exec(this::print_help);
// Command parameters
var time = params().choice("time", List.of(TimeValue.values()), t -> t.name()).ignore_case();
time.exec_player(this::set_time_current_world);
time.choose_world().exec(this::set_time);
private TimeValue time_value(CommandContext<CommandSourceStack> ctx) {
return ctx.getArgument("time", TimeValue.class);
}

private void set_time_current_world(Player player, TimeValue t) {
change_time_smoothly(player.getWorld(), get_module(), t.ticks(), 100);
}

private void set_time(CommandSender sender, TimeValue t, World world) {
private void set_time(TimeValue t, World world) {
change_time_smoothly(world, get_module(), t.ticks(), 100);
}
}
Loading

0 comments on commit ef5e23c

Please sign in to comment.