init tmp
This commit is contained in:
18
lib/.classpath
Normal file
18
lib/.classpath
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
34
lib/.project
Normal file
34
lib/.project
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>lib</name>
|
||||
<comment>Project lib created by Buildship.</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1732479146189</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
29
lib/bin/main/META-INF/sponge_plugins.json
Normal file
29
lib/bin/main/META-INF/sponge_plugins.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"loader": {
|
||||
"name": "java_plain",
|
||||
"version": "1.0"
|
||||
},
|
||||
"license": "All-Rights-Reserved",
|
||||
"plugins": [
|
||||
{
|
||||
"id": "worldswapper2",
|
||||
"name": "WorldSwapper2",
|
||||
"version": "${version}",
|
||||
"entrypoint": "org.punkcraft.worldswapper2.WorldSwapper2",
|
||||
"description": "My plugin description",
|
||||
"branding": {},
|
||||
"links": {
|
||||
},
|
||||
"contributors": [
|
||||
],
|
||||
"dependencies": [
|
||||
{
|
||||
"id": "spongeapi",
|
||||
"version": "7.2.0",
|
||||
"load-order": "after",
|
||||
"optional": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
BIN
lib/bin/main/org/punkcraft/oneworld/OneWorldSponge.class
Normal file
BIN
lib/bin/main/org/punkcraft/oneworld/OneWorldSponge.class
Normal file
Binary file not shown.
BIN
lib/bin/main/org/punkcraft/oneworld/TestMessage.class
Normal file
BIN
lib/bin/main/org/punkcraft/oneworld/TestMessage.class
Normal file
Binary file not shown.
BIN
lib/bin/main/org/punkcraft/oneworld/WSListener.class
Normal file
BIN
lib/bin/main/org/punkcraft/oneworld/WSListener.class
Normal file
Binary file not shown.
BIN
lib/bin/main/org/punkcraft/oneworld/Zone.class
Normal file
BIN
lib/bin/main/org/punkcraft/oneworld/Zone.class
Normal file
Binary file not shown.
20
lib/build.gradle.kts
Normal file
20
lib/build.gradle.kts
Normal file
@ -0,0 +1,20 @@
|
||||
plugins { kotlin("jvm") version "1.8.0" }
|
||||
|
||||
group = "org.punkcraft"
|
||||
version = "1.0.0-Sponge"
|
||||
// description = "Here lies an example plugin definition"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.spongepowered.org/maven")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.spongepowered:spongeapi:7.2.0")
|
||||
// testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
// testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
archiveBaseName.set("OneWorld")
|
||||
}
|
108
lib/src/main/java/org/punkcraft/oneworld/OneWorldSponge.java
Normal file
108
lib/src/main/java/org/punkcraft/oneworld/OneWorldSponge.java
Normal file
@ -0,0 +1,108 @@
|
||||
|
||||
package org.punkcraft.oneworld;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.config.ConfigDir;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
||||
import org.spongepowered.api.network.ChannelBinding;
|
||||
import org.spongepowered.api.network.ChannelRegistrar;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Plugin(id = "oneworldsponge", name = "OneWorldSponge", version = "1.0", description = "OneWorldSponge")
|
||||
public class OneWorldSponge {
|
||||
|
||||
@Inject
|
||||
private Logger logger;
|
||||
|
||||
@Inject
|
||||
@ConfigDir(sharedRoot = false)
|
||||
private Path configDir;
|
||||
|
||||
private ChannelBinding.IndexedMessageChannel channel;
|
||||
private List<Zone> zones = new ArrayList<>();
|
||||
|
||||
@Listener
|
||||
public void onServerStart(GameStartedServerEvent event) {
|
||||
logger.info("Successfully running OneWorldSponge!!!");
|
||||
|
||||
ChannelRegistrar channelRegistrar = Sponge.getChannelRegistrar();
|
||||
this.channel = channelRegistrar.createChannel(this, "custom:main");
|
||||
|
||||
// Регистрация сообщения
|
||||
this.channel.registerMessage(TestMessage.class, 0);
|
||||
|
||||
// Загрузка конфигурации зон
|
||||
createZones();
|
||||
loadZones();
|
||||
|
||||
Sponge.getEventManager().registerListeners(this, new WSListener(this, this.channel, zones));
|
||||
}
|
||||
|
||||
private void createZones() {
|
||||
File configFile = new File("zones.cfg");
|
||||
if (!configFile.exists()) {
|
||||
try {
|
||||
if (configFile.createNewFile()) {
|
||||
System.out.println("Файл zones.cfg успешно создан.");
|
||||
} else {
|
||||
System.out.println("Не удалось создать файл zones.cfg.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("Произошла ошибка при создании файла zones.cfg.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadZones() {
|
||||
try {
|
||||
Path configFile = configDir.resolve("zones.yml");
|
||||
if (Files.notExists(configFile)) {
|
||||
Files.createDirectories(configDir); // на случай если каталог не существует
|
||||
Files.createFile(configFile);
|
||||
}
|
||||
|
||||
YAMLConfigurationLoader loader = YAMLConfigurationLoader.builder().setPath(configFile).build();
|
||||
ConfigurationNode rootNode = loader.load();
|
||||
|
||||
ConfigurationNode zonesNode = rootNode.getNode("zones");
|
||||
if (!zonesNode.isVirtual()) {
|
||||
for (ConfigurationNode node : zonesNode.getChildrenMap().values()) {
|
||||
String name = node.getKey().toString();
|
||||
int x1 = node.getNode("x1").getInt();
|
||||
int y1 = node.getNode("y1").getInt();
|
||||
int z1 = node.getNode("z1").getInt();
|
||||
int x2 = node.getNode("x2").getInt();
|
||||
int y2 = node.getNode("y2").getInt();
|
||||
int z2 = node.getNode("z2").getInt();
|
||||
|
||||
zones.add(new Zone(name, x1, y1, z1, x2, y2, z2));
|
||||
}
|
||||
} else {
|
||||
logger.warn("No zones found in the configuration file.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to load zones from zones.yml", e);
|
||||
}
|
||||
}
|
||||
|
||||
public ChannelBinding.IndexedMessageChannel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
}
|
31
lib/src/main/java/org/punkcraft/oneworld/TestMessage.java
Normal file
31
lib/src/main/java/org/punkcraft/oneworld/TestMessage.java
Normal file
@ -0,0 +1,31 @@
|
||||
package org.punkcraft.oneworld;
|
||||
|
||||
import org.spongepowered.api.network.ChannelBuf;
|
||||
import org.spongepowered.api.network.Message;
|
||||
|
||||
public class TestMessage implements Message {
|
||||
private String string;
|
||||
|
||||
public TestMessage(String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(ChannelBuf buf) {
|
||||
this.string = buf.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(ChannelBuf buf) {
|
||||
buf.writeString(this.string);
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return string;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.string = content;
|
||||
}
|
||||
}
|
||||
|
44
lib/src/main/java/org/punkcraft/oneworld/WSListener.java
Normal file
44
lib/src/main/java/org/punkcraft/oneworld/WSListener.java
Normal file
@ -0,0 +1,44 @@
|
||||
package org.punkcraft.oneworld;
|
||||
|
||||
import org.spongepowered.api.entity.Entity;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.entity.MoveEntityEvent;
|
||||
import org.spongepowered.api.network.ChannelBinding;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WSListener {
|
||||
private final ChannelBinding.IndexedMessageChannel channel;
|
||||
private final List<Zone> zones;
|
||||
|
||||
public WSListener(OneWorldSponge plugin, ChannelBinding.IndexedMessageChannel channel, List<Zone> zones) {
|
||||
this.channel = channel;
|
||||
this.zones = zones;
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onEntityMove(MoveEntityEvent event) {
|
||||
Entity entity = event.getTargetEntity();
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
int x = player.getLocation().getBlockX();
|
||||
int y = player.getLocation().getBlockY();
|
||||
int z = player.getLocation().getBlockZ();
|
||||
|
||||
for (Zone zone : zones) {
|
||||
// player.sendMessage(Text.of("Перебор зоны" + zone.getName()));
|
||||
if (zone.isWithinZone(x, y, z)) {
|
||||
// player.sendMessage(Text.of("Вы находитесь в зоне: " + zone.getName()));
|
||||
|
||||
// Создаем и отправляем сообщение
|
||||
TestMessage testMessage = new TestMessage(player.getName() + " " + zone.getName());
|
||||
channel.sendTo(player, testMessage);
|
||||
|
||||
// Выход из цикла после нахождения первой зоны
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
27
lib/src/main/java/org/punkcraft/oneworld/Zone.java
Normal file
27
lib/src/main/java/org/punkcraft/oneworld/Zone.java
Normal file
@ -0,0 +1,27 @@
|
||||
package org.punkcraft.oneworld;
|
||||
|
||||
public class Zone {
|
||||
private String name;
|
||||
private int x1, y1, z1, x2, y2, z2;
|
||||
|
||||
public Zone(String name, int x1, int y1, int z1, int x2, int y2, int z2) {
|
||||
this.name = name;
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
this.z1 = z1;
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
this.z2 = z2;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isWithinZone(int x, int y, int z) {
|
||||
return (Math.min(x1, x2) <= x && x <= Math.max(x1, x2)) &&
|
||||
(Math.min(y1, y2) <= y && y <= Math.max(y1, y2)) &&
|
||||
(Math.min(z1, z2) <= z && z <= Math.max(z1, z2));
|
||||
}
|
||||
}
|
||||
|
29
lib/src/main/resources/META-INF/sponge_plugins.json
Normal file
29
lib/src/main/resources/META-INF/sponge_plugins.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"loader": {
|
||||
"name": "java_plain",
|
||||
"version": "1.0"
|
||||
},
|
||||
"license": "All-Rights-Reserved",
|
||||
"plugins": [
|
||||
{
|
||||
"id": "worldswapper2",
|
||||
"name": "WorldSwapper2",
|
||||
"version": "${version}",
|
||||
"entrypoint": "org.punkcraft.worldswapper2.WorldSwapper2",
|
||||
"description": "My plugin description",
|
||||
"branding": {},
|
||||
"links": {
|
||||
},
|
||||
"contributors": [
|
||||
],
|
||||
"dependencies": [
|
||||
{
|
||||
"id": "spongeapi",
|
||||
"version": "7.2.0",
|
||||
"load-order": "after",
|
||||
"optional": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user