private void saveData(CommandSender cs) { try { PluginData.saveData(); } catch (IOException ex) { sendIOErrorMessage(cs); Logger.getLogger(AtpSet.class.getName()).log(Level.SEVERE, null, ex); } }
@Override protected void execute(CommandSender cs, String... args) { areaName = args[0]; area = PluginData.getTeleportationArea(args[0]); center = ((Player) cs).getLocation().clone(); cuboid = true; if (args.length > 1) { if (args[1].equalsIgnoreCase("sphere")) { cuboid = false; } else if (!args[1].equalsIgnoreCase("cuboid")) { sentInvalidArgumentMessage(cs); } } if (area == null) { if (cuboid) { area = new CuboidTeleportationArea(center); } else { area = new SphericalTeleportationArea(center); } PluginData.addTeleportationArea(areaName, area); saveData(cs); sendNewAreaMessage(cs); } else { newDynamic = area.isDynamic(); if (area.isDynamic() && !area.getTarget().getWorld().equals(((Player) cs).getWorld())) { newDynamic = false; sendDynamicToStaticMessage(cs); } boolean wasCuboid = area instanceof CuboidTeleportationArea; if (cuboid != wasCuboid) { new ConfirmationFactory(AutoTeleportPlugin.getPluginInstance()) .start( (Player) cs, "Specified shape differs from current shape. " + "You will need to define area size again. Do you want to continue?", this); return; } area.setCenter(center); area.setDynamic(newDynamic); saveData(cs); sendCenterSetMessage(cs); } }
@Override public void confirmed(Player player) { Location target = area.getTarget(); boolean keepOrientation = area.isKeepOrientation(); if (cuboid) { area = new CuboidTeleportationArea(center); } else { area = new SphericalTeleportationArea(center); } area.setDynamic(newDynamic); area.setTarget(target); area.setKeepOrientation(keepOrientation); PluginData.addTeleportationArea(areaName, area); saveData(player); sendCenterAndShapeMessage(player); }
private void sendCenterAndShapeMessage(Player player) { PluginData.getMessageUtil() .sendInfoMessage(player, "Center and shape of teleport area was changed."); }
private void sendNewAreaMessage(CommandSender cs) { PluginData.getMessageUtil().sendInfoMessage(cs, "New teleport area created."); }
private void sendCenterSetMessage(CommandSender cs) { PluginData.getMessageUtil() .sendInfoMessage(cs, "Center of teleport area was moved to your location."); }
@Override public void cancelled(Player player) { PluginData.getMessageUtil() .sendErrorMessage(player, "You cancelled setting of area. No changes were made."); }