Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

oldstuffs/reflection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

idea

master Release

Principles

  • No code in constructors
  • No mutable objects
  • No static
  • No public methods without contract (interface)
  • No implementation inheritance
  • No returns null (Optional)

How to Use

Maven

<builds>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.2.4</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
            <minimizeJar>true</minimizeJar>
            <createDependencyReducedPom>false</createDependencyReducedPom>
            <!-- Relocations(Optional)
            <relocations>
              <relocation>
                <pattern>io.github.portlek.reflection</pattern>
                <shadedPattern>[YOUR_PLUGIN_PACKAGE].shade</shadedPattern>
              </relocation>
            </relocations>
            -->
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</builds>
<repositories>
  <repository>
    <id>jitpack</id>
    <url>https://jitpack.io/</url>
  </repository>
</repositories>
<dependencies>
  <dependency>
    <groupId>com.github.portlek</groupId>
    <artifactId>reflection</artifactId>
    <version>${version}</version>
  </dependency>
</dependencies>

Gradle

plugins {
  id "com.github.johnrengelman.shadow" version "7.0.0"
}
repositories {
  maven {
    url "https://jitpack.io"
  }
}
dependencies {
  implementation("com.github.portlek:reflection:${version}")
}

Example usage

final class Example {

  void clearKnownCommands() {
    new ClassOf<>(Bukkit.getServer())
      .methodByName("getCommandMap")
      .flatMap(refMethod -> refMethod.of(Bukkit.getServer()).call().map(o -> o instanceof CommandMap))
      .ifPresent(commandMap -> new ClassOf<>(commandMap)
        .methodByName("clearCommands")
        .ifPresent(clearCommandsMethod ->
          clearCommandsMethod.of(commandMap).call()));
  }
}