Makes ActionStartEvent give duration in ticks instead of end time
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
				
			This commit is contained in:
		@@ -7,12 +7,10 @@ package net.knarcraft.blacksmith.event;
 | 
			
		||||
public interface ActionStartEvent extends BlacksmithPluginEvent {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the end time for this action
 | 
			
		||||
     * Gets the amount of ticks this action will take
 | 
			
		||||
     *
 | 
			
		||||
     * <p>The end time is a millisecond time-stamp, basically the same format used by currentTimeMillis();.</p>
 | 
			
		||||
     *
 | 
			
		||||
     * @return <p>The end time</p>
 | 
			
		||||
     * @return <p>The duration in ticks</p>
 | 
			
		||||
     */
 | 
			
		||||
    long getActionEndTime();
 | 
			
		||||
    long getActionDurationTicks();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -11,23 +11,23 @@ import org.jetbrains.annotations.NotNull;
 | 
			
		||||
public class BlacksmithReforgeStartEvent extends AbstractBlacksmithPluginEvent implements ActionStartEvent {
 | 
			
		||||
 | 
			
		||||
    private static final HandlerList handlers = new HandlerList();
 | 
			
		||||
    private final Long reforgeEndTime;
 | 
			
		||||
    private final long durationTicks;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Instantiates a new blacksmith reforge start event
 | 
			
		||||
     *
 | 
			
		||||
     * @param npc            <p>The NPC involved in the event</p>
 | 
			
		||||
     * @param player         <p>The player involved in the event</p>
 | 
			
		||||
     * @param reforgeEndTime <p>The time at which this reforging ends</p>
 | 
			
		||||
     * @param npc           <p>The NPC involved in the event</p>
 | 
			
		||||
     * @param player        <p>The player involved in the event</p>
 | 
			
		||||
     * @param durationTicks <p>The duration of the reforge</p>
 | 
			
		||||
     */
 | 
			
