Search in sources :

Example 1 with ClientPluginManager

use of io.xol.chunkstories.api.plugin.ClientPluginManager in project chunkstories by Hugobros3.

the class Lwjgl3ClientInputsManager method onInputPressed.

public boolean onInputPressed(Input input) {
    if (input.equals("fullscreen")) {
        gameWindow.toggleFullscreen();
        return true;
    }
    // System.out.println("Input pressed "+input.getName());
    // Try the client-side event press
    ClientInputPressedEvent event = new ClientInputPressedEvent(gameWindow.getClient(), input);
    ClientPluginManager cpm = gameWindow.getClient().getPluginManager();
    if (cpm != null) {
        cpm.fireEvent(event);
        if (event.isCancelled())
            return false;
    }
    // Try the GUI handling
    Layer layer = gameWindow.getLayer();
    if (layer.handleInput(input))
        return true;
    // System.out.println("wasn't handled");
    final LocalPlayer player = Client.getInstance().getPlayer();
    if (player == null)
        return false;
    final EntityControllable entityControlled = player.getControlledEntity();
    // There has to be a controlled entity for sending inputs to make sense.
    if (entityControlled == null)
        return false;
    // Send input to server
    World world = entityControlled.getWorld();
    if (world instanceof WorldClientRemote) {
        // MouseScroll inputs are strictly client-side
        if (!(input instanceof MouseScroll)) {
            ServerConnection connection = ((WorldClientRemote) entityControlled.getWorld()).getConnection();
            PacketInput packet = new PacketInput(world);
            packet.input = input;
            packet.isPressed = true;
            connection.pushPacket(packet);
        }
        return entityControlled.onControllerInput(input, Client.getInstance().getPlayer());
    } else {
        PlayerInputPressedEvent event2 = new PlayerInputPressedEvent(Client.getInstance().getPlayer(), input);
        cpm.fireEvent(event2);
        if (event2.isCancelled())
            return false;
    // entity.handleInteraction(input, entity.getControllerComponent().getController());
    }
    // Handle interaction locally
    return entityControlled.onControllerInput(input, Client.getInstance().getPlayer());
}
Also used : ClientPluginManager(io.xol.chunkstories.api.plugin.ClientPluginManager) PacketInput(io.xol.chunkstories.net.packets.PacketInput) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) ServerConnection(io.xol.chunkstories.client.net.ServerConnection) ClientInputPressedEvent(io.xol.chunkstories.api.events.client.ClientInputPressedEvent) World(io.xol.chunkstories.api.world.World) Layer(io.xol.chunkstories.api.gui.Layer) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) MouseScroll(io.xol.chunkstories.api.input.Mouse.MouseScroll) PlayerInputPressedEvent(io.xol.chunkstories.api.events.player.PlayerInputPressedEvent)

Example 2 with ClientPluginManager

use of io.xol.chunkstories.api.plugin.ClientPluginManager in project chunkstories by Hugobros3.

the class Lwjgl3ClientInputsManager method onInputReleased.

@Override
public boolean onInputReleased(Input input) {
    ClientInputReleasedEvent event = new ClientInputReleasedEvent(gameWindow.getClient(), input);
    ClientPluginManager cpm = gameWindow.getClient().getPluginManager();
    if (cpm != null) {
        cpm.fireEvent(event);
    }
    final LocalPlayer player = Client.getInstance().getPlayer();
    if (player == null)
        return false;
    final EntityControllable entityControlled = player.getControlledEntity();
    // There has to be a controlled entity for sending inputs to make sense.
    if (entityControlled == null)
        return false;
    // Send input to server
    World world = entityControlled.getWorld();
    if (world instanceof WorldClientRemote) {
        ServerConnection connection = ((WorldClientRemote) entityControlled.getWorld()).getConnection();
        PacketInput packet = new PacketInput(world);
        packet.input = input;
        packet.isPressed = false;
        connection.pushPacket(packet);
        return true;
    } else {
        PlayerInputReleasedEvent event2 = new PlayerInputReleasedEvent(Client.getInstance().getPlayer(), input);
        cpm.fireEvent(event2);
        return true;
    }
}
Also used : ClientPluginManager(io.xol.chunkstories.api.plugin.ClientPluginManager) PacketInput(io.xol.chunkstories.net.packets.PacketInput) ClientInputReleasedEvent(io.xol.chunkstories.api.events.client.ClientInputReleasedEvent) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) ServerConnection(io.xol.chunkstories.client.net.ServerConnection) PlayerInputReleasedEvent(io.xol.chunkstories.api.events.player.PlayerInputReleasedEvent) World(io.xol.chunkstories.api.world.World) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable)

