fix code style

This commit is contained in:
plachta3 2016-08-16 23:02:08 +02:00
parent f06b24440f
commit cf3d34a823
9 changed files with 139 additions and 156 deletions

View File

@ -9,19 +9,17 @@ import com.ne0nx3r0.betteralias.command.BetterAliasCommandExecutor;
import com.ne0nx3r0.betteralias.config.PluginConfig;
import com.ne0nx3r0.betteralias.listener.BetterAliasCommandListener;
public class BetterAlias extends JavaPlugin
{
public class BetterAlias extends JavaPlugin {
public AliasManager aliasManager;
public PluginConfig config;
@Override
public void onEnable()
{
public void onEnable() {
this.config = new PluginConfig(this);
if (this.config.isDebuggingAllowed() == true) {
String version = this.getDescription().getVersion();
this.getLogger().log(Level.INFO, "Debugging enabled by config on version: " + version);
String version = this.getDescription().getVersion();
this.getLogger().log(Level.INFO, "Debugging enabled by config on version: " + version);
}
this.aliasManager = new AliasManager(this);
@ -34,11 +32,11 @@ public class BetterAlias extends JavaPlugin
}
public boolean reload() {
if (aliasManager.loadAliases() && this.config.reload()) {
return true;
}
if (aliasManager.loadAliases() && this.config.reload()) {
return true;
}
return false;
return false;
}
}

View File

@ -5,51 +5,46 @@ import java.util.List;
import org.bukkit.event.EventPriority;
public class Alias
{
public class Alias {
public final String command;
public final boolean caseSensitive;
private final String permission;
private final EventPriority priority;
private final HashMap<Integer, List<AliasCommand>> parameters;
public Alias(String commandName, boolean caseSensitive, String permissionNode, String priority)
{
public Alias(String commandName, boolean caseSensitive, String permissionNode, String priority) {
this.caseSensitive = caseSensitive;
if(this.caseSensitive)
{
if (this.caseSensitive) {
this.command = commandName;
}
else
{
} else {
this.command = commandName.toLowerCase();
}
if (priority != null) {
switch (priority.toLowerCase()) {
case "lowest":
this.priority = EventPriority.LOWEST;
break;
case "low":
this.priority = EventPriority.LOW;
break;
case "normal":
this.priority = EventPriority.NORMAL;
break;
case "high":
this.priority = EventPriority.HIGH;
break;
case "highest":
this.priority = EventPriority.HIGHEST;
break;
switch (priority.toLowerCase()) {
case "lowest":
this.priority = EventPriority.LOWEST;
break;
case "low":
this.priority = EventPriority.LOW;
break;
case "normal":
this.priority = EventPriority.NORMAL;
break;
case "high":
this.priority = EventPriority.HIGH;
break;
case "highest":
this.priority = EventPriority.HIGHEST;
break;
default:
this.priority = EventPriority.LOWEST;
break;
}
default:
this.priority = EventPriority.LOWEST;
break;
}
} else {
this.priority = EventPriority.LOWEST;
this.priority = EventPriority.LOWEST;
}
this.permission = permissionNode;
@ -58,31 +53,26 @@ public class Alias
}
public EventPriority getPriority() {
return this.priority;
return this.priority;
}
// get commands where length is number of arguments
public boolean hasCommandFor(int length)
{
public boolean hasCommandFor(int length) {
return this.parameters.containsKey(length) || this.parameters.containsKey(-1);
}
public String getPermissionNode()
{
public String getPermissionNode() {
return this.permission;
}
public boolean hasPermission()
{
public boolean hasPermission() {
return this.permission != null;
}
Iterable<AliasCommand> getCommands(int length)
{
Iterable<AliasCommand> getCommands(int length) {
List<AliasCommand> commands = this.parameters.get(length);
if(commands != null)
{
if (commands != null) {
return commands;
}
@ -90,8 +80,7 @@ public class Alias
}
// organize aliases by number of arguments
public void setCommandsFor(int length,List<AliasCommand> commandsList)
{
public void setCommandsFor(int length,List<AliasCommand> commandsList) {
this.parameters.put(length, commandsList);
}
}

View File

@ -6,13 +6,11 @@ public class AliasCommand
final AliasCommandTypes type;
int waitTime;
public AliasCommand(String command, AliasCommandTypes type, int waitTime)
{
public AliasCommand(String command, AliasCommandTypes type, int waitTime) {
this.command = command;
this.type = type;
if(waitTime > 0)
{
if (waitTime > 0) {
this.waitTime = waitTime;
}
}

View File

@ -1,7 +1,6 @@
package com.ne0nx3r0.betteralias.alias;
public enum AliasCommandTypes
{
public enum AliasCommandTypes {
PLAYER,
PLAYER_AS_OP,
CONSOLE,

View File

@ -33,22 +33,22 @@ public class AliasManager {
this.aliases = this.config.loadAliases();
}
public boolean loadAliases() {
public boolean loadAliases() {
this.config.reload();
this.config.reload();
this.aliases = this.config.loadAliases();
if (aliases.isEmpty()) {
return false;
return false;
}
return true;
}
return true;
}
public boolean sendAliasCommands(Alias alias, CommandSender cs, String commandString) {
return sendAliasCommands(alias, cs, commandString, "");
}
public boolean sendAliasCommands(Alias alias, CommandSender cs, String commandString) {
return sendAliasCommands(alias, cs, commandString, "");
}
public boolean sendAliasCommands(Alias alias, CommandSender cs, String commandString, String commandPrefix) {
Player player = null;
@ -129,7 +129,7 @@ public class AliasManager {
}
} else if (text.equalsIgnoreCase("*")) {
//ltrim emulation
while(commandString.length() > 0 && commandString.substring(0,1).equals(" ")){
while (commandString.length() > 0 && commandString.substring(0,1).equals(" ")) {
commandString = commandString.substring(1);
}
@ -246,20 +246,20 @@ public class AliasManager {
}
public Collection<Alias> getAliasMatches(String sCommand, EventPriority priority) {
String sCommandLower = sCommand.toLowerCase()+" ";
String sCommandLower = sCommand.toLowerCase() + " ";
ArrayList<Alias> aliasMatches = new ArrayList<Alias>();
for (Alias alias : this.aliases.values()) {
if (priority != null && priority != alias.getPriority()) {
continue;
}
if (priority != null && priority != alias.getPriority()) {
continue;
}
if (alias.caseSensitive) {
if (sCommand.startsWith(alias.command+" ")) {
if (sCommand.startsWith(alias.command + " ")) {
aliasMatches.add(alias);
}
} else if (sCommandLower.startsWith(alias.command+" ")) {
} else if (sCommandLower.startsWith(alias.command + " ")) {
aliasMatches.add(alias);
}
}

View File

@ -35,5 +35,4 @@ public class BetterAliasCommandExecutor implements CommandExecutor {
return true;
}
}

View File

@ -22,36 +22,36 @@ import com.ne0nx3r0.betteralias.alias.AliasCommandTypes;
public class AliasConfig {
private final Plugin plugin;
private final Plugin plugin;
private final File configurationFile;
private final File configurationFile;
private static FileConfiguration configuration;
private static FileConfiguration configuration;
public AliasConfig(final BetterAlias plugin) {
public AliasConfig(final BetterAlias plugin) {
this.plugin = plugin;
this.configurationFile = new File(plugin.getDataFolder(), "aliases.yml");
this.plugin = plugin;
this.configurationFile = new File(plugin.getDataFolder(), "aliases.yml");
if (!configurationFile.exists()) {
configurationFile.getParentFile().mkdirs();
configurationFile.getParentFile().mkdirs();
copy(plugin.getResource("aliases.yml"), configurationFile);
}
AliasConfig.configuration = YamlConfiguration.loadConfiguration(configurationFile);
}
}
public void reload() {
AliasConfig.configuration = YamlConfiguration.loadConfiguration(configurationFile);
}
public void reload() {
AliasConfig.configuration = YamlConfiguration.loadConfiguration(configurationFile);
}
public FileConfiguration getAliasConfiguration() {
return AliasConfig.configuration;
}
public FileConfiguration getAliasConfiguration() {
return AliasConfig.configuration;
}
public final HashMap<String, Alias> loadAliases() {
HashMap<String, Alias> aliases = new HashMap<String, Alias>();
HashMap<String, Alias> aliases = new HashMap<String, Alias>();
Set<String> aliasList = AliasConfig.configuration.getKeys(false);
@ -72,14 +72,14 @@ public class AliasConfig {
List<AliasCommand> commandsList = new ArrayList<AliasCommand>();
if (!sArg.equalsIgnoreCase("permission")
&& !sArg.equalsIgnoreCase("caseSensitive")
&& !sArg.equalsIgnoreCase("priority")) {
&& !sArg.equalsIgnoreCase("caseSensitive")
&& !sArg.equalsIgnoreCase("priority")) {
int iArg;
if (sArg.equals("*")) {
iArg = -1;
} else {
// TODO This raise error sometime on unknown configuration parameter
// TODO This raise error sometime on unknown configuration parameter
iArg = Integer.parseInt(sArg);
}

View File

@ -9,29 +9,29 @@ import com.ne0nx3r0.betteralias.BetterAlias;
public class PluginConfig {
private static Configuration configuration;
private static Configuration configuration;
private final File configurationFile;
private final File configurationFile;
public PluginConfig(final BetterAlias plugin) {
public PluginConfig(final BetterAlias plugin) {
plugin.saveDefaultConfig();
plugin.saveDefaultConfig();
PluginConfig.configuration = plugin.getConfig();
configurationFile = new File(plugin.getDataFolder(), "config.yml");
}
PluginConfig.configuration = plugin.getConfig();
configurationFile = new File(plugin.getDataFolder(), "config.yml");
}
public boolean reload() {
PluginConfig.configuration = YamlConfiguration.loadConfiguration(configurationFile);
return !PluginConfig.configuration.getKeys(false).isEmpty();
}
public boolean reload() {
PluginConfig.configuration = YamlConfiguration.loadConfiguration(configurationFile);
return !PluginConfig.configuration.getKeys(false).isEmpty();
}
public boolean isDebuggingAllowed() {
return PluginConfig.configuration.getBoolean("debug");
}
public boolean isDebuggingAllowed() {
return PluginConfig.configuration.getBoolean("debug");
}
public boolean isCommandBlockAllowed() {
return PluginConfig.configuration.getBoolean("enableCommandBlocks");
}
public boolean isCommandBlockAllowed() {
return PluginConfig.configuration.getBoolean("enableCommandBlocks");
}
}

View File

@ -28,27 +28,27 @@ public class BetterAliasCommandListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommandPreprocessLowest(PlayerCommandPreprocessEvent e) {
onPlayerCommandPreprocess(e, EventPriority.LOWEST);
onPlayerCommandPreprocess(e, EventPriority.LOWEST);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommandPreprocessLow(PlayerCommandPreprocessEvent e) {
onPlayerCommandPreprocess(e, EventPriority.LOW);
onPlayerCommandPreprocess(e, EventPriority.LOW);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerCommandPreprocessNormal(PlayerCommandPreprocessEvent e) {
onPlayerCommandPreprocess(e, EventPriority.NORMAL);
onPlayerCommandPreprocess(e, EventPriority.NORMAL);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerCommandPreprocessHigh(PlayerCommandPreprocessEvent e) {
onPlayerCommandPreprocess(e, EventPriority.HIGH);
onPlayerCommandPreprocess(e, EventPriority.HIGH);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerCommandPreprocessHighest(PlayerCommandPreprocessEvent e) {
onPlayerCommandPreprocess(e, EventPriority.HIGHEST);
onPlayerCommandPreprocess(e, EventPriority.HIGHEST);
}
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e, EventPriority priority) {
@ -56,7 +56,7 @@ public class BetterAliasCommandListener implements Listener {
String sCommand = e.getMessage().substring(1);
if (this.plugin.config.isDebuggingAllowed() == true) {
this.plugin.getLogger().log(Level.INFO, "Player: " + e.getPlayer() + " issue command " + sCommand);
this.plugin.getLogger().log(Level.INFO, "Player: " + e.getPlayer() + " issue command " + sCommand);
}
for (Alias alias : plugin.aliasManager.getAliasMatches(sCommand, priority)) {
@ -80,27 +80,27 @@ public class BetterAliasCommandListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onConsoleCommandLowest(ServerCommandEvent e) {
onConsoleCommand(e, EventPriority.LOWEST);
onConsoleCommand(e, EventPriority.LOWEST);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onConsoleCommandLow(ServerCommandEvent e) {
onConsoleCommand(e, EventPriority.LOW);
onConsoleCommand(e, EventPriority.LOW);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onConsoleCommandNormal(ServerCommandEvent e) {
onConsoleCommand(e, EventPriority.NORMAL);
onConsoleCommand(e, EventPriority.NORMAL);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onConsoleCommandHigh(ServerCommandEvent e) {
onConsoleCommand(e, EventPriority.HIGH);
onConsoleCommand(e, EventPriority.HIGH);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onConsoleCommandHighest(ServerCommandEvent e) {
onConsoleCommand(e, EventPriority.HIGHEST);
onConsoleCommand(e, EventPriority.HIGHEST);
}
public void onConsoleCommand(ServerCommandEvent e, EventPriority priority) {
@ -108,14 +108,14 @@ public class BetterAliasCommandListener implements Listener {
String sCommand = e.getCommand();
if (this.plugin.config.isDebuggingAllowed() == true) {
this.plugin.getLogger().log(Level.INFO, "Server console: " + e.getSender() + " issue command " + sCommand);
this.plugin.getLogger().log(Level.INFO, "Server console: " + e.getSender() + " issue command " + sCommand);
}
for (Alias alias : plugin.aliasManager.getAliasMatches(sCommand, priority)) {
String sArgs = sCommand.substring(alias.command.length());
if (plugin.aliasManager.sendAliasCommands(alias, e.getSender(), sArgs)) {
//
//
e.setCommand("bareload donothing");
}
}
@ -125,42 +125,42 @@ public class BetterAliasCommandListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void redstoneChanges(BlockRedstoneEvent e) {
if (this.plugin.config.isCommandBlockAllowed() == false) return;
if (this.plugin.config.isCommandBlockAllowed() == false) return;
Block block = e.getBlock();
Block block = e.getBlock();
if (e.getOldCurrent() == 0 && e.getNewCurrent() > 0) {
if (block != null) {
BlockState state = block.getState();
if(state != null) {
if (state instanceof CommandBlock) {
CommandBlock cb = (CommandBlock)state;
if (e.getOldCurrent() == 0 && e.getNewCurrent() > 0) {
if (block != null) {
BlockState state = block.getState();
if (state != null) {
if (state instanceof CommandBlock) {
CommandBlock cb = (CommandBlock)state;
String sCommand = cb.getCommand();
String sName = cb.getName();
String sCommand = cb.getCommand();
String sName = cb.getName();
if (this.plugin.config.isDebuggingAllowed() == true) {
this.plugin.getLogger().log(Level.INFO, "CommandBlock: " + sName + " issue command " + sCommand);
}
if (this.plugin.config.isDebuggingAllowed() == true) {
this.plugin.getLogger().log(Level.INFO, "CommandBlock: " + sName + " issue command " + sCommand);
}
for (Alias alias : plugin.aliasManager.getAliasMatches(sCommand, null)) {
String sArgs = sCommand.substring(alias.command.length());
for (Alias alias : plugin.aliasManager.getAliasMatches(sCommand, null)) {
String sArgs = sCommand.substring(alias.command.length());
// get location from block where commandblock is activated
int posX = block.getX();
int posY = block.getY();
int posZ = block.getZ();
// get location from block where commandblock is activated
int posX = block.getX();
int posY = block.getY();
int posZ = block.getZ();
// set execution location /execute @e[type=Player] x y z
String prefix = "execute @e[type=Player] " + posX + " " + posY + " " + posZ + " ";
// set execution location /execute @e[type=Player] x y z
String prefix = "execute @e[type=Player] " + posX + " " + posY + " " + posZ + " ";
ConsoleCommandSender sender = this.plugin.getServer().getConsoleSender();
ConsoleCommandSender sender = this.plugin.getServer().getConsoleSender();
plugin.aliasManager.sendAliasCommands(alias, sender, sArgs, prefix);
}
}
}
}
}
plugin.aliasManager.sendAliasCommands(alias, sender, sArgs, prefix);
}
}
}
}
}
}
}