Refactored TrickOrTreat Stuff.

This commit is contained in:
Jonathan Williams 2015-10-31 14:45:42 -05:00
parent 92a2c2ebaa
commit 073321fb14
9 changed files with 482 additions and 362 deletions

View File

@ -108,6 +108,11 @@ public abstract class MiniPlugin implements Listener
_plugin.getServer().getScheduler().runTaskAsynchronously(_plugin, runnable);
}
public void runAsync(Runnable runnable, long time)
{
_plugin.getServer().getScheduler().runTaskLaterAsynchronously(_plugin, runnable, time);
}
public void runSync(Runnable runnable)
{
_plugin.getServer().getScheduler().runTask(_plugin, runnable);

View File

@ -2,14 +2,13 @@ package mineplex.hub.modules;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Random;
import java.util.Iterator;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
@ -20,31 +19,26 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.HubManager;
import mineplex.hub.HubType;
import mineplex.hub.modules.trickortreat.Blindness;
import mineplex.hub.modules.trickortreat.Nausea;
import mineplex.hub.modules.trickortreat.RandomTeleport;
import mineplex.hub.modules.trickortreat.ShockingStrikes;
import mineplex.hub.modules.trickortreat.Trick;
import mineplex.hub.modules.trickortreat.TrickDialogue;
import org.bukkit.ChatColor;
import org.bukkit.Instrument;
import org.bukkit.Material;
import org.bukkit.Note;
import org.bukkit.Note.Tone;
import org.bukkit.Sound;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
public class TrickOrTreatManager extends MiniPlugin
{
/**
*
* @author Mysticate
*
*/
private HubManager _manager;
private TaskManager _taskManager;
private DonationManager _donationManager;
@ -56,6 +50,10 @@ public class TrickOrTreatManager extends MiniPlugin
private HashSet<String> _interacting = new HashSet<String>();
private HashSet<TrickDialogue> _tricking = new HashSet<TrickDialogue>();
private HashSet<Trick> _tricks = new HashSet<Trick>();
private NautHashMap<String, Trick> _lastTricks = new NautHashMap<String, Trick>();
private String[] _nextYear = new String[]
{
"Nosy kids...",
@ -94,23 +92,36 @@ public class TrickOrTreatManager extends MiniPlugin
_donationManager = donationManager;
_coreClientManager = coreClientManager;
Trick.init(getPlugin());
_tricks.add(new Blindness(plugin));
_tricks.add(new Nausea(plugin));
_tricks.add(new RandomTeleport(plugin));
_tricks.add(new ShockingStrikes(plugin));
}
@EventHandler
public void trickCommand(PlayerCommandPreprocessEvent event)
private Trick nextTrick(String name)
{
if (_manager.Type != HubType.Halloween)
return;
if (!_lastTricks.containsKey(name))
return UtilAlg.Random(_tricks);
if (!event.getMessage().toLowerCase().startsWith("/trick"))
return;
Trick last = _lastTricks.remove(name);
if (!_coreClientManager.hasRank(event.getPlayer(), Rank.JNR_DEV))
return;
//Attempt 10 times
for (int i = 0 ; i < 10 ; i++)
{
Trick trick = UtilAlg.Random(_tricks);
if (trick == last)
continue;
event.setCancelled(true);
new Trick(event.getPlayer(), "Command");
return trick;
}
//Give up
return UtilAlg.Random(_tricks);
}
public void trick(Player player, String villager)
{
UtilPlayer.message(player, C.cGoldB + villager + ": " + C.cYellowB + nextTrick(player.getName()).onTrick(player));
}
@EventHandler(priority = EventPriority.LOW)
@ -124,19 +135,16 @@ public class TrickOrTreatManager extends MiniPlugin
LivingEntity en = (LivingEntity) event.getRightClicked();
if (en.getCustomName() == null)
if (en.getCustomName() == null || !new String(ChatColor.stripColor(en.getCustomName())).toLowerCase().trim().startsWith(_identifier))
return;
if (!new String(ChatColor.stripColor(en.getCustomName())).toLowerCase().trim().startsWith(_identifier))
if (_interacting.contains(event.getPlayer().getName()))
return;
event.setCancelled(true);
final String villagerName = ChatColor.stripColor(en.getCustomName()).substring(_identifier.length()).trim();
if (_interacting.contains(event.getPlayer().getName()))
return;
if (!Recharge.Instance.use(event.getPlayer(), "ToT with " + villagerName, 2000, false, false))
return;
@ -144,113 +152,37 @@ public class TrickOrTreatManager extends MiniPlugin
final String task = "ToT " + _cal.get(Calendar.YEAR) + " " + villagerName;
runAsync(new Runnable()
{
@Override
public void run()
{
if (!_taskManager.hasCompletedTask(event.getPlayer(), task))
{
final boolean trick = UtilMath.r(10) > 5;
UtilPlayer.message(event.getPlayer(), C.cDGreenB + "You: " + C.cGreenB + "Trick or Treat!");
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.NOTE_PIANO, 1F, 1F);
try { Thread.sleep(250); } catch (Exception ex) { } //XXX
event.getPlayer().playNote(event.getPlayer().getLocation(), Instrument.PIANO, Note.natural(1, Tone.D));
event.getPlayer().playNote(event.getPlayer().getLocation(), Instrument.PIANO, Note.natural(1, Tone.A));
try { Thread.sleep(1000); } catch (Exception ex) { } //XXX
if (trick) //Trick
{
UtilPlayer.message(event.getPlayer(), C.cGoldB + villagerName + ": " + C.cYellowB + "I choose... TRICK!");
try { Thread.sleep(750); } catch (Exception ex) { } //XXX
_taskManager.completedTask(null, event.getPlayer(), task);
runSync(new Runnable()
{
@Override
public void run()
{
new Trick(event.getPlayer(), villagerName);
}
});
}
else
{
UtilPlayer.message(event.getPlayer(), C.cGoldB + villagerName + ": " + C.cYellowB + "I choose... TREAT!");
try { Thread.sleep(750); } catch (Exception ex) { } //XXX
UtilPlayer.message(event.getPlayer(), C.cGoldB + villagerName + ": " + C.cYellowB + "Have a Happy Halloween!");
_taskManager.completedTask(new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
if (!data)
return;
if (UtilMath.r(10) > 5) //Coins
{
final int amount = Math.max(new Random().nextInt(100) + 100, (int) Math.floor(new Random().nextDouble() * 600));
_donationManager.RewardCoins(new Callback<Boolean>()
{
public void run(Boolean completed)
{
if (completed)
{
UtilPlayer.message(event.getPlayer(), F.main("Treat", "You received " + F.elem(C.cYellow + amount + " Coins") + " from " + F.name(villagerName) + "."));
//Sound
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
}
else
{
UtilPlayer.message(event.getPlayer(), F.main("Treat", "There was an error giving " + F.elem(C.cYellow + amount + " Coins") + " to you. Please visit that villager again.") + ".");
}
}
}, "Treat " + villagerName, event.getPlayer().getName(), _coreClientManager.getAccountId(event.getPlayer()), amount);
}
else //Gems
{
final int amount = Math.max(new Random().nextInt(100) + 100, (int) Math.floor(new Random().nextDouble() * 600));
_donationManager.RewardGems(new Callback<Boolean>()
{
public void run(Boolean completed)
{
if (completed)
{
UtilPlayer.message(event.getPlayer(), F.main("Treat", "You received " + F.elem(C.cGreen + amount + " Gems") + " from " + F.name(villagerName) + "."));
//Sound
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
}
else
{
UtilPlayer.message(event.getPlayer(), F.main("Treat", "There was an error giving " + F.elem(C.cGreen + amount + " Gems") + " to you. Please visit that villager again.") + ".");
}
}
}, "Treat " + villagerName, event.getPlayer().getName(), event.getPlayer().getUniqueId(), amount);
}
}
}, event.getPlayer(), task);
}
}
else
if (_taskManager.hasCompletedTask(event.getPlayer(), task))
{
UtilPlayer.message(event.getPlayer(), C.cGoldB + villagerName + ": " + C.cYellowB + UtilMath.randomElement(_nextYear));
_interacting.remove(event.getPlayer().getName());
return;
}
_interacting.remove(event.getPlayer().getName());
UtilPlayer.message(event.getPlayer(), C.cDGreenB + "You: " + C.cGreenB + "Trick or Treat!");
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.NOTE_PIANO, 1F, 1F);
final boolean trick = UtilMath.r(10) > 5;
_tricking.add(new TrickDialogue(this, task, event.getPlayer(), villagerName, trick));
}
@EventHandler
public void updateDialogues(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTER)
return;
for (Iterator<TrickDialogue> dialogueIterator = _tricking.iterator(); dialogueIterator.hasNext();)
{
TrickDialogue dialogue = dialogueIterator.next();
if (dialogue.originalUpdateDialogue())
{
_interacting.remove(dialogue.getPlayer().getName());
dialogueIterator.remove();
}
}
});
}
@EventHandler
@ -291,4 +223,19 @@ public class TrickOrTreatManager extends MiniPlugin
}
}
}
public TaskManager getTaskManager()
{
return _taskManager;
}
public DonationManager getDonationManager()
{
return _donationManager;
}
public CoreClientManager getClientManager()
{
return _coreClientManager;
}
}

