A little cleanup

This commit is contained in:
Sekwah 2020-06-29 01:05:14 +01:00
parent 3b4d387191
commit 851b0688c1
No known key found for this signature in database
GPG Key ID: C3BE2E6C861A461A
15 changed files with 113 additions and 194 deletions

View File

@ -3,12 +3,11 @@ package com.sekwah.advancedportals.core.api.services;
import com.sekwah.advancedportals.core.api.destination.Destination;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.repository.DestinationRepositoryOld;
import com.sekwah.advancedportals.core.connector.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 DestinationRepositoryOld}
* Based off the old manager with the data storage and handling moved to
*/
public final class DestinationServices {

View File

@ -1,7 +1,7 @@
package com.sekwah.advancedportals.core.api.services;
import com.google.common.collect.ImmutableList;
import com.sekwah.advancedportals.repository.PortalRepository;
import com.sekwah.advancedportals.repository.IPortalRepository;
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.data.PlayerLocation;
@ -13,7 +13,7 @@ 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 PortalRepository}
* Based off the old manager with the data storage and handling moved to {@link IPortalRepository}
*
* Excluding the temp data like selections
*/

View File

@ -17,9 +17,9 @@ public class RepositoryModule extends AbstractModule {
@Override
protected void configure() {
bind(PortalRepository.class).to(PortalRepositoryImpl.class).in(Scopes.SINGLETON);
bind(DestinationRepository.class).to(DestinationRepositoryImpl.class).in(Scopes.SINGLETON);
bind(PortalRepository.class).to(PortalRepositoryImpl.class).in(Scopes.SINGLETON);
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());
}

View File

