Skip to content

Commit

Permalink
Allow // to be used as comments in command files
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam committed Jul 12, 2021
1 parent 86baae1 commit 0b5ac09
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 26 deletions.
2 changes: 1 addition & 1 deletion javadoc/overview-summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (11.0.11) on Wed Jun 16 09:35:51 EDT 2021 -->
<!-- Generated by javadoc (11.0.11) on Mon Jul 12 17:38:42 EDT 2021 -->
<title>RedLib API</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">window.location.replace('index.html')</script>
Expand Down
2 changes: 1 addition & 1 deletion javadoc/overview-tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ <h2 title="Class Hierarchy">Class Hierarchy</h2>
<li class="circle">redempt.redlib.region.<a href="redempt/redlib/region/SelectionTool.html" title="class in redempt.redlib.region"><span class="typeNameLink">SelectionTool</span></a> (implements org.bukkit.event.Listener)</li>
<li class="circle">redempt.redlib.sql.<a href="redempt/redlib/sql/SQLCache.html" title="class in redempt.redlib.sql"><span class="typeNameLink">SQLCache</span></a></li>
<li class="circle">redempt.redlib.sql.<a href="redempt/redlib/sql/SQLHelper.html" title="class in redempt.redlib.sql"><span class="typeNameLink">SQLHelper</span></a> (implements java.io.Closeable)</li>
<li class="circle">redempt.redlib.sql.<a href="redempt/redlib/sql/SQLHelper.Results.html" title="class in redempt.redlib.sql"><span class="typeNameLink">SQLHelper.Results</span></a> (implements java.io.Closeable)</li>
<li class="circle">redempt.redlib.sql.<a href="redempt/redlib/sql/SQLHelper.Results.html" title="class in redempt.redlib.sql"><span class="typeNameLink">SQLHelper.Results</span></a> (implements java.lang.AutoCloseable)</li>
<li class="circle">redempt.redlib.multiblock.<a href="redempt/redlib/multiblock/Structure.html" title="class in redempt.redlib.multiblock"><span class="typeNameLink">Structure</span></a></li>
<li class="circle">redempt.redlib.multiblock.<a href="redempt/redlib/multiblock/Structure.StructureBlock.html" title="class in redempt.redlib.multiblock"><span class="typeNameLink">Structure.StructureBlock</span></a></li>
<li class="circle">redempt.redlib.multiblock.<a href="redempt/redlib/multiblock/StructureData.html" title="class in redempt.redlib.multiblock"><span class="typeNameLink">StructureData</span></a></li>
Expand Down
1 change: 1 addition & 0 deletions javadoc/redempt/redlib/commandmanager/ArgType.html
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ <h4>convert</h4>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>sender</code> - The sender of the command</dd>
<dd><code>previous</code> - The value of the previous argument</dd>
<dd><code>argument</code> - The argument to be converted</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>The converted argument for use in a method hook</dd>
Expand Down
2 changes: 2 additions & 0 deletions javadoc/redempt/redlib/commandmanager/Command.html
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ <h4>showHelp</h4>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>sender</code> - The sender to show the help to</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>True if the help was shown to the user, false if the usage was shown instead</dd>
</dl>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion javadoc/redempt/redlib/misc/FormatUtils.html
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ <h4>color</h4>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>input</code> - The input string</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>The colored string, replacing color codes using & with proper codes</dd>
<dd>The colored string, replacing color codes using ampersands with proper codes</dd>
</dl>
</li>
</ul>
Expand Down
6 changes: 2 additions & 4 deletions javadoc/redempt/redlib/sql/SQLHelper.Results.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ <h2 title="Class SQLHelper.Results" class="title">Class SQLHelper.Results</h2>
<li class="blockList">
<dl>
<dt>All Implemented Interfaces:</dt>
<dd><code>java.io.Closeable</code>, <code>java.lang.AutoCloseable</code></dd>
<dd><code>java.lang.AutoCloseable</code></dd>
</dl>
<dl>
<dt>Enclosing class:</dt>
Expand All @@ -140,7 +140,7 @@ <h2 title="Class SQLHelper.Results" class="title">Class SQLHelper.Results</h2>
<hr>
<pre>public static class <span class="typeNameLabel">SQLHelper.Results</span>
extends java.lang.Object
implements java.io.Closeable</pre>
implements java.lang.AutoCloseable</pre>
<div class="block">Wraps a <code>ResultSet</code> with easier use</div>
</li>
</ul>
Expand Down Expand Up @@ -362,8 +362,6 @@ <h4>close</h4>
<dl>
<dt><span class="overrideSpecifyLabel">Specified by:</span></dt>
<dd><code>close</code>&nbsp;in interface&nbsp;<code>java.lang.AutoCloseable</code></dd>
<dt><span class="overrideSpecifyLabel">Specified by:</span></dt>
<dd><code>close</code>&nbsp;in interface&nbsp;<code>java.io.Closeable</code></dd>
</dl>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion javadoc/redempt/redlib/sql/package-tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h2 title="Class Hierarchy">Class Hierarchy</h2>
<ul>
<li class="circle">redempt.redlib.sql.<a href="SQLCache.html" title="class in redempt.redlib.sql"><span class="typeNameLink">SQLCache</span></a></li>
<li class="circle">redempt.redlib.sql.<a href="SQLHelper.html" title="class in redempt.redlib.sql"><span class="typeNameLink">SQLHelper</span></a> (implements java.io.Closeable)</li>
<li class="circle">redempt.redlib.sql.<a href="SQLHelper.Results.html" title="class in redempt.redlib.sql"><span class="typeNameLink">SQLHelper.Results</span></a> (implements java.io.Closeable)</li>
<li class="circle">redempt.redlib.sql.<a href="SQLHelper.Results.html" title="class in redempt.redlib.sql"><span class="typeNameLink">SQLHelper.Results</span></a> (implements java.lang.AutoCloseable)</li>
</ul>
</li>
</ul>
Expand Down
1 change: 1 addition & 0 deletions src/redempt/redlib/commandmanager/ArgType.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public String getName() {
/**
* Converts an argument to another type
* @param sender The sender of the command
* @param previous The value of the previous argument
* @param argument The argument to be converted
* @return The converted argument for use in a method hook
*/
Expand Down
1 change: 1 addition & 0 deletions src/redempt/redlib/commandmanager/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ protected Command(String[] names, CommandArgument[] args, Flag[] flags, ContextP
* Shows the help to a CommandSender
*
* @param sender The sender to show the help to
* @return True if the help was shown to the user, false if the usage was shown instead
*/
public boolean showHelp(CommandSender sender) {
String title = msg("helpTitle").replace("%cmdname%", names[0]);
Expand Down
3 changes: 3 additions & 0 deletions src/redempt/redlib/commandmanager/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ private CommandCollection fromLines(List<String> lines, int lineNumber) {
boolean postArg = false;
for (int pos = lineNumber; pos < lines.size(); pos++) {
String line = lines.get(pos);
if (line.startsWith("//")) {
continue;
}
//New command data
if (line.endsWith("{")) {
depth++;
Expand Down
2 changes: 1 addition & 1 deletion src/redempt/redlib/misc/FormatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static String truncateDouble(double input) {
/**
* Shorthand for {@link ChatColor#translateAlternateColorCodes(char, String)}
* @param input The input string
* @return The colored string, replacing color codes using & with proper codes
* @return The colored string, replacing color codes using ampersands with proper codes
*/
public static String color(String input) {
return ChatColor.translateAlternateColorCodes('&', input);
Expand Down
17 changes: 6 additions & 11 deletions src/redempt/redlib/misc/PlayerWrapper.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package redempt.redlib.misc;

import org.bukkit.entity.Player;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;

import org.bukkit.entity.Player;

public class PlayerWrapper {

/**
Expand All @@ -17,16 +17,11 @@ public class PlayerWrapper {
* @return The wrapped player
*/
public static Player wrap(Player player, String... disable) {
return (Player) Proxy.newProxyInstance(player.getClass().getClassLoader(), new Class<?>[] {Player.class}, new InvocationHandler() {

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (Arrays.stream(disable).anyMatch(s -> s.equals(method.getName()))) {
return null;
}
return method.invoke(player, args);
return (Player) Proxy.newProxyInstance(player.getClass().getClassLoader(), new Class<?>[] {Player.class}, (proxy, method, args) -> {
if (Arrays.stream(disable).anyMatch(s -> s.equals(method.getName()))) {
return null;
}

return method.invoke(player, args);
});
}

Expand Down
26 changes: 20 additions & 6 deletions src/redempt/redlib/sql/SQLHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public void execute(String command, Object... fields) {
try {
PreparedStatement statement = prepareStatement(command, fields);
statement.execute();
statement.close();
} catch (SQLException e) {
sneakyThrow(e);
}
Expand All @@ -203,6 +204,7 @@ public <T> T querySingleResult(String query, Object... fields) {
}
T obj = (T) results.getObject(1);
results.close();
statement.close();
return obj;
} catch (SQLException e) {
sneakyThrow(e);
Expand All @@ -226,7 +228,10 @@ public String querySingleResultString(String query, Object... fields) {
if (!results.next()) {
return null;
}
return results.getString(1);
String val = results.getString(1);
results.close();
statement.close();
return val;
} catch (SQLException e) {
sneakyThrow(e);
return null;
Expand All @@ -249,7 +254,10 @@ public Long querySingleResultLong(String query, Object... fields) {
if (!results.next()) {
return null;
}
return results.getLong(1);
long val = results.getLong(1);
results.close();
statement.close();
return val;
} catch (SQLException e) {
sneakyThrow(e);
return null;
Expand All @@ -273,6 +281,7 @@ public <T> List<T> queryResultList(String query, Object... fields) {
list.add((T) results.getObject(1));
}
results.close();
statement.close();
} catch (SQLException e) {
sneakyThrow(e);
}
Expand All @@ -297,6 +306,7 @@ public List<String> queryResultStringList(String query, Object... fields) {
list.add(results.getString(1));
}
results.close();
statement.close();
} catch (SQLException e) {
sneakyThrow(e);
}
Expand All @@ -312,8 +322,9 @@ public List<String> queryResultStringList(String query, Object... fields) {
*/
public Results queryResults(String query, Object... fields) {
try {
ResultSet results = prepareStatement(query, fields).executeQuery();
return new Results(results);
PreparedStatement statement = prepareStatement(query, fields);
ResultSet results = statement.executeQuery();
return new Results(results, statement);
} catch (SQLException e) {
sneakyThrow(e);
return null;
Expand Down Expand Up @@ -421,13 +432,15 @@ public void close() {
* Wraps a {@link ResultSet} with easier use
* @author Redempt
*/
public static class Results implements Closeable {
public static class Results implements AutoCloseable {

private ResultSet results;
private boolean empty;
private PreparedStatement statement;

private Results(ResultSet results) {
private Results(ResultSet results, PreparedStatement statement) {
this.results = results;
this.statement = statement;
try {
empty = !results.next();
} catch (SQLException e) {
Expand Down Expand Up @@ -539,6 +552,7 @@ public int getColumnCount() {
public void close() {
try {
results.close();
statement.close();
} catch (SQLException e) {
sneakyThrow(e);
}
Expand Down

0 comments on commit 0b5ac09

Please sign in to comment.