Updated to 1.20.4
This commit is contained in:
WildInterloper 2024-03-08 15:26:36 -05:00
parent d753abd2b2
commit fb638af6fe
20 changed files with 805 additions and 0 deletions

66
.gitignore vendored Normal file
View File

@ -0,0 +1,66 @@
# Intellij
.idea/
*.iml
*.iws
dependency-reduced-pom.xml
settings.properties
# Eclipse
.classpath
.project
.settings/
# NetBeans
nbproject/
# Mac
.DS_Store
# Maven
log/
target/
# JRebel
.rebel.xml
.rebel-remote.xml
rebel.xml
rebel-remote.xml
build.xml
# Visual Studio
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
*.dll
*.lib
*.sbr
# Artifacts
*.class
# Other
minecraft/1.8.8
bin/
dist/
manifest.mf
Thumbs.db
*.sh
# Generated
.git-versioned-pom.xml
pom.xml.versionsBackup

9
.mvn/extensions.xml Normal file
View File

@ -0,0 +1,9 @@
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 https://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>me.qoomon</groupId>
<artifactId>maven-git-versioning-extension</artifactId>
<version>9.0.1</version>
</extension>
</extensions>

View File

@ -0,0 +1,29 @@
<configuration xmlns="https://github.com/qoomon/maven-git-versioning-extension"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://github.com/qoomon/maven-git-versioning-extension https://qoomon.github.io/maven-git-versioning-extension/configuration-7.0.0.xsd">
<refs>
<!-- Master Branches -->
<!-- Format: <version> -->
<!-- Must manually increase version number -->
<ref type="branch">
<pattern>main</pattern>
<version>${version.release}</version>
</ref>
<ref type="branch">
<pattern>master</pattern>
<version>${version.release}</version>
</ref>
<!-- Development Branches -->
<!-- Format: <version>-DEV -->
<ref type="branch">
<pattern>development</pattern>
<version>${version.release}-DEV</version>
</ref>
<!-- Format: <branch_name>-SNAPSHOT -->
<ref type="branch">
<pattern>.+</pattern>
<version>${ref.slug}-SNAPSHOT</version>
</ref>
</refs>
</configuration>

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Illuzionz Studios
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

130
pom.xml Normal file
View File

@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.illuzionzstudios</groupId>
<artifactId>CustomFishing</artifactId>
<version>5.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
<kotlin.version>1.7.0</kotlin.version>
</properties>
<repositories>
<repository>
<id>nms-repo</id>
<url>https://repo.codemc.org/repository/nms/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
</repositories>
<dependencies>
<!-- <dependency>-->
<!-- <groupId>com.github.IlluzionzDev</groupId>-->
<!-- <artifactId>Mist</artifactId>-->
<!-- <version>9d4b8f8549</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.illuzionzstudios</groupId>-->
<!-- <artifactId>mist</artifactId>-->
<!-- <version>1.0.4</version>-->
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/src/main/libs/Mist-1.0.4.jar</systemPath>-->
<!-- </dependency>-->
<dependency>
<groupId>com.illuzionzstudios</groupId>
<artifactId>mist</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<finalName>CustomFishing-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<relocations>
<relocation>
<pattern>com.illuzionzstudios.mist</pattern>
<shadedPattern>com.illuzionzstudios.customfishing.mist</shadedPattern>
</relocation>
<relocation>
<pattern>kotlin</pattern>
<shadedPattern>com.illuzionzstudios.customfishing.kotlin</shadedPattern>
</relocation>
</relocations>
<createDependencyReducedPom>true</createDependencyReducedPom>
<shadedArtifactAttached>false</shadedArtifactAttached>
<minimizeJar>true</minimizeJar>
</configuration>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/resources/</directory>
</resource>
</resources>
</build>
</project>

View File

