GithubHelp home page GithubHelp logo

icf's Introduction

Download

ICF

Ivan's command framework, providing custom argument handling. Requires Java 8.

I'm using java 7

Get off your dinosaur and get on this rocket ship!

On a serious note, Java 7 is END OF LIFE and it is unsafe to use. Go download java 8.

Set me up

I will show you how to make it with maven.

Install the dependency and the repository:

  <repositories>
    <repository>
      <id>spigotmc-repo</id>
      <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
    </repository>
    <repository>
      <id>sonatype</id>
      <url>https://oss.sonatype.org/content/groups/public/</url>
    </repository>
    <repository>
      <id>mrivanplays</id>
      <url>https://dl.bintray.com/mrivanplaysbg/mrivanplays/</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>org.spigotmc</groupId>
      <artifactId>spigot-api</artifactId>
      <version>1.14.4-R0.1-SNAPSHOT</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.mrivanplays</groupId>
      <artifactId>icf</artifactId>
      <version>VERSION</version> <!-- Replace with latest -->
      <scope>compile</scope>
    </dependency>
  </dependencies>

If it says to you that it can't find the version, don't believe it. It is working perfectly

Then you should relocate the dependency

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <createDependencyReducedPom>false</createDependencyReducedPom>
              <relocations>
                <relocation>
                  <pattern>com.mrivanplays.icf</pattern>
                  <shadedPattern>[YOUR_PACKAGE].icf</shadedPattern>
                </relocation>
              </relocations>
            </configuration>
          </execution>
        </executions>
      </plugin>

Usage

First you will need a command manager

public void setupCommands() {
  CommandManager commandManager = new CommandManager(this /* PLUGIN */ );
}

Then to create a command you need to make a class and extend that class with ICFCommand

public class CommandTestPlaceholders extends ICFCommand {

  @Override
  public void execute(CommandSender sender, String label, CommandArguments args) {
    
  }
}

The argument resolver in the next example is just an example. If you really want to get a string, use args.nextString() instead.

We want to get the 1st argument? Or any other argument? No problem!

public class CommandTestPlaceholders extends ICFCommand {

  @Override
  public void execute(CommandSender sender, String label, CommandArguments args) {
    args.next(ArgumentResolvers.STRING /* ARGUMENT RESOLVER HERE */)
      .ifPresent(sender::sendMessage)
      .orElse(failReason -> sender.sendMessage("You need to have atleast 1 argument!"));
  }
}

The argument resolver in the next example is just an example. If you really want to get a string, use args.nextString() instead.

We want a permission or to force the command to be player only? NO PROBLEM

public class CommandTestPlaceholders extends ICFCommand {

  public CommandTestPlaceholders() {
    super(true, "my.permission");
  }

  @Override
  public void execute(CommandSender sender, String label, CommandArguments args) {
    Player player = (Player) sender;
    args.next(ArgumentResolvers.STRING /* ARGUMENT RESOLVER HERE */)
      .ifPresent(player::sendMessage)
      .orElse(failReason -> player.sendMessage("You need to have atleast 1 argument!"));
  }
}

We want a message from argument? no problem

public class CommandTestPlaceholders extends ICFCommand {

  public CommandTestPlaceholders() {
    super(true, "my.permission");
  }

  @Override
  public void execute(CommandSender sender, String label, CommandArguments args) {
    Player player = (Player) sender;
    String message = args.joinArgumentsSpace(0); // 0 is the starting argument
    player.sendMessage(message);
  }
}

We want to tab complete the command? No problem. You just have to extend the class with our TabCompleter

public class CommandTestPlaceholders extends ICFCommand implements TabCompleter {

  public CommandTestPlaceholders() {
    super(true, "my.permission");
  }

  @Override
  public void execute(CommandSender sender, String label, CommandArguments args) {
    Player player = (Player) sender;
    String message = args.joinArgumentsSpace(0); // 0 is the starting argument
    player.sendMessage(message);
  }
  
  @Override
  public Iterable<String> tabComplete(CommandSender sender, String label, CommandArguments args) {
    return null; // hadle tab completion
  }
}

Registering the command is simple

commandManager.registerCommand(new CommandTestPlaceholders(), "mycommandname1", "mycommandname2");

Making a argument resolver. If you have multiple ones, make sure to make a util class or something with them so they're easily accessable. Also keep in mind that this is a example.

// creation
public static ArgumentResolver<Weapon> WEAPON = Weapon::new;


// usage
args.next(WEAPON).ifPresent(...).orElse(...);

icf's People

Contributors

mrivanplays avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.