Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libraries/text-components/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
setUpLibrary(project)

6 changes: 6 additions & 0 deletions libraries/text-components/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
library_id = text-components
library_name = Text Components
library_description = Versatile text components.
library_version = 0.1.0-alpha.1

osl_dependencies = core:>=0.7.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package net.ornithemc.osl.text.api;

import java.util.Objects;

public class ClickEvent {

private final Action action;
private final String value;

private ClickEvent(Action action, String value) {
this.action = action;
this.value = value;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ClickEvent)) {
return false;
}
ClickEvent event = (ClickEvent) o;
return this.action == event.action && Objects.equals(this.value, event.value);
}

public Action getAction() {
return this.action;
}

public String getValue() {
return this.value;
}

public static ClickEvent openUrl(String url) {
return new ClickEvent(Action.OPEN_URL, url);
}

public static ClickEvent runCommand(String command) {
return new ClickEvent(Action.RUN_COMMAND, command);
}

public static ClickEvent suggestCommand(String command) {
return new ClickEvent(Action.SUGGEST_COMMAND, command);
}

public static ClickEvent copyToClipboard(String text) {
return new ClickEvent(Action.COPY_TO_CLIPBOARD, text);
}

public enum Action {

OPEN_URL, RUN_COMMAND, SUGGEST_COMMAND, COPY_TO_CLIPBOARD

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package net.ornithemc.osl.text.api;

public enum Formatting {

BLACK ('0', 0x000000),
DARK_BLUE ('1', 0x0000AA),
DARK_GREEN ('2', 0x00AA00),
DARK_AQUA ('3', 0x00AAAA),
DARK_RED ('4', 0xAA0000),
DARK_PURPLE ('5', 0xAA00AA),
GOLD ('6', 0xFFAA00),
GRAY ('7', 0xAAAAAA),
DARK_GRAY ('8', 0x555555),
BLUE ('9', 0x5555FF),
GREEN ('a', 0x55FF55),
AQUA ('b', 0x55FFFF),
RED ('c', 0xFF5555),
LIGHT_PURPLE ('d', 0xFF55FF),
YELLOW ('e', 0xFFFF55),
WHITE ('f', 0xFFFFFF),
OBFUSCATED ('k'),
BOLD ('l'),
STRIKETHROUGH('m'),
UNDERLINED ('n'),
ITALIC ('o'),
RESET ('r');

public static final char PREFIX = '§';

final char code;
final Integer color;

private Formatting(char code) {
this(code, null);
}

private Formatting(char code, Integer color) {
this.code = code;
this.color = color;
}

@Override
public String toString() {
return "" + PREFIX + this.code;
}

public char getCode() {
return this.code;
}

public boolean isColor() {
return this.color != null;
}

public Integer getColor() {
return this.color;
}

public static Formatting byCode(char code) {
for (Formatting f : Formatting.values()) {
if (f.code == code) {
return f;
}
}

throw new IllegalStateException("unknown text formatting code " + code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.ornithemc.osl.text.api;

import java.util.Objects;

public class HoverEvent {

private final Action action;
private final Object value;

private HoverEvent(Action action, Object value) {
this.action = action;
this.value = value;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof HoverEvent)) {
return false;
}
HoverEvent event = (HoverEvent) o;
return this.action == event.action && Objects.equals(this.value, event.value);
}

public Action getAction() {
return this.action;
}

public <T> T getValue() {
return (T) this.value;
}

public static HoverEvent showText(TextComponent text) {
return new HoverEvent(Action.SHOW_TEXT, text);
}

public enum Action {

SHOW_TEXT

}
}
Loading
Loading