@ -0,0 +1,49 @@
package com.illuzionzstudios.customfishing
import com.illuzionzstudios.customfishing.command.CustomFishingCommand
import com.illuzionzstudios.customfishing.reward.RewardController
import com.illuzionzstudios.customfishing.reward.fishing.FishingController
import com.illuzionzstudios.customfishing.settings.Locale
import com.illuzionzstudios.customfishing.settings.Settings
import com.illuzionzstudios.mist.config.PluginSettings
import com.illuzionzstudios.mist.config.locale.PluginLocale
import com.illuzionzstudios.mist.plugin.SpigotPlugin
import org.bukkit.ChatColor
class CustomFishing : SpigotPlugin(7247) {
override val pluginColor: ChatColor = ChatColor.LIGHT_PURPLE
override val pluginId: Int = 53634
override val pluginLocale: PluginLocale
get() = Locale(this)
override val pluginSettings: PluginSettings
get() = Settings(this)
override fun onPluginDisable() {
}
override fun onPluginEnable() {
}
override fun onPluginLoad() {
}
override fun onPluginPreEnable() {
}
override fun onPluginPreReload() {
}
override fun onPluginReload() {
}
override fun onRegisterReloadables() {
registerMainCommand(CustomFishingCommand(), "fishing", "customfishing")
reloadables.registerController(RewardController)
reloadables.registerController(FishingController)
}
}

View File

@ -0,0 +1,13 @@
package com.illuzionzstudios.customfishing.command
import com.illuzionzstudios.mist.command.SpigotCommandGroup
import com.illuzionzstudios.mist.command.SpigotSubCommand
import com.illuzionzstudios.mist.command.response.ReturnType
import com.illuzionzstudios.mist.command.type.ReloadCommand
class CustomFishingCommand : SpigotCommandGroup() {
override fun registerSubcommands() {
registerSubCommand(ReloadCommand())
}
}

View File

@ -0,0 +1,16 @@
package com.illuzionzstudios.customfishing.reward
import org.bukkit.entity.Player
import org.bukkit.event.Event
/**
* An instance of a reward that triggers on a bukkit event
*/
interface EventReward<E : Event> {
/**
* Reward a player when the event triggers
*/
fun reward(player: Player, event: E)
}

View File

@ -0,0 +1,49 @@
package com.illuzionzstudios.customfishing.reward
import com.illuzionzstudios.customfishing.reward.fishing.FishingReward
import com.illuzionzstudios.customfishing.reward.fishing.loader.FishingRewardLoader
import com.illuzionzstudios.mist.Logger
import com.illuzionzstudios.mist.config.serialization.loader.DirectoryLoader
import com.illuzionzstudios.mist.controller.PluginController
import com.illuzionzstudios.mist.plugin.SpigotPlugin
import com.illuzionzstudios.mist.random.LootTable
import org.bukkit.entity.Player
object RewardController : PluginController {
/**
* All loaded fishing rewards
*/
val loadedRewards: MutableSet<FishingReward> = HashSet()
override fun initialize(plugin: SpigotPlugin) {
loadedRewards.clear()
// Load rewards
DirectoryLoader(
FishingRewardLoader::class.java,
"rewards",
listOf("demo_reward.yml")
).loaders.forEach {
loadedRewards.add(it.`object`)
Logger.info("Loading fishing reward '${it.`object`.name}'")
}
}
override fun stop(plugin: SpigotPlugin) {
}
fun pickReward(player: Player): FishingReward? {
// Load loot for player
val lootTable: LootTable<FishingReward> = LootTable()
loadedRewards.forEach {
var passTests = true
it.requirements?.forEach { requirement -> if (!requirement.test(player)) passTests = false }
if (passTests) {
lootTable.addLoot(it, it.chance)
}
}
return lootTable.pick()
}
}

View File

