mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-15 15:18:04 +00:00
1.21.7 initial work
This commit is contained in:
@@ -21,8 +21,8 @@ allprojects {
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
maven("https://repo.aikar.co/content/groups/aikar/")
|
||||
maven("https://libraries.minecraft.net")
|
||||
maven("https://repo.codemc.io/repository/maven-public/")
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
[versions]
|
||||
paper = "1.21.4-R0.1-SNAPSHOT"
|
||||
paper = "1.21.7-R0.1-SNAPSHOT"
|
||||
junit = "5.8.2"
|
||||
nuotifier = "2.7.2"
|
||||
|
||||
[plugins]
|
||||
paper-userdev = { id = "io.papermc.paperweight.userdev", version = "2.0.0-beta.11" }
|
||||
shadow = { id = "com.github.johnrengelman.shadow", version = "8.1.1" }
|
||||
paper-userdev = { id = "io.papermc.paperweight.userdev", version = "2.0.0-beta.17" }
|
||||
shadow = { id = "com.gradleup.shadow", version = "8.3.8" }
|
||||
runpaper = { id = "xyz.jpenilla.run-paper", version = "2.3.1" }
|
||||
|
||||
[libraries]
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
6
gradlew
vendored
6
gradlew
vendored
@@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -55,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -84,7 +86,7 @@ done
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
22
gradlew.bat
vendored
22
gradlew.bat
vendored
@@ -13,6 +13,8 @@
|
||||
@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 ##########################################################################
|
||||
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
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
|
||||
|
||||
@@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
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
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("com.github.johnrengelman.shadow")
|
||||
id("com.gradleup.shadow")
|
||||
}
|
||||
|
||||
version = "2.0.1"
|
||||
|
||||
@@ -53,7 +53,7 @@ subprojects {
|
||||
create<MavenPublication>("maven") {
|
||||
from(components["java"])
|
||||
}
|
||||
pluginManager.withPlugin("com.github.johnrengelman.shadow") {
|
||||
pluginManager.withPlugin("com.gradleup.shadow") {
|
||||
create<MavenPublication>("shadow") {
|
||||
from(components["java"])
|
||||
}
|
||||
@@ -76,7 +76,7 @@ subprojects {
|
||||
}
|
||||
}
|
||||
|
||||
pluginManager.withPlugin("com.github.johnrengelman.shadow") {
|
||||
pluginManager.withPlugin("com.gradleup.shadow") {
|
||||
tasks {
|
||||
named("build") {
|
||||
dependsOn("shadowJar")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("com.github.johnrengelman.shadow")
|
||||
id("com.gradleup.shadow")
|
||||
id("xyz.jpenilla.run-paper")
|
||||
}
|
||||
|
||||
|
||||
@@ -20,20 +20,10 @@ public abstract class ACivMod extends JavaPlugin {
|
||||
|
||||
private final Set<Class<? extends ConfigurationSerializable>> configClasses = new HashSet<>(0);
|
||||
|
||||
/**
|
||||
* Primary constructor used by the real server
|
||||
*/
|
||||
protected ACivMod() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Secondary constructor used for testing
|
||||
*/
|
||||
protected ACivMod(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
|
||||
super(loader, description, dataFolder, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Self disable when a hard dependency is disabled
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package vg.civcraft.mc.civmodcore;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
import vg.civcraft.mc.civmodcore.chat.dialog.DialogManager;
|
||||
import vg.civcraft.mc.civmodcore.commands.ChunkMetaCommand;
|
||||
import vg.civcraft.mc.civmodcore.commands.CommandManager;
|
||||
@@ -31,20 +27,10 @@ import vg.civcraft.mc.civmodcore.world.locations.global.WorldIDManager;
|
||||
|
||||
public class CivModCorePlugin extends ACivMod {
|
||||
|
||||
/**
|
||||
* Primary constructor used by the real server
|
||||
*/
|
||||
public CivModCorePlugin() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Secondary constructor used for testing
|
||||
*/
|
||||
protected CivModCorePlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
|
||||
super(loader, description, dataFolder, file);
|
||||
}
|
||||
|
||||
private static CivModCorePlugin instance;
|
||||
|
||||
private CivModCoreConfig config;
|
||||
|
||||
@@ -200,6 +200,7 @@ public final class ChatUtils {
|
||||
* @return Returns true if the component is null or has no visible content.
|
||||
* @deprecated Has been deprecated due to Paper's move to Kyori's Adventure.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isNullOrEmpty(@Nullable final Component component) {
|
||||
if (component == null || component == Component.empty()) {
|
||||
return true;
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.bukkit.entity.EntityType;
|
||||
public final class EntityUtils {
|
||||
|
||||
/**
|
||||
* Attempts to retrieve an entity type by its slug or id.
|
||||
* Attempts to retrieve an entity type by its slug.
|
||||
*
|
||||
* @param value The value to search for a matching entity type by.
|
||||
* @return Returns a matched entity type or null.
|
||||
@@ -23,13 +23,6 @@ public final class EntityUtils {
|
||||
return EntityType.valueOf(value.toUpperCase());
|
||||
} catch (final Throwable ignored) {
|
||||
}
|
||||
try {
|
||||
final EntityType type = EntityType.fromId(Short.parseShort(value));
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
} catch (final Throwable ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.translation.Translatable;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -98,7 +99,7 @@ public final class EnchantUtils {
|
||||
if (!missing.isEmpty()) {
|
||||
//noinspection deprecation
|
||||
LOGGER.warning("The following enchants are missing abbreviations: %s.".formatted(
|
||||
missing.stream().map(Enchantment::getName).collect(Collectors.joining(","))
|
||||
missing.stream().map(Enchantment::getKey).map(NamespacedKey::asString).collect(Collectors.joining(","))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.UUID;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.destroystokyo.paper.utils.PaperPluginLogger;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import io.papermc.paper.plugin.configuration.PluginMeta;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -67,7 +68,7 @@ public final class CivLogger extends Logger {
|
||||
final var descriptionField = FieldUtils.getDeclaredField(PluginClassLoader.class, "description", true);
|
||||
try {
|
||||
final var description = (PluginDescriptionFile) descriptionField.get(loader);
|
||||
final var logger = PaperPluginLogger.getLogger(description);
|
||||
final var logger = PaperPluginLogger.getLogger((PluginMeta) description);
|
||||
return new CivLogger(logger, clazz.getSimpleName());
|
||||
} catch (final IllegalAccessException ignored) {
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("com.github.johnrengelman.shadow")
|
||||
id("com.gradleup.shadow")
|
||||
id("xyz.jpenilla.run-paper")
|
||||
}
|
||||
|
||||
|
||||
@@ -66,8 +66,7 @@ public final class NpcManager {
|
||||
if (plugin.getSettings().playEffect()) {
|
||||
Location l = entity.getLocation();
|
||||
l.getWorld().playEffect(l, Effect.MOBSPAWNER_FLAMES, 0, 64);
|
||||
// NOTE: Do not directly access the values in the sound enum, as that can change across versions\
|
||||
l.getWorld().playSound(l, EXPLODE_SOUND, 0.9F, 0);
|
||||
l.getWorld().playSound(l, Sound.ENTITY_GENERIC_EXPLODE, 0.9F, 0);
|
||||
}
|
||||
|
||||
// Create and start the NPCs despawn task
|
||||
@@ -121,22 +120,4 @@ public final class NpcManager {
|
||||
public boolean hasDespawnTask(Npc npc) {
|
||||
return despawnTasks.containsKey(npc);
|
||||
}
|
||||
|
||||
// Use reflection
|
||||
private static final Sound EXPLODE_SOUND;
|
||||
|
||||
static {
|
||||
Sound sound;
|
||||
try {
|
||||
sound = Sound.valueOf("ENTITY_GENERIC_EXPLODE"); // 1.9 name
|
||||
} catch (IllegalArgumentException e) {
|
||||
try {
|
||||
sound = Sound.valueOf("EXPLODE"); // 1.8 name
|
||||
} catch (IllegalArgumentException e2) {
|
||||
throw new AssertionError("Unable to find explosion sound");
|
||||
}
|
||||
}
|
||||
EXPLODE_SOUND = sound;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.minelink.ctplus;
|
||||
|
||||
import net.minelink.ctplus.compat.base.NpcNameGenerator;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.minelink.ctplus.event.PlayerCombatTagEvent;
|
||||
import net.minelink.ctplus.task.SafeLogoutTask;
|
||||
import net.minelink.ctplus.task.TagUpdateTask;
|
||||
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package net.minelink.ctplus.nms;
|
||||
|
||||
import io.papermc.paper.util.KeepAlive;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class NpcPlayerConnection extends ServerGamePacketListenerImpl {
|
||||
|
||||
public NpcPlayerConnection(ServerPlayer player) {
|
||||
super(MinecraftServer.getServer(), new NpcNetworkManager(), player, new CommonListenerCookie(player.gameProfile, -1, player.clientInformation(), false));
|
||||
super(MinecraftServer.getServer(), new NpcNetworkManager(), player, new CommonListenerCookie(player.gameProfile, -1, player.clientInformation(), false, null, new HashSet<>(), new KeepAlive()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.ProblemReporter;
|
||||
import net.minecraft.world.ItemStackWithSlot;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeMap;
|
||||
@@ -20,6 +22,7 @@ import net.minecraft.world.food.FoodData;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.storage.PlayerDataStorage;
|
||||
import net.minecraft.world.level.storage.TagValueOutput;
|
||||
import net.minelink.ctplus.compat.base.NpcIdentity;
|
||||
import net.minelink.ctplus.compat.base.NpcPlayerHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -73,7 +76,7 @@ public class NpcPlayerHelperImpl implements NpcPlayerHelper {
|
||||
serverPlayer.connection.send(packet);
|
||||
}
|
||||
|
||||
ServerLevel worldServer = entity.serverLevel();
|
||||
ServerLevel worldServer = entity.level();
|
||||
worldServer.chunkSource.removeEntity(entity);
|
||||
worldServer.getPlayers(serverPlayer -> serverPlayer instanceof NpcPlayer).remove(entity);
|
||||
removePlayerList(player);
|
||||
@@ -120,7 +123,7 @@ public class NpcPlayerHelperImpl implements NpcPlayerHelper {
|
||||
List<Pair<EquipmentSlot, ItemStack>> list = Lists.newArrayList();
|
||||
list.add(Pair.of(slot, item));
|
||||
Packet<ClientGamePacketListener> packet = new ClientboundSetEquipmentPacket(entity.getId(), list);
|
||||
entity.serverLevel().chunkSource.broadcast(entity, packet);
|
||||
entity.level().chunkSource.broadcast(entity, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +140,7 @@ public class NpcPlayerHelperImpl implements NpcPlayerHelper {
|
||||
if (p != null && p.isOnline()) return;
|
||||
|
||||
PlayerDataStorage worldStorage = ((CraftWorld) Bukkit.getWorlds().getFirst()).getHandle().getServer().playerDataStorage;
|
||||
CompoundTag playerNbt = worldStorage.load(identity.getName(), identity.getId().toString()).orElse(null);
|
||||
CompoundTag playerNbt = worldStorage.load(identity.getName(), identity.getId().toString(), ProblemReporter.DISCARDING).orElse(null);
|
||||
|
||||
// foodTickTimer is now private in 1.8.3 -- still private in 1.12 -- still private in 1.20.6
|
||||
Field foodTickTimerField;
|
||||
@@ -163,7 +166,8 @@ public class NpcPlayerHelperImpl implements NpcPlayerHelper {
|
||||
playerNbt.putFloat("foodSaturationLevel", entity.getFoodData().getSaturationLevel());
|
||||
playerNbt.putFloat("foodExhaustionLevel", entity.getFoodData().exhaustionLevel);
|
||||
playerNbt.putShort("Fire", (short) entity.getRemainingFireTicks());
|
||||
playerNbt.put("Inventory", npcPlayer.getInventory().save(new ListTag()));
|
||||
TagValueOutput output = TagValueOutput.createWrappingGlobal(ProblemReporter.DISCARDING, playerNbt);
|
||||
npcPlayer.getInventory().save(output.list("Inventory", ItemStackWithSlot.CODEC));
|
||||
|
||||
File file1 = new File(worldStorage.getPlayerDir(), identity.getId() + ".dat.tmp");
|
||||
File file2 = new File(worldStorage.getPlayerDir(), identity.getId() + ".dat");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("com.github.johnrengelman.shadow")
|
||||
id("com.gradleup.shadow")
|
||||
}
|
||||
|
||||
version = "3.0.8"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("com.github.johnrengelman.shadow")
|
||||
id("com.gradleup.shadow")
|
||||
}
|
||||
|
||||
version = "2.0.3"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("com.github.johnrengelman.shadow")
|
||||
id("com.gradleup.shadow")
|
||||
}
|
||||
|
||||
version = "1.0.0"
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
package com.programmerdan.minecraft.simpleadminhacks.hacks.basic;
|
||||
|
||||
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
|
||||
import com.programmerdan.minecraft.simpleadminhacks.framework.BasicHack;
|
||||
import com.programmerdan.minecraft.simpleadminhacks.framework.BasicHackConfig;
|
||||
import com.programmerdan.minecraft.simpleadminhacks.framework.autoload.AutoLoad;
|
||||
import com.programmerdan.minecraft.simpleadminhacks.framework.autoload.DataParser;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import vg.civcraft.mc.civmodcore.entities.EntityUtils;
|
||||
import vg.civcraft.mc.civmodcore.inventory.items.SpawnEggUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class MobCondenser extends BasicHack {
|
||||
|
||||
private Random rng;
|
||||
private Map<EntityType, Double> mobSpawnModifiers;
|
||||
|
||||
@AutoLoad(processor = DataParser.MATERIAL)
|
||||
private List<Material> materialModificationWhitelist;
|
||||
|
||||
public MobCondenser(SimpleAdminHacks plugin, BasicHackConfig config) {
|
||||
super(plugin, config);
|
||||
this.rng = new Random();
|
||||
this.mobSpawnModifiers = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
|
||||
final ConfigurationSection base = this.config.getBase();
|
||||
final ConfigurationSection spawnModifiers = base.getConfigurationSection("mobSpawnModifiers");
|
||||
if (spawnModifiers != null) {
|
||||
for (final String key : spawnModifiers.getKeys(false)) {
|
||||
final EntityType type = EntityUtils.getEntityType(key);
|
||||
if (type == null) {
|
||||
this.plugin.warning("[" + getClass().getSimpleName() + "] EntityType: \"" + key + "\" does not exist, skipping.");
|
||||
continue;
|
||||
}
|
||||
double modifier = spawnModifiers.getDouble(key, 1.0d);
|
||||
if (modifier < 0.0d) {
|
||||
this.plugin.warning("[" + getClass().getSimpleName() + "] Mob Spawn Modifier: \"" + modifier + "\" for \"" + key + "\" is unsupported, defaulting to 1.0");
|
||||
modifier = 1.0d;
|
||||
}
|
||||
this.mobSpawnModifiers.put(type, modifier);
|
||||
this.plugin.info("[" + getClass().getSimpleName() + "] Registered Mob Spawn Modifier: [" + type + ": " + modifier + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.mobSpawnModifiers.clear();
|
||||
|
||||
super.onDisable();
|
||||
}
|
||||
|
||||
private boolean roll(double chance) {
|
||||
return rng.nextDouble() <= chance;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW) //Run before the PortalSpawnModifier
|
||||
public void onCreatureSpawn(CreatureSpawnEvent e) {
|
||||
if (mobSpawnModifiers.containsKey(e.getEntityType())) {
|
||||
if (!roll(mobSpawnModifiers.get(e.getEntityType()))) {
|
||||
if (e.getSpawnReason() != CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) {
|
||||
e.setCancelled(true);
|
||||
} else if (e.getEntity() instanceof Ageable) // Is from a spawn egg, and is Ageable
|
||||
{
|
||||
Ageable ageable = (Ageable) e.getEntity();
|
||||
|
||||
if (!ageable.isAdult()) { //Only spawns from right clicking other mobs with a spawn egg
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMobEggUse(PlayerInteractEvent e) {
|
||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getItem() != null) {
|
||||
try {
|
||||
EntityType type = SpawnEggUtils.getEntityType(e.getItem().getType());
|
||||
|
||||
if (mobSpawnModifiers.containsKey(type)) {
|
||||
if (!roll(mobSpawnModifiers.get(type))) {
|
||||
e.setCancelled(true);
|
||||
e.getItem().setAmount(e.getItem().getAmount() - 1);
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH) //Run after PortalSpawnModifier
|
||||
public void onEntityDeath(EntityDeathEvent e) {
|
||||
if (mobSpawnModifiers.containsKey(e.getEntityType())) {
|
||||
Iterator<ItemStack> iterator = e.getDrops().iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
ItemStack itemStack = iterator.next();
|
||||
if (materialModificationWhitelist.contains(itemStack.getType())) {
|
||||
itemStack.setAmount((int) Math.round(itemStack.getAmount() / mobSpawnModifiers.get(e.getEntityType())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user