Make quotes be activated with a shift click

This commit is contained in:
Graphica 2017-05-27 17:30:56 -05:00 committed by cnr
parent a61c4cd816
commit 6b2a99a881

View File

@ -55,24 +55,33 @@ public class MorphBobRoss extends MorphGadget
/** The # of minutes for which paint blocks exist */
private static final int PAINT_MINUTES = 1;
/** Likelihood that a quote will be shown above a player every certain number of seconds */
private static final double QUOTE_CHANCE = 0.03;
/** Height above a player's location at which quotes are to be displayed */
private static final double QUOTE_HEIGHT = 2.12;
private static final double QUOTE_HEIGHT = 2.25;
/** The number of seconds for which quotes are displayed */
private static final int QUOTE_PERSISTENCE = 9;
private static final int QUOTE_PERSISTENCE = 10;
/** Cooldown key for changing paint colors */
private static final String COLOR_KEY = "Change Paint Color";
/** Cooldown time for changing paint colors (milliseconds) */
private static final long COLOR_COOLDOWN = 220;
/** Cooldown key for cleaning and putting paint on the brush */
private static final String PAINT_KEY = "Beat The Devil Out Of It";
/** Cooldown time for cleaning and putting paint on the brush (milliseconds) */
private static final long PAINT_COOLDOWN = 700;
/** Cooldown key for displaying a Bob Ross quote above head */
private static final String QUOTE_KEY = "Bob Ross Quote";
/** Cooldown time for displaying a Bob Ross quote (milliseconds) */
private static final long QUOTE_COOLDOWN = 10100;
/** Distance (in blocks) from which the quotes can be seen */
private static final int VIEW_DISTANCE = 14;
/** Quote attribution for bob */
private static final String ATTRIBUTION = C.cGray + "- " + C.cYellow + "Bob Ross";
@ -171,9 +180,6 @@ public class MorphBobRoss extends MorphGadget
/** Blocks that have been painted */
private final List<PaintedBlock> _paintBlocks = new ArrayList<>();
/** Hologram quotes that are currently above players' heads */
private final Map<UUID, Collection<Hologram>> _spokenQuotes = new HashMap<>();
private final HologramManager _holograms;
public MorphBobRoss(GadgetManager manager, HologramManager holograms)
@ -188,7 +194,7 @@ public class MorphBobRoss extends MorphGadget
"",
C.cGreen + "Left click " + C.cWhite + "on your " + C.cYellow + "Paint " + C.cWhite + "to change paintbrush colors.",
"",
C.cWhite + "Hold " + C.cGreen + " crouch " + C.cWhite + "to say a Bob Ross quote."
C.cGreen + "Crouch " + C.cWhite + "to say a Bob Ross quote."
}, LineFormat.LORE), -14, Material.PAINTING, (byte) 0, YearMonth.of(2017, Month.JUNE));
_holograms = holograms;
@ -248,14 +254,14 @@ public class MorphBobRoss extends MorphGadget
if (UtilEvent.isAction(event, UtilEvent.ActionType.L))
{
if (Recharge.Instance.use(event.getPlayer(), COLOR_KEY, 220, false, false))
if (Recharge.Instance.use(event.getPlayer(), COLOR_KEY, COLOR_COOLDOWN, false, false))
{
changePaintColor(event.getPlayer());
}
}
else if (UtilEvent.isAction(event, UtilEvent.ActionType.R))
{
if (Recharge.Instance.use(event.getPlayer(), PAINT_KEY, 1000, false, false))
if (Recharge.Instance.use(event.getPlayer(), PAINT_KEY, PAINT_COOLDOWN, false, false))
{
togglePainting(event.getPlayer());
}
@ -263,7 +269,7 @@ public class MorphBobRoss extends MorphGadget
}
/**
* Randomly display a Bob Ross quote above morphed players' heads.
* Display a Bob Ross quote above players' heads when they sneak.
* Destroy old paint after a certain amount of time has elapsed.
*/
@EventHandler
@ -288,38 +294,41 @@ public class MorphBobRoss extends MorphGadget
limit++;
}
}
else if (event.getType() == UpdateType.SEC_30) // do random quote displaying
else if (event.getType() == UpdateType.TICK) // do random quote displaying
{
for (Player player : getActive())
{
if (Math.random() >= QUOTE_CHANCE)
if (player.isSneaking())
{
// select quote
String[] quote = QUOTES[ThreadLocalRandom.current().nextInt(0, QUOTES.length)];
final Collection<Hologram> holograms = new ArrayList<>();
// add attribution
holograms.add(new Hologram(_holograms, player.getLocation().add(0, QUOTE_HEIGHT, 0), ATTRIBUTION));
// display the quote
double offset = 0.3;
for (int i = quote.length - 1; i >= 0; --i)
if (Recharge.Instance.use(player, QUOTE_KEY, QUOTE_COOLDOWN, false, false))
{
holograms.add(new Hologram(_holograms, player.getLocation().add(0, QUOTE_HEIGHT + offset, 0),
C.cWhite + quote[i]));
offset += 0.25;
}
// select quote
String[] quote = QUOTES[ThreadLocalRandom.current().nextInt(0, QUOTES.length)];
final Collection<Hologram> holograms = new ArrayList<>();
for (Hologram hologram : holograms)
{
hologram.setViewDistance(18);
hologram.setFollowEntity(player);
hologram.start();
}
// add attribution
holograms.add(new Hologram(_holograms, player.getLocation().add(0, QUOTE_HEIGHT, 0), ATTRIBUTION));
// remove hologram a certain number of seconds later
Bukkit.getServer().getScheduler().runTaskLater(UtilServer.getPlugin(), () ->
holograms.forEach(Hologram::stop), QUOTE_PERSISTENCE * 20);
// display the quote
double offset = 0.3;
for (int i = quote.length - 1; i >= 0; --i)
{
holograms.add(new Hologram(_holograms, player.getLocation().add(0, QUOTE_HEIGHT + offset, 0),
C.cWhite + quote[i]));
offset += 0.25;
}
for (Hologram hologram : holograms)
{
hologram.setViewDistance(VIEW_DISTANCE);
hologram.setFollowEntity(player);
hologram.start();
}
// remove hologram a certain number of seconds later
Bukkit.getServer().getScheduler().runTaskLater(UtilServer.getPlugin(), () ->
holograms.forEach(Hologram::stop), QUOTE_PERSISTENCE * 20);
}
}
}
}