Skip to content

Commit

Permalink
Fixed region file naming, fixed bungee memory leak, packets can now h…
Browse files Browse the repository at this point in the history
…ave a target server, fixed sqlite, rewrote island file copying, fixed missing apache commons exception, worlds no longer create / load if they already exist on startup
  • Loading branch information
IllusionTheDev committed Oct 26, 2021
1 parent b2f708e commit e717697
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 63 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ repositories {
jcenter()
mavenCentral()

maven { url = 'http://nexus.hc.to/content/repositories/pub_releases' }
maven { url = 'https://nexus.hc.to/content/repositories/pub_releases' }
maven { url = 'https://hub.spigotmc.org/nexus/content/groups/public/' }
maven { url = 'https://repo.codemc.org/repository/maven-public/' }
maven { url = "http://repo.dmulloy2.net/nexus/repository/public/" }
maven { url = 'http://repo.extendedclip.com/content/repositories/placeholderapi'}
maven { url = "https://repo.dmulloy2.net/nexus/repository/public/" }
maven { url = 'https://repo.extendedclip.com/content/repositories/placeholderapi'}
maven { url = 'https://mvn.intellectualsites.com/content/repositories/releases/'}
maven { url "https://repo.glaremasters.me/repository/concuncan/" }
maven { url = "https://repo.glaremasters.me/repository/concuncan/" }

mavenLocal()

Expand All @@ -26,8 +26,8 @@ dependencies {
implementation group: 'net.md-5', name: 'bungeecord-api', version: '1.16-R0.5-SNAPSHOT'
implementation 'org.spigotmc:spigot:1.8.8-R0.1-SNAPSHOT'

implementation 'org.projectlombok:lombok:1.18.20'
annotationProcessor('org.projectlombok:lombok:1.18.20')
implementation 'org.projectlombok:lombok:1.18.22'
annotationProcessor('org.projectlombok:lombok:1.18.22')

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'de.tr7zw:item-nbt-api-plugin:2.1.0'
Expand Down
Binary file added libs/FastAsyncWorldEdit-Bukkit-1.17-256_.jar
Binary file not shown.
Binary file added libs/WorldEdit.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.illusion.skyblockcore.shared.packet.PacketProcessor;
import me.illusion.skyblockcore.shared.packet.data.ProxyToServerPacket;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
Expand Down Expand Up @@ -34,6 +35,12 @@ public void send(Packet packet) {

ProxyToServerPacket proxyToServerPacket = (ProxyToServerPacket) packet;

String targetServer = proxyToServerPacket.getTargetServer();

if (targetServer == null) {
for (ServerInfo serverInfo : ProxyServer.getInstance().getServers().values())
serverInfo.sendData("SkyblockChannel", packet.getAllBytes());
}
ProxyServer
.getInstance()
.getServerInfo(proxyToServerPacket.getTargetServer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public YMLBase(Plugin plugin, File file, boolean existsOnSource) {
this.file = file;

if (!file.exists()) {
try {
try (InputStream stream = plugin.getResourceAsStream(file.getName())) {
file.getParentFile().mkdirs();
if (existsOnSource) {
InputStream stream = plugin.getResourceAsStream(file.getName());
Files.copy(stream, file.toPath());
stream.close();
} else
file.createNewFile();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected void writeByte(byte value) {
stream.writeByte(value);
}

protected void writeByteArray(byte[] bytes) {
protected void writeByteArray(byte... bytes) {
validateStream();
writeInt(bytes.length);
stream.write(bytes);
Expand Down Expand Up @@ -100,21 +100,19 @@ protected void writeUUID(UUID uuid) {
writeLong(uuid.getLeastSignificantBits());
}

protected void writeBungeeText(BaseComponent[] text) {
protected void writeBungeeText(BaseComponent... text) {
writeString(ComponentSerializer.toString(text));
}


@SneakyThrows
protected void writeObject(Object object) {
validateStream();
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
ObjectOutputStream out = new ObjectOutputStream(bos);
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos)) {
out.writeObject(object);
out.flush();
byte[] bytes = bos.toByteArray();
writeByteArray(bytes);
out.close();
}
// ignore close exception
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.Serializable;
import java.nio.file.Files;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

@EqualsAndHashCode
public class SerializedFile implements Serializable {
Expand All @@ -18,6 +19,15 @@ public SerializedFile(File file) {
setFile(file);
}

private SerializedFile(File file, byte[] contents) {
this.file = file;
this.contents = contents;
}

public SerializedFile copy() {
return new SerializedFile(this.file, contents);
}

public static SerializedFile[] loadArray(File[] array) {
SerializedFile[] newArray = new SerializedFile[array.length];

Expand All @@ -27,6 +37,14 @@ public static SerializedFile[] loadArray(File[] array) {
return newArray;
}

public void save() {
try {
getFile().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}

public CompletableFuture<File> getFile() {
return CompletableFuture.supplyAsync(() -> {
if (!file.exists()) {
Expand All @@ -48,7 +66,15 @@ public CompletableFuture<File> getFile() {
}

public final void setFile(File file) {
setFile(file, true);
}

public final void setFile(File file, boolean readNewContents) {
this.file = file;

if (!file.exists() || !readNewContents)
return;

try {
this.contents = Files.readAllBytes(file.toPath());
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public CompletableFuture<Boolean> setup(String ip, int port, String database, St

@Override
public boolean isFileBased() {
return false;
return true;
}
}
26 changes: 18 additions & 8 deletions src/main/java/me/illusion/skyblockcore/spigot/SkyblockPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import me.illusion.skyblockcore.spigot.hook.VaultHook;
import me.illusion.skyblockcore.spigot.island.IslandManager;
import me.illusion.skyblockcore.spigot.island.world.EmptyWorldGenerator;
import me.illusion.skyblockcore.spigot.listener.DeathListener;
import me.illusion.skyblockcore.spigot.listener.DebugListener;
import me.illusion.skyblockcore.spigot.listener.JoinListener;
import me.illusion.skyblockcore.spigot.listener.LeaveListener;
import me.illusion.skyblockcore.spigot.messaging.BungeeMessaging;
Expand All @@ -21,6 +23,7 @@
import org.bukkit.Bukkit;
import org.bukkit.WorldCreator;
import org.bukkit.entity.Player;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
Expand Down Expand Up @@ -89,6 +92,14 @@ Bungee messaging handler, responsible for communication to proxy(ies)

@Override
public void onEnable() {
emptyWorldGenerator = new EmptyWorldGenerator();

System.out.println("Registering configuration files");
messages = new MessagesFile(this);
islandConfig = new IslandConfig(this);

System.out.println("Creating worlds");
worldManager = new WorldManager(this);
// Loads the SQL, when that's complete with a response (true|false), loads if false
setupStorage().whenComplete((val, throwable) -> {
if (!val) // if the setup is incorrect, don't load
Expand All @@ -104,27 +115,22 @@ public void onEnable() {
}

private void load() {
System.out.println("Registering configuration files");

messages = new MessagesFile(this);
islandConfig = new IslandConfig(this);
islandManager = new IslandManager(this);
commandManager = new CommandManager(this);
playerManager = new PlayerManager();
emptyWorldGenerator = new EmptyWorldGenerator();

System.out.println("Setting up pasting handler");
pastingHandler = PastingType.enable(this, islandConfig.getPastingSelection());

System.out.println("Registering start files");
startSchematic = startFiles();

System.out.println("Creating worlds");
worldManager = new WorldManager(this);

System.out.println("Registering listeners");
Bukkit.getPluginManager().registerEvents(new JoinListener(this), this);
Bukkit.getPluginManager().registerEvents(new LeaveListener(this), this);
Bukkit.getPluginManager().registerEvents(new DeathListener(this), this);
Bukkit.getPluginManager().registerEvents(new DebugListener(this), this);

System.out.println("Registering default commands.");
registerDefaultCommands();
Expand Down Expand Up @@ -206,7 +212,7 @@ private File[] startFiles() {
if (pastingHandler.getType() == PastingType.FAWE)
saveResource("start-schematic" + File.separator + "skyblock-schematic.schematic", false);
else
saveResource("start-schematic" + File.separator + "r0.0.mca", false);
saveResource("start-schematic" + File.separator + "r.0.0.mca", false);
}

return startSchematicFolder.listFiles();
Expand All @@ -216,4 +222,8 @@ private void sync(Runnable runnable) {
Bukkit.getScheduler().runTask(this, runnable);
}

@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
return emptyWorldGenerator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,31 @@ public class ComparisonResult {
private boolean fullyMatches;
private int[] wildcardPositions = null;

private final String[] currentSplit;

public ComparisonResult(String current, String test, String[] aliases) {
currentSplit = StringUtil.split(current, '.');
test(test);
public ComparisonResult(String identifier, String test, String[] aliases) {
test(identifier, test);

if (!fullyMatches)
for (String str : aliases) {
test(str);
test(str, test);

if (fullyMatches)
break;
}

partiallyMatches = fullyMatches || partiallyMatches;

}

private void test(String test) {
private void test(String identifier, String test) {
String[] identifierSplit = StringUtil.split(identifier, '.');
String[] testSplit = StringUtil.split(test, '.');

int length = currentSplit.length;
int length = identifierSplit.length;

wildcardPositions = new int[length];
int wildcard = 0;

for(int i = 0; i < length; i++) {
String word = currentSplit[i];
for (int i = 0; i < length; i++) {
String word = identifierSplit[i];
String testWord = testSplit[i];

if ("*".equals(word)) { // If word is wildcard
Expand Down
Loading

0 comments on commit e717697

Please sign in to comment.