@ -0,0 +1,54 @@
package com.illuzionzstudios.customfishing.reward.fishing
import com.illuzionzstudios.customfishing.reward.RewardController
import com.illuzionzstudios.customfishing.settings.Settings
import com.illuzionzstudios.mist.compatibility.ServerVersion.V
import com.illuzionzstudios.mist.compatibility.ServerVersion.atLeast
import com.illuzionzstudios.mist.controller.PluginController
import com.illuzionzstudios.mist.plugin.SpigotPlugin
import com.illuzionzstudios.mist.random.RandomNumberGenerator
import com.illuzionzstudios.mist.util.MathUtil
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.player.PlayerFishEvent
object FishingController : PluginController {
override fun initialize(plugin: SpigotPlugin) {
}
override fun stop(plugin: SpigotPlugin) {
}
@EventHandler
fun onFish(event: PlayerFishEvent) {
if (atLeast(V.v1_16)) {
// Custom hook features
val hook = event.hook
hook.minWaitTime = Settings.MIN_WAIT_TIME.int
hook.maxWaitTime = Settings.MAX_WAIT_TIME.int
}
// Detect if they catch a fish
if (event.state == PlayerFishEvent.State.CAUGHT_FISH) {
// Set experience default reward
event.expToDrop = RandomNumberGenerator.parse(Settings.EXP_REWARD.getString("1 to 6")).generate().toInt()
// Detect if they actually get a reward
if (MathUtil.chance(Settings.REWARD_CHANCE.double))
processRewards(event.player, event)
}
}
/**
* Process rewards for a player. All calculations
* will be done here, and if null, will rerun until reward is picked.
*
* @param player Player to reward
* @param event The fishing event
*/
private fun processRewards(player: Player, event: PlayerFishEvent) {
// Try reward. Kotlin will handle null checks :)
val reward: FishingReward? = RewardController.pickReward(player)
reward?.reward(player, event)
}
}

View File

@ -0,0 +1,120 @@
package com.illuzionzstudios.customfishing.reward.fishing
import com.cryptomorin.xseries.XSound
import com.illuzionzstudios.customfishing.reward.EventReward
import com.illuzionzstudios.customfishing.reward.fishing.item.FishingItem
import com.illuzionzstudios.mist.config.locale.MistString
import com.illuzionzstudios.mist.config.locale.mist
import com.illuzionzstudios.mist.random.RandomNumberGenerator
import com.illuzionzstudios.mist.requirement.PlayerRequirement
import com.illuzionzstudios.mist.util.MathUtil
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.event.player.PlayerFishEvent
/**
* A fishing reward that can be caught in the water
*/
class FishingReward : EventReward<PlayerFishEvent> {
/**
* Name of the reward
*/
var name: String? = null
/**
* Commands to execute
*/
var commands: List<String>? = ArrayList()
/**
* Custom items to give. Built in the reward loader
*/
var items: List<FishingItem>? = ArrayList()
/**
* Messages to send
*/
var messages: List<String>? = ArrayList()
/**
* Broadcast messages to send
*/
var broadcasts: List<String>? = ArrayList()
/**
* Title message
*/
var title: String? = null
/**
* Subtitle message
*/
var subtitle: String? = null
/**
* Chance to find this reward
*/
var chance = 0.0
/**
* If default vanilla rewards are enabled
*/
var vanillaRewards = false
/**
* Experience to give the player in a range. E.g "1 to 6"
*/
var experienceRange: RandomNumberGenerator = RandomNumberGenerator(1.0, 6.0)
/**
* Sound to play
*/
var sound: XSound? = null
/**
* Requirements for this reward
*/
var requirements: List<PlayerRequirement>? = ArrayList()
override fun reward(player: Player, event: PlayerFishEvent) {
// Get global reward placeholders
val rewardPlaceholders: MutableMap<String, Any> = HashMap()
rewardPlaceholders["player"] = player.name
// Try reward actual items (commands and items)
commands?.forEach {
var replacer = MistString(it)
replacer = replacer.toString(rewardPlaceholders)
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), replacer.toString())
}
// Roll items
items?.forEach {
if (MathUtil.chance(it.chance)) it.givePlayer(player)
}
// Exp and vanilla rewards
event.expToDrop = this.experienceRange.generate().toInt()
if (!vanillaRewards) event.caught?.remove()
// Messages and cosmetics
this.sound?.play(player.location)
title?.mist?.sendTitle(player, subtitle?.mist)
// Messages
messages?.forEach { message ->
val toSend = message.mist.toString(rewardPlaceholders)
toSend.sendMessage(player)
}
// Global Messages
broadcasts?.forEach { broadcast ->
val toSend = broadcast.mist.toString(rewardPlaceholders)
Bukkit.getOnlinePlayers().forEach {
toSend.sendMessage(it)
}
}
}
}

View File

