org.bukkit.conversations.ConversationContext Java Examples

The following examples show how to use org.bukkit.conversations.ConversationContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnimationBuilderInputPrompt.java    From HoloAPI with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getPromptText(ConversationContext conversationContext) {
    if (conversationContext.getSessionData("askingForDelay") == null) {
        conversationContext.setSessionData("askingForDelay", false);
    }
    if (conversationContext.getSessionData("nextFrame") == null) {
        conversationContext.setSessionData("nextFrame", false);
    }

    if ((Boolean) conversationContext.getSessionData("askingForDelay")) {
        return Lang.PROMPT_DELAY.getValue();
    }
    if ((Boolean) conversationContext.getSessionData("nextFrame")) {
        conversationContext.setSessionData("nextFrame", false);
        return Lang.PROMPT_NEXT_FRAME.getValue("num", (this.frames.size() + 1) + "");
    }
    if (this.first) {
        return Lang.PROMPT_INPUT_FRAMES.getValue();
    } else {
        return Lang.PROMPT_INPUT_NEXT.getValue("input", ChatColor.translateAlternateColorCodes('&', conversationContext.getSessionData("lastAdded") + ""));
    }
}
 
Example #2
Source File: BuilderInputSuccessPrompt.java    From HoloAPI with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getPromptText(ConversationContext conversationContext) {
    ArrayList<HoloInputBuilder> builders = (ArrayList<HoloInputBuilder>) conversationContext.getSessionData("builders");
    //ArrayList<String> lines = new ArrayList<String>();
    HologramFactory hf = new HologramFactory(HoloAPI.getCore());
    for (HoloInputBuilder b : builders) {
        if (b.getType() == null || b.getLineData() == null) {
            continue;
        }
        if (b.getType().equalsIgnoreCase("IMAGE")) {
            ImageGenerator gen = HoloAPI.getImageLoader().getGenerator(b.getLineData());
            if (gen == null) {
                continue;
            }
            hf.withImage(gen);
        } else {
            hf.withText(b.getLineData());
        }
    }
    if (hf.isEmpty()) {
        return Lang.BUILDER_EMPTY_LINES.getValue();
    }
    hf.withLocation(((Player) conversationContext.getForWhom()).getLocation());
    Hologram h = hf.build();
    return Lang.HOLOGRAM_CREATED.getValue("id", h.getSaveId());
}
 
Example #3
Source File: NameSuccessPrompt.java    From EchoPet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getPromptText(ConversationContext context) {
    String name = (String) context.getSessionData("name");
    boolean success = this.pet.setPetName(name, false);
    if (success) {
        return this.admin ? Lang.ADMIN_NAME_PET.toString()
                .replace("%player%", this.pet.getNameOfOwner())
                .replace("%type%", StringUtil.capitalise(this.pet.getPetType().toString().replace("_", " ")))
                .replace("%name%", name)

                : Lang.NAME_PET.toString()
                .replace("%type%", StringUtil.capitalise(this.pet.getPetType().toString().replace("_", " ")))
                .replace("%name%", name);
    } else {
        return Lang.NAME_NOT_ALLOWED.toString().replace("%name%", name);
    }
}
 
Example #4
Source File: NameSuccessPrompt.java    From SonarPet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getPromptText(ConversationContext context) {
    String name = (String) context.getSessionData("name");
    boolean success = this.pet.setPetName(name, false);
    if (success) {
        return this.admin ? Lang.ADMIN_NAME_PET.toString()
                .replace("%player%", this.pet.getNameOfOwner())
                .replace("%type%", this.pet.getPetType().toPrettyString())
                .replace("%name%", name)

                : Lang.NAME_PET.toString()
                .replace("%type%", this.pet.getPetType().toPrettyString())
                .replace("%name%", name);
    } else {
        return Lang.NAME_NOT_ALLOWED.toString().replace("%name%", name);
    }
}
 