		||||
    public BlacksmithReforgeStartEvent(@NotNull NPC npc, @NotNull Player player, long reforgeEndTime) {
 | 
			
		||||
    public BlacksmithReforgeStartEvent(@NotNull NPC npc, @NotNull Player player, long durationTicks) {
 | 
			
		||||
        super(npc, player);
 | 
			
		||||
        this.reforgeEndTime = reforgeEndTime;
 | 
			
		||||
        this.durationTicks = durationTicks;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public long getActionEndTime() {
 | 
			
		||||
        return reforgeEndTime;
 | 
			
		||||
    public long getActionDurationTicks() {
 | 
			
		||||
        return durationTicks;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -12,23 +12,23 @@ import org.jetbrains.annotations.NotNull;
 | 
			
		||||
public class ScrapperSalvageStartEvent extends AbstractBlacksmithPluginEvent implements ActionStartEvent {
 | 
			
		||||
 | 
			
		||||
    private static final HandlerList handlers = new HandlerList();
 | 
			
		||||
    private final long salvageEndTime;
 | 
			
		||||
    private final long durationTicks;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Instantiates a new scrapper salvage start event
 | 
			
		||||
     *
 | 
			
		||||
     * @param npc            <p>The NPC involved in the event</p>
 | 
			
		||||
     * @param player         <p>The player involved in the event</p>
 | 
			
		||||
     * @param salvageEndTime <p>The time at which this salvaging ends</p>
 | 
			
		||||
     * @param npc           <p>The NPC involved in the event</p>
 | 
			
		||||
     * @param player        <p>The player involved in the event</p>
 | 
			
		||||
     * @param durationTicks <p>The duration of the salvage</p>
 | 
			
		||||
     */
 | 
			
		||||
    public ScrapperSalvageStartEvent(@NotNull NPC npc, @NotNull Player player, long salvageEndTime) {
 | 
			
		||||
    public ScrapperSalvageStartEvent(@NotNull NPC npc, @NotNull Player player, long durationTicks) {
 | 
			
		||||
        super(npc, player);
 | 
			
		||||
        this.salvageEndTime = salvageEndTime;
 | 
			
		||||
        this.durationTicks = durationTicks;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public long getActionEndTime() {
 | 
			
		||||
        return this.salvageEndTime;
 | 
			
		||||
    public long getActionDurationTicks() {
 | 
			
		||||
        return this.durationTicks;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -99,22 +99,15 @@ public abstract class Session implements Runnable {
 | 
			
		||||
        BukkitScheduler scheduler = BlacksmithPlugin.getInstance().getServer().getScheduler();
 | 
			
		||||
        int actionDelay = getActionDelay();
 | 
			
		||||
        this.finishTime = System.currentTimeMillis() + (actionDelay * 1000L);
 | 
			
		||||
        long actionDelayTicks = actionDelay * 20L;
 | 
			
		||||
 | 
			
		||||
        if (this instanceof ReforgeSession) {
 | 
			
		||||
            BlacksmithPlugin.getInstance().callEvent(new BlacksmithReforgeStartEvent(npc, player, this.finishTime));
 | 
			
		||||
            BlacksmithPlugin.getInstance().callEvent(new BlacksmithReforgeStartEvent(npc, player, actionDelayTicks));
 | 
			
		||||
        } else if (this instanceof SalvageSession) {
 | 
			
		||||
            BlacksmithPlugin.getInstance().callEvent(new ScrapperSalvageStartEvent(npc, player, this.finishTime));
 | 
			
		||||
            BlacksmithPlugin.getInstance().callEvent(new ScrapperSalvageStartEvent(npc, player, actionDelayTicks));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        taskId = scheduler.scheduleSyncDelayedTask(BlacksmithPlugin.getInstance(), this, actionDelay * 20L);
 | 
			
		||||
        int playWorkSound = scheduler.scheduleSyncRepeatingTask(BlacksmithPlugin.getInstance(),
 | 
			
		||||
                () -> {
 | 
			
		||||
                    if (random.nextInt(100) < 20) {
 | 
			
		||||
                        this.playWorkSound();
 | 
			
		||||
                    }
 | 
			
		||||
                }, 20, 5);
 | 
			
		||||
        scheduler.scheduleSyncDelayedTask(BlacksmithPlugin.getInstance(), () -> scheduler.cancelTask(playWorkSound),
 | 
			
		||||
                (actionDelay * 20L) - 20);
 | 
			
		||||
        taskId = scheduler.scheduleSyncDelayedTask(BlacksmithPlugin.getInstance(), this, actionDelayTicks);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -174,13 +167,6 @@ public abstract class Session implements Runnable {
 | 
			
		||||
        playSound(this.npc.getEntity(), sound);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Plays the working NPC sound
 | 
			
		||||
     */
 | 
			
		||||
    protected void playWorkSound() {
 | 
			
		||||
        playSound(this.npc.getEntity(), Sound.ITEM_ARMOR_EQUIP_NETHERITE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Plays a npc sound using a cancellable event
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -184,15 +184,12 @@ public final class SalvageHelper {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the salvage resulting from the given recipe and the given item
 | 
			
		||||
     * Gets the raw salvage of a recipe, assuming full salvage would be possible
 | 
			
		||||
     *
 | 
			
		||||
     * @param recipe       <p>The recipe to get salvage for</p>
 | 
			
		||||
     * @param salvagedItem <p>The item to be salvaged</p>
 | 
			
		||||
     * @param trashSalvage <p>Any material treated as trash salvage</p>
 | 
			
		||||
     * @return <p>A list of items, or null if not a valid type of recipe</p>
 | 
			
		||||
     * @param recipe <p>The recipe to get salvage for</p>
 | 
			
		||||
     * @return <p>The salvage resulting from the recipe</p>
 | 
			
		||||
     */
 | 
			
		||||
    private static @Nullable List<ItemStack> getRecipeSalvage(@NotNull Recipe recipe, @NotNull ItemStack salvagedItem,
 | 
			
		||||
                                                              @NotNull Collection<Material> trashSalvage) {
 | 
			
		||||
    private static List<ItemStack> getRawRecipeSalvage(@NotNull Recipe recipe) {
 | 
			
		||||
        List<ItemStack> ingredients;
 | 
			
		||||
        if (recipe instanceof ShapedRecipe shapedRecipe) {
 | 
			
		||||
            ingredients = getIngredients(shapedRecipe);
 | 
			
		||||
@@ -203,8 +200,23 @@ public final class SalvageHelper {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
        //Make things easier by eliminating identical stacks
 | 
			
		||||
        ingredients = combineStacks(ingredients);
 | 
			
		||||
        return combineStacks(ingredients);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the salvage resulting from the given recipe and the given item
 | 
			
		||||
     *
 | 
			
		||||
     * @param recipe       <p>The recipe to get salvage for</p>
 | 
			
		||||
     * @param salvagedItem <p>The item to be salvaged</p>
 | 
			
		||||
     * @param trashSalvage <p>Any material treated as trash salvage</p>
 | 
			
		||||
     * @return <p>A list of items, or null if not a valid type of recipe</p>
 | 
			
		||||
     */
 | 
			
		||||
    private static @Nullable List<ItemStack> getRecipeSalvage(@NotNull Recipe recipe, @NotNull ItemStack salvagedItem,
 | 
			
		||||
                                                              @NotNull Collection<Material> trashSalvage) {
 | 
			
		||||
        List<ItemStack> ingredients = getRawRecipeSalvage(recipe);
 | 
			
		||||
        if (ingredients == null) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
        return combineStacks(getSalvage(copyItems(ingredients), salvagedItem, trashSalvage));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user