Skip to content

Commit

Permalink
Added STRIP_LOGS job type (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
Picono435 committed Jun 4, 2023
1 parent 8a2c451 commit 91f3ddf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public Integer call() throws Exception {
Bukkit.getPluginManager().registerEvents(new RepairListener(), this);
Bukkit.getPluginManager().registerEvents(new SmeltListener(), this);
Bukkit.getPluginManager().registerEvents(new KillEntityListener(), this);
Bukkit.getPluginManager().registerEvents(new StripLogsListener(), this);

this.getLogger().info("The plugin was succefully enabled.");

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/gmail/picono435/picojobs/api/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public enum Type {
MILK(""),
MOVE("material"),
TRADE("material"),
KILL_ENTITY("entity");
KILL_ENTITY("entity"),
STRIP_LOGS("material");

private final static Map<String, Type> BY_NAME = new HashMap<String, Type>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.gmail.picono435.picojobs.listeners.jobs;

import com.gmail.picono435.picojobs.api.Job;
import com.gmail.picono435.picojobs.api.JobPlayer;
import com.gmail.picono435.picojobs.api.PicoJobsAPI;
import com.gmail.picono435.picojobs.api.Type;
import com.gmail.picono435.picojobs.api.managers.LanguageManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;

public class StripLogsListener implements Listener {

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onStripLogs(EntityChangeBlockEvent event) {
if(!(event.getEntity() instanceof Player)) return;
Player p = (Player) event.getEntity();
JobPlayer jp = PicoJobsAPI.getPlayersManager().getJobPlayer(p);
if(!jp.hasJob()) return;
if(!jp.isWorking()) return;
Job job = jp.getJob();
if(!job.getTypes().contains(Type.STRIP_LOGS)) return;
if(!event.getTo().name().startsWith("STRIPPED_")) return;
if(!jp.isInWorkZone(p)) return;

if(!job.inWhitelist(Type.STRIP_LOGS, event.getBlock().getType())) return;

if(jp.simulateEvent()) {
p.sendMessage(LanguageManager.getMessage("finished-work", p));
}
}
}

0 comments on commit 91f3ddf

Please sign in to comment.