Example #5
Source File: BuilderInputPrompt.java    From HoloAPI with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getPromptText(ConversationContext conversationContext) {
    if (this.currentBuilder != null) {
        if (this.currentBuilder.getLineData() == null) {
            return this.currentBuilder.getType().equalsIgnoreCase("TEXT") ? Lang.BUILDER_INPUT_LINE_DATA.getValue() : Lang.BUILDER_INPUT_IMAGE_PATH.getValue();
        } else {
            if (b) {
                int size = this.builders.size();
                return Lang.BUILDER_INPUT_NEXT_WITH_NUMBER.getValue("line", size + (size == 1 ? "st" : (size == 2 ? "nd" : (size == 3 ? "rd" : "4th"))));
            } else {
                return Lang.IMAGE_NOT_FOUND.getValue();
            }
        }
    } else {
        return Lang.BUILDER_INPUT_FIRST.getValue();
    }
}
 
Example #6
Source File: AnimationBuilderInputPrompt.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean isInputValid(ConversationContext conversationContext, String s) {
    if (conversationContext.getSessionData("askingForDelay") == null) {
        conversationContext.setSessionData("askingForDelay", false);
    }
    if (conversationContext.getSessionData("nextFrame") == null) {
        conversationContext.setSessionData("nextFrame", false);
    }

    return !((Boolean) conversationContext.getSessionData("askingForDelay") && !GeneralUtil.isInt(s)) && !(this.first && s.equalsIgnoreCase("DONE")) && !(s.equalsIgnoreCase("NEXT") && this.lines.isEmpty());
}
 
Example #7
Source File: ScriptBuilderPrompt.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getPromptText(ConversationContext context) {
    if (this.currentlyEditing == 0 && lines.isEmpty()) {
        return ChatColor.DARK_AQUA + "function(hologram, player) {";
    }
    int edit = currentlyEditing;
    currentlyEditing = lines.size() - 1;
    return new PowerMessage().then(edit).colour(ChatColor.DARK_AQUA).then(lines.get(edit)).colour(ChatColor.AQUA).group().tooltip(buildCompiledOutput()).tooltip(ChatColor.YELLOW + "" + ChatColor.ITALIC + "Click to edit this line").perform("script editcurrent " + edit).exit().toJson();
}
 
Example #8
Source File: UHPrompts.java    From KTP with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Prompt acceptValidatedInput(ConversationContext context,
		String input) {
	context.setSessionData("color", StringToChatColor.getChatColorByName(ChatColor.stripColor(input)));
	p.createTeam((String) context.getSessionData("nomTeam"), (ChatColor) context.getSessionData("color"));
	context.getForWhom().sendRawMessage(ChatColor.GRAY+"Team "+((ChatColor)context.getSessionData("color"))+context.getSessionData("nomTeam")+ChatColor.GRAY+" créée.");
	return Prompt.END_OF_CONVERSATION;
}
 
Example #9
Source File: InputPrompt.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Prompt acceptValidatedInput(ConversationContext conversationContext, String s) {
    Object findLoc = conversationContext.getSessionData("findloc");
    if (findLoc != null && ((Boolean) findLoc)) {
        if (s.contains(" ")) {
            String[] split = s.split("\\s");
            if (split.length == 4) {
                if (Bukkit.getWorld(split[0]) != null) {
                    try {
                        conversationContext.setSessionData("location", new Location(Bukkit.getWorld(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3])));
                        return this.successPrompt;
                    } catch (NumberFormatException e) {
                        conversationContext.setSessionData("fail_int", true);
                    }
                } else {
                    conversationContext.setSessionData("fail_world", true);
                }
            } else {
                conversationContext.setSessionData("fail_format", true);
            }
        } else {
            conversationContext.setSessionData("fail_format", true);
        }
    } else if (s.equalsIgnoreCase("DONE")) {
        conversationContext.setSessionData("lines", this.lines.toArray(new String[this.lines.size()]));
        if (conversationContext.getSessionData("location") == null) {
            if (conversationContext.getForWhom() instanceof Player) {
                conversationContext.setSessionData("location", ((Player) conversationContext.getForWhom()).getLocation());
                return this.successPrompt;
            } else {
                conversationContext.setSessionData("findloc", true);
            }
        } else {
            return this.successPrompt;
        }
    } else {
        this.lines.add(s);
    }
    return new InputPrompt(this.lines, this.successPrompt, s);
}
 
Example #10
Source File: UHPrompts.java    From KTP with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean isInputValid(ConversationContext context, String input) {
	for (String s : colors) {
		if (ChatColor.stripColor(s).equalsIgnoreCase(input)) return true;
	}
	return false;
}
 
