This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
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.
[1.20.4-0.0.1] Sync with private Repo, Fixed Textures, PingBypass Con…
…figWorld not fully functional yet
- Loading branch information
1 parent
0a1e382
commit 69f1fbb
Showing
98 changed files
with
2,436 additions
and
917 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
plugins { | ||
id 'java-test-fixtures' | ||
} | ||
|
||
sourceSets { | ||
testNoRuntime { | ||
compileClasspath += sourceSets.test.compileClasspath | ||
} | ||
test { | ||
compileClasspath += sourceSets.testNoRuntime.runtimeClasspath | ||
} | ||
} | ||
|
||
dependencies { | ||
api project(':pb-security-api') | ||
testImplementation(testFixtures(project)) | ||
} |
7 changes: 1 addition & 6 deletions
7
pb-api/src/main/java/me/earth/pingbypass/api/command/Command.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 |
---|---|---|
@@ -1,10 +1,5 @@ | ||
package me.earth.pingbypass.api.command; | ||
|
||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import me.earth.pingbypass.api.traits.HasDescription; | ||
import me.earth.pingbypass.api.traits.Nameable; | ||
|
||
public interface Command extends Nameable, HasDescription { | ||
void build(LiteralArgumentBuilder<CommandSource> builder); | ||
public interface Command extends GenericCommand<CommandSource> { | ||
|
||
} |
10 changes: 1 addition & 9 deletions
10
pb-api/src/main/java/me/earth/pingbypass/api/command/CommandManager.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 |
---|---|---|
@@ -1,13 +1,5 @@ | ||
package me.earth.pingbypass.api.command; | ||
|
||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import me.earth.pingbypass.api.registry.Registry; | ||
|
||
public interface CommandManager extends Registry<Command>, ProvidesSuggestions<CommandSource> { | ||
void execute(String command, CommandSource source) throws CommandSyntaxException; | ||
|
||
String getPrefix(); | ||
|
||
void setPrefix(String prefix); | ||
public interface CommandManager extends GenericCommandManager<CommandSource, Command> { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
pb-api/src/main/java/me/earth/pingbypass/api/command/GenericCommand.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,10 @@ | ||
package me.earth.pingbypass.api.command; | ||
|
||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import me.earth.pingbypass.api.traits.HasDescription; | ||
import me.earth.pingbypass.api.traits.Nameable; | ||
|
||
public interface GenericCommand<S> extends Nameable, HasDescription { | ||
void build(LiteralArgumentBuilder<S> builder); | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
pb-api/src/main/java/me/earth/pingbypass/api/command/GenericCommandManager.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,16 @@ | ||
package me.earth.pingbypass.api.command; | ||
|
||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import com.mojang.brigadier.tree.RootCommandNode; | ||
import me.earth.pingbypass.api.registry.Registry; | ||
|
||
public interface GenericCommandManager<S, C extends GenericCommand<S>> extends Registry<C>, ProvidesSuggestions<S> { | ||
void execute(String command, S source) throws CommandSyntaxException; | ||
|
||
RootCommandNode<S> getRoot(); | ||
|
||
String getPrefix(); | ||
|
||
void setPrefix(String prefix); | ||
|
||
} |
10 changes: 5 additions & 5 deletions
10
pb-api/src/main/java/me/earth/pingbypass/api/command/impl/AbstractCommand.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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package me.earth.pingbypass.api.command.impl; | ||
|
||
import lombok.Data; | ||
import me.earth.pingbypass.api.command.Command; | ||
import me.earth.pingbypass.api.command.CommandSource; | ||
|
||
@Data | ||
public abstract class AbstractCommand implements Command { | ||
private final String name; | ||
private final String description; | ||
public abstract class AbstractCommand extends AbstractGenericCommand<CommandSource> implements Command { | ||
public AbstractCommand(String name, String description) { | ||
super(name, description); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
pb-api/src/main/java/me/earth/pingbypass/api/command/impl/AbstractGenericCommand.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,27 @@ | ||
package me.earth.pingbypass.api.command.impl; | ||
|
||
import com.mojang.brigadier.arguments.ArgumentType; | ||
import lombok.Data; | ||
import me.earth.pingbypass.api.command.GenericCommand; | ||
import me.earth.pingbypass.api.command.impl.arguments.StringArgument; | ||
import me.earth.pingbypass.api.command.impl.builder.ExtendedLiteralArgumentBuilder; | ||
import me.earth.pingbypass.api.command.impl.builder.ExtendedRequiredArgumentBuilder; | ||
|
||
@Data | ||
public abstract class AbstractGenericCommand<S> implements GenericCommand<S> { | ||
private final String name; | ||
private final String description; | ||
|
||
public <T> ExtendedRequiredArgumentBuilder<S, T> arg(String name, ArgumentType<T> type) { | ||
return new ExtendedRequiredArgumentBuilder<>(type, name); | ||
} | ||
|
||
public ExtendedLiteralArgumentBuilder<S> literal(String literal) { | ||
return new ExtendedLiteralArgumentBuilder<>(literal); | ||
} | ||
|
||
public ExtendedRequiredArgumentBuilder<S, String> greedy(String name) { | ||
return new ExtendedRequiredArgumentBuilder<>(StringArgument.greedy(name), name); | ||
} | ||
|
||
} |
83 changes: 1 addition & 82 deletions
83
pb-api/src/main/java/me/earth/pingbypass/api/command/impl/CommandManagerImpl.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 |
---|---|---|
@@ -1,90 +1,9 @@ | ||
package me.earth.pingbypass.api.command.impl; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.ParseResults; | ||
import com.mojang.brigadier.StringReader; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import com.mojang.brigadier.suggestion.Suggestions; | ||
import com.mojang.brigadier.tree.CommandNode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import me.earth.pingbypass.api.command.Command; | ||
import me.earth.pingbypass.api.command.CommandManager; | ||
import me.earth.pingbypass.api.command.CommandSource; | ||
import me.earth.pingbypass.api.command.impl.builder.ExtendedLiteralArgumentBuilder; | ||
import me.earth.pingbypass.api.registry.impl.SortedRegistry; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static java.util.Collections.synchronizedMap; | ||
|
||
public class CommandManagerImpl extends SortedRegistry<Command> implements CommandManager { | ||
private final Map<Command, CommandNode<CommandSource>> builder2Node = synchronizedMap(new LinkedHashMap<>()); | ||
private CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<>(); | ||
@Getter | ||
@Setter | ||
private String prefix = "+"; | ||
|
||
@Override | ||
public boolean register(Command builder) { | ||
synchronized (lock) { | ||
if (super.register(builder)) { | ||
var command = ExtendedLiteralArgumentBuilder.<CommandSource>literal(builder.getName()); | ||
builder.build(command); | ||
var node = command.build(); | ||
builder2Node.put(builder, node); | ||
dispatcher.getRoot().addChild(node); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean unregister(Command builder) { | ||
synchronized (lock) { | ||
// because CommandDispatcher does not support unregistering, we have to build a new one (or reflection...) | ||
// (or could we register a delegating node and set its delegate to null on unregistering?) | ||
if (super.unregister(builder)) { | ||
builder2Node.remove(builder); | ||
CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<>(); | ||
builder2Node.values().forEach(node -> dispatcher.getRoot().addChild(node)); | ||
this.dispatcher = dispatcher; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void execute(String command, CommandSource source) throws CommandSyntaxException { | ||
dispatcher.execute(command, source); | ||
} | ||
|
||
@Override | ||
public ParseResults<CommandSource> parse(StringReader reader, CommandSource source) { | ||
return dispatcher.parse(reader, source); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Suggestions> getCompletionSuggestions(ParseResults<CommandSource> parse, | ||
int cursor) { | ||
// TODO: is this needed? Better be safe, a command could get unregistered between parse and getSuggestions? | ||
if (!dispatcher.equals(parse.getContext().getDispatcher())) { | ||
return Suggestions.empty(); | ||
} | ||
|
||
return dispatcher.getCompletionSuggestions(parse, cursor); | ||
} | ||
|
||
@Override | ||
public Map<CommandNode<CommandSource>, String> getSmartUsage(CommandNode<CommandSource> node, | ||
CommandSource source) { | ||
return dispatcher.getSmartUsage(node, source); | ||
} | ||
public class CommandManagerImpl extends GenericCommandManagerImpl<CommandSource, Command> implements CommandManager { | ||
|
||
} |
92 changes: 92 additions & 0 deletions
92
pb-api/src/main/java/me/earth/pingbypass/api/command/impl/GenericCommandManagerImpl.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,92 @@ | ||
package me.earth.pingbypass.api.command.impl; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.ParseResults; | ||
import com.mojang.brigadier.StringReader; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import com.mojang.brigadier.suggestion.Suggestions; | ||
import com.mojang.brigadier.tree.CommandNode; | ||
import com.mojang.brigadier.tree.RootCommandNode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import me.earth.pingbypass.api.command.*; | ||
import me.earth.pingbypass.api.command.impl.builder.ExtendedLiteralArgumentBuilder; | ||
import me.earth.pingbypass.api.registry.impl.SortedRegistry; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static java.util.Collections.synchronizedMap; | ||
|
||
public class GenericCommandManagerImpl<S, C extends GenericCommand<S>> extends SortedRegistry<C> implements GenericCommandManager<S, C> { | ||
private final Map<C, CommandNode<S>> builder2Node = synchronizedMap(new LinkedHashMap<>()); | ||
private CommandDispatcher<S> dispatcher = new CommandDispatcher<>(); | ||
@Getter | ||
@Setter | ||
private String prefix = "+"; | ||
|
||
@Override | ||
public boolean register(C builder) { | ||
synchronized (lock) { | ||
if (super.register(builder)) { | ||
var command = ExtendedLiteralArgumentBuilder.<S>literal(builder.getName()); | ||
builder.build(command); | ||
var node = command.build(); | ||
builder2Node.put(builder, node); | ||
dispatcher.getRoot().addChild(node); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean unregister(C builder) { | ||
synchronized (lock) { | ||
// because CommandDispatcher does not support unregistering, we have to build a new one (or reflection...) | ||
// (or could we register a delegating node and set its delegate to null on unregistering?) | ||
if (super.unregister(builder)) { | ||
builder2Node.remove(builder); | ||
CommandDispatcher<S> dispatcher = new CommandDispatcher<>(); | ||
builder2Node.values().forEach(node -> dispatcher.getRoot().addChild(node)); | ||
this.dispatcher = dispatcher; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void execute(String command, S source) throws CommandSyntaxException { | ||
dispatcher.execute(command, source); | ||
} | ||
|
||
@Override | ||
public RootCommandNode<S> getRoot() { | ||
return dispatcher.getRoot(); | ||
} | ||
|
||
@Override | ||
public ParseResults<S> parse(StringReader reader, S source) { | ||
return dispatcher.parse(reader, source); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Suggestions> getCompletionSuggestions(ParseResults<S> parse, int cursor) { | ||
// TODO: is this needed? Better be safe, a command could get unregistered between parse and getSuggestions? | ||
if (!dispatcher.equals(parse.getContext().getDispatcher())) { | ||
return Suggestions.empty(); | ||
} | ||
|
||
return dispatcher.getCompletionSuggestions(parse, cursor); | ||
} | ||
|
||
@Override | ||
public Map<CommandNode<S>, String> getSmartUsage(CommandNode<S> node, S source) { | ||
return dispatcher.getSmartUsage(node, source); | ||
} | ||
|
||
} |
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
74 changes: 74 additions & 0 deletions
74
pb-api/src/main/java/me/earth/pingbypass/api/event/impl/SideSpecificSubscriber.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,74 @@ | ||
package me.earth.pingbypass.api.event.impl; | ||
|
||
import lombok.*; | ||
import me.earth.pingbypass.PingBypass; | ||
import me.earth.pingbypass.api.event.Lockable; | ||
import me.earth.pingbypass.api.event.api.EventListener; | ||
import me.earth.pingbypass.api.event.api.Subscriber; | ||
import me.earth.pingbypass.api.side.Side; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* If you are writing a plugin that can be used on different pingbypass implementations but you want to target one | ||
* specifically its easy to use events and this class. The implementation might not be available at runtime so | ||
* this works around any {@link ClassNotFoundException} that might occur. | ||
* | ||
* @param <P> the type of the PingBypass implementation to target. | ||
*/ | ||
@Data | ||
public class SideSpecificSubscriber<P extends PingBypass> implements Subscriber, Lockable { | ||
@ToString.Exclude | ||
@Getter(AccessLevel.NONE) | ||
@EqualsAndHashCode.Exclude | ||
private final Object lock = new Object(); | ||
private final List<EventListener<?>> listeners = new ArrayList<>(); | ||
private final P pingBypass; | ||
|
||
@Override | ||
public Object getLock(Object requester) { | ||
return lock; | ||
} | ||
|
||
public void subscribe() { | ||
pingBypass.getEventBus().subscribe(this); | ||
} | ||
|
||
public void unsubscribe() { | ||
pingBypass.getEventBus().unsubscribe(this); | ||
} | ||
|
||
public void addListener(EventListener<?> listener) { | ||
listeners.add(listener); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <T extends PingBypass> List<SideSpecificSubscriber<T>> create(Stream<PingBypass> instances, | ||
@Nullable Side side, | ||
ClassSupplier<T> classSupplier, | ||
Consumer<SideSpecificSubscriber<T>> initialize) | ||
{ | ||
List<SideSpecificSubscriber<T>> result = new ArrayList<>(1); | ||
try { | ||
Class<? extends T> clazz = classSupplier.supply(); | ||
instances.forEach(pb -> { | ||
if (clazz.isInstance(pb) && (side == null || side.equals(pb.getSide()))) { | ||
var subscriber = (SideSpecificSubscriber<T>) new SideSpecificSubscriber<>(pb); | ||
initialize.accept(subscriber); | ||
result.add(subscriber); | ||
} | ||
}); | ||
} catch (ClassNotFoundException | NoClassDefFoundError ignored) { } | ||
return result; | ||
} | ||
|
||
@FunctionalInterface | ||
public interface ClassSupplier<T> { | ||
Class<? extends T> supply() throws ClassNotFoundException; | ||
} | ||
|
||
} |
Oops, something went wrong.