Merge branch 'development'

This commit is contained in:
Christian Koop 2022-09-04 19:39:36 +02:00
commit 8bbed0342e
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
50 changed files with 1409 additions and 47 deletions

View File

@ -29,6 +29,7 @@ jobs:
with: with:
versions: 1.18.2, 1.19, 1.19.2 versions: 1.18.2, 1.19, 1.19.2
remapped: true remapped: true
forceRun: true
# Build project # Build project
- name: Build with Maven - name: Build with Maven

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
@ -243,6 +243,12 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_19_R1v2</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<!-- End NMS --> <!-- End NMS -->
<!-- Start Plugin Hooks --> <!-- Start Plugin Hooks -->
@ -312,7 +318,7 @@
<dependency> <dependency>
<groupId>com.bgsoftware</groupId> <groupId>com.bgsoftware</groupId>
<artifactId>wildstacker</artifactId> <artifactId>wildstacker</artifactId>
<version>3.5.1</version> <version>3.8.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -53,7 +53,7 @@ public class SongodaCore {
/** /**
* @since coreRevision 6 * @since coreRevision 6
*/ */
private final static String coreVersion = "2.6.13"; private final static String coreVersion = "2.6.16";
/** /**
* This is specific to the website api * This is specific to the website api

View File

@ -227,7 +227,7 @@ public class ChatMessage {
Object packet; Object packet;
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_19)) { if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_19)) {
packet = mc_PacketPlayOutChat_new.newInstance(mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList)), 1); packet = mc_PacketPlayOutChat_new.newInstance(mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList)), mc_PacketPlayOutChat_new_1_19_0 ? 1 : true);
}else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) { }else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) {
packet = mc_PacketPlayOutChat_new.newInstance( packet = mc_PacketPlayOutChat_new.newInstance(
mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList)), mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList)),
@ -255,6 +255,7 @@ public class ChatMessage {
private static Method mc_IChatBaseComponent_ChatSerializer_a, cb_craftPlayer_getHandle; private static Method mc_IChatBaseComponent_ChatSerializer_a, cb_craftPlayer_getHandle;
private static Constructor mc_PacketPlayOutChat_new; private static Constructor mc_PacketPlayOutChat_new;
private static Field mc_entityPlayer_playerConnection, mc_chatMessageType_Chat; private static Field mc_entityPlayer_playerConnection, mc_chatMessageType_Chat;
private static boolean mc_PacketPlayOutChat_new_1_19_0 = false;
static { static {
init(); init();
@ -277,7 +278,12 @@ public class ChatMessage {
mc_PacketPlayOutChat = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_19) ? ClassMapping.CLIENTBOUND_SYSTEM_CHAT.getClazz() : ClassMapping.PACKET_PLAY_OUT_CHAT.getClazz(); mc_PacketPlayOutChat = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_19) ? ClassMapping.CLIENTBOUND_SYSTEM_CHAT.getClazz() : ClassMapping.PACKET_PLAY_OUT_CHAT.getClazz();
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_19)) { if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_19)) {
mc_PacketPlayOutChat_new = mc_PacketPlayOutChat.getConstructor(mc_IChatBaseComponent, Integer.TYPE); try {
mc_PacketPlayOutChat_new = mc_PacketPlayOutChat.getConstructor(mc_IChatBaseComponent, Boolean.TYPE);
} catch (NoSuchMethodException ex) {
mc_PacketPlayOutChat_new = mc_PacketPlayOutChat.getConstructor(mc_IChatBaseComponent, Integer.TYPE);
mc_PacketPlayOutChat_new_1_19_0 = true;
}
} else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) { } else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) {
mc_ChatMessageType = ClassMapping.CHAT_MESSAGE_TYPE.getClazz(); mc_ChatMessageType = ClassMapping.CHAT_MESSAGE_TYPE.getClazz();
mc_chatMessageType_Chat = mc_ChatMessageType.getField(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17) ? "a" : "CHAT"); mc_chatMessageType_Chat = mc_ChatMessageType.getField(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17) ? "a" : "CHAT");

View File

@ -1,5 +1,6 @@
package com.songoda.core.database; package com.songoda.core.database;
import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.Arrays; import java.util.Arrays;
@ -23,7 +24,7 @@ public class DataMigrationManager {
* Runs any needed data migrations * Runs any needed data migrations
*/ */
public void runMigrations() { public void runMigrations() {
this.databaseConnector.connect((connection -> { try (Connection connection = this.databaseConnector.getConnection()) {
int currentMigration = -1; int currentMigration = -1;
boolean migrationsExist; boolean migrationsExist;
@ -90,7 +91,10 @@ public class DataMigrationManager {
statement.setInt(1, currentMigration); statement.setInt(1, currentMigration);
statement.execute(); statement.execute();
} }
})); } catch (Exception ex) {
ex.printStackTrace();
}
} }
/** /**

View File

@ -29,4 +29,6 @@ public interface DatabaseConnector {
interface ConnectionCallback { interface ConnectionCallback {
void accept(Connection connection) throws SQLException; void accept(Connection connection) throws SQLException;
} }
Connection getConnection();
} }

View File

@ -12,7 +12,7 @@ public class MySQLConnector implements DatabaseConnector {
private HikariDataSource hikari; private HikariDataSource hikari;
private boolean initializedSuccessfully; private boolean initializedSuccessfully;
public MySQLConnector(Plugin plugin, String hostname, int port, String database, String username, String password, boolean useSSL) { public MySQLConnector(Plugin plugin, String hostname, int port, String database, String username, String password, boolean useSSL, int poolSize) {
this.plugin = plugin; this.plugin = plugin;
plugin.getLogger().info("connecting to " + hostname + " : " + port); plugin.getLogger().info("connecting to " + hostname + " : " + port);
@ -21,7 +21,7 @@ public class MySQLConnector implements DatabaseConnector {
config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database + "?useSSL=" + useSSL); config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database + "?useSSL=" + useSSL);
config.setUsername(username); config.setUsername(username);
config.setPassword(password); config.setPassword(password);
config.setMaximumPoolSize(3); config.setMaximumPoolSize(poolSize);
try { try {
this.hikari = new HikariDataSource(config); this.hikari = new HikariDataSource(config);
@ -41,6 +41,7 @@ public class MySQLConnector implements DatabaseConnector {
this.hikari.close(); this.hikari.close();
} }
@Deprecated
@Override @Override
public void connect(ConnectionCallback callback) { public void connect(ConnectionCallback callback) {
try (Connection connection = this.hikari.getConnection()) { try (Connection connection = this.hikari.getConnection()) {
@ -50,4 +51,14 @@ public class MySQLConnector implements DatabaseConnector {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
@Override
public Connection getConnection() {
try {
return this.hikari.getConnection();
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
} }

View File

@ -39,6 +39,7 @@ public class SQLiteConnector implements DatabaseConnector {
} }
} }
@Deprecated
@Override @Override
public void connect(ConnectionCallback callback) { public void connect(ConnectionCallback callback) {
if (this.connection == null) { if (this.connection == null) {
@ -56,4 +57,20 @@ public class SQLiteConnector implements DatabaseConnector {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
@Override
public Connection getConnection() {
try {
if (this.connection == null || this.connection.isClosed()) {
try {
this.connection = DriverManager.getConnection(this.connectionString);
} catch (SQLException ex) {
this.plugin.getLogger().severe("An error occurred retrieving the SQLite database connection: " + ex.getMessage());
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return this.connection;
}
} }

View File

@ -17,6 +17,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
@ -59,7 +60,7 @@ public class McMMOHandler {
mcmmo_PerksUtils_handleLuckyPerks = mcmmo_PerksUtils.getDeclaredMethod("handleLuckyPerks", Player.class, mcmmo_SkillType); mcmmo_PerksUtils_handleLuckyPerks = mcmmo_PerksUtils.getDeclaredMethod("handleLuckyPerks", Player.class, mcmmo_SkillType);
mcmmo_SecondaryAbility = Class.forName("com.gmail.nossr50.datatypes.skills.SecondaryAbility"); mcmmo_SecondaryAbility = Class.forName("com.gmail.nossr50.datatypes.skills.SecondaryAbility");
mcmmo_SecondaryAbility_valueOf = mcmmo_SecondaryAbility.getDeclaredMethod("valueOf", String.class); mcmmo_SecondaryAbility_valueOf = mcmmo_SecondaryAbility.getDeclaredMethod("valueOf", String.class);
mcmmo_Permissions_secondaryAbilityEnabled = com.gmail.nossr50.util.Permissions.class.getDeclaredMethod("secondaryAbilityEnabled", Player.class, mcmmo_SecondaryAbility); mcmmo_Permissions_secondaryAbilityEnabled = com.gmail.nossr50.util.Permissions.class.getDeclaredMethod("secondaryAbilityEnabled", Permissible.class, mcmmo_SecondaryAbility);
mcmmo_SkillUtils_activationSuccessful = com.gmail.nossr50.util.skills.SkillUtils.class.getDeclaredMethod("activationSuccessful", mcmmo_SecondaryAbility, Player.class, int.class, int.class); mcmmo_SkillUtils_activationSuccessful = com.gmail.nossr50.util.skills.SkillUtils.class.getDeclaredMethod("activationSuccessful", mcmmo_SecondaryAbility, Player.class, int.class, int.class);
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {

View File

@ -1,17 +1,20 @@
package com.songoda.core.hooks.stackers; package com.songoda.core.hooks.stackers;
import com.bgsoftware.wildstacker.WildStackerPlugin;
import com.bgsoftware.wildstacker.api.WildStackerAPI; import com.bgsoftware.wildstacker.api.WildStackerAPI;
import com.bgsoftware.wildstacker.api.enums.SpawnCause;
import com.bgsoftware.wildstacker.api.objects.StackedEntity; import com.bgsoftware.wildstacker.api.objects.StackedEntity;
import com.bgsoftware.wildstacker.utils.GeneralUtils;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class WildStacker extends Stacker { public class WildStacker extends Stacker {
final Plugin plugin; private final WildStackerPlugin plugin;
public WildStacker(Plugin plugin) { public WildStacker() {
this.plugin = plugin; this.plugin = WildStackerPlugin.getPlugin();
} }
@Override @Override
@ -68,12 +71,6 @@ public class WildStacker extends Stacker {
@Override @Override
public int getMinStackSize(EntityType type) { public int getMinStackSize(EntityType type) {
int min = plugin.getConfig().getInt("entities.minimum-limits." + type.name(), -1); return plugin.getSettings().minimumRequiredEntities.getOrDefault(type, SpawnCause.DEFAULT, 0);
if (min == -1) {
min = plugin.getConfig().getInt("entities.minimum-limits.all", -1);
}
return min == -1 ? 0 : min;
} }
} }

View File

@ -12,6 +12,7 @@ import java.util.logging.Logger;
public class NmsManager { public class NmsManager {
private static final String serverPackagePath = Bukkit.getServer().getClass().getPackage().getName(); private static final String serverPackagePath = Bukkit.getServer().getClass().getPackage().getName();
private static final String serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1); private static final String serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1);
private static final String bukkitVersion = Bukkit.getServer().getBukkitVersion().split("-")[0];
private static final NMSPlayer player; private static final NMSPlayer player;
private static final AnvilCore anvil; private static final AnvilCore anvil;
private static final NBTCore nbt; private static final NBTCore nbt;
@ -128,10 +129,17 @@ public class NmsManager {
world = new com.songoda.core.nms.v1_18_R2.world.WorldCoreImpl(); world = new com.songoda.core.nms.v1_18_R2.world.WorldCoreImpl();
break; break;
case "v1_19_R1": case "v1_19_R1":
player = new com.songoda.core.nms.v1_19_R1.entity.NMSPlayerImpl(); if (bukkitVersion.endsWith(".0")) {
anvil = new com.songoda.core.nms.v1_19_R1.anvil.AnvilCore(); player = new com.songoda.core.nms.v1_19_R1.entity.NMSPlayerImpl();
nbt = new com.songoda.core.nms.v1_19_R1.nbt.NBTCoreImpl(); anvil = new com.songoda.core.nms.v1_19_R1.anvil.AnvilCore();
world = new com.songoda.core.nms.v1_19_R1.world.WorldCoreImpl(); nbt = new com.songoda.core.nms.v1_19_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_19_R1.world.WorldCoreImpl();
}else{
player = new com.songoda.core.nms.v1_19_R1v2.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_19_R1v2.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_19_R1v2.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_19_R1v2.world.WorldCoreImpl();
}
break; break;
default: default:
Logger.getLogger(NmsManager.class.getName()).log(Level.SEVERE, "Failed to load NMS for this server version: version {0} not found", serverPackageVersion); Logger.getLogger(NmsManager.class.getName()).log(Level.SEVERE, "Failed to load NMS for this server version: version {0} not found", serverPackageVersion);

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -19,7 +19,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -60,7 +60,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -60,7 +60,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -142,7 +142,7 @@ public class AnvilView extends AnvilMenu implements CustomAnvil {
this.customTitle = title; this.customTitle = title;
try { try {
mc_Container_title.set(this, new TranslatableComponent(customTitle != null ? customTitle : "")); mc_Container_title.set(this, MutableComponent.create(new TranslatableContents(customTitle != null ? customTitle : "")));
} catch (Exception ex) { } catch (Exception ex) {
Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex);
} }

105
NMS/NMS-v1_19_R1v2/pom.xml Normal file
View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<release>${java.release}</release>
</configuration>
</plugin>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.4</version>
<executions>
<execution>
<id>remap-obf</id>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<configuration>
<srgIn>org.spigotmc:minecraft-server:${nms.ver}:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:${nms.ver}:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<id>remap-spigot</id>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:${nms.ver}:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:${nms.ver}:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.16</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<properties>
<java.version>17</java.version>
<java.release>17</java.release>
<nms.ver>1.19.2-R0.1-SNAPSHOT</nms.ver>
</properties>
<artifactId>SongodaCore-NMS-v1_19_R1v2</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${nms.ver}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>${nms.ver}</version>
<scope>provided</scope>
<classifier>remapped-mojang</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,21 @@
package com.songoda.core.nms.v1_19_R1v2.anvil;
import com.songoda.core.nms.anvil.CustomAnvil;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore {
@Override
public CustomAnvil createAnvil(Player player) {
ServerPlayer p = ((CraftPlayer) player).getHandle();
return new AnvilView(p.nextContainerCounter(), p, null);
}
@Override
public CustomAnvil createAnvil(Player player, InventoryHolder holder) {
ServerPlayer p = ((CraftPlayer) player).getHandle();
return new AnvilView(p.nextContainerCounter(), p, holder);
}
}

View File

@ -0,0 +1,22 @@
package com.songoda.core.nms.v1_19_R1v2.anvil;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.AnvilMenu;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryAnvil;
import org.bukkit.inventory.InventoryHolder;
public class AnvilInventoryCustom extends CraftInventoryAnvil {
final InventoryHolder holder;
public AnvilInventoryCustom(InventoryHolder holder, Location location, Container inventory, Container resultInventory, AnvilMenu container) {
super(location, inventory, resultInventory, container);
this.holder = holder;
}
@Override
public InventoryHolder getHolder() {
return holder;
}
}

View File

@ -0,0 +1,215 @@
package com.songoda.core.nms.v1_19_R1v2.anvil;
import com.songoda.core.nms.anvil.CustomAnvil;
import com.songoda.core.nms.anvil.methods.AnvilTextChange;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.TranslatableContents;
import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.AnvilMenu;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.inventory.ItemCombinerMenu;
import net.minecraft.world.inventory.MenuType;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
public class AnvilView extends AnvilMenu implements CustomAnvil {
private final ServerPlayer entity;
private final Inventory inventory;
private String customTitle = "Repairing";
private int cost = -1;
private boolean canUse = true;
private AnvilTextChange textChange;
// used for setting custom inventory
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
static Field mc_ContainerAnvil_resultInventory; // full inventory
static Field mc_ContainerAnvil_bukkitEntity;
static {
try {
mc_ContainerAnvil_repairInventory = ItemCombinerMenu.class.getDeclaredField("p");
mc_ContainerAnvil_repairInventory.setAccessible(true);
mc_ContainerAnvil_resultInventory = ItemCombinerMenu.class.getDeclaredField("o");
mc_ContainerAnvil_resultInventory.setAccessible(true);
mc_ContainerAnvil_bukkitEntity = AnvilMenu.class.getDeclaredField("bukkitEntity");
mc_ContainerAnvil_bukkitEntity.setAccessible(true);
} catch (Exception ex) {
Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex);
}
}
// 1.14 also introduced a title field, also private, which can only be set once and can't be checked
static Field mc_Container_title;
static {
try {
mc_Container_title = AbstractContainerMenu.class.getDeclaredField("title");
mc_Container_title.setAccessible(true);
} catch (Exception ex) {
Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex);
}
}
public AnvilView(int id, ServerPlayer entity, InventoryHolder holder) {
super(entity.nextContainerCounter(), entity.getInventory(), ContainerLevelAccess.create(entity.level, new BlockPos(0, 0, 0)));
this.setTitle(MutableComponent.create(new TranslatableContents(customTitle != null ? customTitle : "")));
this.checkReachable = false;
this.entity = entity;
if (holder != null) {
this.inventory = getBukkitView(entity, holder).getTopInventory();
} else {
this.inventory = getBukkitView().getTopInventory();
}
}
public CraftInventoryView getBukkitView(Player player, InventoryHolder holder) {
try {
AnvilInventoryCustom craftInventory = new AnvilInventoryCustom(holder,
new Location(entity.level.getWorld(), 0, 0, 0),
(Container) mc_ContainerAnvil_repairInventory.get(this),
(Container) mc_ContainerAnvil_resultInventory.get(this), this);
CraftInventoryView view = new CraftInventoryView(player.getBukkitEntity(), craftInventory, this);
mc_ContainerAnvil_bukkitEntity.set(this, view);
return view;
} catch (Exception ex) {
Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex);
}
return getBukkitView();
}
@Override
public boolean stillValid(Player entityHuman) {
return canUse;
}
@Override
public void broadcastFullState() {
super.broadcastFullState();
if (cost >= 0) {
this.setLevelCost(cost);
}
textChange.onChange();
}
@Override
public void update() {
broadcastFullState();
}
@Override
public String getRenameText() {
return this.itemName;
}
@Override
public void setRenameText(String text) {
this.setItemName(text);
}
@Override
public void setOnChange(AnvilTextChange handler) {
textChange = handler;
}
@Override
public String getCustomTitle() {
return customTitle;
}
@Override
public void setCustomTitle(String title) {
this.customTitle = title;
try {
mc_Container_title.set(this, MutableComponent.create(new TranslatableContents(customTitle != null ? customTitle : "")));
} catch (Exception ex) {
Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex);
}
}
@Override
public void setLevelCost(int cost) {
this.cost = cost;
}
@Override
public int getLevelCost() {
if (cost >= 0) {
return cost;
}
return this.getLevelCost();
}
@Override
public void setCanUse(boolean bool) {
this.canUse = bool;
}
@Override
public ItemStack getLeftInput() {
return inventory.getItem(0);
}
@Override
public ItemStack getRightInput() {
return inventory.getItem(1);
}
@Override
public ItemStack getOutput() {
return inventory.getItem(2);
}
@Override
public void setLeftInput(ItemStack item) {
inventory.setItem(0, item);
}
@Override
public void setRightInput(ItemStack item) {
inventory.setItem(1, item);
}
@Override
public void setOutput(ItemStack item) {
inventory.setItem(2, item);
}
@Override
public Inventory getInventory() {
return inventory;
}
@Override
public void open() {
// Send the packet
entity.connection.send(new ClientboundOpenScreenPacket(super.containerId, MenuType.ANVIL, MutableComponent.create(new TranslatableContents(customTitle != null ? customTitle : ""))));
// Set their active container to this anvil
entity.containerMenu = this;
// Add the slot listener
entity.initMenu(entity.containerMenu);
}
}

View File

@ -0,0 +1,13 @@
package com.songoda.core.nms.v1_19_R1v2.anvil.entity;
import com.songoda.core.nms.entity.NMSPlayer;
import net.minecraft.network.protocol.Packet;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class NMSPlayerImpl implements NMSPlayer {
@Override
public void sendPacket(Player p, Object packet) {
((CraftPlayer) p).getHandle().connection.send((Packet<?>) packet);
}
}

View File

@ -0,0 +1,13 @@
package com.songoda.core.nms.v1_19_R1v2.entity;
import com.songoda.core.nms.entity.NMSPlayer;
import net.minecraft.network.protocol.Packet;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class NMSPlayerImpl implements NMSPlayer {
@Override
public void sendPacket(Player p, Object packet) {
((CraftPlayer) p).getHandle().connection.send((Packet<?>) packet);
}
}

View File

@ -0,0 +1,208 @@
package com.songoda.core.nms.v1_19_R1v2.nbt;
import com.songoda.core.nms.nbt.NBTCompound;
import com.songoda.core.nms.nbt.NBTObject;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Set;
import java.util.UUID;
public class NBTCompoundImpl implements NBTCompound {
protected CompoundTag compound;
protected NBTCompoundImpl(CompoundTag compound) {
this.compound = compound;
}
public NBTCompoundImpl() {
this.compound = new CompoundTag();
}
@Override
public NBTCompound set(String tag, String s) {
compound.putString(tag, s);
return this;
}
@Override
public NBTCompound set(String tag, boolean b) {
compound.putBoolean(tag, b);
return this;
}
@Override
public NBTCompound set(String tag, int i) {
compound.putInt(tag, i);
return this;
}
@Override
public NBTCompound set(String tag, double i) {
compound.putDouble(tag, i);
return this;
}
@Override
public NBTCompound set(String tag, long l) {
compound.putLong(tag, l);
return this;
}
@Override
public NBTCompound set(String tag, short s) {
compound.putShort(tag, s);
return this;
}
@Override
public NBTCompound set(String tag, byte b) {
compound.putByte(tag, b);
return this;
}
@Override
public NBTCompound set(String tag, int[] i) {
compound.putIntArray(tag, i);
return this;
}
@Override
public NBTCompound set(String tag, byte[] b) {
compound.putByteArray(tag, b);
return this;
}
@Override
public NBTCompound set(String tag, UUID u) {
compound.putUUID(tag, u);
return this;
}
@Override
public NBTCompound remove(String tag) {
compound.remove(tag);
return this;
}
@Override
public boolean has(String tag) {
return compound.contains(tag);
}
@Override
public NBTObject getNBTObject(String tag) {
return new NBTObjectImpl(compound, tag);
}
@Override
public String getString(String tag) {
return getNBTObject(tag).asString();
}
@Override
public boolean getBoolean(String tag) {
return getNBTObject(tag).asBoolean();
}
@Override
public int getInt(String tag) {
return getNBTObject(tag).asInt();
}
@Override
public double getDouble(String tag) {
return getNBTObject(tag).asDouble();
}
@Override
public long getLong(String tag) {
return getNBTObject(tag).asLong();
}
@Override
public short getShort(String tag) {
return getNBTObject(tag).asShort();
}
@Override
public byte getByte(String tag) {
return getNBTObject(tag).asByte();
}
@Override
public int[] getIntArray(String tag) {
return getNBTObject(tag).asIntArray();
}
@Override
public byte[] getByteArray(String tag) {
return getNBTObject(tag).asByteArray();
}
@Override
public NBTCompound getCompound(String tag) {
if (has(tag)) {
return getNBTObject(tag).asCompound();
}
CompoundTag newCompound = new CompoundTag();
compound.put(tag, newCompound);
return new NBTCompoundImpl(newCompound);
}
@Override
public Set<String> getKeys() {
return compound.getAllKeys();
}
@Override
public Set<String> getKeys(String tag) {
return compound.getCompound(tag).getAllKeys();
}
@Override
public byte[] serialize(String... exclusions) {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
addExtras();
CompoundTag compound = this.compound.copy();
for (String exclusion : exclusions) {
compound.remove(exclusion);
}
NbtIo.writeCompressed(compound, dataOutput);
return outputStream.toByteArray();
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
@Override
public void deSerialize(byte[] serialized) {
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
compound = NbtIo.readCompressed(dataInput);
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public void addExtras() {
// None
}
@Override
public String toString() {
return compound.toString();
}
}

View File

@ -0,0 +1,38 @@
package com.songoda.core.nms.v1_19_R1v2.nbt;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.nbt.NBTEntity;
import com.songoda.core.nms.nbt.NBTItem;
import net.minecraft.nbt.CompoundTag;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
public class NBTCoreImpl implements NBTCore {
@Deprecated
@Override
public NBTItem of(ItemStack item) {
return new NBTItemImpl(CraftItemStack.asNMSCopy(item));
}
@Deprecated
@Override
public NBTItem newItem() {
return new NBTItemImpl(null);
}
@Override
public NBTEntity of(Entity entity) {
net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
CompoundTag nbt = new CompoundTag();
nmsEntity.saveWithoutId(nbt);
return new NBTEntityImpl(nbt, nmsEntity);
}
@Override
public NBTEntity newEntity() {
return new NBTEntityImpl(new CompoundTag(), null);
}
}

View File

@ -0,0 +1,66 @@
package com.songoda.core.nms.v1_19_R1v2.nbt;
import com.songoda.core.nms.nbt.NBTEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobSpawnType;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import java.util.Optional;
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
private Entity nmsEntity;
public NBTEntityImpl(CompoundTag entityNBT, Entity nmsEntity) {
super(entityNBT);
this.nmsEntity = nmsEntity;
}
@Override
public org.bukkit.entity.Entity spawn(Location location) {
String entityType = getNBTObject("entity_type").asString();
Optional<EntityType<?>> optionalEntity = EntityType.byString(entityType);
if (optionalEntity.isPresent()) {
assert location.getWorld() != null;
Entity spawned = optionalEntity.get().spawn(
((CraftWorld) location.getWorld()).getHandle(),
compound,
null,
null,
new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()),
MobSpawnType.COMMAND,
true,
false
);
if (spawned != null) {
spawned.load(compound);
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
entity.teleport(location);
nmsEntity = spawned;
return entity;
}
}
return null;
}
@Override
public org.bukkit.entity.Entity reSpawn(Location location) {
nmsEntity.discard();
return spawn(location);
}
@Override
public void addExtras() {
compound.putString("entity_type", Registry.ENTITY_TYPE.getKey(nmsEntity.getType()).toString());
}
}

View File

@ -0,0 +1,24 @@
package com.songoda.core.nms.v1_19_R1v2.nbt;
import com.songoda.core.nms.nbt.NBTItem;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
private final ItemStack nmsItem;
public NBTItemImpl(ItemStack nmsItem) {
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new CompoundTag());
this.nmsItem = nmsItem;
}
public org.bukkit.inventory.ItemStack finish() {
if (nmsItem == null) {
return CraftItemStack.asBukkitCopy(ItemStack.of(compound));
}
return CraftItemStack.asBukkitCopy(nmsItem);
}
}

View File

@ -0,0 +1,72 @@
package com.songoda.core.nms.v1_19_R1v2.nbt;
import com.songoda.core.nms.nbt.NBTCompound;
import com.songoda.core.nms.nbt.NBTObject;
import net.minecraft.nbt.CompoundTag;
import java.util.Set;
public class NBTObjectImpl implements NBTObject {
private final CompoundTag compound;
private final String tag;
public NBTObjectImpl(CompoundTag compound, String tag) {
this.compound = compound;
this.tag = tag;
}
@Override
public String asString() {
return compound.getString(tag);
}
@Override
public boolean asBoolean() {
return compound.getBoolean(tag);
}
@Override
public int asInt() {
return compound.getInt(tag);
}
@Override
public double asDouble() {
return compound.getDouble(tag);
}
@Override
public long asLong() {
return compound.getLong(tag);
}
@Override
public short asShort() {
return compound.getShort(tag);
}
@Override
public byte asByte() {
return compound.getByte(tag);
}
@Override
public int[] asIntArray() {
return compound.getIntArray(tag);
}
@Override
public byte[] asByteArray() {
return compound.getByteArray(tag);
}
@Override
public NBTCompound asCompound() {
return new NBTCompoundImpl(compound.getCompound(tag));
}
@Override
public Set<String> getKeys() {
return compound.getAllKeys();
}
}

View File

@ -0,0 +1,39 @@
package com.songoda.core.nms.v1_19_R1v2.world;
import com.songoda.core.nms.world.SItemStack;
import net.minecraft.core.particles.ItemParticleOption;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.Vec3;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class SItemStackImpl implements SItemStack {
private final ItemStack item;
public SItemStackImpl(ItemStack item) {
this.item = item;
}
@Override
public void breakItem(Player player, int amount) {
ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
for (int i = 0; i < amount; ++i) {
Vec3 vec3d = new Vec3(((double) random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
vec3d = vec3d.xRot(-entityPlayer.getXRot() * 0.017453292F);
vec3d = vec3d.yRot(-entityPlayer.getYRot() * 0.017453292F);
double d0 = (double) (-random.nextFloat()) * 0.6D - 0.3D;
Vec3 vec3d1 = new Vec3(((double) random.nextFloat() - 0.5D) * 0.3D, d0, 0.6D);
vec3d1 = vec3d1.xRot(-entityPlayer.getXRot() * 0.017453292F);
vec3d1 = vec3d1.yRot(-entityPlayer.getYRot() * 0.017453292F);
vec3d1 = vec3d1.add(entityPlayer.getX(), entityPlayer.getEyeY(), entityPlayer.getZ());
entityPlayer.level.addParticle(new ItemParticleOption(ParticleTypes.ITEM, CraftItemStack.asNMSCopy(item)), vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z);
}
}
}

View File

@ -0,0 +1,132 @@
package com.songoda.core.nms.v1_19_R1v2.world;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.CompatibleParticleHandler;
import com.songoda.core.nms.world.SSpawner;
import com.songoda.core.nms.world.SpawnedEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.level.SpawnData;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Optional;
import java.util.Set;
public class SSpawnerImpl implements SSpawner {
private final Location spawnerLocation;
public SSpawnerImpl(Location location) {
this.spawnerLocation = location;
}
@Override
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<CompatibleMaterial> canSpawnOn) {
SpawnData data = new SpawnData();
CompoundTag compound = data.getEntityToSpawn();
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
.replace("mushroom_cow", "mooshroom");
compound.putString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
assert spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
RandomSource random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = net.minecraft.world.entity.EntityType.create(compound, world);
if (optionalEntity.isEmpty()) continue;
Entity entity = optionalEntity.get();
entity.setPos(x, y, z);
BlockPos position = entity.blockPosition();
DifficultyInstance damageScaler = world.getCurrentDifficultyAt(position);
if (!(entity instanceof Mob entityInsentient)) {
continue;
}
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
}
entityInsentient.finalizeSpawn(world, damageScaler, MobSpawnType.SPAWNER, null, null);
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
if (spawned != null && !spawned.onSpawn(craftEntity)) {
return null;
}
if (particleType != null) {
float xx = (float) (0 + (Math.random() * 1));
float yy = (float) (0 + (Math.random() * 2));
float zz = (float) (0 + (Math.random() * 1));
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType), spot, 5, xx, yy, zz, 0);
}
world.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
spot.setYaw(random.nextFloat() * 360.0F);
craftEntity.teleport(spot);
return craftEntity;
}
return null;
}
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
if (!world.noCollision(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
if (spawnedIn == null || spawnedOn == null) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,38 @@
package com.songoda.core.nms.v1_19_R1v2.world;
import com.songoda.core.nms.world.SWorld;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.entity.LevelEntityGetter;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
public class SWorldImpl implements SWorld {
private final World world;
public SWorldImpl(World world) {
this.world = world;
}
@Override
public List<LivingEntity> getLivingEntities() {
List<LivingEntity> result = new ArrayList<>();
ServerLevel worldServer = ((CraftWorld) world).getHandle();
LevelEntityGetter<Entity> entities = worldServer.entityManager.getEntityGetter();
entities.getAll().forEach((mcEnt) -> {
org.bukkit.entity.Entity bukkitEntity = mcEnt.getBukkitEntity();
if (bukkitEntity instanceof LivingEntity && bukkitEntity.isValid()) {
result.add((LivingEntity) bukkitEntity);
}
});
return result;
}
}

View File

@ -0,0 +1,93 @@
package com.songoda.core.nms.v1_19_R1v2.world;
import com.songoda.core.nms.ReflectionUtils;
import com.songoda.core.nms.v1_19_R1v2.world.spawner.BBaseSpawnerImpl;
import com.songoda.core.nms.world.BBaseSpawner;
import com.songoda.core.nms.world.SItemStack;
import com.songoda.core.nms.world.SSpawner;
import com.songoda.core.nms.world.SWorld;
import com.songoda.core.nms.world.WorldCore;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.material.FluidState;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_19_R1.CraftChunk;
import org.bukkit.inventory.ItemStack;
public class WorldCoreImpl implements WorldCore {
@Override
public SSpawner getSpawner(CreatureSpawner spawner) {
return new SSpawnerImpl(spawner.getLocation());
}
@Override
public SSpawner getSpawner(Location location) {
return new SSpawnerImpl(location);
}
@Override
public SItemStack getItemStack(ItemStack item) {
return new SItemStackImpl(item);
}
@Override
public SWorld getWorld(World world) {
return new SWorldImpl(world);
}
@Override
public BBaseSpawner getBaseSpawner(CreatureSpawner spawner) throws NoSuchFieldException, IllegalAccessException {
Object cTileEntity = ReflectionUtils.getFieldValue(spawner, "tileEntity");
return new BBaseSpawnerImpl(spawner, (BaseSpawner) ReflectionUtils.getFieldValue(cTileEntity, "a"));
}
/**
* Method is based on {@link ServerLevel#tickChunk(LevelChunk, int)}.
*/
@Override
public void randomTickChunk(org.bukkit.Chunk bukkitChunk, int tickAmount) {
LevelChunk chunk = ((CraftChunk) bukkitChunk).getHandle();
ServerLevel world = chunk.q;
ProfilerFiller gameProfilerFiller = world.getProfiler();
ChunkPos chunkCoordIntPair = chunk.getPos();
int j = chunkCoordIntPair.getMinBlockX();
int k = chunkCoordIntPair.getMinBlockZ();
gameProfilerFiller.popPush("tickBlocks");
if (tickAmount > 0) {
LevelChunkSection[] aChunkSection = chunk.getSections();
for (LevelChunkSection chunkSection : aChunkSection) {
if (chunkSection.isRandomlyTicking()) {
int j1 = chunkSection.bottomBlockY();
for (int k1 = 0; k1 < tickAmount; ++k1) {
BlockPos blockposition2 = world.getBlockRandomPos(j, j1, k, 15);
gameProfilerFiller.push("randomTick");
BlockState iBlockData1 = chunkSection.getBlockState(blockposition2.getX() - j, blockposition2.getY() - j1, blockposition2.getZ() - k);
if (iBlockData1.isRandomlyTicking()) {
iBlockData1.randomTick(world, blockposition2, world.random);
}
FluidState fluid = iBlockData1.getFluidState();
if (fluid.isRandomlyTicking()) {
fluid.randomTick(world, blockposition2, world.random);
}
gameProfilerFiller.pop();
}
}
}
}
}
}

