[factions-banking] Refinement on last commit with entry + exit stuff. IT WORKS!
Some checks are pending
build / build (21) (push) Waiting to run
Some checks are pending
build / build (21) (push) Waiting to run
This commit is contained in:
parent
bcbd481fcf
commit
d274810ca4
@ -91,11 +91,11 @@ public class AttributeMgr {
|
||||
msg = "Applied attribute '" + attributeName + "' successfully";
|
||||
} else {
|
||||
msg = "Player tree not found!";
|
||||
String debug = "PlayerTree is null";
|
||||
if (playerTree != null) {
|
||||
debug = playerTree.ContainsAttribute(attributeName) ? "YES":"NO";
|
||||
}
|
||||
System.out.println("APPLY ATTRIBUTE FAIL: TREE NULL, NODE NULL, OR PLAYER ALREADY HAS THIS ATTRIBUTE (DO THEY? " + debug + ")");
|
||||
// String debug = "PlayerTree is null";
|
||||
// if (playerTree != null) {
|
||||
// debug = playerTree.ContainsAttribute(attributeName) ? "YES":"NO";
|
||||
// }
|
||||
// System.out.println("APPLY ATTRIBUTE FAIL: TREE NULL, NODE NULL, OR PLAYER ALREADY HAS THIS ATTRIBUTE (DO THEY? " + debug + ")");
|
||||
}
|
||||
} else {
|
||||
msg = "Could not apply attribute, attribute name does not exist!";
|
||||
|
@ -4,6 +4,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AbstractNode;
|
||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerEnteredBaseCallback;
|
||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerExitedBaseCallback;
|
||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerInBaseCallback;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
@ -34,8 +36,18 @@ public class FactionFlight extends AbstractNode {
|
||||
|
||||
@Override
|
||||
public void RegisterCallbacks(ServerPlayerEntity playerObj, ServerWorld worldObj) {
|
||||
PlayerInBaseCallback.EVENT.register((player, world) -> {
|
||||
player.sendMessage(Text.of("Welcome home! Feel free to fly around!"));
|
||||
// PlayerInBaseCallback.EVENT.register((player, world) -> {
|
||||
// player.sendMessage(Text.of("Welcome home! Feel free to fly around!"));
|
||||
// return ActionResult.SUCCESS;
|
||||
// });
|
||||
|
||||
PlayerEnteredBaseCallback.EVENT.register((player, world) -> {
|
||||
player.sendMessage(Text.of("Faction flight enabled"));
|
||||
return ActionResult.SUCCESS;
|
||||
});
|
||||
|
||||
PlayerExitedBaseCallback.EVENT.register((player, world) -> {
|
||||
player.sendMessage(Text.of("Faction flight disabled"));
|
||||
return ActionResult.SUCCESS;
|
||||
});
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
package jesse.keeblarcraft.CustomBlocks.BlockEntities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import jesse.keeblarcraft.AttributeMgr.AttributeMgr;
|
||||
import jesse.keeblarcraft.AttributeMgr.AttributeTree;
|
||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerEnteredBaseCallback;
|
||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerExitedBaseCallback;
|
||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerInBaseCallback;
|
||||
import jesse.keeblarcraft.GuiMgr.FactionBlockScreenHandler;
|
||||
import jesse.keeblarcraft.world.ImplementedInventory;
|
||||
@ -33,6 +37,7 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
||||
private static int factionPower = 0;
|
||||
Boolean stopMobSpawn = true;
|
||||
Boolean hasBuildFlight = true;
|
||||
private ArrayList<String> playersInRadius = new ArrayList<>();
|
||||
|
||||
protected final PropertyDelegate propertyDelegate;
|
||||
|
||||
@ -122,34 +127,46 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
||||
return;
|
||||
}
|
||||
|
||||
// Do stuff here that we need to do on a per tick basis. Probably check the items inside the slots and do stuff?
|
||||
// Maybe something with callback handlers might be done here? Like the temp flight within bounds of the faction block if that powerup is
|
||||
// active, etc?
|
||||
// TODO: Optimize this block so that when it is placed the placers UUID is related to a faction and only pull from a list of those players not the entire server
|
||||
for (PlayerEntity player : world.getPlayers()) {
|
||||
Boolean isPlayerInFactionRadius = IsPlayerInBounds(player, pos);
|
||||
if (isPlayerInFactionRadius) {
|
||||
// Run individual faction modules for players here
|
||||
// First time entry callback check
|
||||
if (!playersInRadius.contains(player.getUuidAsString())) {
|
||||
playersInRadius.add(player.getUuidAsString());
|
||||
ActionResult result = PlayerEnteredBaseCallback.EVENT.invoker().interact(player, world);
|
||||
}
|
||||
|
||||
if (stopMobSpawn) {
|
||||
// Temporary for now
|
||||
// Sphere center point is going to be X,Y,Z
|
||||
Integer X = pos.getX();
|
||||
Integer y = pos.getY();
|
||||
Integer z = pos.getZ();
|
||||
Integer radius = 10;
|
||||
}
|
||||
|
||||
if (hasBuildFlight) {
|
||||
int worldX = pos.east().getX();
|
||||
int worldY = pos.getY();
|
||||
int worldZ = pos.east().getZ();
|
||||
System.out.println("FACTION BLOCK DEBUG INFO: " + worldX + " " + worldY + " " + worldZ);
|
||||
|
||||
for (PlayerEntity player : world.getPlayers()) {
|
||||
if (IsPlayerInBounds(player, pos)) {
|
||||
// Notify the attribute tree to enable this attribute!
|
||||
AttributeMgr.ApplyAttribute(player.getUuidAsString(), "factions_flight");
|
||||
// Invoke the flight attribute on this player
|
||||
if (hasBuildFlight) {
|
||||
AttributeMgr.ApplyAttribute(player.getUuidAsString(), "faction_flight");
|
||||
ActionResult result = PlayerInBaseCallback.EVENT.invoker().interact(player, world);
|
||||
}
|
||||
} else if (!isPlayerInFactionRadius && playersInRadius.contains(player.getUuidAsString())) {
|
||||
playersInRadius.remove(player.getUuidAsString());
|
||||
ActionResult result = PlayerExitedBaseCallback.EVENT.invoker().interact(player, world);
|
||||
}
|
||||
|
||||
world.getBlockEntity(pos.east());
|
||||
}
|
||||
|
||||
// if (stopMobSpawn) {
|
||||
// // Temporary for now
|
||||
// // Sphere center point is going to be X,Y,Z
|
||||
// Integer X = pos.getX();
|
||||
// Integer y = pos.getY();
|
||||
// Integer z = pos.getZ();
|
||||
// Integer radius = 10;
|
||||
// }
|
||||
|
||||
// if (hasBuildFlight) {
|
||||
// for (PlayerEntity player : world.getPlayers()) {
|
||||
// if (IsPlayerInBounds(player, pos)) {
|
||||
// // Notify the attribute tree to enable this attribute!
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
// world.getBlockEntity(pos.east());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package jesse.keeblarcraft.FactionMgr.Callbacks;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface PlayerEnteredBaseCallback {
|
||||
Event<PlayerEnteredBaseCallback> EVENT = EventFactory.createArrayBacked(PlayerEnteredBaseCallback.class,
|
||||
(listeners) -> (player, world) -> {
|
||||
for (PlayerEnteredBaseCallback listener : listeners) {
|
||||
ActionResult result = listener.interact(player, world);
|
||||
|
||||
if (result != ActionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
ActionResult interact(PlayerEntity player, World world);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package jesse.keeblarcraft.FactionMgr.Callbacks;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface PlayerExitedBaseCallback {
|
||||
Event<PlayerExitedBaseCallback> EVENT = EventFactory.createArrayBacked(PlayerExitedBaseCallback.class,
|
||||
(listeners) -> (player, world) -> {
|
||||
for (PlayerExitedBaseCallback listener : listeners) {
|
||||
ActionResult result = listener.interact(player, world);
|
||||
|
||||
if (result != ActionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
ActionResult interact(PlayerEntity player, World world);
|
||||
}
|
Loading…
Reference in New Issue
Block a user