use of com.elmakers.mine.bukkit.api.block.magic.MagicBlock in project MagicPlugin by elBukkit.
the class MagicBlockPopulator method populate.
@Override
public BlockResult populate(Block block, Random random) {
if (replace != null && !replace.testBlock(block)) {
return BlockResult.SKIP;
}
String templateKey = RandomUtils.weightedRandom(templateProbability);
if (templateKey.equalsIgnoreCase("none")) {
return BlockResult.SKIP;
}
try {
BlockResult result = BlockResult.valueOf(templateKey.toUpperCase());
return result;
} catch (Exception ignore) {
}
Location location = block.getLocation();
MagicBlock automaton = controller.addMagicBlock(location, templateKey, null, null, parameters);
String message = " magic block: " + templateKey + " at " + location.getWorld().getName() + "," + location.toVector();
if (automaton == null) {
message = "Failed to create" + message;
} else {
message = "Created" + message;
}
controller.info(message);
return automaton == null ? BlockResult.SKIP : BlockResult.REMOVE_DROPS;
}
use of com.elmakers.mine.bukkit.api.block.magic.MagicBlock in project MagicPlugin by elBukkit.
the class FindMagicBlocksAction method addLocations.
@Override
public void addLocations(CastContext context, List<Location> locations) {
if (targetMagicBlocks == null)
return;
context.addWork(20);
Mage mage = context.getMage();
Location sourceLocation = context.getTargetLocation();
if (mage.getDebugLevel() > 8) {
mage.sendDebugMessage(ChatColor.GREEN + "Finding magic blocks from " + ChatColor.GRAY + sourceLocation.getBlockX() + ChatColor.DARK_GRAY + "," + ChatColor.GRAY + sourceLocation.getBlockY() + ChatColor.DARK_GRAY + "," + ChatColor.GRAY + sourceLocation.getBlockZ() + ChatColor.DARK_GREEN + " with radius of " + ChatColor.GREEN + radius, 14);
}
Collection<MagicBlock> magicBlocks = context.getController().getMagicBlocks();
for (MagicBlock magicBlock : magicBlocks) {
if (!targetMagicBlocks.contains(magicBlock.getTemplateKey()))
continue;
Location location = targetBlockMage ? magicBlock.getMage().getLocation() : magicBlock.getLocation();
if (!allowCrossWorld || radius > 0) {
if (location == null || location.getWorld() == null || !location.getWorld().equals(sourceLocation.getWorld()))
continue;
} else if (radius > 0) {
if (location.distanceSquared(sourceLocation) > radius * radius)
continue;
}
locations.add(location);
}
}
use of com.elmakers.mine.bukkit.api.block.magic.MagicBlock in project MagicPlugin by elBukkit.
the class ArenaCommandExecutor method onConfigureArena.
protected void onConfigureArena(CommandSender sender, Arena arena, String propertyName, String[] args) {
if (propertyName.equalsIgnoreCase("randomize")) {
String randomizeType = "spawn";
if (args.length > 0) {
randomizeType = args[0];
}
String vectorParameter = null;
if (args.length > 1) {
vectorParameter = args[1];
}
if (randomizeType.equalsIgnoreCase("spawn")) {
if (vectorParameter == null || vectorParameter.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Cleared randomized spawn of " + arena.getName());
arena.setRandomizeSpawn(null);
} else {
Vector vector = ConfigurationUtils.toVector(vectorParameter);
sender.sendMessage(ChatColor.AQUA + "Set randomized spawn of " + arena.getName() + " to " + vector);
arena.setRandomizeSpawn(vector);
}
return;
}
sender.sendMessage(ChatColor.RED + "Not a valid randomization option: " + randomizeType);
sender.sendMessage(ChatColor.AQUA + "Options: " + StringUtils.join(ARENA_RANDOMIZE, ", "));
return;
}
if (propertyName.equalsIgnoreCase("lobby") || propertyName.equalsIgnoreCase("spawn") || propertyName.equalsIgnoreCase("win") || propertyName.equalsIgnoreCase("lose") || propertyName.equalsIgnoreCase("center") || propertyName.equalsIgnoreCase("exit") || propertyName.equalsIgnoreCase("add") || propertyName.equalsIgnoreCase("remove")) {
boolean isAdd = propertyName.equalsIgnoreCase("add");
boolean isRemove = propertyName.equalsIgnoreCase("remove");
if (isAdd || isRemove) {
String subItem = "spawn";
if (args.length > 0) {
subItem = args[0];
}
if (subItem.equalsIgnoreCase("spawn")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Must be used in-game");
return;
}
Player player = (Player) sender;
Location location = player.getLocation();
if (isAdd) {
arena.addSpawn(location);
sender.sendMessage(ChatColor.AQUA + "You have added a spawn location!");
} else {
Location removed = arena.removeSpawn(location);
if (removed != null) {
sender.sendMessage(ChatColor.AQUA + "You have removed a spawn location at: " + removed.toVector());
} else {
sender.sendMessage(ChatColor.RED + "No nearby spawn locations");
}
}
return;
}
if (subItem.equalsIgnoreCase("magic_block")) {
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: " + ChatColor.WHITE + "/marena configure <arena> add magic_block <block name>");
return;
}
String blockKey = args[1];
if (isAdd) {
MagicBlock magicBlock = controller.getMagicBlock(blockKey);
if (magicBlock == null) {
sender.sendMessage(ChatColor.RED + "Could not find magic block: " + ChatColor.WHITE + blockKey);
return;
}
magicBlock.disable();
arena.addMagicBlock(blockKey);
sender.sendMessage(ChatColor.AQUA + "You have added a magic block to this arena: " + ChatColor.DARK_AQUA + blockKey);
} else {
boolean removed = arena.removeMagicBlock(blockKey);
if (removed) {
sender.sendMessage(ChatColor.AQUA + "You have removed the magic block: " + ChatColor.DARK_AQUA + blockKey);
} else {
sender.sendMessage(ChatColor.RED + "This arena doesn't have a magic block " + ChatColor.YELLOW + blockKey);
}
}
return;
}
sender.sendMessage(ChatColor.RED + "Not a valid add/remove option: " + subItem);
sender.sendMessage(ChatColor.AQUA + "Options: " + StringUtils.join(ARENA_LISTS, ", "));
return;
}
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Must be used in-game");
return;
}
Player player = (Player) sender;
Location location = player.getLocation();
if (propertyName.equalsIgnoreCase("lobby")) {
arena.setLobby(location);
sender.sendMessage(ChatColor.AQUA + "You have set the lobby!");
} else if (propertyName.equalsIgnoreCase("spawn")) {
arena.setSpawn(location);
sender.sendMessage(ChatColor.AQUA + "You have set the spawn location!");
} else if (propertyName.equalsIgnoreCase("exit")) {
arena.setExit(location);
sender.sendMessage(ChatColor.AQUA + "You have set the exit location!");
} else if (propertyName.equalsIgnoreCase("center")) {
arena.setCenter(location);
sender.sendMessage(ChatColor.AQUA + "You have set the center location!");
} else if (propertyName.equalsIgnoreCase("lose")) {
arena.setLoseLocation(location);
sender.sendMessage(ChatColor.AQUA + "You have set the spectating room!");
} else if (propertyName.equalsIgnoreCase("win")) {
arena.setWinLocation(location);
sender.sendMessage(ChatColor.AQUA + "You have set the treasure room!");
}
return;
}
String propertyValue = null;
if (args.length > 0) {
propertyValue = StringUtils.join(args, " ");
}
if (propertyName.equalsIgnoreCase("name")) {
if (propertyValue == null || propertyValue.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Cleared name of " + arena.getName());
} else {
sender.sendMessage(ChatColor.AQUA + "Changed name of " + arena.getName() + " to " + propertyValue);
}
arena.setName(propertyValue);
return;
}
if (propertyName.equalsIgnoreCase("description")) {
if (propertyValue == null || propertyValue.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Cleared description of " + arena.getName());
} else {
sender.sendMessage(ChatColor.AQUA + "Change description of " + arena.getName() + " to " + propertyValue);
}
arena.setDescription(propertyValue);
return;
}
if (propertyName.equalsIgnoreCase("portal_death_message")) {
if (propertyValue == null || propertyValue.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Cleared portal death message of " + arena.getName());
} else {
sender.sendMessage(ChatColor.AQUA + "Change portal death message of " + arena.getName() + " to " + propertyValue);
}
arena.setPortalDeathMessage(propertyValue);
return;
}
if (propertyName.equalsIgnoreCase("sudden_death_effect")) {
if (arena.setSuddenDeathEffect(propertyValue)) {
sender.sendMessage(ChatColor.AQUA + "Set sudden death effects for " + arena.getName());
} else {
sender.sendMessage(ChatColor.RED + "Cleared sudden death effects for " + arena.getName());
}
return;
}
if (propertyName.equalsIgnoreCase("start_commands")) {
arena.setStartCommands(propertyValue);
if (propertyValue == null || propertyValue.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Cleared start commands for " + arena.getName());
} else {
sender.sendMessage(ChatColor.AQUA + "Set start commands for " + arena.getName());
}
return;
}
if (propertyName.equalsIgnoreCase("end_commands")) {
arena.setEndCommands(propertyValue);
if (propertyValue == null || propertyValue.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Cleared end commands for " + arena.getName());
} else {
sender.sendMessage(ChatColor.AQUA + "Set end commands for " + arena.getName());
}
return;
}
if (propertyName.equalsIgnoreCase("template")) {
if (propertyValue == null) {
arena.setTemplate(null);
sender.sendMessage(ChatColor.YELLOW + "Cleared template for " + ChatColor.GOLD + arena.getName());
return;
}
ArenaTemplate template = arenaController.getTemplate(propertyValue);
if (template == null) {
sender.sendMessage(ChatColor.RED + "Unknown arena tempalte " + ChatColor.YELLOW + propertyValue);
return;
}
arena.setTemplate(template);
sender.sendMessage(ChatColor.AQUA + "Set template to " + ChatColor.DARK_AQUA + propertyValue);
return;
}
if (propertyName.equalsIgnoreCase("border")) {
if (propertyValue == null || propertyValue.isEmpty()) {
arena.setBorder(0, 0);
sender.sendMessage(ChatColor.RED + "Cleared border for " + arena.getName());
} else {
int min = 0;
int max = 0;
try {
if (propertyValue.contains("-")) {
String[] pieces = StringUtils.split(propertyValue, '-');
max = Integer.parseInt(pieces[0]);
min = Integer.parseInt(pieces[1]);
if (min > max) {
int temp = min;
min = max;
max = temp;
}
} else {
max = Integer.parseInt(propertyValue);
}
} catch (Exception ignore) {
}
arena.setBorder(min, max);
sender.sendMessage(ChatColor.AQUA + "Set border for " + arena.getName() + " to " + max + "-" + min);
}
return;
}
if (propertyValue == null) {
sender.sendMessage(ChatColor.RED + "Must specify a property value");
return;
}
if (propertyName.equalsIgnoreCase("op_check")) {
boolean checkOn = propertyValue.equalsIgnoreCase("true");
if (checkOn) {
sender.sendMessage(ChatColor.RED + "Enabled OP check for " + arena.getName());
} else {
sender.sendMessage(ChatColor.AQUA + "Disabled OP check for " + arena.getName());
}
arena.setOpCheck(checkOn);
return;
}
if (propertyName.equalsIgnoreCase("allow_interrupt")) {
boolean checkOn = propertyValue.equalsIgnoreCase("true");
if (checkOn) {
sender.sendMessage(ChatColor.RED + "Allow joining mid-match for " + arena.getName());
} else {
sender.sendMessage(ChatColor.AQUA + "Don't allow joining mid-match for " + arena.getName());
}
arena.setAllowInterrupt(checkOn);
return;
}
if (propertyName.equalsIgnoreCase("keep_inventory")) {
boolean keepOn = propertyValue.equalsIgnoreCase("true");
if (keepOn) {
sender.sendMessage(ChatColor.GREEN + "Enabled keep inventory for " + arena.getName());
} else {
sender.sendMessage(ChatColor.RED + "Disabled keep inventory for " + arena.getName());
}
arena.setKeepInventory(keepOn);
return;
}
if (propertyName.equalsIgnoreCase("item_wear")) {
boolean wear = propertyValue.equalsIgnoreCase("true");
if (wear) {
sender.sendMessage(ChatColor.GREEN + "Enabled item wear for " + arena.getName());
} else {
sender.sendMessage(ChatColor.RED + "Disabled item wear for " + arena.getName());
}
arena.setItemWear(wear);
return;
}
if (propertyName.equalsIgnoreCase("allow_consuming")) {
boolean consume = propertyValue.equalsIgnoreCase("true");
if (consume) {
sender.sendMessage(ChatColor.GREEN + "Enabled consuming for " + arena.getName());
} else {
sender.sendMessage(ChatColor.RED + "Disabled consuming for " + arena.getName());
}
arena.setAllowConsuming(consume);
return;
}
if (propertyName.equalsIgnoreCase("heal")) {
boolean heal = propertyValue.equalsIgnoreCase("true");
if (heal) {
sender.sendMessage(ChatColor.GREEN + "Enabled healing for " + arena.getName());
} else {
sender.sendMessage(ChatColor.RED + "Disabled healing for " + arena.getName());
}
arena.setHeal(heal);
return;
}
if (propertyName.equalsIgnoreCase("allow_melee")) {
boolean allow = propertyValue.equalsIgnoreCase("true");
if (allow) {
sender.sendMessage(ChatColor.GREEN + "Enabled melee for " + arena.getName());
} else {
sender.sendMessage(ChatColor.RED + "Disabled melee for " + arena.getName());
}
arena.setAllowMelee(allow);
return;
}
if (propertyName.equalsIgnoreCase("allow_projectiles")) {
boolean allow = propertyValue.equalsIgnoreCase("true");
if (allow) {
sender.sendMessage(ChatColor.GREEN + "Enabled projectile weapons for " + arena.getName());
} else {
sender.sendMessage(ChatColor.RED + "Disabled projectile weapons for " + arena.getName());
}
arena.setAllowProjectiles(allow);
return;
}
if (propertyName.equalsIgnoreCase("leaderboard_sign_type")) {
try {
Material signMaterial = Material.valueOf(propertyValue.toUpperCase());
arena.setLeaderboardSignType(signMaterial);
sender.sendMessage(ChatColor.RED + "Set leaderboard sign type to " + signMaterial.name().toLowerCase());
arena.updateLeaderboard();
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "Invalid sign type: " + propertyValue);
}
return;
}
if (propertyName.equalsIgnoreCase("keep_level")) {
boolean keepOn = propertyValue.equalsIgnoreCase("true");
if (keepOn) {
sender.sendMessage(ChatColor.GREEN + "Enabled keep XP levels for " + arena.getName());
} else {
sender.sendMessage(ChatColor.RED + "Disabled keep XP levels for " + arena.getName());
}
arena.setKeepLevel(keepOn);
return;
}
if (propertyName.equalsIgnoreCase("min") || propertyName.equalsIgnoreCase("max") || propertyName.equalsIgnoreCase("portal_damage") || propertyName.equalsIgnoreCase("portal_enter_damage") || propertyName.equalsIgnoreCase("leaderboard_games_required") || propertyName.equalsIgnoreCase("leaderboard_size") || propertyName.equalsIgnoreCase("leaderboard_record_size") || propertyName.equalsIgnoreCase("max_teleport_distance") || propertyName.equalsIgnoreCase("win_xp") || propertyName.equalsIgnoreCase("lose_xp") || propertyName.equalsIgnoreCase("draw_xp") || propertyName.equalsIgnoreCase("win_sp") || propertyName.equalsIgnoreCase("lose_sp") || propertyName.equalsIgnoreCase("draw_sp") || propertyName.equalsIgnoreCase("win_money") || propertyName.equalsIgnoreCase("lose_money") || propertyName.equalsIgnoreCase("draw_money") || propertyName.equalsIgnoreCase("countdown") || propertyName.equalsIgnoreCase("countdown_max") || propertyName.equalsIgnoreCase("announcer_range") || propertyName.equalsIgnoreCase("duration") || propertyName.equalsIgnoreCase("sudden_death")) {
Integer intValue;
try {
intValue = Integer.parseInt(propertyValue);
} catch (Exception ex) {
intValue = null;
}
if (intValue == null) {
sender.sendMessage(ChatColor.RED + "Not a valid integer: " + propertyValue);
return;
}
if (propertyName.equalsIgnoreCase("duration")) {
arena.setDuration(intValue * 1000);
sender.sendMessage(ChatColor.AQUA + "Set duration of " + arena.getName() + " to " + intValue + " seconds");
return;
}
if (propertyName.equalsIgnoreCase("sudden_death")) {
arena.setSuddenDeath(intValue * 1000);
sender.sendMessage(ChatColor.AQUA + "Set sudden death time of " + arena.getName() + " to " + intValue + " seconds before end");
return;
}
if (propertyName.equalsIgnoreCase("countdown")) {
arena.setCountdown(intValue);
sender.sendMessage(ChatColor.AQUA + "Set countdown of " + arena.getName() + " to " + intValue + " seconds");
return;
}
if (propertyName.equalsIgnoreCase("countdown_max")) {
arena.setCountdownMax(intValue);
sender.sendMessage(ChatColor.AQUA + "Set max countdown of " + arena.getName() + " to " + intValue + " seconds");
return;
}
if (propertyName.equalsIgnoreCase("max_teleport_distance")) {
arena.setMaxTeleportDistance(intValue);
sender.sendMessage(ChatColor.AQUA + "Set max teleport distance of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("announcer_range")) {
arena.setAnnouncerRange(intValue);
sender.sendMessage(ChatColor.AQUA + "Set announcer range of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("leaderboard_games_required")) {
arena.setLeaderboardGamesRequired(intValue);
sender.sendMessage(ChatColor.AQUA + "Set # games required for leaderboard on " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("leaderboard_size")) {
arena.setLeaderboardSize(intValue);
sender.sendMessage(ChatColor.AQUA + "Set leaderboard size of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("leaderboard_record_size")) {
arena.setLeaderboardRecordSize(intValue);
sender.sendMessage(ChatColor.AQUA + "Set leaderboard record size of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("min")) {
arena.setMinPlayers(intValue);
sender.sendMessage(ChatColor.AQUA + "Set min players of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("max")) {
arena.setMaxPlayers(intValue);
sender.sendMessage(ChatColor.AQUA + "Set max players of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("win_xp")) {
arena.setWinXP(intValue);
sender.sendMessage(ChatColor.AQUA + "Set winning XP of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("lose_xp")) {
arena.setLoseXP(intValue);
sender.sendMessage(ChatColor.AQUA + "Set losing XP of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("draw_xp")) {
arena.setDrawXP(intValue);
sender.sendMessage(ChatColor.AQUA + "Set draw XP of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("win_sp")) {
arena.setWinSP(intValue);
sender.sendMessage(ChatColor.AQUA + "Set winning SP of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("lose_sp")) {
arena.setLoseSP(intValue);
sender.sendMessage(ChatColor.AQUA + "Set losing SP of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("draw_sp")) {
arena.setDrawSP(intValue);
sender.sendMessage(ChatColor.AQUA + "Set draw SP of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("win_money")) {
arena.setWinMoney(intValue);
sender.sendMessage(ChatColor.AQUA + "Set winning money of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("lose_money")) {
arena.setLoseMoney(intValue);
sender.sendMessage(ChatColor.AQUA + "Set losing money of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("draw_money")) {
arena.setDrawMoney(intValue);
sender.sendMessage(ChatColor.AQUA + "Set draw money of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("portal_damage")) {
arena.setPortalDamage(intValue);
sender.sendMessage(ChatColor.AQUA + "Set portal damage of " + arena.getName() + " to " + intValue);
return;
}
if (propertyName.equalsIgnoreCase("portal_enter_damage")) {
arena.setPortalEnterDamage(intValue);
sender.sendMessage(ChatColor.AQUA + "Set portal entry damage of " + arena.getName() + " to " + intValue);
return;
}
}
sender.sendMessage(ChatColor.RED + "Not a valid property: " + propertyName);
sender.sendMessage(ChatColor.AQUA + "Options: " + StringUtils.join(ARENA_PROPERTIES, ", "));
}
Aggregations