From b9475a3550a4ebb176121dcae233773f1f83d481 Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 3 Jun 2018 04:33:52 -0600 Subject: [PATCH] Moved classes and packages to be in src > main > java --- .../core/AdvancedPortalsCore.java | 20 +++---- .../advancedportals/core/CoreListeners.java | 4 +- .../core/api/destination/Destination.java | 4 +- .../core/api/effect/TestEffect.java | 2 +- .../core/api/effect/WarpEffect.java | 2 +- .../core/api/portal/AdvancedPortal.java | 3 +- .../subcommands/CreateSubCommand.java | 3 +- .../desti/CreateDestiSubCommand.java | 2 +- .../portal/CreatePortalSubCommand.java | 2 +- .../{api/portal => entities}/DataTag.java | 2 +- .../{data => entities}/PlayerLocation.java | 2 +- .../{data => entities}/PortalLocation.java | 2 +- .../core/enums/EnumHandSelection.java | 6 +++ .../repository/DestinationRepository.java | 12 +++++ .../DestinationRepositoryImpl.java} | 38 +++++++------ .../PortalManager.java | 6 +-- .../core/repository/SelectionRepository.java | 18 +++++++ .../repository/SelectionRepositoryImpl.java | 53 +++++++++++++++++++ 18 files changed, 139 insertions(+), 42 deletions(-) rename src/main/java/com/sekwah/advancedportals/core/{api/portal => entities}/DataTag.java (79%) rename src/main/java/com/sekwah/advancedportals/core/{data => entities}/PlayerLocation.java (95%) rename src/main/java/com/sekwah/advancedportals/core/{data => entities}/PortalLocation.java (90%) create mode 100644 src/main/java/com/sekwah/advancedportals/core/enums/EnumHandSelection.java create mode 100644 src/main/java/com/sekwah/advancedportals/core/repository/DestinationRepository.java rename src/main/java/com/sekwah/advancedportals/core/{api/managers/DestinationManager.java => repository/DestinationRepositoryImpl.java} (71%) rename src/main/java/com/sekwah/advancedportals/core/{api/managers => repository}/PortalManager.java (98%) create mode 100644 src/main/java/com/sekwah/advancedportals/core/repository/SelectionRepository.java create mode 100644 src/main/java/com/sekwah/advancedportals/core/repository/SelectionRepositoryImpl.java diff --git a/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index 4d49210f..94b95d56 100644 --- a/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -2,8 +2,8 @@ package com.sekwah.advancedportals.core; import com.sekwah.advancedportals.core.api.commands.SubCommand; import com.sekwah.advancedportals.core.api.destination.Destination; -import com.sekwah.advancedportals.core.api.managers.DestinationManager; -import com.sekwah.advancedportals.core.api.managers.PortalManager; +import com.sekwah.advancedportals.core.repository.DestinationRepositoryImpl; +import com.sekwah.advancedportals.core.repository.PortalRepositoryImpl; import com.sekwah.advancedportals.core.api.portal.AdvancedPortal; import com.sekwah.advancedportals.core.api.registry.TagRegistry; import com.sekwah.advancedportals.core.api.registry.WarpEffectRegistry; @@ -37,8 +37,8 @@ public class AdvancedPortalsCore { private CommandWithSubCommands portalCommand; private CommandWithSubCommands destiCommand; - private PortalManager portalManager; - private DestinationManager destiManager; + private PortalRepositoryImpl portalRepositoryImpl; + private DestinationRepositoryImpl destiManager; public static final String version = "1.0.0"; public static final String lastTranslationUpdate = "1.0.0"; @@ -103,8 +103,8 @@ public class AdvancedPortalsCore { private void onEnable() { this.coreListeners = new CoreListeners(this); - this.portalManager = new PortalManager(this); - this.destiManager = new DestinationManager(this); + this.portalRepositoryImpl = new PortalRepositoryImpl(this); + this.destiManager = new DestinationRepositoryImpl(this); this.warpEffectRegistry = new WarpEffectRegistry(); this.portalTagRegistry = new TagRegistry<>(); this.destiTagRegistry = new TagRegistry<>(); @@ -117,7 +117,7 @@ public class AdvancedPortalsCore { this.registerPortalCommand(); this.registerDestinationCommand(); - this.portalManager.loadPortals(); + this.portalRepositoryImpl.loadPortals(); this.destiManager.loadDestinations(); @@ -196,11 +196,11 @@ public class AdvancedPortalsCore { return instance.coreListeners; } - public static PortalManager getPortalManager() { - return instance.portalManager; + public static PortalRepositoryImpl getPortalManager() { + return instance.portalRepositoryImpl; } - public static DestinationManager getDestinationManager() { + public static DestinationRepositoryImpl getDestinationManager() { return instance.destiManager; } diff --git a/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java b/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java index 17f3dd16..fcf3c834 100644 --- a/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java +++ b/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java @@ -1,7 +1,7 @@ package com.sekwah.advancedportals.core; -import com.sekwah.advancedportals.core.data.PlayerLocation; -import com.sekwah.advancedportals.core.data.PortalLocation; +import com.sekwah.advancedportals.core.entities.PlayerLocation; +import com.sekwah.advancedportals.core.entities.PortalLocation; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; import com.sekwah.advancedportals.coreconnector.container.WorldContainer; diff --git a/src/main/java/com/sekwah/advancedportals/core/api/destination/Destination.java b/src/main/java/com/sekwah/advancedportals/core/api/destination/Destination.java index 3a4b4be0..683dda4e 100644 --- a/src/main/java/com/sekwah/advancedportals/core/api/destination/Destination.java +++ b/src/main/java/com/sekwah/advancedportals/core/api/destination/Destination.java @@ -2,12 +2,12 @@ package com.sekwah.advancedportals.core.api.destination; import com.google.gson.annotations.SerializedName; import com.sekwah.advancedportals.core.AdvancedPortalsCore; -import com.sekwah.advancedportals.core.api.portal.DataTag; +import com.sekwah.advancedportals.core.entities.DataTag; import com.sekwah.advancedportals.core.api.portal.PortalException; 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.data.PlayerLocation; +import com.sekwah.advancedportals.core.entities.PlayerLocation; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; import java.util.ArrayList; diff --git a/src/main/java/com/sekwah/advancedportals/core/api/effect/TestEffect.java b/src/main/java/com/sekwah/advancedportals/core/api/effect/TestEffect.java index f8ce1d0d..a280e681 100644 --- a/src/main/java/com/sekwah/advancedportals/core/api/effect/TestEffect.java +++ b/src/main/java/com/sekwah/advancedportals/core/api/effect/TestEffect.java @@ -1,7 +1,7 @@ package com.sekwah.advancedportals.core.api.effect; import com.sekwah.advancedportals.core.api.portal.AdvancedPortal; -import com.sekwah.advancedportals.core.data.PortalLocation; +import com.sekwah.advancedportals.core.entities.PortalLocation; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; /** diff --git a/src/main/java/com/sekwah/advancedportals/core/api/effect/WarpEffect.java b/src/main/java/com/sekwah/advancedportals/core/api/effect/WarpEffect.java index 37201a8c..d8aa3627 100644 --- a/src/main/java/com/sekwah/advancedportals/core/api/effect/WarpEffect.java +++ b/src/main/java/com/sekwah/advancedportals/core/api/effect/WarpEffect.java @@ -1,7 +1,7 @@ package com.sekwah.advancedportals.core.api.effect; import com.sekwah.advancedportals.core.api.portal.AdvancedPortal; -import com.sekwah.advancedportals.core.data.PortalLocation; +import com.sekwah.advancedportals.core.entities.PortalLocation; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; /** diff --git a/src/main/java/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java b/src/main/java/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java index 6cf441ee..219a73e1 100644 --- a/src/main/java/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java +++ b/src/main/java/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java @@ -5,7 +5,8 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore; 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.data.PortalLocation; +import com.sekwah.advancedportals.core.entities.DataTag; +import com.sekwah.advancedportals.core.entities.PortalLocation; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; import java.util.ArrayList; diff --git a/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/CreateSubCommand.java b/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/CreateSubCommand.java index d8ab71a8..4f3ecdd2 100644 --- a/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/CreateSubCommand.java +++ b/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/CreateSubCommand.java @@ -1,7 +1,6 @@ package com.sekwah.advancedportals.core.commands.subcommands; -import com.sekwah.advancedportals.core.AdvancedPortalsCore; -import com.sekwah.advancedportals.core.api.portal.DataTag; +import com.sekwah.advancedportals.core.entities.DataTag; import java.util.ArrayList; diff --git a/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java b/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java index fdaa88ec..a76d9de5 100644 --- a/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java +++ b/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java @@ -3,7 +3,7 @@ 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.api.portal.DataTag; +import com.sekwah.advancedportals.core.entities.DataTag; import com.sekwah.advancedportals.core.api.portal.PortalException; import com.sekwah.advancedportals.core.commands.subcommands.CreateSubCommand; import com.sekwah.advancedportals.core.util.Lang; diff --git a/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java b/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java index 59136e64..96d8a89b 100644 --- a/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java +++ b/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java @@ -3,7 +3,7 @@ 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.api.portal.DataTag; +import com.sekwah.advancedportals.core.entities.DataTag; import com.sekwah.advancedportals.core.api.portal.PortalException; import com.sekwah.advancedportals.core.commands.subcommands.CreateSubCommand; import com.sekwah.advancedportals.core.util.Lang; diff --git a/src/main/java/com/sekwah/advancedportals/core/api/portal/DataTag.java b/src/main/java/com/sekwah/advancedportals/core/entities/DataTag.java similarity index 79% rename from src/main/java/com/sekwah/advancedportals/core/api/portal/DataTag.java rename to src/main/java/com/sekwah/advancedportals/core/entities/DataTag.java index 4f8e2dac..2b85bcdd 100644 --- a/src/main/java/com/sekwah/advancedportals/core/api/portal/DataTag.java +++ b/src/main/java/com/sekwah/advancedportals/core/entities/DataTag.java @@ -1,4 +1,4 @@ -package com.sekwah.advancedportals.core.api.portal; +package com.sekwah.advancedportals.core.entities; public class DataTag { diff --git a/src/main/java/com/sekwah/advancedportals/core/data/PlayerLocation.java b/src/main/java/com/sekwah/advancedportals/core/entities/PlayerLocation.java similarity index 95% rename from src/main/java/com/sekwah/advancedportals/core/data/PlayerLocation.java rename to src/main/java/com/sekwah/advancedportals/core/entities/PlayerLocation.java index dc2aac66..94222368 100644 --- a/src/main/java/com/sekwah/advancedportals/core/data/PlayerLocation.java +++ b/src/main/java/com/sekwah/advancedportals/core/entities/PlayerLocation.java @@ -1,4 +1,4 @@ -package com.sekwah.advancedportals.core.data; +package com.sekwah.advancedportals.core.entities; import com.google.gson.annotations.SerializedName; diff --git a/src/main/java/com/sekwah/advancedportals/core/data/PortalLocation.java b/src/main/java/com/sekwah/advancedportals/core/entities/PortalLocation.java similarity index 90% rename from src/main/java/com/sekwah/advancedportals/core/data/PortalLocation.java rename to src/main/java/com/sekwah/advancedportals/core/entities/PortalLocation.java index 2cca8698..d1caaf4b 100644 --- a/src/main/java/com/sekwah/advancedportals/core/data/PortalLocation.java +++ b/src/main/java/com/sekwah/advancedportals/core/entities/PortalLocation.java @@ -1,4 +1,4 @@ -package com.sekwah.advancedportals.core.data; +package com.sekwah.advancedportals.core.entities; import com.google.gson.annotations.SerializedName; diff --git a/src/main/java/com/sekwah/advancedportals/core/enums/EnumHandSelection.java b/src/main/java/com/sekwah/advancedportals/core/enums/EnumHandSelection.java new file mode 100644 index 00000000..1c96d2d9 --- /dev/null +++ b/src/main/java/com/sekwah/advancedportals/core/enums/EnumHandSelection.java @@ -0,0 +1,6 @@ +package com.sekwah.advancedportals.core.enums; + +public enum EnumHandSelection { + LEFTHAND, + RIGHTHAND +} diff --git a/src/main/java/com/sekwah/advancedportals/core/repository/DestinationRepository.java b/src/main/java/com/sekwah/advancedportals/core/repository/DestinationRepository.java new file mode 100644 index 00000000..32454409 --- /dev/null +++ b/src/main/java/com/sekwah/advancedportals/core/repository/DestinationRepository.java @@ -0,0 +1,12 @@ +package com.sekwah.advancedportals.core.repository; + +import com.google.common.collect.ImmutableMap; +import com.sekwah.advancedportals.core.api.destination.Destination; + +public interface DestinationRepository { + void create(String name, Destination destination); + + void delete(String name); + + ImmutableMap getDestinations(); +} diff --git a/src/main/java/com/sekwah/advancedportals/core/api/managers/DestinationManager.java b/src/main/java/com/sekwah/advancedportals/core/repository/DestinationRepositoryImpl.java similarity index 71% rename from src/main/java/com/sekwah/advancedportals/core/api/managers/DestinationManager.java rename to src/main/java/com/sekwah/advancedportals/core/repository/DestinationRepositoryImpl.java index 84550488..b976809d 100644 --- a/src/main/java/com/sekwah/advancedportals/core/api/managers/DestinationManager.java +++ b/src/main/java/com/sekwah/advancedportals/core/repository/DestinationRepositoryImpl.java @@ -1,33 +1,41 @@ -package com.sekwah.advancedportals.core.api.managers; +package com.sekwah.advancedportals.core.repository; +import com.google.common.collect.ImmutableMap; import com.google.gson.reflect.TypeToken; +import com.google.inject.Singleton; import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.api.destination.Destination; -import com.sekwah.advancedportals.core.api.portal.DataTag; +import com.sekwah.advancedportals.core.entities.DataTag; import com.sekwah.advancedportals.core.api.portal.PortalException; import com.sekwah.advancedportals.core.api.warphandler.TagHandler; -import com.sekwah.advancedportals.core.data.PlayerLocation; +import com.sekwah.advancedportals.core.entities.PlayerLocation; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; +import java.util.Map; -/** - * @author sekwah41 - */ -public class DestinationManager { +@Singleton +public class DestinationRepositoryImpl implements DestinationRepository { + private Map destiHashMap = new HashMap<>(); - private final AdvancedPortalsCore portalsCore; - /** - * Contains all the data for the destinations - */ - private HashMap destiHashMap = new HashMap<>(); - - public DestinationManager(AdvancedPortalsCore portalsCore) { - this.portalsCore = portalsCore; + @Override + public void create(String name, Destination destination) { + destiHashMap.put(name, destination); } + @Override + public void delete(String name) { + destiHashMap.remove(name); + } + + @Override + public ImmutableMap getDestinations() { + return ImmutableMap.copyOf(destiHashMap); + } + + public Destination createDesti(String name, PlayerContainer player, PlayerLocation playerLocation, ArrayList tags) throws PortalException { if(name == null || name.equals("")) { throw new PortalException("desti.error.noname"); diff --git a/src/main/java/com/sekwah/advancedportals/core/api/managers/PortalManager.java b/src/main/java/com/sekwah/advancedportals/core/repository/PortalManager.java similarity index 98% rename from src/main/java/com/sekwah/advancedportals/core/api/managers/PortalManager.java rename to src/main/java/com/sekwah/advancedportals/core/repository/PortalManager.java index 78e12447..6e03719f 100644 --- a/src/main/java/com/sekwah/advancedportals/core/api/managers/PortalManager.java +++ b/src/main/java/com/sekwah/advancedportals/core/repository/PortalManager.java @@ -3,11 +3,11 @@ package com.sekwah.advancedportals.core.api.managers; import com.google.gson.reflect.TypeToken; import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.api.portal.AdvancedPortal; -import com.sekwah.advancedportals.core.api.portal.DataTag; +import com.sekwah.advancedportals.core.entities.DataTag; import com.sekwah.advancedportals.core.api.portal.PortalException; import com.sekwah.advancedportals.core.api.warphandler.TagHandler; -import com.sekwah.advancedportals.core.data.PlayerLocation; -import com.sekwah.advancedportals.core.data.PortalLocation; +import com.sekwah.advancedportals.core.entities.PlayerLocation; +import com.sekwah.advancedportals.core.entities.PortalLocation; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; diff --git a/src/main/java/com/sekwah/advancedportals/core/repository/SelectionRepository.java b/src/main/java/com/sekwah/advancedportals/core/repository/SelectionRepository.java new file mode 100644 index 00000000..d31bafb1 --- /dev/null +++ b/src/main/java/com/sekwah/advancedportals/core/repository/SelectionRepository.java @@ -0,0 +1,18 @@ +package com.sekwah.advancedportals.core.repository; + +import com.sekwah.advancedportals.core.entities.PortalLocation; +import com.sekwah.advancedportals.core.enums.EnumHandSelection; + +import java.util.UUID; + +public interface SelectionRepository { + void addSelectedPortal(UUID selectedPlayer, String portal); + + void removeSelectedPortal(UUID uuid); + + void addSelectedHand(UUID uuid, EnumHandSelection enumHandSelection, PortalLocation portalLocation); + + void removeSelectedHand(UUID uuid, EnumHandSelection enumHandSelection); + + void removeAllSelectedHand(UUID uuid); +} diff --git a/src/main/java/com/sekwah/advancedportals/core/repository/SelectionRepositoryImpl.java b/src/main/java/com/sekwah/advancedportals/core/repository/SelectionRepositoryImpl.java new file mode 100644 index 00000000..950ffcf8 --- /dev/null +++ b/src/main/java/com/sekwah/advancedportals/core/repository/SelectionRepositoryImpl.java @@ -0,0 +1,53 @@ +package com.sekwah.advancedportals.core.repository; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheBuilderSpec; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Table; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.sekwah.advancedportals.core.entities.PortalLocation; +import com.sekwah.advancedportals.core.enums.EnumHandSelection; +import com.sun.media.jfxmedia.events.PlayerStateEvent; + +import java.util.HashMap; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +@Singleton +public class SelectionRepositoryImpl implements SelectionRepository { + Cache selectedPortal = CacheBuilder.newBuilder() + .concurrencyLevel(4) + .expireAfterAccess(30, TimeUnit.DAYS) + .build(); + + Table selectedHand = 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 addSelectedHand(UUID uuid, EnumHandSelection enumHandSelection, PortalLocation portalLocation) { + selectedHand.put(uuid, enumHandSelection, portalLocation); + } + + @Override + public void removeSelectedHand(UUID uuid, EnumHandSelection enumHandSelection) { + selectedHand.remove(uuid, enumHandSelection); + } + + @Override + public void removeAllSelectedHand(UUID uuid) { + selectedHand.remove(uuid, EnumHandSelection.LEFTHAND); + selectedHand.remove(uuid, EnumHandSelection.RIGHTHAND); + } +}