-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support tooltip in paper * ignore relocation, fix TAB_COMPLETION_CLASS * fix unable to create a Completion correctly * If the string is empty, there is no tooltip * Support Fabric, Minestom and Sponge * . * Add tests * Remove Completion * Update Suggestion.java * Update tests * Add tooltipCollector * fix test * Update litecommands-unit/src/dev/rollczi/litecommands/unit/AssertSuggest.java Co-authored-by: Norbert Dejlich <[email protected]> * catch style * remove tooltip method, fix assertSuggest, remove tooltipCollector * tooltip for partial platform arguments * Remove tooltips from the suggestion result. * Make tooltip notnull * Add missing collector for tooltips. Code style fixes. * Use collector * Make assertSuggest more simpler * Use tooltip collector. * Copy tooltip while appending * Add preconditions for Suggestion. * Make Suggestion#from internal. * Support async suggestions for 1.12-1.15 paper --------- Co-authored-by: Norbert Dejlich <[email protected]>
- Loading branch information
1 parent
9e7f1d8
commit f621def
Showing
23 changed files
with
383 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
litecommands-bukkit/src/dev/rollczi/litecommands/bukkit/TabCompletePaper1_15Async.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package dev.rollczi.litecommands.bukkit; | ||
|
||
import dev.rollczi.litecommands.LiteCommandsException; | ||
import dev.rollczi.litecommands.reflect.ReflectUtil; | ||
import dev.rollczi.litecommands.suggestion.Suggestion; | ||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.plugin.PluginManager; | ||
|
||
/** | ||
* This class is responsible for handling tab completion for Paper 1.12-1.15 versions. | ||
*/ | ||
class TabCompletePaper1_15Async extends TabComplete implements Listener { | ||
|
||
public TabCompletePaper1_15Async(Plugin plugin) { | ||
PluginManager pluginManager = plugin.getServer().getPluginManager(); | ||
pluginManager.registerEvent(PaperAsyncTabCompleteEvent.TAB_COMPLETE_CLASS, this, EventPriority.HIGHEST, (listener, event) -> executeListener(event), plugin); | ||
} | ||
|
||
private void executeListener(Event event) { | ||
PaperAsyncTabCompleteEvent tabCompleteEvent = new PaperAsyncTabCompleteEvent(event); | ||
Set<Suggestion> result = this.callListener(tabCompleteEvent.getSender(), tabCompleteEvent.getBuffer()); | ||
|
||
if (result == null) { | ||
return; | ||
} | ||
|
||
tabCompleteEvent.setCompletions(result.stream() | ||
.map(suggestion -> suggestion.multilevel()) | ||
.collect(Collectors.toList()) | ||
); | ||
} | ||
|
||
public void close() { | ||
super.close(); | ||
HandlerList.unregisterAll(this); | ||
} | ||
|
||
static class PaperAsyncTabCompleteEvent { | ||
|
||
private static final String TAB_COMPLETE_CLASS_NAME = "com.destroystokyo.paper.event.server.AsyncTabCompleteEvent"; | ||
|
||
static final Class<? extends Event> TAB_COMPLETE_CLASS; | ||
static final Method GET_COMMAND_SENDER_METHOD; | ||
static final Method GET_BUFFER_METHOD; | ||
static final Method SET_COMPLETIONS_METHOD; | ||
|
||
static { | ||
TAB_COMPLETE_CLASS = ReflectUtil.getClass(TAB_COMPLETE_CLASS_NAME); | ||
GET_COMMAND_SENDER_METHOD = ReflectUtil.getMethod(TAB_COMPLETE_CLASS, "getSender"); | ||
GET_BUFFER_METHOD = ReflectUtil.getMethod(TAB_COMPLETE_CLASS, "getBuffer"); | ||
SET_COMPLETIONS_METHOD = ReflectUtil.getMethod(TAB_COMPLETE_CLASS, "setCompletions", List.class); | ||
} | ||
|
||
private final Object event; | ||
|
||
PaperAsyncTabCompleteEvent(Object event) { | ||
if (!ReflectUtil.instanceOf(event, TAB_COMPLETE_CLASS)) { | ||
throw new LiteCommandsException("Event is not instance of " + TAB_COMPLETE_CLASS_NAME); | ||
} | ||
|
||
this.event = event; | ||
} | ||
|
||
public CommandSender getSender() { | ||
return ReflectUtil.invokeMethod(GET_COMMAND_SENDER_METHOD, event); | ||
} | ||
|
||
public String getBuffer() { | ||
return ReflectUtil.invokeMethod(GET_BUFFER_METHOD, event); | ||
} | ||
|
||
public void setCompletions(List<String> completions) { | ||
ReflectUtil.invokeMethod(SET_COMPLETIONS_METHOD, event, completions); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.