Skip to content

Commit

Permalink
修正
Browse files Browse the repository at this point in the history
  • Loading branch information
Matchan0727 committed Jun 15, 2022
1 parent 5bd790e commit 1cc5301
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ public void onChat(ChatEvent event){
return;
}
ProxiedPlayer sender = (ProxiedPlayer) event.getSender();

TextComponent component = new TextComponent(ChatColor.GRAY + "[CL] "+sender.getServer().getInfo().getName()+"@" + sender.getName() + " " + event.getMessage());
BSimpleCommandLog.getLog().info(component.getText());
List<String> list = config.getStringList("cmdlog.players");
for(String puuid : list){
ProxiedPlayer p = proxy.getPlayer(UUID.fromString(puuid));
if(p!=null) p.sendMessage(new TextComponent(ChatColor.GRAY + "[CL] "+sender.getServer().getInfo().getName()+"@" + sender.getName() + " " + event.getMessage()));
if(p!=null) p.sendMessage(component);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,7 @@ public void saveDefaultConfig(){
public void saveConfig(Configuration config) throws IOException {
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config,new File(getDataFolder(),"config.yml"));
}
public static Logger getLog(){
return logger;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.RawCommand;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.event.player.PlayerChatEvent;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import jp.simplespace.simplecommandlog.ConfigData;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;

import java.util.ArrayList;
Expand All @@ -27,35 +29,44 @@ public void execute(Invocation invocation) {
Player p = (Player) source;
ConfigData configData = VSimpleCommandLog.getConfigData();
if (p.hasPermission("scl.command.scl")) {
List<String> list = new ArrayList<>(configData.getCmdlog().get("players"));
List<String> list = configData.getCmdlog().get("players");
if(list==null){
list=new ArrayList<>();
}
if (list.contains(p.getUniqueId().toString())) {
list.remove(p.getUniqueId().toString());
p.sendMessage(Component.text().append(prefix).append(Component.text( "コマンドログ表示を無効にしました。",NamedTextColor.GRAY)).build());
} else {
list.add(p.getUniqueId().toString());
p.sendMessage(Component.text().append(prefix).append(Component.text("コマンドログ表示を有効にしました。",NamedTextColor.GRAY)).build());
}
configData.getCmdlog().replace("players",list);
if(!configData.cmdlog.containsKey("players")) configData.getCmdlog().put("players",list);
else configData.getCmdlog().replace("players",list);
VSimpleCommandLog.saveConfig(configData);
} else p.sendMessage(noPermission);
}
}

//コマンドログをログ表示を有効にしているプレイヤーに送信。
@Subscribe
public void onPlayerChat(PlayerChatEvent event) {
if (!event.getMessage().startsWith("/")) {
return;
}
Player sender = event.getPlayer();
public void onCommandExecute(CommandExecuteEvent event) {
if(!(event.getCommandSource() instanceof Player sender)) return;
ProxyServer proxy = VSimpleCommandLog.getServer();

ConfigData data = VSimpleCommandLog.getConfigData();
List<String> list = new ArrayList<>(data.getCmdlog().get("players"));
TextComponent component = Component.text("[CL] " + sender.getCurrentServer().get().getServerInfo().getName() + "@" + sender.getUsername() + " /" + event.getCommand(), NamedTextColor.GRAY);
VSimpleCommandLog.getLogger().info(component.content());
for (String puuid : list) {
Player p = proxy.getPlayer(UUID.fromString(puuid)).get();
if (p != null)
p.sendMessage(Component.text("[CL] " + sender.getCurrentServer().get().getServerInfo().getName() + "@" + sender.getUsername() + " " + event.getMessage(), NamedTextColor.GRAY));
if (p != null){
p.sendMessage(component);
}
}
}

@Override
public boolean hasPermission(Invocation invocation) {
return invocation.source().hasPermission("scl.command.scl");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public void execute(Invocation invocation) {
se.put("NamedTextColor","net.kyori.adventure.text.format.NamedTextColor");
se.put("source",source);
if(source instanceof Player) se.put("player",(Player)source);
se.put("config",configData);
se.put("yaml",VSimpleCommandLog.getYaml());
map.put(source,se);
}
ScriptEngine se = map.get(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,19 @@ public static ConfigData getNewConfigData(){
public static void saveConfig(ConfigData configData){
String str = yaml.dump(configData);
try {
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(config),StandardCharsets.UTF_8);
BufferedWriter bw = new BufferedWriter(osw);
bw.write(str);
FileWriter fw = new FileWriter(config);
fw.write(str);
fw.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static ConfigData getConfigData(){
return configData;
}
public static Yaml getYaml(){
return yaml;
}
public static void saveDefaultConfig(){
if(!dataDirectory.toFile().exists()) dataDirectory.toFile().mkdir();
config = getConfig();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cmdlog:
players:
players: []
eval: false
3 changes: 0 additions & 3 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,3 @@ permissions:
scl.command.eval:
description: evalコマンドの権限
default: op
scl.command.stl:
description: stlコマンドの権限
default: op

0 comments on commit 1cc5301

Please sign in to comment.