Changed inject annotation and build so it only does for spigot atm

Still learning a lot about all this and loving it so far
This commit is contained in:
Sekwah 2018-07-03 01:26:23 +01:00 committed by Sekwah
parent ed3c28faee
commit f7d47519b7
24 changed files with 66 additions and 106 deletions

View File

@ -55,7 +55,7 @@ group = 'com.sekwah.advancedportals'
description = ""
minecraft {
/*minecraft {
version = "1.12.2-14.23.2.2611"
runDir = "run"
@ -66,7 +66,7 @@ minecraft {
// simply re-run your setup task after changing the mappings to update your workspace.
mappings = "snapshot_20180607"
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
}
}*/
sourceCompatibility = 1.8
targetCompatibility = 1.8
@ -458,7 +458,7 @@ task runJar() << {
}
}
processResources
/*processResources
{
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
@ -476,4 +476,4 @@ processResources
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
}*/

View File

@ -4,18 +4,18 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.api.destination.Destination;
import com.sekwah.advancedportals.core.api.services.DestinationServices;
import com.sekwah.advancedportals.core.api.services.PortalServices;
import com.sekwah.advancedportals.core.api.services.PortalTempDataServices;
import com.sekwah.advancedportals.core.config.RepositoryModule;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.api.registry.TagRegistry;
import com.sekwah.advancedportals.core.api.registry.WarpEffectRegistry;
import com.sekwah.advancedportals.core.api.services.DestinationServices;
import com.sekwah.advancedportals.core.api.services.PortalServices;
import com.sekwah.advancedportals.core.api.services.PortalTempDataServices;
import com.sekwah.advancedportals.core.commands.CommandWithSubCommands;
import com.sekwah.advancedportals.core.commands.subcommands.desti.CreateDestiSubCommand;
import com.sekwah.advancedportals.core.commands.subcommands.portal.*;
import com.sekwah.advancedportals.core.config.RepositoryModule;
import com.sekwah.advancedportals.core.data.DataStorage;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.util.InfoLogger;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.ConnectorDataCollector;
@ -40,7 +40,7 @@ public class AdvancedPortalsCore {
private CoreListeners coreListeners = injector.getInstance(CoreListeners.class);
private final DataStorage dataStorage = injector.getInstance(DataStorage.class);
private final DataStorage dataStorage;
private CommandWithSubCommands portalCommand;
private CommandWithSubCommands destiCommand;
@ -62,7 +62,7 @@ public class AdvancedPortalsCore {
*/
public AdvancedPortalsCore(File dataStorageLoc, InfoLogger infoLogger, CommandRegister commandRegister,
ConnectorDataCollector dataCollector, int[] mcVer) {
this.dataStorage.setStorageLocation(dataStorageLoc);
this.dataStorage = new DataStorage(dataStorageLoc);
this.infoLogger = infoLogger;
instance = this;
this.commandRegister = commandRegister;
@ -113,8 +113,8 @@ public class AdvancedPortalsCore {
}
private void onEnable() {
this.portalTagRegistry = new TagRegistry<>(this);
this.destiTagRegistry = new TagRegistry<>(this);
this.portalTagRegistry = new TagRegistry<>();
this.destiTagRegistry = new TagRegistry<>();
this.dataStorage.copyDefaultFile("lang/en_GB.lang", false);
@ -136,12 +136,12 @@ public class AdvancedPortalsCore {
this.portalCommand = new CommandWithSubCommands();
this.portalCommand.registerSubCommand("version", new VersionSubCommand());
this.portalCommand.registerSubCommand("transupdate", new TransUpdateSubCommand(this));
this.portalCommand.registerSubCommand("reload", new ReloadSubCommand(this));
this.portalCommand.registerSubCommand("selector", new SelectorSubCommand(this), "wand");
this.portalCommand.registerSubCommand("portalblock", new PortalBlockSubCommand(this));
this.portalCommand.registerSubCommand("endportalblock", new EndPortalBlockSubCommand(this));
this.portalCommand.registerSubCommand("endgatewayblock", new EndGatewayBlockSubCommand(this));
this.portalCommand.registerSubCommand("transupdate", new TransUpdateSubCommand());
this.portalCommand.registerSubCommand("reload", new ReloadSubCommand());
this.portalCommand.registerSubCommand("selector", new SelectorSubCommand(), "wand");
this.portalCommand.registerSubCommand("portalblock", new PortalBlockSubCommand());
this.portalCommand.registerSubCommand("endportalblock", new EndPortalBlockSubCommand());
this.portalCommand.registerSubCommand("endgatewayblock", new EndGatewayBlockSubCommand());
this.portalCommand.registerSubCommand("create", new CreatePortalSubCommand());
this.portalCommand.registerSubCommand("remove", new RemoveSubCommand());

View File

@ -1,7 +1,6 @@
package com.sekwah.advancedportals.core;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.sekwah.advancedportals.core.api.services.PortalServices;
import com.sekwah.advancedportals.core.api.services.PortalTempDataServices;
import com.sekwah.advancedportals.core.entities.PlayerLocation;
@ -19,7 +18,6 @@ public class CoreListeners {
private PortalServices portalServices;
@Inject
@Named("portals-core")
private AdvancedPortalsCore portalsCore;
public void playerJoin(PlayerContainer player) {

View File

@ -2,10 +2,10 @@ package com.sekwah.advancedportals.core.api.destination;
import com.google.gson.annotations.SerializedName;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.entities.DataTag;
import com.sekwah.advancedportals.core.api.registry.TagRegistry;
import com.sekwah.advancedportals.core.api.warphandler.ActivationData;
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
import com.sekwah.advancedportals.core.entities.DataTag;
import com.sekwah.advancedportals.core.entities.PlayerLocation;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;

View File

@ -2,7 +2,6 @@ package com.sekwah.advancedportals.core.api.registry;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.util.InfoLogger;
import java.util.ArrayList;

View File

@ -1,5 +1,6 @@
package com.sekwah.advancedportals.core.api.registry;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
@ -16,7 +17,8 @@ import java.util.Map;
*/
public class TagRegistry<T> {
private final AdvancedPortalsCore portalsCore;
@Inject
private AdvancedPortalsCore portalsCore;
/**
* List of tag names which should be in order alphabetically
@ -30,10 +32,6 @@ public class TagRegistry<T> {
private Map<String, TagHandler.Creation<T>> creationHandlers = new HashMap();
private Map<String, TagHandler.TagStatus<T>> statusHandlers = new HashMap();
public TagRegistry(AdvancedPortalsCore portalsCore) {
this.portalsCore = portalsCore;
}
/**
*
* @param arg

View File

@ -1,7 +1,6 @@
package com.sekwah.advancedportals.core.api.registry;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.effect.WarpEffect;
@ -19,7 +18,6 @@ public class WarpEffectRegistry {
private Map<String, WarpEffect> soundEffects = new HashMap();
@Inject
@Named("portals-core")
private AdvancedPortalsCore portalsCore;
/**

View File

@ -144,6 +144,9 @@ public class CommandWithSubCommands implements CommandTemplate {
}
public List<String> filterTabResults(List<String> tabList, String lastArg) {
if(tabList == null) {
return null;
}
for(String arg : tabList.toArray(new String[0])) {
if(!arg.startsWith(lastArg.toLowerCase())) {
tabList.remove(arg);

View File

@ -3,8 +3,8 @@ package com.sekwah.advancedportals.core.commands.subcommands.desti;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.api.destination.Destination;
import com.sekwah.advancedportals.core.entities.DataTag;
import com.sekwah.advancedportals.core.commands.subcommands.CreateSubCommand;
import com.sekwah.advancedportals.core.entities.DataTag;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;

View File

@ -3,8 +3,8 @@ package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.entities.DataTag;
import com.sekwah.advancedportals.core.commands.subcommands.CreateSubCommand;
import com.sekwah.advancedportals.core.entities.DataTag;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;

View File

@ -1,5 +1,6 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.util.Lang;
@ -10,11 +11,8 @@ import java.util.List;
public class EndGatewayBlockSubCommand implements SubCommand {
private final AdvancedPortalsCore portalsCore;
public EndGatewayBlockSubCommand(AdvancedPortalsCore portalsCore) {
this.portalsCore = portalsCore;
}
@Inject
private AdvancedPortalsCore portalsCore;
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {

View File

@ -1,5 +1,6 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.util.Lang;
@ -10,11 +11,8 @@ import java.util.List;
public class EndPortalBlockSubCommand implements SubCommand {
private final AdvancedPortalsCore portalsCore;
public EndPortalBlockSubCommand(AdvancedPortalsCore portalsCore) {
this.portalsCore = portalsCore;
}
@Inject
private AdvancedPortalsCore portalsCore;
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {

View File

@ -1,5 +1,6 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.util.Lang;
@ -10,11 +11,9 @@ import java.util.List;
public class PortalBlockSubCommand implements SubCommand {
private final AdvancedPortalsCore portalsCore;
@Inject
private AdvancedPortalsCore portalsCore;
public PortalBlockSubCommand(AdvancedPortalsCore portalsCore) {
this.portalsCore = portalsCore;
}
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {

View File

@ -1,5 +1,6 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.util.Lang;
@ -9,11 +10,8 @@ import java.util.List;
public class ReloadSubCommand implements SubCommand {
private final AdvancedPortalsCore portalsCore;
public ReloadSubCommand(AdvancedPortalsCore portalsCore) {
this.portalsCore = portalsCore;
}
@Inject
private AdvancedPortalsCore portalsCore;
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {

View File

@ -1,5 +1,6 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.util.Lang;
@ -10,11 +11,8 @@ import java.util.List;
public class SelectorSubCommand implements SubCommand {
private final AdvancedPortalsCore portalsCore;
public SelectorSubCommand(AdvancedPortalsCore portalsCore) {
this.portalsCore = portalsCore;
}
@Inject
private AdvancedPortalsCore portalsCore;
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {

View File

@ -1,5 +1,6 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.util.Lang;
@ -9,10 +10,10 @@ import java.util.List;
public class TransUpdateSubCommand implements SubCommand {
private final AdvancedPortalsCore portalsCore;
@Inject
private AdvancedPortalsCore portalsCore;
public TransUpdateSubCommand(AdvancedPortalsCore portalsCore) {
this.portalsCore = portalsCore;
public TransUpdateSubCommand() {
}
@Override

View File

@ -3,12 +3,9 @@ package com.sekwah.advancedportals.core.config;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.name.Named;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.repository.*;
import java.util.Properties;
public class RepositoryModule extends AbstractModule {
private final AdvancedPortalsCore portalsCore;
@ -26,7 +23,6 @@ public class RepositoryModule extends AbstractModule {
}
@Provides
@Named("portals-core")
AdvancedPortalsCore providePortalsCore() {
return this.portalsCore;
}

View File

@ -2,12 +2,9 @@ package com.sekwah.advancedportals.core.data;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.inject.name.Named;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
import javax.inject.Inject;
import javax.xml.crypto.Data;
import java.io.*;
import java.lang.reflect.Type;
@ -18,17 +15,10 @@ public class DataStorage {
private File dataFolder;
@Inject
@Named("portals-core")
private AdvancedPortalsCore portalsCore;
/**
* Only lets it be set once
* @param location
*/
public void setStorageLocation(File location) {
if(this.dataFolder == null) {
this.dataFolder = location;
}
public DataStorage(File dataStorageLoc) {
this.dataFolder = dataStorageLoc;
}
/**

View File

@ -2,11 +2,12 @@ package com.sekwah.advancedportals.core.repository;
import com.google.common.collect.ImmutableMap;
import com.google.gson.reflect.TypeToken;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.destination.Destination;
import com.sekwah.advancedportals.core.entities.DataTag;
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
import com.sekwah.advancedportals.core.entities.DataTag;
import com.sekwah.advancedportals.core.entities.PlayerLocation;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
@ -20,6 +21,9 @@ import java.util.Map;
public class DestinationRepositoryImpl implements DestinationRepository {
private Map<String, Destination> destiHashMap = new HashMap<>();
@Inject
private AdvancedPortalsCore portalsCore;
@Override
public void create(String name, Destination destination) {
destiHashMap.put(name, destination);
@ -35,11 +39,6 @@ public class DestinationRepositoryImpl implements DestinationRepository {
return ImmutableMap.copyOf(destiHashMap);
}
@Override
public void loadDestinations() {
}
public Destination createDesti(String name, PlayerContainer player, PlayerLocation playerLocation, ArrayList<DataTag> tags) {
// TODO change to write messages
@ -63,25 +62,21 @@ public class DestinationRepositoryImpl implements DestinationRepository {
}
}
this.destiHashMap.put(name, desti);
this.saveDestinations(AdvancedPortalsCore.getInstance());
this.saveDestinations();
return desti;
}
/**
* TODO change these, may be good if the data storage was an inject as well as it would save time and clean up layout
* @param portalsCore
*/
public void loadDestinations(AdvancedPortalsCore portalsCore) {
public void loadDestinations() {
Type type = new TypeToken<HashMap<String, Destination>>() {
}.getType();
this.destiHashMap = portalsCore.getDataStorage().loadJson(type, "destinations.json");
this.saveDestinations(portalsCore);
this.destiHashMap = this.portalsCore.getDataStorage().loadJson(type, "destinations.json");
this.saveDestinations();
}
public void saveDestinations(AdvancedPortalsCore portalsCore) {
public void saveDestinations() {
if (this.destiHashMap == null) {
this.destiHashMap = new HashMap<>();
}
portalsCore.getDataStorage().storeJson(this.destiHashMap, "destinations.json");
this.portalsCore.getDataStorage().storeJson(this.destiHashMap, "destinations.json");
}
}

View File

@ -1,11 +1,14 @@
package com.sekwah.advancedportals.coreconnector.container;
import com.sekwah.advancedportals.core.entities.PlayerLocation;
import com.sekwah.advancedportals.core.entities.PortalLocation;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.UUID;
/**

View File

@ -17,13 +17,7 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;

View File

@ -1,7 +1,5 @@
package com.sekwah.advancedportals.spigot;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.util.DataStorage;
import com.sekwah.advancedportals.coreconnector.ConnectorDataCollector;
@ -10,7 +8,6 @@ import com.sekwah.advancedportals.metrics.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

View File

@ -1,6 +1,5 @@
package com.sekwah.advancedportals.spigot;
import com.google.inject.name.Named;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.CoreListeners;
import com.sekwah.advancedportals.core.data.PortalLocation;
@ -15,8 +14,6 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import javax.inject.Inject;
public class Listeners implements Listener {
private CoreListeners coreListeners = AdvancedPortalsCore.getInstance().getCoreListeners();

View File

@ -1,8 +1,8 @@
package com.sekwah.advancedportals.spigot.convertolddata;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;