Skip to content

Commit

Permalink
Fix vCompat not working if loaded on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Aug 21, 2023
1 parent 6af07c9 commit 087c7ef
Show file tree
Hide file tree
Showing 39 changed files with 161 additions and 45 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.5</version>
<version>3.0.6</version>
<packaging>pom</packaging>

<distributionManagement>
Expand Down
2 changes: 1 addition & 1 deletion vcompat-1_17_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.5</version>
<version>3.0.6</version>
</parent>
<artifactId>vcompat-1_17_R1</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getProperties().levelName;
}

@Override
public ConsoleReaderWrapper1_17_R1 getConsole() {
Expand Down
2 changes: 1 addition & 1 deletion vcompat-1_18_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.5</version>
<version>3.0.6</version>
</parent>
<artifactId>vcompat-1_18_R1</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getProperties().levelName;
}

@Override
public ConsoleReaderWrapper1_18_R1 getConsole() {
Expand Down
2 changes: 1 addition & 1 deletion vcompat-1_18_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.5</version>
<version>3.0.6</version>
</parent>
<artifactId>vcompat-1_18_R2</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getProperties().levelName;
}

@Override
public ConsoleReaderWrapper1_18_R2 getConsole() {
Expand Down
2 changes: 1 addition & 1 deletion vcompat-1_19_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.5</version>
<version>3.0.6</version>
</parent>
<artifactId>vcompat-1_19_R1</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getProperties().levelName;
}

@Override
public ConsoleReaderWrapper1_19_R1 getConsole() {
Expand Down
2 changes: 1 addition & 1 deletion vcompat-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.5</version>
<version>3.0.6</version>
</parent>
<artifactId>vcompat-api</artifactId>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
package net.sourcewriters.minecraft.vcompat.provider.tools;

import java.io.File;

import org.bukkit.Bukkit;

import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper;

public abstract class ServerTools {

private final File worldFolder;

public ServerTools() {
this.worldFolder = new File(Bukkit.getServer().getWorldContainer(), getLevelName());
}

public abstract void setMotd(String text);

public abstract String getMotd();

public abstract String getLevelName();

public final File getWorldFolder() {
return worldFolder;
}

public abstract ConsoleReaderWrapper getConsole();

}
2 changes: 1 addition & 1 deletion vcompat-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.5</version>
<version>3.0.6</version>
</parent>
<artifactId>vcompat</artifactId>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.sourcewriters.minecraft.vcompat;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

import net.sourcewriters.minecraft.vcompat.provider.VersionControl;
import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup;
import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.utils.java.tools.Container;
import net.sourcewriters.minecraft.vcompat.version.Versions;

Expand All @@ -24,18 +26,21 @@ protected final void init() throws Exception {

@Override
protected final void shutdown() {
if(!init) {
if (!init) {
return;
}
control.ifPresent(VersionControl::shutdown);
}

private final VersionControl initControl() {
Object object = ClassLookup.of(VERSION_PATH).searchMethod("init", "init").run("init");
if (object == null || !(object instanceof VersionControl)) {
throw new IllegalStateException("Can't initialize VersionControl");
try {
Class<?> clazz = Class.forName(VERSION_PATH, true, getClass().getClassLoader());
Object object = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup())
.findStatic(clazz, "init", MethodType.methodType(clazz)).invoke();
return (VersionControl) object;
} catch (Throwable e) {
throw new IllegalStateException("Couldn't initialize VersionControl", e);
}
return (VersionControl) object;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion vcompat-legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat-parent</artifactId>
<version>3.0.5</version>
<version>3.0.6</version>
</parent>
<artifactId>vcompat-legacy</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.File;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.entity.Player1_10_R1;
Expand All @@ -18,8 +17,9 @@ public class PlayerProvider1_10_R1 extends PlayerProvider<VersionControl1_10_R1>

protected PlayerProvider1_10_R1(VersionControl1_10_R1 versionControl) {
super(versionControl);
distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"),
uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM);
distributor = versionControl.getDataProvider().createDistributor(
new File(versionControl.getToolProvider().getServerTools().getWorldFolder(), "playerdata"), uuid -> "custom_" + uuid.toString(),
DataProvider.DEFAULT_RANDOM);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getPropertyManager().getString("level-name", "world");
}

@Override
public ConsoleReaderWrapper1_10_R1 getConsole() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.File;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.entity.Player1_11_R1;
Expand All @@ -18,8 +17,9 @@ public class PlayerProvider1_11_R1 extends PlayerProvider<VersionControl1_11_R1>

protected PlayerProvider1_11_R1(VersionControl1_11_R1 versionControl) {
super(versionControl);
distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"),
uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM);
distributor = versionControl.getDataProvider().createDistributor(
new File(versionControl.getToolProvider().getServerTools().getWorldFolder(), "playerdata"), uuid -> "custom_" + uuid.toString(),
DataProvider.DEFAULT_RANDOM);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getPropertyManager().getString("level-name", "world");
}

@Override
public ConsoleReaderWrapper1_11_R1 getConsole() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.File;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.entity.Player1_12_R1;
Expand All @@ -18,8 +17,9 @@ public class PlayerProvider1_12_R1 extends PlayerProvider<VersionControl1_12_R1>

protected PlayerProvider1_12_R1(VersionControl1_12_R1 versionControl) {
super(versionControl);
distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"),
uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM);
distributor = versionControl.getDataProvider().createDistributor(
new File(versionControl.getToolProvider().getServerTools().getWorldFolder(), "playerdata"), uuid -> "custom_" + uuid.toString(),
DataProvider.DEFAULT_RANDOM);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getPropertyManager().getString("level-name", "world");
}

@Override
public ConsoleReaderWrapper1_12_R1 getConsole() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.File;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.entity.Player1_13_R1;
Expand All @@ -18,8 +17,9 @@ public class PlayerProvider1_13_R1 extends PlayerProvider<VersionControl1_13_R1>

protected PlayerProvider1_13_R1(VersionControl1_13_R1 versionControl) {
super(versionControl);
distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"),
uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM);
distributor = versionControl.getDataProvider().createDistributor(
new File(versionControl.getToolProvider().getServerTools().getWorldFolder(), "playerdata"), uuid -> "custom_" + uuid.toString(),
DataProvider.DEFAULT_RANDOM);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getPropertyManager().getString("level-name", "world");
}

