Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlammar authored and Vlammar committed Dec 31, 2024
1 parent b11633c commit 207d6b0
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 183 deletions.
15 changes: 4 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,17 @@
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.8</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>fr.zcraft</groupId>
<artifactId>quartzlib</artifactId>
<version>0.0.7-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.8</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
39 changes: 18 additions & 21 deletions src/main/java/fr/moribus/imageonmap/Argument.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@

import fr.zcraft.quartzlib.tools.PluginLogger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;

Expand All @@ -50,7 +52,7 @@ public class Argument {
private final Status status;

private String content;
private String defaultValue;
private Object defaultValue;

public Argument(String name, Type type, Status status) {
this.name = name;
Expand Down Expand Up @@ -108,19 +110,19 @@ public <T extends Object> T getDefault() {
}
switch (type) {
case BOOLEAN:
return (T) Boolean.valueOf(defaultValue);
return (T) Boolean.valueOf((Boolean) defaultValue);
case INT:
return (T) Integer.getInteger(defaultValue);
return (T) Integer.getInteger((String) defaultValue);
case UUID:
return (T) UUID.fromString(defaultValue);
return (T) UUID.fromString((String) defaultValue);
case DOUBLE:
return (T) Double.valueOf(defaultValue);
return (T) Double.valueOf((String) defaultValue);
case STRING:
return (T) defaultValue;
case ONLINE_PLAYER:
return (T) Bukkit.getPlayer(toUUID(defaultValue));
return (T) Bukkit.getPlayer(toUUID((String) defaultValue));
case OFFLINE_PLAYER:
return (T) Bukkit.getOfflinePlayer(toUUID(defaultValue));
return (T) Bukkit.getOfflinePlayer(toUUID((String) defaultValue));

default:
PluginLogger.info("To be implemented");
Expand Down Expand Up @@ -232,15 +234,16 @@ public static boolean isAmbiguous(List<Argument> prototype, boolean isPlayer) {
return false;
}

public static List<Argument> parseArguments(List<Argument> prototype, ArrayList<String> args, boolean isPlayer)
public static Map<String, Argument> parseArguments(List<Argument> prototype, ArrayList<String> args,
boolean isPlayer)
throws Exception {
//check if the command is not ambiguous
if (isAmbiguous(prototype, isPlayer)) {
throw new Exception("Parsing error, ambiguous command prototype");
}
// givemap Vlammar Vlammar:"carte 1" 10
// string |string| string <int>
List<Argument> list = new ArrayList<>();
Map<String, Argument> map = new HashMap<>();
List<Argument> uncertain = new ArrayList<>();

for (int i = 0; i < args.size(); i++) {
Expand All @@ -250,44 +253,38 @@ public static List<Argument> parseArguments(List<Argument> prototype, ArrayList<
for (int j = i; j < prototype.size(); j++) {
PluginLogger.info("j = {0}", j);
Argument a = prototype.get(j);
PluginLogger.info("argument name: \n{0}", a.toString());
switch (a.status) {
case OBLIGATORY:
case MANDATORY:
PluginLogger.info("OBLIGATORY");
if (uncertain.isEmpty()) {
PluginLogger.info(a.getName());
list.add(a);
map.put(a.getName(), a);
a.setContent(arg);
PluginLogger.info("argument : \n{0}", a.toString());
next = true;
} else {
for (Argument l : uncertain) {
//if size doesnt match or
try {
PluginLogger.info("test pour l'erreur");
PluginLogger.info(a.getContent());
a.setContent(a.content); //todo erreur ?
PluginLogger.info("argument : \n{0}", a.toString());
} catch (Exception e) {
//shift to the right
}
}
PluginLogger.info(a.getName());
list.add(a);
map.put(a.getName(), a);
uncertain = new ArrayList<>();
}
break;
case OPTIONAL:
PluginLogger.info("OPTIONAL");
PluginLogger.info(a.getName());
a.setContent(arg);
uncertain.add(a);
PluginLogger.info("argument : \n{0}", a.toString());
break;
case OPTIONAL_FOR_PLAYER_ONLY:
PluginLogger.info("OPTIONAL_FOR_PLAYER_ONLY");
if (!isPlayer) {
PluginLogger.info(a.getName());
list.add(a);
map.put(a.getName(), a);
a.setContent(arg);
PluginLogger.info("argument : \n{0}", a.toString());
next = true;
Expand All @@ -308,7 +305,7 @@ public static List<Argument> parseArguments(List<Argument> prototype, ArrayList<
}
}
}
return list;
return map;
}

@Override
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/fr/moribus/imageonmap/ImageOnMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import fr.moribus.imageonmap.commands.maptool.GetRemainingCommand;
import fr.moribus.imageonmap.commands.maptool.GiveCommand;
import fr.moribus.imageonmap.commands.maptool.ListCommand;
import fr.moribus.imageonmap.commands.maptool.MigrateCommand;
import fr.moribus.imageonmap.commands.maptool.NewCommand;
import fr.moribus.imageonmap.commands.maptool.RemotePlacingCommand;
import fr.moribus.imageonmap.commands.maptool.RenameCommand;
Expand Down Expand Up @@ -78,14 +79,11 @@
// rework des GUI (map part utile ???);
// Pouvoir déployer carte à distance;
// carte interractive (5.1?);
// bug: hover text ne marche plus;
// glow effect a refaire (vraiment utile ???);
// Miniature des maps en 1x1 (migration?);
// ecrire directement sur les cartes pour ne pas tout perdre(migration);
// réduire dépendance QL;
// retirer les prints de QL et IoM => verbose ou debug pour avoir une trace de ce qui est fait ?;
// bug: suppression image chat (inconnue ?) laisse item frame invisible;
// passer invisibiliter et glow dans le GUI si permission sinon solution RP avec le nombre qu'il faut de glowsac
// passer invisibiliter et glow dans le GUI si permission
// avec un clic droit sur les frames et fenetre en verre pour la protection contre le grief des mobs et potion
// invisibilité pour rendre frame invisible (peut etre que l'item utilisé pour le craft); proposer craft RP des cartes
// soit avec un item map vide+ un item de peintre ? soit avec un atelier?
Expand Down Expand Up @@ -160,7 +158,6 @@ public void onEnable() {
return;
}


saveDefaultConfig();
commandWorker = loadComponent(CommandWorkers.class);
loadComponents(I18n.class, Gui.class, Commands.class, PluginConfiguration.class, ImageIOExecutor.class,
Expand All @@ -184,7 +181,7 @@ public void onEnable() {
GiveCommand.class,
GetRemainingCommand.class,
ExploreCommand.class,
//MigrateCommand.class,//Removed for now doesn't work nor is useful, maybe useful later on
MigrateCommand.class,
UpdateCommand.class,
RemotePlacingCommand.class
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/moribus/imageonmap/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
package fr.moribus.imageonmap;

public enum Status {
OBLIGATORY, OPTIONAL, OPTIONAL_FOR_PLAYER_ONLY
MANDATORY, OPTIONAL, OPTIONAL_FOR_PLAYER_ONLY
}
2 changes: 2 additions & 0 deletions src/main/java/fr/moribus/imageonmap/commands/IoMCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
public abstract class IoMCommand extends Command {
protected UUID getPlayerUUID(String playerName) {
return Bukkit.getOfflinePlayer(playerName).getUniqueId();
//TODO replace with homemade solution using https://api.mojang.com/users/profiles/minecraft/
}

private boolean checkTooArguments(boolean bool, String msg) throws CommandException {
Expand All @@ -72,6 +73,7 @@ protected boolean checkTooFewArguments(boolean bool) throws CommandException {
}

protected boolean checkArguments(boolean bool1, boolean bool2) throws CommandException {
//TODO WTF is happening here
return !(checkTooManyArguments(bool1) || checkTooFewArguments(bool2));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ protected void run() throws CommandException {
}

OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName);
//TODO replace with homemade solution using https://api.mojang.com/users/profiles/minecraft/playername
// to get the UUId
if (sender.isOnline()) {
Gui.open(sender, new PosterListGui(offlinePlayer, playerName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import fr.zcraft.quartzlib.tools.PluginLogger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
Expand All @@ -58,9 +59,9 @@
@CommandInfo(name = "give", usageParameters = "<player name> [playerFrom]:<map name> [quantity]")
public class GiveCommand extends IoMCommand {
protected List<Argument> commandPrototype() {
Argument target = new Argument("target", Type.STRING, Status.OBLIGATORY);
Argument target = new Argument("target", Type.STRING, Status.MANDATORY);
Argument from = new Argument("from", Type.STRING, Status.OPTIONAL_FOR_PLAYER_ONLY);
Argument posterName = new Argument("posterName", Type.STRING, Status.OBLIGATORY);
Argument posterName = new Argument("posterName", Type.STRING, Status.MANDATORY);
Argument quantity = new Argument("quantity", Type.INT, Status.OPTIONAL, "1");

List<Argument> list = new ArrayList<>();
Expand All @@ -79,10 +80,17 @@ protected void run() throws CommandException {

List<Argument> cmdProto = commandPrototype();
ArrayList<String> arguments = getArgs();
Boolean isPlayer = sender != null;
List<Argument> args;
boolean isPlayer = sender != null;
final String posterName;
final String from;
final String playerName;
final int quantity;
try {
args = Argument.parseArguments(cmdProto, arguments, isPlayer);
Map<String, Argument> argMap = Argument.parseArguments(cmdProto, arguments, isPlayer);
posterName = argMap.get("posterName").getContent();
from = argMap.get("from").getContent();
playerName = argMap.get("target").getContent();
quantity = argMap.get("quantity").getContent();
} catch (Exception e) {
PluginLogger.error("Error while parsing command");
return;
Expand All @@ -95,11 +103,12 @@ protected void run() throws CommandException {
return;
}

/*
final String posterName = Argument.findContent("posterName", args);
final String from = Argument.findContent("from", args);
final String playerName = Argument.findContent("target", args);
final int quantity = Argument.findContent("quantity", args);

*/
PluginLogger.info("quantity {0}", quantity);
if (posterName == null || from == null || playerName == null) {
PluginLogger.error("Error one argument is null, check argument names");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@

package fr.moribus.imageonmap.commands.maptool;

import fr.moribus.imageonmap.Argument;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.Status;
import fr.moribus.imageonmap.Type;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImagePoster;
import fr.moribus.imageonmap.map.PosterManager;
Expand All @@ -49,7 +52,11 @@
import fr.zcraft.quartzlib.tools.PluginLogger;
import fr.zcraft.quartzlib.tools.text.RawMessage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
Expand All @@ -70,6 +77,7 @@ protected void run() throws CommandException {

String playerName;
final boolean isHuman = (sender instanceof Player);

if (arguments.size() == 1) {
if (!Permissions.LISTOTHER.grantedTo(sender) && isHuman) {
throwNotAuthorized();
Expand All @@ -85,6 +93,19 @@ protected void run() throws CommandException {
return;
}
}
try {
List<Argument> prototype = new ArrayList<>();
prototype.add(new Argument("playerName", Type.STRING, Status.OPTIONAL, playerName));
Map<String, Argument> argMap = Argument.parseArguments(prototype, arguments, isHuman);

for (String key : argMap.keySet()) {
Argument arg = argMap.get(key);
PluginLogger.info("Arguments : \n name " + arg.getName() + "\n type " + arg.getType()
+ "\n status " + arg.getStatus());
}
} catch (Exception e) {
PluginLogger.warning(e.toString());
}
final Player playerSender;
if (isHuman) {
playerSender = playerSender();
Expand All @@ -102,6 +123,7 @@ protected void run() throws CommandException {
}
return;
}

String msg = I.tn("{white}{bold}{0} map found.",
"{white}{bold}{0} maps found.",
posterList.size());
Expand Down
Loading

0 comments on commit 207d6b0

Please sign in to comment.