View File

@ -0,0 +1,39 @@
package mineplex.hub.modules.trickortreat;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.core.common.util.UtilMath;
public class Blindness extends Trick
{
public Blindness(JavaPlugin plugin)
{
super(plugin);
}
@Override
public String onTrick(Player player)
{
player.playSound(player.getLocation(), Sound.ENDERMAN_SCREAM, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1.2F, 0F);
for (int i = 0 ; i < UtilMath.r(5) ; i++)
player.playSound(player.getLocation(), i % 2 == 0 ? Sound.GHAST_SCREAM : Sound.GHAST_SCREAM2, 1.5F, 0F);
player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_PIG_ANGRY, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.CREEPER_HISS, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_REMEDY, 1.2F, 0F);
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 400, 0));
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 400, 0));
return "See you around...";
}
}

View File

@ -0,0 +1,48 @@
package mineplex.hub.modules.trickortreat;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityLook;
public class HeadSpasms extends Trick
{
public HeadSpasms(JavaPlugin plugin)
{
super(plugin);
}
@Override
public String onTrick(final Player player)
{
for (int i = 0 ; i < UtilMath.r(5) ; i++)
player.playSound(player.getLocation(), i % 2 == 0 ? Sound.GHAST_SCREAM : Sound.GHAST_SCREAM2, 1.5F, 0F);
player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_PIG_ANGRY, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.CREEPER_HISS, 1.2F, 0F);
for (int i = 0 ; i < 5 ; i++)
player.playSound(player.getLocation(), Sound.ENDERMAN_SCREAM, 1.2F, 0F);
for (int i = 0 ; i < 40 ; i++)
{
final int i2 = i;
Bukkit.getScheduler().runTaskLater(Plugin, new Runnable()
{
@Override
public void run()
{
UtilPlayer.sendPacket(player, new PacketPlayOutEntityLook(player.getEntityId(), (byte) player.getLocation().getYaw(), (byte) ((i2 % 2 == 0 ? 1 : -1) * 80), true));
}
}, i);
}
return "What is wrong with your head, dear?";
}
}

