Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
26d1f27f79 | |||
4e0195f7ab | |||
9856ad0e54 | |||
de4f24c368 |
253
pom.xml
253
pom.xml
@@ -1,121 +1,132 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>dev.viper</groupId>
|
<groupId>dev.viper</groupId>
|
||||||
<artifactId>RealTimeWeather</artifactId>
|
<artifactId>RealTimeWeather</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>RealTimeWeather</name>
|
<name>RealTimeWeather</name>
|
||||||
<description>MC Plugin: Echtzeit & Wetter synchronisieren</description>
|
<description>MC Plugin: Echtzeit & Wetter synchronisieren</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>spigot-repo</id>
|
<id>spigot-repo</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>sonatype</id>
|
<id>sonatype</id>
|
||||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- Spigot API -->
|
<!-- Spigot API -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.21.1-R0.1-SNAPSHOT</version>
|
<version>1.21.1-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- JSON library -->
|
<!-- JSON library -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.json</groupId>
|
<groupId>org.json</groupId>
|
||||||
<artifactId>json</artifactId>
|
<artifactId>json</artifactId>
|
||||||
<version>20231013</version>
|
<version>20231013</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Adventure API -->
|
<!-- Adventure API -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>adventure-api</artifactId>
|
<artifactId>adventure-api</artifactId>
|
||||||
<version>4.17.0</version>
|
<version>4.17.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Adventure Platform Bukkit -->
|
<!-- Adventure Platform Bukkit -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>adventure-platform-bukkit</artifactId>
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
<version>4.3.3</version>
|
<version>4.3.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
|
||||||
|
<!-- bStats Bukkit Library -->
|
||||||
<build>
|
<dependency>
|
||||||
<plugins>
|
<groupId>org.bstats</groupId>
|
||||||
<plugin>
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<version>3.1.0</version>
|
||||||
<version>3.10.1</version>
|
<scope>compile</scope>
|
||||||
<configuration>
|
</dependency>
|
||||||
<source>${maven.compiler.source}</source>
|
</dependencies>
|
||||||
<target>${maven.compiler.target}</target>
|
|
||||||
</configuration>
|
<build>
|
||||||
</plugin>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
<plugin>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<version>3.10.1</version>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<configuration>
|
||||||
<version>3.4.1</version>
|
<source>${maven.compiler.source}</source>
|
||||||
<executions>
|
<target>${maven.compiler.target}</target>
|
||||||
<execution>
|
</configuration>
|
||||||
<phase>package</phase>
|
</plugin>
|
||||||
<goals><goal>shade</goal></goals>
|
|
||||||
<configuration>
|
<plugin>
|
||||||
<relocations>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<!-- Shade org.json -->
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<relocation>
|
<version>3.4.1</version>
|
||||||
<pattern>org.json</pattern>
|
<executions>
|
||||||
<shadedPattern>dev.viper.shaded.org.json</shadedPattern>
|
<execution>
|
||||||
</relocation>
|
<phase>package</phase>
|
||||||
<!-- Shade Adventure API -->
|
<goals><goal>shade</goal></goals>
|
||||||
<relocation>
|
<configuration>
|
||||||
<pattern>net.kyori.adventure</pattern>
|
<relocations>
|
||||||
<shadedPattern>dev.viper.shaded.net.kyori.adventure</shadedPattern>
|
<!-- Shade org.json -->
|
||||||
</relocation>
|
<relocation>
|
||||||
<!-- Shade Adventure Platform Bukkit -->
|
<pattern>org.json</pattern>
|
||||||
<relocation>
|
<shadedPattern>dev.viper.shaded.org.json</shadedPattern>
|
||||||
<pattern>net.kyori.platform.bukkit</pattern>
|
</relocation>
|
||||||
<shadedPattern>dev.viper.shaded.net.kyori.platform.bukkit</shadedPattern>
|
<!-- Shade Adventure API -->
|
||||||
</relocation>
|
<relocation>
|
||||||
</relocations>
|
<pattern>net.kyori.adventure</pattern>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<shadedPattern>dev.viper.shaded.net.kyori.adventure</shadedPattern>
|
||||||
<!-- Minimieren, um die JAR-Größe zu reduzieren (optional) -->
|
</relocation>
|
||||||
<minimizeJar>true</minimizeJar>
|
<!-- Shade Adventure Platform Bukkit -->
|
||||||
<!-- Filter, um unnötige Klassen auszuschließen -->
|
<relocation>
|
||||||
<filters>
|
<pattern>net.kyori.platform.bukkit</pattern>
|
||||||
<filter>
|
<shadedPattern>dev.viper.shaded.net.kyori.platform.bukkit</shadedPattern>
|
||||||
<artifact>*:*</artifact>
|
</relocation>
|
||||||
<excludes>
|
<!-- Shade bStats -->
|
||||||
<exclude>META-INF/*.SF</exclude>
|
<relocation>
|
||||||
<exclude>META-INF/*.DSA</exclude>
|
<pattern>org.bstats</pattern>
|
||||||
<exclude>META-INF/*.RSA</exclude>
|
<shadedPattern>dev.viper.shaded.org.bstats</shadedPattern>
|
||||||
</excludes>
|
</relocation>
|
||||||
</filter>
|
</relocations>
|
||||||
</filters>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
</configuration>
|
<minimizeJar>true</minimizeJar>
|
||||||
</execution>
|
<filters>
|
||||||
</executions>
|
<filter>
|
||||||
</plugin>
|
<artifact>*:*</artifact>
|
||||||
</plugins>
|
<excludes>
|
||||||
</build>
|
<exclude>META-INF/*.SF</exclude>
|
||||||
</project>
|
<exclude>META-INF/*.DSA</exclude>
|
||||||
|
<exclude>META-INF/*.RSA</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
|
21
src/main/java/dev/viper/weathertime/MetricsManager.java
Normal file
21
src/main/java/dev/viper/weathertime/MetricsManager.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package dev.viper.weathertime;
|
||||||
|
|
||||||
|
import org.bstats.bukkit.Metrics;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class MetricsManager {
|
||||||
|
|
||||||
|
private final Metrics metrics;
|
||||||
|
|
||||||
|
public MetricsManager(JavaPlugin plugin) {
|
||||||
|
int pluginId = 26865; // Deine Plugin-ID von bStats eintragen
|
||||||
|
this.metrics = new Metrics(plugin, pluginId);
|
||||||
|
|
||||||
|
// Optional: Eigene Charts hinzufügen
|
||||||
|
// metrics.addCustomChart(new Metrics.SingleLineChart("custom_chart", () -> 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Metrics getMetrics() {
|
||||||
|
return metrics;
|
||||||
|
}
|
||||||
|
}
|
50
src/main/java/dev/viper/weathertime/UpdateChecker.java
Normal file
50
src/main/java/dev/viper/weathertime/UpdateChecker.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package dev.viper.weathertime;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
public class UpdateChecker {
|
||||||
|
private final JavaPlugin plugin;
|
||||||
|
private final int resourceId;
|
||||||
|
|
||||||
|
public UpdateChecker(JavaPlugin plugin, int resourceId) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.resourceId = resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getLatestVersion(Consumer<String> consumer) {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
try {
|
||||||
|
HttpURLConnection connection = (HttpURLConnection)
|
||||||
|
new URL("https://api.spiget.org/v2/resources/" + resourceId + "/versions/latest").openConnection();
|
||||||
|
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.addRequestProperty("User-Agent", "Mozilla/5.0");
|
||||||
|
|
||||||
|
try (InputStream inputStream = connection.getInputStream();
|
||||||
|
Scanner scanner = new Scanner(inputStream)) {
|
||||||
|
String response = scanner.useDelimiter("\\A").next();
|
||||||
|
|
||||||
|
JSONObject json = new JSONObject(response);
|
||||||
|
String versionName = json.optString("name");
|
||||||
|
|
||||||
|
// Nur Zahlen + Punkte behalten (z.B. "version 1.1" -> "1.1")
|
||||||
|
String cleanVersion = versionName.replaceAll("[^0-9.]", "").trim();
|
||||||
|
|
||||||
|
consumer.accept(cleanVersion.isEmpty() ? versionName : cleanVersion);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().warning("Konnte keine Update-Info abrufen: " + e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -23,6 +23,12 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -32,6 +38,10 @@ import java.time.ZonedDateTime;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
// <--- NEU: Einbinden der Hilfsklassen (keine Änderung am bestehenden Code)
|
||||||
|
import dev.viper.weathertime.MetricsManager;
|
||||||
|
import dev.viper.weathertime.UpdateChecker;
|
||||||
|
|
||||||
public class WeatherTimeSyncPlugin extends JavaPlugin implements Listener {
|
public class WeatherTimeSyncPlugin extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
private String apiKey;
|
private String apiKey;
|
||||||
@@ -47,6 +57,13 @@ public class WeatherTimeSyncPlugin extends JavaPlugin implements Listener {
|
|||||||
private final Set<String> processedLocations = new HashSet<>();
|
private final Set<String> processedLocations = new HashSet<>();
|
||||||
private FileConfiguration langConfig;
|
private FileConfiguration langConfig;
|
||||||
|
|
||||||
|
// NEU: bStats & Updater-Felder
|
||||||
|
private MetricsManager metricsManager;
|
||||||
|
private UpdateChecker updateChecker;
|
||||||
|
|
||||||
|
// Variable, um die aktuell bekannte neue Version zu speichern
|
||||||
|
private String latestVersion = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
@@ -54,11 +71,41 @@ public class WeatherTimeSyncPlugin extends JavaPlugin implements Listener {
|
|||||||
loadConfig();
|
loadConfig();
|
||||||
audiences = BukkitAudiences.create(this);
|
audiences = BukkitAudiences.create(this);
|
||||||
|
|
||||||
|
// bStats initialisieren
|
||||||
|
metricsManager = new MetricsManager(this);
|
||||||
|
|
||||||
|
// Spigot UpdateChecker initialisieren (Resource-ID)
|
||||||
|
updateChecker = new UpdateChecker(this, 127846);
|
||||||
|
updateChecker.getLatestVersion(version -> {
|
||||||
|
// Version bereinigen: nur Zahlen und Punkte
|
||||||
|
String cleanVersion = version.replaceAll("[^0-9.]", "").trim();
|
||||||
|
String currentVersion = getDescription().getVersion();
|
||||||
|
|
||||||
|
// Nur dann melden, wenn cleanVersion wirklich neuer ist
|
||||||
|
if (isVersionNewer(currentVersion, cleanVersion)) {
|
||||||
|
latestVersion = cleanVersion; // Neue Version merken
|
||||||
|
|
||||||
|
// Konsolen-Info
|
||||||
|
getLogger().info("Neue Version verfügbar: " + cleanVersion + " (aktuell: " + currentVersion + ")");
|
||||||
|
getLogger().info("Download: https://www.spigotmc.org/resources/127846/");
|
||||||
|
|
||||||
|
// Ingame-Info an alle aktuell online Operatoren
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (player.isOp()) {
|
||||||
|
player.sendMessage("§aEine neue Version von §eRealTimeWeather §aist verfügbar: §e"
|
||||||
|
+ cleanVersion + " §7(aktuell: " + currentVersion + ")");
|
||||||
|
player.sendMessage("§eDownload: §bhttps://www.spigotmc.org/resources/127846/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Objects.requireNonNull(getCommand("wetter")).setExecutor(new WetterCommand());
|
Objects.requireNonNull(getCommand("wetter")).setExecutor(new WetterCommand());
|
||||||
Objects.requireNonNull(getCommand("weatherforecast")).setExecutor(new WeatherForecastCommand());
|
Objects.requireNonNull(getCommand("weatherforecast")).setExecutor(new WeatherForecastCommand());
|
||||||
Objects.requireNonNull(getCommand("toggleweather")).setExecutor(new ToggleWeatherCommand());
|
Objects.requireNonNull(getCommand("toggleweather")).setExecutor(new ToggleWeatherCommand());
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(this, this);
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
getServer().getPluginManager().registerEvents(new UpdateNotifyListener(), this);
|
||||||
|
|
||||||
setDoDaylightCycleForWorlds();
|
setDoDaylightCycleForWorlds();
|
||||||
startWeatherUpdateTask();
|
startWeatherUpdateTask();
|
||||||
@@ -66,6 +113,41 @@ public class WeatherTimeSyncPlugin extends JavaPlugin implements Listener {
|
|||||||
initializePlayerDisplays();
|
initializePlayerDisplays();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Methode zum Versionsvergleich, damit nur wirklich neuere Versionen gemeldet werden
|
||||||
|
private boolean isVersionNewer(String current, String latest) {
|
||||||
|
String[] curParts = current.split("\\.");
|
||||||
|
String[] latParts = latest.split("\\.");
|
||||||
|
int length = Math.max(curParts.length, latParts.length);
|
||||||
|
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
int curNum = i < curParts.length ? Integer.parseInt(curParts[i]) : 0;
|
||||||
|
int latNum = i < latParts.length ? Integer.parseInt(latParts[i]) : 0;
|
||||||
|
|
||||||
|
if (latNum > curNum) {
|
||||||
|
return true; // neuere Version gefunden
|
||||||
|
}
|
||||||
|
if (latNum < curNum) {
|
||||||
|
return false; // keine neuere Version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false; // Versionen sind gleich
|
||||||
|
}
|
||||||
|
|
||||||
|
// Event Listener für Join-Nachricht
|
||||||
|
public class UpdateNotifyListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.isOp() && latestVersion != null) {
|
||||||
|
String currentVersion = getDescription().getVersion();
|
||||||
|
player.sendMessage("§aEine neue Version von §eRealTimeWeather §aist verfügbar: §e"
|
||||||
|
+ latestVersion + " §7(aktuell: " + currentVersion + ")");
|
||||||
|
player.sendMessage("§eDownload: §bhttps://www.spigotmc.org/resources/127846/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if (weatherUpdateTask != null) weatherUpdateTask.cancel();
|
if (weatherUpdateTask != null) weatherUpdateTask.cancel();
|
||||||
@@ -226,6 +308,13 @@ public class WeatherTimeSyncPlugin extends JavaPlugin implements Listener {
|
|||||||
case "snow":
|
case "snow":
|
||||||
world.setStorm(true);
|
world.setStorm(true);
|
||||||
world.setThundering(false);
|
world.setThundering(false);
|
||||||
|
|
||||||
|
// ---- FAKE-SCHNEE ----
|
||||||
|
spawnTemporarySnowInWorld(world, WeatherTimeSyncPlugin.this);
|
||||||
|
|
||||||
|
// ---- Schneemänner, temporär spawnen (z.B. 25 Stück) ----
|
||||||
|
spawnTemporarySnowmen(world, 25, WeatherTimeSyncPlugin.this);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
world.setStorm(false);
|
world.setStorm(false);
|
||||||
@@ -234,12 +323,93 @@ public class WeatherTimeSyncPlugin extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTask(this);
|
}.runTask(this);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
getLogger().warning("Fehler beim Abrufen von Wetter/Zeit für Welt " + world.getName() + ": " + e.getMessage());
|
getLogger().warning("Fehler beim Abrufen von Wetter/Zeit für Welt " + world.getName() + ": " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fake-Schnee auf allen aktuell geladenen Chunks platzieren
|
||||||
|
*/
|
||||||
|
private void spawnTemporarySnowInWorld(World world, JavaPlugin plugin) {
|
||||||
|
List<Block> snowBlocks = new ArrayList<>();
|
||||||
|
|
||||||
|
for (org.bukkit.Chunk chunk : world.getLoadedChunks()) {
|
||||||
|
int chunkX = chunk.getX() << 4;
|
||||||
|
int chunkZ = chunk.getZ() << 4;
|
||||||
|
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
if (Math.random() > 0.7) continue;
|
||||||
|
int worldX = chunkX + x;
|
||||||
|
int worldZ = chunkZ + z;
|
||||||
|
int worldY = world.getHighestBlockYAt(worldX, worldZ);
|
||||||
|
|
||||||
|
Block ground = world.getBlockAt(worldX, worldY - 1, worldZ);
|
||||||
|
Block above = world.getBlockAt(worldX, worldY, worldZ);
|
||||||
|
|
||||||
|
if (ground.getType().isSolid() && above.getType() == Material.AIR) {
|
||||||
|
above.setType(Material.SNOW);
|
||||||
|
snowBlocks.add(above);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schnee entfernen
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (Block b : snowBlocks) {
|
||||||
|
if (b.getType() == Material.SNOW) {
|
||||||
|
b.setType(Material.AIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, 180 * 20L); // 3 Minuten bleibt der Schnee liegen
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spawn temporärer Schneemänner in geladenen Chunks
|
||||||
|
*/
|
||||||
|
private void spawnTemporarySnowmen(World world, int count, JavaPlugin plugin) {
|
||||||
|
List<org.bukkit.entity.Snowman> snowmen = new ArrayList<>();
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
List<org.bukkit.Chunk> loadedChunks = Arrays.asList(world.getLoadedChunks());
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
if (loadedChunks.isEmpty()) break;
|
||||||
|
org.bukkit.Chunk chunk = loadedChunks.get(random.nextInt(loadedChunks.size()));
|
||||||
|
|
||||||
|
int chunkX = chunk.getX() << 4;
|
||||||
|
int chunkZ = chunk.getZ() << 4;
|
||||||
|
int x = chunkX + random.nextInt(16);
|
||||||
|
int z = chunkZ + random.nextInt(16);
|
||||||
|
int y = world.getHighestBlockYAt(x, z);
|
||||||
|
|
||||||
|
if (world.getBlockAt(x, y - 1, z).getType().isSolid()) {
|
||||||
|
org.bukkit.entity.Snowman snowman = (org.bukkit.entity.Snowman)
|
||||||
|
world.spawnEntity(new org.bukkit.Location(world, x + 0.5, y, z + 0.5),
|
||||||
|
org.bukkit.entity.EntityType.SNOW_GOLEM);
|
||||||
|
snowmen.add(snowman);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schneemänner nach 30 Sekunden wieder entfernen
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (org.bukkit.entity.Snowman s : snowmen) {
|
||||||
|
if (!s.isDead()) s.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, 180 * 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void syncMinecraftTime(World world, ZonedDateTime dateTime) {
|
private void syncMinecraftTime(World world, ZonedDateTime dateTime) {
|
||||||
int hour = dateTime.getHour();
|
int hour = dateTime.getHour();
|
||||||
int minute = dateTime.getMinute();
|
int minute = dateTime.getMinute();
|
||||||
@@ -351,7 +521,7 @@ public class WeatherTimeSyncPlugin extends JavaPlugin implements Listener {
|
|||||||
new WeatherForecastCommand().onCommand(player, null, "weatherforecast", new String[]{});
|
new WeatherForecastCommand().onCommand(player, null, "weatherforecast", new String[]{});
|
||||||
} else if (clickedItem.getType() == Material.OAK_SIGN) {
|
} else if (clickedItem.getType() == Material.OAK_SIGN) {
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
String infoMessage = "RealTimeWeather Plugin\nVersion: 1.0\nAutor: M_Viper\nGetestete Minecraft-Version: 1.21.1 - 1.21.8";
|
String infoMessage = "RealTimeWeather Plugin\nVersion: 1.2\nAutor: M_Viper\nGetestete Minecraft-Version: 1.21.1 - 1.21.8";
|
||||||
audiences.player(player).sendMessage(Component.text(infoMessage, NamedTextColor.AQUA));
|
audiences.player(player).sendMessage(Component.text(infoMessage, NamedTextColor.AQUA));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
name: RealTimeWeather
|
name: RealTimeWeather
|
||||||
version: 1.0
|
version: 1.3
|
||||||
main: dev.viper.weathertime.WeatherTimeSyncPlugin
|
main: dev.viper.weathertime.WeatherTimeSyncPlugin
|
||||||
api-version: 1.21
|
api-version: 1.21
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user