Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import space.yurisi.universecorev2.subplugins.elevator.Elevator;
import space.yurisi.universecorev2.subplugins.evolutionitem.EvolutionItem;
import space.yurisi.universecorev2.subplugins.fishingsystem.FishingSystem;
import space.yurisi.universecorev2.subplugins.flysystem.FlySystem;
import space.yurisi.universecorev2.subplugins.gacha.Gacha;
import space.yurisi.universecorev2.subplugins.itemhat.ItemHat;
import space.yurisi.universecorev2.subplugins.freemarket.FreeMarket;
Expand All @@ -32,7 +33,6 @@
import space.yurisi.universecorev2.subplugins.tickfreezer.TickFreezer;
import space.yurisi.universecorev2.subplugins.universeguns.UniverseGuns;
import space.yurisi.universecorev2.subplugins.universejob.UniverseJob;
import space.yurisi.universecorev2.subplugins.universejob.command.JobCommand;
import space.yurisi.universecorev2.subplugins.universeslot.UniverseSlot;
import space.yurisi.universecorev2.subplugins.universeutilcommand.UniverseUtilCommand;
import space.yurisi.universecorev2.subplugins.signcommand.SignCommand;
Expand Down Expand Up @@ -101,6 +101,8 @@ private void registerPlugin() {
this.subPlugins.add(new UniverseSlot());
this.subPlugins.add(new SpaceShip());
this.subPlugins.add(new Cooking());
this.subPlugins.add(new FlySystem());

}

public void onEnable() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package space.yurisi.universecorev2.subplugins.flysystem;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import space.yurisi.universecorev2.api.LuckPermsWrapper;

import java.util.Locale;

public class FlyCommand implements CommandExecutor {

private final FlySystemMessageFormatter formatter;

public FlyCommand() {
this.formatter = new FlySystemMessageFormatter();
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage("このコマンドはゲーム内から実行してください。");
return false;
}

// TODO: とりあえず管理者と開発者のみ使用可能にしているが,拡張性がなさすぎるのでいつか直す
if (!LuckPermsWrapper.isUserInAdminOrDevGroup(player)) {
player.sendMessage(formatter.formatError("このコマンドを実行する権限がありません。"));
return false;
}

boolean newFlyState = !player.getAllowFlight();
player.setAllowFlight(newFlyState);
if (!newFlyState) {
player.setFlying(false);
}

player.sendMessage(formatter.format(newFlyState ? "飛行モードを有効にしました。" : "飛行モードを無効にしました。"));
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package space.yurisi.universecorev2.subplugins.flysystem;

import space.yurisi.universecorev2.UniverseCoreV2;
import space.yurisi.universecorev2.subplugins.SubPlugin;

public final class FlySystem implements SubPlugin {

@Override
public void onEnable(UniverseCoreV2 core) {
core.getCommand("fly").setExecutor(new FlyCommand());
}

@Override
public void onDisable() {
}

@Override
public String getName() {
return "fly";
}

@Override
public String getVersion() {
return "1.0.0";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package space.yurisi.universecorev2.subplugins.flysystem;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;

public class FlySystemMessageFormatter {

public static final String PREFIX = "[飛行システムAI]";

private static final NamedTextColor PREFIX_COLOR = NamedTextColor.GREEN;
private static final NamedTextColor MESSAGE_COLOR = NamedTextColor.WHITE;
private static final NamedTextColor ERROR_COLOR = NamedTextColor.RED;

/**
* 通常メッセージをフォーマットします。
*
* @param message メッセージ本文
* @return フォーマットされた Component
*/
public Component format(String message) {
return Component.text(PREFIX, PREFIX_COLOR)
.append(Component.text(" "))
.append(Component.text(message, MESSAGE_COLOR));
}

/**
* エラーメッセージをフォーマットします。
*
* @param errorMessage エラーメッセージ本文
* @return フォーマットされた Component
*/
public Component formatError(String errorMessage) {
return Component.text(PREFIX, PREFIX_COLOR)
.append(Component.text(" "))
.append(Component.text(errorMessage, ERROR_COLOR));
}
}
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,7 @@ commands:
#cooking:
cooking:
description: レシピを編集します

#fly
fly:
description: 飛行モードを切り替えます