Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
fix: 実行したコマンドを全権限で表示するように (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
book000 authored Aug 11, 2022
1 parent 9dba3aa commit bafc57c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 46 deletions.
48 changes: 48 additions & 0 deletions src/main/java/com/jaoafa/mymaid4/event/Event_CommandFeedback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* jaoLicense
*
* Copyright (c) 2022 jao Minecraft Server
*
* The following license applies to this project: jaoLicense
*
* Japanese: https://github.com/jaoafa/jao-Minecraft-Server/blob/master/jaoLICENSE.md
* English: https://github.com/jaoafa/jao-Minecraft-Server/blob/master/jaoLICENSE-en.md
*/

package com.jaoafa.mymaid4.event;

import com.jaoafa.mymaid4.lib.EventPremise;
import com.jaoafa.mymaid4.lib.MyMaidLibrary;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;

public class Event_CommandFeedback extends MyMaidLibrary implements Listener, EventPremise {
@Override
public String description() {
return "実行したコマンドを実行者に対して表示します。";
}

@EventHandler(priority = EventPriority.MONITOR)
public void onCommand(PlayerCommandPreprocessEvent event) {
Player executor = event.getPlayer();
String command = event.getMessage();

executor.sendMessage(Component.join(JoinConfiguration.noSeparators(),
Component.text("["),
Component.text("Cmd", Style.style(TextDecoration.UNDERLINED))
.hoverEvent(HoverEvent.showText(Component.text("クリックすると実行したコマンドをコピーします。")))
.clickEvent(ClickEvent.copyToClipboard(command)),
Component.text("] " + command))
.colorIfAbsent(NamedTextColor.DARK_GRAY));
}
}
77 changes: 31 additions & 46 deletions src/main/java/com/jaoafa/mymaid4/event/Event_CommandSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,6 @@
import org.bukkit.event.player.PlayerCommandPreprocessEvent;

public class Event_CommandSender extends MyMaidLibrary implements Listener, EventPremise {
private static void sendCmd(Player player, Player executer, String group, String command, PlayerCommandPreprocessEvent event) {
player.sendMessage(
Component.text()
.color(NamedTextColor.DARK_GRAY)
.append(
// [Group/PlayerName] command test test (取り消し済み)
Component.text(
String.format("[%s|", group),
NamedTextColor.GRAY
),
Component.text(
executer.getName(),
Style.style()
.color(NamedTextColor.GRAY)
.decorate(TextDecoration.UNDERLINED)
.clickEvent(ClickEvent.runCommand("/secrettp " + executer.getName()))
.hoverEvent(HoverEvent.showText(
Component.text(String.format("スペクテイターで%sにテレポート", executer.getName()))
))
.build()
),
Component.text(
"] ",
NamedTextColor.GRAY
),
Component.text(command, NamedTextColor.YELLOW),
Component.text((event.isCancelled() ? " (拒否)" : ""), NamedTextColor.RED)
)
);

}

@Override
public String description() {
return "実行されたコマンドを特定権限に通知します。";
Expand All @@ -71,20 +39,6 @@ public void onCommand(PlayerCommandPreprocessEvent event) {
String command = event.getMessage();
String group = getPermissionMainGroup(executor);

//feedback
if (isAMRV(executor)) {
// Verified以上は実行試行したコマンドを返す
executor.sendMessage(
Component.text()
.color(NamedTextColor.DARK_GRAY)
.append(
Component.text("["),
Component.text("Cmd", Style.style(TextDecoration.UNDERLINED, ClickEvent.copyToClipboard(command)).toBuilder().build()),
Component.text("] " + command)
)
);
}

//sender
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
//TempMute or 実行者本人
Expand All @@ -108,4 +62,35 @@ public void onCommand(PlayerCommandPreprocessEvent event) {
}
}
}

private static void sendCmd(Player player, Player executer, String group, String command, PlayerCommandPreprocessEvent event) {
player.sendMessage(
Component.text()
.color(NamedTextColor.DARK_GRAY)
.append(
// [Group/PlayerName] command test test (取り消し済み)
Component.text(
String.format("[%s|", group),
NamedTextColor.GRAY
),
Component.text(
executer.getName(),
Style.style()
.color(NamedTextColor.GRAY)
.decorate(TextDecoration.UNDERLINED)
.clickEvent(ClickEvent.runCommand("/secrettp " + executer.getName()))
.hoverEvent(HoverEvent.showText(
Component.text(String.format("スペクテイターで%sにテレポート", executer.getName()))
))
.build()
),
Component.text(
"] ",
NamedTextColor.GRAY
),
Component.text(command, NamedTextColor.YELLOW),
Component.text((event.isCancelled() ? " (拒否)" : ""), NamedTextColor.RED)
)
);
}
}

0 comments on commit bafc57c

Please sign in to comment.