Skip to content

Commit

Permalink
Fix some bugs and cleaning code (#6)
Browse files Browse the repository at this point in the history
Fix attributes and commands.

* fix console command bug and add renovate bot

* renovate bot

* plugin version -> 1.17.3-beta

* use BukkitTasks#runTask

* .

* use new asyncChat event

* cleanup code
new command
remove deprecated api

* исправление ошибки с флагами #2

* Code corrections

* fix error ;D

* Code reformat for PropFlags. Add whitespaces

Signed-off-by: Stanislav Panchenko <[email protected]>

* Update src/main/java/ru/abstractmenus/data/activators/OpenPlate.java

* Update src/main/java/ru/abstractmenus/data/activators/OpenLever.java

---------

Signed-off-by: Stanislav Panchenko <[email protected]>
Co-authored-by: Stanislav Panchenko <[email protected]>
  • Loading branch information
WhyZerVellasskx and BrainRTP authored Nov 26, 2024
1 parent 2739d30 commit 9b493f3
Show file tree
Hide file tree
Showing 192 changed files with 1,065 additions and 1,161 deletions.
14 changes: 14 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base",
"config:recommended",
":disableRateLimiting",
"group:all"
],
"ignoreDeps": [
"com.destroystokyo.paper:paper-api",
"com.sk89q.worldguard:worldguard-bukkit",
"com.sk89q.worldedit:worldedit-bukkit"
]
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ java {


group 'ru.abstractmenus'
version '1.17.2-beta'
version '1.17.4-beta'

repositories {
mavenLocal()
Expand Down
19 changes: 7 additions & 12 deletions src/main/java/ru/abstractmenus/AbstractMenus.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import ru.abstractmenus.commands.VarCommand;
import ru.abstractmenus.commands.VarpCommand;
import ru.abstractmenus.commands.am.CommandOpen;
import ru.abstractmenus.commands.am.CommandPluginVersion;
import ru.abstractmenus.commands.am.CommandReload;
import ru.abstractmenus.commands.am.CommandServe;
import ru.abstractmenus.commands.var.*;
Expand Down Expand Up @@ -57,6 +58,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.Optional;

@Getter
Expand All @@ -72,14 +74,6 @@ public final class AbstractMenus extends JavaPlugin implements AbstractMenusPlug
@Setter
public boolean isProxyMode;

public Metrics getMetrics() {
return metrics;
}

public CommandManager getCommandManager() {
return commandManager;
}

@Override
public Plugin getPlugin() {
return this;
Expand Down Expand Up @@ -209,7 +203,8 @@ private void registerCommands() {
Command am = new AbstractMenuCommand("am.admin")
.addSub("reload", new CommandReload())
.addSub("open", new CommandOpen())
.addSub("serve", new CommandServe());
.addSub("serve", new CommandServe())
.addSub("version", new CommandPluginVersion());

Command var = new VarCommand("am.admin")
.addSub("get", new VarGet())
Expand All @@ -229,9 +224,9 @@ private void registerCommands() {
.addSub("mul", new VarpMul())
.addSub("div", new VarpDiv());

getServer().getPluginCommand("am").setExecutor(am);
getServer().getPluginCommand("var").setExecutor(var);
getServer().getPluginCommand("varp").setExecutor(varp);
Objects.requireNonNull(getServer().getPluginCommand("am")).setExecutor(am);
Objects.requireNonNull(getServer().getPluginCommand("var")).setExecutor(var);
Objects.requireNonNull(getServer().getPluginCommand("varp")).setExecutor(varp);
}

private void disablePlugin() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ru/abstractmenus/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public final class Constants {
public static final String FIELD_ACTIONS = "actions";
public static final String FIELD_DENY_ACTIONS = "denyActions";

private Constants() {}
private Constants() {
}

}
51 changes: 28 additions & 23 deletions src/main/java/ru/abstractmenus/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -51,7 +52,14 @@ public class Metrics {
// The url to which the data is sent
private static final String URL = "https://bStats.org/submitData/bukkit";

/**
* -- GETTER --
* Checks if bStats is enabled.
*
* @return Whether bStats is enabled or not.
*/
// Is bStats enabled on this server?
@Getter
private boolean enabled;

// Should failed requests be logged?
Expand Down Expand Up @@ -111,7 +119,8 @@ public Metrics(Plugin plugin) {
).copyDefaults(true);
try {
config.save(configFile);
} catch (IOException ignored) { }
} catch (IOException ignored) {
}
}

// Load the data
Expand All @@ -129,7 +138,8 @@ public Metrics(Plugin plugin) {
service.getField("B_STATS_VERSION"); // Our identifier :)
found = true; // We aren't the first
break;
} catch (NoSuchFieldException ignored) { }
} catch (NoSuchFieldException ignored) {
}
}
// Register our service
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
Expand All @@ -140,15 +150,6 @@ public Metrics(Plugin plugin) {
}
}

/**
* Checks if bStats is enabled.
*
* @return Whether bStats is enabled or not.
*/
public boolean isEnabled() {
return enabled;
}

