Skip to content

Commit

Permalink
Merge pull request #829 from JasperLorelai/main
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
Chronoken authored Jan 16, 2024
2 parents 80b9618 + b8c6f6e commit 240edcd
Show file tree
Hide file tree
Showing 396 changed files with 2,429 additions and 3,428 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
<img src="https://media.discordapp.net/attachments/335237931633606656/595352328341684427/Untitled.png" alt="MagicSpells Icon">
<hr>
<h2><i>Magic without writing Java</i></h2>
<!--
Build badge is commented out until it is fixed.
<a href="https://travis-ci.org/TheComputerGeek2/MagicSpells"><img src="https://travis-ci.org/TheComputerGeek2/MagicSpells.svg?branch=main" alt="Build Status"></a>
-->
<a href="https://github.com/TheComputerGeek2/MagicSpells/actions"><img src="https://img.shields.io/github/actions/workflow/status/TheComputerGeek2/MagicSpells/build.yml" alt="Build Status"></a>
<a href="https://discord.magicspells.dev"><img src="https://img.shields.io/discord/335237931633606656?color=5562e9&logo=discord&logoColor=white" alt="Discord Server"></a>
<a href="https://github.com/TheComputerGeek2/MagicSpells/releases"><img src="https://img.shields.io/github/downloads/TheComputerGeek2/MagicSpells/total.svg" alt="Github Releases"></a>
<img src="https://img.shields.io/bstats/servers/892" alt="In MC servers">
<a href="https://github.com/TheComputerGeek2/MagicSpells/releases">
<img src="https://img.shields.io/github/downloads/TheComputerGeek2/MagicSpells/total.svg" alt="Github Downloads">
<img src="https://img.shields.io/github/downloads-pre/TheComputerGeek2/MagicSpells/latest/total.svg" alt="Github Downloads Latest">
</a>
<img src="https://img.shields.io/github/license/TheComputerGeek2/MagicSpells" alt="Licence">
<a href="https://bstats.org/plugin/bukkit/MagicSpells/892"><img src="https://img.shields.io/bstats/servers/892" alt="In MC servers"></a>
</div>

