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

Commit

Permalink
feat: サバイバルモード/アドベンチャーモードでsit/layを使えないように (#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
book000 authored Aug 26, 2022
1 parent 071d9f6 commit ea1c778
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/main/java/com/jaoafa/mymaid4/event/Event_SurvivalSitLay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.format.NamedTextColor;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;

import java.util.Locale;
import java.util.Set;

public class Event_SurvivalSitLay extends MyMaidLibrary implements Listener, EventPremise {

@Override
public String description() {
return "サバイバルモードなどでsitやlayコマンドを使えないようにします。";
}

static Set<String> targetCommands = Set.of("/sit", "/lay", "/gsit:sit", "/glay:lay");

@EventHandler
public void onCommand(PlayerCommandPreprocessEvent event) {
String command = event.getMessage();
Player player = event.getPlayer();
if (command.length() == 0) {
return;
}
String[] args = command.split(" ");
if (!targetCommands.contains(args[0].toLowerCase(Locale.ROOT))) {
return;
}
if (isAMR(player)) {
return;
}
if (player.getGameMode() != GameMode.SURVIVAL && player.getGameMode() != GameMode.ADVENTURE) {
return;
}
player.sendMessage(Component.text().append(
Component.text("[SitLay] "),
Component.text("サバイバルモードやアドベンチャーモードでは、このコマンドを実行できません。", NamedTextColor.GREEN)
));
event.setCancelled(true);
}
}

0 comments on commit ea1c778

Please sign in to comment.