Skip to content

Commit e14ee66

Browse files
Avoid using entity.getLocation as much since it makes use of defensive copying
Use utility from AccessibleObject for reflection to reduce necessary checks. Give ReflectionHelper some new tools. Change the area specification options on the AreaEffectSpell to accept doubles instead of ints. Changed max-distance in PulserSpell to accept a double instead of an integer for better control. Changed retarget-reange and target-range in SpawnMonsterSpell to accept doubles instead of ints for better control. Changed radius in ForcebombSpell to accept a double for better control. Changed bounce-range in ChainSpell to a double for better control. Changed range in RoarSpell to a double for better control. Changed max-range in RecallSpell to a double for better control. Changed range in PurgeSpell to a double for better control. [WIP] Started a framework for command argument processing. [WIP] template for reset spell CRITICAL introduced new option for the general config: ignore-grant-perms-fake-value This defaults to true for avoiding changes in behavior. However, it is HIGHLY recommended to set this to false.
1 parent b9abe1f commit e14ee66

33 files changed

+228
-60
lines changed

src/com/nisovin/magicspells/MagicSpells.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public class MagicSpells extends JavaPlugin {
105105
boolean opsHaveAllSpells;
106106
boolean defaultAllPermsFalse;
107107
boolean ignoreGrantPerms;
108+
boolean ignoreGrantPermsFakeValue;
108109
boolean ignoreCastPerms;
109110

110111
boolean enableTempGrantPerms = true;
@@ -297,6 +298,7 @@ void load() {
297298
opsHaveAllSpells = config.getBoolean("general.ops-have-all-spells", true);
298299
defaultAllPermsFalse = config.getBoolean("general.default-all-perms-false", false);
299300
ignoreGrantPerms = config.getBoolean("general.ignore-grant-perms", false);
301+
ignoreGrantPermsFakeValue = config.getBoolean("general.ignore-grant-perms-fake-value", true);
300302
ignoreCastPerms = config.getBoolean("general.ignore-cast-perms", false);
301303
enableTempGrantPerms = config.getBoolean("general.enable-tempgrant-perms", true);
302304

src/com/nisovin/magicspells/Spellbook.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void load(World playerWorld) {
100100
loadFromFile(playerWorld);
101101

102102
// Give all spells to ops, or if ignoring grant perms
103-
if (plugin.ignoreGrantPerms || (player.isOp() && plugin.opsHaveAllSpells)) {
103+
if ((plugin.ignoreGrantPerms && plugin.ignoreGrantPermsFakeValue) || (player.isOp() && plugin.opsHaveAllSpells)) {
104104
MagicSpells.debug(2, " Op, granting all spells...");
105105
for (Spell spell : plugin.spellsOrdered) {
106106
if (spell.isHelperSpell()) continue;
@@ -398,10 +398,10 @@ public boolean hasSpell(Spell spell) {
398398

399399
// DEBUG INFO: level 2, adding granted spell for player, spell
400400
public boolean hasSpell(Spell spell, boolean checkGranted) {
401-
if (plugin.ignoreGrantPerms) return true;
401+
if (plugin.ignoreGrantPerms && plugin.ignoreGrantPermsFakeValue) return true;
402402
boolean has = allSpells.contains(spell);
403403
if (has) return true;
404-
if (checkGranted && Perm.GRANT.has(player, spell)) {
404+
if (checkGranted && !plugin.ignoreGrantPerms && Perm.GRANT.has(player, spell)) {
405405
MagicSpells.debug(2, "Adding granted spell for " + player.getName() + ": " + spell.getName());
406406
addSpell(spell);
407407
save();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.nisovin.magicspells.exception;
2+
3+
public class MagicException extends Exception {
4+
5+
public MagicException(String message) {
6+
super(message);
7+
}
8+
9+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.nisovin.magicspells.spells.command;
2+
3+
import com.nisovin.magicspells.spells.CommandSpell;
4+
import com.nisovin.magicspells.util.MagicConfig;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.entity.Player;
7+
8+
import java.util.List;
9+
10+
// PLANNED OPTIONS
11+
// get spellbook(s)
12+
// remove certain spells
13+
// remove all spells
14+
// remove bindings
15+
// variables
16+
// remove certain variables
17+
// remove all variables
18+
// MarkSpell
19+
// remove certain
20+
// remove all
21+
// KeybindSpell
22+
// reset
23+
24+
// Spellbook spells
25+
// remove by player/world/all
26+
public class ResetSpell extends CommandSpell {
27+
28+
public ResetSpell(MagicConfig config, String spellName) {
29+
super(config, spellName);
30+
}
31+
32+
@Override
33+
public boolean castFromConsole(CommandSender sender, String[] args) {
34+
return false;
35+
}
36+
37+
@Override
38+
public PostCastAction castSpell(Player player, SpellCastState state, float power, String[] args) {
39+
// get player(s)
40+
41+
return null;
42+
}
43+
44+
@Override
45+
public List<String> tabComplete(CommandSender sender, String partial) {
46+
return null;
47+
}
48+
49+
50+
51+
}

src/com/nisovin/magicspells/spells/instant/ParticleProjectileSpell.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ public ProjectileTracker(Player caster, Location from, float power) {
193193
this.startLocation.setY(this.startLocation.getY() + ParticleProjectileSpell.this.startYOffset);
194194
}
195195
if (ParticleProjectileSpell.this.startForwardOffset != 0) {
196+
// TODO see what can be cleaned up here with constructing locations and vectors
196197
this.startLocation.add(this.startLocation.getDirection().clone().multiply(ParticleProjectileSpell.this.startForwardOffset));
197198
}
198199
this.previousLocation = this.startLocation.clone();

src/com/nisovin/magicspells/spells/instant/ProjectileSpell.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private class ProjectileInfo {
420420

421421
public ProjectileInfo(Player player, float power) {
422422
this.player = player;
423-
this.start = player.getLocation().clone();
423+
this.start = player.getLocation();
424424
this.power = power;
425425
this.done = false;
426426
this.monitor = null;

src/com/nisovin/magicspells/spells/instant/PurgeSpell.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
public class PurgeSpell extends InstantSpell implements TargetedLocationSpell {
2323

24-
private int radius;
24+
private double radius;
2525
private List<EntityType> entities;
2626

2727
public PurgeSpell(MagicConfig config, String spellName) {
2828
super(config, spellName);
2929

30-
this.radius = getConfigInt("range", 15);
30+
this.radius = getConfigDouble("range", 15);
3131

3232
List<String> list = getConfigStringList("entities", null);
3333
if (list != null && !list.isEmpty()) {
@@ -47,7 +47,7 @@ public PurgeSpell(MagicConfig config, String spellName) {
4747
@Override
4848
public PostCastAction castSpell(Player player, SpellCastState state, float power, String[] args) {
4949
if (state == SpellCastState.NORMAL) {
50-
int castingRange = Math.round(this.radius * power);
50+
double castingRange = this.radius * power;
5151
List<Entity> entitiesNearby = player.getNearbyEntities(castingRange, castingRange, castingRange);
5252
boolean killed = false;
5353
for (Entity entity : entitiesNearby) {

src/com/nisovin/magicspells/spells/instant/RecallSpell.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class RecallSpell extends InstantSpell implements TargetedEntitySpell {
1818

1919
private String markSpellName;
2020
private boolean allowCrossWorld;
21-
private int maxRange;
21+
private double maxRange;
2222
private boolean useBedLocation;
2323
private String strNoMark;
2424
private String strOtherWorld;
@@ -32,7 +32,7 @@ public RecallSpell(MagicConfig config, String spellName) {
3232

3333
this.markSpellName = getConfigString("mark-spell", "mark");
3434
this.allowCrossWorld = getConfigBoolean("allow-cross-world", true);
35-
this.maxRange = getConfigInt("max-range", 0);
35+
this.maxRange = getConfigDouble("max-range", 0);
3636
this.useBedLocation = getConfigBoolean("use-bed-location", false);
3737
this.strNoMark = getConfigString("str-no-mark", "You have no mark to recall to.");
3838
this.strOtherWorld = getConfigString("str-other-world", "Your mark is in another world.");

src/com/nisovin/magicspells/spells/instant/RitualSpell.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ public ActiveRitual(Player caster, float power, String[] args) {
128128
this.power = power;
129129
this.args = args;
130130
this.caster = caster;
131-
this.channelers.put(caster, caster.getLocation().clone());
131+
this.channelers.put(caster, caster.getLocation());
132132
this.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(MagicSpells.plugin, this, tickInterval, tickInterval);
133133
if (showProgressOnExpBar) MagicSpells.getExpBarManager().lock(caster, this);
134134
playSpellEffects(EffectPosition.CASTER, caster);
135135
}
136136

137137
public void addChanneler(Player player) {
138138
if (this.channelers.containsKey(player)) return;
139-
this.channelers.put(player, player.getLocation().clone());
139+
this.channelers.put(player, player.getLocation());
140140
if (showProgressOnExpBar) MagicSpells.getExpBarManager().lock(player, this);
141141
playSpellEffects(EffectPosition.CASTER, player);
142142
}

src/com/nisovin/magicspells/spells/instant/RoarSpell.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
public class RoarSpell extends InstantSpell {
1515

16-
private int radius;
16+
private double radius;
1717
private boolean cancelIfNoTargets;
1818
private String strNoTarget;
1919

2020
public RoarSpell(MagicConfig config, String spellName) {
2121
super(config, spellName);
2222

23-
this.radius = getConfigInt("range", 8);
23+
this.radius = getConfigDouble("range", 8);
2424
this.cancelIfNoTargets = getConfigBoolean("cancel-if-no-targets", true);
2525
this.strNoTarget = getConfigString("str-no-target", "No targets found.");
2626
}

0 commit comments

Comments
 (0)