Skip to content

Commit

Permalink
Merge pull request #56 from EriolEandur/master
Browse files Browse the repository at this point in the history
added glowing to job creation conversation
  • Loading branch information
EriolEandur authored Oct 28, 2019
2 parents ce77e31 + d5ad676 commit 59ed9c2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ public Prompt newTeamspeakOrDiscordOrFinishPrompt() {
if (TheGaffer.isDiscordEnabled()) {
return new discordAnnouncePrompt();
}
if (TheGaffer.isGlowing()) {
return new GlowEffectPrompt();
}
return new finishedPrompt();
}

Expand Down Expand Up @@ -244,9 +247,11 @@ protected Prompt acceptValidatedInput(ConversationContext context, boolean input
context.setSessionData("discordSend", input);
if (input) {
return new discordTagPrompt();
} else {
return new finishedPrompt();
}
if (TheGaffer.isGlowing()) {
return new GlowEffectPrompt();
}
return new finishedPrompt();
}

@Override
Expand All @@ -268,6 +273,9 @@ public String getPromptText(ConversationContext context) {
public Prompt acceptInput(ConversationContext context, String input) {
input = input.replace(" ", "");
context.setSessionData("discordTag", input);
if (TheGaffer.isGlowing()) {
return new GlowEffectPrompt();
}
return new finishedPrompt();
}

Expand All @@ -294,9 +302,11 @@ public Prompt acceptInput(ConversationContext context, String input) {
private Prompt newDiscordOrFinishedPrompt() {
if (TheGaffer.isDiscordEnabled()) {
return new discordAnnouncePrompt();
} else {
return new finishedPrompt();
}
if (TheGaffer.isGlowing()) {
return new GlowEffectPrompt();
}
return new finishedPrompt();
}

@Override
Expand Down Expand Up @@ -338,6 +348,21 @@ public String getPromptText(ConversationContext context) {

}

private class GlowEffectPrompt extends BooleanPrompt {

@Override
protected Prompt acceptValidatedInput(ConversationContext context, boolean input) {
context.setSessionData("glowEffect", input);
return new finishedPrompt();
}

@Override
public String getPromptText(ConversationContext context) {
return "Should people in this job get a glow effect? (true or false)";
}

}

private class finishedPrompt extends MessagePrompt {

@Override
Expand All @@ -358,8 +383,16 @@ public String getPromptText(ConversationContext context) {
String[] discordTags = (context.getSessionData("discordTag")!=null?((String) context.getSessionData("discordTag")).split(","):new String[0]);
String description = (String) context.getSessionData("description");
int radius = ((Number) context.getSessionData("jobradius")).intValue();
boolean glowing = false;
Object temp = context.getSessionData("glowEffect");
if(temp!=null) {
glowing = (boolean) temp;
}
Job jerb = new Job(jobname, description, owner, true, warp, warp.getWorld(), Private, radius,
discordSend, discordTags, ts, tsWarp);
if(glowing) {
jerb.setGlowing();
}
if (setKit) {
JobKit kit = new JobKit(((Player) context.getForWhom()).getInventory());
jerb.setKit(kit);
Expand Down
49 changes: 29 additions & 20 deletions src/main/java/com/mcmiddleearth/thegaffer/storage/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public class Job implements Listener {
@Setter
private JobKit kit;

private boolean glowing;

private Team helperTeam;
private String helperTeamName;
private Team workerTeam;
Expand Down Expand Up @@ -165,19 +167,22 @@ public Job(String name, String description, String owner, boolean running, JobWa
this.area = new Polygon(xbounds, zbounds, xbounds.length);
this.bounds = area.getBounds2D();

if(TheGaffer.isGlowing()) {
scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
helperTeamName = name+"Helper";
helperTeam = scoreboard.registerNewTeam(name+"Helper");
helperTeam.setColor(ChatColor.valueOf(TheGaffer.getHelperColor()));
//helperTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
workerTeamName = name+"Worker";
workerTeam = scoreboard.registerNewTeam(name+"Worker");
workerTeam.setColor(ChatColor.valueOf(TheGaffer.getWorkerColor()));
//workerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
}

public void setGlowing() {
scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
helperTeamName = name+"Helper";
helperTeam = scoreboard.registerNewTeam(name+"Helper");
helperTeam.setColor(ChatColor.valueOf(TheGaffer.getHelperColor()));
//helperTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
workerTeamName = name+"Worker";
workerTeam = scoreboard.registerNewTeam(name+"Worker");
workerTeam.setColor(ChatColor.valueOf(TheGaffer.getWorkerColor()));
//workerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);

addHelperTeam(owner);
}
glowing = true;

addHelperTeam(owner);
}

public Job() {
Expand Down Expand Up @@ -559,13 +564,13 @@ public void onLeave(PlayerQuitEvent event) {
public void onJoin(PlayerJoinEvent event) {
if (left.containsKey(event.getPlayer().getUniqueId())) {
left.remove(event.getPlayer().getUniqueId());
if(TheGaffer.isGlowing()) {
if(glowing) {
event.getPlayer().setGlowing(true);
event.getPlayer().setScoreboard(scoreboard);
}
} else if(event.getPlayer().getName().equals(owner)
|| helpers.contains(event.getPlayer().getName())) {
if(TheGaffer.isGlowing()) {
if(glowing) {
event.getPlayer().setGlowing(true);
event.getPlayer().setScoreboard(scoreboard);
}
Expand All @@ -589,7 +594,7 @@ public void jobChat(Player p, String[] chat) {

public void setRunning(boolean running) {
this.running = running;
if(TheGaffer.isGlowing() && !running) {
if(glowing && !running) {
helpers.forEach(helper -> removeHelperTeam(helper));
workers.forEach(worker -> removeWorkerTeam(worker));
removeHelperTeam(owner);
Expand All @@ -599,33 +604,37 @@ public void setRunning(boolean running) {
}

private void addHelperTeam(String playerName) {
if(TheGaffer.isGlowing()) {
if(glowing) {
Logger.getGlobal().info("add helper: "+playerName);
helperTeam.addEntry(playerName);
setGlow(playerName,true);
}
}
private void addWorkerTeam(String playerName) {
if(TheGaffer.isGlowing()) {
if(glowing) {
Logger.getGlobal().info("add worker: "+playerName);
workerTeam.addEntry(playerName);
setGlow(playerName,true);
}
}
private void removeHelperTeam(String playerName) {
if(TheGaffer.isGlowing()) {
if(glowing) {
Logger.getGlobal().info("remove helper: "+playerName);
helperTeam.removeEntry(playerName);
setGlow(playerName,false);
}
}
private void removeWorkerTeam(String playerName) {
if(TheGaffer.isGlowing()) {
if(glowing) {
Logger.getGlobal().info("remove Worker: "+playerName);
workerTeam.removeEntry(playerName);
setGlow(playerName,false);
}
}

private void setGlow(String playerName, boolean flag) {
Player player = Bukkit.getPlayer(playerName);
if(player!=null && TheGaffer.isGlowing()) {
if(player!=null && glowing) {
player.setGlowing(flag);
if(flag) {
player.setScoreboard(scoreboard);
Expand Down

0 comments on commit 59ed9c2

Please sign in to comment.