/**
* Adds a custom chart.
*
Expand Down Expand Up @@ -192,8 +193,8 @@ public void run() {
public JsonObject getPluginData() {
JsonObject data = new JsonObject();

String pluginName = plugin.getDescription().getName();
String pluginVersion = plugin.getDescription().getVersion();
String pluginName = plugin.getPluginMeta().getName();
String pluginVersion = plugin.getPluginMeta().getVersion();

data.addProperty("pluginName", pluginName); // Append the name of the plugin
data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
Expand All @@ -216,6 +217,7 @@ public JsonObject getPluginData() {
*
* @return The server specific data.
*/
@SuppressWarnings("UnstableApiUsage")
private JsonObject getServerData() {
// Minecraft specific data
int playerAmount;
Expand Down Expand Up @@ -292,9 +294,12 @@ private void submitData() {
}
}
}
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException |
InvocationTargetException ignored) {
}
}
} catch (NoSuchFieldException ignored) { }
} catch (NoSuchFieldException ignored) {
}
}

data.add("plugins", pluginData);
Expand All @@ -317,7 +322,7 @@ private void submitData() {
* Sends the data to the bStats server.
*
* @param plugin Any plugin. It's just used to get a logger instance.
* @param data The data to send.
* @param data The data to send.
* @throws Exception If the request failed.
*/
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
Expand Down Expand Up @@ -434,7 +439,7 @@ public static class SimplePie extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimplePie(String chartId, Callable<String> callable) {
Expand Down Expand Up @@ -465,7 +470,7 @@ public static class AdvancedPie extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
Expand Down Expand Up @@ -509,7 +514,7 @@ public static class DrilldownPie extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
Expand Down Expand Up @@ -558,7 +563,7 @@ public static class SingleLineChart extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SingleLineChart(String chartId, Callable<Integer> callable) {
Expand Down Expand Up @@ -590,7 +595,7 @@ public static class MultiLineChart extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
Expand Down Expand Up @@ -635,7 +640,7 @@ public static class SimpleBarChart extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
Expand Down Expand Up @@ -673,7 +678,7 @@ public static class AdvancedBarChart extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
Expand Down
27 changes: 9 additions & 18 deletions src/main/java/ru/abstractmenus/command/Command.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.abstractmenus.command;

import lombok.Getter;
import lombok.Setter;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import ru.abstractmenus.api.Handlers;
Expand All @@ -14,13 +16,17 @@

public class Command {

@Getter
private final String name;
@Getter
private final List<String> aliases;
private final List<Argument> args;
private final String errorMessage;
private final String helpPrefix;
@Getter
private final boolean override;

@Setter
private boolean playerOnly;
private CommandHandler handler;

Expand All @@ -35,18 +41,6 @@ public Command(String name, List<String> aliases, List<Argument> args,
this.override = override;
}

public String getName() {
return name;
}

public List<String> getAliases() {
return aliases;
}

public boolean isOverride() {
return override;
}

public String help() {
return "/" + name + " " + args.stream()
.map(Argument::help)
Expand All @@ -58,10 +52,6 @@ public void setHandler(CommandHandler handler) {
this.handler = handler;
}

public void setPlayerOnly(boolean playerOnly) {
this.playerOnly = playerOnly;
}

public void execute(CommandSender sender, List<String> args) {
if (playerOnly && !(sender instanceof Player)) return;

Expand All @@ -87,7 +77,8 @@ public void execute(CommandSender sender, List<String> args) {
ctx.add(arg.getKey(), defObj);
continue;
}
} catch (Throwable ignore) {}
} catch (Throwable ignore) {
}
}

sender.sendMessage(String.format(errorMessage, arg.getErrorMessage()));
Expand Down Expand Up @@ -154,7 +145,7 @@ public Command deserialize(Class<Command> type, ConfigNode node) throws NodeSeri
? values.subList(1, values.size())
: Collections.emptyList();

return new Command(values.get(0), aliases, Collections.emptyList(),
return new Command(values.getFirst(), aliases, Collections.emptyList(),
Colors.of(defMsg), Colors.of(defHelp), false);
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/ru/abstractmenus/command/CommandContext.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.abstractmenus.command;

import lombok.Getter;
import org.bukkit.entity.Player;

import java.util.Collection;
Expand All @@ -8,17 +9,14 @@

public class CommandContext {

@Getter
private final Command command;
private final Map<String, Object> args = new HashMap<>();

public CommandContext(Command command) {
this.command = command;
}

public Command getCommand() {
return command;
}

public Collection<Object> values() {
return args.values();
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ru/abstractmenus/command/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ public Command get(String name) {
return commands.get(name.toLowerCase());
}

@SuppressWarnings("UnstableApiUsage")
public void register(Command cmd) {
CommandWrapper wrapper = new CommandWrapper(cmd.getName(),
"AbstractMenus generated command",
cmd.help(),
cmd.getAliases(),
this);

commandMap.register(cmd.getName(), plugin.getDescription().getName(), wrapper);
commandMap.register(cmd.getName(), plugin.getPluginMeta().getName(), wrapper);
addCommand(cmd);
}

Expand Down Expand Up @@ -82,7 +83,7 @@ public List<String> complete(CommandSender sender, String label, String[] argsAr
List<String> suggestions = cmd.suggest(sender, args);

if (argsArr.length > 0 && suggestions != null) {
String last = argsArr[argsArr.length-1];
String last = argsArr[argsArr.length - 1];

return suggestions.stream()
.filter(val -> val.startsWith(last))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ru.abstractmenus.hocon.api.ConfigNode;
import ru.abstractmenus.hocon.api.serialize.NodeSerializeException;
import ru.abstractmenus.hocon.api.serialize.NodeSerializer;

import java.util.List;

public class ChoiceArgument extends Argument {
Expand Down
Loading

0 comments on commit 9b493f3

Please sign in to comment.