forked from GeyserMC/Geyser
Move common stuff used only by connector and bootstrap to connector
This commit is contained in:
parent
dd1747cae9
commit
8f763dfc5f
44 changed files with 162 additions and 112 deletions
|
@ -1,33 +0,0 @@
|
|||
package org.geysermc.common;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum AuthType {
|
||||
OFFLINE,
|
||||
ONLINE,
|
||||
FLOODGATE;
|
||||
|
||||
public static final AuthType[] VALUES = values();
|
||||
|
||||
public static AuthType getById(int id) {
|
||||
return id < VALUES.length ? VALUES[id] : OFFLINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the AuthType string (from config) to the enum, OFFLINE on fail
|
||||
*
|
||||
* @param name AuthType string
|
||||
*
|
||||
* @return The converted AuthType
|
||||
*/
|
||||
public static AuthType getByName(String name) {
|
||||
String upperCase = name.toUpperCase();
|
||||
for (AuthType type : VALUES) {
|
||||
if (type.name().equals(upperCase)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return OFFLINE;
|
||||
}
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.common;
|
||||
|
||||
public class ChatColor {
|
||||
|
||||
public static final char ESCAPE = '§';
|
||||
public static final String BLACK = ESCAPE + "0";
|
||||
public static final String DARK_BLUE = ESCAPE + "1";
|
||||
public static final String DARK_GREEN = ESCAPE + "2";
|
||||
public static final String DARK_AQUA = ESCAPE + "3";
|
||||
public static final String DARK_RED = ESCAPE + "4";
|
||||
public static final String DARK_PURPLE = ESCAPE + "5";
|
||||
public static final String GOLD = ESCAPE + "6";
|
||||
public static final String GRAY = ESCAPE + "7";
|
||||
public static final String DARK_GRAY = ESCAPE + "8";
|
||||
public static final String BLUE = ESCAPE + "9";
|
||||
public static final String GREEN = ESCAPE + "a";
|
||||
public static final String AQUA = ESCAPE + "b";
|
||||
public static final String RED = ESCAPE + "c";
|
||||
public static final String LIGHT_PURPLE = ESCAPE + "d";
|
||||
public static final String YELLOW = ESCAPE + "e";
|
||||
public static final String WHITE = ESCAPE + "f";
|
||||
public static final String OBFUSCATED = ESCAPE + "k";
|
||||
public static final String BOLD = ESCAPE + "l";
|
||||
public static final String STRIKETHROUGH = ESCAPE + "m";
|
||||
public static final String UNDERLINE = ESCAPE + "n";
|
||||
public static final String ITALIC = ESCAPE + "o";
|
||||
public static final String RESET = ESCAPE + "r";
|
||||
|
||||
/**
|
||||
* Convert chat colour codes to terminal colours
|
||||
*
|
||||
* @param string The text to replace colours for
|
||||
*
|
||||
* @return A string ready for terminal printing
|
||||
*/
|
||||
public static String toANSI(String string) {
|
||||
string = string.replace(BOLD, (char) 0x1b + "[1m");
|
||||
string = string.replace(OBFUSCATED, (char) 0x1b + "[5m");
|
||||
string = string.replace(ITALIC, (char) 0x1b + "[3m");
|
||||
string = string.replace(UNDERLINE, (char) 0x1b + "[4m");
|
||||
string = string.replace(STRIKETHROUGH, (char) 0x1b + "[9m");
|
||||
string = string.replace(RESET, (char) 0x1b + "[0m");
|
||||
string = string.replace(BLACK, (char) 0x1b + "[0;30m");
|
||||
string = string.replace(DARK_BLUE, (char) 0x1b + "[0;34m");
|
||||
string = string.replace(DARK_GREEN, (char) 0x1b + "[0;32m");
|
||||
string = string.replace(DARK_AQUA, (char) 0x1b + "[0;36m");
|
||||
string = string.replace(DARK_RED, (char) 0x1b + "[0;31m");
|
||||
string = string.replace(DARK_PURPLE, (char) 0x1b + "[0;35m");
|
||||
string = string.replace(GOLD, (char) 0x1b + "[0;33m");
|
||||
string = string.replace(GRAY, (char) 0x1b + "[0;37m");
|
||||
string = string.replace(DARK_GRAY, (char) 0x1b + "[30;1m");
|
||||
string = string.replace(BLUE, (char) 0x1b + "[34;1m");
|
||||
string = string.replace(GREEN, (char) 0x1b + "[32;1m");
|
||||
string = string.replace(AQUA, (char) 0x1b + "[36;1m");
|
||||
string = string.replace(RED, (char) 0x1b + "[31;1m");
|
||||
string = string.replace(LIGHT_PURPLE, (char) 0x1b + "[35;1m");
|
||||
string = string.replace(YELLOW, (char) 0x1b + "[33;1m");
|
||||
string = string.replace(WHITE, (char) 0x1b + "[37;1m");
|
||||
return string;
|
||||
}
|
||||
|
||||
public String translateAlternateColorCodes(char color, String message) {
|
||||
return message.replace(color, ESCAPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all colour formatting tags from a message
|
||||
*
|
||||
* @param message Message to remove colour tags from
|
||||
*
|
||||
* @return The sanitised message
|
||||
*/
|
||||
public static String stripColors(String message) {
|
||||
return message = message.replaceAll("(&([a-fk-or0-9]))","").replaceAll("(§([a-fk-or0-9]))","").replaceAll("s/\\x1b\\[[0-9;]*[a-zA-Z]//g","");
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package org.geysermc.common;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum PlatformType {
|
||||
|
||||
BUNGEECORD("BungeeCord"),
|
||||
SPIGOT("Spigot"),
|
||||
SPONGE("Sponge"),
|
||||
STANDALONE("Standalone"),
|
||||
VELOCITY("Velocity");
|
||||
|
||||
private String platformName;
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.common.main;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class IGeyserMain {
|
||||
|
||||
public void displayMessage() {
|
||||
String message = createMessage();
|
||||
|
||||
if (System.console() == null) {
|
||||
JOptionPane.showMessageDialog(null, message, "GeyserMC Plugin: " + this.getPluginType(), JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
printMessage(message);
|
||||
}
|
||||
|
||||
private String createMessage() {
|
||||
String message = "";
|
||||
|
||||
InputStream helpStream = IGeyserMain.class.getClassLoader().getResourceAsStream("help.txt");
|
||||
Scanner help = new Scanner(helpStream).useDelimiter("\\Z");
|
||||
String line = "";
|
||||
while (help.hasNext()) {
|
||||
line = help.next();
|
||||
|
||||
line = line.replace("${plugin_type}", this.getPluginType());
|
||||
line = line.replace("${plugin_folder}", this.getPluginFolder());
|
||||
|
||||
message += line + "\n";
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
private void printMessage(String message) {
|
||||
System.out.print(message);
|
||||
}
|
||||
|
||||
public String getPluginType() {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
public String getPluginFolder() {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.common.ping;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
@Data
|
||||
public class GeyserPingInfo {
|
||||
|
||||
public final String motd;
|
||||
public final int currentPlayerCount;
|
||||
public final int maxPlayerCount;
|
||||
|
||||
@Getter
|
||||
private Collection<String> players = new ArrayList<>();
|
||||
|
||||
public void addPlayer(String username) {
|
||||
players.add(username);
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.common.serializer;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.BeanProperty;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.Optional;
|
||||
|
||||
public class AsteriskSerializer extends StdSerializer<Object> implements ContextualSerializer {
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@JacksonAnnotationsInside
|
||||
@JsonSerialize(using = AsteriskSerializer.class)
|
||||
public @interface Asterisk {
|
||||
String value() default "***";
|
||||
}
|
||||
|
||||
String asterisk;
|
||||
|
||||
public AsteriskSerializer() {
|
||||
super(Object.class);
|
||||
}
|
||||
|
||||
public AsteriskSerializer(String asterisk) {
|
||||
super(Object.class);
|
||||
this.asterisk = asterisk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonSerializer<?> createContextual(SerializerProvider serializerProvider, BeanProperty property) {
|
||||
Optional<Asterisk> anno = Optional.ofNullable(property)
|
||||
.map(prop -> prop.getAnnotation(Asterisk.class));
|
||||
return new AsteriskSerializer(anno.map(Asterisk::value).orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(Object obj, JsonGenerator gen, SerializerProvider prov) throws IOException {
|
||||
gen.writeString(asterisk);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue