forked from nisovin/MagicSpells
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #841 from TonytheMacaroni/main
Add gametestaddmarker and gametestclearmarkers effects
- Loading branch information
Showing
7 changed files
with
237 additions
and
1 deletion.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
...c/main/java/com/nisovin/magicspells/spelleffects/effecttypes/GameTestAddMarkerEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package com.nisovin.magicspells.spelleffects.effecttypes; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.Color; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
|
||
import com.nisovin.magicspells.MagicSpells; | ||
import com.nisovin.magicspells.util.SpellData; | ||
import com.nisovin.magicspells.util.config.ConfigData; | ||
import com.nisovin.magicspells.spelleffects.SpellEffect; | ||
import com.nisovin.magicspells.util.config.ConfigDataUtil; | ||
|
||
public class GameTestAddMarkerEffect extends SpellEffect { | ||
|
||
private ConfigData<Color> color; | ||
private ConfigData<String> name; | ||
private ConfigData<Integer> lifetime; | ||
private ConfigData<Boolean> broadcast; | ||
private ConfigData<MarkerViewer> viewer; | ||
private ConfigData<Boolean> useViewerAsTarget; | ||
private ConfigData<Boolean> useViewerAsDefault; | ||
|
||
@Override | ||
protected void loadFromConfig(ConfigurationSection config) { | ||
name = ConfigDataUtil.getString(config, "name", ""); | ||
color = ConfigDataUtil.getARGBColor(config, "color", Color.BLACK); | ||
viewer = ConfigDataUtil.getEnum(config, "viewer", MarkerViewer.class, MarkerViewer.POSITION); | ||
lifetime = ConfigDataUtil.getInteger(config, "lifetime", 1000); | ||
broadcast = ConfigDataUtil.getBoolean(config, "broadcast", false); | ||
useViewerAsTarget = ConfigDataUtil.getBoolean(config, "use-viewer-as-target", false); | ||
useViewerAsDefault = ConfigDataUtil.getBoolean(config, "use-viewer-as-default", true); | ||
} | ||
|
||
@Override | ||
protected Runnable playEffectLocation(Location location, SpellData data) { | ||
if (broadcast.get(data)) { | ||
broadcast(location, data); | ||
return null; | ||
} | ||
|
||
Player viewer = switch (this.viewer.get(data)) { | ||
case CASTER -> data.caster() instanceof Player p ? p : null; | ||
case TARGET -> data.target() instanceof Player p ? p : null; | ||
case POSITION -> null; | ||
}; | ||
if (viewer == null) return null; | ||
|
||
String name = this.name.get(data); | ||
Color color = this.color.get(data); | ||
int lifetime = this.lifetime.get(data); | ||
MagicSpells.getVolatileCodeHandler().addGameTestMarker(viewer, location, color.asARGB(), name, lifetime); | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
protected Runnable playEffectEntity(Entity entity, SpellData data) { | ||
if (broadcast.get(data)) { | ||
broadcast(entity.getLocation(), data); | ||
return null; | ||
} | ||
|
||
Player viewer = switch (this.viewer.get(data)) { | ||
case CASTER -> data.caster() instanceof Player p ? p : null; | ||
case TARGET -> data.target() instanceof Player p ? p : null; | ||
case POSITION -> entity instanceof Player p ? p : null; | ||
}; | ||
if (viewer == null) return null; | ||
|
||
String name = this.name.get(data); | ||
Color color = this.color.get(data); | ||
int lifetime = this.lifetime.get(data); | ||
MagicSpells.getVolatileCodeHandler().addGameTestMarker(viewer, entity.getLocation(), color.asARGB(), name, lifetime); | ||
|
||
return null; | ||
} | ||
|
||
private void broadcast(Location location, SpellData data) { | ||
boolean useViewerAsTarget = this.useViewerAsTarget.get(data); | ||
boolean useViewerAsDefault = this.useViewerAsDefault.get(data); | ||
|
||
String name = null; | ||
Color color = null; | ||
int lifetime = 0; | ||
|
||
if (!useViewerAsTarget && !useViewerAsDefault) { | ||
name = this.name.get(data); | ||
color = this.color.get(data); | ||
lifetime = this.lifetime.get(data); | ||
} | ||
|
||
for (Player viewer : location.getWorld().getPlayers()) { | ||
if (useViewerAsTarget || useViewerAsDefault) { | ||
SpellData spellData = data; | ||
if (useViewerAsTarget) spellData = spellData.target(viewer); | ||
if (useViewerAsDefault) spellData = spellData.recipient(viewer); | ||
|
||
name = this.name.get(spellData); | ||
color = this.color.get(spellData); | ||
lifetime = this.lifetime.get(spellData); | ||
} | ||
|
||
MagicSpells.getVolatileCodeHandler().addGameTestMarker(viewer, location, color.asARGB(), name, lifetime); | ||
} | ||
} | ||
|
||
private enum MarkerViewer { | ||
|
||
CASTER, | ||
TARGET, | ||
POSITION | ||
|
||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
...ain/java/com/nisovin/magicspells/spelleffects/effecttypes/GameTestClearMarkersEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.nisovin.magicspells.spelleffects.effecttypes; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
|
||
import com.nisovin.magicspells.MagicSpells; | ||
import com.nisovin.magicspells.util.SpellData; | ||
import com.nisovin.magicspells.util.config.ConfigData; | ||
import com.nisovin.magicspells.spelleffects.SpellEffect; | ||
import com.nisovin.magicspells.util.config.ConfigDataUtil; | ||
|
||
public class GameTestClearMarkersEffect extends SpellEffect { | ||
|
||
private ConfigData<Boolean> broadcast; | ||
private ConfigData<MarkerViewer> viewer; | ||
|
||
@Override | ||
protected void loadFromConfig(ConfigurationSection config) { | ||
viewer = ConfigDataUtil.getEnum(config, "viewer", MarkerViewer.class, MarkerViewer.POSITION); | ||
broadcast = ConfigDataUtil.getBoolean(config, "broadcast", false); | ||
} | ||
|
||
@Override | ||
protected Runnable playEffectLocation(Location location, SpellData data) { | ||
if (broadcast.get(data)) { | ||
for (Player viewer : location.getWorld().getPlayers()) | ||
MagicSpells.getVolatileCodeHandler().clearGameTestMarkers(viewer); | ||
|
||
return null; | ||
} | ||
|
||
Player viewer = switch (this.viewer.get(data)) { | ||
case CASTER -> data.caster() instanceof Player p ? p : null; | ||
case TARGET -> data.target() instanceof Player p ? p : null; | ||
case POSITION -> null; | ||
}; | ||
if (viewer == null) return null; | ||
|
||
MagicSpells.getVolatileCodeHandler().clearGameTestMarkers(viewer); | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
protected Runnable playEffectEntity(Entity entity, SpellData data) { | ||
if (broadcast.get(data)) { | ||
for (Player viewer : entity.getWorld().getPlayers()) | ||
MagicSpells.getVolatileCodeHandler().clearGameTestMarkers(viewer); | ||
|
||
return null; | ||
} | ||
|
||
Player viewer = switch (this.viewer.get(data)) { | ||
case CASTER -> data.caster() instanceof Player p ? p : null; | ||
case TARGET -> data.target() instanceof Player p ? p : null; | ||
case POSITION -> entity instanceof Player p ? p : null; | ||
}; | ||
if (viewer == null) return null; | ||
|
||
MagicSpells.getVolatileCodeHandler().clearGameTestMarkers(viewer); | ||
|
||
return null; | ||
} | ||
|
||
private enum MarkerViewer { | ||
|
||
CASTER, | ||
TARGET, | ||
POSITION | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters