Skip to content

Commit

Permalink
Networks
Browse files Browse the repository at this point in the history
  • Loading branch information
Sefiraat committed Jan 27, 2022
1 parent c59afd3 commit 9c54e52
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 23 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
<repository>
<id>sefi-central</id>
<name>Sefiraat</name>
<url>https://sefiraat.jfrog.io/artifactory/default-maven-local</url>
</repository>
</repositories>

<build>
Expand Down Expand Up @@ -149,5 +154,11 @@
<artifactId>acf-paper</artifactId>
<version>0.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.github.sefiraat</groupId>
<artifactId>networks</artifactId>
<version>MODIFIED_1.0.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package io.github.sefiraat.slimetinker.events;

import de.jeff_media.morepersistentdatatypes.DataType;
import io.github.sefiraat.networks.slimefun.network.grid.NetworkGrid;
import io.github.sefiraat.networks.utils.Theme;
import io.github.sefiraat.networks.utils.datatypes.DataTypeMethods;
import io.github.sefiraat.slimetinker.SlimeTinker;
import io.github.sefiraat.slimetinker.events.friend.ActiveFriendElement;
import io.github.sefiraat.slimetinker.events.friend.EventFriend;
import io.github.sefiraat.slimetinker.runnables.event.KingsmanSpam;
import io.github.sefiraat.slimetinker.utils.BlockUtils;
Expand All @@ -15,6 +20,8 @@
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.libraries.dough.data.persistent.PersistentDataAPI;
import io.github.thebusybiscuit.slimefun4.libraries.dough.protection.Interaction;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import org.apache.commons.lang.Validate;
import org.bukkit.Effect;
import org.bukkit.Location;
Expand All @@ -28,15 +35,17 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

public final class RightClickEvents {
public final class InteractionEvents {

private RightClickEvents() {
private InteractionEvents() {
throw new UnsupportedOperationException("Utility Class");
}

Expand Down Expand Up @@ -230,4 +239,75 @@ public static void headSefirite(EventFriend friend) {
player.sendMessage(ThemeUtils.WARNING + "This ability is on cooldown.");
}
}

public static void linksUltimaninium(EventFriend friend) {
if (friend.getActiveFriendElement() != ActiveFriendElement.HELMET) {
return;
}

final Player player = friend.getPlayer();

if (player.getInventory().getItemInMainHand().getType() != Material.AIR) {
return;
}

if (friend.getAction() != Action.LEFT_CLICK_AIR && friend.getAction() != Action.LEFT_CLICK_BLOCK) {
return;
}

if (player.isSneaking()) {
final Block block = friend.getBlock();
if (block == null) {
return;
}

final SlimefunItem slimefunItem = BlockStorage.check(block);
if (Slimefun.getProtectionManager().hasPermission(player, block, Interaction.INTERACT_BLOCK)
&& slimefunItem instanceof NetworkGrid
) {
setGrid(friend.getActiveStack(), block, player);
} else {
player.sendMessage(Theme.ERROR + "Must be set to a Network Grid (not crafting grid).");
}
} else {
tryOpenGrid(friend.getActiveStack(), player);
}
}

private static void setGrid(@Nonnull ItemStack itemStack, @Nonnull Block block, @Nonnull Player player) {
final NamespacedKey key = io.github.sefiraat.networks.utils.Keys.newKey("location");
final ItemMeta itemMeta = itemStack.getItemMeta();
DataTypeMethods.setCustom(itemMeta, key, DataType.LOCATION, block.getLocation());
itemStack.setItemMeta(itemMeta);
player.sendMessage(Theme.SUCCESS + "Grid has been bound to the remote.");
}

private static void tryOpenGrid(@Nonnull ItemStack itemStack, @Nonnull Player player) {
final NamespacedKey key = io.github.sefiraat.networks.utils.Keys.newKey("location");
final ItemMeta itemMeta = itemStack.getItemMeta();
final Location location = DataTypeMethods.getCustom(itemMeta, key, DataType.LOCATION);

if (location != null) {

if (!location.getWorld().isChunkLoaded(location.getBlockX() / 16, location.getBlockZ() / 16)) {
player.sendMessage(Theme.ERROR + "The bound grid is not loaded.");
return;
}
openGrid(location, player);
} else {
player.sendMessage(Theme.ERROR + "Remote is not bound to a grid.");
}
}

private static void openGrid(@Nonnull Location location, @Nonnull Player player) {
BlockMenu blockMenu = BlockStorage.getInventory(location);
SlimefunItem slimefunItem = BlockStorage.check(location);
if (Slimefun.getProtectionManager().hasPermission(player, blockMenu.getLocation(), Interaction.INTERACT_BLOCK)
&& slimefunItem instanceof NetworkGrid
) {
blockMenu.open(player);
} else {
player.sendMessage(Theme.ERROR + "The bound grid can no longer be found.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
Expand Down Expand Up @@ -40,6 +41,10 @@ public class EventFriend {
* The block broken in BlockBreakEvents
*/
private Block block;
/**
* The block broken in BlockBreakEvents
*/
private Action action;
/**
* The entity doing the damaging (for EntityDamageEvents)
* Otherwise use player for PlayerDamageEvents
Expand Down Expand Up @@ -183,6 +188,14 @@ public void setBlock(Block block) {
this.block = block;
}

public Action getAction() {
return this.action;
}

public void setAction(Action action) {
this.action = action;
}

public Entity getDamagedEntity() {
return damagedEntity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public enum TraitEventType {
ENTITY_DAMAGED,
PLAYER_DAMAGED,
TICK,
RIGHT_CLICK
INTERACT
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.github.sefiraat.slimetinker.items.tinkermaterials.setup.TinkersMaterialsDynatech;
import io.github.sefiraat.slimetinker.items.tinkermaterials.setup.TinkersMaterialsInfinity;
import io.github.sefiraat.slimetinker.items.tinkermaterials.setup.TinkersMaterialsLiteXpansion;
import io.github.sefiraat.slimetinker.items.tinkermaterials.setup.TinkersMaterialsNetworks;
import io.github.sefiraat.slimetinker.items.tinkermaterials.setup.TinkersMaterialsSlimefunWarfare;
import io.github.sefiraat.slimetinker.items.tinkermaterials.setup.TinkersMaterialsTranscEndence;
import io.github.sefiraat.slimetinker.managers.SupportedPluginsManager;
Expand Down Expand Up @@ -122,6 +123,9 @@ public TinkerMaterialManager() {
if (SupportedPluginsManager.TRANSCENDENCE) {
MAP.putAll(TinkersMaterialsTranscEndence.getCmMap());
}
if (SupportedPluginsManager.NETWORKS) {
MAP.putAll(TinkersMaterialsNetworks.getCmMap());
}

TraitManager traitManager = SlimeTinker.getInstance().getTraitManager();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,25 @@ public void setupTrait(@Nonnull TinkerMaterial parentCM) {
protected static String getTraitTexture(@Nonnull String addedBy) {
if (addedBy.equals(SupportedPluginsManager.CORE_NOTE)) {
return SkullTextures.TRAITS_CORE;
} else if (addedBy.equals(SupportedPluginsManager.INFINITY_EXPANSION_NOTE)) {
}
if (addedBy.equals(SupportedPluginsManager.INFINITY_EXPANSION_NOTE)) {
return SkullTextures.TRAITS_INFINITY;
} else if (addedBy.equals(SupportedPluginsManager.SLIMEFUN_WARFARE_NOTE)) {
}
if (addedBy.equals(SupportedPluginsManager.SLIMEFUN_WARFARE_NOTE)) {
return SkullTextures.TRAITS_WARFARE;
} else if (addedBy.equals(SupportedPluginsManager.DYNATECH_NOTE)) {
}
if (addedBy.equals(SupportedPluginsManager.DYNATECH_NOTE)) {
return SkullTextures.TRAITS_DYNATECH;
} else if (addedBy.equals(SupportedPluginsManager.LITEXPANSION_NOTE)) {
}
if (addedBy.equals(SupportedPluginsManager.LITEXPANSION_NOTE)) {
return SkullTextures.TRAITS_LITEXPANSION;
} else if (addedBy.equals(SupportedPluginsManager.TRANSCENDENCE_NOTE)) {
}
if (addedBy.equals(SupportedPluginsManager.TRANSCENDENCE_NOTE)) {
return SkullTextures.TRAITS_TRANCSENENCE;
}
if (addedBy.equals(SupportedPluginsManager.NETWORKS_NOTE)) {
return SkullTextures.TRAITS_NETWORKS;
}
return "error";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.github.sefiraat.slimetinker.items.tinkermaterials.setup;

import io.github.sefiraat.slimetinker.items.tinkermaterials.TinkerMaterial;
import io.github.sefiraat.slimetinker.utils.Ids;
import io.github.sefiraat.slimetinker.utils.SkullTextures;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("SpellCheckingInspection")
public final class TinkersMaterialsNetworks {

private TinkersMaterialsNetworks() {
throw new UnsupportedOperationException("Utility Class");
}

private static final Map<String, TinkerMaterial> CM_MAP = new HashMap<>();

private static final TinkerMaterial MOLTEN_PRESENCE = new TinkerMaterial(Ids.MOLTEN_PRESENCE, SlimefunItem.getById("NTW_INTERDIMENSIONAL_PRESENCE").getItem(), "#15ab26")
.setLiquidTexture(SkullTextures.ALLOY_GREEN)
.setFormBlock("NTW_INTERDIMENSIONAL_PRESENCE")
.build();

private static final TinkerMaterial REMOTININIUM = new TinkerMaterial(Ids.REMOTININIUM, SlimefunItem.getById("NTW_REMOTE_PRISTINE").getItem(), "#acacac")
.setLiquidTexture(SkullTextures.ALLOY_SILVER)
.setFormBlock("NTW_REMOTE_PRISTINE")
.build();

private static final TinkerMaterial ULTIMANINIUM = new TinkerMaterial(Ids.ULTIMANINIUM, SlimefunItem.getById("NTW_REMOTE_ULTIMATE").getItem(), "#acacac")
.setLiquidTexture(SkullTextures.ALLOY_SILVER)
.addAlloyRecipe(
MOLTEN_PRESENCE.getLiquidItemStack(1),
REMOTININIUM.getLiquidItemStack(2)
)
.setTraitArmorLinks(Traits.NTW_UTLIMANINIUM)
.build();

static {
CM_MAP.put(Ids.MOLTEN_PRESENCE, MOLTEN_PRESENCE);
CM_MAP.put(Ids.REMOTININIUM, REMOTININIUM);
CM_MAP.put(Ids.ULTIMANINIUM, ULTIMANINIUM);
}

public static Map<String, TinkerMaterial> getCmMap() {
return CM_MAP;
}
}
Loading

0 comments on commit 9c54e52

Please sign in to comment.