commit a82de54648ebfc2abf56b4e64b1454fbf7c1df92 Author: Mysaa Date: Mon May 24 18:45:04 2021 +0200 Premier commit - inclusion dans le système git diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..572533e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.classpath +.settings +.project +bin/ diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..f16c57f --- /dev/null +++ b/plugin.yml @@ -0,0 +1,8 @@ +name: Le Ptit Plugin +main: com.bernard.ptitPlugin.LePtitPlugin +version: beta +api-version: 1.13 +commands: + grenze: + usage: /grenze list + description: Permet de gérer les frontières \ No newline at end of file diff --git a/src/com/bernard/ptitPlugin/LePtitPlugin.java b/src/com/bernard/ptitPlugin/LePtitPlugin.java new file mode 100644 index 0000000..4387d6d --- /dev/null +++ b/src/com/bernard/ptitPlugin/LePtitPlugin.java @@ -0,0 +1,28 @@ +package com.bernard.ptitPlugin; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +public class LePtitPlugin extends JavaPlugin { + + @Override + public void onEnable() { + super.onEnable(); + + + } + + @Override + public void onDisable() { + super.onDisable(); + } + + + + public void setupConfig() { + FileConfiguration config = this.getConfig(); + + this.saveDefaultConfig(); + } + +} diff --git a/src/com/bernard/ptitPlugin/construcation/Construcation.java b/src/com/bernard/ptitPlugin/construcation/Construcation.java new file mode 100644 index 0000000..3c2d9c4 --- /dev/null +++ b/src/com/bernard/ptitPlugin/construcation/Construcation.java @@ -0,0 +1,5 @@ +package com.bernard.ptitPlugin.construcation; + +public class Construcation { + +} diff --git a/src/com/bernard/ptitPlugin/grenzen/GrenzeModif.java b/src/com/bernard/ptitPlugin/grenzen/GrenzeModif.java new file mode 100644 index 0000000..ecdb849 --- /dev/null +++ b/src/com/bernard/ptitPlugin/grenzen/GrenzeModif.java @@ -0,0 +1,230 @@ +package com.bernard.ptitPlugin.grenzen; + +import java.util.HashSet; +import java.util.regex.Pattern; + +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.bernard.ptitPlugin.grenzen.Stockeur.Region; + +public class GrenzeModif implements CommandExecutor{ + + Stockeur stck; + + Pattern REGNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_][a-zA-Z0-9.-_]*$"); + Pattern REGDNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_][a-zA-Z0-9.-_ :&|$#~’;']*$"); + + + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if(!(sender instanceof Player)) { + sender.sendMessage("Cette commande doit être envoyée par un joueur !"); + return true; + } + if(args.length==0) + return false; + + String subcommand = args[0]; + + switch(subcommand) { + + case "new": // nom [displayName] [rayon] + // Crée une nouvelle région + if(args.length<2) + return false; + String nom = args[1]; + String displayName = nom; + if(args.length>=3) + displayName = args[2]; + long rayon = 1; + try { + if(args.length>=4) + rayon = Integer.parseInt(args[3]); + }catch(NumberFormatException e) { + sender.sendMessage("Je ne saurais pas interpréter "+args[3]+" comme un entier …"); + return true; + } + if(rayon < 0) { + sender.sendMessage("Je ne suis pas sur que "+rayon+" soit un entier strictement positif"); + return true; + } + + if(REGNAME_PATTERN.matcher(nom).matches()){ + sender.sendMessage("Ce nom n'est pas légal !"); + return true; + } + + + if(REGDNAME_PATTERN.matcher(displayName).matches()){ + sender.sendMessage("Ce nom d'affichage n'est pas légal !"); + return true; + } + + Region r = new Region(new HashSet<>(), nom, displayName, rayon); + + stck.newRegion(r); + + + break; + + case "remove":// nom + // Supprime une région + if(args.length<2) + return false; + String nom1 = args[1]; + + if(!stck.delRegion(nom1)) { + sender.sendMessage("Je ne connais pas la région "+nom1+" !"); + return true; + } + sender.sendMessage("Région supprimée !"); + + break; + + case "name":// nom displayName + //Définit le nom d'affichage d'une région + if(args.length<2) + return false; + String nom2 = args[1]; + String displayName2 = nom2; + if(args.length>=3) + displayName = args[2]; + + if(REGDNAME_PATTERN.matcher(displayName2).matches()){ + sender.sendMessage("Ce nom d'affichage n'est pas légal !"); + return true; + } + + if(!stck.dnameRegion(nom2,displayName2)) { + sender.sendMessage("Je ne connais pas la région "+nom2+" !"); + return true; + } + sender.sendMessage("Nom d'affichage changé !"); + + break; + + case "list": + // Liste les régions enregistrées, et d'autres infos (nbre points, region) + + sender.sendMessage("Voici la liste des régions enregistrées"); + for (Region reg : stck.regions) { + sender.sendMessage(" - "+reg.nom+" as "+reg.displayName+" : "+reg.points.size()+ " points enregistrés"); + } + + break; + + case "addpt": // nom [x z] + if(args.length<2) + return false; + String nom3 = args[1]; + int x,z; + double poids = 1.; + if(args.length<4) { + if(!(sender instanceof Player)) { + sender.sendMessage("Si vous n'envoyez cette commande en tant que joueur, vous devez préciser les coordonées !"); + return false; + } + Location loc = ((Player)sender).getLocation(); + x=loc.getBlockX(); + z=loc.getBlockZ(); + if(args.length>=3) { + try { + poids = Double.parseDouble(args[2]); + }catch(NumberFormatException e) { + sender.sendMessage("Je ne saurais pas interpréter "+args[2]+" comme un flottant …"); + return true; + } + } + }else { + try { + x = Integer.parseInt(args[3]); + z = Integer.parseInt(args[4]); + }catch(NumberFormatException e) { + sender.sendMessage("Je ne saurais pas interpréter "+args[3]+" "+args[4]+" comme des coordonées entières …"); + return true; + } + + if(args.length>=5) { + try { + poids = Double.parseDouble(args[5]); + }catch(NumberFormatException e) { + sender.sendMessage("Je ne saurais pas interpréter "+args[2]+" comme un flottant …"); + return true; + } + } + } + if(!stck.addPtRegion(nom3,x,z,poids)) { + sender.sendMessage("Je ne connais pas la région "+nom3+" !"); + return true; + } + + break; + + case "delpt": // nom [x z/*exact*/] // sinon nearest + if(args.length<2) + return false; + String nom4 = args[1]; + int x4,z4; + if(args.length<4) { + if(!(sender instanceof Player)) { + sender.sendMessage("Si vous n'envoyez cette commande en tant que joueur, vous devez préciser les coordonées !"); + return false; + } + Location loc = ((Player)sender).getLocation(); + x=loc.getBlockX(); + z=loc.getBlockZ(); + }else { + try { + x = Integer.parseInt(args[3]); + z = Integer.parseInt(args[4]); + }catch(NumberFormatException e) { + sender.sendMessage("Je ne saurais pas interpréter "+args[3]+" "+args[4]+" comme des coordonées entières …"); + return true; + } + } + if(!stck.delNearestPtRegion(nom4,x,z)) { + sender.sendMessage("Je ne connais pas la région "+nom3+" !"); + return true; + } + + break; + + case "modpt": // nom nx ny nz/*nouvelle*/ [ox oy oz] // sinon nearest + break; + + case "clearpts": // nom + // Supprime tous les points de la région séléctionnée + break; + + case "listpts": // nom + // Liste les points de la région, avec le rayon + break; + + case "load": + // Recharge le fichier des régions + break; + + case "modrayon": // rayon + // Redéfinit le rayon + break; + + default: + // Afficher l'aide + break; + + } + + return true; + } + + public Region getReg(String name) { + return stck.regions.stream().filter(r->r.nom.equals(name)).findAny().orElse(null); + } + +} diff --git a/src/com/bernard/ptitPlugin/grenzen/Grenzen.java b/src/com/bernard/ptitPlugin/grenzen/Grenzen.java new file mode 100644 index 0000000..da13640 --- /dev/null +++ b/src/com/bernard/ptitPlugin/grenzen/Grenzen.java @@ -0,0 +1,48 @@ +package com.bernard.ptitPlugin.grenzen; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; + +public class Grenzen implements Listener{ + + public static final double PLAYER_UPDATE_DIST2 = 64.; // distance 8 + + Stockeur stockeur; + + Map lastPlayerPos; + Map> whereis; + + public Grenzen() { + lastPlayerPos = new HashMap(); + stockeur = new Stockeur(); + } + + public void onMoved(PlayerMoveEvent event) { + Player p = event.getPlayer(); + if(!lastPlayerPos.containsKey(p.getUniqueId()) || p.getLocation().distanceSquared(lastPlayerPos.get(p.getUniqueId())) > PLAYER_UPDATE_DIST2) { + lastPlayerPos.put(p.getUniqueId(), p.getLocation()); + + List plast = whereis.get(p.getUniqueId()); + List pWhereIs = stockeur.regionsIn(p.getLocation()); + for (int i = 0; i < plast.size(); i++) { + if(pWhereIs.get(i)!=plast.get(i)) { + if(pWhereIs.get(i)) { + //Est rentré + p.sendMessage("Vous entrez dans le territoire "+stockeur.getDisplayName(i)); + }else { + // Est sorti + p.sendMessage("Vous sortez du territoire "+stockeur.getDisplayName(i)); + } + } + } + + } + } +} diff --git a/src/com/bernard/ptitPlugin/grenzen/Stockeur.java b/src/com/bernard/ptitPlugin/grenzen/Stockeur.java new file mode 100644 index 0000000..34c3210 --- /dev/null +++ b/src/com/bernard/ptitPlugin/grenzen/Stockeur.java @@ -0,0 +1,167 @@ +package com.bernard.ptitPlugin.grenzen; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.OptionalInt; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import org.bukkit.Location; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; + + +public class Stockeur { + + public static final String FILENAME = "regions.yml"; + + List regions = new ArrayList<>(); + + public Stockeur() { + if(!new File(FILENAME).exists()) + saveFile(); + readFile(); + } + + public List regionsIn(Location l){ + List poz = new ArrayList(regions.size()); + + for(Region r : regions) { + double d2 = 0; + for(PointPondere p : r.points) + d2 += (l.getBlockX()-p.x)*(l.getBlockX()-p.x)+(l.getBlockZ()-p.z)*(l.getBlockZ()-p.z); + poz.add(d2<=r.rayon); + } + + return poz; + } + + public String getDisplayName(int index) { + return regions.get(index).displayName; + } + + public void readFile() { + + ConfigurationSection cs = YamlConfiguration.loadConfiguration(new File(FILENAME)); + Map regs = cs.getConfigurationSection("regions").getValues(false); + List regions = new ArrayList(); + for(String nom : regs.keySet()) { + ConfigurationSection reg = cs.getConfigurationSection(nom); + List pts = (List) reg.get("points"); + Set ptz = pts.stream().map(p -> new PointPondere((int)p[0],(int)p[1],p.length>2?(int)p[2]:1)).collect(Collectors.toSet()); + String dName = reg.getString("displayName"); + long rayon = reg.getLong("rayon"); + regions.add(new Region(ptz, nom, dName,rayon)); + } + this.regions = regions; + + + } + + public void saveFile() { + YamlConfiguration file = new YamlConfiguration(); + ConfigurationSection regionsCS = file.createSection("regions"); + for(Region r : regions) { + + ConfigurationSection region = regionsCS.createSection(r.nom); + region.set("displayName", r.displayName); + region.set("rayon", r.rayon); + List lo = r.points.stream().map(pp -> new Object[] {pp.x,pp.z,pp.poids}).collect(Collectors.toList()); + region.set("points", lo); + } + try { + file.save(new File(FILENAME)); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + + public static class Region{ + + Set points; + String nom; + String displayName; + long rayon; + + public Region(Set points, String nom, String displayName, long rayon) { + this.points = points; + this.nom = nom; + this.displayName = displayName; + this.rayon = rayon; + } + + + + } + + public static class PointPondere{ + + int x,z; + double poids; + public PointPondere(int x, int z, double poids) { + this.x = x; + this.z = z; + this.poids = poids; + } + + + + } + + public void newRegion(Region r) { + regions.add(r); + + } + + public boolean delRegion(String name) { + OptionalInt index = IntStream.range(0, regions.size()).filter(i-> regions.get(i).nom.contentEquals(name)).findAny(); + if(index.isPresent()) { + regions.remove(index.getAsInt()); + return true; + }else + return false; + + } + + public boolean dnameRegion(String nom2, String displayName2) { + for(Region r : regions) { + if(r.nom.contentEquals(nom2)) { + r.displayName = displayName2; + return true; + } + } + return false; + } + + public boolean addPtRegion(String nom3, int x, int z, double poids) { + for(Region r : regions) { + if(r.nom.contentEquals(nom3)) { + r.points.add(new PointPondere(x, z, poids)); + return true; + } + } + return false; + } + + public int delNearestPtRegion(String nom4, int x, int z) { + for(Region r : regions) { + if(r.nom.contentEquals(nom4)) { + + int dcarre = 0; + for (PointPondere pp : r.points) { + + } + + return true; + } + } + return -1; + } + +} diff --git a/src/com/bernard/ptitPlugin/mobiseur/Mobiseur.java b/src/com/bernard/ptitPlugin/mobiseur/Mobiseur.java new file mode 100644 index 0000000..b6b4ec0 --- /dev/null +++ b/src/com/bernard/ptitPlugin/mobiseur/Mobiseur.java @@ -0,0 +1,5 @@ +package com.bernard.ptitPlugin.mobiseur; + +public class Mobiseur { + +} diff --git a/src/com/bernard/ptitPlugin/unicitax/Unicitax.java b/src/com/bernard/ptitPlugin/unicitax/Unicitax.java new file mode 100644 index 0000000..56260c0 --- /dev/null +++ b/src/com/bernard/ptitPlugin/unicitax/Unicitax.java @@ -0,0 +1,5 @@ +package com.bernard.ptitPlugin.unicitax; + +public class Unicitax { + +}