Introduced magicspells.yml for disabling custom spells.
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,13 @@
|
|||||||
|
# MobArena disabled MagicSpells spells
|
||||||
|
# Use this file to disable the MagicSpells spells you don't want your players
|
||||||
|
# to use during arena sessions. Make sure to put a hyphen (-) before every
|
||||||
|
# spell, and try to keep the indentation proper.
|
||||||
|
|
||||||
|
# Spells that will be disabled for the entire arena session.
|
||||||
|
disabled-spells:
|
||||||
|
- carpet
|
||||||
|
- blink
|
||||||
|
|
||||||
|
# Spells that will be disabled only while a boss is present.
|
||||||
|
disabled-only-on-bosses:
|
||||||
|
- purge
|
||||||
@@ -1,17 +1,31 @@
|
|||||||
package com.garbagemule.MobArena.listeners;
|
package com.garbagemule.MobArena.listeners;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.util.config.Configuration;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.Arena;
|
import com.garbagemule.MobArena.Arena;
|
||||||
import com.garbagemule.MobArena.MobArena;
|
import com.garbagemule.MobArena.MobArena;
|
||||||
|
import com.garbagemule.MobArena.util.FileUtils;
|
||||||
import com.nisovin.MagicSpells.Events.SpellCastEvent;
|
import com.nisovin.MagicSpells.Events.SpellCastEvent;
|
||||||
import com.nisovin.MagicSpells.Events.SpellListener;
|
import com.nisovin.MagicSpells.Events.SpellListener;
|
||||||
|
|
||||||
public class MagicSpellsListener extends SpellListener
|
public class MagicSpellsListener extends SpellListener
|
||||||
{
|
{
|
||||||
private MobArena plugin;
|
private MobArena plugin;
|
||||||
|
private List<String> disabled, disabledOnBoss;
|
||||||
|
|
||||||
public MagicSpellsListener(MobArena plugin)
|
public MagicSpellsListener(MobArena plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
||||||
|
// Set up the MagicSpells config-file.
|
||||||
|
File spellFile = FileUtils.extractFile(plugin.getDataFolder(), "magicspells.yml");
|
||||||
|
Configuration spellConfig = new Configuration(spellFile);
|
||||||
|
spellConfig.load();
|
||||||
|
setupSpells(spellConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSpellCast(SpellCastEvent event)
|
public void onSpellCast(SpellCastEvent event)
|
||||||
@@ -19,7 +33,25 @@ public class MagicSpellsListener extends SpellListener
|
|||||||
Arena arena = plugin.getAM().getArenaWithPlayer(event.getCaster());
|
Arena arena = plugin.getAM().getArenaWithPlayer(event.getCaster());
|
||||||
if (arena == null || !arena.isRunning()) return;
|
if (arena == null || !arena.isRunning()) return;
|
||||||
|
|
||||||
if (event.getSpell().getName().equals("purge") && arena.isBossWave())
|
String spell = event.getSpell().getName();
|
||||||
|
|
||||||
|
if (disabled.contains(spell) || (arena.isBossWave() && disabledOnBoss.contains(spell)))
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupSpells(Configuration config)
|
||||||
|
{
|
||||||
|
this.disabled = config.getStringList("disabled-spells", new LinkedList<String>());
|
||||||
|
this.disabledOnBoss = config.getStringList("disabled-only-on-bosses", new LinkedList<String>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableSpell(String spell)
|
||||||
|
{
|
||||||
|
disabled.add(spell);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableSpellOnBoss(String spell)
|
||||||
|
{
|
||||||
|
disabledOnBoss.add(spell);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,15 +183,15 @@ public class FileUtils
|
|||||||
extractFile(MobArena.dir, filename);
|
extractFile(MobArena.dir, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void extractFile(File dir, String filename)
|
public static File extractFile(File dir, String filename)
|
||||||
{
|
{
|
||||||
// Skip if file exists
|
// Skip if file exists
|
||||||
File file = new File(dir, filename);
|
File file = new File(dir, filename);
|
||||||
if (file.exists()) return;
|
if (file.exists()) return file;
|
||||||
|
|
||||||
// Skip if there is no resource with that name
|
// Skip if there is no resource with that name
|
||||||
InputStream in = MobArena.class.getResourceAsStream("/res/" + filename);
|
InputStream in = MobArena.class.getResourceAsStream("/res/" + filename);
|
||||||
if (in == null) return;
|
if (in == null) return null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -206,11 +206,15 @@ public class FileUtils
|
|||||||
|
|
||||||
if (in != null) in.close();
|
if (in != null) in.close();
|
||||||
if (out != null) out.close();
|
if (out != null) out.close();
|
||||||
|
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
MobArena.warning("Problem creating file '" + filename + "'!");
|
MobArena.warning("Problem creating file '" + filename + "'!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user