Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
kidofcubes committed Jul 17, 2022
2 parents 32d31f5 + 91145e2 commit fae7170
Show file tree
Hide file tree
Showing 33 changed files with 1,789 additions and 506 deletions.
128 changes: 106 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
# RpgPlugin
Minecraft [Paper](https://papermc.io) server RPG library
Minecraft [Paper](https://papermc.io) server RPG library for 1.19
(Paper only I believe)
# Development setup

Grab the latest jar from the [releases](https://github.com/KidOfCubes/RpgPlugin/releases/), drop it in your /libs folder, and add it as a compileOnly dependency.

example addon:

Gradle:
```groovy
dependencies {
compileOnly(files("${project.projectDir}/libs/RpgPlugin-VERSION.jar"))
}
```

Replace **VERSION** with the version of your downloaded jar.
(You will also need the plugin running on your server)

# Usage

Example plugin:

ExampleAddon.java
```java
public class ExampleAddon extends JavaPlugin {
@Override
public void onEnable(){
StatManager.register(new SmiteStat(), List.of(RpgActivateStatEvent.class));
StatManager.register(new SmiteStat(), List.of(RpgActivateStatEvent.class)); //has to be registered or else it will not work
}
}
```
Expand All @@ -19,33 +35,101 @@ SmiteStat.java
public class SmiteStat extends Stat {
@Override
public RpgObject elementToStatCheck(Event event){
return ((RpgActivateStatEvent)event).getParent(); //Gets the object that has the stat being activated
return ((RpgActivateStatEvent)event).getParent(); //Gets the object that has the stat thats being activated
}

@Override
public void run(Event event, int level){
public void run(Event event){ //the code to be run when the stat is eligible to run
RpgActivateStatEvent activateEvent = (RpgActivateStatEvent) event;
if(activateEvent.getTarget() instanceof RpgEntity target) { //target could be item or entity
target.livingEntity.getWorld().strikeLightningEffect(target.livingEntity.getLocation());
target.damage(DamageType.Thunder, level * 3);
}
}
}
@Override
public float getManaCost(){ //Set the mana cost of activating this stat
return 5;
}
}
```

add the latest release jar as a dependency in your gradle/maven
and also the release jar needs to be running as a plugin

(i think this only supports paper havent tested on spigot or bukkit)
leave me a dm on discord if something KidOfCubes#4867




plans: (all going to be disablable)
custom mob spawning thing
custom hit detection (custom range, hit hitbox size, etc)
classes

not sure plans:


plugin.yml
```yml
main: io.github.kidofcubes.ExampleAddon
name: ExampleAddon
version: 0.0.1
description: A example plugin
api-version: 1.19
depend: [RpgPlugin]
commands:
```
Now to add the SmiteStat to something, you use the addStat function on RpgEntity or RpgItem like so: <br>
`RpgManager.getRpgEntity(livingEntity).addStat(new SmiteStat());`


`RpgManager.getRpgItem(itemStack).addStat(new SmiteStat());`

# Things
RpgManager:

How you get RpgItems and RpgEntities from itemStacks and livingEntities


Stat:

Can cost mana
Listens for events
Has a parent (where the stat is on) and a user (whats currently using the stat)
TimedStat:

A extension of Stat that gets called every `getInterval()` ticks (calls run with a null event)

RpgObject:

Holds stats
Can use other RpgObjects to use their stats
Can have multiple RpgClasses

RpgEntity:

Extension of RpgObject
Linked to a LivingEntity

RpgItem:

Extension of RpgObject
Somewhat linked to a itemstack

RpgClass:

Has stats that get added when this class is added



# Other section

Still in beta so there's probably some (hopefully not critical) bugs, It's still in active development though so if you made a GitHub issue I should be able to fix it relatively soon.

Ideas are also welcome (provided that they aren't too specific)

Some parts may drastically change over beta, so I do not recommend upgrading in production without testing.

Compatibility with other plugins should be okayish

I can be contacted on Discord at `KidOfCubes#4867` if you need or want to report anything
<br>
<br>
<br>

Future plans: (all going to be configurable hopefully)

Custom hit detection (custom range, attack hitbox size, etc)
Less bugs

Other ideas:

Custom world generation things
Custom mob spawning

49 changes: 0 additions & 49 deletions build.gradle

This file was deleted.

26 changes: 26 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
plugins {

`java-library`
id("io.papermc.paperweight.userdev") version "1.3.7"
}

group = "io.github.kidofcubes"
version = "v1.1"

repositories {
mavenLocal()
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")

}

dependencies {
paperDevBundle("1.19-R0.1-SNAPSHOT")
}

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
9 changes: 0 additions & 9 deletions settings.gradle

This file was deleted.

9 changes: 9 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven ("https://repo.papermc.io/repository/maven-public/")
}
}

rootProject.name = "RpgPlugin"

10 changes: 10 additions & 0 deletions src/main/java/io/github/kidofcubes/ActivateStats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.kidofcubes;

import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

import java.util.*;

public interface ActivateStats {
Map<Class<? extends Stat>, Stat> getActivationStats();
}
56 changes: 37 additions & 19 deletions src/main/java/io/github/kidofcubes/ExtraFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.inventory.ItemStack;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

Expand All @@ -33,7 +34,7 @@ public class ExtraFunctions {

public static boolean isEmpty(ItemStack itemStack) {
if (itemStack != null) {
return itemStack.getType().isAir();
return itemStack.getType().isAir()||itemStack.getType().isEmpty()||itemStack.getType().isEmpty();
} else {
return true;
}
Expand All @@ -49,32 +50,32 @@ public static String toRoman(int number) {

public final static String damageToString(Map<DamageType, Double> damage) {
TextComponent output = Component.text("");
if (damage.get(DamageType.Physical) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.Physical), 1) + "❤ ", TextColor.fromCSSHexString("#AA0000")));
if (damage.get(DamageType.PHYSICAL) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.PHYSICAL), 1) + "❤ ", TextColor.fromCSSHexString("#AA0000")));
}
if (damage.get(DamageType.Light) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.Light), 1) + "❤ ", TextColor.fromCSSHexString("#FFFFFF")));
if (damage.get(DamageType.LIGHT) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.LIGHT), 1) + "❤ ", TextColor.fromCSSHexString("#FFFFFF")));
}
if (damage.get(DamageType.Magical) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.Magical), 1) + "❤ ", TextColor.fromCSSHexString("#0000AA")));
if (damage.get(DamageType.MAGICAL) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.MAGICAL), 1) + "❤ ", TextColor.fromCSSHexString("#0000AA")));
}
if (damage.get(DamageType.Darkness) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.Darkness), 1) + "❂ ", TextColor.fromCSSHexString("#555555")));
if (damage.get(DamageType.DARKNESS) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.DARKNESS), 1) + "❂ ", TextColor.fromCSSHexString("#555555")));
}
if (damage.get(DamageType.Earth) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.Earth), 1) + "✤ ", TextColor.fromCSSHexString("#00AA00")));
if (damage.get(DamageType.EARTH) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.EARTH), 1) + "✤ ", TextColor.fromCSSHexString("#00AA00")));
}
if (damage.get(DamageType.Thunder) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.Thunder), 1) + "✦ ", TextColor.fromCSSHexString("#FFFF55")));
if (damage.get(DamageType.THUNDER) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.THUNDER), 1) + "✦ ", TextColor.fromCSSHexString("#FFFF55")));
}
if (damage.get(DamageType.Water) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.Water), 1) + "✽ ", TextColor.fromCSSHexString("#55FFFF")));
if (damage.get(DamageType.WATER) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.WATER), 1) + "✽ ", TextColor.fromCSSHexString("#55FFFF")));
}
if (damage.get(DamageType.Fire) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.Fire), 1) + " ", TextColor.fromCSSHexString("#FFFF55")));
if (damage.get(DamageType.FIRE) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.FIRE), 1) + " ", TextColor.fromCSSHexString("#FF5555")));
}
if (damage.get(DamageType.Air) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.Air), 1) + " ", TextColor.fromCSSHexString("#FFFFFF")));
if (damage.get(DamageType.AIR) != 0) {
output = output.append(Component.text("-" + round(damage.get(DamageType.AIR), 1) + " ", TextColor.fromCSSHexString("#FFFFFF")));
}
return LegacyComponentSerializer.legacySection().serialize(output);
}
Expand All @@ -83,4 +84,21 @@ public static double round(double value, int precision) {
int scale = (int) Math.pow(10, precision);
return (double) Math.round(value * scale) / scale;
}

public static Map<String,Stat> joinStatMaps(Map<String,Stat> map1, Map<String,Stat> map2){
Map<String,Stat> returnvalue = new HashMap<>(map1);
for (Map.Entry<String, Stat> entry :
map2.entrySet()) {
Stat orig = returnvalue.getOrDefault(entry.getKey(),null);
if(orig!=null){
if(orig.getLevel()<entry.getValue().getLevel()){
orig.setLevel(entry.getValue().getLevel());
}
}else{
returnvalue.put(entry.getKey(),entry.getValue());
}

}
return returnvalue;
}
}
Loading

0 comments on commit fae7170

Please sign in to comment.