From fafc2d20d8669de6dae62a2e59d9ff791fc9348a Mon Sep 17 00:00:00 2001 From: Sekwah Date: Thu, 5 Jul 2018 03:17:17 +0100 Subject: [PATCH] Changed connector to have an implementation interface --- .../core/AdvancedPortalsCore.java | 11 +- .../api/services/DestinationServices.java | 1 - .../core/api/services/PortalServices.java | 1 - .../core/api/warphandler/TagHandler.java | 2 - .../subcommands/portal/ReloadSubCommand.java | 4 +- .../core/config/RepositoryModule.java | 2 + .../coreconnector/command/CommandHandler.java | 22 +--- .../command/CommandRegister.java | 17 +-- .../container/CommandSenderContainer.java | 31 +----- .../container/PlayerContainer.java | 50 ++------- .../container/WorldContainer.java | 30 +---- .../coreconnector/info/DataCollector.java | 10 ++ .../spigot/command/SpigotCommandHandler.java | 29 +++++ .../spigot/command/SpigotCommandRegister.java | 26 +++++ .../SpigotCommandSenderContainer.java | 36 ++++++ .../container/SpigotPlayerContainer.java | 103 ++++++++++++++++++ .../container/SpigotWorldContainer.java | 40 +++++++ .../info/SpigotDataCollector.java} | 10 +- .../spigot/AdvancedPortalsPlugin.java | 2 +- .../advancedportals/spigot/Listeners.java | 8 +- 20 files changed, 293 insertions(+), 142 deletions(-) create mode 100644 src/main/java/com/sekwah/advancedportals/coreconnector/info/DataCollector.java create mode 100644 src/main/java/com/sekwah/advancedportals/coreconnector/spigot/command/SpigotCommandHandler.java create mode 100644 src/main/java/com/sekwah/advancedportals/coreconnector/spigot/command/SpigotCommandRegister.java create mode 100644 src/main/java/com/sekwah/advancedportals/coreconnector/spigot/container/SpigotCommandSenderContainer.java create mode 100644 src/main/java/com/sekwah/advancedportals/coreconnector/spigot/container/SpigotPlayerContainer.java create mode 100644 src/main/java/com/sekwah/advancedportals/coreconnector/spigot/container/SpigotWorldContainer.java rename src/main/java/com/sekwah/advancedportals/coreconnector/{ConnectorDataCollector.java => spigot/info/SpigotDataCollector.java} (51%) diff --git a/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index a8ec71d3..ddc74c7f 100644 --- a/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -18,8 +18,8 @@ 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; import com.sekwah.advancedportals.coreconnector.command.CommandRegister; +import com.sekwah.advancedportals.coreconnector.info.DataCollector; import java.io.File; @@ -30,7 +30,7 @@ public class AdvancedPortalsCore { private final CommandRegister commandRegister; private final InfoLogger infoLogger; private final int mcMinorVer; - private final ConnectorDataCollector dataCollector; + private final DataCollector dataCollector; private Injector injector = Guice.createInjector(new RepositoryModule(this)); @@ -61,7 +61,7 @@ public class AdvancedPortalsCore { * @param mcVer Minecraft version e.g. 1.12.2 */ public AdvancedPortalsCore(File dataStorageLoc, InfoLogger infoLogger, CommandRegister commandRegister, - ConnectorDataCollector dataCollector, int[] mcVer) { + DataCollector dataCollector, int[] mcVer) { this.dataStorage = new DataStorage(dataStorageLoc); this.infoLogger = infoLogger; instance = this; @@ -69,6 +69,9 @@ public class AdvancedPortalsCore { this.dataCollector = dataCollector; this.mcMinorVer = this.checkMcVer(mcVer); + + System.out.println("Core"); + this.onEnable(); } @@ -196,7 +199,7 @@ public class AdvancedPortalsCore { return this.infoLogger; } - public ConnectorDataCollector getDataCollector() { + public DataCollector getDataCollector() { return this.dataCollector; } diff --git a/src/main/java/com/sekwah/advancedportals/core/api/services/DestinationServices.java b/src/main/java/com/sekwah/advancedportals/core/api/services/DestinationServices.java index dc23dbfb..92111fed 100644 --- a/src/main/java/com/sekwah/advancedportals/core/api/services/DestinationServices.java +++ b/src/main/java/com/sekwah/advancedportals/core/api/services/DestinationServices.java @@ -1,6 +1,5 @@ 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.entities.DataTag; import com.sekwah.advancedportals.core.entities.PlayerLocation; diff --git a/src/main/java/com/sekwah/advancedportals/core/api/services/PortalServices.java b/src/main/java/com/sekwah/advancedportals/core/api/services/PortalServices.java index f036d39b..125324f9 100644 --- a/src/main/java/com/sekwah/advancedportals/core/api/services/PortalServices.java +++ b/src/main/java/com/sekwah/advancedportals/core/api/services/PortalServices.java @@ -1,7 +1,6 @@ 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.entities.DataTag; import com.sekwah.advancedportals.core.entities.PlayerLocation; diff --git a/src/main/java/com/sekwah/advancedportals/core/api/warphandler/TagHandler.java b/src/main/java/com/sekwah/advancedportals/core/api/warphandler/TagHandler.java index 2f69bd8d..60584393 100644 --- a/src/main/java/com/sekwah/advancedportals/core/api/warphandler/TagHandler.java +++ b/src/main/java/com/sekwah/advancedportals/core/api/warphandler/TagHandler.java @@ -14,7 +14,6 @@ public class TagHandler { * * @param player if null then created by the server or a plugin * @param argData - * @throws PortalException message given is the reason the portal (or destination) cannot be made */ void created(T target, PlayerContainer player, String argData); @@ -23,7 +22,6 @@ public class TagHandler { * * @param player if null then removed by the server or a plugin * @param argData - * @throws PortalException message given is the reason the portal cant be removed */ void destroyed(T target, PlayerContainer player, String argData); diff --git a/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java b/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java index 5233abd3..ca9df45d 100644 --- a/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java +++ b/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java @@ -16,8 +16,8 @@ public class ReloadSubCommand implements SubCommand { @Override public void onCommand(CommandSenderContainer sender, String[] args) { portalsCore.loadPortalConfig(); - portalsCore.getPortalServices().loadPortals(portalsCore); - portalsCore.getDestinationServices().loadDestinations(portalsCore); + portalsCore.getPortalServices().loadPortals(); + portalsCore.getDestinationServices().loadDestinations(); sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.reload.reloaded")); } diff --git a/src/main/java/com/sekwah/advancedportals/core/config/RepositoryModule.java b/src/main/java/com/sekwah/advancedportals/core/config/RepositoryModule.java index 9f25644f..6d127241 100644 --- a/src/main/java/com/sekwah/advancedportals/core/config/RepositoryModule.java +++ b/src/main/java/com/sekwah/advancedportals/core/config/RepositoryModule.java @@ -16,6 +16,7 @@ public class RepositoryModule extends AbstractModule { @Override protected void configure() { + System.out.println("Configured"); 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); @@ -24,6 +25,7 @@ public class RepositoryModule extends AbstractModule { @Provides AdvancedPortalsCore providePortalsCore() { + System.out.println("TEST"); return this.portalsCore; } } diff --git a/src/main/java/com/sekwah/advancedportals/coreconnector/command/CommandHandler.java b/src/main/java/com/sekwah/advancedportals/coreconnector/command/CommandHandler.java index 6b70aff5..42a0fbc4 100644 --- a/src/main/java/com/sekwah/advancedportals/coreconnector/command/CommandHandler.java +++ b/src/main/java/com/sekwah/advancedportals/coreconnector/command/CommandHandler.java @@ -1,30 +1,14 @@ package com.sekwah.advancedportals.coreconnector.command; + import com.sekwah.advancedportals.core.commands.CommandTemplate; -import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import java.util.List; +public abstract class CommandHandler { -public class CommandHandler implements CommandExecutor, TabCompleter { - - private final CommandTemplate commandExecutor; + protected final CommandTemplate commandExecutor; public CommandHandler(CommandTemplate commandExecutor) { this.commandExecutor = commandExecutor; } - @Override - public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { - this.commandExecutor.onCommand(new CommandSenderContainer(commandSender), command.getName(), args); - return true; - } - - @Override - public List onTabComplete(CommandSender commandSender, Command command, String s, String[] args) { - return this.commandExecutor.onTabComplete(new CommandSenderContainer(commandSender), args); - } } diff --git a/src/main/java/com/sekwah/advancedportals/coreconnector/command/CommandRegister.java b/src/main/java/com/sekwah/advancedportals/coreconnector/command/CommandRegister.java index e304f16f..683f34d7 100644 --- a/src/main/java/com/sekwah/advancedportals/coreconnector/command/CommandRegister.java +++ b/src/main/java/com/sekwah/advancedportals/coreconnector/command/CommandRegister.java @@ -1,25 +1,14 @@ package com.sekwah.advancedportals.coreconnector.command; import com.sekwah.advancedportals.core.commands.CommandTemplate; -import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin; -/** - * Register the CommandTemplate files to the appropriate system - */ -public class CommandRegister { - - private final AdvancedPortalsPlugin plugin; - - public CommandRegister(AdvancedPortalsPlugin plugin) { - this.plugin = plugin; - } +public interface CommandRegister { /** * Registers the command to the appropriate system * @param commandName * @param commandExecutor */ - public void registerCommand(String commandName, CommandTemplate commandExecutor) { - this.plugin.getCommand(commandName).setExecutor(new CommandHandler(commandExecutor)); - } + void registerCommand(String commandName, CommandTemplate commandExecutor); + } diff --git a/src/main/java/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java b/src/main/java/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java index c7f1269d..267744b0 100644 --- a/src/main/java/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java +++ b/src/main/java/com/sekwah/advancedportals/coreconnector/container/CommandSenderContainer.java @@ -1,35 +1,16 @@ package com.sekwah.advancedportals.coreconnector.container; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +public interface CommandSenderContainer { -public class CommandSenderContainer { + void sendMessage(String message); - private final CommandSender sender; - - public CommandSenderContainer(CommandSender commandSender) { - this.sender = commandSender; - } - - public void sendMessage(String message) { - sender.sendMessage(message); - } - - public boolean isOp() { - return sender.isOp(); - } + boolean isOp(); /** * @return null if there isnt a player e.g. the console */ - public PlayerContainer getPlayerContainer() { - if (sender instanceof Player) { - return new PlayerContainer((Player) sender); - } - return null; - } + PlayerContainer getPlayerContainer(); + + boolean hasPermission(String permission); - public boolean hasPermission(String permission) { - return sender.hasPermission(permission); - } } diff --git a/src/main/java/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java b/src/main/java/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java index 2f1da002..ada63fe1 100644 --- a/src/main/java/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java +++ b/src/main/java/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java @@ -8,60 +8,34 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.Arrays; import java.util.UUID; /** * Just a temporary container for whenever advanced portals needs to get data from a player */ -public class PlayerContainer { +public interface PlayerContainer { - private final Player player; + UUID getUUID(); - public PlayerContainer(Player player) { - this.player = player; - } + public void sendMessage(String message); - public UUID getUUID() { - return player.getUniqueId(); - } - - public void sendMessage(String message) { - player.sendMessage(message); - } + boolean isOp(); - public boolean isOp() { - return this.player.isOp(); - } + PlayerLocation getLoc(); - public PlayerLocation getLoc() { - Location loc = this.player.getLocation(); - return new PlayerLocation(loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ()); - } + double getEyeHeight(); - public double getEyeHeight() { - return 0; - } + void teleport(PlayerLocation location); - public void teleport(PlayerLocation location) { - this.player.teleport(new Location(Bukkit.getWorld(location.worldName), location.posX, location.posY, location.posZ)); - } + boolean hasPermission(String permission); - public boolean hasPermission(String permission) { - return this.player.hasPermission(permission); - } - - public WorldContainer getWorld() { - return new WorldContainer(this.player.getWorld()); - } + WorldContainer getWorld(); /** * @param blockPos * @param material */ - public void sendFakeBlock(PortalLocation blockPos, String material) { - - } + void sendFakeBlock(PortalLocation blockPos, String material); /** * Only 1.12 and below supported @@ -69,9 +43,9 @@ public class PlayerContainer { * @param material * @param data */ - public void sendFakeBlockWithData(PortalLocation blockPos, String material, byte data) { + void sendFakeBlockWithData(PortalLocation blockPos, String material, byte data); - } + void giveWool(String dyeColor, String itemName, String... itemDescription); public void giveItem(String material, String itemName, String... itemDescription) { ItemStack regionselector = new ItemStack(Material.getMaterial(material)); diff --git a/src/main/java/com/sekwah/advancedportals/coreconnector/container/WorldContainer.java b/src/main/java/com/sekwah/advancedportals/coreconnector/container/WorldContainer.java index 02aaee42..fd7ec8e0 100644 --- a/src/main/java/com/sekwah/advancedportals/coreconnector/container/WorldContainer.java +++ b/src/main/java/com/sekwah/advancedportals/coreconnector/container/WorldContainer.java @@ -7,33 +7,13 @@ import org.bukkit.block.BlockFace; import org.bukkit.material.Directional; import org.bukkit.material.MaterialData; -public class WorldContainer { +public interface WorldContainer { - private final World world; + void setBlock(PortalLocation location, String material); - public WorldContainer(World world) { - this.world = world; - } + void setBlockData(PortalLocation location, byte data); - public void setBlock(PortalLocation location, String material) { - this.world.getBlockAt(location.posX, location.posY, location.posZ).setType(Material.getMaterial(material)); - } + String getBlock(PortalLocation location); - public void setBlockData(PortalLocation location, byte data) { - MaterialData matData = world.getBlockAt(location.posX, location.posY, location.posZ).getState().getData(); - if(matData instanceof Directional) { - System.out.println("IS DIRECTIONAL"); - Directional dir = (Directional) world.getBlockAt(location.posX, location.posY, location.posZ).getState().getData(); - dir.setFacingDirection(BlockFace.NORTH); - } - - } - - public String getBlock(PortalLocation location) { - return this.world.getBlockAt(location.posX, location.posY, location.posZ).getType().toString(); - } - - public byte getBlockData(PortalLocation location) { - return 0; - } + byte getBlockData(PortalLocation location); } diff --git a/src/main/java/com/sekwah/advancedportals/coreconnector/info/DataCollector.java b/src/main/java/com/sekwah/advancedportals/coreconnector/info/DataCollector.java new file mode 100644 index 00000000..fa36dba5 --- /dev/null +++ b/src/main/java/com/sekwah/advancedportals/coreconnector/info/DataCollector.java @@ -0,0 +1,10 @@ +package com.sekwah.advancedportals.coreconnector.info; + +/** + * Gets info from the specific implementation + */ +public interface DataCollector { + + boolean materialExists(String materialName); + +} diff --git a/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/command/SpigotCommandHandler.java b/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/command/SpigotCommandHandler.java new file mode 100644 index 00000000..bdba6695 --- /dev/null +++ b/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/command/SpigotCommandHandler.java @@ -0,0 +1,29 @@ +package com.sekwah.advancedportals.coreconnector.spigot.command; + +import com.sekwah.advancedportals.core.commands.CommandTemplate; +import com.sekwah.advancedportals.coreconnector.command.CommandHandler; +import com.sekwah.advancedportals.coreconnector.spigot.container.SpigotCommandSenderContainer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import java.util.List; + +public class SpigotCommandHandler extends CommandHandler implements CommandExecutor, TabCompleter { + + public SpigotCommandHandler(CommandTemplate commandExecutor) { + super(commandExecutor); + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + this.commandExecutor.onCommand(new SpigotCommandSenderContainer(commandSender), command.getName(), args); + return true; + } + + @Override + public List onTabComplete(CommandSender commandSender, Command command, String s, String[] args) { + return this.commandExecutor.onTabComplete(new SpigotCommandSenderContainer(commandSender), args); + } +} diff --git a/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/command/SpigotCommandRegister.java b/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/command/SpigotCommandRegister.java new file mode 100644 index 00000000..06b8d029 --- /dev/null +++ b/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/command/SpigotCommandRegister.java @@ -0,0 +1,26 @@ +package com.sekwah.advancedportals.coreconnector.spigot.command; + +import com.sekwah.advancedportals.core.commands.CommandTemplate; +import com.sekwah.advancedportals.coreconnector.command.CommandRegister; +import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin; + +/** + * Register the CommandTemplate files to the appropriate system + */ +public class SpigotCommandRegister implements CommandRegister { + + private final AdvancedPortalsPlugin plugin; + + public SpigotCommandRegister(AdvancedPortalsPlugin plugin) { + this.plugin = plugin; + } + + /** + * Registers the command to the appropriate system + * @param commandName + * @param commandExecutor + */ + public void registerCommand(String commandName, CommandTemplate commandExecutor) { + this.plugin.getCommand(commandName).setExecutor(new SpigotCommandHandler(commandExecutor)); + } +} diff --git a/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/container/SpigotCommandSenderContainer.java b/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/container/SpigotCommandSenderContainer.java new file mode 100644 index 00000000..8e643f73 --- /dev/null +++ b/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/container/SpigotCommandSenderContainer.java @@ -0,0 +1,36 @@ +package com.sekwah.advancedportals.coreconnector.spigot.container; + +import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class SpigotCommandSenderContainer implements CommandSenderContainer { + + private final CommandSender sender; + + public SpigotCommandSenderContainer(CommandSender commandSender) { + this.sender = commandSender; + } + + public void sendMessage(String message) { + sender.sendMessage(message); + } + + public boolean isOp() { + return sender.isOp(); + } + + /** + * @return null if there isnt a player e.g. the console + */ + public SpigotPlayerContainer getPlayerContainer() { + if (sender instanceof Player) { + return new SpigotPlayerContainer((Player) sender); + } + return null; + } + + public boolean hasPermission(String permission) { + return sender.hasPermission(permission); + } +} diff --git a/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/container/SpigotPlayerContainer.java b/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/container/SpigotPlayerContainer.java new file mode 100644 index 00000000..0d76d27f --- /dev/null +++ b/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/container/SpigotPlayerContainer.java @@ -0,0 +1,103 @@ +package com.sekwah.advancedportals.coreconnector.spigot.container; + +import com.google.inject.Inject; +import com.sekwah.advancedportals.core.AdvancedPortalsCore; +import com.sekwah.advancedportals.core.entities.PlayerLocation; +import com.sekwah.advancedportals.core.entities.PortalLocation; +import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; +import com.sekwah.advancedportals.coreconnector.container.WorldContainer; +import org.bukkit.Bukkit; +import org.bukkit.DyeColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.material.Wool; + +import java.util.Arrays; +import java.util.UUID; + +/** + * Just a temporary container for whenever advanced portals needs to get data from a player + */ +public class SpigotPlayerContainer implements PlayerContainer { + + @Inject + private AdvancedPortalsCore portalsCore; + + private final Player player; + + public SpigotPlayerContainer(Player player) { + this.player = player; + } + + public UUID getUUID() { + return player.getUniqueId(); + } + + public void sendMessage(String message) { + player.sendMessage(message); + } + + public boolean isOp() { + return this.player.isOp(); + } + + public PlayerLocation getLoc() { + Location loc = this.player.getLocation(); + return new PlayerLocation(loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ()); + } + + public double getEyeHeight() { + return 0; + } + + public void teleport(PlayerLocation location) { + this.player.teleport(new Location(Bukkit.getWorld(location.worldName), location.posX, location.posY, location.posZ)); + } + + public boolean hasPermission(String permission) { + return this.player.hasPermission(permission); + } + + public WorldContainer getWorld() { + return new SpigotWorldContainer(this.player.getWorld()); + } + + /** + * @param blockPos + * @param material + */ + public void sendFakeBlock(PortalLocation blockPos, String material) { + + } + + /** + * Only 1.12 and below supported + * @param blockPos + * @param material + * @param data + */ + public void sendFakeBlockWithData(PortalLocation blockPos, String material, byte data) { + + } + + public void giveWool(String dyeColor, String itemName, String... itemDescription) { + ItemStack regionselector = new Wool(DyeColor.valueOf(dyeColor)).toItemStack(1); + ItemMeta selectorname = regionselector.getItemMeta(); + selectorname.setDisplayName(itemName); + selectorname.setLore(Arrays.asList(itemDescription)); + regionselector.setItemMeta(selectorname); + this.player.getInventory().addItem(regionselector); + } + + public void giveItem(String material, String itemName, String... itemDescription) { + ItemStack regionselector = new ItemStack(Material.getMaterial(material)); + ItemMeta selectorname = regionselector.getItemMeta(); + selectorname.setDisplayName(itemName); + selectorname.setLore(Arrays.asList(itemDescription)); + regionselector.setItemMeta(selectorname); + this.player.getInventory().addItem(regionselector); + } +} diff --git a/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/container/SpigotWorldContainer.java b/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/container/SpigotWorldContainer.java new file mode 100644 index 00000000..5e686853 --- /dev/null +++ b/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/container/SpigotWorldContainer.java @@ -0,0 +1,40 @@ +package com.sekwah.advancedportals.coreconnector.spigot.container; + +import com.sekwah.advancedportals.core.entities.PortalLocation; +import com.sekwah.advancedportals.coreconnector.container.WorldContainer; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.BlockFace; +import org.bukkit.material.Directional; +import org.bukkit.material.MaterialData; + +public class SpigotWorldContainer implements WorldContainer { + + private final World world; + + public SpigotWorldContainer(World world) { + this.world = world; + } + + public void setBlock(PortalLocation location, String material) { + this.world.getBlockAt(location.posX, location.posY, location.posZ).setType(Material.getMaterial(material)); + } + + public void setBlockData(PortalLocation location, byte data) { + MaterialData matData = world.getBlockAt(location.posX, location.posY, location.posZ).getState().getData(); + if(matData instanceof Directional) { + System.out.println("IS DIRECTIONAL"); + Directional dir = (Directional) world.getBlockAt(location.posX, location.posY, location.posZ).getState().getData(); + dir.setFacingDirection(BlockFace.NORTH); + } + + } + + public String getBlock(PortalLocation location) { + return this.world.getBlockAt(location.posX, location.posY, location.posZ).getType().toString(); + } + + public byte getBlockData(PortalLocation location) { + return 0; + } +} diff --git a/src/main/java/com/sekwah/advancedportals/coreconnector/ConnectorDataCollector.java b/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/info/SpigotDataCollector.java similarity index 51% rename from src/main/java/com/sekwah/advancedportals/coreconnector/ConnectorDataCollector.java rename to src/main/java/com/sekwah/advancedportals/coreconnector/spigot/info/SpigotDataCollector.java index e978454b..d4b4165d 100644 --- a/src/main/java/com/sekwah/advancedportals/coreconnector/ConnectorDataCollector.java +++ b/src/main/java/com/sekwah/advancedportals/coreconnector/spigot/info/SpigotDataCollector.java @@ -1,14 +1,12 @@ -package com.sekwah.advancedportals.coreconnector; +package com.sekwah.advancedportals.coreconnector.spigot.info; +import com.sekwah.advancedportals.coreconnector.info.DataCollector; import org.bukkit.Material; -/** - * Gets info from the specific implementation - */ -public class ConnectorDataCollector { +public class SpigotDataCollector implements DataCollector { + public boolean materialExists(String materialName) { String sameCase = materialName.toUpperCase(); return Material.getMaterial(sameCase) != null; } - } diff --git a/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java b/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java index a320420f..80941ef8 100644 --- a/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java +++ b/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java @@ -35,7 +35,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin { versionInts[i] = Integer.parseInt(versionNums[i]); } this.portalsCore = new AdvancedPortalsCore(this.getDataFolder(), - new SpigotInfoLogger(this), new CommandRegister(this), new ConnectorDataCollector(), versionInts); + new SpigotInfoLogger(this), new SpigotCommandRegister(this), new SpigotDataCollector(), versionInts); } else { this.getLogger().warning("Could not parse mc version from: " + Bukkit.getVersion()); diff --git a/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java b/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java index f93774e8..705ae50b 100644 --- a/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java +++ b/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java @@ -20,19 +20,19 @@ public class Listeners implements Listener { @EventHandler public void onJoinEvent(PlayerJoinEvent event) { - coreListeners.playerJoin(new PlayerContainer(event.getPlayer())); + coreListeners.playerJoin(new SpigotPlayerContainer(event.getPlayer())); } @EventHandler public void onJoinEvent(PlayerQuitEvent event) { - coreListeners.playerLeave(new PlayerContainer(event.getPlayer())); + coreListeners.playerLeave(new SpigotPlayerContainer(event.getPlayer())); } @EventHandler(priority = EventPriority.HIGH) public void onBlockPlace(BlockPlaceEvent event) { if (!event.isCancelled()) { Location blockloc = event.getBlock().getLocation(); - this.coreListeners.blockPlace(new PlayerContainer(event.getPlayer()), + this.coreListeners.blockPlace(new SpigotPlayerContainer(event.getPlayer()), new PortalLocation(blockloc.getWorld().getName(), blockloc.getBlockX(), blockloc.getBlockY(), blockloc.getBlockZ()), event.getBlockPlaced().getType().toString(), event.getItemInHand().getType().toString(), event.getItemInHand().getItemMeta().getDisplayName()); } @@ -42,7 +42,7 @@ public class Listeners implements Listener { public void onItemInteract(PlayerInteractEvent event) { if (!event.isCancelled() && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) && event.getItem() != null) { Location blockloc = event.getClickedBlock().getLocation(); - boolean allowEvent = this.coreListeners.playerInteractWithBlock(new PlayerContainer(event.getPlayer()), event.getMaterial().toString(), + boolean allowEvent = this.coreListeners.playerInteractWithBlock(new SpigotPlayerContainer(event.getPlayer()), event.getMaterial().toString(), event.getItem().getItemMeta().getDisplayName(), new PortalLocation(blockloc.getWorld().getName(), blockloc.getBlockX(), blockloc.getBlockY(), blockloc.getBlockZ()), event.getAction() == Action.LEFT_CLICK_BLOCK);