diff --git a/lib/bin/main/org/punkcraft/oneworld/OneWorldSponge.class b/lib/bin/main/org/punkcraft/oneworld/OneWorldSponge.class index b9c7727..5a192de 100644 Binary files a/lib/bin/main/org/punkcraft/oneworld/OneWorldSponge.class and b/lib/bin/main/org/punkcraft/oneworld/OneWorldSponge.class differ diff --git a/lib/src/main/java/org/punkcraft/oneworld/OneWorldSponge.java b/lib/src/main/java/org/punkcraft/oneworld/OneWorldSponge.java index 0eb348c..9775f66 100644 --- a/lib/src/main/java/org/punkcraft/oneworld/OneWorldSponge.java +++ b/lib/src/main/java/org/punkcraft/oneworld/OneWorldSponge.java @@ -1,108 +1,9 @@ - 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 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; - } } diff --git a/lib/src/main/java/org/punkcraft/oneworld/TestMessage.java b/lib/src/main/java/org/punkcraft/oneworld/TestMessage.java deleted file mode 100644 index 5291a71..0000000 --- a/lib/src/main/java/org/punkcraft/oneworld/TestMessage.java +++ /dev/null @@ -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; - } -} - diff --git a/lib/src/main/java/org/punkcraft/oneworld/WSListener.java b/lib/src/main/java/org/punkcraft/oneworld/WSListener.java deleted file mode 100644 index aeb717f..0000000 --- a/lib/src/main/java/org/punkcraft/oneworld/WSListener.java +++ /dev/null @@ -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 zones; - - public WSListener(OneWorldSponge plugin, ChannelBinding.IndexedMessageChannel channel, List 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; - } - } - } - } -} diff --git a/lib/src/main/java/org/punkcraft/oneworld/Zone.java b/lib/src/main/java/org/punkcraft/oneworld/Zone.java deleted file mode 100644 index 79e3124..0000000 --- a/lib/src/main/java/org/punkcraft/oneworld/Zone.java +++ /dev/null @@ -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)); - } -} -