Skip to content

Commit

Permalink
Fix addonet og tilføj lidt forskellige features.
Browse files Browse the repository at this point in the history
  • Loading branch information
TFSMads committed Dec 5, 2024
1 parent 14a7f84 commit 54d235b
Show file tree
Hide file tree
Showing 53 changed files with 1,628 additions and 422 deletions.
16 changes: 4 additions & 12 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
version = "0.1.0"

plugins {
id("java-library")
}
import net.labymod.labygradle.common.extension.LabyModAnnotationProcessorExtension.ReferenceType

dependencies {
labyProcessor()
labyApi("api")
}

labyModProcessor {
referenceType = net.labymod.gradle.core.processor.ReferenceType.INTERFACE
}

java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
labyModAnnotationProcessor {
referenceType = ReferenceType.INTERFACE
}
89 changes: 17 additions & 72 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
plugins {
id("java-library")
id("net.labymod.gradle")
id("net.labymod.gradle.addon")
id("net.labymod.labygradle")
id("net.labymod.labygradle.addon")
}

val versions = providers.gradleProperty("net.labymod.minecraft-versions").get().split(";")

group = "ml.volder"
version = System.getenv().getOrDefault("VERSION", "1.0.0")

labyMod {
defaultPackageName = "ml.volder" //change this to your main package name (used by all modules)
defaultPackageName = "ml.volder"

addonInfo {
namespace = "sa-transporter"
displayName = "Transporter Addon"
Expand All @@ -19,78 +21,21 @@ labyMod {
}

minecraft {
registerVersions(
"1.8.9",
"1.12.2",
"1.16.5",
"1.17.1",
"1.18.2",
"1.19.2",
"1.19.3",
"1.19.4",
"1.20.1",
"1.20.2",
"1.20.4",
"1.20.5",
"1.20.6",
"1.21"
) { version, provider ->
configureRun(provider, version)
}

subprojects.forEach {
if (it.name != "game-runner") {
filter(it.name)
registerVersion(versions.toTypedArray()) {
runs {
getByName("client") {
// When the property is set to true, you can log in with a Minecraft account
// devLogin = true
}
}
}
}

addonDev {
productionRelease()
}
}

subprojects {
plugins.apply("java-library")
plugins.apply("net.labymod.gradle")
plugins.apply("net.labymod.gradle.addon")

repositories {
maven("https://libraries.minecraft.net/")
maven("https://repo.spongepowered.org/repository/maven-public/")
}
}

fun configureRun(provider: net.labymod.gradle.core.minecraft.provider.VersionProvider, gameVersion: String) {
provider.runConfiguration {
mainClass = "net.minecraft.launchwrapper.Launch"
jvmArgs("-Dnet.labymod.running-version=${gameVersion}")
jvmArgs("-Dmixin.debug=true")
jvmArgs("-Dnet.labymod.debugging.all=true")
jvmArgs("-Dmixin.env.disableRefMap=true")

args("--tweakClass", "net.labymod.core.loader.vanilla.launchwrapper.LabyModLaunchWrapperTweaker")
args("--labymod-dev-environment", "true")
args("--addon-dev-environment", "true")
}

provider.javaVersion = when (gameVersion) {
else -> {
JavaVersion.VERSION_21
}
}

provider.mixin {
val mixinMinVersion = when (gameVersion) {
"1.8.9", "1.12.2", "1.16.5" -> {
"0.6.6"
}
plugins.apply("net.labymod.labygradle")
plugins.apply("net.labymod.labygradle.addon")

else -> {
"0.8.2"
}
}

minVersion = mixinMinVersion
}
}
group = rootProject.group
version = rootProject.version
}
16 changes: 5 additions & 11 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
version = "0.1.0"

plugins {
id("java-library")
}
import net.labymod.labygradle.common.extension.LabyModAnnotationProcessorExtension.ReferenceType

dependencies {
labyProcessor()
api(project(":api"))
}

labyModProcessor {
referenceType = net.labymod.gradle.core.processor.ReferenceType.DEFAULT
implementation("io.netty:netty-buffer:4.1.113.Final")
}

java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
labyModAnnotationProcessor {
referenceType = ReferenceType.DEFAULT
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import ml.volder.transporter.classes.exceptions.LoadingFailedException;
import ml.volder.transporter.classes.items.ItemManager;
import ml.volder.transporter.dev.command.DevCommand;
import ml.volder.transporter.gui.TransporterModulesMenu;
import ml.volder.transporter.listeners.KeyboardListener;
import ml.volder.transporter.listeners.MainMenuOpenListener;
import ml.volder.transporter.messaging.PluginMessageHandler;
import ml.volder.transporter.modules.ModuleManager;
import ml.volder.transporter.updater.UpdateManager;
import ml.volder.unikapi.AddonMain;
Expand All @@ -14,6 +16,7 @@
import ml.volder.unikapi.datasystem.DataManager;
import ml.volder.unikapi.event.EventManager;
import ml.volder.unikapi.keysystem.Key;
import ml.volder.unikapi.loader.Laby4Loader;
import ml.volder.unikapi.logger.Logger;
import ml.volder.unikapi.utils.LoadTimer;
import net.labymod.api.Laby;
Expand Down Expand Up @@ -86,6 +89,9 @@ public void onEnable() {
transporterItemManager = new ItemManager();
transporterItemManager.loadItems();

//Payload Handler
PluginMessageHandler.getInstance().init();

//Modules
ModuleManager.getInstance().registerModules();
ModuleManager.getInstance().initModules();
Expand All @@ -94,6 +100,9 @@ public void onEnable() {
//Events
EventManager.registerEvents(new KeyboardListener());
EventManager.registerEvents(new MainMenuOpenListener());

//Developer tools
//Laby4Loader.registerCommands(new DevCommand());
}catch (Exception e) {
UnikAPI.getCommonDataFolder().delete();
UnikAPI.LOGGER.printStackTrace(Logger.LOG_LEVEL.SEVERE, e);
Expand Down
34 changes: 34 additions & 0 deletions core/src/main/java/ml/volder/transporter/classes/items/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import ml.volder.transporter.TransporterAddon;
import ml.volder.transporter.classes.api.TransporterPriceApi;
import ml.volder.transporter.events.ItemAmountUpdatedEvent;
import ml.volder.transporter.messaging.PluginMessageHandler;
import ml.volder.transporter.messaging.channels.GetChannel;
import ml.volder.transporter.messaging.channels.PutChannel;
import ml.volder.unikapi.api.player.PlayerAPI;
import ml.volder.unikapi.datasystem.Data;
import ml.volder.unikapi.datasystem.DataManager;
import ml.volder.unikapi.event.EventManager;
import ml.volder.unikapi.event.EventType;
import ml.volder.unikapi.types.Material;
Expand All @@ -15,6 +20,8 @@

public class Item {

private DataManager<Data> dataManagerSettings;

private Material material;

private Integer sellValue;
Expand All @@ -27,6 +34,7 @@ public class Item {
public Item(String type, String legacy_type){
this.material = Material.create("minecraft", type, legacy_type);
loadData();
this.dataManagerSettings = DataManager.getOrCreateDataManager("%common%/settings.json");
}

public void setSellValue(Integer sellValue) {
Expand Down Expand Up @@ -86,6 +94,32 @@ public Material getMaterial() {
return material;
}

/**
* Send get payload to server
*
* @param amount amount to get from transporter
*/
public void get(Integer amount) {
if(dataManagerSettings.getBoolean("useTransporterPackets")) {
PluginMessageHandler.getChannel(GetChannel.class).sendPayload(this.getModernType(), amount);
} else {
PlayerAPI.getAPI().sendCommand("transporter get " + this.getModernType() + " " + amount);
}
}

/**
* Send put payload to server
*
* @param amount amount to put in transporter
*/
public void put(Integer amount) {
if(dataManagerSettings.getBoolean("useTransporterPackets")) {
PluginMessageHandler.getChannel(PutChannel.class).sendPayload(this.getModernType(), amount);
} else {
PlayerAPI.getAPI().sendCommand("transporter put " + this.getModernType() + " " + amount);
}
}

private void loadData() {
this.sellValue = TransporterAddon.getInstance().getTransporterItemManager().getDataManagerGlobal().getSettings().getData().has("sellValue." + this.getModernType())
? TransporterAddon.getInstance().getTransporterItemManager().getDataManagerGlobal().getSettings().getData().get("sellValue." + this.getModernType()).getAsInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
public class ItemManager {
private List<Item> itemList = new ArrayList<>();

private boolean hasTransporterData = false;

public void loadItems() {
LoadTimer.start("loadItems");
loadItemsFromCSV();
Expand Down Expand Up @@ -157,6 +159,7 @@ private void initDataManager() {
return;
this.dataManager = DataManager.getOrCreateDataManager(new File(UnikAPI.getPlayerDataFolder(), "itemData.json"));
dataManagerUUID = PlayerAPI.getAPI().getUUID();
hasTransporterData = dataManager.getBoolean("hasTransporterData");
}

public DataManager<Data> getDataManager() {
Expand All @@ -176,4 +179,19 @@ public DataManager<Data> getDataManagerGlobal() {
initDataManagerGlobal();
return globalDataManager;
}

public boolean hasTransporterData() {
if(dataManager == null || PlayerAPI.getAPI().getUUID() == null || !dataManagerUUID.equals(PlayerAPI.getAPI().getUUID()))
getDataManager();
return hasTransporterData;
}

public void transporterInfoSet() {
if(hasTransporterData)
return;
hasTransporterData = true;
getDataManager().getSettings().getData().addProperty("hasTransporterData", hasTransporterData);
getDataManager().save();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package ml.volder.transporter.dev.command;

import ml.volder.transporter.messaging.PluginMessageHandler;
import ml.volder.transporter.messaging.channels.*;
import net.labymod.api.Laby;
import net.labymod.api.client.chat.command.Command;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;

import java.util.UUID;
import java.util.function.Consumer;

public class DevCommand extends Command {


public DevCommand() {
super("dev", "developer");
}

@Override
public boolean execute(String prefix, String[] arguments) {
if(arguments.length >= 1) {
if(arguments[0].equalsIgnoreCase("get")) {
if(arguments.length == 3) {
String item = arguments[1];
Integer amount = Integer.parseInt(arguments[2]);
PluginMessageHandler.getChannel(GetChannel.class).sendPayload(item, amount);
}
} else if(arguments[0].equalsIgnoreCase("put")) {
if(arguments.length == 3) {
String item = arguments[1];
Integer amount = Integer.parseInt(arguments[2]);
PluginMessageHandler.getChannel(PutChannel.class).sendPayload(item, amount);

}
} else if(arguments[0].equalsIgnoreCase("send")) {
if(arguments.length == 4) {
String item = arguments[2];
Integer amount = Integer.parseInt(arguments[3]);
UUID player = UUID.fromString(arguments[1]);
PluginMessageHandler.getChannel(SendChannel.class).sendPayload(item, amount, player);
}
} else if(arguments[0].equalsIgnoreCase("infoall")) {
PluginMessageHandler.getChannel(InfoAllChannel.class).sendPayload("sand", "stone", "dirt");
} else if(arguments[0].equalsIgnoreCase("balance")) {
PluginMessageHandler.getChannel(BalanceChannel.class).sendPayload();
}
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ml.volder.transporter.events;

import ml.volder.unikapi.event.Event;
import ml.volder.unikapi.event.EventType;
import ml.volder.unikapi.event.Handler;

import java.util.ArrayList;
import java.util.List;

public class TransporterChannelRegisteredEvent extends Event {
private static List<Handler> handlerList = new ArrayList<>();

public TransporterChannelRegisteredEvent(EventType eventType, String eventName) {
super(eventType, eventName);
}

public TransporterChannelRegisteredEvent(EventType eventType) {
this(eventType, "transporter_channel_registered_event");
}

@Override
public List<Handler> getHandlerList() {
return handlerList;
}

public static List<Handler> getHandlers(){
return handlerList;
}
}
Loading

0 comments on commit 54d235b

Please sign in to comment.