Blacksmith/src/main/java/net/apunch/blacksmith/ReforgeSession.java

48 lines
1.4 KiB
Java
Raw Normal View History

2012-02-20 19:43:59 -06:00
package net.apunch.blacksmith;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
2012-02-22 19:23:16 -06:00
public class ReforgeSession {
2012-02-25 00:52:17 -06:00
private final BlacksmithPlugin plugin;
2012-02-20 19:43:59 -06:00
private final Player player;
private final ItemStack reforge;
private final NPC npc;
private int taskId;
2012-02-22 19:23:16 -06:00
public ReforgeSession(Player player, NPC npc) {
2012-02-20 19:43:59 -06:00
this.player = player;
reforge = player.getItemInHand();
this.npc = npc;
2012-02-25 00:52:17 -06:00
plugin = (BlacksmithPlugin) player.getServer().getPluginManager().getPlugin("Blacksmith");
2012-02-20 19:43:59 -06:00
}
// Return is the session should end
public boolean handleClick() {
// Prevent player from switching items during session
if (!reforge.equals(player.getItemInHand())) {
npc.chat(player, "<c>That's not the item you wanted to reforge before!");
return true;
}
2012-02-21 19:23:01 -06:00
if (!plugin.doesPlayerHaveEnough(player)) {
2012-02-25 00:52:17 -06:00
npc.chat(player, ((Blacksmith) npc.getCharacter()).getInsufficientFundsMessage());
2012-02-20 19:43:59 -06:00
return true;
}
return false;
}
public boolean isRunning() {
return plugin.getServer().getScheduler().isQueued(taskId);
}
public boolean isInSession(Player other) {
return player.getName().equals(other.getName());
}
public void setTask(int taskId) {
this.taskId = taskId;
}
}