View File

@ -0,0 +1,40 @@
package mineplex.hub.modules.trickortreat;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.core.common.util.UtilMath;
public class Nausea extends Trick
{
public Nausea(JavaPlugin plugin)
{
super(plugin);
}
@Override
public String onTrick(Player player)
{
player.playSound(player.getLocation(), Sound.ENDERMAN_SCREAM, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1.2F, 0F);
for (int i = 0 ; i < UtilMath.r(5) ; i++)
player.playSound(player.getLocation(), i % 2 == 0 ? Sound.GHAST_SCREAM : Sound.GHAST_SCREAM2, 1.5F, 0F);
player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_PIG_ANGRY, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.CREEPER_HISS, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.GHAST_MOAN, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_WOODBREAK, 1.2F, 0F);
player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 400, 3));
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 400, 9));
return "Did someone eat too much candy?";
}
}

View File

@ -0,0 +1,34 @@
package mineplex.hub.modules.trickortreat;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.UtilMath;
public class RandomTeleport extends Trick
{
public RandomTeleport(JavaPlugin plugin)
{
super(plugin);
}
@Override
public String onTrick(Player player)
{
player.teleport(player.getWorld().getHighestBlockAt(Math.max(UtilMath.r(100), 25), Math.max(UtilMath.r(100), 25)).getLocation().add(0, UtilMath.r(30), 0).clone().add(.5, 1, .5));
for (int i = 0 ; i < UtilMath.r(5) ; i++)
player.playSound(player.getLocation(), i % 2 == 0 ? Sound.GHAST_SCREAM : Sound.GHAST_SCREAM2, 1.5F, 0F);
player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_PIG_ANGRY, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.CREEPER_HISS, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1.2F, 0F);
return "Goodbye...";
}
}