Example #11
Source File: ScriptBuilderPrompt.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Prompt acceptInput(ConversationContext context, String input) {
    if (input.equalsIgnoreCase("DONE")) {
        LangSetting.send(context.getForWhom(), "}");
        return new ScriptBuilderSuccess(this.lines, this.scriptName);
    }

    this.lines.add(currentlyEditing, input);
    return this;
}
 
Example #12
Source File: NamePrompt.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Prompt acceptInput(ConversationContext conversationContext, String s) {
    if (s.length() > 32) {
        conversationContext.getForWhom().sendRawMessage(EchoPet.getPrefix() + Lang.PET_NAME_TOO_LONG.toString());
        return this;
    }
    conversationContext.setSessionData("name", s);
    return new NameSuccessPrompt(this.pet, this.admin);
}
 
Example #13
Source File: UHPrompts.java    From KTP with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Prompt acceptValidatedInput(ConversationContext context,
		Player input) {
	p.getTeam((String) context.getSessionData("nomTeam")).addPlayer(input);
	context.getForWhom().sendRawMessage(ChatColor.GREEN+input.getName()+ChatColor.DARK_GREEN+" a été ajouté à l'équipe "+((ChatColor)context.getSessionData("color"))+context.getSessionData("nomTeam")+".");
	return Prompt.END_OF_CONVERSATION;
}
 
Example #14
Source File: NamePrompt.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Prompt acceptInput(ConversationContext conversationContext, String s) {
    if (s.length() > 32) {
        conversationContext.getForWhom().sendRawMessage(EchoPet.getPrefix() + Lang.PET_NAME_TOO_LONG.toString());
        return this;
    }
    conversationContext.setSessionData("name", s);
    return new NameSuccessPrompt(this.pet, this.admin);
}
 
Example #15
Source File: UHPrompts.java    From KTP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getPromptText(ConversationContext context) {
	String colorsString = "";
	for(String s : colors) {
		colorsString += s+ChatColor.WHITE+", ";
	}
	colorsString = colorsString.substring(0, colorsString.length()-2);
	return ChatColor.GRAY+"Veuillez entrer une couleur pour la team. /cancel pour annuler.\n"+colorsString;
}
 
Example #16
Source File: InputPrompt.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getPromptText(ConversationContext conversationContext) {
    Object findLoc = conversationContext.getSessionData("findloc");
    if (findLoc != null && ((Boolean) findLoc)) {
        return Lang.PROMPT_FIND_LOCATION.getValue();
    }
    if (this.first) {
        return Lang.PROMPT_INPUT.getValue();
    } else
        return Lang.PROMPT_INPUT_NEXT.getValue("input", ChatColor.translateAlternateColorCodes('&', this.lastAdded));
}
 
Example #17
Source File: InputPrompt.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected String getFailedValidationText(ConversationContext context, String invalidInput) {
    Object failInt = context.getSessionData("fail_int");
    Object failFormat = context.getSessionData("fail_format");
    Object failWorld = context.getSessionData("fail_world");
    if (failInt != null && ((Boolean) failInt)) {
        return Lang.PROMPT_INPUT_FAIL_INT.getValue();
    } else if (failFormat != null && (Boolean) failFormat) {
        return Lang.PROMPT_INPUT_FAIL_FORMAT.getValue();
    } else if (failWorld != null && (Boolean) failWorld) {
        return Lang.PROMPT_INPUT_FAIL_WORLD.getValue("world", invalidInput.split(" ")[0]);
    }
    return Lang.PROMPT_INPUT_FAIL.getValue();
}
 
Example #18
Source File: UHPrompts.java    From KTP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Prompt acceptInput(ConversationContext context, String input) {
	if (input.length() > 16) {
		context.getForWhom().sendRawMessage(ChatColor.RED+"Le nom de la team doit faire 16 caractères maximum.");
		return this;
	}
	context.setSessionData("nomTeam", input);
	return new TeamColorPrompt();
}
 
Example #19
Source File: InputSuccessPrompt.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getPromptText(ConversationContext conversationContext) {
    String[] lines = (String[]) conversationContext.getSessionData("lines");
    Location location = (Location) conversationContext.getSessionData("location");
    Hologram h = new HologramFactory(HoloAPI.getCore()).withText(lines).withLocation(location).build();
    return Lang.HOLOGRAM_CREATED.getValue("id", h.getSaveId());
}
 
