Repository reorganisation
Unified kotlin and java into just src/main Unified the rs09 and core packages Took all content out of the core package, and placed it into the new content package Reorganised all source code relating to content to be easier to find and explore
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package core.game.component;
|
||||
|
||||
import core.game.node.entity.player.Player;
|
||||
|
||||
/**
|
||||
* An event called when the interface gets closed.
|
||||
* @author Emperor
|
||||
*/
|
||||
public interface CloseEvent {
|
||||
|
||||
/**
|
||||
* Called when the interface gets closed.
|
||||
* @param player The player.
|
||||
* @param c The component.
|
||||
* @return {@code True} if successful, {@code false} if the component should
|
||||
* remain open.
|
||||
*/
|
||||
boolean close(Player player, Component c);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package core.game.component;
|
||||
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.entity.player.link.InterfaceManager;
|
||||
import core.net.packet.PacketRepository;
|
||||
import core.net.packet.context.InterfaceContext;
|
||||
import core.net.packet.out.Interface;
|
||||
import core.game.interaction.InterfaceListeners;
|
||||
|
||||
/**
|
||||
* Represents a component.
|
||||
* @author Emperor
|
||||
*
|
||||
*/
|
||||
public class Component {
|
||||
|
||||
/**
|
||||
* The component id.
|
||||
*/
|
||||
protected int id;
|
||||
|
||||
/**
|
||||
* The component definitions.
|
||||
*/
|
||||
protected final ComponentDefinition definition;
|
||||
|
||||
/**
|
||||
* The close event.
|
||||
*/
|
||||
protected CloseEvent closeEvent;
|
||||
|
||||
/**
|
||||
* The component plugin.
|
||||
*/
|
||||
protected ComponentPlugin plugin;
|
||||
|
||||
/**
|
||||
* If the component is hidden.
|
||||
*/
|
||||
private boolean hidden;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code Component} {@code Object}.
|
||||
* @param id The component id.
|
||||
*/
|
||||
public Component(int id) {
|
||||
this.id = id;
|
||||
this.definition = ComponentDefinition.forId(id);
|
||||
this.plugin = definition.getPlugin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the component.
|
||||
*/
|
||||
public void open(Player player) {
|
||||
InterfaceManager manager = player.getInterfaceManager();
|
||||
InterfaceListeners.runOpen(player,this);
|
||||
if (definition == null) {
|
||||
PacketRepository.send(Interface.class, new InterfaceContext(player, manager.getWindowPaneId(), manager.getDefaultChildId(), getId(), false));
|
||||
if (plugin != null) {
|
||||
plugin.open(player, this);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (definition.getType() == InterfaceType.WINDOW_PANE) {
|
||||
return;
|
||||
}
|
||||
if (definition.getType() == InterfaceType.TAB) {
|
||||
PacketRepository.send(Interface.class, new InterfaceContext(player, definition.getWindowPaneId(manager.isResizable()), definition.getChildId(manager.isResizable()) + definition.getTabIndex(), getId(), definition.isWalkable()));
|
||||
if (plugin != null) {
|
||||
plugin.open(player, this);
|
||||
}
|
||||
return;
|
||||
}
|
||||
PacketRepository.send(Interface.class, new InterfaceContext(player, definition.getWindowPaneId(manager.isResizable()), definition.getChildId(manager.isResizable()), getId(), definition.isWalkable()));
|
||||
if (plugin != null) {
|
||||
plugin.open(player, this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the component.
|
||||
* @param player The player.
|
||||
* @return {@code True} if the component can be closed.
|
||||
*/
|
||||
public boolean close(Player player) {
|
||||
return (closeEvent == null || closeEvent.close(player, this)) && InterfaceListeners.runClose(player, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
* @return The id.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the definition.
|
||||
* @return The definition.
|
||||
*/
|
||||
public ComponentDefinition getDefinition() {
|
||||
return definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the closeEvent.
|
||||
* @return The closeEvent.
|
||||
*/
|
||||
public CloseEvent getCloseEvent() {
|
||||
return closeEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the closeEvent.
|
||||
* @param closeEvent The closeEvent to set.
|
||||
*/
|
||||
public Component setCloseEvent(CloseEvent closeEvent) {
|
||||
this.closeEvent = closeEvent;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the component unclosable.
|
||||
* @param c The component.
|
||||
*/
|
||||
public static void setUnclosable(Player p, Component c) {
|
||||
p.setAttribute("close_c_", true);
|
||||
c.setCloseEvent(new CloseEvent() {
|
||||
@Override
|
||||
public boolean close(Player player, Component c) {
|
||||
return !player.getAttribute("close_c_", false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the plugin.
|
||||
* @param plugin the plugin.
|
||||
*/
|
||||
public void setPlugin(ComponentPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component plugin.
|
||||
* @return the plugin.
|
||||
*/
|
||||
public ComponentPlugin getPlugin() {
|
||||
if (plugin == null) {
|
||||
ComponentPlugin p = ComponentDefinition.forId(getId()).getPlugin();
|
||||
if ((plugin = p) != null) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hidden value.
|
||||
* @return The hidden.
|
||||
*/
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hidden value.
|
||||
* @param hidden The hidden to set.
|
||||
*/
|
||||
public void setHidden(boolean hidden) {
|
||||
this.hidden = hidden;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
package core.game.component;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents the component definitions.
|
||||
* @author Emperor
|
||||
*
|
||||
*/
|
||||
public final class ComponentDefinition {
|
||||
|
||||
/**
|
||||
* The component definitions mapping.
|
||||
*/
|
||||
private static final Map<Integer, ComponentDefinition> DEFINITIONS = new HashMap<Integer, ComponentDefinition>();
|
||||
|
||||
/**
|
||||
* The interface type.
|
||||
*/
|
||||
private InterfaceType type = InterfaceType.DEFAULT;
|
||||
|
||||
/**
|
||||
* The interface context.
|
||||
*/
|
||||
private boolean walkable;
|
||||
|
||||
/**
|
||||
* The tab index.
|
||||
*/
|
||||
private int tabIndex = -1;
|
||||
|
||||
/**
|
||||
* Represents the plugin handler.
|
||||
*/
|
||||
private ComponentPlugin plugin;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code ComponentDefinition} {@code Object}.
|
||||
*/
|
||||
public ComponentDefinition() {
|
||||
/*
|
||||
* empty.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the definition values from a result set.
|
||||
* @throws SQLException The exception if thrown.
|
||||
*/
|
||||
public ComponentDefinition parse(String type, String walkable, String tabIndex){
|
||||
setType(InterfaceType.values()[Integer.parseInt(type)]);
|
||||
setWalkable(Boolean.parseBoolean(walkable));
|
||||
setTabIndex(Integer.parseInt(tabIndex));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component definitions for the component id.
|
||||
* @param componentId The component id.
|
||||
* @return The component definitions.
|
||||
*/
|
||||
public static ComponentDefinition forId(int componentId) {
|
||||
ComponentDefinition def = DEFINITIONS.get(componentId);
|
||||
if (def == null) {
|
||||
DEFINITIONS.put(componentId, def = new ComponentDefinition());
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a plugin to a definition.
|
||||
* @param id the id.
|
||||
* @param plugin the plugin.
|
||||
*/
|
||||
public static void put(int id, ComponentPlugin plugin) {
|
||||
ComponentDefinition.forId(id).setPlugin(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the definitions mapping.
|
||||
* @return The definitions mapping.
|
||||
*/
|
||||
public static Map<Integer, ComponentDefinition> getDefinitions() {
|
||||
return DEFINITIONS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin.
|
||||
* @return The plugin.
|
||||
*/
|
||||
public ComponentPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the plugin.
|
||||
* @param plugin The plugin to set.
|
||||
*/
|
||||
public void setPlugin(ComponentPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the window pane id.
|
||||
* @param resizable If the player is using resizable mode.
|
||||
* @return The window pane id.
|
||||
*/
|
||||
public int getWindowPaneId(boolean resizable) {
|
||||
return resizable ? type.getResizablePaneId() : type.getFixedPaneId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the child id.
|
||||
* @param resizable If the player is using resizable mode.
|
||||
* @return The child id.
|
||||
*/
|
||||
public int getChildId(boolean resizable) {
|
||||
return resizable ? type.getResizableChildId() : type.getFixedChildId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
* @return the type
|
||||
*/
|
||||
public InterfaceType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the batype.
|
||||
* @param type the type to set.
|
||||
*/
|
||||
public void setType(InterfaceType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the walkable.
|
||||
* @return the walkable
|
||||
*/
|
||||
public boolean isWalkable() {
|
||||
return walkable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bawalkable.
|
||||
* @param walkable the walkable to set.
|
||||
*/
|
||||
public void setWalkable(boolean walkable) {
|
||||
this.walkable = walkable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tabIndex.
|
||||
* @return the tabIndex
|
||||
*/
|
||||
public int getTabIndex() {
|
||||
return tabIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the batabIndex.
|
||||
* @param tabIndex the tabIndex to set.
|
||||
*/
|
||||
public void setTabIndex(int tabIndex) {
|
||||
this.tabIndex = tabIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ComponentDefinition [type=" + type + ", walkable=" + walkable + ", tabIndex=" + tabIndex + ", plugin=" + plugin + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package core.game.component;
|
||||
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Represents the plugin used to handle a component reward.
|
||||
* @author Vexia
|
||||
*/
|
||||
public abstract class ComponentPlugin implements Plugin<Object> {
|
||||
|
||||
/**
|
||||
* Handles the interface interaction.
|
||||
* @param player The player.
|
||||
* @param component The component.
|
||||
* @param opcode The opcode.
|
||||
* @param slot The slot.
|
||||
* @param itemId The item id.
|
||||
* @return {@code True} if succesfully handled.
|
||||
*/
|
||||
public abstract boolean handle(final Player player, Component component, final int opcode, final int button, int slot, int itemId);
|
||||
|
||||
/**
|
||||
* Called when this component opens.
|
||||
* @param player The player
|
||||
* @param component The component opening.
|
||||
*/
|
||||
public void open(Player player, Component component) {}
|
||||
|
||||
@Override
|
||||
public Object fireEvent(String identifier, Object... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package core.game.component;
|
||||
|
||||
|
||||
import org.rs09.consts.Components;
|
||||
|
||||
/**
|
||||
* Represents an interface type.
|
||||
* @author Emperor
|
||||
*
|
||||
*/
|
||||
public enum InterfaceType {
|
||||
|
||||
/**
|
||||
* Default interface.
|
||||
*/
|
||||
DEFAULT(Components.TOPLEVEL_548, Components.TOPLEVEL_FULLSCREEN_746, 11, 6),
|
||||
|
||||
/**
|
||||
* Walkable interface.
|
||||
*/
|
||||
OVERLAY(Components.TOPLEVEL_548, Components.TOPLEVEL_FULLSCREEN_746, 4, 5),
|
||||
|
||||
/**
|
||||
* A tab interface.
|
||||
*/
|
||||
TAB(Components.TOPLEVEL_548, Components.TOPLEVEL_FULLSCREEN_746, 83, 93),
|
||||
|
||||
/**
|
||||
* The only tab to be shown (when this type is opened).
|
||||
*/
|
||||
SINGLE_TAB(Components.TOPLEVEL_548, Components.TOPLEVEL_FULLSCREEN_746, 80, 76),
|
||||
|
||||
/**
|
||||
* Chatbox dialogue interface.
|
||||
*/
|
||||
DIALOGUE(Components.CHATTOP_752, Components.CHATTOP_752, 12, 12),
|
||||
|
||||
/**
|
||||
* A window pane.
|
||||
*/
|
||||
WINDOW_PANE(Components.TOPLEVEL_548, Components.TOPLEVEL_FULLSCREEN_746, 0, 0),
|
||||
|
||||
/**
|
||||
* Client script chatbox interface.
|
||||
*/
|
||||
CS_CHATBOX(Components.CHATTOP_752, Components.CHATTOP_752, 6, 6),
|
||||
|
||||
/**
|
||||
* Chatbox interface.
|
||||
*/
|
||||
CHATBOX(Components.CHATTOP_752, Components.CHATTOP_752, 8, 8),
|
||||
|
||||
/**
|
||||
* Wilderness overlay
|
||||
*/
|
||||
WILDERNESS_OVERLAY(Components.TOPLEVEL_548, Components.TOPLEVEL_FULLSCREEN_746, 11, 3);
|
||||
|
||||
/**
|
||||
* The fixed window pane id.
|
||||
*/
|
||||
private final int fixedPaneId;
|
||||
|
||||
/**
|
||||
* The resizable window pane id.
|
||||
*/
|
||||
private final int resizablePaneId;
|
||||
|
||||
/**
|
||||
* The fixed child id.
|
||||
*/
|
||||
private final int fixedChildId;
|
||||
|
||||
/**
|
||||
* The resizable child id.
|
||||
*/
|
||||
private final int resizableChildId;
|
||||
|
||||
/**
|
||||
* Constructs a new {@Code InterfaceType} {@Code Object}
|
||||
* @param fixedPaneId The fixed window pane id.
|
||||
* @param resizablePaneId The resizable window pane id.
|
||||
* @param fixedChildId The fixed child id.
|
||||
* @param resizableChildId The resizable child id.
|
||||
*/
|
||||
private InterfaceType(int fixedPaneId, int resizablePaneId, int fixedChildId, int resizableChildId) {
|
||||
this.fixedPaneId = fixedPaneId;
|
||||
this.resizablePaneId = resizablePaneId;
|
||||
this.fixedChildId = fixedChildId;
|
||||
this.resizableChildId = resizableChildId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fixedPaneId.
|
||||
* @return the fixedPaneId
|
||||
*/
|
||||
public int getFixedPaneId() {
|
||||
return fixedPaneId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the resizablePaneId.
|
||||
* @return the resizablePaneId
|
||||
*/
|
||||
public int getResizablePaneId() {
|
||||
return resizablePaneId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fixedChildId.
|
||||
* @return the fixedChildId
|
||||
*/
|
||||
public int getFixedChildId() {
|
||||
return fixedChildId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the resizableChildId.
|
||||
* @return the resizableChildId
|
||||
*/
|
||||
public int getResizableChildId() {
|
||||
return resizableChildId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user