use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class MagicController method clear.
protected void clear() {
initialized = false;
Collection<Mage> saveMages = new ArrayList<Mage>(mages.values());
for (Mage mage : saveMages) {
playerQuit(mage);
}
mages.clear();
pendingConstruction.clear();
spells.clear();
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class MagicController method undoRecent.
@Nullable
@Override
public UndoList undoRecent(Block target, int timeout) {
for (Mage mage : mages.values()) {
com.elmakers.mine.bukkit.api.block.UndoQueue queue = mage.getUndoQueue();
UndoList undid = queue.undoRecent(target, timeout);
if (undid != null) {
return undid;
}
}
return null;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class MagicController method clearCache.
public void clearCache() {
schematics.clear();
for (Mage mage : mages.values()) {
if (mage instanceof com.elmakers.mine.bukkit.magic.Mage) {
((com.elmakers.mine.bukkit.magic.Mage) mage).clearCache();
}
}
maps.clearCache();
maps.resetAll();
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class SourceLocation method getLocation.
@Nullable
public Location getLocation(CastContext context) {
Mage mage;
Location eyeLocation;
Location feetLocation;
if (isSource) {
mage = context.getMage();
eyeLocation = context.getEyeLocation();
feetLocation = context.getLocation();
} else {
Entity targetEntity = context.getTargetEntity();
if (targetEntity == null) {
mage = null;
feetLocation = context.getTargetLocation();
eyeLocation = context.getTargetLocation();
} else {
mage = context.getController().getRegisteredMage(targetEntity);
feetLocation = targetEntity.getLocation();
eyeLocation = targetEntity instanceof LivingEntity ? ((LivingEntity) targetEntity).getEyeLocation() : targetEntity.getLocation();
}
}
if (mage == null && (locationType == LocationType.CAST || locationType == LocationType.WAND)) {
locationType = LocationType.EYES;
}
Location location = null;
switch(locationType) {
case CAST:
if (isSource) {
location = context.getCastLocation();
} else {
location = mage.getCastLocation();
}
break;
case EYES:
location = eyeLocation;
break;
case FEET:
location = feetLocation;
break;
case WAND:
if (isSource) {
location = context.getWandLocation();
} else {
location = mage.getWandLocation();
}
break;
case BODY:
if (eyeLocation != null && feetLocation != null) {
location = eyeLocation.clone().add(feetLocation).multiply(0.5);
}
break;
case HIT:
location = context.getTargetLocation();
break;
case BLOCK:
if (feetLocation != null) {
location = feetLocation.getBlock().getLocation();
}
break;
}
if (location == null) {
location = feetLocation;
}
Location targetLocation = isSource ? context.getTargetLocation() : context.getLocation();
if (orientToTarget && targetLocation != null && location != null) {
Vector direction = targetLocation.toVector().subtract(location.toVector()).normalize();
if (MathUtils.isFinite(direction.getX()) && MathUtils.isFinite(direction.getY()) && MathUtils.isFinite(direction.getZ())) {
location.setDirection(direction);
}
}
return location;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class CastCommandExecutor method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
String commandName = command.getName();
if (commandName.equalsIgnoreCase("castp")) {
if (!api.hasPermission(sender, "Magic.commands.castp")) {
sendNoPermission(sender);
return true;
}
if (args.length < 1) {
if (sender != null)
sender.sendMessage("Usage: /castp [player] [spell] <parameters>");
return true;
}
String playerName = args[0];
// Look for Entity-based Mages
Mage mage = null;
if (playerName.contains(",")) {
String[] idPieces = StringUtils.split(playerName, ',');
if (idPieces.length == 4 || idPieces.length == 2) {
try {
String worldName = idPieces[0];
String entityId = idPieces[idPieces.length - 1];
World world = Bukkit.getWorld(worldName);
if (world == null) {
if (sender != null)
sender.sendMessage("Unknown world: " + worldName);
return false;
}
Entity entity = NMSUtils.getEntity(world, UUID.fromString(entityId));
if (entity == null) {
if (sender != null)
sender.sendMessage("Entity not found with id " + entityId + " in " + world.getName());
return false;
}
MageController controller = api.getController();
mage = controller.getMage(entity);
// If we have the mage, we no longer want to send anything to the console.
sender = null;
} catch (Throwable ex) {
if (sender != null)
sender.sendMessage("Your spell failed (badly... check server logs)");
ex.printStackTrace();
return false;
}
}
} else if (playerName.contains(":")) {
// Look for custom id/name Mages
String[] pieces = StringUtils.split(playerName, ':');
String mageId = pieces[0];
String mageName = (pieces.length > 0) ? pieces[1] : mageId;
MageController controller = api.getController();
mage = controller.getMage(mageId, mageName);
}
if (mage != null && !mage.isLoading()) {
String[] castParameters = Arrays.copyOfRange(args, 1, args.length);
if (castParameters.length < 1) {
if (sender != null)
sender.sendMessage("Invalid command line, expecting more parameters");
return false;
}
String spellName = castParameters[0];
Spell spell = mage.getSpell(spellName);
if (spell == null) {
if (sender != null)
sender.sendMessage("Unknown spell " + spellName);
return false;
}
String[] parameters = new String[castParameters.length - 1];
for (int i = 1; i < castParameters.length; i++) {
parameters[i - 1] = castParameters[i];
}
if (spell.cast(parameters)) {
if (sender != null)
sender.sendMessage("Cast " + spell.getName() + " as " + mage.getName());
} else {
if (sender != null)
sender.sendMessage("Failed to cast " + spell.getName() + " as " + mage.getName());
}
return true;
}
Player player = DeprecatedUtils.getPlayer(playerName);
if (player == null) {
if (sender != null)
sender.sendMessage("Can't find player " + playerName);
return true;
}
if (!player.isOnline()) {
if (sender != null)
sender.sendMessage("Player " + playerName + " is not online");
return true;
}
String[] args2 = Arrays.copyOfRange(args, 1, args.length);
return processCastCommand(sender, player, args2);
}
if (commandName.equalsIgnoreCase("cast")) {
if (!api.hasPermission(sender, "Magic.commands.cast")) {
sendNoPermission(sender);
return true;
}
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
}
return processCastCommand(sender, player, args);
}
return false;
}
Aggregations