Some misc refactoring and cleanup

This commit is contained in:
Luck 2020-09-10 21:13:12 +01:00
parent 442c7d46f9
commit 2ea43d4b2e
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 22 additions and 17 deletions

View File

@ -45,7 +45,13 @@ public class PreparedStatementBuilder {
return this; return this;
} }
public PreparedStatementBuilder append(char c) {
this.sb.append(c);
return this;
}
public PreparedStatementBuilder variable(String variable) { public PreparedStatementBuilder variable(String variable) {
this.sb.append('?');
this.variables.add(variable); this.variables.add(variable);
return this; return this;
} }

View File

@ -93,7 +93,7 @@ public class UpdateAction implements Action {
@Override @Override
public void appendSql(PreparedStatementBuilder builder) { public void appendSql(PreparedStatementBuilder builder) {
builder.append("UPDATE {table} SET " + this.field.getSqlName() + "=?"); builder.append("UPDATE {table} SET " + this.field.getSqlName() + "=");
builder.variable(this.value); builder.variable(this.value);
} }
} }

View File

@ -55,9 +55,9 @@ public class Constraint {
public void appendSql(PreparedStatementBuilder builder, String field) { public void appendSql(PreparedStatementBuilder builder, String field) {
// e.g. field LIKE ? // e.g. field LIKE ?
builder.append(field + " "); builder.append(field).append(' ');
this.comparison.appendSql(builder); this.comparison.appendSql(builder);
builder.append(" ?"); builder.append(' ');
builder.variable(this.expressionValue); builder.variable(this.expressionValue);
} }

View File

@ -54,6 +54,7 @@ import java.util.stream.Stream;
public class SeparatedConfigurateStorage extends AbstractConfigurateStorage { public class SeparatedConfigurateStorage extends AbstractConfigurateStorage {
private final String fileExtension; private final String fileExtension;
private final Predicate<Path> fileExtensionFilter;
private Path usersDirectory; private Path usersDirectory;
private Path groupsDirectory; private Path groupsDirectory;
@ -74,6 +75,7 @@ public class SeparatedConfigurateStorage extends AbstractConfigurateStorage {
public SeparatedConfigurateStorage(LuckPermsPlugin plugin, String implementationName, ConfigurateLoader loader, String fileExtension, String dataFolderName) { public SeparatedConfigurateStorage(LuckPermsPlugin plugin, String implementationName, ConfigurateLoader loader, String fileExtension, String dataFolderName) {
super(plugin, implementationName, loader, dataFolderName); super(plugin, implementationName, loader, dataFolderName);
this.fileExtension = fileExtension; this.fileExtension = fileExtension;
this.fileExtensionFilter = path -> path.getFileName().toString().endsWith(this.fileExtension);
} }
@Override @Override
@ -120,10 +122,6 @@ public class SeparatedConfigurateStorage extends AbstractConfigurateStorage {
} }
} }
private Predicate<Path> getFileTypeFilter() {
return path -> path.getFileName().toString().endsWith(this.fileExtension);
}
private void registerFileAction(StorageLocation type, Path file) { private void registerFileAction(StorageLocation type, Path file) {
switch (type) { switch (type) {
case USER: case USER:
@ -210,7 +208,7 @@ public class SeparatedConfigurateStorage extends AbstractConfigurateStorage {
public void applyBulkUpdate(BulkUpdate bulkUpdate) throws Exception { public void applyBulkUpdate(BulkUpdate bulkUpdate) throws Exception {
if (bulkUpdate.getDataType().isIncludingUsers()) { if (bulkUpdate.getDataType().isIncludingUsers()) {
try (Stream<Path> s = Files.list(getDirectory(StorageLocation.USER))) { try (Stream<Path> s = Files.list(getDirectory(StorageLocation.USER))) {
s.filter(getFileTypeFilter()).forEach(file -> { s.filter(this.fileExtensionFilter).forEach(file -> {
try { try {
registerFileAction(StorageLocation.USER, file); registerFileAction(StorageLocation.USER, file);
ConfigurationNode object = readFile(file); ConfigurationNode object = readFile(file);
@ -227,7 +225,7 @@ public class SeparatedConfigurateStorage extends AbstractConfigurateStorage {
if (bulkUpdate.getDataType().isIncludingGroups()) { if (bulkUpdate.getDataType().isIncludingGroups()) {
try (Stream<Path> s = Files.list(getDirectory(StorageLocation.GROUP))) { try (Stream<Path> s = Files.list(getDirectory(StorageLocation.GROUP))) {
s.filter(getFileTypeFilter()).forEach(file -> { s.filter(this.fileExtensionFilter).forEach(file -> {
try { try {
registerFileAction(StorageLocation.GROUP, file); registerFileAction(StorageLocation.GROUP, file);
ConfigurationNode object = readFile(file); ConfigurationNode object = readFile(file);
@ -246,7 +244,7 @@ public class SeparatedConfigurateStorage extends AbstractConfigurateStorage {
@Override @Override
public Set<UUID> getUniqueUsers() throws IOException { public Set<UUID> getUniqueUsers() throws IOException {
try (Stream<Path> stream = Files.list(this.usersDirectory)) { try (Stream<Path> stream = Files.list(this.usersDirectory)) {
return stream.filter(getFileTypeFilter()) return stream.filter(this.fileExtensionFilter)
.map(p -> p.getFileName().toString()) .map(p -> p.getFileName().toString())
.map(s -> s.substring(0, s.length() - this.fileExtension.length())) .map(s -> s.substring(0, s.length() - this.fileExtension.length()))
.map(Uuids::fromString) .map(Uuids::fromString)
@ -259,7 +257,7 @@ public class SeparatedConfigurateStorage extends AbstractConfigurateStorage {
public <N extends Node> List<NodeEntry<UUID, N>> searchUserNodes(ConstraintNodeMatcher<N> constraint) throws Exception { public <N extends Node> List<NodeEntry<UUID, N>> searchUserNodes(ConstraintNodeMatcher<N> constraint) throws Exception {
List<NodeEntry<UUID, N>> held = new ArrayList<>(); List<NodeEntry<UUID, N>> held = new ArrayList<>();
try (Stream<Path> stream = Files.list(getDirectory(StorageLocation.USER))) { try (Stream<Path> stream = Files.list(getDirectory(StorageLocation.USER))) {
stream.filter(getFileTypeFilter()) stream.filter(this.fileExtensionFilter)
.forEach(file -> { .forEach(file -> {
String fileName = file.getFileName().toString(); String fileName = file.getFileName().toString();
try { try {
@ -285,7 +283,7 @@ public class SeparatedConfigurateStorage extends AbstractConfigurateStorage {
public void loadAllGroups() throws IOException { public void loadAllGroups() throws IOException {
List<String> groups; List<String> groups;
try (Stream<Path> stream = Files.list(this.groupsDirectory)) { try (Stream<Path> stream = Files.list(this.groupsDirectory)) {
groups = stream.filter(getFileTypeFilter()) groups = stream.filter(this.fileExtensionFilter)
.map(p -> p.getFileName().toString()) .map(p -> p.getFileName().toString())
.map(s -> s.substring(0, s.length() - this.fileExtension.length())) .map(s -> s.substring(0, s.length() - this.fileExtension.length()))
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -302,7 +300,7 @@ public class SeparatedConfigurateStorage extends AbstractConfigurateStorage {
public <N extends Node> List<NodeEntry<String, N>> searchGroupNodes(ConstraintNodeMatcher<N> constraint) throws Exception { public <N extends Node> List<NodeEntry<String, N>> searchGroupNodes(ConstraintNodeMatcher<N> constraint) throws Exception {
List<NodeEntry<String, N>> held = new ArrayList<>(); List<NodeEntry<String, N>> held = new ArrayList<>();
try (Stream<Path> stream = Files.list(getDirectory(StorageLocation.GROUP))) { try (Stream<Path> stream = Files.list(getDirectory(StorageLocation.GROUP))) {
stream.filter(getFileTypeFilter()) stream.filter(this.fileExtensionFilter)
.forEach(file -> { .forEach(file -> {
String fileName = file.getFileName().toString(); String fileName = file.getFileName().toString();
try { try {
@ -328,7 +326,7 @@ public class SeparatedConfigurateStorage extends AbstractConfigurateStorage {
public void loadAllTracks() throws IOException { public void loadAllTracks() throws IOException {
List<String> tracks; List<String> tracks;
try (Stream<Path> stream = Files.list(this.tracksDirectory)) { try (Stream<Path> stream = Files.list(this.tracksDirectory)) {
tracks = stream.filter(getFileTypeFilter()) tracks = stream.filter(this.fileExtensionFilter)
.map(p -> p.getFileName().toString()) .map(p -> p.getFileName().toString())
.map(s -> s.substring(0, s.length() - this.fileExtension.length())) .map(s -> s.substring(0, s.length() - this.fileExtension.length()))
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@ -50,6 +50,7 @@ import me.lucko.luckperms.sponge.listeners.SpongePlatformListener;
import me.lucko.luckperms.sponge.messaging.SpongeMessagingFactory; import me.lucko.luckperms.sponge.messaging.SpongeMessagingFactory;
import me.lucko.luckperms.sponge.model.manager.SpongeGroupManager; import me.lucko.luckperms.sponge.model.manager.SpongeGroupManager;
import me.lucko.luckperms.sponge.model.manager.SpongeUserManager; import me.lucko.luckperms.sponge.model.manager.SpongeUserManager;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.service.ProxyFactory; import me.lucko.luckperms.sponge.service.ProxyFactory;
import me.lucko.luckperms.sponge.service.events.UpdateEventHandler; import me.lucko.luckperms.sponge.service.events.UpdateEventHandler;
import me.lucko.luckperms.sponge.service.model.LPPermissionService; import me.lucko.luckperms.sponge.service.model.LPPermissionService;
@ -89,7 +90,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
private SpongeGroupManager groupManager; private SpongeGroupManager groupManager;
private StandardTrackManager trackManager; private StandardTrackManager trackManager;
private SpongeContextManager contextManager; private SpongeContextManager contextManager;
private me.lucko.luckperms.sponge.service.LuckPermsService service; private LuckPermsService service;
private UpdateEventHandler updateEventHandler; private UpdateEventHandler updateEventHandler;
private boolean lateLoad = false; private boolean lateLoad = false;
@ -166,7 +167,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
protected void setupPlatformHooks() { protected void setupPlatformHooks() {
getLogger().info("Registering PermissionService..."); getLogger().info("Registering PermissionService...");
this.updateEventHandler = UpdateEventHandler.obtain(this); this.updateEventHandler = UpdateEventHandler.obtain(this);
this.service = new me.lucko.luckperms.sponge.service.LuckPermsService(this); this.service = new LuckPermsService(this);
PermissionService oldService = this.bootstrap.getGame().getServiceManager().provide(PermissionService.class).orElse(null); PermissionService oldService = this.bootstrap.getGame().getServiceManager().provide(PermissionService.class).orElse(null);
if (oldService != null && !(oldService instanceof ProxiedServiceObject)) { if (oldService != null && !(oldService instanceof ProxiedServiceObject)) {
@ -316,7 +317,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
return this.contextManager; return this.contextManager;
} }
public me.lucko.luckperms.sponge.service.LuckPermsService getService() { public LuckPermsService getService() {
return this.service; return this.service;
} }