View File

@ -0,0 +1,53 @@
package mineplex.hub.modules.trickortreat;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import net.minecraft.server.v1_7_R4.EntityLightning;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityStatus;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityWeather;
public class ShockingStrikes extends Trick
{
public ShockingStrikes(JavaPlugin plugin)
{
super(plugin);
}
@Override
public String onTrick(final Player player)
{
for (int i = 0 ; i < UtilMath.r(5) ; i++)
player.playSound(player.getLocation(), i % 2 == 0 ? Sound.GHAST_SCREAM : Sound.GHAST_SCREAM2, 1.5F, 0F);
player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_PIG_ANGRY, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.CREEPER_HISS, 1.2F, 0F);
for (int i = 0 ; i < 5 ; i++)
player.playSound(player.getLocation(), Sound.ENDERMAN_SCREAM, 1.2F, 0F);
UtilPlayer.sendPacket(player, new PacketPlayOutSpawnEntityWeather(new EntityLightning(((CraftWorld) player.getWorld()).getHandle(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), true, false)));
for (int i = 0 ; i < 20 ; i++)
{
Bukkit.getScheduler().runTaskLater(Plugin, new Runnable()
{
@Override
public void run()
{
UtilPlayer.sendPacket(player, new PacketPlayOutEntityStatus(((CraftPlayer) player).getHandle(), (byte) 2));
}
}, 2 * i);
}
return "I hope you're not too shocked...";
}
}

View File

