Skip to content

Commit

Permalink
Channeling Rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Flo56958 committed Oct 30, 2020
1 parent c99b128 commit 04b8ea1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void onInventoryClick(@NotNull final InventoryClickEvent event) {
if (repair == null) return;

final ItemMeta repairMeta = repair.getItemMeta();
if(repairMeta != null) {
if (repairMeta != null) {
if (repairMeta.hasDisplayName() || repairMeta.hasLore()) return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ private void setCreator(@Nullable final ItemStack is, @Nullable final Entity ent
DataHandler.setTag(is, "creator", entity.getUniqueId(), UUIDTagType.instance, false);
}

public OfflinePlayer getCreator(@Nullable final ItemStack is) {
public @Nullable OfflinePlayer getCreator(@Nullable final ItemStack is) {
if (is == null) return null;
UUID creator = DataHandler.getTag(is, "creator", UUIDTagType.instance, false);
if (creator == null) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@

import de.flo56958.minetinker.MineTinker;
import de.flo56958.minetinker.data.ToolType;
import de.flo56958.minetinker.events.MTEntityDamageByEntityEvent;
import de.flo56958.minetinker.events.MTProjectileHitEvent;
import de.flo56958.minetinker.modifiers.Modifier;
import de.flo56958.minetinker.utils.ChatWriter;
import de.flo56958.minetinker.utils.ConfigurationManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public class Channeling extends Modifier {
public class Channeling extends Modifier implements Listener {

private static Channeling instance;

private boolean worksOnlyInStorms;

private Channeling() {
super(MineTinker.getPlugin());
customModelData = 10_007;
Expand All @@ -43,7 +49,7 @@ public String getKey() {

@Override
public List<ToolType> getAllowedTools() {
return Collections.singletonList(ToolType.TRIDENT);
return Arrays.asList(ToolType.TRIDENT, ToolType.BOW, ToolType.AXE, ToolType.CROSSBOW, ToolType.SWORD);
}

@Override
Expand All @@ -69,6 +75,8 @@ public void reload() {
config.addDefault("Recipe.Middle", "PCP");
config.addDefault("Recipe.Bottom", "SPS");

config.addDefault("WorksOnlyInStorms", true);

Map<String, String> recipeMaterials = new HashMap<>();
recipeMaterials.put("S", Material.SEA_LANTERN.name());
recipeMaterials.put("P", Material.PRISMARINE_SHARD.name());
Expand All @@ -80,10 +88,12 @@ public void reload() {
ConfigurationManager.loadConfig("Modifiers" + File.separator, getFileName());

init(Material.PRISMARINE_SHARD);

worksOnlyInStorms = config.getBoolean("WorksOnlyInStorms", true);
}

@Override
public boolean applyMod(Player player, ItemStack tool, boolean isCommand) {
public boolean applyMod(Player player, @NotNull ItemStack tool, final boolean isCommand) {
ItemMeta meta = tool.getItemMeta();

if (meta != null) {
Expand All @@ -96,4 +106,31 @@ public boolean applyMod(Player player, ItemStack tool, boolean isCommand) {

return true;
}

@EventHandler(ignoreCancelled = true)
private void onProjectileHit(@NotNull final MTProjectileHitEvent event) {
final ItemStack tool = event.getTool();
if (!event.getPlayer().hasPermission("minetinker.modifiers.channeling.use")) return;
if (event.getEvent().getHitEntity() != null) return;

if (modManager.hasMod(tool, this)) {
final Location loc = event.getEvent().getEntity().getLocation();
if (!loc.getWorld().hasStorm() && worksOnlyInStorms) return;
loc.getWorld().strikeLightning(loc);
ChatWriter.logModifier(event.getPlayer(), event, this, tool, String.format("Location: %d/%d/%d", loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}
}

@EventHandler(ignoreCancelled = true)
private void onEntityHit(@NotNull final MTEntityDamageByEntityEvent event) {
final ItemStack tool = event.getTool();
if (!event.getPlayer().hasPermission("minetinker.modifiers.channeling.use")) return;

if (modManager.hasMod(tool, this)) {
final Location loc = event.getEntity().getLocation();
if (!loc.getWorld().hasStorm() && worksOnlyInStorms) return;
loc.getWorld().strikeLightning(loc);
ChatWriter.logModifier(event.getPlayer(), event, this, tool, String.format("Location: %d/%d/%d", loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/lang/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Modifier:
DescriptionModifierItem: "Modifier-Item for the Berserk-Modifier"
Channeling:
Name: "Channeling"
Description: "Summons lightning when the trident hits its foes!"
Description: "Summon lightning!"
ModifierItemName: "Lightning Infused Shard"
DescriptionModifierItem: "Modifier-Item for the Channeling-Modifier"
Directing:
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,13 @@ permissions:
minetinker.modifiers.channeling.*:
children:
minetinker.modifiers.channeling.apply: true
minetinker.modifiers.channeling.use: true
minetinker.modifiers.channeling.apply:
description: Allows to apply Channeling to the MineTinker-Tool
default: true
minetinker.modifiers.channeling.use:
description: Allows to use Channeling on a MineTinker-Tool
default: true

minetinker.modifiers.directing.*:
children:
Expand Down

0 comments on commit 04b8ea1

Please sign in to comment.