use of com.gamingmesh.jobs.container.JobsPlayer in project Jobs by GamingMesh.
the class JobsPaymentListener method onFurnaceSmelt.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onFurnaceSmelt(FurnaceSmeltEvent event) {
if (!plugin.isEnabled())
return;
Block block = event.getBlock();
if (block == null)
return;
if (!block.hasMetadata(furnaceOwnerMetadata))
return;
List<MetadataValue> data = block.getMetadata(furnaceOwnerMetadata);
if (data.isEmpty())
return;
// only care about first
MetadataValue value = data.get(0);
String playerName = value.asString();
Player player = Bukkit.getServer().getPlayerExact(playerName);
if (player == null || !player.isOnline())
return;
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
return;
double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(player);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
Jobs.action(jPlayer, new ItemActionInfo(event.getResult(), ActionType.SMELT), multiplier);
}
use of com.gamingmesh.jobs.container.JobsPlayer in project Jobs by GamingMesh.
the class JobsPaymentListener method onInventoryCraft.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryCraft(InventoryClickEvent e) {
if (!(e instanceof CraftItemEvent))
return;
CraftItemEvent event = (CraftItemEvent) e;
// make sure plugin is enabled
if (!plugin.isEnabled())
return;
// If event is nothing or place, do nothing
switch(event.getAction()) {
case NOTHING:
case PLACE_ONE:
case PLACE_ALL:
case PLACE_SOME:
return;
default:
break;
}
if (event.getAction() == InventoryAction.NOTHING)
return;
CraftingInventory inv = event.getInventory();
if (!(inv instanceof CraftingInventory) || !event.getSlotType().equals(SlotType.RESULT))
return;
Recipe recipe = event.getRecipe();
if (recipe == null)
return;
if (!(event.getWhoClicked() instanceof Player))
return;
Player player = (Player) event.getWhoClicked();
ItemStack resultStack = recipe.getResult();
if (resultStack == null)
return;
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
return;
// check if in creative
if (player.getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
return;
double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(player);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.CRAFT), multiplier);
}
use of com.gamingmesh.jobs.container.JobsPlayer in project Jobs by GamingMesh.
the class PlayerManager method playerJoin.
/**
* Handles join of new player
* @param playername
*/
public void playerJoin(Player player) {
synchronized (players) {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer == null) {
jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player);
players.put(player.getName().toLowerCase(), jPlayer);
}
jPlayer.onConnect();
jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
}
}
use of com.gamingmesh.jobs.container.JobsPlayer in project Jobs by GamingMesh.
the class PlayerManager method reload.
/**
* Perform reload
*/
public void reload() {
synchronized (players) {
for (JobsPlayer jPlayer : players.values()) {
for (JobProgression progression : jPlayer.getJobProgression()) {
String jobName = progression.getJob().getName();
Job job = Jobs.getJob(jobName);
if (job != null) {
progression.setJob(job);
}
}
if (jPlayer.isOnline()) {
jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
}
}
}
}
use of com.gamingmesh.jobs.container.JobsPlayer in project Jobs by GamingMesh.
the class JobsCommands method grantxp.
@JobCommand
public boolean grantxp(CommandSender sender, String[] args) {
if (args.length < 3) {
sendUsage(sender, "grantxp");
return true;
}
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
Job job = Jobs.getJob(args[1]);
if (job == null) {
sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.job"));
return true;
}
double xpGained;
try {
xpGained = Double.parseDouble(args[2]);
} catch (Exception e) {
sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
return true;
}
if (xpGained <= 0) {
sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
return true;
}
// check if player already has the job
if (jPlayer.isInJob(job)) {
Jobs.getPlayerManager().addExperience(jPlayer, job, xpGained);
Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
if (player != null) {
String message = Language.getMessage("command.grantxp.output.target");
message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
message = message.replace("%xpgained%", Double.valueOf(xpGained).toString());
player.sendMessage(message);
}
sender.sendMessage(Language.getMessage("command.admin.success"));
}
return true;
}
Aggregations