Add CustomCommandListener
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
6436cacb04
Commit
f0e38afb8e
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.features.script;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.core.VersionedCallable;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
|
||||||
|
@Linked(LinkageType.LISTENER)
|
||||||
|
public class CustomCommandListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) {
|
||||||
|
for (ItemStack item : e.getPlayer().getInventory().getContents()) {
|
||||||
|
if (item == null || isNoBook(item) || item.getItemMeta() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
BookMeta bookMeta = ((BookMeta) item.getItemMeta());
|
||||||
|
if (bookMeta.getPageCount() == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (bookMeta.getPage(1).isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String s = bookMeta.getPage(1).split("\n")[0];
|
||||||
|
if (!s.startsWith("#!CMD ")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (s.substring(6).equals(e.getMessage())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
new ScriptExecutor(bookMeta, e.getPlayer());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isNoBook(ItemStack item) {
|
||||||
|
return VersionedCallable.call(new VersionedCallable<>(() -> ScriptListener_15.isNoBook(item), 15));
|
||||||
|
}
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren