Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add teleport arg support to all points #77

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public abstract class ServerTutorialPoint{
protected boolean lockView;
protected double time;
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;
Expand All @@ -61,6 +62,7 @@ public ServerTutorialPoint(ServerTutorialPlus plugin, Location loc, PointType ty
this.lockPlayer = false;
this.lockView = false;
this.pointionEffects = new ArrayList<>();
this.teleport = teleport;
}

/**
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -201,6 +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");
String teleportConfigPath = "tutorials." + ID + ".points." + i + ".teleport";
if (tutorialSaves.isBoolean(teleportConfigPath)) {
teleport = tutorialSaves.getBoolean(teleportConfigPath);
}
/*
Fire work meta!
*/
Expand Down Expand Up @@ -266,6 +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);
tutorialSaves.set("tutorials." + key + ".points." + i + ".teleport", teleport);

if(titleInfo != null){
tutorialSaves.set("tutorials." + key + ".points." + i + ".title.title", titleInfo.title);
Expand Down Expand Up @@ -321,6 +328,7 @@ public List<PointArg> getArgs(){
args.add(new PotionEffectArg());
args.add(new SoundArg());
args.add(new TitleArg());
args.add(new TeleportArg());
return args;
}

Expand Down Expand Up @@ -439,4 +447,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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ 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);
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;
Expand All @@ -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 <id> <point> setblock" + ChatColor.RED + " to set the clickable block!");
Expand Down Expand Up @@ -118,15 +117,13 @@ 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
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
Expand Down Expand Up @@ -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 <t> <p> particles <TRUE/FALSE>");
return false;
}

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


return args;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CommandPoint extends ServerTutorialPoint {
private static Map<UUID, IPointCallBack> waiting = new WeakHashMap<>();

public CommandPoint(ServerTutorialPlus plugin, Location loc) {
super(plugin, loc, PointType.COMMAND);
super(plugin, loc, PointType.COMMAND, true);
}

@Override
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <t> <p> teleport <false/true>");
return false;
}

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