use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class AnimateSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
if (parameters.getString("animate", null) != null) {
return super.onCast(parameters);
}
final Block targetBlock = getTargetBlock();
if (targetBlock == null) {
return SpellResult.NO_TARGET;
}
if (!hasBuildPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
int seedRadius = parameters.getInt("seed_radius", 0);
MaterialAndData targetMaterial = new MaterialAndData(targetBlock);
List<String> materials = ConfigurationUtils.getStringList(parameters, "materials");
if (seedRadius > 0 && materials != null && !materials.isEmpty()) {
targetMaterial = new MaterialAndData(RandomUtils.getRandom(materials));
} else if (parameters.contains("material")) {
targetMaterial = ConfigurationUtils.getMaterialAndData(parameters, "material", targetMaterial);
if (targetMaterial.isValid()) {
addDestructible(targetMaterial);
}
}
if (!mage.isSuperPowered() && seedRadius == 0) {
MaterialSetManager materialSets = controller.getMaterialSetManager();
MaterialSet restricted = materialSets.getMaterialSet("restricted");
if (restricted != null && restricted.testMaterialAndData(targetMaterial)) {
return SpellResult.FAIL;
}
if (parameters.contains("restricted")) {
String customRestricted = parameters.getString("restricted");
if (customRestricted != null && !customRestricted.equals("restricted")) {
restricted = materialSets.fromConfigEmpty(customRestricted);
if (restricted.testMaterialAndData(targetMaterial)) {
return SpellResult.FAIL;
}
}
}
}
if (!isDestructible(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
registerForUndo(targetBlock);
if (seedRadius > 0) {
for (int dx = -seedRadius; dx < seedRadius; dx++) {
for (int dz = -seedRadius; dz < seedRadius; dz++) {
for (int dy = -seedRadius; dy < seedRadius; dy++) {
Block seedBlock = targetBlock.getRelative(dx, dy, dz);
if (isDestructible(seedBlock)) {
registerForUndo(seedBlock);
targetMaterial.modify(seedBlock);
}
}
}
}
}
// Look for randomized levels
int level = 0;
if (parameters.contains("level")) {
level = parameters.getInt("level", level);
} else if (levelWeights != null) {
level = RandomUtils.weightedRandom(levelWeights);
}
boolean simCheckDestructible = parameters.getBoolean("sim_check_destructible", true);
simCheckDestructible = parameters.getBoolean("scd", simCheckDestructible);
final ConfigurationSection automataParameters = new MemoryConfiguration();
automataParameters.set("target", "self");
automataParameters.set("cooldown", 0);
automataParameters.set("m", targetMaterial.getKey());
automataParameters.set("cd", (simCheckDestructible ? true : false));
automataParameters.set("level", level);
String automataName = parameters.getString("name", "Automata");
Messages messages = controller.getMessages();
String automataType = parameters.getString("message_type", "evil");
List<String> prefixes = messages.getAll("automata." + automataType + ".prefixes");
List<String> suffixes = messages.getAll("automata." + automataType + ".suffixes");
automataName = prefixes.get(random.nextInt(prefixes.size())) + " " + automataName + " " + suffixes.get(random.nextInt(suffixes.size()));
if (level > 1) {
automataName += " " + escapeLevel(messages, "automata.level", level);
}
String message = getMessage("cast_broadcast").replace("$name", automataName);
if (message.length() > 0) {
controller.sendToMages(message, targetBlock.getLocation());
}
automataParameters.set("animate", automataName);
String automataId = UUID.randomUUID().toString();
final Mage mage = controller.getAutomaton(automataId, automataName);
mage.setLocation(targetBlock.getLocation());
mage.setQuiet(true);
mage.addTag(getKey());
final Spell spell = mage.getSpell(getKey());
Bukkit.getScheduler().runTaskLater(controller.getPlugin(), new Runnable() {
@Override
public void run() {
spell.cast(automataParameters);
}
}, 1);
registerForUndo();
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class MagicMobCommandExecutor method onClearMobs.
protected void onClearMobs(CommandSender sender, String[] args) {
String mobType = args.length > 1 ? args[1] : null;
if (mobType != null && mobType.equalsIgnoreCase("all")) {
mobType = null;
}
String worldName = null;
Integer radiusSquared = null;
Location targetLocation = null;
Player player = (sender instanceof Player) ? (Player) sender : null;
BlockCommandSender commandBlock = (sender instanceof BlockCommandSender) ? (BlockCommandSender) sender : null;
if (args.length == 3) {
if (!(sender instanceof ConsoleCommandSender) && Bukkit.getWorld(args[2]) == null) {
try {
int radius = Integer.parseInt(args[2]);
radiusSquared = radius * radius;
} catch (Exception ignored) {
}
}
if (radiusSquared == null) {
worldName = args[2];
} else {
if (player != null) {
targetLocation = player.getLocation();
} else if (commandBlock != null) {
targetLocation = commandBlock.getBlock().getLocation();
} else {
sender.sendMessage(ChatColor.RED + "Invalid world: " + args[2]);
}
}
} else if (args.length > 5) {
World world = null;
if (args.length > 6) {
worldName = args[6];
world = Bukkit.getWorld(worldName);
}
if (world == null) {
sender.sendMessage(ChatColor.RED + "Invalid world: " + worldName);
}
try {
int radius = Integer.parseInt(args[2]);
radiusSquared = radius * radius;
double currentX = 0;
double currentY = 0;
double currentZ = 0;
if (player != null) {
targetLocation = player.getLocation();
} else if (commandBlock != null) {
targetLocation = commandBlock.getBlock().getLocation();
}
if (targetLocation != null) {
currentX = targetLocation.getX();
currentY = targetLocation.getY();
currentZ = targetLocation.getZ();
if (world == null) {
world = targetLocation.getWorld();
worldName = world.getName();
}
}
if (world == null) {
sender.sendMessage(ChatColor.RED + "Usage: mmob clear <type> <radius> <x> <y> <z> <world>");
return;
}
targetLocation = new Location(world, ConfigurationUtils.overrideDouble(args[3], currentX), ConfigurationUtils.overrideDouble(args[4], currentY), ConfigurationUtils.overrideDouble(args[5], currentZ));
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "Usage: mmob clear <type> <radius> <x> <y> <z> <world>");
return;
}
}
Collection<Mage> mages = new ArrayList<>(api.getController().getMobMages());
int removed = 0;
for (Mage mage : mages) {
EntityData entityData = mage.getEntityData();
if (entityData == null)
continue;
if (worldName != null && !mage.getLocation().getWorld().getName().equals(worldName))
continue;
if (mobType != null && !entityData.getKey().equals(mobType))
continue;
if (radiusSquared != null && targetLocation != null && mage.getLocation().distanceSquared(targetLocation) > radiusSquared)
continue;
Entity entity = mage.getEntity();
mage.undoScheduled();
api.getController().removeMage(mage);
if (entity != null) {
entity.remove();
}
removed++;
}
List<World> worlds = new ArrayList<>();
if (worldName != null) {
World world = Bukkit.getWorld(worldName);
if (world == null) {
sender.sendMessage(ChatColor.RED + "Unknown world: " + ChatColor.WHITE + worldName);
return;
}
worlds.add(world);
} else {
worlds.addAll(Bukkit.getWorlds());
}
Set<String> mobNames = new HashSet<>();
if (mobType != null) {
EntityData mob = api.getController().getMob(mobType);
if (mob == null) {
sender.sendMessage(ChatColor.RED + "Unknown mob type: " + ChatColor.WHITE + mobType);
return;
}
mobNames.add(mob.getName());
} else {
Set<String> allKeys = api.getController().getMobKeys();
for (String key : allKeys) {
EntityData mob = api.getController().getMob(key);
mobNames.add(mob.getName());
}
}
for (World world : worlds) {
List<Entity> entities = world.getEntities();
for (Entity entity : entities) {
String customName = entity.getCustomName();
if (entity.isValid() && customName != null && mobNames.contains(customName)) {
if (radiusSquared != null && targetLocation != null && entity.getLocation().distanceSquared(targetLocation) > radiusSquared)
continue;
entity.remove();
removed++;
}
}
}
sender.sendMessage("Removed " + removed + " magic mobs");
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class MagicSaveCommandExecutor method onCommand.
@Override
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
Player player;
if (args.length < 1) {
return false;
}
if (sender instanceof Player) {
player = (Player) sender;
if (!player.hasPermission("Magic.commands.msave")) {
return false;
}
}
player = DeprecatedUtils.getPlayer(args[0]);
if (player == null) {
return false;
}
String executeCommand = "";
for (int i = 1; i < args.length; i++) {
executeCommand = executeCommand + args[i] + " ";
}
MagicController controller = (MagicController) api.getController();
Mage mage = controller.getMage(player);
final String cmd = executeCommand.trim().replace("@p", mage.getName());
final Plugin plugin = controller.getPlugin();
controller.saveMage(mage, true, new MageDataCallback() {
@Override
public void run(MageData data) {
if (cmd.length() > 0) {
plugin.getServer().dispatchCommand(sender, cmd);
}
}
});
return true;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class MagicSkillsCommandExecutor method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!api.hasPermission(sender, "Magic.commands.mskills")) {
sendNoPermission(sender);
return true;
}
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "This command may only be used in-game");
return true;
}
Mage mage = controller.getMage(sender);
SkillSelectorAction selector = new SkillSelectorAction();
int page = 1;
if (args.length > 0) {
try {
page = Integer.parseInt(args[0]);
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "Expect page number, got " + args[0]);
return true;
}
}
selector.setPage(page);
selector.perform(new CastContext(mage));
return true;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class MagicController method sendPlayerToServer.
@Override
public void sendPlayerToServer(final Player player, final String server) {
MageDataCallback callback = new MageDataCallback() {
@Override
public void run(MageData data) {
Bukkit.getScheduler().runTaskLater(plugin, new ChangeServerTask(plugin, player, server), 1);
}
};
info("Moving " + player.getName() + " to server " + server, 1);
Mage mage = getRegisteredMage(player);
if (mage != null) {
playerQuit(mage, callback);
} else {
callback.run(null);
}
}
Aggregations