From f6b90132dca6aab1bbd8f0bf9da2fabeada6dbaf Mon Sep 17 00:00:00 2001 From: alan67160 <20385640+alan67160@users.noreply.github.com> Date: Fri, 29 Sep 2023 15:24:38 +0800 Subject: [PATCH 1/3] add teleport arg support to all points --- .../points/ServerTutorialPoint.java | 17 ++++++++-- .../points/custom/CheckPoint.java | 2 +- .../points/custom/ClickBlockPoint.java | 24 +------------- .../points/custom/CommandPoint.java | 2 +- .../points/editor/args/TeleportArg.java | 33 +++++++++++++++++++ 5 files changed, 51 insertions(+), 27 deletions(-) create mode 100644 src/main/java/nl/martenm/servertutorialplus/points/editor/args/TeleportArg.java diff --git a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java index 2ff449e..759bf2a 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java @@ -49,6 +49,7 @@ public abstract class ServerTutorialPoint{ protected boolean lockView; protected double time; protected boolean flying; + protected boolean teleport; public ServerTutorialPoint(ServerTutorialPlus plugin, Location loc, PointType type) { this.plugin = plugin; @@ -61,6 +62,7 @@ public ServerTutorialPoint(ServerTutorialPlus plugin, Location loc, PointType ty this.lockPlayer = false; this.lockView = false; this.pointionEffects = new ArrayList<>(); + this.teleport = true; } /** @@ -76,7 +78,7 @@ public IPlayPoint createPlay(Player player, OldValuesPlayer oldValuesPlayer, IPo @Override public void start() { - playDefault(player, oldValuesPlayer, true); + playDefault(player, oldValuesPlayer); timerTask = new BukkitRunnable() { @Override @@ -99,7 +101,7 @@ public void stop() { * @param player The targeted player. * @param oldValuesPlayer Old values of the player before starting the tutorial / point. */ - protected void playDefault(Player player, OldValuesPlayer oldValuesPlayer, boolean teleport) { + protected void playDefault(Player player, OldValuesPlayer oldValuesPlayer) { if(teleport) player.teleport(loc); for (String message : message_chat) { @@ -201,6 +203,7 @@ public void readSaveData(Config tutorialSaves, String ID, String i) { lockPlayer = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".locplayer"); lockView = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".locview"); flying = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".setFly"); + teleport = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".teleport"); /* Fire work meta! */ @@ -266,6 +269,7 @@ public void saveData(Config tutorialSaves, String key, String i){ tutorialSaves.set("tutorials." + key + ".points." + i + ".actionbar", message_actionBar); tutorialSaves.set("tutorials." + key + ".points." + i + ".commands", commands); if(flying) tutorialSaves.set("tutorials." + key + ".points." + i + ".setFly", flying); + if(!teleport) tutorialSaves.set("tutorials." + key + ".points." + i + ".teleport", teleport); if(titleInfo != null){ tutorialSaves.set("tutorials." + key + ".points." + i + ".title.title", titleInfo.title); @@ -321,6 +325,7 @@ public List getArgs(){ args.add(new PotionEffectArg()); args.add(new SoundArg()); args.add(new TitleArg()); + args.add(new TeleportArg()); return args; } @@ -439,4 +444,12 @@ public boolean isSetFlying() { public void setFlying(boolean setFlying) { this.flying = setFlying; } + + public boolean isSetTeleport() { + return flying; + } + + public void setTeleport(boolean setTeleport) { + this.teleport = setTeleport; + } } diff --git a/src/main/java/nl/martenm/servertutorialplus/points/custom/CheckPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/custom/CheckPoint.java index 0d844b4..9bc66d8 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/custom/CheckPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/custom/CheckPoint.java @@ -59,7 +59,7 @@ public IPlayPoint createPlay(Player player, OldValuesPlayer oldValuesPlayer, IPo @Override public void start() { - playDefault(player, oldValuesPlayer, false); + playDefault(player, oldValuesPlayer); checker = new BukkitRunnable() { int count; diff --git a/src/main/java/nl/martenm/servertutorialplus/points/custom/ClickBlockPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/custom/ClickBlockPoint.java index c3415c2..bf0bd83 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/custom/ClickBlockPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/custom/ClickBlockPoint.java @@ -37,7 +37,6 @@ public class ClickBlockPoint extends ServerTutorialPoint { private boolean enableParticles; private Color particleColor; - private boolean teleport; public ClickBlockPoint(ServerTutorialPlus plugin, Location loc) { super(plugin, loc, PointType.CLICK_BLOCK); @@ -57,7 +56,7 @@ public IPlayPoint createPlay(Player player, OldValuesPlayer oldValuesPlayer, IPo return new IPlayPoint(){ @Override public void start() { - playDefault(player, oldValuesPlayer, teleport); + playDefault(player, oldValuesPlayer); if(clickableBlock == null){ player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "SKIPPED: " + ChatColor.RED + "Point has not been setup! Use the command " + ChatColor.YELLOW + "/st editpoint setblock" + ChatColor.RED + " to set the clickable block!"); @@ -118,7 +117,6 @@ protected void saveCustomData(Config tutorialSaves, String key, String i) { tutorialSaves.set("tutorials." + key + ".points." + i + ".blocklocation", PluginUtils.fromLocation(clickableBlock)); tutorialSaves.set("tutorials." + key + ".points." + i + ".particles", enableParticles); tutorialSaves.set("tutorials." + key + ".points." + i + ".colour", particleColor.toString()); - tutorialSaves.set("tutorials." + key + ".points." + i + ".teleport", teleport); } @Override @@ -126,7 +124,6 @@ protected void readCustomSaveData(Config tutorialSaves, String key, String i) { clickableBlock = PluginUtils.fromString(plugin, tutorialSaves.getString("tutorials." + key + ".points." + i + ".blocklocation")).getBlock().getLocation(); particleColor = Color.fromString(tutorialSaves.getString("tutorials." + key + ".points." + i + ".colour")); enableParticles = tutorialSaves.getBoolean("tutorials." + key + ".points." + i + ".particles"); - teleport = tutorialSaves.getBoolean("tutorials." + key + ".points." + i + ".teleport"); } @Override @@ -208,25 +205,6 @@ public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, Com } }); - args.add(new PointArg("teleport", new String[] {"tp"} ) { - @Override - public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) { - if (args.length < 1) { - sender.sendMessage(ChatColor.RED + "Wrong usage. /st editpoint

particles "); - return false; - } - - try{ - teleport = Boolean.valueOf(args[0]); - } catch (NumberFormatException ex){ - sender.sendMessage(ChatColor.RED + "Wrong usage. /st editpoint

particles "); - return false; - } - return true; - } - }); - - return args; } } diff --git a/src/main/java/nl/martenm/servertutorialplus/points/custom/CommandPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/custom/CommandPoint.java index a175e25..7d54f8e 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/custom/CommandPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/custom/CommandPoint.java @@ -32,7 +32,7 @@ public IPlayPoint createPlay(Player player, OldValuesPlayer oldValuesPlayer, IPo @Override public void start() { waiting.put(player.getUniqueId(), callBack); - playDefault(player, oldValuesPlayer, true); + playDefault(player, oldValuesPlayer); } @Override diff --git a/src/main/java/nl/martenm/servertutorialplus/points/editor/args/TeleportArg.java b/src/main/java/nl/martenm/servertutorialplus/points/editor/args/TeleportArg.java new file mode 100644 index 0000000..28c8584 --- /dev/null +++ b/src/main/java/nl/martenm/servertutorialplus/points/editor/args/TeleportArg.java @@ -0,0 +1,33 @@ +package nl.martenm.servertutorialplus.points.editor.args; + +import nl.martenm.servertutorialplus.language.Lang; +import nl.martenm.servertutorialplus.objects.ServerTutorial; +import nl.martenm.servertutorialplus.points.ServerTutorialPoint; +import nl.martenm.servertutorialplus.points.editor.PointArg; +import org.bukkit.command.CommandSender; + +public class TeleportArg extends PointArg { + + + public TeleportArg() { + super("teleport", new String[] {"tp"}); + } + + @Override + public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) { + + if(args.length < 1){ + sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint

teleport "); + return false; + } + + try{ + point.setTeleport(Boolean.parseBoolean(args[0])); + } catch (Exception ex){ + sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint

teleport "); + return false; + } + return true; + } +} + From e6be8c9f58e2d9bfb915e79a30a0564d393553e7 Mon Sep 17 00:00:00 2001 From: alan67160 <20385640+alan67160@users.noreply.github.com> Date: Fri, 29 Sep 2023 16:13:10 +0800 Subject: [PATCH 2/3] fix default tp value --- .../martenm/servertutorialplus/points/ServerTutorialPoint.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java index 759bf2a..a041ad2 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java @@ -203,7 +203,7 @@ public void readSaveData(Config tutorialSaves, String ID, String i) { lockPlayer = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".locplayer"); lockView = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".locview"); flying = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".setFly"); - teleport = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".teleport"); + teleport = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".teleport", true); /* Fire work meta! */ From a1833526661d0b6096fef9ac835a44d497285f63 Mon Sep 17 00:00:00 2001 From: alan67160 <20385640+alan67160@users.noreply.github.com> Date: Sun, 1 Oct 2023 12:46:23 +0800 Subject: [PATCH 3/3] teleport default update --- .../points/ServerTutorialPoint.java | 11 +++++++---- .../servertutorialplus/points/custom/CheckPoint.java | 2 +- .../points/custom/ClickBlockPoint.java | 4 ++-- .../points/custom/CommandPoint.java | 2 +- .../servertutorialplus/points/custom/TimedPoint.java | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java index a041ad2..4f35ac1 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java @@ -51,7 +51,7 @@ public abstract class ServerTutorialPoint{ protected boolean flying; protected boolean teleport; - public ServerTutorialPoint(ServerTutorialPlus plugin, Location loc, PointType type) { + public ServerTutorialPoint(ServerTutorialPlus plugin, Location loc, PointType type, Boolean teleport) { this.plugin = plugin; this.loc = loc; this.type = type; @@ -62,7 +62,7 @@ public ServerTutorialPoint(ServerTutorialPlus plugin, Location loc, PointType ty this.lockPlayer = false; this.lockView = false; this.pointionEffects = new ArrayList<>(); - this.teleport = true; + this.teleport = teleport; } /** @@ -203,7 +203,10 @@ public void readSaveData(Config tutorialSaves, String ID, String i) { lockPlayer = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".locplayer"); lockView = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".locview"); flying = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".setFly"); - teleport = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".teleport", true); + String teleportConfigPath = "tutorials." + ID + ".points." + i + ".teleport"; + if (tutorialSaves.isBoolean(teleportConfigPath)) { + teleport = tutorialSaves.getBoolean(teleportConfigPath); + } /* Fire work meta! */ @@ -269,7 +272,7 @@ public void saveData(Config tutorialSaves, String key, String i){ tutorialSaves.set("tutorials." + key + ".points." + i + ".actionbar", message_actionBar); tutorialSaves.set("tutorials." + key + ".points." + i + ".commands", commands); if(flying) tutorialSaves.set("tutorials." + key + ".points." + i + ".setFly", flying); - if(!teleport) tutorialSaves.set("tutorials." + key + ".points." + i + ".teleport", teleport); + tutorialSaves.set("tutorials." + key + ".points." + i + ".teleport", teleport); if(titleInfo != null){ tutorialSaves.set("tutorials." + key + ".points." + i + ".title.title", titleInfo.title); diff --git a/src/main/java/nl/martenm/servertutorialplus/points/custom/CheckPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/custom/CheckPoint.java index 9bc66d8..86ab90a 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/custom/CheckPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/custom/CheckPoint.java @@ -43,7 +43,7 @@ public enum AnimationType { } public CheckPoint(ServerTutorialPlus plugin, Location loc) { - super(plugin, loc, PointType.CHECKPOINT); + super(plugin, loc, PointType.CHECKPOINT, false); animationType = AnimationType.CIRCLE; color = new Color(244, 153, 0); guideColor = new Color(244, 244, 244); diff --git a/src/main/java/nl/martenm/servertutorialplus/points/custom/ClickBlockPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/custom/ClickBlockPoint.java index bf0bd83..d68e491 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/custom/ClickBlockPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/custom/ClickBlockPoint.java @@ -39,13 +39,13 @@ public class ClickBlockPoint extends ServerTutorialPoint { private Color particleColor; public ClickBlockPoint(ServerTutorialPlus plugin, Location loc) { - super(plugin, loc, PointType.CLICK_BLOCK); + super(plugin, loc, PointType.CLICK_BLOCK, false); particleColor = new Color(125, 255, 0); clickableBlock = loc.clone(); } public ClickBlockPoint(ServerTutorialPlus plugin, Location loc, boolean enableParticles) { - super(plugin, loc, PointType.CLICK_BLOCK); + super(plugin, loc, PointType.CLICK_BLOCK, false); clickableBlock = loc.getBlock().getLocation(); particleColor = new Color(125, 255, 0); this.enableParticles = enableParticles; diff --git a/src/main/java/nl/martenm/servertutorialplus/points/custom/CommandPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/custom/CommandPoint.java index 7d54f8e..91d1991 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/custom/CommandPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/custom/CommandPoint.java @@ -23,7 +23,7 @@ public class CommandPoint extends ServerTutorialPoint { private static Map waiting = new WeakHashMap<>(); public CommandPoint(ServerTutorialPlus plugin, Location loc) { - super(plugin, loc, PointType.COMMAND); + super(plugin, loc, PointType.COMMAND, true); } @Override diff --git a/src/main/java/nl/martenm/servertutorialplus/points/custom/TimedPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/custom/TimedPoint.java index 47e3f01..679532b 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/custom/TimedPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/custom/TimedPoint.java @@ -12,7 +12,7 @@ public class TimedPoint extends ServerTutorialPoint { public TimedPoint(ServerTutorialPlus plugin, Location loc) { - super(plugin, loc, PointType.TIMED); + super(plugin, loc, PointType.TIMED, true); } //Timed point is basically just a default point without additions.