@ -1,235 +1,16 @@
package mineplex.hub.modules.trickortreat;
import java.util.HashSet;
import mineplex.core.common.util.C;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import net.minecraft.server.v1_7_R4.EntityLightning;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityLook;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityStatus;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityWeather;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class Trick
public abstract class Trick
{
/**
*
* @author Mysticate
*
*/
protected JavaPlugin Plugin;
private static interface ITrick
protected Trick(JavaPlugin plugin)
{
public String onTrick(Player player);
Plugin = plugin;
}
private static JavaPlugin _plugin;
private static HashSet<ITrick> _tricks = new HashSet<ITrick>();
private static NautHashMap<String, ITrick> _lastTricks = new NautHashMap<String, ITrick>();
public static void init(JavaPlugin plugin)
{
_plugin = plugin;
}
private static ITrick nextTrick(String name)
{
if (!_lastTricks.containsKey(name))
return UtilAlg.Random(_tricks);
ITrick last = _lastTricks.remove(name);
//Attempt 10 times
for (int i = 0 ; i < 10 ; i++)
{
ITrick trick = UtilAlg.Random(_tricks);
if (trick == last)
continue;
return trick;
}
//Give up
return UtilAlg.Random(_tricks);
}
static
{
_tricks.add(new ITrick() // blindness
{
@Override
public String onTrick(Player player)
{
player.playSound(player.getLocation(), Sound.ENDERMAN_SCREAM, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1.2F, 0F);
for (int i = 0 ; i < UtilMath.r(5) ; i++)
player.playSound(player.getLocation(), i % 2 == 0 ? Sound.GHAST_SCREAM : Sound.GHAST_SCREAM2, 1.5F, 0F);
player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_PIG_ANGRY, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.CREEPER_HISS, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_REMEDY, 1.2F, 0F);
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 400, 0));
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 400, 0));
return "See you around...";
}
});
_tricks.add(new ITrick() // nausea
{
@Override
public String onTrick(Player player)
{
player.playSound(player.getLocation(), Sound.ENDERMAN_SCREAM, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1.2F, 0F);
for (int i = 0 ; i < UtilMath.r(5) ; i++)
player.playSound(player.getLocation(), i % 2 == 0 ? Sound.GHAST_SCREAM : Sound.GHAST_SCREAM2, 1.5F, 0F);
player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_PIG_ANGRY, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.CREEPER_HISS, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.GHAST_MOAN, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_WOODBREAK, 1.2F, 0F);
player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 400, 3));
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 400, 9));
return "Did someone eat too much candy?";
}
});
_tricks.add(new ITrick() // Random teleport
{
@Override
public String onTrick(Player player)
{
player.teleport(player.getWorld().getHighestBlockAt(Math.max(UtilMath.r(100), 25), Math.max(UtilMath.r(100), 25)).getLocation().add(0, UtilMath.r(30), 0).clone().add(.5, 1, .5));
for (int i = 0 ; i < UtilMath.r(5) ; i++)
player.playSound(player.getLocation(), i % 2 == 0 ? Sound.GHAST_SCREAM : Sound.GHAST_SCREAM2, 1.5F, 0F);
player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_PIG_ANGRY, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.CREEPER_HISS, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1.2F, 0F);
return "Goodbye...";
}
});
// _tricks.add(new ITrick() // Kick
// {
// @Override
// public String onTrick(final Player player)
// {
// for (int i = 0 ; i < 10 ; i++)
// player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1.2F, 0F);
//
// Bukkit.getScheduler().runTaskLater(_plugin, new Runnable()
// {
// @Override
// public void run()
// {
// player.kickPlayer(C.cDRedB + "Trick: " + C.cRedB + "Better luck next time!");
// }
// }, 20);
//
// return "Off in such a hurry?";
// }
// });
_tricks.add(new ITrick() // Shocking strikes
{
@Override
public String onTrick(final Player player)
{
for (int i = 0 ; i < UtilMath.r(5) ; i++)
player.playSound(player.getLocation(), i % 2 == 0 ? Sound.GHAST_SCREAM : Sound.GHAST_SCREAM2, 1.5F, 0F);
player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_PIG_ANGRY, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.CREEPER_HISS, 1.2F, 0F);
for (int i = 0 ; i < 5 ; i++)
player.playSound(player.getLocation(), Sound.ENDERMAN_SCREAM, 1.2F, 0F);
UtilPlayer.sendPacket(player, new PacketPlayOutSpawnEntityWeather(new EntityLightning(((CraftWorld) player.getWorld()).getHandle(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), true, false)));
for (int i = 0 ; i < 20 ; i++)
{
Bukkit.getScheduler().runTaskLater(_plugin, new Runnable()
{
@Override
public void run()
{
UtilPlayer.sendPacket(player, new PacketPlayOutEntityStatus(((CraftPlayer) player).getHandle(), (byte) 2));
}
}, 2 * i);
}
return "I hope you're not too shocked...";
}
});
_tricks.add(new ITrick() // Creepy head spazmes
{
@Override
public String onTrick(final Player player)
{
for (int i = 0 ; i < UtilMath.r(5) ; i++)
player.playSound(player.getLocation(), i % 2 == 0 ? Sound.GHAST_SCREAM : Sound.GHAST_SCREAM2, 1.5F, 0F);
player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.ZOMBIE_PIG_ANGRY, 1.2F, 0F);
player.playSound(player.getLocation(), Sound.CREEPER_HISS, 1.2F, 0F);
for (int i = 0 ; i < 5 ; i++)
player.playSound(player.getLocation(), Sound.ENDERMAN_SCREAM, 1.2F, 0F);
for (int i = 0 ; i < 40 ; i++)
{
final int i2 = i;
Bukkit.getScheduler().runTaskLater(_plugin, new Runnable()
{
@Override
public void run()
{
UtilPlayer.sendPacket(player, new PacketPlayOutEntityLook(player.getEntityId(), (byte) player.getLocation().getYaw(), (byte) ((i2 % 2 == 0 ? 1 : -1) * 80), true));
}
}, i);
}
return "What is wrong with your head, dear?";
}
});
}
public Trick(Player player, String villager)
{
UtilPlayer.message(player, C.cGoldB + villager + ": " + C.cYellowB + nextTrick(player.getName()).onTrick(player));
}
public abstract String onTrick(Player player);
}

View File

