This commit is contained in:
TheCrunchy committed 2023-07-12 20:03:31 +01:00
1 parent 706e60187c
commit 49ec9c788d
17 files changed
+139 -64

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+3 -1
View File
@@ -5,9 +5,11 @@ import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public interface CrunchProjectile {
public void Shoot(Player player, Entity entity, double XOffset, double YOffset, Float velocity);
public String ProjectileType = "Default";
}
@@ -17,6 +17,7 @@ import siegeCore.CrunchSiegeCore;
public class EntityProjectile implements CrunchProjectile{
public String ProjectileType = "Entity";
public int EntityCount = 20;
public int ArrowOnlyDamage = 6;
public Boolean DelayedFire = false;
@@ -17,7 +17,8 @@ import siegeCore.ClickHandler;
import siegeCore.CrunchSiegeCore;
public class ExplosiveProjectile implements CrunchProjectile {
public String ProjectileType = "Explosive";
public int ExplodePower = 2;
public float Inaccuracy = 0.3f;
public int ProjectilesCount = 1;
@@ -23,6 +23,7 @@ import org.bukkit.util.Vector;
import siegeCore.CrunchSiegeCore;
public class PotionProjectile implements CrunchProjectile {
public String ProjectileType = "Potion";
public int EntityCount = 3;
public Boolean DelayedFire = false;
public int DelayTime = 6;
+20 -3
View File
@@ -1,5 +1,6 @@
package siegeCore;
import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -53,22 +54,38 @@ import CrunchProjectiles.CrunchProjectile;
import CrunchProjectiles.ExplosiveProjectile;
import CrunchProjectiles.PotionProjectile;
public class CrunchSiegeCore extends JavaPlugin {
public static Plugin plugin;
public static Random random = new Random();
private static String Path;
@SuppressWarnings("deprecation")
@Override
public void onEnable() {
plugin = this;
Path = this.getDataFolder().getAbsolutePath();
this.getCommand("siegetest").setExecutor(new SiegeCommand());
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
getServer().getPluginManager().registerEvents(new ClickHandler(), this);
StorageManager.setup(Path, plugin);
AddDefined();
File f = new File(Path + "/Example.Json");
if (!f.exists()) {
for (SiegeEquipment i : DefinedEquipment.values()) {
StorageManager.Save(i);
}
DefinedEquipment.clear();
}
File folder = new File(Path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
SiegeEquipment equip = StorageManager.load(listOfFiles[i].getAbsolutePath());
DefinedEquipment.put(equip.ReadyModelNumber, equip);
}
}
}
public class SiegeCommand implements CommandExecutor {
-59
View File
@@ -36,12 +36,8 @@ public class SiegeEquipment implements Cloneable {
public UUID EntityId;
public Entity Entity;
public ItemStack ItemToPlace;
public HashMap<Material, CrunchProjectile> Projectiles = new HashMap<Material, CrunchProjectile>() ;
public String ItemToUseForModel;
public String WorldName;
public int XOffset = 7;
@@ -49,14 +45,12 @@ public class SiegeEquipment implements Cloneable {
public int MaxFuel = 5;
public float VelocityPerFuel = 0.75f;
public Material FuelMaterial = Material.GUNPOWDER;
public int FuseTime;
public long NextShotTime = System.currentTimeMillis();
public int MillisecondsBetweenFiringStages;
public int MillisecondsBetweenReloadingStages;
public int MillisecondsToLoad;
public Location location;
public int ModelNumberToFireAt;
public Boolean CycleThroughModelsBeforeFiring = false;
public Boolean RotateSideways = false;
@@ -145,7 +139,6 @@ public class SiegeEquipment implements Cloneable {
this.NextModelNumber = 0;
this.location = loc;
// player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
//player.sendMessage("task");
@@ -206,9 +199,6 @@ public class SiegeEquipment implements Cloneable {
loc.add(direction);
this.NextModelNumber = 0;
this.location = loc;
// player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, XOffset, YOffset, loadedFuel * this.VelocityPerFuel);
}, (long) delay);
@@ -216,54 +206,5 @@ public class SiegeEquipment implements Cloneable {
}
}
//
// public void Shoot(Location loc, float loadedFuel, Material LoadedProjectile) {
//
// switch (LoadedProjectile) {
//
// case COBBLESTONE:
// case COPPER_BLOCK:
// {
// float randomVar = random.nextFloat() * (6 - -6) + -6;
// loc.setYaw(loc.getYaw() + randomVar);
// Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
// ClickHandler.projectiles.put(tnt.getUniqueId(), );
// tnt.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel));
// Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_GENERIC_EXPLODE, 20, 2);
// Bukkit.getServer().getWorld(this.WorldName).spawnParticle(Particle.EXPLOSION_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0);
// }
// break;
// case GRAVEL:
// {
// }
// break;
// case TNT:
// {
// for (int i = 0; i < 5; i++) {
// //float randomVar = random.nextFloat() * (15 - -15) + -15;
// Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
// ClickHandler.projectiles.put(tnt.getUniqueId(), Projectiles.get(LoadedProjectile));
// tnt.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel).add(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble())
// .subtract(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble()))));
// Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_GENERIC_EXPLODE, 20, 2);
// Bukkit.getServer().getWorld(this.WorldName).spawnParticle(Particle.EXPLOSION_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0);
// }
// }
// break;
// case FIREWORK_STAR:
// {
// for (int i = 0; i < 4; i++) {
// Entity arrow = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SMALL_FIREBALL);
// arrow.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel).add(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble())
// .subtract(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble()))));
// Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ITEM_CROSSBOW_SHOOT, 20, 2);
// }
// }
// break;
// }
//
//
// }
}
+112
View File
@@ -0,0 +1,112 @@
package siegeCore;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import CrunchProjectiles.CrunchProjectile;
import CrunchProjectiles.EntityProjectile;
import CrunchProjectiles.ExplosiveProjectile;
import CrunchProjectiles.PotionProjectile;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.UUID;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
public class StorageManager {
private static File folder;
private static File storage;
private static Gson gson = new GsonBuilder().setPrettyPrinting().create();
private static Plugin plugin;
public static void setup(String path, Plugin pluginInput) {
plugin = pluginInput;
folder = new File(path);
if (!folder.exists()) folder.mkdir();
}
//put this stuff in a try catch so i dont need a try catch everytime i call the methods
public static SiegeEquipment load(String s) {
storage = new File(s);
FileReader reader;
Deserializer deserializer = new Deserializer();
gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(CrunchProjectile.class, deserializer).create();
SiegeEquipment data = null;
if (!storage.exists()) {
try {
storage.createNewFile();
FileWriter writer = new FileWriter(storage, false);
writer.write(gson.toJson(new SiegeEquipment()));
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
reader = new FileReader(storage);
JsonReader test = new JsonReader(reader);
test.setLenient(true);
Type temp = new TypeToken<SiegeEquipment>() {}.getType();
data = gson.fromJson(test, temp);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return data;
}
public static void Save(SiegeEquipment equipment) {
storage = new File(folder, "Example.json");
FileWriter writer;
try {
writer = new FileWriter(storage, false);
writer.write(gson.toJson(equipment));
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static class Deserializer implements JsonDeserializer<CrunchProjectile> {
private String TypeName = "ProjectileType";
private Gson gson = new Gson();
@Override
public CrunchProjectile deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
JsonObject Object = json.getAsJsonObject();
JsonElement type = Object.get(TypeName);
System.out.println(type.getAsString());
switch (type.getAsString()) {
case "Entity":
return gson.fromJson(Object, EntityProjectile.class);
case "Explosive":
return gson.fromJson(Object, ExplosiveProjectile.class);
case "Potion":
return gson.fromJson(Object, PotionProjectile.class);
}
return null;
}
}
}