mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-12 16:27:40 +00:00
close #15
This commit is contained in:
1 parent
9815d74980
commit
bdba3c5584
6 files changed
+106
-216
No files matched your search
@@ -645,34 +645,36 @@ public class MineTweakerImplementationAPI {
|
||||
MineTweakerAPI.tweaker.rollback();
|
||||
|
||||
if (MineTweakerAPI.server != null) {
|
||||
server.addCommand("minetweaker", "", new String[]{"mt"}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (arguments.length == 0) {
|
||||
player.sendChat("Please provide a command. Use /mt help for more info.");
|
||||
} else if (arguments[0].equals("help")) {
|
||||
String[] keys = minetweakerCommands.keySet().toArray(new String[minetweakerCommands.size()]);
|
||||
Arrays.sort(keys);
|
||||
for (String key : keys) {
|
||||
for (String helpMessage : minetweakerCommands.get(key).description) {
|
||||
player.sendChat(helpMessage);
|
||||
if (!MineTweakerAPI.server.isCommandAdded("minetweaker")) {
|
||||
server.addCommand("minetweaker", "", new String[]{"mt"}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (arguments.length == 0) {
|
||||
player.sendChat("Please provide a command. Use /mt help for more info.");
|
||||
} else if (arguments[0].equals("help")) {
|
||||
String[] keys = minetweakerCommands.keySet().toArray(new String[minetweakerCommands.size()]);
|
||||
Arrays.sort(keys);
|
||||
for (String key : keys) {
|
||||
for (String helpMessage : minetweakerCommands.get(key).description) {
|
||||
player.sendChat(helpMessage);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MineTweakerCommand command = minetweakerCommands.get(arguments[0]);
|
||||
if (command == null) {
|
||||
player.sendChat("No such minetweaker command available");
|
||||
} else {
|
||||
command.function.execute(Arrays.copyOfRange(arguments, 1, arguments.length), player);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MineTweakerCommand command = minetweakerCommands.get(arguments[0]);
|
||||
if (command == null) {
|
||||
player.sendChat("No such minetweaker command available");
|
||||
} else {
|
||||
command.function.execute(Arrays.copyOfRange(arguments, 1, arguments.length), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, new ICommandValidator() {
|
||||
@Override
|
||||
public boolean canExecute(IPlayer player) {
|
||||
return server.isOp(player);
|
||||
}
|
||||
}, null);
|
||||
}, new ICommandValidator() {
|
||||
@Override
|
||||
public boolean canExecute(IPlayer player) {
|
||||
return server.isOp(player);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
||||
ONRELOAD.publish(new ReloadEvent());
|
||||
@@ -724,7 +726,6 @@ public class MineTweakerImplementationAPI {
|
||||
|
||||
private static class AddMineTweakerCommandAction implements IUndoableAction {
|
||||
private final MineTweakerCommand command;
|
||||
private boolean added;
|
||||
|
||||
public AddMineTweakerCommandAction(MineTweakerCommand command) {
|
||||
this.command = command;
|
||||
@@ -734,32 +735,30 @@ public class MineTweakerImplementationAPI {
|
||||
public void apply() {
|
||||
if (!minetweakerCommands.containsKey(command.name)) {
|
||||
minetweakerCommands.put(command.name, command);
|
||||
added = true;
|
||||
} else {
|
||||
added = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
if (added) {
|
||||
minetweakerCommands.remove(command.name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding minetweaker command " + command.name;
|
||||
if (!minetweakerCommands.containsKey(command.name)) {
|
||||
return "Adding minetweaker command " + command.name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing minetweaker command " + command.name;
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,9 +30,6 @@ public interface IServer {
|
||||
@Optional ICommandValidator validator,
|
||||
@Optional ICommandTabCompletion completion);
|
||||
|
||||
@ZenMethod
|
||||
public void removeCommand(String name);
|
||||
|
||||
@ZenMethod
|
||||
public void addMineTweakerCommand(String name, String[] usage, ICommandFunction function);
|
||||
|
||||
@@ -44,4 +41,7 @@ public interface IServer {
|
||||
|
||||
@ZenMethod
|
||||
public IEventHandle onPlayerLoggedOut(IEventHandler<PlayerLoggedOutEvent> ev);
|
||||
|
||||
@ZenMethod
|
||||
public boolean isCommandAdded(String name);
|
||||
}
|
||||
@@ -6,9 +6,6 @@
|
||||
|
||||
package minetweaker.mc19.server;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
@@ -27,8 +24,10 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.server.management.UserListOps;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCServer extends AbstractServer {
|
||||
@@ -44,16 +43,6 @@ public class MCServer extends AbstractServer {
|
||||
MineTweakerAPI.apply(new AddCommandAction(command));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCommand(String name) {
|
||||
ICommand command = (ICommand) ((CommandHandler) server.getCommandManager()).getCommands().get(name);
|
||||
if (command == null) {
|
||||
MineTweakerAPI.logWarning("No such command: " + name);
|
||||
} else {
|
||||
MineTweakerAPI.apply(new RemoveCommandAction(command));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp(IPlayer player) {
|
||||
if (player == ServerPlayer.INSTANCE)
|
||||
@@ -67,6 +56,11 @@ public class MCServer extends AbstractServer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCommandAdded(String name) {
|
||||
return MinecraftServer.getServer().getCommandManager().getCommands().containsKey(name);
|
||||
}
|
||||
|
||||
private static IPlayer getPlayer(ICommandSender commandSender) {
|
||||
if (commandSender instanceof EntityPlayer) {
|
||||
return MineTweakerMC.getIPlayer((EntityPlayer) commandSender);
|
||||
@@ -81,17 +75,6 @@ public class MCServer extends AbstractServer {
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeCommand(ICommand command) {
|
||||
CommandHandler ch = (CommandHandler) MinecraftServer.getServer().getCommandManager();
|
||||
ch.getCommands().remove(command.getCommandName());
|
||||
|
||||
if (command.getCommandAliases() != null) {
|
||||
for (String alias : (List<String>) command.getCommandAliases()) {
|
||||
ch.getCommands().remove(alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class MCCommand implements ICommand {
|
||||
private final String name;
|
||||
private final String usage;
|
||||
@@ -164,11 +147,11 @@ public class MCServer extends AbstractServer {
|
||||
public AddCommandAction(ICommand command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
CommandHandler ch = (CommandHandler) MinecraftServer.getServer().getCommandManager();
|
||||
ch.registerCommand(command);
|
||||
if (!ch.getCommands().containsValue(command))
|
||||
ch.registerCommand(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,56 +161,20 @@ public class MCServer extends AbstractServer {
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
removeCommand(command);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding command " + command.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing command " + command.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private class RemoveCommandAction implements IUndoableAction {
|
||||
private final ICommand command;
|
||||
|
||||
public RemoveCommandAction(ICommand command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
removeCommand(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
CommandHandler ch = (CommandHandler) MinecraftServer.getServer().getCommandManager();
|
||||
ch.registerCommand(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding command " + command.getCommandName();
|
||||
if (!ch.getCommands().containsValue(command))
|
||||
return "Adding command " + command.getCommandName();
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing command " + command.getCommandName();
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -235,4 +182,5 @@ public class MCServer extends AbstractServer {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -70,15 +70,10 @@ public class ItemBracketHandler implements IBracketHandler{
|
||||
@Override
|
||||
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens){
|
||||
// any symbol
|
||||
System.out.println("resolving");
|
||||
if(tokens.size() == 1 && tokens.get(0).getValue().equals("*")){
|
||||
return symbolAny;
|
||||
}
|
||||
|
||||
for(Token tok : tokens){
|
||||
System.out.println(tok.getValue());
|
||||
}
|
||||
|
||||
// detect special cases:
|
||||
// item: at the start means item-specific syntax
|
||||
// :xxx with xxx an integer means sub-item syntax
|
||||
|
||||
@@ -33,71 +33,55 @@ import java.util.List;
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCServer extends AbstractServer{
|
||||
public class MCServer extends AbstractServer {
|
||||
private final MinecraftServer server;
|
||||
|
||||
public MCServer(MinecraftServer server){
|
||||
public MCServer(MinecraftServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
private static IPlayer getPlayer(ICommandSender commandSender){
|
||||
if(commandSender instanceof EntityPlayer){
|
||||
private static IPlayer getPlayer(ICommandSender commandSender) {
|
||||
if (commandSender instanceof EntityPlayer) {
|
||||
return MineTweakerMC.getIPlayer((EntityPlayer) commandSender);
|
||||
}else if(commandSender instanceof DedicatedServer){
|
||||
} else if (commandSender instanceof DedicatedServer) {
|
||||
return ServerPlayer.INSTANCE;
|
||||
}else if(commandSender instanceof RConConsoleSource){
|
||||
} else if (commandSender instanceof RConConsoleSource) {
|
||||
return new RconPlayer(commandSender);
|
||||
}else{
|
||||
} else {
|
||||
System.out.println("Unsupported command sender: " + commandSender);
|
||||
System.out.println("player name: " + commandSender.getName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeCommand(ICommand command){
|
||||
CommandHandler ch = (CommandHandler) MineTweakerMod.server.getCommandManager();
|
||||
ch.getCommands().remove(command.getCommandName());
|
||||
|
||||
if(command.getCommandAliases() != null){
|
||||
for(String alias : command.getCommandAliases()){
|
||||
ch.getCommands().remove(alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCommand(String name, String usage, String[] aliases, ICommandFunction function, ICommandValidator validator, ICommandTabCompletion completion){
|
||||
public void addCommand(String name, String usage, String[] aliases, ICommandFunction function, ICommandValidator validator, ICommandTabCompletion completion) {
|
||||
|
||||
ICommand command = new MCCommand(name, usage, aliases, function, validator, completion);
|
||||
MineTweakerAPI.apply(new AddCommandAction(command));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCommand(String name){
|
||||
ICommand command = server.getCommandManager().getCommands().get(name);
|
||||
if(command == null){
|
||||
MineTweakerAPI.logWarning("No such command: " + name);
|
||||
}else{
|
||||
MineTweakerAPI.apply(new RemoveCommandAction(command));
|
||||
public boolean isOp(IPlayer player) {
|
||||
if (player == ServerPlayer.INSTANCE)
|
||||
return true;
|
||||
|
||||
UserListOps ops = MineTweakerMod.server.getPlayerList().getOppedPlayers();
|
||||
if (server.isDedicatedServer() && ops != null) {
|
||||
//TODO figure if this is correct
|
||||
// return ops.func_152690_d() || ops.func_152700_a(player.getName()) != null || player instanceof RconPlayer;
|
||||
return ops.isEmpty() || ops.getGameProfileFromName(player.getName()) != null || player instanceof RconPlayer;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp(IPlayer player){
|
||||
if(player == ServerPlayer.INSTANCE)
|
||||
return true;
|
||||
|
||||
UserListOps ops = MineTweakerMod.server.getPlayerList().getOppedPlayers();
|
||||
if(server.isDedicatedServer() && ops != null){
|
||||
//TODO figure if this is correct
|
||||
// return ops.func_152690_d() || ops.func_152700_a(player.getName()) != null || player instanceof RconPlayer;
|
||||
return ops.isEmpty() || ops.getGameProfileFromName(player.getName()) != null || player instanceof RconPlayer;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
public boolean isCommandAdded(String name) {
|
||||
return MineTweakerMod.server.getCommandManager().getCommands().containsKey(name);
|
||||
}
|
||||
|
||||
private class MCCommand implements ICommand{
|
||||
private class MCCommand implements ICommand {
|
||||
private final String name;
|
||||
private final String usage;
|
||||
private final List<String> aliases;
|
||||
@@ -105,7 +89,7 @@ public class MCServer extends AbstractServer{
|
||||
private final ICommandValidator validator;
|
||||
private final ICommandTabCompletion completion;
|
||||
|
||||
public MCCommand(String name, String usage, String[] aliases, ICommandFunction function, ICommandValidator validator, ICommandTabCompletion completion){
|
||||
public MCCommand(String name, String usage, String[] aliases, ICommandFunction function, ICommandValidator validator, ICommandTabCompletion completion) {
|
||||
this.name = name;
|
||||
this.usage = usage;
|
||||
this.aliases = Arrays.asList(aliases);
|
||||
@@ -115,129 +99,95 @@ public class MCServer extends AbstractServer{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName(){
|
||||
public String getCommandName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender var1){
|
||||
public String getCommandUsage(ICommandSender var1) {
|
||||
return usage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getCommandAliases(){
|
||||
public List getCommandAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException{
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||
function.execute(args, getPlayer(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender){
|
||||
if(validator == null){
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
|
||||
if (validator == null) {
|
||||
return true;
|
||||
}else{
|
||||
} else {
|
||||
return validator.canExecute(getPlayer(sender));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos){
|
||||
if(completion != null){
|
||||
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
|
||||
if (completion != null) {
|
||||
return Arrays.asList(completion.getTabCompletionOptions(args, getPlayer(sender)));
|
||||
}else{
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsernameIndex(String[] var1, int var2){
|
||||
public boolean isUsernameIndex(String[] var1, int var2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ICommand o){
|
||||
public int compareTo(ICommand o) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private class AddCommandAction implements IUndoableAction{
|
||||
private class AddCommandAction implements IUndoableAction {
|
||||
private final ICommand command;
|
||||
|
||||
public AddCommandAction(ICommand command){
|
||||
public AddCommandAction(ICommand command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
public void apply() {
|
||||
CommandHandler ch = (CommandHandler) MineTweakerMod.server.getCommandManager();
|
||||
ch.registerCommand(command);
|
||||
if (!ch.getCommands().containsValue(command))
|
||||
ch.registerCommand(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo(){
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(){
|
||||
removeCommand(command);
|
||||
public void undo() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe(){
|
||||
return "Adding command " + command.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo(){
|
||||
return "Removing command " + command.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey(){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private class RemoveCommandAction implements IUndoableAction{
|
||||
private final ICommand command;
|
||||
|
||||
public RemoveCommandAction(ICommand command){
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
removeCommand(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(){
|
||||
public String describe() {
|
||||
CommandHandler ch = (CommandHandler) MineTweakerMod.server.getCommandManager();
|
||||
ch.registerCommand(command);
|
||||
if (!ch.getCommands().containsValue(command))
|
||||
return "Adding command " + command.getCommandName();
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe(){
|
||||
return "Adding command " + command.getCommandName();
|
||||
public String describeUndo() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo(){
|
||||
return "Removing command " + command.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey(){
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,9 +2,7 @@ package minetweaker.mods.jei;
|
||||
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.MineTweakerImplementationAPI;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.NotNull;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
@@ -14,12 +12,12 @@ import static minetweaker.mods.jei.JEIAddonPlugin.jeiHelpers;
|
||||
|
||||
/**
|
||||
* MineTweaker JEI support.
|
||||
*
|
||||
*
|
||||
* Enables hiding JEI items as well as adding new item stacks. These item stacks
|
||||
* can then show a custom message or contain NBT data. Can be used to show a
|
||||
* custom message or lore with certain items, or to provide spawnable items with
|
||||
* specific NBT tags.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.jei.JEI")
|
||||
@@ -28,7 +26,7 @@ public class JEI {
|
||||
/**
|
||||
* Hides a specific item in JEI. Will take into account metadata values, if
|
||||
* any.
|
||||
*
|
||||
*
|
||||
* @param item
|
||||
* item to be hidden
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user