Skip to content

Commit

Permalink
chore: Remove unused code and deprecated parts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylfare committed Jul 11, 2024
1 parent 05f0924 commit baa48f0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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 static org.oddlama.vane.util.WorldUtil.change_time_smoothly;

import org.bukkit.World;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

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 java.util.List;

import org.bukkit.World;
import org.bukkit.command.CommandSender;
Expand All @@ -27,12 +24,6 @@ public class Weather extends Command<Admin> {

public Weather(Context<Admin> context) {
super(context);
// Add help
params().fixed("help").ignore_case().exec(this::print_help);
// Command parameters
var time = params().choice("weather", List.of(WeatherValue.values()), t -> t.name()).ignore_case();
time.exec_player(this::set_weather_current_world);
time.choose_world().exec(this::set_weather);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import static org.oddlama.vane.util.StorageUtil.namespaced_key;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
Expand Down Expand Up @@ -37,6 +37,9 @@
import org.oddlama.vane.core.functional.Function6;
import org.oddlama.vane.core.module.Module;

import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;

@SuppressWarnings("overloads")
public interface Param {
public List<Param> get_params();
Expand Down Expand Up @@ -292,14 +295,14 @@ public default DynamicChoiceParam<Enchantment> choose_enchantment(
return choice(
"enchantment",
sender ->
org.bukkit.Registry.ENCHANTMENT.stream().filter(e -> filter.apply(sender, e)).collect(Collectors.toList()),
RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).stream().filter(e -> filter.apply(sender, e)).collect(Collectors.toList()),
(sender, e) -> e.getKey().toString(),
(sender, str) -> {
var parts = str.split(":");
if (parts.length != 2) {
return null;
}
var e = org.bukkit.Registry.ENCHANTMENT.get(namespaced_key(parts[0], parts[1]));
var e = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).get(namespaced_key(parts[0], parts[1]));
if (!filter.apply(sender, e)) {
return null;
}
Expand Down

This file was deleted.

5 changes: 3 additions & 2 deletions vane-core/src/main/java/org/oddlama/vane/util/ItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;

import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.HoverEvent;
Expand All @@ -42,7 +44,6 @@
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.item.ItemParser;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.Item;

public class ItemUtil {
Expand Down Expand Up @@ -324,7 +325,7 @@ private static ItemStack apply_enchants(final ItemStack item_stack, @Nullable St
key = key.substring(0, level_delim);
}

final var ench = org.bukkit.Registry.ENCHANTMENT.get(NamespacedKey.fromString(key));
final var ench = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).get(NamespacedKey.fromString(key));
if (ench == null) {
throw new IllegalArgumentException(
"Cannot apply unknown enchantment '" + key + "' to item '" + item_stack + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,55 +69,6 @@ public class Permission extends Command<Permissions> {

public Permission(Context<Permissions> context) {
super(context);
// Add help
params().fixed("help").ignore_case().exec(this::print_help);

// Command parameters
var list = params().fixed("list").ignore_case();

// list groups
var groups = list.fixed("groups").ignore_case();
groups.exec(this::list_groups);
groups.choose_any_player().exec(this::list_groups_for_player);

// list permissions
var permissions = list.fixed("permissions").ignore_case();
permissions.exec(this::list_permissions);
permissions.choose_any_player().exec(this::list_permissions_for_player);
permissions
.choice(
"permission_group",
sender -> get_module().permission_groups.keySet(),
(sender, g) -> g,
(sender, str) -> get_module().permission_groups.containsKey(str) ? str : null
)
.exec(this::list_permissions_for_group);

// add a group to player
params()
.fixed("add")
.ignore_case()
.choose_any_player()
.choice(
"permission_group",
sender -> get_module().permission_groups.keySet(),
(sender, g) -> g,
(sender, str) -> get_module().permission_groups.containsKey(str) ? str : null
)
.exec(this::add_player_to_group);

// remove a group from player
params()
.fixed("remove")
.ignore_case()
.choose_any_player()
.choice(
"permission_group",
sender -> get_module().permission_groups.keySet(),
(sender, g) -> g,
(sender, str) -> get_module().permission_groups.containsKey(str) ? str : null
)
.exec(this::remove_player_from_group);
}

@Override
Expand All @@ -143,20 +94,20 @@ public LiteralArgumentBuilder<CommandSourceStack> get_command_base() {
.executes(ctx -> {list_permissions(ctx.getSource().getSender()); return SINGLE_SUCCESS;})
)
)

.then(literal("add")
.then(argument("offline_player", OfflinePlayerArgumentType.offlinePlayer())
.then(argument("permission_group", PermissionGroupArgumentType.permissionGroup(get_module().permission_groups))
.executes(ctx -> {add_player_to_group(ctx.getSource().getSender(), offline_player(ctx), permission_group(ctx)); return SINGLE_SUCCESS;})
)
)
)
)
.then(literal("remove")
.then(argument("offline_player", OfflinePlayerArgumentType.offlinePlayer())
.then(argument("permission_group", PermissionGroupArgumentType.permissionGroup(get_module().permission_groups))
.executes(ctx -> {remove_player_from_group(ctx.getSource().getSender(), offline_player(ctx), permission_group(ctx)); return SINGLE_SUCCESS;})
)
)
)
)
;
}
Expand Down

0 comments on commit baa48f0

Please sign in to comment.