Backport anti-poz from 1.13.2 branch to 1.12.2/master
This commit is contained in:
@@ -23,31 +23,13 @@ import baritone.api.event.events.type.Overrideable;
|
|||||||
/**
|
/**
|
||||||
* @author LoganDark
|
* @author LoganDark
|
||||||
*/
|
*/
|
||||||
public abstract class TabCompleteEvent extends Cancellable {
|
public class TabCompleteEvent extends Cancellable {
|
||||||
|
|
||||||
public final Overrideable<String> prefix;
|
public final String prefix;
|
||||||
public final Overrideable<String[]> completions;
|
public String[] completions;
|
||||||
|
|
||||||
TabCompleteEvent(String prefix, String[] completions) {
|
public TabCompleteEvent(String prefix) {
|
||||||
this.prefix = new Overrideable<>(prefix);
|
this.prefix = prefix;
|
||||||
this.completions = new Overrideable<>(completions);
|
this.completions = null;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean wasModified() {
|
|
||||||
return prefix.wasModified() || completions.wasModified();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class Pre extends TabCompleteEvent {
|
|
||||||
|
|
||||||
public Pre(String prefix) {
|
|
||||||
super(prefix, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class Post extends TabCompleteEvent {
|
|
||||||
|
|
||||||
public Post(String prefix, String[] completions) {
|
|
||||||
super(prefix, completions);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -40,10 +40,7 @@ public interface AbstractGameEventListener extends IGameEventListener {
|
|||||||
default void onSendChatMessage(ChatEvent event) {}
|
default void onSendChatMessage(ChatEvent event) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void onPreTabComplete(TabCompleteEvent.Pre event) {}
|
default void onPreTabComplete(TabCompleteEvent event) {}
|
||||||
|
|
||||||
@Override
|
|
||||||
default void onPostTabComplete(TabCompleteEvent.Post event) {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void onChunkEvent(ChunkEvent event) {}
|
default void onChunkEvent(ChunkEvent event) {}
|
||||||
|
@@ -62,15 +62,7 @@ public interface IGameEventListener {
|
|||||||
*
|
*
|
||||||
* @param event The event
|
* @param event The event
|
||||||
*/
|
*/
|
||||||
void onPreTabComplete(TabCompleteEvent.Pre event);
|
void onPreTabComplete(TabCompleteEvent event);
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs whenever the client player tries to tab complete in chat once completions have been recieved from the
|
|
||||||
* server. This will only be called if the {@link TabCompleteEvent#cancel()} method was not called.
|
|
||||||
*
|
|
||||||
* @param event The event
|
|
||||||
*/
|
|
||||||
void onPostTabComplete(TabCompleteEvent.Post event);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs before and after whenever a chunk is either loaded, unloaded, or populated.
|
* Runs before and after whenever a chunk is either loaded, unloaded, or populated.
|
||||||
|
@@ -26,14 +26,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
@Mixin(GuiChat.ChatTabCompleter.class)
|
@Mixin(GuiChat.ChatTabCompleter.class)
|
||||||
public abstract class MixinChatTabCompleter extends MixinTabCompleter {
|
public abstract class MixinChatTabCompleter extends MixinTabCompleter {
|
||||||
|
|
||||||
@Inject(
|
|
||||||
method = "<init>*",
|
|
||||||
at = @At("RETURN")
|
|
||||||
)
|
|
||||||
private void onConstruction(CallbackInfo ci) {
|
|
||||||
isChatCompleter = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
method = "complete",
|
method = "complete",
|
||||||
at = @At("HEAD"),
|
at = @At("HEAD"),
|
||||||
|
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Baritone.
|
|
||||||
*
|
|
||||||
* Baritone is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Baritone 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 Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package baritone.launch.mixins;
|
|
||||||
|
|
||||||
import baritone.utils.accessor.ITabCompleter;
|
|
||||||
import net.minecraft.client.gui.GuiChat;
|
|
||||||
import net.minecraft.util.TabCompleter;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(GuiChat.class)
|
|
||||||
public abstract class MixinGuiChat implements net.minecraft.util.ITabCompleter {
|
|
||||||
|
|
||||||
@Shadow
|
|
||||||
private TabCompleter tabCompleter;
|
|
||||||
|
|
||||||
@Inject(
|
|
||||||
method = "setCompletions",
|
|
||||||
at = @At("HEAD"),
|
|
||||||
cancellable = true
|
|
||||||
)
|
|
||||||
private void onSetCompletions(String[] newCompl, CallbackInfo ci) {
|
|
||||||
if (((ITabCompleter) tabCompleter).onGuiChatSetCompletions(newCompl)) {
|
|
||||||
ci.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -20,7 +20,7 @@ package baritone.launch.mixins;
|
|||||||
import baritone.api.BaritoneAPI;
|
import baritone.api.BaritoneAPI;
|
||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.event.events.TabCompleteEvent;
|
import baritone.api.event.events.TabCompleteEvent;
|
||||||
import baritone.utils.accessor.ITabCompleter;
|
import net.minecraft.client.gui.GuiChat;
|
||||||
import net.minecraft.client.gui.GuiTextField;
|
import net.minecraft.client.gui.GuiTextField;
|
||||||
import net.minecraft.util.TabCompleter;
|
import net.minecraft.util.TabCompleter;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
@@ -32,7 +32,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(TabCompleter.class)
|
@Mixin(TabCompleter.class)
|
||||||
public abstract class MixinTabCompleter implements ITabCompleter {
|
public abstract class MixinTabCompleter {
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
@Final
|
@Final
|
||||||
@@ -44,36 +44,22 @@ public abstract class MixinTabCompleter implements ITabCompleter {
|
|||||||
@Shadow
|
@Shadow
|
||||||
public abstract void setCompletions(String... newCompl);
|
public abstract void setCompletions(String... newCompl);
|
||||||
|
|
||||||
@Unique
|
|
||||||
protected boolean isChatCompleter = false;
|
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
protected boolean dontComplete = false;
|
protected boolean dontComplete = false;
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPrefix() {
|
|
||||||
return textField.getText().substring(0, textField.getCursorPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPrefix(String prefix) {
|
|
||||||
textField.setText(prefix + textField.getText().substring(textField.getCursorPosition()));
|
|
||||||
textField.setCursorPosition(prefix.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
method = "requestCompletions",
|
method = "requestCompletions",
|
||||||
at = @At("HEAD"),
|
at = @At("HEAD"),
|
||||||
cancellable = true
|
cancellable = true
|
||||||
)
|
)
|
||||||
private void onRequestCompletions(String prefix, CallbackInfo ci) {
|
private void onRequestCompletions(String prefix, CallbackInfo ci) {
|
||||||
if (!isChatCompleter) {
|
if (!((Object) this instanceof GuiChat.ChatTabCompleter)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
|
IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
|
||||||
|
|
||||||
TabCompleteEvent.Pre event = new TabCompleteEvent.Pre(prefix);
|
TabCompleteEvent event = new TabCompleteEvent(prefix);
|
||||||
baritone.getGameEventHandler().onPreTabComplete(event);
|
baritone.getGameEventHandler().onPreTabComplete(event);
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
@@ -81,50 +67,17 @@ public abstract class MixinTabCompleter implements ITabCompleter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.prefix.wasModified()) {
|
if (event.completions != null) {
|
||||||
setPrefix(event.prefix.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.completions.wasModified()) {
|
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
|
|
||||||
dontComplete = true;
|
this.dontComplete = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
requestedCompletions = true;
|
this.requestedCompletions = true;
|
||||||
setCompletions(event.completions.get());
|
setCompletions(event.completions);
|
||||||
} finally {
|
} finally {
|
||||||
dontComplete = false;
|
this.dontComplete = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onGuiChatSetCompletions(String[] newCompl) {
|
|
||||||
IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
|
|
||||||
|
|
||||||
if (baritone == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
TabCompleteEvent.Post event = new TabCompleteEvent.Post(getPrefix(), newCompl);
|
|
||||||
baritone.getGameEventHandler().onPostTabComplete(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.prefix.wasModified()) {
|
|
||||||
String prefix = event.prefix.get();
|
|
||||||
textField.setText(prefix + textField.getText().substring(textField.getCursorPosition()));
|
|
||||||
textField.setCursorPosition(prefix.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.completions.wasModified()) {
|
|
||||||
setCompletions(event.completions.get());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,6 @@
|
|||||||
"MixinEntityLivingBase",
|
"MixinEntityLivingBase",
|
||||||
"MixinEntityPlayerSP",
|
"MixinEntityPlayerSP",
|
||||||
"MixinEntityRenderer",
|
"MixinEntityRenderer",
|
||||||
"MixinGuiChat",
|
|
||||||
"MixinGuiScreen",
|
"MixinGuiScreen",
|
||||||
"MixinItemStack",
|
"MixinItemStack",
|
||||||
"MixinMinecraft",
|
"MixinMinecraft",
|
||||||
|
@@ -146,11 +146,11 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPreTabComplete(TabCompleteEvent.Pre event) {
|
public void onPreTabComplete(TabCompleteEvent event) {
|
||||||
if (!settings.prefixControl.value) {
|
if (!settings.prefixControl.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String prefix = event.prefix.get();
|
String prefix = event.prefix;
|
||||||
String commandPrefix = settings.prefix.value;
|
String commandPrefix = settings.prefix.value;
|
||||||
if (!prefix.startsWith(commandPrefix)) {
|
if (!prefix.startsWith(commandPrefix)) {
|
||||||
return;
|
return;
|
||||||
@@ -161,7 +161,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
|
|||||||
if (args.size() == 1) {
|
if (args.size() == 1) {
|
||||||
stream = stream.map(x -> commandPrefix + x);
|
stream = stream.map(x -> commandPrefix + x);
|
||||||
}
|
}
|
||||||
event.completions.set(stream.toArray(String[]::new));
|
event.completions = stream.toArray(String[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream<String> tabComplete(String msg) {
|
public Stream<String> tabComplete(String msg) {
|
||||||
|
@@ -70,15 +70,10 @@ public final class GameEventHandler implements IEventBus, Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPreTabComplete(TabCompleteEvent.Pre event) {
|
public void onPreTabComplete(TabCompleteEvent event) {
|
||||||
listeners.forEach(l -> l.onPreTabComplete(event));
|
listeners.forEach(l -> l.onPreTabComplete(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPostTabComplete(TabCompleteEvent.Post event) {
|
|
||||||
listeners.forEach(l -> l.onPostTabComplete(event));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onChunkEvent(ChunkEvent event) {
|
public final void onChunkEvent(ChunkEvent event) {
|
||||||
EventState state = event.getState();
|
EventState state = event.getState();
|
||||||
|
@@ -1,10 +0,0 @@
|
|||||||
package baritone.utils.accessor;
|
|
||||||
|
|
||||||
public interface ITabCompleter {
|
|
||||||
|
|
||||||
String getPrefix();
|
|
||||||
|
|
||||||
void setPrefix(String prefix);
|
|
||||||
|
|
||||||
boolean onGuiChatSetCompletions(String[] newCompl);
|
|
||||||
}
|
|
Reference in New Issue
Block a user