mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-01-11 10:48:36 +01:00
Moving to service handlers
This commit is contained in:
parent
77e037601b
commit
6dbfa6f242
@ -1,7 +1,14 @@
|
||||
package com.sekwah.advancedportals.core;
|
||||
|
||||
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.repository.DestinationRepositoryImpl;
|
||||
import com.sekwah.advancedportals.core.repository.PortalRepositoryImpl;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
@ -10,7 +17,6 @@ import com.sekwah.advancedportals.core.api.registry.WarpEffectRegistry;
|
||||
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.Config;
|
||||
import com.sekwah.advancedportals.core.data.DataStorage;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
@ -30,15 +36,17 @@ public class AdvancedPortalsCore {
|
||||
private TagRegistry<AdvancedPortal> portalTagRegistry;
|
||||
private TagRegistry<Destination> destiTagRegistry;
|
||||
|
||||
private CoreListeners coreListeners;
|
||||
private Injector injector = Guice.createInjector(new RepositoryModule(this));
|
||||
|
||||
private Config config;
|
||||
private CoreListeners coreListeners = injector.getInstance(CoreListeners.class);
|
||||
|
||||
private CommandWithSubCommands portalCommand;
|
||||
private CommandWithSubCommands destiCommand;
|
||||
|
||||
private PortalRepositoryImpl portalRepositoryImpl;
|
||||
private DestinationRepositoryImpl destiManager;
|
||||
private PortalServices portalServices = injector.getInstance(PortalServices.class);
|
||||
private DestinationServices destiServices = injector.getInstance(DestinationServices.class);
|
||||
private PortalTempDataServices portalTempDataServices = injector.getInstance(PortalTempDataServices.class);
|
||||
private ConfigRepository configRepository = injector.getInstance(ConfigRepository.class);
|
||||
|
||||
public static final String version = "1.0.0";
|
||||
public static final String lastTranslationUpdate = "1.0.0";
|
||||
@ -53,7 +61,7 @@ public class AdvancedPortalsCore {
|
||||
ConnectorDataCollector dataCollector, int[] mcVer) {
|
||||
this.dataStorage = dataStorage;
|
||||
this.infoLogger = infoLogger;
|
||||
this.instance = this;
|
||||
instance = this;
|
||||
this.commandRegister = commandRegister;
|
||||
this.dataCollector = dataCollector;
|
||||
this.mcMinorVer = this.checkMcVer(mcVer);
|
||||
@ -98,13 +106,10 @@ public class AdvancedPortalsCore {
|
||||
|
||||
|
||||
public static String getTranslationName() {
|
||||
return instance.config.getTranslation();
|
||||
return instance.configRepository.getTranslation();
|
||||
}
|
||||
|
||||
private void onEnable() {
|
||||
this.coreListeners = new CoreListeners(this);
|
||||
this.portalRepositoryImpl = new PortalRepositoryImpl(this);
|
||||
this.destiManager = new DestinationRepositoryImpl(this);
|
||||
this.warpEffectRegistry = new WarpEffectRegistry();
|
||||
this.portalTagRegistry = new TagRegistry<>();
|
||||
this.destiTagRegistry = new TagRegistry<>();
|
||||
@ -112,14 +117,14 @@ public class AdvancedPortalsCore {
|
||||
this.dataStorage.copyDefaultFile("lang/en_GB.lang", false);
|
||||
|
||||
this.loadPortalConfig();
|
||||
Lang.loadLanguage(config.getTranslation());
|
||||
Lang.loadLanguage(configRepository.getTranslation());
|
||||
|
||||
this.registerPortalCommand();
|
||||
this.registerDestinationCommand();
|
||||
|
||||
this.portalRepositoryImpl.loadPortals();
|
||||
this.portalServices.loadPortals(this);
|
||||
|
||||
this.destiManager.loadDestinations();
|
||||
this.destiServices.loadDestinations(this);
|
||||
|
||||
this.infoLogger.log(Lang.translate("logger.pluginenable"));
|
||||
}
|
||||
@ -161,8 +166,8 @@ public class AdvancedPortalsCore {
|
||||
* (basically if values are missing or whatever)
|
||||
*/
|
||||
public void loadPortalConfig() {
|
||||
this.config = this.dataStorage.loadJson(Config.class, "config.json");
|
||||
this.dataStorage.storeJson(this.config, "config.json");
|
||||
this.configRepository.loadConfig(this.dataStorage);
|
||||
this.dataStorage.storeJson(this.configRepository, "config.json");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,8 +181,8 @@ public class AdvancedPortalsCore {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Config getConfig() {
|
||||
return this.config;
|
||||
public ConfigRepository getConfigRepo() {
|
||||
return this.configRepository;
|
||||
}
|
||||
|
||||
public DataStorage getDataStorage() {
|
||||
@ -196,12 +201,16 @@ public class AdvancedPortalsCore {
|
||||
return instance.coreListeners;
|
||||
}
|
||||
|
||||
public static PortalRepositoryImpl getPortalManager() {
|
||||
return instance.portalRepositoryImpl;
|
||||
public static PortalServices getPortalServices() {
|
||||
return instance.portalServices;
|
||||
}
|
||||
|
||||
public static DestinationRepositoryImpl getDestinationManager() {
|
||||
return instance.destiManager;
|
||||
public static DestinationServices getDestinationServices() {
|
||||
return instance.destiServices;
|
||||
}
|
||||
|
||||
public static PortalTempDataServices getPortalTempDataServices() {
|
||||
return instance.portalTempDataServices;
|
||||
}
|
||||
|
||||
public static TagRegistry<AdvancedPortal> getPortalTagRegistry() {
|
||||
|
@ -1,21 +1,30 @@
|
||||
package com.sekwah.advancedportals.core;
|
||||
|
||||
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;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.core.repository.PortalRepository;
|
||||
import com.sekwah.advancedportals.core.repository.PortalTempDataRepository;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
import com.sekwah.advancedportals.coreconnector.container.WorldContainer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class CoreListeners {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
private PortalTempDataServices portalTempDataServices;
|
||||
|
||||
public CoreListeners(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
private PortalServices portalServices;
|
||||
|
||||
@Inject
|
||||
@Named("portals-core")
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
public void playerJoin(PlayerContainer player) {
|
||||
AdvancedPortalsCore.getPortalManager().activateCooldown(player);
|
||||
this.portalTempDataServices.activateCooldown(player);
|
||||
if(player.isOp()) {
|
||||
if(!Lang.translate("translatedata.lastchange").equals(AdvancedPortalsCore.lastTranslationUpdate)) {
|
||||
player.sendMessage(Lang.translateColor("messageprefix.negative")
|
||||
@ -27,11 +36,11 @@ public class CoreListeners {
|
||||
}
|
||||
|
||||
public void teleportEvent(PlayerContainer player) {
|
||||
AdvancedPortalsCore.getPortalManager().activateCooldown(player);
|
||||
this.portalTempDataServices.activateCooldown(player);
|
||||
}
|
||||
|
||||
public void playerLeave(PlayerContainer player) {
|
||||
AdvancedPortalsCore.getPortalManager().playerLeave(player);
|
||||
this.portalTempDataServices.playerLeave(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,7 +48,7 @@ public class CoreListeners {
|
||||
* @return if the entity is allowed to spawn
|
||||
*/
|
||||
public boolean mobSpawn(PlayerLocation loc) {
|
||||
return !AdvancedPortalsCore.getPortalManager().inPortalRegion(loc);
|
||||
return !this.portalServices.inPortalRegion(loc);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,7 +58,7 @@ public class CoreListeners {
|
||||
* @return if the player is allowed to move
|
||||
*/
|
||||
public boolean playerMove(PlayerContainer player, PlayerLocation fromLoc, PlayerLocation toLoc) {
|
||||
return AdvancedPortalsCore.getPortalManager().playerMove(player, fromLoc, toLoc);
|
||||
return this.portalServices.playerMove(player, fromLoc, toLoc);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,9 +125,9 @@ public class CoreListeners {
|
||||
public boolean playerInteractWithBlock(PlayerContainer player, String materialName, String itemName,
|
||||
PortalLocation blockLoc, boolean leftClick) {
|
||||
if(itemName != null && (player.isOp() || player.hasPermission("advancedportals.createportal")) &&
|
||||
materialName.equalsIgnoreCase(this.portalsCore.getConfig().getSelectorMaterial())
|
||||
&& (!this.portalsCore.getConfig().getUseOnlySpecialAxe() || itemName.equals("\u00A7ePortal Region Selector"))) {
|
||||
AdvancedPortalsCore.getPortalManager().playerSelectorActivate(player, blockLoc, leftClick);
|
||||
materialName.equalsIgnoreCase(this.portalsCore.getConfigRepo().getSelectorMaterial())
|
||||
&& (!this.portalsCore.getConfigRepo().getUseOnlySpecialAxe() || itemName.equals("\u00A7ePortal Region Selector"))) {
|
||||
this.portalTempDataServices.playerSelectorActivate(player, blockLoc, leftClick);
|
||||
return false;
|
||||
}
|
||||
else if(itemName != null && leftClick && itemName.equals("\u00A75Portal Block Placer") && player.hasPermission("advancedportals.build")) {
|
||||
|
@ -1,4 +1,33 @@
|
||||
package com.sekwah.advancedportals.core.api.services;
|
||||
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.api.portal.PortalException;
|
||||
import com.sekwah.advancedportals.core.entities.DataTag;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.util.ArrayList; /**
|
||||
* https://github.com/sekwah41/Advanced-Portals/blob/24175610892152828e21f4ff824eb1589ccb0338/src/com/sekwah/advancedportals/core/api/managers/DestinationManager.java
|
||||
* Based off the old manager with the data storage and handling moved to {@link com.sekwah.advancedportals.core.repository.DestinationRepository}
|
||||
*/
|
||||
public class DestinationServices {
|
||||
|
||||
/**
|
||||
* @param portalsCore
|
||||
*/
|
||||
public void loadDestinations(AdvancedPortalsCore portalsCore) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param player
|
||||
* @param loc
|
||||
* @param destiTags
|
||||
* @return
|
||||
*/
|
||||
public Destination createDesti(String name, PlayerContainer player, PlayerLocation loc, ArrayList<DataTag> destiTags) throws PortalException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,45 @@
|
||||
package com.sekwah.advancedportals.core.api.services;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.api.portal.PortalException;
|
||||
import com.sekwah.advancedportals.core.entities.DataTag;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* https://github.com/sekwah41/Advanced-Portals/blob/24175610892152828e21f4ff824eb1589ccb0338/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java
|
||||
*
|
||||
* Based off the old manager with the data storage and handling moved to {@link com.sekwah.advancedportals.core.repository.PortalRepository}
|
||||
*
|
||||
* Excluding the temp data like selections
|
||||
*/
|
||||
public class PortalServices {
|
||||
public void loadPortals(AdvancedPortalsCore advancedPortalsCore) {
|
||||
|
||||
}
|
||||
|
||||
public boolean inPortalRegion(PlayerLocation loc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean playerMove(PlayerContainer player, PlayerLocation fromLoc, PlayerLocation toLoc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ImmutableList<? extends Map.Entry<String, AdvancedPortal>> getPortals() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removePortal(String name, PlayerContainer player) throws PortalException {
|
||||
|
||||
}
|
||||
|
||||
public AdvancedPortal createPortal(String name, PlayerContainer player, ArrayList<DataTag> portalTags) throws PortalException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,23 @@
|
||||
package com.sekwah.advancedportals.core.api.services;
|
||||
|
||||
import com.sekwah.advancedportals.core.api.portal.PortalException;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
public class PortalTempDataServices {
|
||||
public void activateCooldown(PlayerContainer player) {
|
||||
|
||||
}
|
||||
|
||||
public void playerLeave(PlayerContainer player) {
|
||||
|
||||
}
|
||||
|
||||
public void playerSelectorActivate(PlayerContainer player, PortalLocation blockLoc, boolean leftClick) {
|
||||
|
||||
}
|
||||
|
||||
public void removePlayerSelection(PlayerContainer player) throws PortalException {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class CreateDestiSubCommand extends CreateSubCommand implements SubComman
|
||||
}
|
||||
ArrayList<DataTag> destiTags = this.getTagsFromArgs(args);
|
||||
try {
|
||||
Destination desti = AdvancedPortalsCore.getDestinationManager().createDesti(args[1], player, player.getLoc(), destiTags);
|
||||
Destination desti = AdvancedPortalsCore.getDestinationServices().createDesti(args[1], player, player.getLoc(), destiTags);
|
||||
if(desti != null) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.createdesti.complete"));
|
||||
sender.sendMessage(Lang.translateColor("command.create.tags"));
|
||||
|
@ -27,7 +27,7 @@ public class CreatePortalSubCommand extends CreateSubCommand implements SubComma
|
||||
ArrayList<DataTag> portalTags = this.getTagsFromArgs(args);
|
||||
try {
|
||||
System.out.println(Arrays.toString(portalTags.toArray()));
|
||||
AdvancedPortal portal = AdvancedPortalsCore.getPortalManager().createPortal(args[1], player, portalTags);
|
||||
AdvancedPortal portal = AdvancedPortalsCore.getPortalServices().createPortal(args[1], player, portalTags);
|
||||
if(portal != null) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.create.complete"));
|
||||
sender.sendMessage(Lang.translateColor("command.create.tags"));
|
||||
|
@ -18,8 +18,8 @@ public class ReloadSubCommand implements SubCommand {
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
portalsCore.loadPortalConfig();
|
||||
portalsCore.getPortalManager().loadPortals();
|
||||
portalsCore.getDestinationManager().loadDestinations();
|
||||
portalsCore.getPortalServices().loadPortals(portalsCore);
|
||||
portalsCore.getDestinationServices().loadDestinations(portalsCore);
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.reload.reloaded"));
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class RemoveSubCommand implements SubCommand {
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
if(args.length > 1) {
|
||||
try {
|
||||
AdvancedPortalsCore.getPortalManager().removePortal(args[1], sender.getPlayerContainer());
|
||||
AdvancedPortalsCore.getPortalServices().removePortal(args[1], sender.getPlayerContainer());
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.remove.complete"));
|
||||
} catch (PortalException portalTagExeption) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative")
|
||||
@ -33,7 +33,7 @@ public class RemoveSubCommand implements SubCommand {
|
||||
}
|
||||
else {
|
||||
try {
|
||||
AdvancedPortalsCore.getPortalManager().removePlayerSelection(player);
|
||||
AdvancedPortalsCore.getPortalTempDataServices().removePlayerSelection(player);
|
||||
} catch (PortalException portalTagExeption) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative")
|
||||
+ Lang.translateColor("command.remove.error") + " " + Lang.translate(portalTagExeption.getMessage()));
|
||||
@ -50,7 +50,7 @@ public class RemoveSubCommand implements SubCommand {
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
List<String> portalNames = new ArrayList<>();
|
||||
for(Map.Entry<String, AdvancedPortal> portal : AdvancedPortalsCore.getPortalManager().getPortals()) {
|
||||
for(Map.Entry<String, AdvancedPortal> portal : AdvancedPortalsCore.getPortalServices().getPortals()) {
|
||||
portalNames.add(portal.getKey());
|
||||
}
|
||||
Collections.sort(portalNames);
|
||||
|
@ -23,7 +23,7 @@ public class SelectorSubCommand implements SubCommand {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.playeronly"));
|
||||
}
|
||||
else {
|
||||
player.giveItem(this.portalsCore.getConfig().getSelectorMaterial(), "\u00A7ePortal Region Selector"
|
||||
player.giveItem(this.portalsCore.getConfigRepo().getSelectorMaterial(), "\u00A7ePortal Region Selector"
|
||||
, "\u00A7rThis wand with has the power to help", "\u00A7r create portals bistowed upon it!");
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.selector"));
|
||||
}
|
||||
|
@ -5,45 +5,30 @@ package com.sekwah.advancedportals.core.config;
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
private boolean useOnlySpecialAxe = true;
|
||||
public boolean useOnlySpecialAxe = true;
|
||||
|
||||
private String selectorMaterial = "IRON_AXE";
|
||||
public String selectorMaterial = "IRON_AXE";
|
||||
|
||||
private boolean portalProtection = true;
|
||||
public boolean portalProtection = true;
|
||||
|
||||
private int portalProtectionRaduis = 5;
|
||||
public int portalProtectionRaduis = 5;
|
||||
|
||||
private String defaultTriggerBlock = "PORTAL";
|
||||
public String defaultTriggerBlock = "PORTAL";
|
||||
|
||||
private boolean stopWaterFlow = true;
|
||||
public boolean stopWaterFlow = true;
|
||||
|
||||
private int portalCooldown = 5;
|
||||
public int portalCooldown = 5;
|
||||
|
||||
private String warpParticles = "ENDER";
|
||||
public String warpParticles = "ENDER";
|
||||
|
||||
private String warpSound = "ENDER";
|
||||
public String warpSound = "ENDER";
|
||||
|
||||
private String selectionBlock_BELOW_1_13 = "STAINED_GLASS";
|
||||
public String selectionBlock_BELOW_1_13 = "STAINED_GLASS";
|
||||
|
||||
private String selectionBlock = "RED_STAINED_GLASS";
|
||||
public String selectionBlock = "RED_STAINED_GLASS";
|
||||
|
||||
private String translationFile = "en_GB";
|
||||
public String translationFile = "en_GB";
|
||||
|
||||
private int selectionSubID_BELOW_1_13 = 14;
|
||||
public int selectionSubID_BELOW_1_13 = 14;
|
||||
|
||||
public boolean getUseOnlySpecialAxe() {
|
||||
return useOnlySpecialAxe;
|
||||
}
|
||||
|
||||
public void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe) {
|
||||
useOnlySpecialAxe = useOnlyServerMadeAxe;
|
||||
}
|
||||
|
||||
public String getTranslation() {
|
||||
return translationFile;
|
||||
}
|
||||
|
||||
public String getSelectorMaterial() {
|
||||
return selectorMaterial;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,33 @@
|
||||
package com.sekwah.advancedportals.core.config;
|
||||
|
||||
public class RepositoryModule {
|
||||
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;
|
||||
|
||||
public RepositoryModule(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(PortalRepository.class).to(PortalRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
bind(DestinationRepository.class).to(DestinationRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
bind(PortalTempDataRepository.class).to(PortalTempDataRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
bind(ConfigRepository.class).to(ConfigRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("portals-core")
|
||||
AdvancedPortalsCore providePortalsCore() {
|
||||
return this.portalsCore;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,16 @@
|
||||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.sekwah.advancedportals.core.data.DataStorage;
|
||||
|
||||
public interface ConfigRepository {
|
||||
|
||||
boolean getUseOnlySpecialAxe();
|
||||
|
||||
void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe);
|
||||
|
||||
String getTranslation();
|
||||
|
||||
String getSelectorMaterial();
|
||||
|
||||
void loadConfig(DataStorage dataStorage);
|
||||
}
|
||||
|
@ -1,4 +1,34 @@
|
||||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.sekwah.advancedportals.core.config.Config;
|
||||
import com.sekwah.advancedportals.core.data.DataStorage;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class ConfigRepositoryImpl implements ConfigRepository {
|
||||
|
||||
private Config config;
|
||||
|
||||
public boolean getUseOnlySpecialAxe() {
|
||||
return this.config.useOnlySpecialAxe;
|
||||
}
|
||||
|
||||
public void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe) {
|
||||
this.config.useOnlySpecialAxe = useOnlyServerMadeAxe;
|
||||
}
|
||||
|
||||
public String getTranslation() {
|
||||
return this.config.translationFile;
|
||||
}
|
||||
|
||||
public String getSelectorMaterial() {
|
||||
return this.config.selectorMaterial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadConfig(DataStorage dataStorage) {
|
||||
this.config = dataStorage.loadJson(Config.class, "config.json");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,4 +9,6 @@ public interface DestinationRepository {
|
||||
void delete(String name);
|
||||
|
||||
ImmutableMap<String, Destination> getDestinations();
|
||||
|
||||
void loadDestinations();
|
||||
}
|
||||
|
@ -35,6 +35,11 @@ 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) throws PortalException {
|
||||
if(name == null || name.equals("")) {
|
||||
@ -55,23 +60,25 @@ public class DestinationRepositoryImpl implements DestinationRepository {
|
||||
}
|
||||
}
|
||||
this.destiHashMap.put(name, desti);
|
||||
AdvancedPortalsCore.getDestinationManager().saveDestinations();
|
||||
this.saveDestinations(AdvancedPortalsCore.getInstance());
|
||||
return desti;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void loadDestinations() {
|
||||
/**
|
||||
* 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) {
|
||||
Type type = new TypeToken<HashMap<String, Destination>>() {
|
||||
}.getType();
|
||||
this.destiHashMap = this.portalsCore.getDataStorage().loadJson(type, "destinations.json");
|
||||
this.saveDestinations();
|
||||
this.destiHashMap = portalsCore.getDataStorage().loadJson(type, "destinations.json");
|
||||
this.saveDestinations(portalsCore);
|
||||
}
|
||||
|
||||
public void saveDestinations() {
|
||||
public void saveDestinations(AdvancedPortalsCore portalsCore) {
|
||||
if (this.destiHashMap == null) {
|
||||
this.destiHashMap = new HashMap<>();
|
||||
}
|
||||
this.portalsCore.getDataStorage().storeJson(this.destiHashMap, "destinations.json");
|
||||
portalsCore.getDataStorage().storeJson(this.destiHashMap, "destinations.json");
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,13 @@
|
||||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
public interface PortalRepository {
|
||||
|
||||
void loadPortals();
|
||||
|
||||
void savePortals();
|
||||
|
||||
boolean playerMove(PlayerContainer player, PlayerLocation fromLoc, PlayerLocation toLoc);
|
||||
}
|
||||
|
@ -1,4 +1,23 @@
|
||||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
public class PortalRepositoryImpl {
|
||||
import com.google.inject.Singleton;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
@Singleton
|
||||
public class PortalRepositoryImpl implements PortalRepository {
|
||||
@Override
|
||||
public void loadPortals() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePortals() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerMove(PlayerContainer player, PlayerLocation fromLoc, PlayerLocation toLoc) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface TempPlayerDataRepository {
|
||||
public interface PortalTempDataRepository {
|
||||
void addSelectedPortal(UUID selectedPlayer, String portal);
|
||||
|
||||
void removeSelectedPortal(UUID uuid);
|
||||
|
@ -5,14 +5,16 @@ import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Table;
|
||||
import com.google.inject.Singleton;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.core.enums.EnumHandSelection;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Singleton
|
||||
public class TempPlayerDataRepositoryImpl implements TempPlayerDataRepository {
|
||||
public class PortalTempDataRepositoryImpl implements PortalTempDataRepository {
|
||||
Cache<UUID, String> selectedPortal = CacheBuilder.newBuilder()
|
||||
.concurrencyLevel(4)
|
||||
.expireAfterAccess(30, TimeUnit.DAYS)
|
||||
@ -45,4 +47,19 @@ public class TempPlayerDataRepositoryImpl implements TempPlayerDataRepository {
|
||||
selectedHand.remove(uuid, EnumHandSelection.LEFTHAND);
|
||||
selectedHand.remove(uuid, EnumHandSelection.RIGHTHAND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateCooldown(PlayerContainer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerLeave(PlayerContainer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inPortalRegion(PlayerLocation loc) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user