Compare commits
No commits in common. "LongerDay" and "master" have entirely different histories.
@ -2,7 +2,7 @@ plugins { kotlin("jvm") version "1.8.0" }
|
|||||||
|
|
||||||
group = "org.punkcraft"
|
group = "org.punkcraft"
|
||||||
version = "1.0.0-Sponge"
|
version = "1.0.0-Sponge"
|
||||||
// description = "Here lies an example plugin definition"
|
description = "example plugin description"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@ -24,8 +24,8 @@ tasks.jar {
|
|||||||
}
|
}
|
||||||
manifest {
|
manifest {
|
||||||
attributes(
|
attributes(
|
||||||
"Main-Class" to "org.punkcraft.longerday.LongerDay"
|
"Main-Class" to "org.punkcraft.example.Example"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
archiveBaseName.set("LongerDay")
|
archiveBaseName.set("Example")
|
||||||
}
|
}
|
||||||
|
22
lib/src/main/java/org/punkcraft/example/Example.java
Normal file
22
lib/src/main/java/org/punkcraft/example/Example.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package org.punkcraft.example;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.spongepowered.api.event.Listener;
|
||||||
|
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
||||||
|
import org.spongepowered.api.plugin.Plugin;
|
||||||
|
|
||||||
|
@Plugin(id = "example", name = "Example", version = "1.0", description = "Example")
|
||||||
|
public class Example {
|
||||||
|
@Inject
|
||||||
|
private Logger logger;
|
||||||
|
|
||||||
|
@Listener
|
||||||
|
public void onServerStart(GameStartedServerEvent event) {
|
||||||
|
logger.info("Successfully running Example");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Logger getLogger() {
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
}
|
@ -1,55 +0,0 @@
|
|||||||
package org.punkcraft.longerday;
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.spongepowered.api.Sponge;
|
|
||||||
import org.spongepowered.api.scheduler.Task;
|
|
||||||
import org.spongepowered.api.world.World;
|
|
||||||
import org.spongepowered.api.event.Listener;
|
|
||||||
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
|
||||||
import org.spongepowered.api.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Plugin(id = "longerday", name = "LongerDay", version = "1.0", description = "Extends the day cycle")
|
|
||||||
public class LongerDay {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private Logger logger;
|
|
||||||
|
|
||||||
private int timeCounter = 0;
|
|
||||||
|
|
||||||
@Listener
|
|
||||||
public void onServerStart(GameStartedServerEvent event) {
|
|
||||||
logger.info("Successfully running LongerDay");
|
|
||||||
|
|
||||||
// Получаем первый мир (обычно это "world")
|
|
||||||
Optional<World> worldOptional = Sponge.getServer().getWorlds().stream().findFirst();
|
|
||||||
if (!worldOptional.isPresent()) {
|
|
||||||
logger.error("No worlds found! Unable to set game rules.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
World world = worldOptional.get();
|
|
||||||
|
|
||||||
|
|
||||||
// Запускаем задачу для изменения времени каждые 5 тиков
|
|
||||||
Task.builder()
|
|
||||||
.intervalTicks(5) // Выполняется каждые 5 тиков
|
|
||||||
.execute(() -> {
|
|
||||||
try {
|
|
||||||
// Изменяем время в мире
|
|
||||||
timeCounter = (timeCounter + 1) % 24000; // Циклический счетчик времени
|
|
||||||
world.getProperties().setWorldTime((long) timeCounter); // Устанавливаем новое время
|
|
||||||
logger.debug("Time set to: {} in world: {}", timeCounter, world.getName());
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Error while setting world time: ", e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.submit(this); // Подаем задачу в планировщик
|
|
||||||
}
|
|
||||||
|
|
||||||
public Logger getLogger() {
|
|
||||||
return logger;
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,10 +6,10 @@
|
|||||||
"license": "All-Rights-Reserved",
|
"license": "All-Rights-Reserved",
|
||||||
"plugins": [
|
"plugins": [
|
||||||
{
|
{
|
||||||
"id": "longerday",
|
"id": "example",
|
||||||
"name": "LongerDay",
|
"name": "Example",
|
||||||
"version": "${version}",
|
"version": "${version}",
|
||||||
"entrypoint": "org.punkcraft.longerday.LongerDay",
|
"entrypoint": "org.punkcraft.example.Example",
|
||||||
"description": "My plugin description",
|
"description": "My plugin description",
|
||||||
"branding": {},
|
"branding": {},
|
||||||
"links": {
|
"links": {
|
||||||
|
Loading…
Reference in New Issue
Block a user