.
This commit is contained in:
		| @ -0,0 +1,68 @@ | ||||
| package ovh.herisson.thevoidroad.Commands; | ||||
|  | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.WorldBorder; | ||||
| import org.bukkit.command.Command; | ||||
| import org.bukkit.command.CommandExecutor; | ||||
| import org.bukkit.command.CommandSender; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
|  | ||||
| public class VoidCommands implements CommandExecutor{ | ||||
|  | ||||
|     @Override | ||||
|     public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||||
|  | ||||
| 		//balance | ||||
| 		if(args.length == 0){ | ||||
| 			if(sender instanceof Player ply){ | ||||
| 				// long voids = ply.getPersistentDataContainer().has(TheVoidRoad.voids) ? ply.getPersistentDataContainer().get(TheVoidRoad.voids, PersistentDataType.LONG) : 0; | ||||
| 				// ply.sendMessage(Component.text("Vous avez : ").append(Component.text(voids).color(NamedTextColor.GREEN).append(Component.text(TheVoidRoad.CoinGlyph)))); | ||||
| 				return true; | ||||
| 			} | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		//Args | ||||
| 		switch (args[0].toLowerCase()) { | ||||
| 			case "event": | ||||
| 			case "give": | ||||
| 				sender.sendMessage("TODO"); | ||||
| 				return true; | ||||
| 			case "manage":  | ||||
| 				if(sender.hasPermission("TheVoidRoad.manage")) | ||||
| 					return manage(sender, args); | ||||
| 				else | ||||
| 				sender.sendMessage("You don't have the permissions to do that!"); | ||||
| 		} | ||||
| 		return false; | ||||
|     } | ||||
|  | ||||
| 	// Manage sub command | ||||
|     private boolean manage(CommandSender sender, String[] args) { | ||||
| 		switch(args[1]){ | ||||
| 			case "balance": | ||||
| 				switch (args[2]) { | ||||
| 					case "set":  | ||||
| 						// Player ply = Bukkit.getServer().getPlayer(args[3]); | ||||
| 						// ply.getPersistentDataContainer().set(TheVoidRoad.voids, PersistentDataType.LONG, Long.parseLong(args[4])); | ||||
| 						return true; | ||||
| 				} | ||||
| 			case "setspawn": | ||||
| 				if(sender instanceof Player ply){ | ||||
| 					Location loc = ply.getLocation(); | ||||
| 					WorldBorder border = ply.getWorld().getWorldBorder(); | ||||
| 					 | ||||
| 					ply.getWorld().setSpawnLocation(loc); | ||||
| 					border.setCenter(loc); | ||||
| 					border.setSize(750); | ||||
| 				return true; | ||||
| 				} | ||||
| 				break; | ||||
| 			case "init": | ||||
| 				break; | ||||
| 		} | ||||
| 		return false; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,39 @@ | ||||
| package ovh.herisson.thevoidroad; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.sql.Connection; | ||||
| import java.sql.DriverManager; | ||||
| import java.sql.SQLException; | ||||
| import java.sql.Statement; | ||||
|  | ||||
| import org.bukkit.Bukkit; | ||||
|  | ||||
| public class DatabaseManager { | ||||
|  | ||||
| 	private static DatabaseManager instance; | ||||
|  | ||||
| 	public static DatabaseManager getInstance(){ | ||||
| 		if (instance != null) return instance; | ||||
| 		try { instance = new DatabaseManager();} | ||||
| 	   	catch(SQLException e){ Bukkit.getLogger().warning("Could not Initiate database : " + e); } | ||||
| 		return instance; | ||||
| 	} | ||||
|  | ||||
| 	private Connection con; | ||||
|  | ||||
| 	private DatabaseManager() throws SQLException{ | ||||
| 		new File("plugins/TheVoidRoad").mkdirs(); | ||||
| 		con = DriverManager.getConnection("jdbc:sqlite:plugins/TheVoidRoad/voids.db"); | ||||
| 		InitTables(); | ||||
| 	} | ||||
|  | ||||
| 	private void InitTables() throws SQLException{ | ||||
| 		String query = "CREATE TABLE IF NOT EXISTS voids (\n" | ||||
| 			+ "id integer PRIMARY KEY,\n" | ||||
| 			+ "uuid text NOT NULL,\n" | ||||
| 			+ "ammount INTEGER DEFAULT 0)"; | ||||
|  | ||||
| 			Statement st = con.createStatement(); | ||||
| 			st.execute(query); | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,39 @@ | ||||
| package ovh.herisson.thevoidroad.Entity; | ||||
|  | ||||
| import java.util.Random; | ||||
|  | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.entity.EntityType; | ||||
| import org.bukkit.entity.Villager; | ||||
| import org.bukkit.event.Listener; | ||||
|  | ||||
| //Unique, so singleton patern | ||||
| public class Merchand implements Listener{ | ||||
| 	private static Merchand instance; | ||||
|  | ||||
| 	public static Merchand getInstance(){ | ||||
| 		if(instance != null) | ||||
| 			return instance; | ||||
| 		return new Merchand(); | ||||
| 	} | ||||
|  | ||||
| 	private Villager m ; | ||||
| 	private Merchand() { | ||||
| 		int x = new Random().nextInt(750 * 2) - 750, z = new Random().nextInt(750 * 2) - 750; | ||||
| 		m = (Villager) Bukkit.getWorld("world").spawnEntity(new Location(Bukkit.getWorld("world"), x, 300, z), EntityType.VILLAGER); | ||||
| 		m.setGlowing(true); | ||||
| 		m.setInvulnerable(true); | ||||
| 	} | ||||
|  | ||||
| 	public void regenerate(){ | ||||
| 		m.remove(); | ||||
| 		int x = new Random().nextInt(750 * 2) - 750, z = new Random().nextInt(750 * 2) - 750; | ||||
| 		m = (Villager) Bukkit.getWorld("world").spawnEntity(new Location(Bukkit.getWorld("world"), x, 300, z), EntityType.VILLAGER); | ||||
| 		m.setGlowing(true); | ||||
| 		m.setInvulnerable(true); | ||||
| 	} | ||||
|  | ||||
| 	 | ||||
|  | ||||
| } | ||||
| @ -0,0 +1,27 @@ | ||||
| package ovh.herisson.thevoidroad.Event; | ||||
|  | ||||
| import java.time.LocalTime; | ||||
|  | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.event.EventHandler; | ||||
| import org.bukkit.event.Listener; | ||||
|  | ||||
| import com.destroystokyo.paper.event.server.ServerTickStartEvent; | ||||
|  | ||||
| public class NewHourEvent implements Listener{ | ||||
|  | ||||
| 	public int hour = 0; | ||||
| 	@EventHandler | ||||
| 	public void onHour(ServerTickStartEvent e){ | ||||
| 		if(LocalTime.now().getHour() != hour){ | ||||
| 			hour = LocalTime.now().getHour(); | ||||
| 			hourEvent(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	//This function will be called once per hours | ||||
|     private void hourEvent() { | ||||
| 		Bukkit.getLogger().info("test"); //TODO | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -1,17 +1,24 @@ | ||||
| /* | ||||
|  * This Java source file was generated by the Gradle 'init' task. | ||||
|  */ | ||||
| package ovh.herisson.thevoidroad; | ||||
|  | ||||
| import java.util.logging.Level; | ||||
|  | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.event.Listener; | ||||
| import org.bukkit.plugin.java.JavaPlugin; | ||||
|  | ||||
| public class TheVoidRoad extends JavaPlugin{ | ||||
| 	 | ||||
| import ovh.herisson.thevoidroad.Commands.VoidCommands; | ||||
| import ovh.herisson.thevoidroad.Event.NewHourEvent; | ||||
|  | ||||
| public class TheVoidRoad extends JavaPlugin implements Listener{ | ||||
|  | ||||
| 	public static String CoinGlyph = "Ⓥ"; // Ɣ, √, ▼, Ṿ, ṿ | ||||
|  | ||||
| 	@Override | ||||
| 	public void onEnable(){ | ||||
| 		Bukkit.getLogger().log(Level.INFO, "Hello World!"); | ||||
|  | ||||
| 		DatabaseManager db = DatabaseManager.getInstance(); | ||||
|  | ||||
| 		//Commands | ||||
| 		getCommand("void").setExecutor(new VoidCommands()); | ||||
|  | ||||
| 		//Events | ||||
| 		getServer().getPluginManager().registerEvents(new NewHourEvent(), this); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -5,3 +5,7 @@ description: This is a plugin for the void road's server | ||||
| author: Tonitch | ||||
| website: herisson.ovh | ||||
| api-version: '1.20' | ||||
| commands: | ||||
|   void: | ||||
|     description: Interact with the void road plugin | ||||
|     usage: "/void <give|manage>" | ||||
|  | ||||
		Reference in New Issue
	
	Block a user