@Override
public ConsoleReaderWrapper1_13_R1 getConsole() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.File;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.entity.Player1_13_R2;
Expand All @@ -18,8 +17,9 @@ public class PlayerProvider1_13_R2 extends PlayerProvider<VersionControl1_13_R2>

protected PlayerProvider1_13_R2(VersionControl1_13_R2 versionControl) {
super(versionControl);
distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"),
uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM);
distributor = versionControl.getDataProvider().createDistributor(
new File(versionControl.getToolProvider().getServerTools().getWorldFolder(), "playerdata"), uuid -> "custom_" + uuid.toString(),
DataProvider.DEFAULT_RANDOM);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getPropertyManager().getString("level-name", "world");
}

@Override
public ConsoleReaderWrapper1_13_R2 getConsole() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getDedicatedServerProperties().levelName;
}

@Override
public ConsoleReaderWrapper1_14_R1 getConsole() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getDedicatedServerProperties().levelName;
}

@Override
public ConsoleReaderWrapper1_15_R1 getConsole() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getDedicatedServerProperties().levelName;
}

@Override
public ConsoleReaderWrapper1_16_R1 getConsole() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void setMotd(String text) {
public String getMotd() {
return ((CraftServer) Bukkit.getServer()).getServer().getMotd();
}

@Override
public String getLevelName() {
return ((CraftServer) Bukkit.getServer()).getServer().getDedicatedServerProperties().levelName;
}

@Override
public ConsoleReaderWrapper1_16_R2 getConsole() {
Expand Down
Loading

0 comments on commit 087c7ef

Please sign in to comment.