@ -0,0 +1,15 @@
package com.illuzionzstudios.customfishing.reward.fishing.item
import com.illuzionzstudios.mist.item.CustomItem
/**
* A custom item that can be caught from fishing
*/
class FishingItem : CustomItem() {
/**
* Chance of this item being caught out of 100
*/
var chance: Double = 100.0
}

View File

@ -0,0 +1,16 @@
package com.illuzionzstudios.customfishing.reward.fishing.loader
import com.illuzionzstudios.customfishing.reward.fishing.item.FishingItem
import com.illuzionzstudios.mist.config.ConfigSection
import com.illuzionzstudios.mist.item.loader.BaseCustomItemLoader
class FishingItemLoader(section: ConfigSection) : BaseCustomItemLoader<FishingItem>(section) {
override fun returnImplementedObject(section: ConfigSection?): FishingItem {
// Lets try build the reward
val item = FishingItem()
item.chance = section?.getDouble("chance") ?: 0.0
return item
}
}

View File

@ -0,0 +1,58 @@
package com.illuzionzstudios.customfishing.reward.fishing.loader
import com.cryptomorin.xseries.XSound
import com.illuzionzstudios.customfishing.reward.fishing.FishingReward
import com.illuzionzstudios.customfishing.reward.fishing.item.FishingItem
import com.illuzionzstudios.mist.config.ConfigSection
import com.illuzionzstudios.mist.config.YamlConfig
import com.illuzionzstudios.mist.config.locale.MistString
import com.illuzionzstudios.mist.config.serialization.loader.YamlFileLoader
import com.illuzionzstudios.mist.random.RandomNumberGenerator
import com.illuzionzstudios.mist.requirement.PlayerRequirement
import com.illuzionzstudios.mist.requirement.PlayerRequirementLoader
/**
* Load a fishing reward from a file
*/
class FishingRewardLoader(directory: String, fileName: String) : YamlFileLoader<FishingReward>(directory, fileName) {
override fun loadYamlObject(file: YamlConfig?): FishingReward {
val reward = FishingReward()
reward.name = file?.getString("name")
reward.commands = file?.getStringList("commands")
val items: MutableList<FishingItem> = ArrayList()
file?.getSections("items")?.forEach {
items.add(FishingItemLoader(it!!).`object`)
}
reward.items = items
reward.messages = file?.getStringList("messages")
reward.broadcasts = file?.getStringList("broadcasts")
reward.title = file?.getString("title")
reward.subtitle = file?.getString("sub-title")
reward.chance = file?.getDouble("weight") ?: 0.0
reward.vanillaRewards = file?.getBoolean("vanilla-rewards") ?: false
reward.experienceRange = RandomNumberGenerator.parse(file?.getString("exp-amount") ?: "1 to 6")
try {
reward.sound = XSound.matchXSound(config?.getString("sound") ?: "").get()
} catch (ignored: Exception) {
}
// Load requirements
val requirements: MutableList<PlayerRequirement> = ArrayList()
file?.getSections("requirements")?.forEach {
requirements.add(PlayerRequirementLoader(it!!).`object`)
}
reward.requirements = requirements
return reward
}
override fun saveYaml() {
TODO("Not yet implemented")
}
}

View File

@ -0,0 +1,12 @@
package com.illuzionzstudios.customfishing.settings
import com.illuzionzstudios.mist.config.locale.PluginLocale
import com.illuzionzstudios.mist.plugin.SpigotPlugin
class Locale(plugin: SpigotPlugin): PluginLocale(plugin) {
companion object {
var GENERAL_PLUGIN_SAVE = createString("general.save", "&7Saved all rewards")
}
}

View File