[//]: # (These links are here for easier hyperlink referencing and less clutter in the actual text below.)
Expand Down
2 changes: 2 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
shadow(group: "com.github.Chronoken", name: "EffectLib", version: "d28b6e2")
shadow(group: "co.aikar", name: "acf-paper", version: "0.5.1-SNAPSHOT")
shadow(group: "org.jetbrains.kotlin", name: "kotlin-stdlib-jdk8", version: "1.9.21")
shadow(group: "org.bstats", name: "bstats-bukkit", version: "3.0.2")

shadow(project(path: ":nms:shared", configuration: "apiElements"))
shadow(project(path: ":nms:v1_20_R2", configuration: "reobf"))
Expand Down Expand Up @@ -55,6 +56,7 @@ shadowJar {
relocate("kotlin", "com.nisovin.magicspells.shaded.kotlin")
relocate("co.aikar.commands", "com.nisovin.magicspells.shaded.acf")
relocate("co.aikar.locales", "com.nisovin.magicspells.shaded.locales")
relocate("org.bstats", "com.nisovin.magicspells.shaded.bstats")
archiveClassifier.set("")
}

Expand Down
62 changes: 49 additions & 13 deletions core/src/main/java/com/nisovin/magicspells/MagicSpells.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

import de.slikey.effectlib.EffectManager;

import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bstats.charts.AdvancedPie;
import org.bstats.charts.DrilldownPie;

import org.jetbrains.annotations.NotNull;

import co.aikar.commands.PaperCommandManager;
Expand Down Expand Up @@ -72,6 +77,7 @@
import com.nisovin.magicspells.volatilecode.VolatileCodeHandle;
import com.nisovin.magicspells.events.SpellLearnEvent.LearnSource;
import com.nisovin.magicspells.spelleffects.trackers.EffectTracker;
import com.nisovin.magicspells.spells.passive.util.PassiveListener;
import com.nisovin.magicspells.variables.variabletypes.GlobalVariable;
import com.nisovin.magicspells.spelleffects.trackers.AsyncEffectTracker;
import com.nisovin.magicspells.spelleffects.effecttypes.EffectLibEffect;
Expand Down Expand Up @@ -218,7 +224,44 @@ public class MagicSpells extends JavaPlugin {
public void onEnable() {
load();

new Metrics(this);
Metrics metrics = new Metrics(this, 892);

metrics.addCustomChart(new DrilldownPie("spells", () -> {
Map<String, Map<String, Integer>> map = new HashMap<>();
if (spells == null) return map;

for (Spell spell : spells.values()) {
String name = spell.getClass().getName();
if (!name.startsWith("com.nisovin.magicspells.spells")) continue;
name = name.replace("com.nisovin.magicspells.spells.", "");

String[] typeSplit = name.split("\\.", 2);
String formalPackage = typeSplit[0].substring(0, 1).toUpperCase() + typeSplit[0].substring(1);

String spellPackage = (typeSplit.length == 1 ? "General" : formalPackage) + " Spells";
String spellClass = typeSplit.length == 1 ? typeSplit[0] : typeSplit[1];

map.computeIfAbsent(spellPackage, key -> new HashMap<>());
map.get(spellPackage).compute(spellClass, (k, v) -> (v == null ? 0 : v) + 1);
}
return map;
}));
metrics.addCustomChart(new AdvancedPie("passive_listeners", () -> {
IntMap<String> map = new IntMap<>();
if (spells == null) return map;

for (Spell spell : spells.values()) {
if (!spell.getName().startsWith("com.nisovin.magicspells.spells")) continue;
if (!(spell instanceof PassiveSpell passiveSpell)) continue;

for (PassiveListener listener : passiveSpell.getPassiveListeners()) {
String name = listener.getClass().getSimpleName();
map.increment(name.substring(0, name.lastIndexOf("Listener")));
}
}
return map;
}));
metrics.addCustomChart(new SimplePie("reload_time", () -> (lastReloadTime - lastReloadTime % 20) + " ms"));
}

public void load() {
Expand Down Expand Up @@ -510,7 +553,7 @@ public void load() {
for (Spell spell : spells.values()) {
spellNames.put(Util.getPlainString(Util.getMiniMessage(spell.getName().toLowerCase())), spell);
String[] aliases = spell.getAliases();
if (aliases != null && aliases.length > 0) {
if (aliases != null) {
for (String alias : aliases) {
if (!spellNames.containsKey(alias.toLowerCase())) spellNames.put(alias.toLowerCase(), spell);
}
Expand Down Expand Up @@ -956,9 +999,7 @@ public static Spell getSpellByInGameName(String spellName) {
* @return the player's spellbook
*/
public static Spellbook getSpellbook(Player player) {
Spellbook spellbook = plugin.spellbooks.computeIfAbsent(player.getName(), playerName -> new Spellbook(player));
if (spellbook == null) throw new IllegalStateException();
return spellbook;
return plugin.spellbooks.computeIfAbsent(player.getName(), playerName -> new Spellbook(player));
}

public static ChatColor getTextColor() {
Expand Down Expand Up @@ -1069,7 +1110,7 @@ public static boolean isDebugNull() {
public static boolean isDebugNumberFormat() {
return plugin.debugNumberFormat;
}

public static boolean areBowCycleButtonsReversed() {
return plugin.reverseBowCycleButtons;
}
Expand Down Expand Up @@ -1551,7 +1592,7 @@ public static String doArgumentAndVariableSubstitution(String string, Player pla
}

public static String doReplacements(String message, SpellData data, String... replacements) {
return doReplacements(message, data.recipient(), data, replacements);
return doReplacements(message, data.recipient(), data, replacements);
}

/**
Expand All @@ -1570,7 +1611,7 @@ public static String doReplacements(String message, SpellData data, String... re
* @param replacements the replacements to be made, in pairs
*/
public static String doReplacements(String message, LivingEntity recipient, SpellData data, String... replacements) {
if (message == null || message.isEmpty()) return message;
if (message == null || message.isEmpty()) return message;

message = doArgumentSubstitution(message, data.args());
message = doVariableReplacements(message, recipient, data.caster(), data.target());
Expand Down Expand Up @@ -2145,8 +2186,3 @@ public MagicConfig getMagicConfig() {
}

}

/*
* TODO:
* - Move NoMagicZoneWorldGuard outside of the core plugin
*/
6 changes: 3 additions & 3 deletions core/src/main/java/com/nisovin/magicspells/Spell.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void loadConfigData(MagicConfig config, String spellName, String section
MagicItem magicItem = MagicItems.getMagicItemFromString(iconStr);
if (magicItem != null) {
spellIcon = magicItem.getItemStack();
if (spellIcon != null && !BlockUtils.isAir(spellIcon.getType())) {
if (spellIcon != null && !spellIcon.getType().isAir()) {
if (!magicItem.getMagicItemData().hasAttribute(MagicItemData.MagicItemAttribute.NAME)) {
ItemMeta iconMeta = spellIcon.getItemMeta();
iconMeta.displayName(Component.text(MagicSpells.getTextColor() + name));
Expand Down Expand Up @@ -1032,7 +1032,7 @@ protected void postCast(SpellCastEvent spellCast, PostCastAction action) {
* This method is called when a player casts a spell, either by command, with a wand item, or otherwise.
*
* @param caster the living entity casting the spell
* @param state the state of the spell cast (normal, on cooldown, missing reagents, etc)
* @param state the state of the spell cast (normal, on cooldown, missing reagents, etc.)
* @param power the power multiplier the spell should be cast with (1.0 is normal)
* @param args the spell arguments, if cast by command
* @return the action to take after the spell is processed
Expand Down Expand Up @@ -1261,7 +1261,7 @@ public boolean isIgnoringGlobalCooldown() {

public boolean isValidItemForCastCommand(ItemStack item) {
if (!requireCastItemOnCommand || castItems == null) return true;
if (item == null && castItems.length == 1 && BlockUtils.isAir(castItems[0].getType())) return true;
if (item == null && castItems.length == 1 && castItems[0].getType().isAir()) return true;
for (CastItem castItem : castItems) {
if (castItem.equals(new CastItem(item))) return true;
}
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/com/nisovin/magicspells/Spellbook.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ public void addTemporarySpell(Spell spell, Plugin plugin) {
if (hasSpell(spell)) return;
addSpell(spell);
Set<Spell> temps = temporarySpells.computeIfAbsent(plugin, pl -> new HashSet<>());
if (temps == null) throw new IllegalStateException("temporarySpells should not contain a null value!");
temps.add(spell);
}

Expand All @@ -409,8 +408,7 @@ public boolean isTemporary(Spell spell) {
public void addCastItem(Spell spell, CastItem castItem) {
// Add to custom bindings
Set<CastItem> bindings = customBindings.computeIfAbsent(spell, s -> new HashSet<>());
if (bindings == null) throw new IllegalStateException("customBindings spells should not contain a null value!");
if (!bindings.contains(castItem)) bindings.add(castItem);
bindings.add(castItem);

// Add to item bindings
List<Spell> bindList = itemSpells.get(castItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;

import org.jetbrains.annotations.NotNull;

public abstract class Condition {

public abstract boolean initialize(String var);
public abstract boolean initialize(@NotNull String var);

public abstract boolean check(LivingEntity livingEntity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.bukkit.entity.LivingEntity;

import com.nisovin.magicspells.MagicSpells;
import com.nisovin.magicspells.util.RegexUtil;
import com.nisovin.magicspells.util.SpellData;
import com.nisovin.magicspells.util.ModifierResult;
import com.nisovin.magicspells.events.SpellCastEvent;
Expand Down Expand Up @@ -42,8 +41,8 @@ public Modifier() {
public boolean process(String string) {
if (MagicSpells.getConditionManager() == null) return false;

String[] s = RegexUtil.split(MODIFIER_STR_FAILED_PATTERN, string, 0);
if (s == null || s.length <= 0) return false;
String[] s = MODIFIER_STR_FAILED_PATTERN.split(string);
if (s == null || s.length == 0) return false;
String[] data = s[0].trim().split(" ", 4);

if (data.length < 2) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void apply(SpellTargetLocationEvent event) {

public ModifierResult apply(LivingEntity caster, SpellData data) {
for (Modifier modifier : modifiers) {
ModifierResult result = modifier.apply(caster, data);
ModifierResult result = modifier.apply(caster, data);
if (result.check()) {
data = result.data();
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;

import org.jetbrains.annotations.NotNull;

import com.nisovin.magicspells.castmodifiers.conditions.util.OperatorCondition;

public class AbsorptionCondition extends OperatorCondition {

private float health = 0;

@Override
public boolean initialize(String var) {
public boolean initialize(@NotNull String var) {
if (var.length() < 2 || !super.initialize(var)) return false;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.bukkit.entity.LivingEntity;
import org.bukkit.advancement.Advancement;

import org.jetbrains.annotations.NotNull;

import com.nisovin.magicspells.MagicSpells;
import com.nisovin.magicspells.castmodifiers.Condition;

Expand All @@ -18,8 +20,8 @@ public class AdvancementCondition extends Condition {
private Set<Advancement> advancements;

@Override
public boolean initialize(String var) {
if (var == null || var.isEmpty()) return false;
public boolean initialize(@NotNull String var) {
if (var.isEmpty()) return false;

advancements = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.bukkit.entity.Ageable;
import org.bukkit.entity.LivingEntity;

import org.jetbrains.annotations.NotNull;

import com.nisovin.magicspells.castmodifiers.Condition;

public class AgeCondition extends Condition {
Expand All @@ -12,18 +14,9 @@ public class AgeCondition extends Condition {
private boolean passAdult = false;

@Override
public boolean initialize(String var) {
if (var != null) {
if (var.equalsIgnoreCase("baby")) {
passBaby = true;
return true;
} else if (var.equalsIgnoreCase("adult")) {
passAdult = true;
return true;
}
}
passBaby = true;
passAdult = true;
public boolean initialize(@NotNull String var) {
passBaby = var.isEmpty() || var.equalsIgnoreCase("baby");
passAdult = var.isEmpty() || var.equalsIgnoreCase("adult");
return true;
}

Expand All @@ -43,8 +36,8 @@ public boolean check(LivingEntity caster, Location location) {
}

private boolean age(LivingEntity target) {
if (!(target instanceof Ageable t)) return false;
boolean adult = t.isAdult();
if (!(target instanceof Ageable age)) return false;
boolean adult = age.isAdult();
return adult ? passAdult : passBaby;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.bukkit.entity.Player;
import org.bukkit.entity.LivingEntity;

import org.jetbrains.annotations.NotNull;

import com.nisovin.magicspells.MagicSpells;
import com.nisovin.magicspells.handlers.DebugHandler;
import com.nisovin.magicspells.castmodifiers.conditions.util.OperatorCondition;
Expand All @@ -13,7 +15,7 @@ public class AliveCondition extends OperatorCondition {
private int time;

@Override
public boolean initialize(String var) {
public boolean initialize(@NotNull String var) {
if (var.length() < 2 || !super.initialize(var)) return false;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;

import org.jetbrains.annotations.NotNull;

import com.nisovin.magicspells.castmodifiers.Condition;

public class AlwaysCondition extends Condition {

@Override
public boolean initialize(String var) {
public boolean initialize(@NotNull String var) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.bukkit.util.Vector;
import org.bukkit.entity.LivingEntity;

import org.jetbrains.annotations.NotNull;

import org.apache.commons.math4.core.jdkmath.AccurateMath;

import com.nisovin.magicspells.handlers.DebugHandler;
Expand All @@ -14,7 +16,7 @@ public class AngleCondition extends OperatorCondition {
private double angle;

@Override
public boolean initialize(String var) {
public boolean initialize(@NotNull String var) {
if (var.length() < 2 || !super.initialize(var)) return false;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.bukkit.block.Biome;
import org.bukkit.entity.LivingEntity;

import org.jetbrains.annotations.NotNull;

import com.nisovin.magicspells.util.Util;
import com.nisovin.magicspells.handlers.DebugHandler;
import com.nisovin.magicspells.castmodifiers.Condition;
Expand All @@ -15,7 +17,7 @@ public class BiomeCondition extends Condition {
private final EnumSet<Biome> biomes = EnumSet.noneOf(Biome.class);

@Override
public boolean initialize(String var) {
public boolean initialize(@NotNull String var) {
String[] s = var.split(",");

for (String value : s) {
Expand Down
Loading

0 comments on commit 240edcd

Please sign in to comment.