Example #20
Source File: LocationFunction.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isValid(ConversationContext context, String input) {
    if (input.contains(" ")) {
        String[] split = input.split("\\s");
        if (split.length == 4) {
            if (Bukkit.getWorld(split[0]) != null) {
                for (int i = 1; i <= 3; i++) {
                    if (!GeneralUtil.isInt(split[i])) {
                        context.setSessionData("fail_int", true);
                        return false;
                    }
                }
                this.location = new Location(Bukkit.getWorld(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]));
            } else {
                context.setSessionData("fail_world", true);
                return false;
            }
        } else {
            context.setSessionData("fail_format", true);
            return false;
        }
    } else {
        context.setSessionData("fail_format", true);
        return false;
    }
    return true;
}
 
Example #21
Source File: LocationFunction.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getFailedText(ConversationContext context, String invalidInput) {
    Object failInt = context.getSessionData("fail_int");
    Object failFormat = context.getSessionData("fail_format");
    Object failWorld = context.getSessionData("fail_world");
    if (failInt != null && ((Boolean) failInt)) {
        return Lang.PROMPT_INPUT_FAIL_INT.getValue();
    } else if (failFormat != null && (Boolean) failFormat) {
        return Lang.PROMPT_INPUT_FAIL_FORMAT.getValue();
    } else if (failWorld != null && (Boolean) failWorld) {
        return Lang.PROMPT_INPUT_FAIL_WORLD.getValue("world", invalidInput.split("\\s")[0]);
    }
    return "";
}
 
Example #22
Source File: BuilderInputPrompt.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean isInputValid(ConversationContext conversationContext, String s) {
    if (s.equalsIgnoreCase("DONE")) {
        return true;
    }
    return this.currentBuilder != null || s.equalsIgnoreCase("TEXT") || s.equalsIgnoreCase("IMAGE");
}
 
Example #23
Source File: SimpleInputPrompt.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Prompt acceptValidatedInput(ConversationContext context, String input) {
    Prompt next = this.function.function(context, input);
    if (next != null) {
        return next;
    }
    return this.successPrompt != null ? this.successPrompt : new SimpleInputSuccessPrompt(this.function.getSuccessMessage(context, input));
}
 
Example #24
Source File: AnimationBuilderInputSuccessPrompt.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getPromptText(ConversationContext conversationContext) {
    ArrayList<Frame> frames = new ArrayList<>();
    for (Frame f : this.frames) {
        frames.add(new Frame(delay, f.getLines()));
    }
    // If we're here it should be a player
    AnimatedHologram h = new AnimatedHologramFactory(HoloAPI.getCore()).withText(new AnimatedTextGenerator(frames.toArray(new Frame[frames.size()]))).withLocation(((Player) conversationContext.getForWhom()).getLocation()).build();
    return Lang.HOLOGRAM_CREATED.getValue("id", h.getSaveId());
}
 
Example #25
Source File: SingleQuestionPrompt.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@Override
protected Prompt acceptValidatedInput(ConversationContext context, String input)
{
	if(input.equalsIgnoreCase("quit") || input.equalsIgnoreCase("stop") || input.equalsIgnoreCase("end"))
		return Prompt.END_OF_CONVERSATION;
	
	if(listener.onAnswer(input))
		return Prompt.END_OF_CONVERSATION;
	else 
		return this;
}
 
Example #26
Source File: UHPrompts.java    From KTP with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getPromptText(ConversationContext context) {
	return ChatColor.GRAY+"Veuillez entrer un nom pour la team. /cancel pour annuler.";
}
 
Example #27
Source File: AnimationBuilderInputSuccessPrompt.java    From HoloAPI with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Prompt getNextPrompt(ConversationContext conversationContext) {
    return END_OF_CONVERSATION;
}
 
Example #28
Source File: AnimationBuilderInputPrompt.java    From HoloAPI with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected String getFailedValidationText(ConversationContext context, String invalidInput) {
    return Lang.PROMPT_INPUT_INVALID.getValue();
}
 
Example #29
Source File: NameConversationPrefix.java    From EchoPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getPrefix(ConversationContext conversationContext) {
    return EchoPet.getPrefix();
}
 
Example #30
Source File: SimpleInputReturningFunction.java    From HoloAPI with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Prompt function(ConversationContext context, String input) {
    this.input = input;
    return this.onFunctionRequest(context, input);
}