From 4462c956075dcb0a886f7e84160fb29f7043fdf0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Sep 2022 19:59:20 +0200 Subject: [PATCH] Add CaseInsensitiveCommandsListener --- CommonCore | 2 +- .../CaseInsensitiveCommandsListener.java | 35 +++++++++++++++++++ .../src/de/steamwar/command/SWCommand.java | 2 +- .../src/de/steamwar/core/Core.java | 6 ++-- 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 SpigotCore_Main/src/de/steamwar/command/CaseInsensitiveCommandsListener.java diff --git a/CommonCore b/CommonCore index 211f625..1dea719 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 211f6258b5bd5a50253a21bd82804edb12f34e3e +Subproject commit 1dea71993d897354d3f52a705f6e0e1e0c8ec580 diff --git a/SpigotCore_Main/src/de/steamwar/command/CaseInsensitiveCommandsListener.java b/SpigotCore_Main/src/de/steamwar/command/CaseInsensitiveCommandsListener.java new file mode 100644 index 0000000..a829308 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/command/CaseInsensitiveCommandsListener.java @@ -0,0 +1,35 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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 . + */ + +package de.steamwar.command; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class CaseInsensitiveCommandsListener implements Listener { + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + String[] strings = event.getMessage().split(" "); + strings[0] = strings[0].toLowerCase(); + event.setMessage(String.join(" ", strings)); + } +} diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index cee412d..e0997f7 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -102,7 +102,7 @@ public class SWCommand extends AbstractSWCommand { } @Register(help = true) - private void internalHelp(Player p, String... args) { + public void internalHelp(Player p, String... args) { if (message == null) { return; } diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index 52b5841..ad70625 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -20,10 +20,7 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.TinyProtocol; -import de.steamwar.command.SWCommandUtils; -import de.steamwar.command.SWTypeMapperCreator; -import de.steamwar.command.TabCompletionCache; -import de.steamwar.command.TypeMapper; +import de.steamwar.command.*; import de.steamwar.core.authlib.AuthlibInjector; import de.steamwar.core.events.ChattingEvent; import de.steamwar.core.events.PartialChunkFixer; @@ -118,6 +115,7 @@ public class Core extends JavaPlugin{ } }); Bukkit.getScheduler().runTaskTimer(this, TabCompletionCache::invalidateOldEntries, 20, 20); + Bukkit.getPluginManager().registerEvents(new CaseInsensitiveCommandsListener(), this); Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this); Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this);