mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-02-16 12:21:20 +01:00
feat: add permission tag & compatible block trigger list
* Update DataStorage.java - Fix error in folder creation. - Use output file directly instead of asserting a new one * Fix Null PlayerDataServices * Feature: Add only compatible blocks to the trigger block list * Permission Tag Added
This commit is contained in:
parent
c9d98b39c3
commit
6386a89913
@ -15,10 +15,7 @@ import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.tags.activation.CooldownTag;
|
||||
import com.sekwah.advancedportals.core.tags.activation.DestiTag;
|
||||
import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||
import com.sekwah.advancedportals.core.tags.activation.TriggerBlockTag;
|
||||
import com.sekwah.advancedportals.core.tags.activation.*;
|
||||
import com.sekwah.advancedportals.core.util.GameScheduler;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
@ -121,6 +118,7 @@ public class AdvancedPortalsCore {
|
||||
this.tagRegistry.registerTag(new DestiTag());
|
||||
this.tagRegistry.registerTag(new CooldownTag());
|
||||
this.tagRegistry.registerTag(new TriggerBlockTag());
|
||||
this.tagRegistry.registerTag(new PermissionTag());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,7 @@ public class PortalPermissions {
|
||||
|
||||
|
||||
/**
|
||||
* this will not currently build the permissions for the files, but maybe at some point. I'tll just make it easier though.
|
||||
* this will not currently build the permissions for the files, but maybe at some point. It'll just make it easier though.
|
||||
*/
|
||||
public static class PermissionBuilder {
|
||||
private final String permissionTag;
|
||||
|
@ -12,7 +12,6 @@ import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.tags.activation.TriggerBlockTag;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.util.PlayerUtils;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
@ -24,7 +23,7 @@ import java.util.*;
|
||||
public class AdvancedPortal implements TagTarget {
|
||||
|
||||
@Inject
|
||||
transient TagRegistry tagRegistry;
|
||||
private transient TagRegistry tagRegistry;
|
||||
|
||||
@SerializedName("max")
|
||||
private BlockLocation maxLoc;
|
||||
@ -33,15 +32,17 @@ public class AdvancedPortal implements TagTarget {
|
||||
private BlockLocation minLoc;
|
||||
|
||||
@SerializedName("a")
|
||||
private HashMap<String, String[]> args = new HashMap<>();
|
||||
private final HashMap<String, String[]> args = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
transient PlayerDataServices playerDataServices;
|
||||
private transient PlayerDataServices playerDataServices;
|
||||
|
||||
@Inject
|
||||
transient ConfigRepository configRepository;
|
||||
|
||||
public AdvancedPortal(BlockLocation minLoc, BlockLocation maxLoc) {
|
||||
public AdvancedPortal(BlockLocation minLoc, BlockLocation maxLoc, TagRegistry tagRegistry, PlayerDataServices playerDataServices) {
|
||||
this.tagRegistry = tagRegistry;
|
||||
this.playerDataServices = playerDataServices;
|
||||
this.updateBounds(minLoc, maxLoc);
|
||||
}
|
||||
|
||||
@ -103,7 +104,7 @@ public class AdvancedPortal implements TagTarget {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param player The player on the server attempting to use an advanced portal
|
||||
* @param moveActivated if the portal was activated by a move event (won't trigger knockback)
|
||||
* @return
|
||||
*/
|
||||
@ -157,7 +158,6 @@ public class AdvancedPortal implements TagTarget {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean isLocationInPortal(BlockLocation loc) {
|
||||
return this.isLocationInPortal(loc, 0);
|
||||
}
|
||||
@ -166,7 +166,6 @@ public class AdvancedPortal implements TagTarget {
|
||||
return this.isLocationInPortal(loc.toBlockPos(), 0);
|
||||
}
|
||||
|
||||
|
||||
public boolean isLocationInPortal(PlayerLocation loc, int additionalArea) {
|
||||
return this.isLocationInPortal(loc.toBlockPos(), additionalArea);
|
||||
}
|
||||
|
@ -78,14 +78,14 @@ public class DataStorage {
|
||||
public boolean storeJson(Object dataHolder, String location) {
|
||||
// Create folders if they don't exist
|
||||
File outFile = new File(this.dataFolder, location);
|
||||
if (!outFile.exists()) {
|
||||
if (!outFile.getParentFile().exists()) { // Check if parent folder exists
|
||||
if(!outFile.getParentFile().mkdirs()) {
|
||||
infoLogger.warning("Failed to create folder for file: " + location);
|
||||
}
|
||||
}
|
||||
String json = gson.toJson(dataHolder);
|
||||
try {
|
||||
FileWriter fileWriter = new FileWriter(new File(this.dataFolder, location));
|
||||
FileWriter fileWriter = new FileWriter(outFile); // Use outFile directly here
|
||||
fileWriter.write(json);
|
||||
fileWriter.close();
|
||||
return true;
|
||||
|
@ -25,7 +25,7 @@ public class PortalServices {
|
||||
private IPortalRepository portalRepository;
|
||||
|
||||
@Inject
|
||||
private PlayerDataServices playerDataServices;
|
||||
private transient PlayerDataServices playerDataServices;
|
||||
|
||||
@Inject
|
||||
private ConfigRepository configRepository;
|
||||
@ -88,17 +88,17 @@ public class PortalServices {
|
||||
|| (portal.isLocationInPortal(blockEntityTopLoc)
|
||||
&& portal.isTriggerBlock(blockEntityTopMaterial))) {
|
||||
notInPortal = false;
|
||||
if(portal.activate(player, true)) {
|
||||
if (portal.activate(player, true)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
if(!notInPortal) {
|
||||
if (!notInPortal) {
|
||||
var strength = configRepository.getThrowbackStrength();
|
||||
PlayerUtils.throwPlayerBack(player, strength);
|
||||
}
|
||||
if(playerData.isInPortal() && notInPortal) {
|
||||
if (playerData.isInPortal() && notInPortal) {
|
||||
playerData.setInPortal(false);
|
||||
}
|
||||
}
|
||||
@ -154,7 +154,7 @@ public class PortalServices {
|
||||
return null;
|
||||
}
|
||||
|
||||
AdvancedPortal portal = new AdvancedPortal(pos1, pos2);
|
||||
AdvancedPortal portal = new AdvancedPortal(pos1, pos2, tagRegistry, playerDataServices);
|
||||
|
||||
for (DataTag portalTag : tags) {
|
||||
portal.setArgValues(portalTag);
|
||||
|
@ -6,6 +6,7 @@ import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -46,6 +47,12 @@ public class NameTag implements Tag.AutoComplete, Tag.Creation {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String splitString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean created(TagTarget target, PlayerContainer player, String[] argData) {
|
||||
if (argData.length > 0) {
|
||||
|
@ -0,0 +1,74 @@
|
||||
package com.sekwah.advancedportals.core.tags.activation;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionTag implements Tag.Activation{
|
||||
|
||||
@Inject
|
||||
transient PlayerDataServices playerDataServices;
|
||||
|
||||
@Inject
|
||||
transient ConfigRepository configRepository;
|
||||
|
||||
@Inject
|
||||
private InfoLogger infoLogger;
|
||||
|
||||
public static String TAG_NAME = "permission";
|
||||
|
||||
private final String[] aliases = new String[]{ "perm" };
|
||||
|
||||
private final TagType[] tagTypes = new TagType[]{ TagType.PORTAL };
|
||||
|
||||
@Override
|
||||
public TagType[] getTagTypes() {
|
||||
return tagTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return TAG_NAME;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return Lang.translate("tag.permission.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preActivated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) {
|
||||
if (target instanceof AdvancedPortal portal) {
|
||||
var portalName = portal.getName();
|
||||
if (!player.hasPermission(argData[0])) return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postActivated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -55,6 +55,8 @@ public interface Tag {
|
||||
@Nullable
|
||||
List<String> autoComplete(String argData);
|
||||
|
||||
@Nullable
|
||||
String splitString();
|
||||
}
|
||||
|
||||
interface Split extends Tag {
|
||||
|
@ -160,6 +160,7 @@ items.selector.pos=Select pos %1$s
|
||||
items.interact.left=Left Click
|
||||
items.interact.right=Right Click
|
||||
|
||||
tag.permission.description=Sets the permission of a portal
|
||||
tag.desti.description=Sets the destination of the portal
|
||||
tag.name.error.nospaces= The name cannot contain spaces.
|
||||
tag.triggerblock.description=Sets the trigger block/s of the portal. Comma seperated or multi tag.
|
||||
|
@ -5,6 +5,7 @@ import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -13,7 +14,7 @@ import java.util.UUID;
|
||||
public class SpigotServerContainer implements ServerContainer {
|
||||
|
||||
private final Server server;
|
||||
private final List<String> triggerBlockList = Arrays.stream(Material.values()).filter(Material::isBlock).map(Enum::name)
|
||||
private final List<String> triggerBlockList = Arrays.stream(Material.values()).filter(this::isAdvancedPortalBlock).map(Enum::name)
|
||||
.toList();
|
||||
|
||||
public SpigotServerContainer(Server server) {
|
||||
@ -61,4 +62,12 @@ public class SpigotServerContainer implements ServerContainer {
|
||||
.map(SpigotPlayerContainer::new)
|
||||
.toArray(PlayerContainer[]::new);
|
||||
}
|
||||
|
||||
// Check if it's a material compatible with making portals
|
||||
private boolean isAdvancedPortalBlock(Material material) {
|
||||
return switch (material) {
|
||||
case WATER, LAVA, AIR, NETHER_PORTAL, END_GATEWAY, END_PORTAL -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user