mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-02-02 21:41:23 +01:00
refactor: reorganise the package structure
This commit is contained in:
parent
590507029e
commit
182fdb846d
@ -59,6 +59,13 @@ allprojects {
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
if (project.name != "advanced-portals") {
|
||||
task buildSubmodules doLast {
|
||||
task -> println "Building $task.project.name"
|
||||
}
|
||||
buildSubmodule.finalizedBy build
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
}
|
||||
|
@ -1,10 +1,16 @@
|
||||
package com.sekwah.advancedportals.core;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.sekwah.advancedportals.core.config.CoreModule;
|
||||
|
||||
public class AdvancedPortalsCore {
|
||||
|
||||
private Injector injector;
|
||||
/**
|
||||
* https://github.com/google/guice/wiki/GettingStarted
|
||||
*
|
||||
*/
|
||||
private Injector injector = Guice.createInjector(new CoreModule(this));
|
||||
|
||||
/**
|
||||
* For some platforms we could do this on construction but this just allows for a bit more control
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.sekwah.advancedportals.core.config;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
|
||||
public class CoreModule extends AbstractModule {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
|
||||
/**
|
||||
* Parts provided by the core module. Check the implementation for its individual integrations.
|
||||
* @param portalsCore
|
||||
*/
|
||||
public CoreModule(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
// bind(IPortalRepository.class).to(PortalRepository.class).in(Scopes.SINGLETON);
|
||||
// bind(IDestinationRepository.class).to(DestinationRepository.class).in(Scopes.SINGLETON);
|
||||
// bind(IPortalRepository.class).to(PortalRepository.class).in(Scopes.SINGLETON);
|
||||
// bind(ConfigRepository.class).to(ConfigRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
//bindListener(Matchers.Any(), new Log4JTypeListenr());
|
||||
}
|
||||
|
||||
// https://github.com/google/guice/wiki/GettingStarted
|
||||
@Provides
|
||||
AdvancedPortalsCore providePortalsCore() {
|
||||
return this.portalsCore;
|
||||
}
|
||||
}
|
@ -2,12 +2,148 @@ package com.sekwah.advancedportals.core.data;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.util.InfoLogger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class DataStorage {
|
||||
|
||||
private Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
private File dataFolder;
|
||||
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
@Inject
|
||||
private InfoLogger infoLogger;
|
||||
|
||||
public DataStorage(File dataStorageLoc) {
|
||||
this.dataFolder = dataStorageLoc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the default file, defaults to true to keep true to the name
|
||||
*
|
||||
* @param fileLoc
|
||||
* @return
|
||||
*/
|
||||
public boolean copyDefaultFile(String fileLoc) {
|
||||
return this.copyDefaultFile(fileLoc, true);
|
||||
}
|
||||
|
||||
public void copyDefaultFiles(boolean override, String... fileLocs) {
|
||||
for (String fileLoc : fileLocs) {
|
||||
this.copyDefaultFile(fileLoc, override);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T loadJson(Type dataHolder, String location) {
|
||||
InputStream jsonResource = this.loadResource(location);
|
||||
if(jsonResource == null) {
|
||||
return null;
|
||||
}
|
||||
BufferedReader bufReader = new BufferedReader(new InputStreamReader(jsonResource));
|
||||
T object = gson.fromJson(bufReader, dataHolder);
|
||||
return object;
|
||||
}
|
||||
public <T> T loadJson(Class<T> dataHolder, String location) {
|
||||
InputStream jsonResource = this.loadResource(location);
|
||||
if(jsonResource == null) {
|
||||
try {
|
||||
return dataHolder.getDeclaredConstructor().newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
BufferedReader bufReader = new BufferedReader(new InputStreamReader(jsonResource));
|
||||
return gson.fromJson(bufReader, dataHolder);
|
||||
}
|
||||
|
||||
public void storeJson(Object dataHolder, String location) {
|
||||
String json = gson.toJson(dataHolder);
|
||||
try {
|
||||
FileWriter fileWriter = new FileWriter(new File(this.dataFolder, location));
|
||||
fileWriter.write(json);
|
||||
fileWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the specified file out of the plugin and into the plugins folder.
|
||||
*
|
||||
* @param fileLoc
|
||||
* @return if the file is copied, will be false if override is false and the file already existed.
|
||||
*/
|
||||
public boolean copyDefaultFile(String fileLoc, boolean overwrite) {
|
||||
File outFile = new File(this.dataFolder, fileLoc);
|
||||
if (!outFile.exists()) {
|
||||
outFile.getParentFile().mkdirs();
|
||||
}
|
||||
if (!outFile.exists() || overwrite) {
|
||||
try {
|
||||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(fileLoc);
|
||||
if(inputStream == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FileOutputStream outStream = new FileOutputStream(outFile);
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = inputStream.read(buf)) > 0) {
|
||||
outStream.write(buf, 0, len);
|
||||
}
|
||||
inputStream.close();
|
||||
outStream.close();
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
this.infoLogger.logWarning("Could not load " + fileLoc + ". The file does" +
|
||||
"not exist or there has been an error reading the file.");
|
||||
return false;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
this.infoLogger.logWarning("Could not create " + fileLoc);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
this.infoLogger.logWarning("File error reading " + fileLoc);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to try to grab the files from the plugin and if its in the plugin folder load from there instead.
|
||||
* <p>
|
||||
* @param location
|
||||
* @return
|
||||
*/
|
||||
public InputStream loadResource(String location) {
|
||||
File inFile = new File(dataFolder, location);
|
||||
if (inFile.exists() && !inFile.isDirectory()) {
|
||||
try {
|
||||
return new FileInputStream(inFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
copyDefaultFile(location, false);
|
||||
return this.getClass().getClassLoader().getResourceAsStream(location);
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
this.infoLogger.logWarning("Could not load " + location + ". The file does" +
|
||||
"not exist or there has been an error reading the file.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.sekwah.advancedportals.core.data;
|
||||
|
||||
public class DataTag {
|
||||
|
||||
public final String NAME;
|
||||
public final String VALUE;
|
||||
|
||||
public DataTag(String argName, String value) {
|
||||
this.NAME = argName;
|
||||
this.VALUE = value;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package com.sekwah.advancedportals.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.data.DataStorage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -22,6 +24,16 @@ public class Lang {
|
||||
|
||||
private static final Lang instance = new Lang();
|
||||
private final HashMap<String, String> languageMap = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
@Inject
|
||||
private DataStorage dataStorage;
|
||||
|
||||
@Inject
|
||||
private InfoLogger infoLogger;
|
||||
|
||||
//private final String DEFAULT_LANG = "en_GB";
|
||||
|
||||
/*public Lang() {
|
||||
@ -67,7 +79,7 @@ public class Lang {
|
||||
//URL url = lang.getClass().getClassLoader().getResource("lang/" + fileName + ".lang");
|
||||
//System.out.println(url);
|
||||
//Map<String, String> newLangMap = lang.parseLang(url.openStream());
|
||||
InputStream stream = AdvancedPortalsCore.getInstance().getDataStorage().loadResource("lang/" + fileName + ".lang");
|
||||
InputStream stream = this.dataStorage.loadResource("lang/" + fileName + ".lang");
|
||||
if (stream != null) {
|
||||
Map<String, String> newLangMap = lang.parseLang(stream);
|
||||
if (newLangMap != null) {
|
||||
@ -76,7 +88,7 @@ public class Lang {
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
AdvancedPortalsCore.getInstance().getInfoLogger().logWarning("Could not load " + fileName + ".lang The file does" +
|
||||
this.infoLogger.logWarning("Could not load " + fileName + ".lang The file does" +
|
||||
"not exist or there has been an error reading the file. Canceled loading language file.");
|
||||
}
|
||||
}
|
||||
|
@ -1,52 +0,0 @@
|
||||
main: com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin
|
||||
name: AdvancedPortals
|
||||
version: 1.0.0
|
||||
author: sekwah41
|
||||
description: An advanced portals plugin for bukkit.
|
||||
api-version: 1.13
|
||||
commands:
|
||||
portal:
|
||||
description: The main command for the advanced portals
|
||||
aliases: [portals, aportals, advancedportals]
|
||||
usage: /<command>
|
||||
destination:
|
||||
description: Can be used to access portal destinations.
|
||||
aliases: [desti]
|
||||
usage: /<command>
|
||||
permissions:
|
||||
advancedportals.*:
|
||||
description: Gives access to all commands
|
||||
default: op
|
||||
children:
|
||||
advancedportals.createportal: true
|
||||
advancedportals.portal: true
|
||||
advancedportals.build: true
|
||||
advancedportals.desti: true
|
||||
advancedportals.createportal:
|
||||
description: Allows you to create portals
|
||||
default: op
|
||||
advancedportals.createportal.commandlevel.*:
|
||||
description: Gives access to all level raisers
|
||||
default: false
|
||||
children:
|
||||
advancedportals.createportal.commandlevel.op: true
|
||||
advancedportals.createportal.commandlevel.perms: true
|
||||
advancedportals.createportal.commandlevel.console: true
|
||||
advancedportals.createportal.commandlevel.op:
|
||||
description: Allows you to increase the users level temporaily to op
|
||||
default: false
|
||||
advancedportals.createportal.commandlevel.perms:
|
||||
description: Allows you to increase the users level temporaily to have all perms
|
||||
default: false
|
||||
advancedportals.createportal.commandlevel.console:
|
||||
description: Executes command in the console
|
||||
default: false
|
||||
advancedportals.portal:
|
||||
description: Allows use of portal commands
|
||||
default: op
|
||||
advancedportals.build:
|
||||
description: Allows you to build in the portal regions
|
||||
default: op
|
||||
advancedportals.desti:
|
||||
description: Gives access to all desti commands
|
||||
default: op
|
@ -1,7 +1,7 @@
|
||||
z# https://docs.gradle.org/current/userguide/build_environment.html
|
||||
# Disable with --no-build-cache
|
||||
org.gradle.caching=true
|
||||
version=1.0.0-0
|
||||
version=1.0.0
|
||||
|
||||
github=https://github.com/sekwah41/Advanced-Portals
|
||||
curse_project_id=86001
|
||||
|
Loading…
Reference in New Issue
Block a user