mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-26 04:25:21 +01:00
Introduced magicspells.yml for disabling custom spells.
This commit is contained in:
parent
34f688da70
commit
b85f87f856
BIN
MobArena.jar
BIN
MobArena.jar
Binary file not shown.
13
resources/res/magicspells.yml
Normal file
13
resources/res/magicspells.yml
Normal file
@ -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;
|
||||
|
||||
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.MobArena;
|
||||
import com.garbagemule.MobArena.util.FileUtils;
|
||||
import com.nisovin.MagicSpells.Events.SpellCastEvent;
|
||||
import com.nisovin.MagicSpells.Events.SpellListener;
|
||||
|
||||
public class MagicSpellsListener extends SpellListener
|
||||
{
|
||||
private MobArena plugin;
|
||||
private List<String> disabled, disabledOnBoss;
|
||||
|
||||
public MagicSpellsListener(MobArena 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)
|
||||
@ -19,7 +33,25 @@ public class MagicSpellsListener extends SpellListener
|
||||
Arena arena = plugin.getAM().getArenaWithPlayer(event.getCaster());
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public static void extractFile(File dir, String filename)
|
||||
public static File extractFile(File dir, String filename)
|
||||
{
|
||||
// Skip if file exists
|
||||
File file = new File(dir, filename);
|
||||
if (file.exists()) return;
|
||||
if (file.exists()) return file;
|
||||
|
||||
// Skip if there is no resource with that name
|
||||
InputStream in = MobArena.class.getResourceAsStream("/res/" + filename);
|
||||
if (in == null) return;
|
||||
if (in == null) return null;
|
||||
|
||||
try
|
||||
{
|
||||
@ -206,11 +206,15 @@ public class FileUtils
|
||||
|
||||
if (in != null) in.close();
|
||||
if (out != null) out.close();
|
||||
|
||||
return file;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
MobArena.warning("Problem creating file '" + filename + "'!");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user