Compare commits

...

27 Commits

Author SHA1 Message Date
Auxilor
991290095b Updated to 6.35.8 2022-05-17 10:19:48 +01:00
Auxilor
8735478fc3 More bit manip 2022-05-17 10:19:36 +01:00
Auxilor
6e44f09621 Fixed ItemFlags in FastItemStack 2022-05-17 10:11:04 +01:00
Auxilor
060106881e Updated to 6.35.7 2022-05-13 12:07:26 +01:00
Auxilor
96cc9706b3 Placeholder injection fixes 2022-05-13 12:07:15 +01:00
Auxilor
3d87b1eb73 Revert "Fixed placeholder injection bugs"
This reverts commit 06bcb10958.
2022-05-13 11:46:57 +01:00
Auxilor
4c4247b4ec Revert "Updated to 6.35.7"
This reverts commit b94dc4ac3a.
2022-05-13 11:46:57 +01:00
Auxilor
b94dc4ac3a Updated to 6.35.7 2022-05-13 11:34:58 +01:00
Auxilor
06bcb10958 Fixed placeholder injection bugs 2022-05-13 11:34:42 +01:00
Auxilor
295095e9ce Fixed spelling 2022-05-09 12:34:14 +01:00
Auxilor
ba9c5865e3 Updated to 6.35.6 2022-05-09 12:30:22 +01:00
Auxilor
d24be4121f Added conflict finder 2022-05-09 12:30:14 +01:00
Auxilor
bcc5e4ef08 Skull improvements 2022-05-09 10:23:35 +01:00
Auxilor
bf8609666a Codestyle 2022-05-09 10:20:05 +01:00
Auxilor
1a02335825 Fixed dumbest error of all time 2022-05-09 10:14:18 +01:00
Auxilor
f5ef98ec5c Improved custom item lookup 2022-05-09 10:11:06 +01:00
Auxilor
45135e2b55 Updated to 6.35.5 2022-05-08 17:27:14 +01:00
Auxilor
758b42ff8e Fixed ItemsAdder integration 2022-05-08 17:26:50 +01:00
Auxilor
4a134402da Fixed Prerequisite#HAS_PAPER 2022-05-06 09:09:54 +01:00
Auxilor
e6ad4c9268 Updated to 6.35.4 2022-05-06 09:08:38 +01:00
Auxilor
809dcbae85 Improved NaturalExpGainListeners for paper 2022-05-06 09:07:57 +01:00
Auxilor
d7fce6834c Updated to 6.35.3 2022-05-03 13:05:41 +01:00
Auxilor
ac807a991b Players can no longer tab-complete commands they don't have permission for 2022-05-03 13:05:32 +01:00
Auxilor
ba315ced3c Updated to 6.35.2 2022-04-29 22:45:42 +01:00
Auxilor
f2e65174f9 Reverted to old block vein code 2022-04-29 22:45:02 +01:00
Auxilor
d5584e863b Updated to 6.35.1 2022-04-27 18:52:39 +01:00
Auxilor
d9c0e8e763 Fixed overload resolution ambiguity 2022-04-27 18:52:27 +01:00
18 changed files with 173 additions and 60 deletions

View File

@@ -376,12 +376,12 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
PlaceholderManager.addIntegration(Eco.getHandler().createPAPIIntegration(this)); PlaceholderManager.addIntegration(Eco.getHandler().createPAPIIntegration(this));
} }
this.loadIntegrationLoaders().forEach((integrationLoader -> { this.loadIntegrationLoaders().forEach(integrationLoader -> {
if (enabledPlugins.contains(integrationLoader.getPluginName().toLowerCase())) { if (enabledPlugins.contains(integrationLoader.getPluginName().toLowerCase())) {
this.loadedIntegrations.add(integrationLoader.getPluginName()); this.loadedIntegrations.add(integrationLoader.getPluginName());
integrationLoader.load(); integrationLoader.load();
} }
})); });
this.getLogger().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations())); this.getLogger().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations()));

