use of com.oheers.fish.api.EMFRewardEvent in project EvenMoreFish by Oheers.
the class Reward method run.
public void run(OfflinePlayer player, Location hookLocation) {
Player p = null;
if (player.isOnline())
p = (Player) player;
switch(type) {
case COMMAND:
String inputCommand = this.action.replace("{player}", player.getName());
inputCommand = PlaceholderAPI.setPlaceholders(p, inputCommand);
if (hookLocation != null) {
inputCommand = inputCommand.replace("{x}", Double.toString(hookLocation.getX())).replace("{y}", Double.toString(hookLocation.getY())).replace("{z}", Double.toString(hookLocation.getZ())).replace("{world}", hookLocation.getWorld().getName());
}
// running the command
String finalCommand = inputCommand;
Bukkit.getScheduler().callSyncMethod(plugin, () -> Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), finalCommand));
break;
case EFFECT:
if (p != null) {
String[] parsedEffect = action.split(",");
// Adds a potion effect in accordance to the config.yml "EFFECT:" value
p.addPotionEffect(new PotionEffect(Objects.requireNonNull(PotionEffectType.getByName(parsedEffect[0])), Integer.parseInt(parsedEffect[2]) * 20, Integer.parseInt(parsedEffect[1])));
}
break;
case HEALTH:
if (p != null) {
if (!(p.getHealth() > 20)) {
double newhealth = p.getHealth() + Integer.parseInt(action);
// checking the new health won't go above 20
if (newhealth > 20) {
p.setHealth(20);
} else {
p.setHealth(newhealth);
}
}
}
break;
case HUNGER:
if (p != null) {
p.setFoodLevel(p.getFoodLevel() + Integer.parseInt(action));
}
break;
case ITEM:
if (p != null) {
String[] parsedItem = action.split(",");
FishUtils.giveItems(Collections.singletonList(new ItemStack(Material.getMaterial(parsedItem[0]), Integer.parseInt(parsedItem[1]))), p);
}
break;
case MESSAGE:
if (p != null) {
p.sendMessage(new OldMessage().setMSG(action).setReceiver(p).toString());
}
break;
case MONEY:
EvenMoreFish.econ.depositPlayer(player, Integer.parseInt(action));
break;
case OTHER:
PluginManager pM = Bukkit.getPluginManager();
EMFRewardEvent event = new EMFRewardEvent(this, p, fishVelocity, hookLocation);
pM.callEvent(event);
break;
default:
EvenMoreFish.logger.log(Level.SEVERE, "Error in loading a reward.");
}
}
Aggregations