Solved Topspin script, doesnt start at 45 degree angle

Discussion in 'Spigot Plugin Development' started by Attacler, Apr 14, 2017.

  1. Hello there,

    I made a simple script to make a topspin but i want that it starts where the redstone block is, now it starts at the obsidian block.
    [​IMG]
    package Main;

    import java.io.File;
    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.ArmorStand;
    import org.bukkit.entity.Minecart;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.util.Vector;

    public class Topspin extends JavaPlugin{
    public Map<ArmorStand, Double> ar = new HashMap<ArmorStand, Double>();
    //setup
    File ride = new File(this.getDataFolder()+"/data/ride.yml");
    FileConfiguration ridec = YamlConfiguration.loadConfiguration(ride);
    public void saveCustomYml(FileConfiguration ymlConfig, File ymlFile) {
    try {
    ymlConfig.save(ymlFile);
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    {
    if(cmd.getName().equalsIgnoreCase("topspin")){

    Location lo = new Location(Bukkit.getWorld(args[0]), Integer.valueOf(args[1]), Integer.valueOf(args[2]), Integer.valueOf(args[3]));
    Location loc = lo.clone().add(0, -4, 0);
    for(int x = 0; x < 6; x++){
    Minecart m1 = (Minecart)lo.getWorld().spawn(lo, Minecart.class);
    loc.setDirection(new Vector(0,0,180));
    if(x == 1){
    loc.add(1, 0, 0);
    }
    if(x == 2){
    loc.add(1, 0, 0);
    }
    if(x == 3){
    loc.add(1, 0, 0);
    }
    if(x == 4){
    loc.add(1, 0, 0);
    }
    if(x == 5){
    loc.add(1, 0, 0);
    }
    Bukkit.getLogger().info(loc.toString());
    ArmorStand a = (ArmorStand)lo.getWorld().spawn(loc, ArmorStand.class);
    ar.put(a, (double) 4);
    a.setVisible(false);
    a.setPassenger(m1);
    a.setSmall(true);
    if(ridec.get(args[4] + ".maximum") == null){
    ridec.set(args[4] + ".maximum", (int) 0);
    for(int z = 0; z < 10;z++){
    ridec.set(args[4] + "." + z, (int) 1);
    }
    saveCustomYml(ridec, ride);
    }
    new BukkitRunnable()
    {
    int z =0;
    boolean spinf = true;
    double angle1 = 0D;
    double step1 = ((2 * Math.PI) / 100.0D);
    double speed1 = 0.1875D;

    @Override
    public void run() {
    Bukkit.getLogger().info("" + z + " "+ ridec.getInt(args[4] + ".maximum"));
    if(z >= ridec.getInt(args[4] + ".maximum")){
    Bukkit.getScheduler().cancelTask(getTaskId());
    return;
    }
    if(angle1 < ridec.getDouble(args[4] + "." + z) *6.3){
    if(spinf){
    a.setVelocity(new Vector(0.0D, -Math.cos(angle1 + 1.5) * speed1, Math.sin(angle1 + 1.5) * speed1));
    angle1 += step1;
    }else{
    a.setVelocity(new Vector(0.0D, Math.cos(angle1 + 1.5) * speed1, -Math.sin(angle1 + 1.5) * speed1));
    angle1 -= step1;
    }
    }
    if(spinf){
    if(angle1 > ridec.getDouble(args[4] + "." + z)*6.29){
    spinf = false;
    angle1 = 6.25;
    z++;
    }
    }else{
    if(angle1 < 0.1){
    spinf = true;
    angle1 = 0;
    z++;
    }

    }
    Bukkit.getLogger().info(""+Double.valueOf(angle1));
    }
    }.runTaskTimer(this, 0L, 1L);
    }
    }
    return true;
    }

    public boolean iseven(int z){
    if ( z % 2 == 0 )
    return true;
    else
    return false;
    }
    }
    Can some one help me to do this?

    Bye,
    Bart
     
  2. Hey,
    set "angle1" to Math.PI / 2 when you creating the variable.
     
    • Like Like x 1
  3. Thanks, i already made a better script of it, ill mark this al solved