Skip to content

Commit

Permalink
1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HimaJyun committed Dec 20, 2020
1 parent 6dcfd97 commit 660c988
Show file tree
Hide file tree
Showing 16 changed files with 353 additions and 101 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: CI
on: [push, pull_request]
on: [ push, pull_request ]

jobs:
build:
name: Maven package
runs-on: ubuntu-latest
strategy:
matrix:
java: ['8','11']
java: [ '8','11' ]
steps:
- uses: actions/checkout@v1
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Maven package
run: mvn package
- uses: actions/checkout@v1
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Maven package
run: mvn javadoc:jar source:jar package
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# JBukkitLib

Library for Bukkit

# Usage

Add Maven dependency

```xml
Expand All @@ -17,7 +19,7 @@ Add Maven dependency
<dependency>
<groupId>jp.jyn</groupId>
<artifactId>JBukkitLib</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
</dependency>
</dependencies>
</project>
Expand Down Expand Up @@ -60,8 +62,10 @@ It is recommended to "relocation" to prevent conflicts with different versions i
```

# Version

|Version|Bukkit|Java|
|:------|:-----|:---|
|1.7.0|1.16.4-R0.1-SNAPSHOT|8|
|1.6.0|1.16.4-R0.1-SNAPSHOT|8|
|1.5.0|1.16.4-R0.1-SNAPSHOT|8|
|1.4.0|1.15.2-R0.1-SNAPSHOT|8|
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>jp.jyn</groupId>
<artifactId>JBukkitLib</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
<description>Library for Bukkit</description>
<url>https://github.com/HimaJyun/JBukkitLib</url>
<properties>
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/jp/jyn/jbukkitlib/command/CommandMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package jp.jyn.jbukkitlib.command;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Specify the command mode.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface CommandMode {
/**
* true if this command is player only
*
* @return player only
*/
boolean playerOnly() default false;

/**
* Minimum required arguments for this command
*
* @return number of minimum argument
*/
int minimumArgs() default 0;

/**
* Required permission for the execute this command.
*
* @return permission
*/
String permission() default "";
}
8 changes: 4 additions & 4 deletions src/main/java/jp/jyn/jbukkitlib/command/ErrorExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface ErrorExecutor {
* onError
*
* @param error error info
* @return result a boolean to return with onCommand
* @return result a boolean to return with {@link org.bukkit.command.CommandExecutor#onCommand(CommandSender, Command, String, String[])}
*/
boolean onError(Info error);

Expand All @@ -25,12 +25,12 @@ class Info {
*/
public final SubCommand.Result cause;
/**
* <p>The subcommand you attempted to execute</p>
* <p>Note: It is null if it is called with no argument specified when the default command is not set</p>
* <p>SubCommand that the player tried to execute.</p>
* <p>Note: It is null if it is called with no argument specified when the default command is not set.</p>
*/
public final String subArgs;
/**
* <p>The subcommand you attempted to execute</p>
* <p>SubCommand that the player tried to execute.</p>
* <p>Note: It is null if no subcommand was found.</p>
*/
public final SubCommand subCommand;
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/jp/jyn/jbukkitlib/command/SubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* SubCommand class
*/
public abstract class SubCommand implements TabExecutor {
private final static Deque<String> EMPTY_DEQUE = EmptyDeque.getInstanceException();

/**
* Execution result
*/
Expand All @@ -27,6 +25,25 @@ public enum Result {
PLAYER_ONLY, DONT_HAVE_PERMISSION, MISSING_ARGUMENT
}

private final static Deque<String> EMPTY_DEQUE = EmptyDeque.getInstanceException();
private final String permission;
private final boolean isPlayerOnly;
private final int minimumArgs;

protected SubCommand() {
Class clazz = this.getClass();
CommandMode mode = (CommandMode) clazz.getAnnotation(CommandMode.class);
if (mode == null) {
this.permission = null;
this.isPlayerOnly = false;
this.minimumArgs = 0;
} else {
this.permission = mode.permission().isEmpty() ? null : mode.permission();
this.isPlayerOnly = mode.playerOnly();
this.minimumArgs = mode.minimumArgs();
}
}

@Override
public final boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
return onCommand(sender, args) == Result.OK;
Expand Down Expand Up @@ -96,7 +113,7 @@ private Deque<String> argsDeque(String... args) {
* @return If true then for players only
*/
protected boolean isPlayerOnly() {
return false;
return isPlayerOnly;
}

/**
Expand All @@ -105,7 +122,7 @@ protected boolean isPlayerOnly() {
* @return Permission
*/
protected String requirePermission() {
return null;
return permission;
}

/**
Expand All @@ -114,7 +131,7 @@ protected String requirePermission() {
* @return minimum args.
*/
protected int minimumArgs() {
return 0;
return minimumArgs;
}

/**
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/jp/jyn/jbukkitlib/config/YamlLoader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jp.jyn.jbukkitlib.config;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
Expand All @@ -15,8 +16,16 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
Expand Down Expand Up @@ -103,6 +112,72 @@ public void reloadConfig() {
YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, StandardCharsets.UTF_8)));
}

/**
* Iterates the child elements of the specified ConfigurationSection.
*
* @param config ConfigurationSection
* @param consumer The ConfigurationSection of the child element is passed as an argument.
*/
public static void section(ConfigurationSection config, Consumer<ConfigurationSection> consumer) {
if (config == null) return;

for (String k : config.getKeys(false)) {
if (config.isConfigurationSection(k)) {
consumer.accept(Objects.requireNonNull(config.getConfigurationSection(k)));
}
}
}

/**
* Iterates the child elements of the specified ConfigurationSection.
*
* @param config ConfigurationSection
* @param consumer The key of the child element and the ConfigurationSection passed as an argument are passed.
*/
public static void section(ConfigurationSection config, BiConsumer<String, ConfigurationSection> consumer) {
if (config == null) return;

for (String k : config.getKeys(false)) {
consumer.accept(k, config);
}
}

/**
* Create a Map using the section keys and values.
*
* @param config ConfigurationSection
* @param mapper The ConfigurationSection of the child element is passed as an argument.
* @param <E> Element type
* @return Map
*/
public static <E> Map<String, E> section(ConfigurationSection config, Function<ConfigurationSection, E> mapper) {
if (config == null) return Collections.emptyMap();

Map<String, E> result = new HashMap<>();
for (String k : config.getKeys(false)) {
if (!config.isConfigurationSection(k)) continue;
result.put(k, mapper.apply(Objects.requireNonNull(config.getConfigurationSection(k))));
}
return result;
}

/**
* Create a Map using the section keys and values.
*
* @param config ConfigurationSection
* @param mapper The key of the child element and the ConfigurationSection passed as an argument are passed.
* @param <E> Element type
* @return Map
*/
public static <E> Map<String, E> section(ConfigurationSection config, BiFunction<String, ConfigurationSection, E> mapper) {
if (config == null) return Collections.emptyMap();

Map<String, E> result = new HashMap<>();
for (String k : config.getKeys(false)) {
result.put(k, mapper.apply(k, config));
}
return result;
}

/**
* Copy directory from plugin jar.
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/jp/jyn/jbukkitlib/config/parser/MinecraftParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,15 @@ public String getValue() {
* <li>aaa(bbb,ccc) -> aaa ["bbb","ccc"] (arguments delimited by ",")</li>
* <li>aaa(b&amp;,bb,ccc) -> aaa ["b,bb","ccc"] ("," escaped by "&amp;")</li>
* <li>aaa(b&amp;"bb,ccc) -> aaa ["b\"bb","ccc"] ("\"" escaped by "&amp;")</li>
* <li>aaa(b&amp;'bb,ccc) -> aaa ["b'bb","ccc"] ("'" escaped by "&amp;")</li>
* <li>aaa(b&amp;(bb,ccc) -> aaa ["b)bb","ccc"] ("(" escaped by "&amp;")</li>
* <li>aaa(b&amp;)bb,ccc) -> aaa ["b)bb","ccc"] (")" escaped by "&amp;")</li>
* <li>aaa(b&amp;&amp;bb,ccc) -> aaa ["b&amp;bb","ccc"] ("&amp;" escaped by "&amp;")</li>
* <li>aaa(b&amp;bb,ccc) -> aaa ["b&amp;bb","ccc"] (escape only for "\"", ",","(", ")" or "&amp;")</li>
* <li>aaa(b b b,ccc) -> aaa ["bbb","ccc"] (white-space ignored)</li>
* <li>aaa("b b b",ccc) -> aaa ["b b b","ccc"] (white-space allowed only in "\"")</li>
* <li>aaa("b,)b",ccc) -> aaa ["b,)b","ccc"] (escape for "," and ")" can be omit in "\"")</li>
* <li>aaa("b,)'b",ccc) -> aaa ["b,)'b","ccc"] (escape for "," and "'" and ")" can be omit in "\"")</li>
* <li>aaa('b,)"b',ccc) -> aaa ["b,)\"b","ccc"] (escape for "," and "\"" and ")" can be omit in "\"")</li>
* </ul>
* function name is allowed in any characters except parentheses. (even if it empty)<br>
* but, common characters ([a-zA-Z0-9_]) are recommended.
Expand All @@ -316,16 +318,16 @@ public static Map.Entry<String, List<String>> parseFunction(String str) {

StringBuilder buf = new StringBuilder();
boolean escape = false;
boolean quote = false;
char quote = '\0';

// OUT: for...IDEA settings does not support this style.
OUT:
for (int i = 0; i < rawArgs.length(); i++) {
char c = rawArgs.charAt(i);

if (escape) {
switch (c) {
case '"':
case '\'':
case '&':
case ',':
case '(':
Expand All @@ -340,14 +342,17 @@ public static Map.Entry<String, List<String>> parseFunction(String str) {
continue;
}

if (quote) {
if (quote != '\0') {
switch (c) {
case '&':
escape = true;
break;
case '"':
quote = false;
break;
case '\'':
if (quote == c) {
quote = '\0';
break;
}
default:
buf.append(c);
break;
Expand All @@ -357,7 +362,8 @@ public static Map.Entry<String, List<String>> parseFunction(String str) {

switch (c) {
case '"':
quote = true;
case '\'':
quote = c;
continue;
case '&':
escape = true;
Expand Down
Loading

0 comments on commit 660c988

Please sign in to comment.