View File

@@ -26,7 +26,7 @@ public class Prerequisite {
* Requires the server to be running an implementation of paper. * Requires the server to be running an implementation of paper.
*/ */
public static final Prerequisite HAS_PAPER = new Prerequisite( public static final Prerequisite HAS_PAPER = new Prerequisite(
() -> ClassUtils.exists("com.destroystokyo.paper.event.player.PlayerElytraBoostEvent"), () -> ClassUtils.exists("com.destroystokyo.paper.event.block.BeaconEffectEvent"),
"Requires server to be running paper (or a fork)" "Requires server to be running paper (or a fork)"
); );

View File

@@ -167,7 +167,10 @@ abstract class HandledCommand implements CommandBase {
StringUtil.copyPartialMatches( StringUtil.copyPartialMatches(
args[0], args[0],
this.getSubcommands().stream().map(CommandBase::getName).collect(Collectors.toList()), this.getSubcommands().stream()
.filter(subCommand -> sender.hasPermission(subCommand.getPermission()))
.map(CommandBase::getName)
.collect(Collectors.toList()),
completions completions
); );
@@ -182,6 +185,10 @@ abstract class HandledCommand implements CommandBase {
HandledCommand command = null; HandledCommand command = null;
for (CommandBase subcommand : this.getSubcommands()) { for (CommandBase subcommand : this.getSubcommands()) {
if (!sender.hasPermission(subcommand.getPermission())) {
continue;
}
if (args[0].equalsIgnoreCase(subcommand.getName())) { if (args[0].equalsIgnoreCase(subcommand.getName())) {
command = (HandledCommand) subcommand; command = (HandledCommand) subcommand;
} }

View File

@@ -222,7 +222,10 @@ public final class Items {
if (part == null && PROVIDERS.containsKey(namespace)) { if (part == null && PROVIDERS.containsKey(namespace)) {
ItemProvider provider = PROVIDERS.get(namespace); ItemProvider provider = PROVIDERS.get(namespace);
item = provider.provideForKey(keyID);
String reformattedKey = keyID.replace("__", ":");
item = provider.provideForKey(reformattedKey);
if (item instanceof EmptyTestableItem || item == null) { if (item instanceof EmptyTestableItem || item == null) {
return new EmptyTestableItem(); return new EmptyTestableItem();
} }

View File

@@ -23,26 +23,25 @@ public final class BlockUtils {
*/ */
private static final int MAX_BLOCKS = 2500; private static final int MAX_BLOCKS = 2500;
private static Set<Block> getNearbyBlocks(@NotNull final Block origin, private static Set<Block> getNearbyBlocks(@NotNull final Block start,
@NotNull final List<Material> allowedMaterials, @NotNull final List<Material> allowedMaterials,
@NotNull final Set<Block> blocks, @NotNull final Set<Block> blocks,
final int limit) { final int limit) {
for (BlockFace face : BlockFace.values()) { for (BlockFace face : BlockFace.values()) {
Block block = origin.getRelative(face); Block block = start.getRelative(face);
if (!allowedMaterials.contains(block.getType())) {
continue;
}
if (blocks.contains(block)) { if (blocks.contains(block)) {
continue; continue;
} }
if (blocks.size() >= limit || blocks.size() > MAX_BLOCKS) { if (allowedMaterials.contains(block.getType())) {
return blocks; blocks.add(block);
}
blocks.addAll(getNearbyBlocks(block, allowedMaterials, blocks, limit)); if (blocks.size() > limit || blocks.size() > MAX_BLOCKS) {
return blocks;
}
blocks.addAll(getNearbyBlocks(block, allowedMaterials, blocks, limit));
}
} }
return blocks; return blocks;

View File

@@ -32,12 +32,6 @@ fun CommandSender.asAudience(): Audience =
fun Player.runExempted(action: () -> Unit) = fun Player.runExempted(action: () -> Unit) =
PlayerUtils.runExempted(this, action) PlayerUtils.runExempted(this, action)
/**
* @see PlayerUtils.runExempted
*/
fun Player.runExempted(action: (Player) -> Unit) =
PlayerUtils.runExempted(this, action)
/** /**
* @see PlayerUtils.tryAsPlayer * @see PlayerUtils.tryAsPlayer
*/ */

View File

@@ -103,11 +103,13 @@ open class EcoConfig(
} }
override fun getSubsectionOrNull(path: String): Config? { override fun getSubsectionOrNull(path: String): Config? {
return get(path) as? Config return (get(path) as? Config)?.apply { this.addInjectablePlaceholder(injections) }
} }
override fun getSubsectionsOrNull(path: String): List<Config>? { override fun getSubsectionsOrNull(path: String): List<Config>? {
return (get(path) as? Iterable<Config>)?.toList() return (get(path) as? Iterable<Config>)
?.map { it.apply { this.addInjectablePlaceholder(injections) } }
?.toList()
} }
override fun getType(): ConfigType { override fun getType(): ConfigType {

View File

@@ -26,6 +26,8 @@ import org.bukkit.inventory.ItemFlag
import org.bukkit.persistence.PersistentDataContainer import org.bukkit.persistence.PersistentDataContainer
import org.bukkit.persistence.PersistentDataType import org.bukkit.persistence.PersistentDataType
import kotlin.experimental.and import kotlin.experimental.and
import kotlin.experimental.inv
import kotlin.experimental.or
@Suppress("UsePropertyAccessSyntax") @Suppress("UsePropertyAccessSyntax")
class EcoFastItemStack( class EcoFastItemStack(
@@ -149,35 +151,25 @@ class EcoFastItemStack(
override fun getDisplayName(): String = displayNameComponent.toLegacy() override fun getDisplayName(): String = displayNameComponent.toLegacy()
override fun addItemFlags(vararg hideFlags: ItemFlag) { override fun addItemFlags(vararg hideFlags: ItemFlag) {
for (flag in hideFlags) { for (f in hideFlags) {
this.flagBits = this.flagBits or getBitModifier(flag) this.flagBits = this.flagBits or getBitModifier(f)
} }
apply()
} }
override fun removeItemFlags(vararg hideFlags: ItemFlag) { override fun removeItemFlags(vararg hideFlags: ItemFlag) {
for (flag in hideFlags) { for (f in hideFlags) {
this.flagBits = this.flagBits and getBitModifier(flag) this.flagBits = this.flagBits and getBitModifier(f).inv()
} }
apply()
} }
override fun getItemFlags(): MutableSet<ItemFlag> { override fun getItemFlags(): Set<ItemFlag> {
val flags = mutableSetOf<ItemFlag>() val currentFlags = mutableSetOf<ItemFlag>()
for (f in ItemFlag.values()) {
var flagArr: Array<ItemFlag> if (hasItemFlag(f)) {
val size = ItemFlag.values().also { flagArr = it }.size currentFlags.add(f)
for (i in 0 until size) {
val flag = flagArr[i]
if (this.hasItemFlag(flag)) {
flags.add(flag)
} }
} }
return currentFlags
return flags
} }
override fun hasItemFlag(flag: ItemFlag): Boolean { override fun hasItemFlag(flag: ItemFlag): Boolean {
@@ -194,15 +186,15 @@ class EcoFastItemStack(
} }
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION") @Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
private var flagBits: Int private var flagBits: Byte
get() = get() =
if (handle.hasTag() && handle.getTag()!!.contains( if (handle.hasTag() && handle.getTag()!!.contains(
"HideFlags", "HideFlags",
99 99
) )
) handle.getTag()!!.getInt("HideFlags") else 0 ) handle.getTag()!!.getInt("HideFlags").toByte() else 0
set(value) = set(value) =
handle.getOrCreateTag().putInt("HideFlags", value) handle.getOrCreateTag().putInt("HideFlags", value.toInt())
override fun getRepairCost(): Int { override fun getRepairCost(): Int {
return handle.getBaseRepairCost() return handle.getBaseRepairCost()
@@ -268,8 +260,8 @@ class EcoFastItemStack(
bukkit.mergeIfNeeded(handle) bukkit.mergeIfNeeded(handle)
} }
private fun getBitModifier(hideFlag: ItemFlag): Int { private fun getBitModifier(hideFlag: ItemFlag): Byte {
return 1 shl hideFlag.ordinal return (1 shl hideFlag.ordinal).toByte()
} }
override fun unwrap(): org.bukkit.inventory.ItemStack { override fun unwrap(): org.bukkit.inventory.ItemStack {

View File

@@ -20,6 +20,10 @@ class Skull : SkullProxy {
setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java) setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java)
setProfile.isAccessible = true setProfile.isAccessible = true
} }
if (base64.length < 20) {
return
}
val uuid = UUID( val uuid = UUID(
base64.substring(base64.length - 20).hashCode().toLong(), base64.substring(base64.length - 20).hashCode().toLong(),
base64.substring(base64.length - 10).hashCode().toLong() base64.substring(base64.length - 10).hashCode().toLong()
@@ -39,6 +43,6 @@ class Skull : SkullProxy {
val profile = profile[meta] as GameProfile? ?: return null val profile = profile[meta] as GameProfile? ?: return null
val properties = profile.properties ?: return null val properties = profile.properties ?: return null
val prop = properties["textures"] ?: return null val prop = properties["textures"] ?: return null
return prop.toMutableList().firstOrNull()?.value return prop.toMutableList().firstOrNull()?.name
} }
} }

View File

@@ -20,6 +20,10 @@ class Skull : SkullProxy {
setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java) setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java)
setProfile.isAccessible = true setProfile.isAccessible = true
} }
if (base64.length < 20) {
return
}
val uuid = UUID( val uuid = UUID(
base64.substring(base64.length - 20).hashCode().toLong(), base64.substring(base64.length - 20).hashCode().toLong(),
base64.substring(base64.length - 10).hashCode().toLong() base64.substring(base64.length - 10).hashCode().toLong()
@@ -39,6 +43,6 @@ class Skull : SkullProxy {
val profile = profile[meta] as GameProfile? ?: return null val profile = profile[meta] as GameProfile? ?: return null
val properties = profile.properties ?: return null val properties = profile.properties ?: return null
val prop = properties["textures"] ?: return null val prop = properties["textures"] ?: return null
return prop.toMutableList().firstOrNull()?.value return prop.toMutableList().firstOrNull()?.name
} }
} }

View File

@@ -20,6 +20,10 @@ class Skull : SkullProxy {
setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java) setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java)
setProfile.isAccessible = true setProfile.isAccessible = true
} }
if (base64.length < 20) {
return
}
val uuid = UUID( val uuid = UUID(
base64.substring(base64.length - 20).hashCode().toLong(), base64.substring(base64.length - 20).hashCode().toLong(),
base64.substring(base64.length - 10).hashCode().toLong() base64.substring(base64.length - 10).hashCode().toLong()
@@ -39,6 +43,6 @@ class Skull : SkullProxy {
val profile = profile[meta] as GameProfile? ?: return null val profile = profile[meta] as GameProfile? ?: return null
val properties = profile.properties ?: return null val properties = profile.properties ?: return null
val prop = properties["textures"] ?: return null val prop = properties["textures"] ?: return null
return prop.toMutableList().firstOrNull()?.value return prop.toMutableList().firstOrNull()?.name
} }
} }

View File

@@ -17,7 +17,7 @@ dependencies {
// Included in spigot jar // Included in spigot jar
compileOnly 'com.google.code.gson:gson:2.8.8' compileOnly 'com.google.code.gson:gson:2.8.8'
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT' compileOnly 'io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT'
// Plugin dependencies // Plugin dependencies
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.1-SNAPSHOT' compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.1-SNAPSHOT'

View File

@@ -0,0 +1,59 @@
package com.willfp.eco.internal.spigot
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.util.containsIgnoreCase
import org.bukkit.Bukkit
import org.bukkit.plugin.Plugin
import java.io.File
import java.util.zip.ZipFile
object ConflictFinder {
fun searchForConflicts(eco: EcoPlugin): List<Conflict> {
val conflicts = mutableListOf<Conflict>()
for (plugin in Bukkit.getPluginManager().plugins) {
if (eco.configYml.getStrings("conflicts.whitelist").containsIgnoreCase(plugin.name)) {
continue
}
val conflict = plugin.getConflict()
if (conflict != null) {
conflicts.add(conflict)
}
}
return conflicts
}
}
data class Conflict(
val plugin: Plugin,
val conflictType: ConflictType
) {
val conflictMessage: String
get() = "${plugin.name} will likely conflict with eco! Reason: ${conflictType.friendlyMessage}"
}
enum class ConflictType(
val friendlyMessage: String
) {
LIB_LOADER("Kotlin found in libraries (lib-loader)"),
KOTLIN_SHADE("Kotlin shaded into jar");
}
private fun Plugin.getConflict(): Conflict? {
if (this.description.libraries.any { it.contains("kotlin-stdlib") }) {
return Conflict(this, ConflictType.LIB_LOADER)
}
val zip = ZipFile(File(this::class.java.protectionDomain.codeSource.location.toURI()))
for (entry in zip.entries()) {
if (entry.name.startsWith("kotlin/")) {
return Conflict(this, ConflictType.KOTLIN_SHADE)
}
}
return null
}

View File

@@ -63,7 +63,8 @@ import com.willfp.eco.internal.spigot.display.PacketWindowItems
import com.willfp.eco.internal.spigot.display.frame.clearFrames import com.willfp.eco.internal.spigot.display.frame.clearFrames
import com.willfp.eco.internal.spigot.drops.CollatedRunnable import com.willfp.eco.internal.spigot.drops.CollatedRunnable
import com.willfp.eco.internal.spigot.eventlisteners.EntityDeathByEntityListeners import com.willfp.eco.internal.spigot.eventlisteners.EntityDeathByEntityListeners
import com.willfp.eco.internal.spigot.eventlisteners.NaturalExpGainListeners import com.willfp.eco.internal.spigot.eventlisteners.NaturalExpGainListenersPaper
import com.willfp.eco.internal.spigot.eventlisteners.NaturalExpGainListenersSpigot
import com.willfp.eco.internal.spigot.eventlisteners.PlayerJumpListenersPaper import com.willfp.eco.internal.spigot.eventlisteners.PlayerJumpListenersPaper
import com.willfp.eco.internal.spigot.eventlisteners.PlayerJumpListenersSpigot import com.willfp.eco.internal.spigot.eventlisteners.PlayerJumpListenersSpigot
import com.willfp.eco.internal.spigot.eventlisteners.armor.ArmorChangeEventListeners import com.willfp.eco.internal.spigot.eventlisteners.armor.ArmorChangeEventListeners
@@ -191,7 +192,27 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
} }
override fun handleEnable() { override fun handleEnable() {
this.logger.info("Scanning for conflicts...")
val conflicts = ConflictFinder.searchForConflicts(this)
for (conflict in conflicts) {
this.logger.warning(conflict.conflictMessage)
}
if (conflicts.isNotEmpty()) {
this.logger.warning(
"You can fix the conflicts by either removing the conflicting plugins, " +
"or by asking on the support discord to have them patched!"
)
this.logger.warning(
"Only remove potentially conflicting plugins if you see " +
"Loader Constraint Violation / LinkageError anywhere"
)
} else {
this.logger.info("No conflicts found!")
}
CollatedRunnable(this) CollatedRunnable(this)
CustomItemsManager.registerProviders() // Do it again here
// Register events for ShopSellEvent // Register events for ShopSellEvent
ShopManager.registerEvents(this) ShopManager.registerEvents(this)
@@ -329,7 +350,6 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
override fun loadListeners(): List<Listener> { override fun loadListeners(): List<Listener> {
val listeners = mutableListOf( val listeners = mutableListOf(
NaturalExpGainListeners(),
ArmorListener(), ArmorListener(),
EntityDeathByEntityListeners(this), EntityDeathByEntityListeners(this),
CraftingRecipeListener(), CraftingRecipeListener(),
@@ -343,8 +363,10 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
if (Prerequisite.HAS_PAPER.isMet) { if (Prerequisite.HAS_PAPER.isMet) {
listeners.add(PlayerJumpListenersPaper()) listeners.add(PlayerJumpListenersPaper())
listeners.add(NaturalExpGainListenersPaper())
} else { } else {
listeners.add(PlayerJumpListenersSpigot()) listeners.add(PlayerJumpListenersSpigot())
listeners.add(NaturalExpGainListenersSpigot())
} }
return listeners return listeners

View File

@@ -1,11 +1,28 @@
package com.willfp.eco.internal.spigot.eventlisteners package com.willfp.eco.internal.spigot.eventlisteners
import com.willfp.eco.core.events.NaturalExpGainEvent
import org.bukkit.Bukkit
import org.bukkit.entity.ThrownExpBottle
import org.bukkit.event.EventHandler import org.bukkit.event.EventHandler
import org.bukkit.event.Listener import org.bukkit.event.Listener
import org.bukkit.event.entity.ExpBottleEvent import org.bukkit.event.entity.ExpBottleEvent
import org.bukkit.event.player.PlayerExpChangeEvent import org.bukkit.event.player.PlayerExpChangeEvent
class NaturalExpGainListeners : Listener { class NaturalExpGainListenersPaper : Listener {
@EventHandler
fun onEvent(event: PlayerExpChangeEvent) {
val source = event.source
if (source is ThrownExpBottle) {
return
}
val ecoEvent = NaturalExpGainEvent(event)
Bukkit.getPluginManager().callEvent(ecoEvent)
}
}
class NaturalExpGainListenersSpigot : Listener {
private val events: MutableSet<NaturalExpGainBuilder> = HashSet() private val events: MutableSet<NaturalExpGainBuilder> = HashSet()
@EventHandler @EventHandler

View File

@@ -21,7 +21,9 @@ class CustomItemsItemsAdder : CustomItemsIntegration {
private class ItemsAdderProvider : ItemProvider("itemsadder") { private class ItemsAdderProvider : ItemProvider("itemsadder") {
override fun provideForKey(key: String): TestableItem? { override fun provideForKey(key: String): TestableItem? {
val item = CustomStack.getInstance("itemsadder:$key") ?: return null val internalId = if (key.contains(":")) key else "itemsadder:$key"
val item = CustomStack.getInstance(internalId) ?: return null
val id = item.id val id = item.id
val namespacedKey = NamespacedKeyUtils.create("itemsadder", key) val namespacedKey = NamespacedKeyUtils.create("itemsadder", key)
val stack = item.itemStack val stack = item.itemStack
@@ -34,6 +36,5 @@ class CustomItemsItemsAdder : CustomItemsIntegration {
stack stack
) )
} }
} }
} }

View File

@@ -19,6 +19,11 @@ mysql:
user: username user: username
password: passy password: passy
# Options to manage the conflict finder
conflicts:
whitelist: # Plugins that should never be marked as conflicts
- eco
# Options to fix villager bugs left behind from old (buggy) versions. # Options to fix villager bugs left behind from old (buggy) versions.
villager-display-fix: false villager-display-fix: false

View File

@@ -1,3 +1,3 @@
version = 6.35.0 version = 6.35.8
plugin-name = eco plugin-name = eco
kotlin.code.style = official kotlin.code.style = official