View File

@ -0,0 +1,209 @@
package com.songoda.core.nms.v1_19_R1v2.world.spawner;
import com.songoda.core.nms.world.BBaseSpawner;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.Difficulty;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.SpawnData;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AABB;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.block.CraftCreatureSpawner;
import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Iterator;
import java.util.Optional;
public class BBaseSpawnerImpl implements BBaseSpawner {
private final CreatureSpawner bukkitSpawner;
private final BaseSpawner spawner;
public BBaseSpawnerImpl(CreatureSpawner bukkitSpawner, BaseSpawner spawner) {
this.bukkitSpawner = bukkitSpawner;
this.spawner = spawner;
}
/**
* This method is based on {@link BaseSpawner#isNearPlayer(Level, BlockPos)}.
*/
@SuppressWarnings("JavadocReference")
@Override
public boolean isNearPlayer() {
BlockPos bPos = getBlockPosition();
return getWorld().hasNearbyAlivePlayer(
(double) bPos.getX() + 0.5,
(double) bPos.getY() + 0.5,
(double) bPos.getZ() + 0.5,
this.spawner.requiredPlayerRange
);
}
/**
* This method is based on {@link BaseSpawner#serverTick(ServerLevel, BlockPos)}.
*/
@Override
public void tick() {
ServerLevel world = getWorld();
BlockPos bPos = getBlockPosition();
if (this.spawner.spawnDelay == -1) {
delay(world, bPos);
}
if (this.spawner.spawnDelay > 0) {
--this.spawner.spawnDelay;
} else {
boolean flag = false;
int i = 0;
while (true) {
if (i >= this.spawner.spawnCount) {
if (flag) {
delay(world, bPos);
}
break;
}
CompoundTag nbtTagCompound = this.spawner.nextSpawnData.getEntityToSpawn();
Optional<EntityType<?>> optional = EntityType.by(nbtTagCompound);
if (optional.isEmpty()) {
delay(world, bPos);
return;
}
ListTag nbtTagList = nbtTagCompound.getList("Pos", 6);
int j = nbtTagList.size();
RandomSource randomsource = world.getRandom();
double d0 = j >= 1 ? nbtTagList.getDouble(0) : (double) bPos.getX() + (randomsource.nextDouble() - randomsource.nextDouble()) * (double) this.spawner.spawnRange + 0.5;
double d1 = j >= 2 ? nbtTagList.getDouble(1) : (double) (bPos.getY() + randomsource.nextInt(3) - 1);
double d2 = j >= 3 ? nbtTagList.getDouble(2) : (double) bPos.getZ() + (randomsource.nextDouble() - randomsource.nextDouble()) * (double) this.spawner.spawnRange + 0.5;
if (world.noCollision(optional.get().getAABB(d0, d1, d2))) {
label128:
{
BlockPos blockposition1 = new BlockPos(d0, d1, d2);
if (this.spawner.nextSpawnData.getCustomSpawnRules().isPresent()) {
if (!optional.get().getCategory().isFriendly() && world.getDifficulty() == Difficulty.PEACEFUL) {
break label128;
}
SpawnData.CustomSpawnRules mobSpawnerDataA = this.spawner.nextSpawnData.getCustomSpawnRules().get();
if (!mobSpawnerDataA.blockLightLimit().isValueInRange(world.getBrightness(LightLayer.BLOCK, blockposition1)) ||
!mobSpawnerDataA.skyLightLimit().isValueInRange(world.getBrightness(LightLayer.SKY, blockposition1))) {
break label128;
}
} else if (!SpawnPlacements.checkSpawnRules((EntityType<?>) optional.get(), world, MobSpawnType.SPAWNER, blockposition1, world.getRandom())) {
break label128;
}
Entity entity = EntityType.loadEntityRecursive(nbtTagCompound, world, (entity1) -> {
entity1.moveTo(d0, d1, d2, entity1.getYRot(), entity1.getXRot());
return entity1;
});
if (entity == null) {
delay(world, bPos);
return;
}
int k = world.getEntitiesOfClass(entity.getClass(),
new AABB(bPos.getX(),
bPos.getY(),
bPos.getZ(),
bPos.getX() + 1,
bPos.getY() + 1,
bPos.getZ() + 1).inflate(this.spawner.spawnRange)
).size();
if (k >= this.spawner.maxNearbyEntities) {
delay(world, bPos);
return;
}
entity.moveTo(entity.getX(), entity.getY(), entity.getZ(), randomsource.nextFloat() * 360.0F, 0.0F);
if (entity instanceof Mob) {
Mob entityInsentient = (Mob) entity;
if (this.spawner.nextSpawnData.getCustomSpawnRules().isEmpty() && !entityInsentient.checkSpawnRules(world, MobSpawnType.SPAWNER) || !entityInsentient.checkSpawnObstruction(world)) {
break label128;
}
if (this.spawner.nextSpawnData.getEntityToSpawn().size() == 1 && this.spawner.nextSpawnData.getEntityToSpawn().contains("id", 8)) {
((Mob) entity).finalizeSpawn(world, world.getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.SPAWNER, null, null);
}
if (entityInsentient.level.spigotConfig.nerfSpawnerMobs) {
entityInsentient.aware = false;
}
}
if (CraftEventFactory.callSpawnerSpawnEvent(entity, bPos).isCancelled()) {
Entity vehicle = entity.getVehicle();
if (vehicle != null) {
vehicle.discard();
}
Iterator var21 = entity.getIndirectPassengers().iterator();
while (var21.hasNext()) {
Entity passenger = (Entity) var21.next();
passenger.discard();
}
} else {
if (!world.tryAddFreshEntityWithPassengers(entity, CreatureSpawnEvent.SpawnReason.SPAWNER)) {
delay(world, bPos);
return;
}
world.levelEvent(2004, bPos, 0);
world.gameEvent(entity, GameEvent.ENTITY_PLACE, blockposition1);
if (entity instanceof Mob) {
((Mob) entity).spawnAnim();
}
flag = true;
}
}
}
++i;
}
}
}
/**
* This method is based on {@link BaseSpawner#delay(Level, BlockPos)}.
*/
@SuppressWarnings("JavadocReference")
private void delay(ServerLevel world, BlockPos bPos) {
RandomSource randomsource = world.random;
if (this.spawner.maxSpawnDelay <= this.spawner.minSpawnDelay) {
this.spawner.spawnDelay = this.spawner.minSpawnDelay;
} else {
this.spawner.spawnDelay = this.spawner.minSpawnDelay + randomsource.nextInt(this.spawner.maxSpawnDelay - this.spawner.minSpawnDelay);
}
this.spawner.spawnPotentials.getRandom(randomsource).ifPresent((weightedEntryB) -> {
this.spawner.setNextSpawnData(world, bPos, weightedEntryB.getData());
});
this.spawner.broadcastEvent(world, bPos, 1);
}
private ServerLevel getWorld() {
return ((CraftWorld) this.bukkitSpawner.getWorld()).getHandle();
}
private BlockPos getBlockPosition() {
return ((CraftCreatureSpawner) this.bukkitSpawner).getPosition();
}
}

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

View File

@ -6,7 +6,7 @@
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId> <artifactId>SongodaCore-Modules</artifactId>
<version>2.6.13</version> <version>2.6.16</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<!-- Run 'mvn versions:set -DgenerateBackupPoms=false -DnewVersion=X.Y.Z' to update version recursively --> <!-- Run 'mvn versions:set -DgenerateBackupPoms=false -DnewVersion=X.Y.Z' to update version recursively -->
@ -47,6 +47,7 @@
<module>NMS/NMS-v1_18_R1</module> <module>NMS/NMS-v1_18_R1</module>
<module>NMS/NMS-v1_18_R2</module> <module>NMS/NMS-v1_18_R2</module>
<module>NMS/NMS-v1_19_R1</module> <module>NMS/NMS-v1_19_R1</module>
<module>NMS/NMS-v1_19_R1v2</module>
</modules> </modules>
<issueManagement> <issueManagement>