@ -0,0 +1,173 @@
package mineplex.hub.modules.trickortreat;
import java.util.Random;
import org.bukkit.Instrument;
import org.bukkit.Note;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.Note.Tone;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.task.TaskManager;
import mineplex.hub.modules.TrickOrTreatManager;
public class TrickDialogue
{
private TrickOrTreatManager _plugin;
private TaskManager _taskManager;
private String _task;
private Player _player;
private long _time;
private String _villagerName;
private boolean _trick;
private boolean _delayOne;
private boolean _delayTwo;
private boolean _delayThree;
public TrickDialogue(TrickOrTreatManager plugin, String task, Player player, String villagerName, boolean trick)
{
_plugin = plugin;
_taskManager = plugin.getTaskManager();
_task = task;
_player = player;
_villagerName = villagerName;
_time = System.currentTimeMillis();
_trick = trick;
}
public long getTime()
{
return _time;
}
public boolean originalUpdateDialogue()
{
UtilPlayer.message(_player, (_delayOne == true) + " ");
UtilPlayer.message(_player, (_delayTwo == true) + " ");
UtilPlayer.message(_player, (_delayThree == true) + " ");
if (!_delayOne && System.currentTimeMillis() - _time > 250)
{
_delayOne = true;
_player.playNote(_player.getLocation(), Instrument.PIANO, Note.natural(1, Tone.D));
_player.playNote(_player.getLocation(), Instrument.PIANO, Note.natural(1, Tone.A));
_time = System.currentTimeMillis();
}
else if (_delayOne && !_delayTwo && System.currentTimeMillis() - _time > 1000)
{
_delayTwo = true;
if (_trick) //Trick
UtilPlayer.message(_player, C.cGoldB + _villagerName + ": " + C.cYellowB + "I choose... TRICK!");
else
UtilPlayer.message(_player, C.cGoldB + _villagerName + ": " + C.cYellowB + "I choose... TREAT!");
_time = System.currentTimeMillis();
}
else if (_delayTwo && !_delayThree && System.currentTimeMillis() - _time > 750)
{
_delayThree = true;
if (_trick)
{
_plugin.runAsync(new Runnable()
{
public void run()
{
_taskManager.completedTask(null, _player, _task);
_plugin.runSync(new Runnable()
{
@Override
public void run()
{
_plugin.trick(_player, _villagerName);
}
});
}
});
}
else
{
UtilPlayer.message(_player, C.cGoldB + _villagerName + ": " + C.cYellowB + "Have a Happy Halloween!");
_plugin.runAsync(new Runnable()
{
public void run()
{
_taskManager.completedTask(new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
if (!data)
return;
if (UtilMath.r(10) > 5) //Coins
{
final int amount = Math.max(new Random().nextInt(100) + 100, (int) Math.floor(new Random().nextDouble() * 600));
_plugin.getDonationManager().RewardCoins(new Callback<Boolean>()
{
public void run(Boolean completed)
{
if (completed)
{
UtilPlayer.message(_player, F.main("Treat", "You received " + F.elem(C.cYellow + amount + " Coins") + " from " + F.name(_villagerName) + "."));
//Sound
_player.playSound(_player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
}
else
{
UtilPlayer.message(_player, F.main("Treat", "There was an error giving " + F.elem(C.cYellow + amount + " Coins") + " to you. Please visit that villager again.") + ".");
}
}
}, "Treat " + _villagerName, _player.getName(), _plugin.getClientManager().getAccountId(_player), amount);
}
else //Gems
{
final int amount = Math.max(new Random().nextInt(100) + 100, (int) Math.floor(new Random().nextDouble() * 600));
_plugin.getDonationManager().RewardGems(new Callback<Boolean>()
{
public void run(Boolean completed)
{
if (completed)
{
UtilPlayer.message(_player, F.main("Treat", "You received " + F.elem(C.cGreen + amount + " Gems") + " from " + F.name(_villagerName) + "."));
//Sound
_player.playSound(_player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
}
else
{
UtilPlayer.message(_player, F.main("Treat", "There was an error giving " + F.elem(C.cGreen + amount + " Gems") + " to you. Please visit that villager again.") + ".");
}
}
}, "Treat " + _villagerName, _player.getName(), _player.getUniqueId(), amount);
}
}
}, _player, _task);
}
});
}
_time = System.currentTimeMillis();
}
else if (_delayOne && _delayTwo && _delayThree)
return true;
return false;
}
public Player getPlayer()
{
return _player;
}
}