mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-25 12:06:17 +01:00
Changed connector to have an implementation interface
This commit is contained in:
parent
6d887c5b37
commit
fafc2d20d8
@ -18,8 +18,8 @@ import com.sekwah.advancedportals.core.data.DataStorage;
|
|||||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||||
import com.sekwah.advancedportals.core.util.Lang;
|
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.command.CommandRegister;
|
||||||
|
import com.sekwah.advancedportals.coreconnector.info.DataCollector;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ public class AdvancedPortalsCore {
|
|||||||
private final CommandRegister commandRegister;
|
private final CommandRegister commandRegister;
|
||||||
private final InfoLogger infoLogger;
|
private final InfoLogger infoLogger;
|
||||||
private final int mcMinorVer;
|
private final int mcMinorVer;
|
||||||
private final ConnectorDataCollector dataCollector;
|
private final DataCollector dataCollector;
|
||||||
|
|
||||||
private Injector injector = Guice.createInjector(new RepositoryModule(this));
|
private Injector injector = Guice.createInjector(new RepositoryModule(this));
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ public class AdvancedPortalsCore {
|
|||||||
* @param mcVer Minecraft version e.g. 1.12.2
|
* @param mcVer Minecraft version e.g. 1.12.2
|
||||||
*/
|
*/
|
||||||
public AdvancedPortalsCore(File dataStorageLoc, InfoLogger infoLogger, CommandRegister commandRegister,
|
public AdvancedPortalsCore(File dataStorageLoc, InfoLogger infoLogger, CommandRegister commandRegister,
|
||||||
ConnectorDataCollector dataCollector, int[] mcVer) {
|
DataCollector dataCollector, int[] mcVer) {
|
||||||
this.dataStorage = new DataStorage(dataStorageLoc);
|
this.dataStorage = new DataStorage(dataStorageLoc);
|
||||||
this.infoLogger = infoLogger;
|
this.infoLogger = infoLogger;
|
||||||
instance = this;
|
instance = this;
|
||||||
@ -69,6 +69,9 @@ public class AdvancedPortalsCore {
|
|||||||
this.dataCollector = dataCollector;
|
this.dataCollector = dataCollector;
|
||||||
this.mcMinorVer = this.checkMcVer(mcVer);
|
this.mcMinorVer = this.checkMcVer(mcVer);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("Core");
|
||||||
|
|
||||||
this.onEnable();
|
this.onEnable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +199,7 @@ public class AdvancedPortalsCore {
|
|||||||
return this.infoLogger;
|
return this.infoLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectorDataCollector getDataCollector() {
|
public DataCollector getDataCollector() {
|
||||||
return this.dataCollector;
|
return this.dataCollector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.sekwah.advancedportals.core.api.services;
|
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.destination.Destination;
|
||||||
import com.sekwah.advancedportals.core.entities.DataTag;
|
import com.sekwah.advancedportals.core.entities.DataTag;
|
||||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.sekwah.advancedportals.core.api.services;
|
package com.sekwah.advancedportals.core.api.services;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
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.AdvancedPortal;
|
||||||
import com.sekwah.advancedportals.core.entities.DataTag;
|
import com.sekwah.advancedportals.core.entities.DataTag;
|
||||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||||
|
@ -14,7 +14,6 @@ public class TagHandler {
|
|||||||
*
|
*
|
||||||
* @param player if null then created by the server or a plugin
|
* @param player if null then created by the server or a plugin
|
||||||
* @param argData
|
* @param argData
|
||||||
* @throws PortalException message given is the reason the portal (or destination) cannot be made
|
|
||||||
*/
|
*/
|
||||||
void created(T target, PlayerContainer player, String argData);
|
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 player if null then removed by the server or a plugin
|
||||||
* @param argData
|
* @param argData
|
||||||
* @throws PortalException message given is the reason the portal cant be removed
|
|
||||||
*/
|
*/
|
||||||
void destroyed(T target, PlayerContainer player, String argData);
|
void destroyed(T target, PlayerContainer player, String argData);
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ public class ReloadSubCommand implements SubCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||||
portalsCore.loadPortalConfig();
|
portalsCore.loadPortalConfig();
|
||||||
portalsCore.getPortalServices().loadPortals(portalsCore);
|
portalsCore.getPortalServices().loadPortals();
|
||||||
portalsCore.getDestinationServices().loadDestinations(portalsCore);
|
portalsCore.getDestinationServices().loadDestinations();
|
||||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.reload.reloaded"));
|
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.reload.reloaded"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ public class RepositoryModule extends AbstractModule {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
|
System.out.println("Configured");
|
||||||
bind(PortalRepository.class).to(PortalRepositoryImpl.class).in(Scopes.SINGLETON);
|
bind(PortalRepository.class).to(PortalRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||||
bind(DestinationRepository.class).to(DestinationRepositoryImpl.class).in(Scopes.SINGLETON);
|
bind(DestinationRepository.class).to(DestinationRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||||
bind(PortalTempDataRepository.class).to(PortalTempDataRepositoryImpl.class).in(Scopes.SINGLETON);
|
bind(PortalTempDataRepository.class).to(PortalTempDataRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||||
@ -24,6 +25,7 @@ public class RepositoryModule extends AbstractModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
AdvancedPortalsCore providePortalsCore() {
|
AdvancedPortalsCore providePortalsCore() {
|
||||||
|
System.out.println("TEST");
|
||||||
return this.portalsCore;
|
return this.portalsCore;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,14 @@
|
|||||||
package com.sekwah.advancedportals.coreconnector.command;
|
package com.sekwah.advancedportals.coreconnector.command;
|
||||||
|
|
||||||
|
|
||||||
import com.sekwah.advancedportals.core.commands.CommandTemplate;
|
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 {
|
protected final CommandTemplate commandExecutor;
|
||||||
|
|
||||||
private final CommandTemplate commandExecutor;
|
|
||||||
|
|
||||||
public CommandHandler(CommandTemplate commandExecutor) {
|
public CommandHandler(CommandTemplate commandExecutor) {
|
||||||
this.commandExecutor = 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<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
|
|
||||||
return this.commandExecutor.onTabComplete(new CommandSenderContainer(commandSender), args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,14 @@
|
|||||||
package com.sekwah.advancedportals.coreconnector.command;
|
package com.sekwah.advancedportals.coreconnector.command;
|
||||||
|
|
||||||
import com.sekwah.advancedportals.core.commands.CommandTemplate;
|
import com.sekwah.advancedportals.core.commands.CommandTemplate;
|
||||||
import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
|
|
||||||
|
|
||||||
/**
|
public interface CommandRegister {
|
||||||
* Register the CommandTemplate files to the appropriate system
|
|
||||||
*/
|
|
||||||
public class CommandRegister {
|
|
||||||
|
|
||||||
private final AdvancedPortalsPlugin plugin;
|
|
||||||
|
|
||||||
public CommandRegister(AdvancedPortalsPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the command to the appropriate system
|
* Registers the command to the appropriate system
|
||||||
* @param commandName
|
* @param commandName
|
||||||
* @param commandExecutor
|
* @param commandExecutor
|
||||||
*/
|
*/
|
||||||
public void registerCommand(String commandName, CommandTemplate commandExecutor) {
|
void registerCommand(String commandName, CommandTemplate commandExecutor);
|
||||||
this.plugin.getCommand(commandName).setExecutor(new CommandHandler(commandExecutor));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,16 @@
|
|||||||
package com.sekwah.advancedportals.coreconnector.container;
|
package com.sekwah.advancedportals.coreconnector.container;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
public interface CommandSenderContainer {
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class CommandSenderContainer {
|
void sendMessage(String message);
|
||||||
|
|
||||||
private final CommandSender sender;
|
boolean isOp();
|
||||||
|
|
||||||
public CommandSenderContainer(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
|
* @return null if there isnt a player e.g. the console
|
||||||
*/
|
*/
|
||||||
public PlayerContainer getPlayerContainer() {
|
PlayerContainer getPlayerContainer();
|
||||||
if (sender instanceof Player) {
|
|
||||||
return new PlayerContainer((Player) sender);
|
boolean hasPermission(String permission);
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasPermission(String permission) {
|
|
||||||
return sender.hasPermission(permission);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,60 +8,34 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Just a temporary container for whenever advanced portals needs to get data from a player
|
* 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) {
|
public void sendMessage(String message);
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getUUID() {
|
boolean isOp();
|
||||||
return player.getUniqueId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(String message) {
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOp() {
|
PlayerLocation getLoc();
|
||||||
return this.player.isOp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerLocation getLoc() {
|
double getEyeHeight();
|
||||||
Location loc = this.player.getLocation();
|
|
||||||
return new PlayerLocation(loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getEyeHeight() {
|
void teleport(PlayerLocation location);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void teleport(PlayerLocation location) {
|
boolean hasPermission(String permission);
|
||||||
this.player.teleport(new Location(Bukkit.getWorld(location.worldName), location.posX, location.posY, location.posZ));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasPermission(String permission) {
|
WorldContainer getWorld();
|
||||||
return this.player.hasPermission(permission);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WorldContainer getWorld() {
|
|
||||||
return new WorldContainer(this.player.getWorld());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param blockPos
|
* @param blockPos
|
||||||
* @param material
|
* @param material
|
||||||
*/
|
*/
|
||||||
public void sendFakeBlock(PortalLocation blockPos, String material) {
|
void sendFakeBlock(PortalLocation blockPos, String material);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only 1.12 and below supported
|
* Only 1.12 and below supported
|
||||||
@ -69,9 +43,9 @@ public class PlayerContainer {
|
|||||||
* @param material
|
* @param material
|
||||||
* @param data
|
* @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) {
|
public void giveItem(String material, String itemName, String... itemDescription) {
|
||||||
ItemStack regionselector = new ItemStack(Material.getMaterial(material));
|
ItemStack regionselector = new ItemStack(Material.getMaterial(material));
|
||||||
|
@ -7,33 +7,13 @@ import org.bukkit.block.BlockFace;
|
|||||||
import org.bukkit.material.Directional;
|
import org.bukkit.material.Directional;
|
||||||
import org.bukkit.material.MaterialData;
|
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) {
|
void setBlockData(PortalLocation location, byte data);
|
||||||
this.world = world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBlock(PortalLocation location, String material) {
|
String getBlock(PortalLocation location);
|
||||||
this.world.getBlockAt(location.posX, location.posY, location.posZ).setType(Material.getMaterial(material));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBlockData(PortalLocation location, byte data) {
|
byte getBlockData(PortalLocation location);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.sekwah.advancedportals.coreconnector.info;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets info from the specific implementation
|
||||||
|
*/
|
||||||
|
public interface DataCollector {
|
||||||
|
|
||||||
|
boolean materialExists(String materialName);
|
||||||
|
|
||||||
|
}
|
@ -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<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
|
||||||
|
return this.commandExecutor.onTabComplete(new SpigotCommandSenderContainer(commandSender), args);
|
||||||
|
}
|
||||||
|
}
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
/**
|
public class SpigotDataCollector implements DataCollector {
|
||||||
* Gets info from the specific implementation
|
|
||||||
*/
|
|
||||||
public class ConnectorDataCollector {
|
|
||||||
public boolean materialExists(String materialName) {
|
public boolean materialExists(String materialName) {
|
||||||
String sameCase = materialName.toUpperCase();
|
String sameCase = materialName.toUpperCase();
|
||||||
return Material.getMaterial(sameCase) != null;
|
return Material.getMaterial(sameCase) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -35,7 +35,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
|
|||||||
versionInts[i] = Integer.parseInt(versionNums[i]);
|
versionInts[i] = Integer.parseInt(versionNums[i]);
|
||||||
}
|
}
|
||||||
this.portalsCore = new AdvancedPortalsCore(this.getDataFolder(),
|
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 {
|
else {
|
||||||
this.getLogger().warning("Could not parse mc version from: " + Bukkit.getVersion());
|
this.getLogger().warning("Could not parse mc version from: " + Bukkit.getVersion());
|
||||||
|
@ -20,19 +20,19 @@ public class Listeners implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoinEvent(PlayerJoinEvent event) {
|
public void onJoinEvent(PlayerJoinEvent event) {
|
||||||
coreListeners.playerJoin(new PlayerContainer(event.getPlayer()));
|
coreListeners.playerJoin(new SpigotPlayerContainer(event.getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoinEvent(PlayerQuitEvent event) {
|
public void onJoinEvent(PlayerQuitEvent event) {
|
||||||
coreListeners.playerLeave(new PlayerContainer(event.getPlayer()));
|
coreListeners.playerLeave(new SpigotPlayerContainer(event.getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
Location blockloc = event.getBlock().getLocation();
|
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(),
|
new PortalLocation(blockloc.getWorld().getName(), blockloc.getBlockX(), blockloc.getBlockY(), blockloc.getBlockZ()), event.getBlockPlaced().getType().toString(),
|
||||||
event.getItemInHand().getType().toString(), event.getItemInHand().getItemMeta().getDisplayName());
|
event.getItemInHand().getType().toString(), event.getItemInHand().getItemMeta().getDisplayName());
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ public class Listeners implements Listener {
|
|||||||
public void onItemInteract(PlayerInteractEvent event) {
|
public void onItemInteract(PlayerInteractEvent event) {
|
||||||
if (!event.isCancelled() && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) && event.getItem() != null) {
|
if (!event.isCancelled() && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) && event.getItem() != null) {
|
||||||
Location blockloc = event.getClickedBlock().getLocation();
|
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(),
|
event.getItem().getItemMeta().getDisplayName(),
|
||||||
new PortalLocation(blockloc.getWorld().getName(), blockloc.getBlockX(), blockloc.getBlockY(), blockloc.getBlockZ()),
|
new PortalLocation(blockloc.getWorld().getName(), blockloc.getBlockX(), blockloc.getBlockY(), blockloc.getBlockZ()),
|
||||||
event.getAction() == Action.LEFT_CLICK_BLOCK);
|
event.getAction() == Action.LEFT_CLICK_BLOCK);
|
||||||
|
Loading…
Reference in New Issue
Block a user