@ -0,0 +1,47 @@
package com.illuzionzstudios.customfishing.settings
import com.illuzionzstudios.mist.config.ConfigSetting
import com.illuzionzstudios.mist.config.PluginSettings
import com.illuzionzstudios.mist.plugin.SpigotPlugin
class Settings(plugin: SpigotPlugin) : PluginSettings(plugin) {
override fun loadSettings() {
}
companion object {
/**
* The chance of finding a custom reward
*/
var REWARD_CHANCE: ConfigSetting = GENERAL_GROUP.create(
"fishing.reward-chance", 100.0,
"The chance of finding a custom reward while fishing", "can be a decimal number."
)
/**
* Amount of EXP rewarded from fishing when no custom reward
*/
var EXP_REWARD: ConfigSetting = GENERAL_GROUP.create(
"fishing.exp-reward",
"1 to 6",
"Amount of experience to give the player when they HAVEN'T found a custom reward.",
"X to Y indicates a range between two numbers.",
"0 indicates to not reward exp."
)
var MIN_WAIT_TIME: ConfigSetting = GENERAL_GROUP.create(
"fishing.min-wait-time",
100,
"The minimum amount of ticks to wait for a bite. This is before processing lure and other things",
"REQUIRES 1.16+"
)
var MAX_WAIT_TIME: ConfigSetting = GENERAL_GROUP.create(
"fishing.max-wait-time",
600,
"The maximum amount of ticks to wait for a bite. This is before processing lure and other things",
"REQUIRES 1.16+"
)
}
}

Binary file not shown.

View File

@ -0,0 +1,4 @@
# General Messages
general:
prefix: "&d&lFishing Rewards &8\\u00BB&7"

View File

@ -0,0 +1,6 @@
name: CustomFishing
version: ${project.version}
author: never2nv,Illuzionz Studios
main: com.illuzionzstudios.customfishing.CustomFishing
description: Customize the fishing system of minecraft
api-version: "1.20"

View File

@ -0,0 +1,91 @@
###################################################################
# A custom reward that can be caught by fishing. #
# This files defines all the options for a specific reward #
# identified by 'Name'. Change the options here as you like #
# to make your own reward. To add more than one catchable reward, #
# copy this file and then change the options to your liking. #
# #
# https://docs.illuzionzstudios.com/spigot-plugins/custom-fishing/ #
# Any queries join our discord at https://discord.gg/DbJXzWq #
###################################################################
# Placeholders
# {player} : The player's name
# The name or identifier of the reward. Make it something
# relating to what the reward is.
name: "Demo Reward"
# A list of commands to run when this reward is caught.
commands:
- "msg {player} demo"
# List of custom item rewards, leave the list blank
# if you don't want any custom items or remove this section
items:
# The section for an item
sword:
# Chance out of 100 of getting this reward
chance: 100
# The custom display name of the item.
# If an empty string has no custom name
item-name: "&a&lMy Demo Sword"
# The lore of the item. Set to null for no lore
lore:
- "&7Found While Fishing!"
# The amount of this item
amount: 1
# The material of the item
material: IRON_SWORD
# If has custom model data
model-data: 0
# A list of enchants as "ENCHANT:LEVEL". Set to null for no enchants
enchants:
- "SHARPNESS:5"
# If the item appears as glowing like it's enchanted
glowing: false
# If the item is unbreakable
unbreakable: false
# If to hide flags like unbreakable and enchants
hide-flags: false
# Durability of item
damage: 0
# A list of messages to send the player when this reward is caught.
messages:
- '&7&l(!) &aYou found an awesome sword!'
# A list of messages to broadcast to the server when this reward is caught.
broadcasts:
- '&4&l(!) &c{player} &7found a &c&lLEGENDARY &7reward!'
# Title to send to the player. Leave blank if none.
title: "&a&lYou found a reward!"
# Subtitle to send to the player. Leave blank if none.
sub-title: "&7&oFound: Sword"
# The weight (chance) of this reward being found. The higher the weight
# the more likely it is to be caught.
weight: 4.5
# If the player should still receive default minecraft rewards.
# This means fish, enchanted books, enchanted items etc.
# If set to false only the custom reward will be given
vanilla-rewards: false
# The amount of experience to give the player
# as a range, the "x to y" meaning from x to y (inclusive)
# Can just be a singular number
exp-amount: "1 to 6"
# The sound to play when this reward is caught. Leave blank
# for no sound
sound: ENTITY_FIREWORK_ROCKET_TWINKLE
# Requirements if the player can find this reward
requirements:
# Check if the player has a certain permission
permission:
type: permission
value: "customfishing.vip"