Compare commits

..

No commits in common. "OneWorld" and "master" have entirely different histories.

9 changed files with 127 additions and 218 deletions

3
.gitignore vendored
View File

@ -8,8 +8,5 @@ lib/bin
lib/.project lib/.project
lib/.classpath lib/.classpath
# Доступен в шаблонной master ветке, в остальных удалён.
gradlew.bat
# Ignore Gradle build output directory # Ignore Gradle build output directory
build build

94
gradlew.bat vendored Normal file
View File

@ -0,0 +1,94 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -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 = "example plugin desctiption" description = "example plugin description"
repositories { repositories {
mavenCentral() mavenCentral()
@ -13,14 +13,19 @@ dependencies {
implementation("org.spongepowered:spongeapi:7.4.0") implementation("org.spongepowered:spongeapi:7.4.0")
} }
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.jar { tasks.jar {
from("src/main/resources/plugin.json") { from("src/main/resources/plugin.json") {
include("plugin.json") include("plugin.json")
} }
manifest { manifest {
attributes( attributes(
"Main-Class" to "org.punkcraft.oneworld.OneWorld" "Main-Class" to "org.punkcraft.example.Example"
) )
} }
archiveBaseName.set("OneWorld") archiveBaseName.set("Example")
} }

View 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;
}
}

View File

@ -1,107 +0,0 @@
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 = "oneworld", name = "OneWorld", version = "1.0", description = "OneWorld")
public class OneWorld {
@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 OneWorld!!!");
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;
}
}

View File

@ -1,31 +0,0 @@
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;
}
}

View File

@ -1,44 +0,0 @@
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(OneWorld 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;
}
}
}
}
}

View File

@ -1,27 +0,0 @@
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));
}
}

View File

@ -6,10 +6,10 @@
"license": "All-Rights-Reserved", "license": "All-Rights-Reserved",
"plugins": [ "plugins": [
{ {
"id": "oneworld", "id": "example",
"name": "OneWorld", "name": "Example",
"version": "${version}", "version": "${version}",
"entrypoint": "org.punkcraft.oneworld.OneWorld", "entrypoint": "org.punkcraft.example.Example",
"description": "My plugin description", "description": "My plugin description",
"branding": {}, "branding": {},
"links": { "links": {