Ajout du code des addons en eux-même.
This commit is contained in:
parent
a82de54648
commit
77b03a9eb2
36
plugin.yml
36
plugin.yml
@ -1,8 +1,34 @@
|
|||||||
name: Le Ptit Plugin
|
name: LePtitPlugin
|
||||||
main: com.bernard.ptitPlugin.LePtitPlugin
|
main: com.bernard.ptitPlugin.LePtitPlugin
|
||||||
version: beta
|
version: alpha
|
||||||
api-version: 1.13
|
description: Un plugin fait avec amour pour les besoins des P'tits Potes
|
||||||
|
author: Mysaa(bernard)
|
||||||
|
website: opnutz.bernard.com.de
|
||||||
|
api-version: 1.15
|
||||||
commands:
|
commands:
|
||||||
|
grenze new:
|
||||||
|
aliases: [grenze créer, grenze nouvelle]
|
||||||
|
usage: "Usage : /grenze new"
|
||||||
|
description: Permet de gérer les frontières
|
||||||
|
permission: lpp.grenze.manage
|
||||||
|
permission-message: Seul le président de GOOGLEMAPZ est autorisé à lancer cette commande
|
||||||
|
default: false
|
||||||
|
grenze remove:
|
||||||
|
usage: /grenze remove
|
||||||
|
description: Permet de gérer les frontières
|
||||||
|
grenze addpt:
|
||||||
|
usage: /grenze addpt
|
||||||
|
description: Permet de gérer les frontières
|
||||||
grenze:
|
grenze:
|
||||||
usage: /grenze list
|
usage: /grenze help
|
||||||
description: Permet de gérer les frontières
|
description: Permet de gérer les frontières
|
||||||
|
fisc:
|
||||||
|
usage: /fisc help
|
||||||
|
description: Permet de gérer l'unicité des monnaies crées
|
||||||
|
s:
|
||||||
|
usage: /s
|
||||||
|
description: Switch survie/spec
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
lpp.grenze.manage:
|
||||||
|
|
||||||
@ -1,14 +1,32 @@
|
|||||||
package com.bernard.ptitPlugin;
|
package com.bernard.ptitPlugin;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import com.bernard.ptitPlugin.construcation.Construcation;
|
||||||
|
import com.bernard.ptitPlugin.grenzen.Grenzen;
|
||||||
|
import com.bernard.ptitPlugin.mobiseur.Mobiseur;
|
||||||
|
import com.bernard.ptitPlugin.unicitax.Unicitax;
|
||||||
|
|
||||||
public class LePtitPlugin extends JavaPlugin {
|
public class LePtitPlugin extends JavaPlugin {
|
||||||
|
|
||||||
|
Mobiseur mobiseur;
|
||||||
|
Grenzen grenzen;
|
||||||
|
Unicitax unicitax;
|
||||||
|
Construcation construcation;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
super.onEnable();
|
super.onEnable();
|
||||||
|
grenzen = new Grenzen(this);
|
||||||
|
mobiseur = new Mobiseur();
|
||||||
|
unicitax = new Unicitax(this);
|
||||||
|
construcation = new Construcation();
|
||||||
|
getServer().getPluginManager().registerEvents(grenzen, this);
|
||||||
|
getServer().getPluginManager().registerEvents(mobiseur, this);
|
||||||
|
getServer().getPluginManager().registerEvents(unicitax, this);
|
||||||
|
this.getCommand("grenze").setExecutor(grenzen.gmod);;
|
||||||
|
this.getCommand("fisc").setExecutor(unicitax.fisc);;
|
||||||
|
this.getCommand("s").setExecutor(construcation);;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,8 +38,6 @@ public class LePtitPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
|
|
||||||
public void setupConfig() {
|
public void setupConfig() {
|
||||||
FileConfiguration config = this.getConfig();
|
|
||||||
|
|
||||||
this.saveDefaultConfig();
|
this.saveDefaultConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,39 @@
|
|||||||
package com.bernard.ptitPlugin.construcation;
|
package com.bernard.ptitPlugin.construcation;
|
||||||
|
|
||||||
public class Construcation {
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Construcation implements CommandExecutor{
|
||||||
|
|
||||||
|
Map<UUID, Location> lastPoz = new HashMap<UUID, Location>();
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand( CommandSender sender, Command command, String cmd, String[] args) {
|
||||||
|
|
||||||
|
if(!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage("Cette commande doit être envoyée par un joueur !");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Player pp = (Player)sender;
|
||||||
|
if(pp.getGameMode() == GameMode.SPECTATOR) {
|
||||||
|
if(lastPoz.containsKey(pp.getUniqueId()))pp.teleport(lastPoz.get(pp.getUniqueId()));
|
||||||
|
pp.setGameMode(GameMode.SURVIVAL);
|
||||||
|
}else {
|
||||||
|
lastPoz.put(pp.getUniqueId(), pp.getLocation());
|
||||||
|
pp.setGameMode(GameMode.SPECTATOR);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,32 +1,37 @@
|
|||||||
package com.bernard.ptitPlugin.grenzen;
|
package com.bernard.ptitPlugin.grenzen;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.bernard.ptitPlugin.grenzen.Stockeur.PointPondere;
|
||||||
import com.bernard.ptitPlugin.grenzen.Stockeur.Region;
|
import com.bernard.ptitPlugin.grenzen.Stockeur.Region;
|
||||||
|
|
||||||
public class GrenzeModif implements CommandExecutor{
|
public class GrenzeModif implements CommandExecutor, TabCompleter{
|
||||||
|
|
||||||
|
|
||||||
Stockeur stck;
|
Stockeur stck;
|
||||||
|
|
||||||
Pattern REGNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_][a-zA-Z0-9.-_]*$");
|
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.-_ :&|$#~’;']*$");
|
Pattern REGDNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_][a-zA-Z0-9._ :&|$#~’;'-]*$");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public GrenzeModif(Stockeur stck) {
|
||||||
|
super();
|
||||||
|
this.stck = stck;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
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)
|
if(args.length==0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -34,7 +39,7 @@ public class GrenzeModif implements CommandExecutor{
|
|||||||
|
|
||||||
switch(subcommand) {
|
switch(subcommand) {
|
||||||
|
|
||||||
case "new": // nom [displayName] [rayon]
|
case "new": // nom [displayName [rayon]]
|
||||||
// Crée une nouvelle région
|
// Crée une nouvelle région
|
||||||
if(args.length<2)
|
if(args.length<2)
|
||||||
return false;
|
return false;
|
||||||
@ -55,13 +60,13 @@ public class GrenzeModif implements CommandExecutor{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(REGNAME_PATTERN.matcher(nom).matches()){
|
if(!REGNAME_PATTERN.matcher(nom).matches()){
|
||||||
sender.sendMessage("Ce nom n'est pas légal !");
|
sender.sendMessage("Ce nom n'est pas légal !");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(REGDNAME_PATTERN.matcher(displayName).matches()){
|
if(!REGDNAME_PATTERN.matcher(displayName).matches()){
|
||||||
sender.sendMessage("Ce nom d'affichage n'est pas légal !");
|
sender.sendMessage("Ce nom d'affichage n'est pas légal !");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -70,6 +75,7 @@ public class GrenzeModif implements CommandExecutor{
|
|||||||
|
|
||||||
stck.newRegion(r);
|
stck.newRegion(r);
|
||||||
|
|
||||||
|
sender.sendMessage("La région "+nom+ " a bien été créée !");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -96,7 +102,7 @@ public class GrenzeModif implements CommandExecutor{
|
|||||||
if(args.length>=3)
|
if(args.length>=3)
|
||||||
displayName = args[2];
|
displayName = args[2];
|
||||||
|
|
||||||
if(REGDNAME_PATTERN.matcher(displayName2).matches()){
|
if(!REGDNAME_PATTERN.matcher(displayName2).matches()){
|
||||||
sender.sendMessage("Ce nom d'affichage n'est pas légal !");
|
sender.sendMessage("Ce nom d'affichage n'est pas légal !");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -112,6 +118,10 @@ public class GrenzeModif implements CommandExecutor{
|
|||||||
case "list":
|
case "list":
|
||||||
// Liste les régions enregistrées, et d'autres infos (nbre points, region)
|
// Liste les régions enregistrées, et d'autres infos (nbre points, region)
|
||||||
|
|
||||||
|
if(stck.regions.isEmpty()) {
|
||||||
|
sender.sendMessage("Il n'y a pas de région enregistrée ... :-/");
|
||||||
|
}
|
||||||
|
|
||||||
sender.sendMessage("Voici la liste des régions enregistrées");
|
sender.sendMessage("Voici la liste des régions enregistrées");
|
||||||
for (Region reg : stck.regions) {
|
for (Region reg : stck.regions) {
|
||||||
sender.sendMessage(" - "+reg.nom+" as "+reg.displayName+" : "+reg.points.size()+ " points enregistrés");
|
sender.sendMessage(" - "+reg.nom+" as "+reg.displayName+" : "+reg.points.size()+ " points enregistrés");
|
||||||
@ -163,7 +173,7 @@ public class GrenzeModif implements CommandExecutor{
|
|||||||
sender.sendMessage("Je ne connais pas la région "+nom3+" !");
|
sender.sendMessage("Je ne connais pas la région "+nom3+" !");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
sender.sendMessage("Le point a été enregistré !");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "delpt": // nom [x z/*exact*/] // sinon nearest
|
case "delpt": // nom [x z/*exact*/] // sinon nearest
|
||||||
@ -177,44 +187,185 @@ public class GrenzeModif implements CommandExecutor{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Location loc = ((Player)sender).getLocation();
|
Location loc = ((Player)sender).getLocation();
|
||||||
x=loc.getBlockX();
|
x4=loc.getBlockX();
|
||||||
z=loc.getBlockZ();
|
z4=loc.getBlockZ();
|
||||||
}else {
|
}else {
|
||||||
try {
|
try {
|
||||||
x = Integer.parseInt(args[3]);
|
x4 = Integer.parseInt(args[3]);
|
||||||
z = Integer.parseInt(args[4]);
|
z4 = Integer.parseInt(args[4]);
|
||||||
}catch(NumberFormatException e) {
|
}catch(NumberFormatException e) {
|
||||||
sender.sendMessage("Je ne saurais pas interpréter "+args[3]+" "+args[4]+" comme des coordonées entières …");
|
sender.sendMessage("Je ne saurais pas interpréter "+args[3]+" "+args[4]+" comme des coordonées entières …");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!stck.delNearestPtRegion(nom4,x,z)) {
|
try {
|
||||||
sender.sendMessage("Je ne connais pas la région "+nom3+" !");
|
PointPondere pp = stck.delNearestPtRegion(nom4,x4,z4);
|
||||||
|
if(pp==null) {
|
||||||
|
sender.sendMessage("Il n'y a pas de points dans la région "+nom4+" !");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage("Le point en "+pp.x+" "+pp.z+" a été supprimé de la région "+nom4+" !");
|
||||||
|
}catch(IllegalArgumentException exc) {
|
||||||
|
sender.sendMessage("Je ne connais pas la région "+nom4+" !");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sender.sendMessage("Le point a été supprimé !");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "modpt": // nom nx ny nz/*nouvelle*/ [ox oy oz] // sinon nearest
|
case "modpt": // nom nx nz/*nouvelle*/ [poids |ox oz [poids]] // sinon nearest
|
||||||
|
|
||||||
|
if(args.length<4)
|
||||||
|
return false;
|
||||||
|
String nom5 = args[1];
|
||||||
|
int nx, nz;
|
||||||
|
try {
|
||||||
|
nx = Integer.parseInt(args[2]);
|
||||||
|
nz = Integer.parseInt(args[3]);
|
||||||
|
}catch(NumberFormatException e) {
|
||||||
|
sender.sendMessage("Je ne saurais pas interpréter "+args[2]+" "+args[3]+" comme des coordonées entières …");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ox,oz;
|
||||||
|
double poids5 = 1.;
|
||||||
|
if(args.length<6) {
|
||||||
|
if(!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage("Si vous n'envoyez cette commande en tant que joueur, vous devez préciser les coordonées d'origine!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Location loc = ((Player)sender).getLocation();
|
||||||
|
ox=loc.getBlockX();
|
||||||
|
oz=loc.getBlockZ();
|
||||||
|
if(args.length>=5) {
|
||||||
|
try {
|
||||||
|
poids = Double.parseDouble(args[4]);
|
||||||
|
}catch(NumberFormatException e) {
|
||||||
|
sender.sendMessage("Je ne saurais pas interpréter "+args[4]+" comme un flottant …");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
try {
|
||||||
|
ox = Integer.parseInt(args[4]);
|
||||||
|
oz = Integer.parseInt(args[5]);
|
||||||
|
}catch(NumberFormatException e) {
|
||||||
|
sender.sendMessage("Je ne saurais pas interpréter "+args[4]+" "+args[5]+" comme des coordonées entières …");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args.length>=7) {
|
||||||
|
try {
|
||||||
|
poids = Double.parseDouble(args[6]);
|
||||||
|
}catch(NumberFormatException e) {
|
||||||
|
sender.sendMessage("Je ne saurais pas interpréter "+args[6]+" comme un flottant …");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
PointPondere pp = stck.modNearestPtRegion(nom5,nx,nz,poids5,ox,oz);
|
||||||
|
if(pp==null) {
|
||||||
|
sender.sendMessage("Il n'y a pas de points dans la région "+nom5+" !");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage("Le point en "+pp.x+" "+pp.z+" a été déplacé en "+nx+" "+nz+" avec un poids de "+poids5+" dans la région "+nom5+" !");
|
||||||
|
}catch(IllegalArgumentException exc) {
|
||||||
|
sender.sendMessage("Je ne connais pas la région "+nom5+" !");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage("Le point a été modifié !");
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "clearpts": // nom
|
case "clearpts": // nom
|
||||||
// Supprime tous les points de la région séléctionnée
|
if(args.length<2)
|
||||||
|
return false;
|
||||||
|
String nom7 = args[1];
|
||||||
|
|
||||||
|
if(!stck.emptyRegion(nom7)) {
|
||||||
|
sender.sendMessage("Je ne connais pas la région "+nom7+" !");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage("Région vidée !");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "listpts": // nom
|
case "listpts": // nom
|
||||||
// Liste les points de la région, avec le rayon
|
// Liste les points de la région, avec le rayon
|
||||||
|
if(args.length<2)
|
||||||
|
return false;
|
||||||
|
String nom9 = args[1];
|
||||||
|
Region reg = stck.getRegion(nom9);
|
||||||
|
if(nom9==null) {
|
||||||
|
sender.sendMessage("Je ne connais pas la région "+nom9+" !");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(reg.points.isEmpty()) {
|
||||||
|
sender.sendMessage("Il n'y a pas de points dans la région "+nom9+" ou "+reg.displayName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage("Liste des points de la région "+nom9+" ou "+reg.displayName);
|
||||||
|
reg.points.stream().forEach(p -> sender.sendMessage(" - "+p.x+" "+p.z+" de poids "+p.poids));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "load":
|
case "load":
|
||||||
// Recharge le fichier des régions
|
// Recharge le fichier des régions
|
||||||
break;
|
stck.readFile();
|
||||||
|
sender.sendMessage("Fichier rechargé !");
|
||||||
|
|
||||||
case "modrayon": // rayon
|
break;
|
||||||
|
case "save":
|
||||||
|
// Recharge le fichier des régions
|
||||||
|
stck.saveFile();
|
||||||
|
sender.sendMessage("Fichier enregistré !");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "modrayon": // nom rayon
|
||||||
// Redéfinit le rayon
|
// Redéfinit le rayon
|
||||||
|
|
||||||
|
if(args.length<3)
|
||||||
|
return false;
|
||||||
|
String nom10 = args[1];
|
||||||
|
long rayon10;
|
||||||
|
try {
|
||||||
|
rayon10 = Integer.parseInt(args[2]);
|
||||||
|
}catch(NumberFormatException e) {
|
||||||
|
sender.sendMessage("Je ne saurais pas interpréter "+args[2]+" comme un entier …");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(rayon10 < 0) {
|
||||||
|
sender.sendMessage("Je ne suis pas sur que "+rayon10+" soit un entier strictement positif");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(!stck.modRayon(nom10,rayon10)) {
|
||||||
|
sender.sendMessage("Je ne connais pas la région "+nom10+" !");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage("Rayon changé !");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
sender.sendMessage("Subcommands :");
|
||||||
|
sender.sendMessage(" - new nom [displayName [rayon]]");
|
||||||
|
sender.sendMessage(" - remove nom");
|
||||||
|
sender.sendMessage(" - list");
|
||||||
|
sender.sendMessage(" - name nom displayName");
|
||||||
|
sender.sendMessage(" - addpt nom [x z]");
|
||||||
|
sender.sendMessage(" - delpt nom [x z]");
|
||||||
|
sender.sendMessage(" - modpt nom nx nz [poids |ox oz [poids]]");
|
||||||
|
sender.sendMessage(" - clearpts nom");
|
||||||
|
sender.sendMessage(" - listpts nom");
|
||||||
|
sender.sendMessage(" - load");
|
||||||
|
sender.sendMessage(" - save");
|
||||||
|
sender.sendMessage(" - modrayon nom rayon");
|
||||||
// Afficher l'aide
|
// Afficher l'aide
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -223,8 +374,17 @@ public class GrenzeModif implements CommandExecutor{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Region getReg(String name) {
|
public Region getReg(String name) {
|
||||||
return stck.regions.stream().filter(r->r.nom.equals(name)).findAny().orElse(null);
|
return stck.regions.stream().filter(r->r.nom.equals(name)).findAny().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete( CommandSender sender, Command command, String cmd, String[] args) {
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,26 +4,39 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class Grenzen implements Listener{
|
public class Grenzen implements Listener{
|
||||||
|
|
||||||
public static final double PLAYER_UPDATE_DIST2 = 64.; // distance 8
|
public static final double PLAYER_UPDATE_DIST2 = 64.; // distance 8
|
||||||
|
|
||||||
Stockeur stockeur;
|
Stockeur stockeur;
|
||||||
|
public GrenzeModif gmod;
|
||||||
|
|
||||||
Map<UUID,Location> lastPlayerPos;
|
|
||||||
Map<UUID,List<Boolean>> whereis;
|
|
||||||
|
|
||||||
public Grenzen() {
|
Map<UUID,Location> lastPlayerPos = new HashMap<>();
|
||||||
|
Map<UUID,List<Boolean>> whereis = new HashMap<>();
|
||||||
|
|
||||||
|
public Grenzen(Plugin p) {
|
||||||
lastPlayerPos = new HashMap<UUID, Location>();
|
lastPlayerPos = new HashMap<UUID, Location>();
|
||||||
stockeur = new Stockeur();
|
stockeur = new Stockeur(p);
|
||||||
|
gmod = new GrenzeModif(stockeur);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
|
whereis.put(event.getPlayer().getUniqueId(),stockeur.regions.stream().map(r -> false).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
public void onMoved(PlayerMoveEvent event) {
|
public void onMoved(PlayerMoveEvent event) {
|
||||||
Player p = event.getPlayer();
|
Player p = event.getPlayer();
|
||||||
if(!lastPlayerPos.containsKey(p.getUniqueId()) || p.getLocation().distanceSquared(lastPlayerPos.get(p.getUniqueId())) > PLAYER_UPDATE_DIST2) {
|
if(!lastPlayerPos.containsKey(p.getUniqueId()) || p.getLocation().distanceSquared(lastPlayerPos.get(p.getUniqueId())) > PLAYER_UPDATE_DIST2) {
|
||||||
@ -42,7 +55,9 @@ public class Grenzen implements Listener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.out.println(pWhereIs);
|
||||||
|
whereis.put(p.getUniqueId(), pWhereIs);
|
||||||
|
System.out.println("ouch");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,18 +10,23 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
|
||||||
public class Stockeur {
|
public class Stockeur {
|
||||||
|
|
||||||
public static final String FILENAME = "regions.yml";
|
public static final String FILENAME = "regions.yml";
|
||||||
|
boolean shouldSave = false;
|
||||||
|
Plugin plugin;
|
||||||
|
|
||||||
List<Region> regions = new ArrayList<>();
|
List<Region> regions = new ArrayList<>();
|
||||||
|
|
||||||
public Stockeur() {
|
public Stockeur(Plugin p) {
|
||||||
|
plugin = p;
|
||||||
if(!new File(FILENAME).exists())
|
if(!new File(FILENAME).exists())
|
||||||
saveFile();
|
saveFile();
|
||||||
readFile();
|
readFile();
|
||||||
@ -31,10 +36,11 @@ public class Stockeur {
|
|||||||
List<Boolean> poz = new ArrayList<Boolean>(regions.size());
|
List<Boolean> poz = new ArrayList<Boolean>(regions.size());
|
||||||
|
|
||||||
for(Region r : regions) {
|
for(Region r : regions) {
|
||||||
double d2 = 0;
|
long d2 = 0;
|
||||||
for(PointPondere p : r.points)
|
for(PointPondere p : r.points)
|
||||||
d2 += (l.getBlockX()-p.x)*(l.getBlockX()-p.x)+(l.getBlockZ()-p.z)*(l.getBlockZ()-p.z);
|
d2 += (l.getBlockX()-p.x)*(l.getBlockX()-p.x)+(l.getBlockZ()-p.z)*(l.getBlockZ()-p.z)*p.poids;
|
||||||
poz.add(d2<=r.rayon);
|
poz.add(d2<=r.rayon*r.rayon);
|
||||||
|
System.out.println(r.points+","+l+"->"+d2+"càd"+r.rayon);
|
||||||
}
|
}
|
||||||
|
|
||||||
return poz;
|
return poz;
|
||||||
@ -47,12 +53,17 @@ public class Stockeur {
|
|||||||
public void readFile() {
|
public void readFile() {
|
||||||
|
|
||||||
ConfigurationSection cs = YamlConfiguration.loadConfiguration(new File(FILENAME));
|
ConfigurationSection cs = YamlConfiguration.loadConfiguration(new File(FILENAME));
|
||||||
Map<String,Object> regs = cs.getConfigurationSection("regions").getValues(false);
|
ConfigurationSection rgs = cs.getConfigurationSection("regions");
|
||||||
|
Map<String,Object> regs = rgs.getValues(false);
|
||||||
List<Region> regions = new ArrayList<Stockeur.Region>();
|
List<Region> regions = new ArrayList<Stockeur.Region>();
|
||||||
for(String nom : regs.keySet()) {
|
for(String nom : regs.keySet()) {
|
||||||
ConfigurationSection reg = cs.getConfigurationSection(nom);
|
ConfigurationSection reg = rgs.getConfigurationSection(nom);
|
||||||
List<Object[]> pts = (List<Object[]>) reg.get("points");
|
System.out.println(reg);
|
||||||
Set<PointPondere> ptz = pts.stream().map(p -> new PointPondere((int)p[0],(int)p[1],p.length>2?(int)p[2]:1)).collect(Collectors.toSet());
|
System.out.println(reg.getKeys(true));
|
||||||
|
List<String> pts = new ArrayList<String>();
|
||||||
|
pts = ((List<String>) reg.getList("points",pts));
|
||||||
|
System.out.println(pts);
|
||||||
|
Set<PointPondere> ptz = pts.stream().map(p -> PointPondere.parseString(p)).collect(Collectors.toSet());
|
||||||
String dName = reg.getString("displayName");
|
String dName = reg.getString("displayName");
|
||||||
long rayon = reg.getLong("rayon");
|
long rayon = reg.getLong("rayon");
|
||||||
regions.add(new Region(ptz, nom, dName,rayon));
|
regions.add(new Region(ptz, nom, dName,rayon));
|
||||||
@ -63,6 +74,7 @@ public class Stockeur {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void saveFile() {
|
public void saveFile() {
|
||||||
|
shouldSave=false;
|
||||||
YamlConfiguration file = new YamlConfiguration();
|
YamlConfiguration file = new YamlConfiguration();
|
||||||
ConfigurationSection regionsCS = file.createSection("regions");
|
ConfigurationSection regionsCS = file.createSection("regions");
|
||||||
for(Region r : regions) {
|
for(Region r : regions) {
|
||||||
@ -70,7 +82,7 @@ public class Stockeur {
|
|||||||
ConfigurationSection region = regionsCS.createSection(r.nom);
|
ConfigurationSection region = regionsCS.createSection(r.nom);
|
||||||
region.set("displayName", r.displayName);
|
region.set("displayName", r.displayName);
|
||||||
region.set("rayon", r.rayon);
|
region.set("rayon", r.rayon);
|
||||||
List<Object[]> lo = r.points.stream().map(pp -> new Object[] {pp.x,pp.z,pp.poids}).collect(Collectors.toList());
|
List<String> lo = r.points.stream().map(PointPondere::toString).collect(Collectors.toList());
|
||||||
region.set("points", lo);
|
region.set("points", lo);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -110,19 +122,70 @@ public class Stockeur {
|
|||||||
this.poids = poids;
|
this.poids = poids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int dcarre(int x, int z) {
|
||||||
|
return (this.x-x)*(this.x-x)+(this.z-z)*(this.z-z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void newRegion(Region r) {
|
@Override
|
||||||
regions.add(r);
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
long temp;
|
||||||
|
temp = Double.doubleToLongBits(poids);
|
||||||
|
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||||
|
result = prime * result + x;
|
||||||
|
result = prime * result + z;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
PointPondere other = (PointPondere) obj;
|
||||||
|
if (Double.doubleToLongBits(poids) != Double.doubleToLongBits(other.poids))
|
||||||
|
return false;
|
||||||
|
if (x != other.x)
|
||||||
|
return false;
|
||||||
|
if (z != other.z)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return Integer.toString(x)+"/"+Integer.toString(z)+"/"+Double.toString(poids);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PointPondere parseString(String in) {
|
||||||
|
String[] args = in.split("/");
|
||||||
|
return new PointPondere(Integer.parseInt(args[0]), Integer.parseInt(args[1]), args.length>2?Double.parseDouble(args[2]):1.);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void shouldSave() {
|
||||||
|
if(!shouldSave) {
|
||||||
|
shouldSave=true;
|
||||||
|
Bukkit.getScheduler().runTaskLater(plugin, () -> saveFile(),5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void newRegion(Region r) {
|
||||||
|
regions.add(r);
|
||||||
|
shouldSave();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean delRegion(String name) {
|
public boolean delRegion(String name) {
|
||||||
OptionalInt index = IntStream.range(0, regions.size()).filter(i-> regions.get(i).nom.contentEquals(name)).findAny();
|
OptionalInt index = IntStream.range(0, regions.size()).filter(i-> regions.get(i).nom.contentEquals(name)).findAny();
|
||||||
if(index.isPresent()) {
|
if(index.isPresent()) {
|
||||||
regions.remove(index.getAsInt());
|
regions.remove(index.getAsInt());
|
||||||
|
shouldSave();
|
||||||
return true;
|
return true;
|
||||||
}else
|
}else
|
||||||
return false;
|
return false;
|
||||||
@ -133,35 +196,97 @@ public class Stockeur {
|
|||||||
for(Region r : regions) {
|
for(Region r : regions) {
|
||||||
if(r.nom.contentEquals(nom2)) {
|
if(r.nom.contentEquals(nom2)) {
|
||||||
r.displayName = displayName2;
|
r.displayName = displayName2;
|
||||||
|
shouldSave();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Region getRegion(String nom2) {
|
||||||
|
for(Region r : regions) {
|
||||||
|
if(r.nom.contentEquals(nom2)) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean addPtRegion(String nom3, int x, int z, double poids) {
|
public boolean addPtRegion(String nom3, int x, int z, double poids) {
|
||||||
for(Region r : regions) {
|
for(Region r : regions) {
|
||||||
if(r.nom.contentEquals(nom3)) {
|
if(r.nom.contentEquals(nom3)) {
|
||||||
r.points.add(new PointPondere(x, z, poids));
|
r.points.add(new PointPondere(x, z, poids));
|
||||||
|
shouldSave();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int delNearestPtRegion(String nom4, int x, int z) {
|
public PointPondere delNearestPtRegion(String nom4, int x, int z) throws IllegalArgumentException{
|
||||||
for(Region r : regions) {
|
for(Region r : regions) {
|
||||||
if(r.nom.contentEquals(nom4)) {
|
if(r.nom.contentEquals(nom4)) {
|
||||||
|
if(r.points.isEmpty())
|
||||||
int dcarre = 0;
|
return null;
|
||||||
for (PointPondere pp : r.points) {
|
int minddcarre = Integer.MAX_VALUE;
|
||||||
|
PointPondere mpt = null;
|
||||||
|
for (PointPondere p : r.points) {
|
||||||
|
int dst = p.dcarre(x, z);
|
||||||
|
if (dst < minddcarre) {
|
||||||
|
minddcarre = dst;
|
||||||
|
mpt = p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
r.points.remove(mpt);
|
||||||
|
shouldSave();
|
||||||
|
return mpt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PointPondere modNearestPtRegion(String nom5, int nx, int nz, double poids, int ox, int oz) {
|
||||||
|
for(Region r : regions) {
|
||||||
|
if(r.nom.contentEquals(nom5)) {
|
||||||
|
if(r.points.isEmpty())
|
||||||
|
return null;
|
||||||
|
int minddcarre = Integer.MAX_VALUE;
|
||||||
|
PointPondere mpt = null;
|
||||||
|
for (PointPondere p : r.points) {
|
||||||
|
int dst = p.dcarre(ox, oz);
|
||||||
|
if (dst < minddcarre) {
|
||||||
|
minddcarre = dst;
|
||||||
|
mpt = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r.points.remove(mpt);
|
||||||
|
r.points.add(new PointPondere(nx, nz, poids));
|
||||||
|
shouldSave();
|
||||||
|
return mpt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean emptyRegion(String name) {
|
||||||
|
OptionalInt index = IntStream.range(0, regions.size()).filter(i-> regions.get(i).nom.contentEquals(name)).findAny();
|
||||||
|
if(index.isPresent()) {
|
||||||
|
regions.get(index.getAsInt()).points.clear();
|
||||||
|
shouldSave();
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean modRayon(String nom7, long rayon10) {
|
||||||
|
for(Region r : regions) {
|
||||||
|
if(r.nom.contentEquals(nom7)) {
|
||||||
|
r.rayon = rayon10;
|
||||||
|
shouldSave();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
@ -1,5 +1,23 @@
|
|||||||
package com.bernard.ptitPlugin.mobiseur;
|
package com.bernard.ptitPlugin.mobiseur;
|
||||||
|
|
||||||
public class Mobiseur {
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.SoundCategory;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
|
||||||
|
public class Mobiseur implements Listener{
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onExplode(EntityExplodeEvent event) {
|
||||||
|
if(event.getEntityType().equals(EntityType.CREEPER)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
event.getLocation().getWorld().spawnParticle(Particle.EXPLOSION_HUGE,event.getLocation(),3);
|
||||||
|
event.getLocation().getWorld().playSound(event.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, SoundCategory.HOSTILE, 1.f, 1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
197
src/com/bernard/ptitPlugin/unicitax/Fisc.java
Normal file
197
src/com/bernard/ptitPlugin/unicitax/Fisc.java
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
package com.bernard.ptitPlugin.unicitax;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.bernard.ptitPlugin.unicitax.GardeMonetaire.GardeSceaux;
|
||||||
|
|
||||||
|
public class Fisc implements CommandExecutor{
|
||||||
|
|
||||||
|
GardeMonetaire gm;
|
||||||
|
|
||||||
|
Pattern ASSNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_][a-zA-Z0-9.-_]*$");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Fisc(GardeMonetaire gm) {
|
||||||
|
this.gm = gm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@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": // assign item Player nom
|
||||||
|
// Crée un nouveau garde
|
||||||
|
if(args.length<5)
|
||||||
|
return false;
|
||||||
|
String assign = args[1];
|
||||||
|
String itemS = args[2];
|
||||||
|
String playerS = args[3];
|
||||||
|
String nom = args[4];
|
||||||
|
NamespacedKey item;
|
||||||
|
UUID player;
|
||||||
|
try {
|
||||||
|
item = NamespacedKey.minecraft(itemS);
|
||||||
|
}catch(Exception e) {//TODO trouver la bonne exception
|
||||||
|
sender.sendMessage("Je ne saurais pas interpréter "+args[2]+" comme un item …");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
player = Bukkit.getServer().getPlayer(playerS).getUniqueId();
|
||||||
|
}catch(Exception e) {//TODO trouver la bonne exception
|
||||||
|
sender.sendMessage("Je ne saurais pas interpréter "+args[3]+" comme un joueur …");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!ASSNAME_PATTERN.matcher(nom).matches()){
|
||||||
|
sender.sendMessage("Ce nom n'est pas légal !");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GardeSceaux gs = gm.new GardeSceaux(assign, item, player, nom);
|
||||||
|
|
||||||
|
gm.newGarde(gs);
|
||||||
|
|
||||||
|
sender.sendMessage("Le garde a bien été créé !");
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "remove":// nom
|
||||||
|
// Supprime un garde
|
||||||
|
if(args.length<2)
|
||||||
|
return false;
|
||||||
|
String nom1 = args[1];
|
||||||
|
|
||||||
|
if(!gm.delGarde(nom1)) {
|
||||||
|
sender.sendMessage("Je ne connais pas le garde "+nom1+" !");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage("Garde supprimée !");
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "item":// nom item
|
||||||
|
//Définit l'item d'un garde
|
||||||
|
if(args.length<3)
|
||||||
|
return false;
|
||||||
|
String nom2 = args[1];
|
||||||
|
String item2 = args[2];
|
||||||
|
|
||||||
|
try {
|
||||||
|
item = NamespacedKey.minecraft(item2);
|
||||||
|
}catch(Exception e) {//TODO trouver la bonne exception
|
||||||
|
sender.sendMessage("Je ne saurais pas interpréter "+args[2]+" comme un item …");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!gm.itemGarde(nom2,item)) {
|
||||||
|
sender.sendMessage("Je ne connais pas le garde "+nom2+" !");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage("Item changé !");
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "player":// nom Player
|
||||||
|
//Définit l'item d'un garde
|
||||||
|
if(args.length<3)
|
||||||
|
return false;
|
||||||
|
String nom3 = args[1];
|
||||||
|
String player3 = args[2];
|
||||||
|
|
||||||
|
try {
|
||||||
|
player = Bukkit.getServer().getPlayer(player3).getUniqueId();
|
||||||
|
}catch(Exception e) {//TODO trouver la bonne exception
|
||||||
|
sender.sendMessage("Je ne saurais pas interpréter "+args[3]+" comme un joueur …");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!gm.playerGarde(nom3,player)) {
|
||||||
|
sender.sendMessage("Je ne connais pas le garde "+nom3+" !");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage("Joueur changé !");
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "name":// nom name
|
||||||
|
//Définit le nom d'un garde
|
||||||
|
if(args.length<3)
|
||||||
|
return false;
|
||||||
|
String nom4 = args[1];
|
||||||
|
String name4 = args[2];
|
||||||
|
|
||||||
|
|
||||||
|
if(!gm.nameGarde(nom4,name4)) {
|
||||||
|
sender.sendMessage("Je ne connais pas le garde "+nom4+" !");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage("Nom changé !");
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "list":
|
||||||
|
// Liste les gardes enregistrées, et d'autres infos
|
||||||
|
|
||||||
|
if(gm.gardes.isEmpty()) {
|
||||||
|
sender.sendMessage("Il n'y a pas de garde enregistré !");
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage("Voici la liste des gardes enregistrées");
|
||||||
|
for (GardeSceaux reg : gm.gardes) {
|
||||||
|
sender.sendMessage(" - "+reg.assignationID+" : "+reg.player.toString()+" peut renommer "+reg.item.toString()+ " en "+reg.exactName);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "load":
|
||||||
|
// Recharge le fichier des régions
|
||||||
|
gm.readFile();
|
||||||
|
sender.sendMessage("Fichier rechargé !");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "save":
|
||||||
|
// Recharge le fichier des régions
|
||||||
|
gm.saveFile();
|
||||||
|
sender.sendMessage("Fichier enregistré !");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Afficher l'aide
|
||||||
|
sender.sendMessage("Subcommands :");
|
||||||
|
sender.sendMessage(" - new assign item Player nom");
|
||||||
|
sender.sendMessage(" - remove assign");
|
||||||
|
sender.sendMessage(" - item assign item");
|
||||||
|
sender.sendMessage(" - player assign Player");
|
||||||
|
sender.sendMessage(" - name assign name");
|
||||||
|
sender.sendMessage(" - list");
|
||||||
|
sender.sendMessage(" - load");
|
||||||
|
sender.sendMessage(" - save");
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
188
src/com/bernard/ptitPlugin/unicitax/GardeMonetaire.java
Normal file
188
src/com/bernard/ptitPlugin/unicitax/GardeMonetaire.java
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
package com.bernard.ptitPlugin.unicitax;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class GardeMonetaire {
|
||||||
|
|
||||||
|
public static final String FILENAME = "gardes.yml";
|
||||||
|
|
||||||
|
Set<GardeSceaux> gardes = new HashSet<GardeMonetaire.GardeSceaux>();
|
||||||
|
|
||||||
|
Plugin plugin;
|
||||||
|
|
||||||
|
boolean shouldSave = false;
|
||||||
|
|
||||||
|
public GardeMonetaire(Plugin p) {
|
||||||
|
plugin = p;
|
||||||
|
if(!new File(FILENAME).exists())
|
||||||
|
saveFile();
|
||||||
|
readFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void readFile() {
|
||||||
|
|
||||||
|
ConfigurationSection cs = YamlConfiguration.loadConfiguration(new File(FILENAME));
|
||||||
|
Map<String,Object> gds = cs.getConfigurationSection("gardes").getValues(false);
|
||||||
|
Set<GardeSceaux> gardes = new HashSet<>();
|
||||||
|
for(String nom : gds.keySet()) {
|
||||||
|
ConfigurationSection gd = cs.getConfigurationSection(nom);
|
||||||
|
String name = gd.getString("name");
|
||||||
|
UUID player = UUID.fromString(gd.getString("userUUID"));
|
||||||
|
NamespacedKey item = NamespacedKey.minecraft(gd.getString("item"));
|
||||||
|
gardes.add(new GardeSceaux(nom,item,player,name));
|
||||||
|
}
|
||||||
|
this.gardes = gardes;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveFile() {
|
||||||
|
YamlConfiguration file = new YamlConfiguration();
|
||||||
|
ConfigurationSection cs = file.createSection("gardes");
|
||||||
|
for(GardeSceaux g : gardes) {
|
||||||
|
ConfigurationSection garde = cs.createSection(g.assignationID);
|
||||||
|
garde.set("item", g.item);
|
||||||
|
garde.set("userUUID", g.player.toString());
|
||||||
|
garde.set("name", g.exactName);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
file.save(new File(FILENAME));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class GardeSceaux {
|
||||||
|
|
||||||
|
public String assignationID;
|
||||||
|
public NamespacedKey item;
|
||||||
|
public UUID player;
|
||||||
|
public String exactName;
|
||||||
|
|
||||||
|
public GardeSceaux(String assignationID, NamespacedKey item, UUID player, String exactName) {
|
||||||
|
super();
|
||||||
|
this.assignationID = assignationID;
|
||||||
|
this.item = item;
|
||||||
|
this.player = player;
|
||||||
|
this.exactName = exactName;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((assignationID == null) ? 0 : assignationID.hashCode());
|
||||||
|
result = prime * result + ((exactName == null) ? 0 : exactName.hashCode());
|
||||||
|
result = prime * result + ((item == null) ? 0 : item.hashCode());
|
||||||
|
result = prime * result + ((player == null) ? 0 : player.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
GardeSceaux other = (GardeSceaux) obj;
|
||||||
|
if (assignationID == null) {
|
||||||
|
if (other.assignationID != null)
|
||||||
|
return false;
|
||||||
|
} else if (!assignationID.equals(other.assignationID))
|
||||||
|
return false;
|
||||||
|
if (exactName == null) {
|
||||||
|
if (other.exactName != null)
|
||||||
|
return false;
|
||||||
|
} else if (!exactName.equals(other.exactName))
|
||||||
|
return false;
|
||||||
|
if (item == null) {
|
||||||
|
if (other.item != null)
|
||||||
|
return false;
|
||||||
|
} else if (!item.equals(other.item))
|
||||||
|
return false;
|
||||||
|
if (player == null) {
|
||||||
|
if (other.player != null)
|
||||||
|
return false;
|
||||||
|
} else if (!player.equals(other.player))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shouldSave() {
|
||||||
|
if(!shouldSave) {
|
||||||
|
shouldSave=true;
|
||||||
|
Bukkit.getScheduler().runTaskLater(plugin, () -> saveFile(),5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void newGarde(GardeSceaux gs) {
|
||||||
|
gardes.add(gs);
|
||||||
|
shouldSave();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean delGarde(String ass) {
|
||||||
|
Optional<GardeSceaux> gd = gardes.stream().filter(g-> g.assignationID.contentEquals(ass)).findAny();
|
||||||
|
if(gd.isPresent()) {
|
||||||
|
gardes.remove(gd.get());
|
||||||
|
shouldSave();
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean itemGarde(String nom2, NamespacedKey item) {
|
||||||
|
for(GardeSceaux gs : gardes) {
|
||||||
|
if(gs.assignationID.contentEquals(nom2)) {
|
||||||
|
gs.item = item;
|
||||||
|
shouldSave();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public boolean playerGarde(String nom2, UUID player) {
|
||||||
|
for(GardeSceaux gs : gardes) {
|
||||||
|
if(gs.assignationID.contentEquals(nom2)) {
|
||||||
|
gs.player = player;
|
||||||
|
shouldSave();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public boolean nameGarde(String nom2, String name) {
|
||||||
|
for(GardeSceaux gs : gardes) {
|
||||||
|
if(gs.assignationID.contentEquals(nom2)) {
|
||||||
|
gs.exactName = name;
|
||||||
|
shouldSave();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,5 +1,37 @@
|
|||||||
package com.bernard.ptitPlugin.unicitax;
|
package com.bernard.ptitPlugin.unicitax;
|
||||||
|
|
||||||
public class Unicitax {
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.AnvilInventory;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class Unicitax implements Listener{
|
||||||
|
|
||||||
|
GardeMonetaire gmot;
|
||||||
|
public Fisc fisc;
|
||||||
|
|
||||||
|
public Unicitax(Plugin p) {
|
||||||
|
gmot = new GardeMonetaire(p);
|
||||||
|
fisc = new Fisc(gmot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onRename(InventoryClickEvent ev) {
|
||||||
|
if(!(ev.getInventory() instanceof AnvilInventory) || ev.isCancelled() || !(ev.getWhoClicked() instanceof Player))
|
||||||
|
return;
|
||||||
|
AnvilInventory aiv = (AnvilInventory) ev.getInventory();
|
||||||
|
if(gmot.gardes.stream().anyMatch(g -> aiv.getItem(0/* slot de gauche*/).getType().getKey().equals(g.item) &&
|
||||||
|
((Player)ev.getWhoClicked()).getUniqueId().equals(g.player) &&
|
||||||
|
aiv.getRenameText().contentEquals(g.exactName))) {
|
||||||
|
ev.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user