Merge branch 'Myst_TRICKORTREAT'

This commit is contained in:
Cheese 2015-10-31 14:27:06 +11:00
commit a92a52f009
5 changed files with 524 additions and 5 deletions

View File

@ -29,7 +29,7 @@ public class MobCommand extends MultiCommandBase<Creature>
{
public MobCommand(Creature plugin)
{
super(plugin, Rank.ADMIN, "mob");
super(plugin, Rank.JNR_DEV, "mob");
AddCommand(new KillCommand(Plugin));
}

View File

@ -5,10 +5,6 @@ import java.sql.SQLException;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.Callback;
@ -16,6 +12,10 @@ import mineplex.core.common.util.NautHashMap;
import mineplex.core.task.repository.TaskRepository;
import mineplex.playerCache.PlayerCache;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class TaskManager extends MiniDbClientPlugin<TaskClient>
{
private static Object _taskLock = new Object();
@ -153,4 +153,16 @@ public class TaskManager extends MiniDbClientPlugin<TaskClient>
return _tasks.get(taskName);
}
}
public void createNewTask(final String name)
{
synchronized (_taskLock)
{
if (_tasks.containsKey(name))
return;
}
_repository.addTask(name);
updateTasks();
}
}

View File

@ -66,6 +66,7 @@ import mineplex.hub.modules.NewsManager;
import mineplex.hub.modules.ParkourManager;
import mineplex.hub.modules.SoccerManager;
import mineplex.hub.modules.TextManager;
import mineplex.hub.modules.TrickOrTreatManager;
import mineplex.hub.modules.WorldManager;
import mineplex.hub.profile.gui.GUIProfile;
import mineplex.hub.tutorial.TutorialManager;
@ -142,6 +143,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
private PacketHandler _packetHandler;
private PersonalServerManager _personalServerManager;
// private HalloweenSpookinessManager _halloweenManager;
// private TrickOrTreatManager _trickOrTreatManager;
private Location _spawn;
private int _scoreboardTick = 0;
@ -197,6 +199,8 @@ public class HubManager extends MiniClientPlugin<HubClient>
new SoccerManager(this, _gadgetManager);
new KothManager(this, _gadgetManager);
new TrickOrTreatManager(_plugin, this, taskManager, donationManager, clientManager);
_petManager = petManager;
_partyManager = partyManager;

View File

@ -0,0 +1,268 @@
package mineplex.hub.modules;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Random;
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.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.donation.DonationManager;
import mineplex.core.recharge.Recharge;
import mineplex.core.task.TaskManager;
import mineplex.hub.HubManager;
import mineplex.hub.HubType;
import mineplex.hub.modules.trickortreat.Trick;
import org.bukkit.ChatColor;
import org.bukkit.Instrument;
import org.bukkit.Note;
import org.bukkit.Note.Tone;
import org.bukkit.Sound;
import org.bukkit.entity.LivingEntity;
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.plugin.java.JavaPlugin;
public class TrickOrTreatManager extends MiniPlugin
{
/**
*
* @author Mysticate
*
*/
private HubManager _manager;
private TaskManager _taskManager;
private DonationManager _donationManager;
private CoreClientManager _coreClientManager;
private Calendar _cal = Calendar.getInstance();
private String _identifier = "villager";
private HashSet<String> _interacting = new HashSet<String>();
// private String[] _nextYear = new String[]
// {
// "Nosy kids...",
// "I'm out of candy!",
// "Come back next year.",
// "No double dipping!",
// "I've seen that costume before...",
// "You already have enough candy!",
// "Once is enough.",
// "Isn't it past your bedtime?",
// "I already gave you my candy, what more do you want!",
// "You again...",
// "I said no more!",
// "No taking the whole bowl.",
// "I have my eye on you...",
// "You know what happens to children who want more candy...",
// "This was a great year, wasn't it?",
// "Aww, did you come back just to talk to me?",
// "*heavy staring*",
// "Run along, now!",
// "The real horror will be your dentist's face...",
// "I've heard good things about the house down the road.",
// "I started out with 700 pieces!",
// "I might call it a night soon.",
// "Meow",
// "*heavy ninjaing*",
// "*heavy pandaing*",
// "Sure is a mystical night, isn't it?",
// "Do you want to hear my song? I wrote it myself!",
// };
public TrickOrTreatManager(JavaPlugin plugin, HubManager manager, TaskManager taskManager, DonationManager donationManager, CoreClientManager coreClientManager)
{
super("Trick or Treat", plugin);
_manager = manager;
_taskManager = taskManager;
_donationManager = donationManager;
_coreClientManager = coreClientManager;
Trick.init(getPlugin());
}
@EventHandler
public void trickCommand(PlayerCommandPreprocessEvent event)
{
if (_manager.Type != HubType.Halloween)
return;
if (!event.getMessage().toLowerCase().startsWith("/trick"))
return;
if (!_coreClientManager.hasRank(event.getPlayer(), Rank.JNR_DEV))
return;
event.setCancelled(true);
new Trick(event.getPlayer(), "Command");
}
@EventHandler(priority = EventPriority.LOW)
public void onInteract(final PlayerInteractEntityEvent event)
{
if (_manager.Type != HubType.Halloween)
return;
if (!(event.getRightClicked() instanceof LivingEntity))
return;
LivingEntity en = (LivingEntity) event.getRightClicked();
if (en.getCustomName() == null)
return;
if (!new String(ChatColor.stripColor(en.getCustomName())).toLowerCase().trim().startsWith(_identifier))
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;
_interacting.add(event.getPlayer().getName());
final String task = "ToT " + _cal.get(Calendar.YEAR) + " " + villagerName;
runAsync(new Runnable()
{
@Override
public void run()
{
// Create and store a new task if it doesn't exist.
if (_taskManager.getTaskId(task) == null)
_taskManager.createNewTask(task);
if (!_taskManager.hasCompletedTask(event.getPlayer(), task))
{
final boolean trick = UtilMath.r(10) > 4;
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() * 700));
_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() * 900));
_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
{
try { Thread.sleep(500); } catch (Exception ex) { } //XXX
UtilPlayer.message(event.getPlayer(), C.cGoldB + villagerName + ": " + C.cYellowB + "Back for seconds, are we? Looks like someone needs another trick...");
try { Thread.sleep(750); } catch (Exception ex) { } //XXX
runSync(new Runnable()
{
@Override
public void run()
{
new Trick(event.getPlayer(), villagerName);
}
});
}
_interacting.remove(event.getPlayer().getName());
}
});
}
}

View File

@ -0,0 +1,235 @@
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
{
/**
*
* @author Mysticate
*
*/
private static interface ITrick
{
public String onTrick(Player player);
}
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));
}
}