This commit is contained in:
Blackvein 2012-10-30 15:22:39 -07:00
parent 7bce096fc9
commit 088bdf99f1
5 changed files with 398 additions and 323 deletions

View File

@ -24,9 +24,9 @@ public class NpcListener implements Listener {
if (plugin.questNPCs.contains(evt.getNPC())) {
final Player player = evt.getClicker();
final Player player = evt.getClicker();
if(plugin.checkQuester(player.getName()) == false){
if (plugin.checkQuester(player.getName()) == false) {
final Quester quester = plugin.getQuester(player.getName());
if (quester.hasObjective("talkToNPC")) {
@ -85,8 +85,6 @@ public class NpcListener implements Listener {
}
break;
}
@ -96,7 +94,7 @@ public class NpcListener implements Listener {
}
}
}
}

View File

@ -41,53 +41,57 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerInteract(PlayerInteractEvent evt) {
if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if (plugin.checkQuester(evt.getPlayer().getName()) == false) {
final Quester quester = plugin.getQuester(evt.getPlayer().getName());
final Player player = evt.getPlayer();
if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if (quester.hasObjective("useBlock")) {
final Quester quester = plugin.getQuester(evt.getPlayer().getName());
final Player player = evt.getPlayer();
quester.useBlock(evt.getClickedBlock().getType());
if (quester.hasObjective("useBlock")) {
} else {
quester.useBlock(evt.getClickedBlock().getType());
for (final Quest q : plugin.quests) {
} else {
if (q.blockStart != null) {
for (final Quest q : plugin.quests) {
if (q.blockStart.equals(evt.getClickedBlock().getLocation())) {
if (q.blockStart != null) {
if (quester.currentQuest != null) {
if (q.blockStart.equals(evt.getClickedBlock().getLocation())) {
player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest.");
if (quester.currentQuest != null) {
} else {
player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest.");
if (quester.completedQuests.contains(q.name)) {
} else {
if (q.redoDelay < 0 || q.redoDelay > -1 && (quester.getDifference(q)) > 0) {
if (quester.completedQuests.contains(q.name)) {
player.sendMessage(ChatColor.YELLOW + "You may not take " + ChatColor.AQUA + q.name + ChatColor.YELLOW + " again for another " + ChatColor.DARK_PURPLE + Quests.getTime(quester.getDifference(q)) + ChatColor.YELLOW + ".");
return;
if (q.redoDelay < 0 || q.redoDelay > -1 && (quester.getDifference(q)) > 0) {
player.sendMessage(ChatColor.YELLOW + "You may not take " + ChatColor.AQUA + q.name + ChatColor.YELLOW + " again for another " + ChatColor.DARK_PURPLE + Quests.getTime(quester.getDifference(q)) + ChatColor.YELLOW + ".");
return;
}
}
quester.questToTake = q.name;
String s =
ChatColor.GOLD + "- " + ChatColor.DARK_PURPLE + quester.questToTake + ChatColor.GOLD + " -\n"
+ "\n"
+ ChatColor.RESET + plugin.getQuest(quester.questToTake).description + "\n";
player.sendMessage(s);
plugin.conversationFactory.buildConversation((Conversable) player).begin();
}
quester.questToTake = q.name;
String s =
ChatColor.GOLD + "- " + ChatColor.DARK_PURPLE + quester.questToTake + ChatColor.GOLD + " -\n"
+ "\n"
+ ChatColor.RESET + plugin.getQuest(quester.questToTake).description + "\n";
player.sendMessage(s);
plugin.conversationFactory.buildConversation((Conversable) player).begin();
break;
}
break;
}
}
@ -103,10 +107,14 @@ public class PlayerListener implements Listener {
@EventHandler
public void onBlockDamage(BlockDamageEvent evt) {
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (quester.hasObjective("damageBlock")) {
if (plugin.checkQuester(evt.getPlayer().getName()) == false) {
quester.damageBlock(evt.getBlock().getType());
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (quester.hasObjective("damageBlock")) {
quester.damageBlock(evt.getBlock().getType());
}
}
@ -115,7 +123,7 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent evt) {
if (evt.getPlayer().getName().toLowerCase().contains("_computercraft_") == false && evt.getPlayer().getName().toLowerCase().contains("_buildcraft_") == false && evt.getPlayer().getName().toLowerCase().contains("_redpower_") == false && evt.getPlayer().getName().toLowerCase().contains("_buildcraft_") == false && evt.getPlayer().getName().toLowerCase().contains("(buildcraft)") == false) {
if (plugin.checkQuester(evt.getPlayer().getName()) == false) {
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (quester.hasObjective("placeBlock")) {
@ -133,38 +141,42 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent evt) {
boolean canOpen = true;
if (plugin.checkQuester(evt.getPlayer().getName()) == false) {
if (canOpen == true) {
boolean canOpen = true;
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (quester.hasObjective("breakBlock")) {
if (canOpen == true) {
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (quester.hasObjective("breakBlock")) {
if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false && evt.isCancelled() == false) {
quester.breakBlock(evt.getBlock().getType());
}
if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false && evt.isCancelled() == false) {
quester.breakBlock(evt.getBlock().getType());
}
}
if (quester.hasObjective("placeBlock")) {
if (quester.hasObjective("placeBlock")) {
if (quester.blocksPlaced.containsKey(evt.getBlock().getType())) {
if (quester.blocksPlaced.containsKey(evt.getBlock().getType())) {
if (quester.blocksPlaced.get(evt.getBlock().getType()) > 0) {
if (quester.blocksPlaced.get(evt.getBlock().getType()) > 0) {
if (evt.isCancelled() == false) {
quester.blocksPlaced.put(evt.getBlock().getType(), quester.blocksPlaced.get(evt.getBlock().getType()) - 1);
}
if (evt.isCancelled() == false) {
quester.blocksPlaced.put(evt.getBlock().getType(), quester.blocksPlaced.get(evt.getBlock().getType()) - 1);
}
}
}
}
if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS) && quester.hasObjective("cutBlock")) {
if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS) && quester.hasObjective("cutBlock")) {
quester.cutBlock(evt.getBlock().getType());
quester.cutBlock(evt.getBlock().getType());
}
}
@ -175,10 +187,14 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerPickupItem(PlayerPickupItemEvent evt) {
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (quester.hasObjective("collectItem")) {
if (plugin.checkQuester(evt.getPlayer().getName()) == false) {
quester.collectItem(evt.getItem().getItemStack());
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (quester.hasObjective("collectItem")) {
quester.collectItem(evt.getItem().getItemStack());
}
}
@ -187,11 +203,15 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerShearEntity(PlayerShearEntityEvent evt) {
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (evt.getEntity().getType().equals(EntityType.SHEEP) && quester.hasObjective("shearSheep")) {
if (plugin.checkQuester(evt.getPlayer().getName()) == false) {
Sheep sheep = (Sheep) evt.getEntity();
quester.shearSheep(sheep.getColor());
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (evt.getEntity().getType().equals(EntityType.SHEEP) && quester.hasObjective("shearSheep")) {
Sheep sheep = (Sheep) evt.getEntity();
quester.shearSheep(sheep.getColor());
}
}
@ -203,10 +223,14 @@ public class PlayerListener implements Listener {
if (evt.getOwner() instanceof Player) {
Player p = (Player) evt.getOwner();
Quester quester = plugin.getQuester(p.getName());
if (quester.hasObjective("tameMob")) {
if (plugin.checkQuester(p.getName()) == false) {
quester.tameMob(evt.getEntityType());
Quester quester = plugin.getQuester(p.getName());
if (quester.hasObjective("tameMob")) {
quester.tameMob(evt.getEntityType());
}
}
@ -217,12 +241,16 @@ public class PlayerListener implements Listener {
@EventHandler
public void onEnchantItem(EnchantItemEvent evt) {
Quester quester = plugin.getQuester(evt.getEnchanter().getName());
if (quester.hasObjective("enchantItem")) {
if (plugin.checkQuester(evt.getEnchanter().getName()) == false) {
for (Enchantment e : evt.getEnchantsToAdd().keySet()) {
Quester quester = plugin.getQuester(evt.getEnchanter().getName());
if (quester.hasObjective("enchantItem")) {
quester.enchantItem(e, evt.getItem().getType());
for (Enchantment e : evt.getEnchantsToAdd().keySet()) {
quester.enchantItem(e, evt.getItem().getType());
}
}
@ -236,30 +264,38 @@ public class PlayerListener implements Listener {
if (evt.getWhoClicked() instanceof Player) {
Player p = (Player) evt.getWhoClicked();
Quester quester = plugin.getQuester(p.getName());
if (quester.hasObjective("craftItem")) {
if (plugin.checkQuester(p.getName()) == false) {
quester.craftItem(evt.getCurrentItem());
Quester quester = plugin.getQuester(p.getName());
if (quester.hasObjective("craftItem")) {
quester.craftItem(evt.getCurrentItem());
}
}
}
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent evt){
if(evt.getPlayer() instanceof Player){
Quester quester = plugin.getQuester(((Player)evt.getPlayer()).getName());
if(quester.holdingQuestItemFromStorage){
quester.collectItem(evt.getView().getCursor());
public void onInventoryClose(InventoryCloseEvent evt) {
if (evt.getPlayer() instanceof Player) {
if (plugin.checkQuester(evt.getPlayer().getName()) == false) {
Quester quester = plugin.getQuester(((Player) evt.getPlayer()).getName());
if (quester.holdingQuestItemFromStorage) {
quester.collectItem(evt.getView().getCursor());
}
quester.holdingQuestItemFromStorage = false;
}
quester.holdingQuestItemFromStorage = false;
}
}
/*
*
@ -332,174 +368,184 @@ public class PlayerListener implements Listener {
*
*/
@EventHandler (priority = EventPriority.LOWEST)
@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryClick(InventoryClickEvent evt) {
Player player = null;
if(evt.getWhoClicked() instanceof Player)
if (evt.getWhoClicked() instanceof Player) {
player = (Player) evt.getWhoClicked();
if(evt.isShiftClick() == false){
if (player != null && evt.getCursor() != null && evt.getCurrentItem() == null) {
}
Quester quester = plugin.getQuester(evt.getWhoClicked().getName());
if (quester.currentQuest != null) {
if (player != null) {
if (quester.currentQuest.questItems.containsKey(evt.getCursor().getType())) {
if (plugin.checkQuester(player.getName()) == false) {
//Placing Quest item in empty slot
if (evt.isShiftClick() == false) {
String s = Quester.checkPlacement(evt.getInventory(), evt.getRawSlot());
if (s == null) {
//Placing Quest item in an allowed player inventory slot
if (quester.holdingQuestItemFromStorage) {
quester.collectItem(evt.getCursor());
quester.holdingQuestItemFromStorage = false;
}
} else {
player.sendMessage(ChatColor.YELLOW + s);
evt.setCancelled(true);
player.updateInventory();
}
if (evt.getCursor() != null && evt.getCurrentItem() == null) {
}
Quester quester = plugin.getQuester(evt.getWhoClicked().getName());
if (quester.currentQuest != null) {
}
if (quester.currentQuest.questItems.containsKey(evt.getCursor().getType())) {
} else if (player != null && evt.getCursor() != null && evt.getCurrentItem() != null) {
//Placing Quest item in empty slot
Quester quester = plugin.getQuester(evt.getWhoClicked().getName());
if (quester.currentQuest != null) {
if (quester.currentQuest.questItems.containsKey(evt.getCurrentItem().getType()) || quester.currentQuest.questItems.containsKey(evt.getCursor().getType())) {
//Either the cursor item or the slot item (or both) is a Quest item
Material cursor = evt.getCursor().getType();
Material slot = evt.getCurrentItem().getType();
if (cursor == slot && quester.currentQuest.questItems.containsKey(cursor)) {
//Both are the same item, and quest items
String s = Quester.checkPlacement(evt.getInventory(), evt.getRawSlot());
if(s == null){
ItemStack from = evt.getCursor();
ItemStack to = evt.getCurrentItem();
if((from.getAmount() + to.getAmount()) <= from.getMaxStackSize()){
if(quester.holdingQuestItemFromStorage){
quester.collectItem(from);
quester.holdingQuestItemFromStorage = false;
}
}else if((from.getAmount() + to.getAmount()) > from.getMaxStackSize() && to.getAmount() < to.getMaxStackSize()){
if(quester.holdingQuestItemFromStorage){
ItemStack difference = to.clone();
difference.setAmount(difference.getMaxStackSize() - difference.getAmount());
quester.collectItem(difference);
String s = Quester.checkPlacement(evt.getInventory(), evt.getRawSlot());
if (s == null) {
//Placing Quest item in an allowed player inventory slot
if (quester.holdingQuestItemFromStorage) {
quester.collectItem(evt.getCursor());
quester.holdingQuestItemFromStorage = false;
}
} else {
player.sendMessage(ChatColor.YELLOW + s);
evt.setCancelled(true);
player.updateInventory();
}
}else{
player.sendMessage(ChatColor.YELLOW + s);
evt.setCancelled(true);
player.updateInventory();
}
} else if (cursor != slot && quester.currentQuest.questItems.containsKey(cursor)) {
//Cursor is a quest item, item in clicked slot is not
String s = Quester.checkPlacement(evt.getInventory(), evt.getRawSlot());
if (quester.holdingQuestItemFromStorage && s == null) {
quester.collectItem(evt.getCursor());
quester.holdingQuestItemFromStorage = false;
} else if (s != null) {
player.sendMessage(ChatColor.YELLOW + s);
evt.setCancelled(true);
player.updateInventory();
}
} else if (cursor != slot && quester.currentQuest.questItems.containsKey(slot)) {
//Item in clicked slot is a quest item, cursor is not
String s = Quester.checkPlacement(evt.getInventory(), evt.getRawSlot());
if(s != null)
quester.holdingQuestItemFromStorage = true;
} else {
//Both are different quest items
String s = Quester.checkPlacement(evt.getInventory(), evt.getRawSlot());
if (quester.holdingQuestItemFromStorage && s == null) {
quester.collectItem(evt.getCursor());
quester.holdingQuestItemFromStorage = false;
} else if (s != null) {
player.sendMessage(ChatColor.YELLOW + s);
evt.setCancelled(true);
player.updateInventory();
}
}
} else if (evt.getCursor() != null && evt.getCurrentItem() != null) {
Quester quester = plugin.getQuester(evt.getWhoClicked().getName());
if (quester.currentQuest != null) {
if (quester.currentQuest.questItems.containsKey(evt.getCurrentItem().getType()) || quester.currentQuest.questItems.containsKey(evt.getCursor().getType())) {
//Either the cursor item or the slot item (or both) is a Quest item
Material cursor = evt.getCursor().getType();
Material slot = evt.getCurrentItem().getType();
if (cursor == slot && quester.currentQuest.questItems.containsKey(cursor)) {
//Both are the same item, and quest items
String s = Quester.checkPlacement(evt.getInventory(), evt.getRawSlot());
if (s == null) {
ItemStack from = evt.getCursor();
ItemStack to = evt.getCurrentItem();
if ((from.getAmount() + to.getAmount()) <= from.getMaxStackSize()) {
if (quester.holdingQuestItemFromStorage) {
quester.collectItem(from);
quester.holdingQuestItemFromStorage = false;
}
} else if ((from.getAmount() + to.getAmount()) > from.getMaxStackSize() && to.getAmount() < to.getMaxStackSize()) {
if (quester.holdingQuestItemFromStorage) {
ItemStack difference = to.clone();
difference.setAmount(difference.getMaxStackSize() - difference.getAmount());
quester.collectItem(difference);
quester.holdingQuestItemFromStorage = false;
}
}
} else {
player.sendMessage(ChatColor.YELLOW + s);
evt.setCancelled(true);
player.updateInventory();
}
} else if (cursor != slot && quester.currentQuest.questItems.containsKey(cursor)) {
//Cursor is a quest item, item in clicked slot is not
String s = Quester.checkPlacement(evt.getInventory(), evt.getRawSlot());
if (quester.holdingQuestItemFromStorage && s == null) {
quester.collectItem(evt.getCursor());
quester.holdingQuestItemFromStorage = false;
} else if (s != null) {
player.sendMessage(ChatColor.YELLOW + s);
evt.setCancelled(true);
player.updateInventory();
}
} else if (cursor != slot && quester.currentQuest.questItems.containsKey(slot)) {
//Item in clicked slot is a quest item, cursor is not
String s = Quester.checkPlacement(evt.getInventory(), evt.getRawSlot());
if (s != null) {
quester.holdingQuestItemFromStorage = true;
}
} else {
//Both are different quest items
String s = Quester.checkPlacement(evt.getInventory(), evt.getRawSlot());
if (quester.holdingQuestItemFromStorage && s == null) {
quester.collectItem(evt.getCursor());
quester.holdingQuestItemFromStorage = false;
} else if (s != null) {
player.sendMessage(ChatColor.YELLOW + s);
evt.setCancelled(true);
player.updateInventory();
}
}
}
}
}
} else {
if (evt.getCurrentItem() != null) {
Quester quester = plugin.getQuester(evt.getWhoClicked().getName());
Material mat = evt.getCurrentItem().getType();
if (quester.currentQuest != null) {
if (quester.currentQuest.questItems.containsKey(mat)) {
List<Integer> changedSlots = Quester.getChangedSlots(evt.getInventory(), evt.getCurrentItem());
boolean can = true;
for (int i : changedSlots) {
String s = Quester.checkPlacement(evt.getInventory(), i);
if (s != null) {
can = false;
break;
}
}
if (!can) {
evt.setCancelled(true);
player.updateInventory();
} else if (can && Quester.checkPlacement(evt.getInventory(), evt.getRawSlot()) != null) {
ItemStack oldStack = evt.getCurrentItem();
Inventory inv = plugin.getServer().createInventory(null, evt.getInventory().getType());
HashMap<Integer, ItemStack> map = inv.addItem(oldStack);
if (map.isEmpty() == false) {
ItemStack newStack = oldStack.clone();
newStack.setAmount(oldStack.getAmount() - map.get(0).getAmount());
quester.collectItem(newStack);
} else {
quester.collectItem(oldStack);
}
}
}
}
}
}
}
}else{
if(player != null && evt.getCurrentItem() != null){
Quester quester = plugin.getQuester(evt.getWhoClicked().getName());
Material mat = evt.getCurrentItem().getType();
if(quester.currentQuest != null){
if(quester.currentQuest.questItems.containsKey(mat)){
List<Integer> changedSlots = Quester.getChangedSlots(evt.getInventory(), evt.getCurrentItem());
boolean can = true;
for(int i : changedSlots){
String s = Quester.checkPlacement(evt.getInventory(), i);
if(s != null){
can = false;
break;
}
}
if(!can){
evt.setCancelled(true);
player.updateInventory();
}else if(can && Quester.checkPlacement(evt.getInventory(), evt.getRawSlot()) != null){
ItemStack oldStack = evt.getCurrentItem();
Inventory inv = plugin.getServer().createInventory(null, evt.getInventory().getType());
HashMap<Integer, ItemStack> map = inv.addItem(oldStack);
if(map.isEmpty() == false){
ItemStack newStack = oldStack.clone();
newStack.setAmount(oldStack.getAmount() - map.get(0).getAmount());
quester.collectItem(newStack);
}else{
quester.collectItem(oldStack);
}
}
}
}
}
}
}
@ -585,19 +631,23 @@ public class PlayerListener implements Listener {
if (p.getShooter() instanceof Player) {
Player player = (Player) p.getShooter();
boolean okay = true;
if (plugin.checkQuester(player.getName()) == false) {
if (plugin.citizens != null) {
if (plugin.citizens.getNPCRegistry().isNPC(player) || plugin.citizens.getNPCRegistry().isNPC(evt.getEntity())) {
okay = false;
boolean okay = true;
if (plugin.citizens != null) {
if (plugin.citizens.getNPCRegistry().isNPC(player) || plugin.citizens.getNPCRegistry().isNPC(evt.getEntity())) {
okay = false;
}
}
}
if (okay) {
if (okay) {
Quester quester = plugin.getQuester(player.getName());
if (quester.hasObjective("killPlayer")) {
quester.killPlayer(evt.getEntity().getName());
}
Quester quester = plugin.getQuester(player.getName());
if (quester.hasObjective("killPlayer")) {
quester.killPlayer(evt.getEntity().getName());
}
}
@ -607,21 +657,26 @@ public class PlayerListener implements Listener {
} else if (damager instanceof Player) {
Player player = (Player) damager;
boolean okay = true;
if (plugin.citizens != null) {
if (plugin.checkQuester(player.getName()) == false) {
boolean okay = true;
if (plugin.citizens != null) {
if (plugin.citizens.getNPCRegistry().isNPC(player) || plugin.citizens.getNPCRegistry().isNPC(evt.getEntity())) {
okay = false;
}
if (plugin.citizens.getNPCRegistry().isNPC(player) || plugin.citizens.getNPCRegistry().isNPC(evt.getEntity())) {
okay = false;
}
}
if (okay) {
if (okay) {
Quester quester = plugin.getQuester(player.getName());
if (quester.hasObjective("killPlayer")) {
quester.killPlayer(evt.getEntity().getName());
}
Quester quester = plugin.getQuester(player.getName());
if (quester.hasObjective("killPlayer")) {
quester.killPlayer(evt.getEntity().getName());
}
}
@ -637,9 +692,13 @@ public class PlayerListener implements Listener {
public void onPlayerFish(PlayerFishEvent evt) {
Player player = evt.getPlayer();
Quester quester = plugin.getQuester(player.getName());
if (quester.hasObjective("catchFish") && evt.getState().equals(State.CAUGHT_FISH)) {
quester.catchFish();
if(plugin.checkQuester(player.getName()) == false){
Quester quester = plugin.getQuester(player.getName());
if (quester.hasObjective("catchFish") && evt.getState().equals(State.CAUGHT_FISH)) {
quester.catchFish();
}
}
}
@ -647,16 +706,20 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent evt) {
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (quester.currentQuest != null) {
if(plugin.checkQuester(evt.getPlayer().getName()) == false){
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (quester.currentQuest != null) {
if (quester.currentQuest.questItems.containsKey(evt.getItemDrop().getItemStack().getType())) {
if (quester.currentQuest.questItems.containsKey(evt.getItemDrop().getItemStack().getType())) {
evt.getPlayer().sendMessage(ChatColor.YELLOW + "You may not discard Quest items.");
evt.setCancelled(true);
evt.getPlayer().sendMessage(ChatColor.YELLOW + "You may not discard Quest items.");
evt.setCancelled(true);
}
}
}
}
@ -664,65 +727,77 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent evt) {
Quester quester = new Quester(plugin);
quester.name = evt.getPlayer().getName();
if (new File(plugin.getDataFolder(), "data/" + quester.name + ".yml").exists()) {
quester.loadData();
} else {
quester.saveData();
}
plugin.questers.put(evt.getPlayer().getName(), quester);
if(plugin.checkQuester(evt.getPlayer().getName()) == false){
Quester quester = new Quester(plugin);
quester.name = evt.getPlayer().getName();
if (new File(plugin.getDataFolder(), "data/" + quester.name + ".yml").exists()) {
quester.loadData();
} else {
quester.saveData();
}
plugin.questers.put(evt.getPlayer().getName(), quester);
for (String s : quester.completedQuests) {
for (String s : quester.completedQuests) {
for (Quest q : plugin.quests) {
for (Quest q : plugin.quests) {
if (q.name.equalsIgnoreCase(s)) {
if (q.name.equalsIgnoreCase(s)) {
if (quester.completedTimes.containsKey(q.name) == false && q.redoDelay > -1) {
quester.completedTimes.put(q.name, System.currentTimeMillis());
}
if (quester.completedTimes.containsKey(q.name) == false && q.redoDelay > -1) {
quester.completedTimes.put(q.name, System.currentTimeMillis());
}
}
}
quester.checkQuest();
}
quester.checkQuest();
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent evt) {
Quester quester = plugin.getQuester(evt.getPlayer().getName());
quester.saveData();
plugin.questers.remove(quester.name);
if(plugin.checkQuester(evt.getPlayer().getName()) == false){
Quester quester = plugin.getQuester(evt.getPlayer().getName());
quester.saveData();
plugin.questers.remove(quester.name);
}
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent evt) {
boolean isPlayer = true;
if (plugin.getServer().getPluginManager().getPlugin("Citizens") != null) {
if (plugin.citizens.getNPCRegistry().isNPC(evt.getPlayer())) {
isPlayer = false;
}
}
if (isPlayer) {
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (quester.hasObjective("reachLocation")) {
quester.reachLocation(evt.getTo());
if(plugin.checkQuester(evt.getPlayer().getName()) == false){
boolean isPlayer = true;
if (plugin.getServer().getPluginManager().getPlugin("Citizens") != null) {
if (plugin.citizens.getNPCRegistry().isNPC(evt.getPlayer())) {
isPlayer = false;
}
}
if (isPlayer) {
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (quester.hasObjective("reachLocation")) {
quester.reachLocation(evt.getTo());
}
}
}
}

View File

@ -1886,6 +1886,8 @@ public class Quester {
data.set("items-crafted", itemAmounts);
}
if(currentStage.)
} else {
@ -2553,6 +2555,12 @@ public class Quester {
}
}
if(data.contains("stage-delay")){
delayTimeLeft = data.getLong("stage-delay");
}
}
@ -2562,44 +2570,12 @@ public class Quester {
public void startStageTimer(){
if(delayTimeLeft > -1){
delayStartTime = System.currentTimeMillis();
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
@Override
public void run(){
if(delayOver){
currentQuest.nextStage(Quester.this);
}
delayOver = true;
}
}, delayTimeLeft*50);
}else{
delayStartTime = System.currentTimeMillis();
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
@Override
public void run(){
if(delayOver){
currentQuest.nextStage(Quester.this);
}
delayOver = true;
}
}, currentStage.delay);
}
if(delayTimeLeft > -1)
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(this), delayTimeLeft*50);
else
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(this), currentStage.delay);
delayStartTime = System.currentTimeMillis();
}
@ -2610,6 +2586,8 @@ public class Quester {
else
delayTimeLeft = currentStage.delay - (System.currentTimeMillis() - delayStartTime);
delayOver = false;
}
public void checkQuest() {

View File

@ -1272,7 +1272,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
quester = new Quester(this);
quester.name = player;
if (quester.loadData() == false) {
throw new NullPointerException("[Quests] Quester not found for player \"" + player + "\"");
log.severe("[Quests] Quester not found for player \"" + player + "\". Consider adding them to the Quester blacklist.");
} else {
if (debug == true) {
log.log(Level.INFO, "[Quests] Manual data retrieval succeeded for player \"" + player + "\"");

View File

@ -0,0 +1,24 @@
package me.blackvein.quests;
public class StageTimer implements Runnable{
Quester quester;
public StageTimer(Quester q){
quester = q;
}
@Override
public void run(){
if(quester.delayOver){
quester.currentQuest.nextStage(quester);
}
quester.delayOver = true;
}
}