Example 3 with ClientPluginManager

use of io.xol.chunkstories.api.plugin.ClientPluginManager in project chunkstories by Hugobros3.

the class DefaultPluginManager method reloadPlugins.

@Override
public /**
 * Implementation : Checks %gamedir%/plugins/ folder, loads what it can within, checks enabled mods and their plugins/ folder, enables what it can
 */
void reloadPlugins() {
    // First disable any leftover plugins
    disablePlugins();
    // We make a list
    LinkedList<PluginInformationImplementation> pluginsToLoad = new LinkedList<PluginInformationImplementation>();
    // Creates plugins folder if it isn't present.
    File pluginsFolder = new File(GameDirectory.getGameFolderPath() + "/plugins/");
    pluginsFolder.mkdirs();
    // Iterates over files of the folder
    for (File file : pluginsFolder.listFiles()) {
        if (file.getName().endsWith(".jar")) {
            try {
                PluginInformationImplementation pluginInformation = new PluginInformationImplementation(file, ((ModsManagerImplementation) pluginExecutionContext.getContent().modsManager()).getFinalClassLoader());
                // Client only plugins require actually being a client
                if (pluginInformation.getPluginType() == PluginType.CLIENT_ONLY && !(this instanceof ClientPluginManager))
                    continue;
                else // Server only plugins require the same
                if (pluginInformation.getPluginType() == PluginType.MASTER && !(this instanceof ServerPluginManager))
                    continue;
                pluginsToLoad.add(pluginInformation);
            } catch (PluginLoadException | IOException e) {
                logger().error("Failed to load plugin file " + file + e.getMessage());
                e.printStackTrace();
            }
        }
    }
    // Mods too can bundle plugins
    for (PluginInformationImplementation pluginInformation : ((ModsManagerImplementation) this.pluginExecutionContext.getContent().modsManager()).getAllModsPlugins()) {
        // Client only plugins require actually being a client
        if (pluginInformation.getPluginType() == PluginType.CLIENT_ONLY && !(this instanceof ClientPluginManager))
            continue;
        else // Server only plugins require the same
        if (pluginInformation.getPluginType() == PluginType.MASTER && !(this instanceof ServerPluginManager))
            continue;
        pluginsToLoad.add(pluginInformation);
    }
    // Enables the found plugins
    enablePlugins(pluginsToLoad);
}
Also used : ModsManagerImplementation(io.xol.chunkstories.content.mods.ModsManagerImplementation) ClientPluginManager(io.xol.chunkstories.api.plugin.ClientPluginManager) PluginLoadException(io.xol.chunkstories.api.exceptions.plugins.PluginLoadException) ServerPluginManager(io.xol.chunkstories.api.plugin.ServerPluginManager) IOException(java.io.IOException) File(java.io.File) LinkedList(java.util.LinkedList)

Aggregations

ClientPluginManager (io.xol.chunkstories.api.plugin.ClientPluginManager)3 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)2 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)2 World (io.xol.chunkstories.api.world.World)2 ServerConnection (io.xol.chunkstories.client.net.ServerConnection)2 PacketInput (io.xol.chunkstories.net.packets.PacketInput)2 WorldClientRemote (io.xol.chunkstories.world.WorldClientRemote)2 ClientInputPressedEvent (io.xol.chunkstories.api.events.client.ClientInputPressedEvent)1 ClientInputReleasedEvent (io.xol.chunkstories.api.events.client.ClientInputReleasedEvent)1 PlayerInputPressedEvent (io.xol.chunkstories.api.events.player.PlayerInputPressedEvent)1 PlayerInputReleasedEvent (io.xol.chunkstories.api.events.player.PlayerInputReleasedEvent)1 PluginLoadException (io.xol.chunkstories.api.exceptions.plugins.PluginLoadException)1 Layer (io.xol.chunkstories.api.gui.Layer)1 MouseScroll (io.xol.chunkstories.api.input.Mouse.MouseScroll)1 ServerPluginManager (io.xol.chunkstories.api.plugin.ServerPluginManager)1 ModsManagerImplementation (io.xol.chunkstories.content.mods.ModsManagerImplementation)1 File (java.io.File)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1