This repository has been archived by the owner on May 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
MoonLake
committed
Jun 15, 2017
1 parent
26a4c71
commit 1230a08
Showing
15 changed files
with
1,546 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/com/minecraft/moonlake/chat/ChatClickEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (C) 2017 The MoonLake Authors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
package com.minecraft.moonlake.chat; | ||
|
||
public class ChatClickEvent { | ||
|
||
private final Action action; | ||
private final String value; | ||
|
||
public ChatClickEvent(Action action, String value) { | ||
this.action = action; | ||
this.value = value; | ||
} | ||
|
||
public Action getAction() { | ||
return action; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if(obj == this) | ||
return true; | ||
if(obj instanceof ChatClickEvent) { | ||
ChatClickEvent other = (ChatClickEvent) obj; | ||
return action == other.action && value != null ? value.equals(other.value) : other.value == null; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = action != null ? action.hashCode() : 0; | ||
result = 31 * result + (value != null ? value.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ChatClickEvent{" + | ||
"action=" + action + | ||
", value='" + value + '\'' + | ||
'}'; | ||
} | ||
|
||
public enum Action { | ||
|
||
OPEN_URL, | ||
OPEN_FILE, | ||
RUN_COMMAND, | ||
SUGGEST_COMMAND, | ||
CHANGE_PAGE, | ||
; | ||
|
||
public static Action fromName(String name) { | ||
return Action.valueOf(name.toUpperCase()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (C) 2017 The MoonLake Authors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
package com.minecraft.moonlake.chat; | ||
|
||
public enum ChatColor { | ||
|
||
BLACK('0'), | ||
DARK_BLUE('1'), | ||
DARK_GREEN('2'), | ||
DARK_AQUA('3'), | ||
DARK_RED('4'), | ||
DARK_PURPLE('5'), | ||
GOLD('6'), | ||
GRAY('7'), | ||
DARK_GRAY('8'), | ||
BLUE('9'), | ||
GREEN('a'), | ||
AQUA('b'), | ||
RED('c'), | ||
LIGHT_PURPLE('d'), | ||
YELLOW('e'), | ||
WHITE('f'), | ||
OBFUSCATED('k', true), | ||
BOLD('l', true), | ||
STRIKETHROUGH('m', true), | ||
UNDERLINE('n', true), | ||
ITALIC('o', true), | ||
RESET('r'), | ||
; | ||
|
||
private final char code; | ||
private final boolean format; | ||
|
||
ChatColor(char code) { | ||
this(code, false); | ||
} | ||
|
||
ChatColor(char code, boolean format) { | ||
this.code = code; | ||
this.format = format; | ||
} | ||
|
||
public char getCode() { | ||
return code; | ||
} | ||
|
||
public boolean isFormat() { | ||
return format; | ||
} | ||
|
||
public static ChatColor fromName(String name) { | ||
return ChatColor.valueOf(name.toUpperCase()); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/minecraft/moonlake/chat/ChatComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) 2017 The MoonLake Authors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
package com.minecraft.moonlake.chat; | ||
|
||
import java.util.List; | ||
|
||
public interface ChatComponent { | ||
|
||
ChatStyle getStyle(); | ||
|
||
ChatComponent setStyle(ChatStyle style); | ||
|
||
List<ChatComponent> getExtras(); | ||
|
||
int getExtraSize(); | ||
|
||
ChatComponent append(String text); | ||
|
||
ChatComponent append(ChatComponent extra); | ||
|
||
String toJson(); | ||
|
||
String toRaw(); | ||
|
||
String toRaw(boolean color); | ||
} |
118 changes: 118 additions & 0 deletions
118
src/main/java/com/minecraft/moonlake/chat/ChatComponentBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright (C) 2017 The MoonLake Authors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
package com.minecraft.moonlake.chat; | ||
|
||
import com.minecraft.moonlake.validate.Validate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public abstract class ChatComponentBase implements ChatComponent { | ||
|
||
private ChatStyle style; | ||
private List<ChatComponent> extras; | ||
|
||
ChatComponentBase() { | ||
this.extras = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public ChatComponent setStyle(ChatStyle style) { | ||
Validate.notNull(style, "The chat style object is null."); | ||
this.style = style; | ||
for(ChatComponent component : extras) | ||
component.getStyle().setParent(getStyle()); | ||
return this; | ||
} | ||
|
||
@Override | ||
public ChatStyle getStyle() { | ||
if(style == null) { | ||
this.style = new ChatStyle(); | ||
for(ChatComponent component : extras) | ||
component.getStyle().setParent(style); | ||
} | ||
return style; | ||
} | ||
|
||
@Override | ||
public final List<ChatComponent> getExtras() { | ||
return extras; | ||
} | ||
|
||
@Override | ||
public final int getExtraSize() { | ||
return extras.size(); | ||
} | ||
|
||
@Override | ||
public ChatComponent append(String text) { | ||
Validate.notNull(text, "The text object is null."); | ||
return append(new ChatComponentText(text)); | ||
} | ||
|
||
@Override | ||
public ChatComponent append(ChatComponent extra) { | ||
Validate.notNull(extra, "The extra component object is null."); | ||
extra.getStyle().setParent(getStyle()); | ||
extras.add(extra); | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toJson() { | ||
return ChatSerializer.toJson(this); | ||
} | ||
|
||
@Override | ||
public String toRaw() { | ||
return ChatSerializer.toRaw(this); | ||
} | ||
|
||
@Override | ||
public String toRaw(boolean color) { | ||
return ChatSerializer.toRaw(this, color); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if(obj == this) | ||
return true; | ||
if(obj instanceof ChatComponentBase) { | ||
ChatComponentBase other = (ChatComponentBase) obj; | ||
return getStyle().equals(other.getStyle()) && extras.equals(other.extras); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = style != null ? style.hashCode() : 0; | ||
result = 31 * result + (extras != null ? extras.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ChatComponentBase{" + | ||
"style=" + style + | ||
", extras=" + extras + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.