@ -1,4 +1,56 @@
package com.sekwah.advancedportals.repository;
public interface DestinationRepository<T> extends JsonRepository<T> {
import com.google.common.collect.ImmutableMap;
import com.sekwah.advancedportals.core.api.destination.Destination;
import javax.inject.Singleton;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
@Singleton
public class DestinationRepository implements IDestinationRepository<Destination> {
private final String fileLocation = "";
private Map<String, Destination> destinationCache = new HashMap<String, Destination>();
/*Is there any reason to load it into the array if it's not been used or connected? Q for Sekwah*/
public void AddDestination(String name, Destination destination) throws IOException {
gson.toJson(destination, new FileWriter(fileLocation + name + ".json"));
}
private void test() {
destinationCache.get("");
}
@Override
public boolean save(String name, Destination destination) {
return false;
}
public boolean containsKey(String name) {
return Files.exists(Paths.get(fileLocation + "\\" + name + ".json"));
}
@Override
public boolean delete(String name) {
try {
Files.deleteIfExists(Paths.get(fileLocation + "\\" + name + ".json"));
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
@Override
public boolean update(String name, Destination destination) {
return false;
}
public ImmutableMap<String, Destination> get(String s) {
return null;
}
}

View File

@ -1,56 +0,0 @@
package com.sekwah.advancedportals.repository;
import com.google.common.collect.ImmutableMap;
import com.sekwah.advancedportals.core.api.destination.Destination;
import javax.inject.Singleton;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
@Singleton
public class DestinationRepositoryImpl implements DestinationRepository<Destination>{
private final String fileLocation = "";
private Map<String, Destination> destinationCache = new HashMap<String, Destination>();
/*Is there any reason to load it into the array if it's not been used or connected? Q for Sekwah*/
public void AddDestination(String name, Destination destination) throws IOException {
gson.toJson(destination, new FileWriter(fileLocation + name + ".json"));
}
private void test() {
destinationCache.get("");
}
@Override
public boolean save(String name, Destination destination) {
return false;
}
public boolean containsKey(String name) {
return Files.exists(Paths.get(fileLocation + "\\" + name + ".json"));
}
@Override
public boolean delete(String name) {
try {
Files.deleteIfExists(Paths.get(fileLocation + "\\" + name + ".json"));
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
@Override
public boolean update(String name, Destination destination) {
return false;
}
public ImmutableMap<String, Destination> get(String s) {
return null;
}
}

View File

@ -1,15 +0,0 @@
package com.sekwah.advancedportals.repository;
import com.google.common.collect.ImmutableMap;
import com.sekwah.advancedportals.core.api.destination.Destination;
@Deprecated
public interface DestinationRepositoryOld {
void create(String name, Destination destination);
void delete(String name);
ImmutableMap<String, Destination> getDestinations();
void loadDestinations();
}

View File

@ -0,0 +1,4 @@
package com.sekwah.advancedportals.repository;
public interface IDestinationRepository<T> extends IJsonRepository<T> {
}

View File

@ -2,7 +2,7 @@ package com.sekwah.advancedportals.repository;
import com.google.gson.Gson;
public interface JsonRepository<T> {
public interface IJsonRepository<T> {
Gson gson = new Gson();
public boolean save(String name, T t);

View File

@ -0,0 +1,7 @@
package com.sekwah.advancedportals.repository;
import com.sekwah.advancedportals.core.data.PortalLocation;
public interface IPortalRepository extends IJsonRepository<PortalLocation> {
}

View File

@ -6,7 +6,7 @@ import com.sekwah.advancedportals.core.connector.container.PlayerContainer;
import java.util.UUID;
public interface PortalTempDataRepository {
public interface IPortalTempDataRepository {
void addSelectedPortal(UUID selectedPlayer, String portal);
void removeSelectedPortal(UUID uuid);

View File

@ -1,7 +1,41 @@
package com.sekwah.advancedportals.repository;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.inject.Singleton;
import com.sekwah.advancedportals.core.data.PortalLocation;
public interface PortalRepository extends JsonRepository<PortalLocation> {
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Singleton
public class PortalRepository implements IPortalRepository {
Cache<UUID, String> selectedPortal = CacheBuilder.newBuilder()
.concurrencyLevel(4)
.expireAfterAccess(30, TimeUnit.DAYS)
.build();
public String getSelectedPortal(UUID uuid) {
return selectedPortal.getIfPresent(uuid);
}
@Override
public boolean save(String name, PortalLocation portalLocation) {
return false;
}
@Override
public boolean containsKey(String name) {
return false;
}
@Override
public boolean delete(String name) {
return false;
}
@Override
public boolean update(String name, PortalLocation portalLocation) {
return false;
}
}

View File

@ -1,41 +0,0 @@
package com.sekwah.advancedportals.repository;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.inject.Singleton;
import com.sekwah.advancedportals.core.data.PortalLocation;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Singleton
public class PortalRepositoryImpl implements PortalRepository {
Cache<UUID, String> selectedPortal = CacheBuilder.newBuilder()
.concurrencyLevel(4)
.expireAfterAccess(30, TimeUnit.DAYS)
.build();
public String getSelectedPortal(UUID uuid) {
return selectedPortal.getIfPresent(uuid);
}
@Override
public boolean save(String name, PortalLocation portalLocation) {
return false;
}
@Override
public boolean containsKey(String name) {
return false;
}
@Override
public boolean delete(String name) {
return false;
}
@Override
public boolean update(String name, PortalLocation portalLocation) {
return false;
}
}

View File

@ -1,65 +0,0 @@
package com.sekwah.advancedportals.repository;
import com.google.common.cache.Cache;
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.data.PlayerLocation;
import com.sekwah.advancedportals.core.data.PortalLocation;
import com.sekwah.advancedportals.core.connector.container.PlayerContainer;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Singleton
@Deprecated
public class PortalTempDataRepositoryImpl implements PortalTempDataRepository {
Cache<UUID, String> selectedPortal = CacheBuilder.newBuilder()
.concurrencyLevel(4)
.expireAfterAccess(30, TimeUnit.DAYS)
.build();
Table<UUID, Boolean, PortalLocation> selectedPositions = HashBasedTable.create();
@Override
public void addSelectedPortal(UUID selectedPlayer, String portal) {
selectedPortal.put(selectedPlayer, portal);
}
@Override
public void removeSelectedPortal(UUID uuid) {
selectedPortal.invalidate(uuid);
}
@Override
public void addSelectedPosition(UUID uuid, boolean isPos1, PortalLocation portalLocation) {
selectedPositions.put(uuid, isPos1, portalLocation);
}
@Override
public void removeSelectedPosition(UUID uuid, boolean isPos1) {
selectedPositions.remove(uuid, isPos1);
}
@Override
public void removeAllSelectedHand(UUID uuid) {
selectedPositions.remove(uuid, true);
selectedPositions.remove(uuid, false);
}
@Override
public void activateCooldown(PlayerContainer player) {
}
@Override
public void playerLeave(PlayerContainer player) {
}
@Override
public boolean inPortalRegion(PlayerLocation loc) {
return false;
}
}

View File

@ -10,7 +10,7 @@ import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.connector.container.PlayerContainer;
import com.sekwah.advancedportals.repository.DestinationRepositoryImpl;
import com.sekwah.advancedportals.repository.DestinationRepository;
import javax.inject.Inject;
import java.io.IOException;
@ -24,10 +24,10 @@ import java.util.HashMap;
*/
public class DestinationServices {
DestinationRepositoryImpl destinationRepository;
DestinationRepository destinationRepository;
@Inject
private DestinationServices(DestinationRepositoryImpl destinationRepository) {
private DestinationServices(DestinationRepository destinationRepository) {
this.destinationRepository = destinationRepository;
}

View File

@ -4,16 +4,16 @@ import com.google.inject.Inject;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.data.PortalLocation;
import com.sekwah.advancedportals.core.connector.container.PlayerContainer;
import com.sekwah.advancedportals.repository.PortalRepository;
import com.sekwah.advancedportals.repository.IPortalRepository;
import java.util.UUID;
public class PortalServices {
private final PortalRepository portalRepository;
private final IPortalRepository portalRepository;
@Inject
public PortalServices(PortalRepository portalRepository) {
public PortalServices(IPortalRepository portalRepository) {
this.portalRepository = portalRepository;
}