Skip to content

Commit

Permalink
feat: add command tags (#443)
Browse files Browse the repository at this point in the history
Co-authored-by: TreemanKing <67459602+TreemanKing@users.noreply.github.com>
  • Loading branch information
sekwah41 and TreemanKing committed Nov 18, 2024
1 parent ab92ff1 commit 833399e
Show file tree
Hide file tree
Showing 22 changed files with 335 additions and 96 deletions.
85 changes: 44 additions & 41 deletions .github/workflows/pre-commit-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,56 @@ concurrency:

jobs:
pre-commit-check:
permissions:
pull-requests: write
if: github.event.action != 'labeled' || github.event.label.name == 'pre-commit ci run'
name: Run pre-commit checks
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- run: gh pr edit ${{ github.event.number }} --remove-label 'pre-commit ci run'
if: github.event.action == 'labeled' && github.event.label.name == 'pre-commit ci run'
env:
GH_TOKEN: ${{ github.token }}
- uses: dorny/paths-filter@v2
id: filter
with:
list-files: shell
filters: |
addedOrModified:
- added|modified: '**'
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- run: gh pr edit ${{ github.event.number }} --remove-label 'pre-commit ci run'
if: github.event.action == 'labeled' && github.event.label.name == 'pre-commit ci run'
env:
GH_TOKEN: ${{ github.token }}
- uses: dorny/paths-filter@v2
id: filter
with:
list-files: shell
filters: |
addedOrModified:
- added|modified: '**'
# run only if changed files were detected
- name: Run against changes
uses: pre-commit/action@v3.0.1
if: steps.filter.outputs.addedOrModified == 'true'
with:
extra_args: --files ${{ steps.filter.outputs.addedOrModified_files }}
- name: Run against changes
uses: pre-commit/action@v3.0.1
if: steps.filter.outputs.addedOrModified == 'true'
with:
extra_args: --files ${{ steps.filter.outputs.addedOrModified_files }}

# run if no changed files were detected (e.g. workflow_dispatch on master branch)
- name: Run against all files
uses: pre-commit/action@v3.0.1
if: steps.filter.outputs.addedOrModified != 'true'
with:
extra_args: --all-files
- uses: pre-commit-ci/lite-action@v1.0.2
if: always()
with:
msg: apply code formatting
- name: Run against all files
uses: pre-commit/action@v3.0.1
if: steps.filter.outputs.addedOrModified != 'true'
with:
extra_args: --all-files

- name: Commit pre-commit changes
if: always() && github.event.action != 'pull_request' && github.event.action != 'labeled'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "chore: pre-commit changes" || echo "No changes to commit"
git push ${{ github.head_ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit pre-commit changes
if: always()
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "chore: pre-commit changes [skip ci]" || echo "No changes to commit"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Push pre-commit changes
if: always() && github.event.action != 'pull_request' && github.event.action != 'labeled' && github.event.action != 'synchronize'
run: |
git push ${{ github.head_ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: pre-commit-ci/lite-action@v1.0.2
if: always()
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private void registerTags() {
this.tagRegistry.registerTag(new CooldownTag());
this.tagRegistry.registerTag(new TriggerBlockTag());
this.tagRegistry.registerTag(new PermissionTag());
this.tagRegistry.registerTag(new CommandTag());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class CoreListeners {

public void playerJoin(PlayerContainer player) {
this.playerDataServices.setJoinCooldown(player);
this.playerDataServices.getPlayerData(player).setInPortal(true);
}

public void teleportEvent(PlayerContainer player) {
Expand Down Expand Up @@ -173,6 +174,7 @@ public boolean playerInteractWithBlock(PlayerContainer player,

public void worldChange(PlayerContainer player) {
this.playerDataServices.setJoinCooldown(player);
this.playerDataServices.getPlayerData(player).setInPortal(true);
}

public boolean preventEntityCombust(EntityContainer entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ public List<String> onTabComplete(CommandSenderContainer sender,
String baseString = endsWithSplit
? argData
: argData.substring(
0,
argData.lastIndexOf(multiTagSplit) + 1);
0,
argData.lastIndexOf(multiTagSplit)
+ 1);

tagSuggestions =
tagSuggestions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
// Find the tag with the "name" NAME
DataTag nameTag =
portalTags.stream()
.filter(tag -> {
this.infoLogger.info("Tag: " + tag.NAME);
this.infoLogger.info(
"Equals: " + tag.NAME.equals(NameTag.TAG_NAME));
return tag.NAME.equals(NameTag.TAG_NAME);
})
.filter(tag -> tag.NAME.equals(NameTag.TAG_NAME))
.findFirst()
.orElse(null);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sekwah.advancedportals.core.connector.containers;

import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.tags.activation.CommandTag;
import java.util.UUID;

/**
Expand Down Expand Up @@ -37,4 +38,6 @@ void sendFakeBlockWithData(BlockLocation blockPos, String material,
boolean sendPacket(String channel, byte[] bytes);

void playSound(String sound, float volume, float pitch);

ServerContainer getServer();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sekwah.advancedportals.core.connector.containers;

import com.sekwah.advancedportals.core.tags.activation.CommandTag;
import java.util.List;
import java.util.UUID;

Expand All @@ -13,4 +14,7 @@ public interface ServerContainer {
List<String> getTriggerBlocks();

PlayerContainer[] getPlayers();

void dispatchCommand(UUID uuid, String command,
CommandTag.CommandLevel commandLevel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.Tag;

import java.util.*;

/**
Expand Down Expand Up @@ -104,28 +105,27 @@ public void updateBounds(BlockLocation loc1, BlockLocation loc2) {
}*/

/**
* @param player The player on the server attempting to use an advanced
* portal
* @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)
* trigger knockback)
* @return
*/
public boolean activate(PlayerContainer player, boolean moveActivated) {
var playerData = playerDataServices.getPlayerData(player);
if (playerData.isInPortal())
return false;
playerData.setInPortal(true);
if (playerData.hasJoinCooldown()) {
var cooldown =
(int) Math.ceil(playerData.getJoinCooldownLeft() / 1000D);
(int) Math.ceil(playerData.getJoinCooldownLeft() / 1000D);
player.sendMessage(Lang.translateInsertVariables(
"portal.cooldown.join", cooldown,
Lang.translate(cooldown == 1 ? "time.second"
: "time.seconds")));
"portal.cooldown.join", cooldown,
Lang.translate(cooldown == 1 ? "time.second"
: "time.seconds")));
if (configRepository.playFailSound()) {
var rand = new Random();
player.playSound("block.portal.travel", 0.05f,
rand.nextFloat() * 0.4F + 0.8F);
rand.nextFloat() * 0.4F + 0.8F);
}
return false;
}
Expand All @@ -139,36 +139,33 @@ public boolean activate(PlayerContainer player, boolean moveActivated) {

for (DataTag portalTag : portalTags) {
Tag.Activation activationHandler =
tagRegistry.getActivationHandler(portalTag.NAME);
if (activationHandler != null) {
if (!activationHandler.preActivated(
this, player, data,
this.getArgValues(portalTag.NAME))) {
return false;
}
tagRegistry.getActivationHandler(portalTag.NAME);
if (activationHandler != null && !activationHandler.preActivated(
this, player, data,
this.getArgValues(portalTag.NAME))) {
return false;
}
}
for (DataTag portalTag : portalTags) {
Tag.Activation activationHandler =
tagRegistry.getActivationHandler(portalTag.NAME);
if (activationHandler != null) {
if (!activationHandler.activated(
this, player, data,
this.getArgValues(portalTag.NAME))) {
return false;
}
tagRegistry.getActivationHandler(portalTag.NAME);
if (activationHandler != null && !activationHandler.activated(
this, player, data,
this.getArgValues(portalTag.NAME))) {
return false;
}
}
for (DataTag portalTag : portalTags) {
Tag.Activation activationHandler =
tagRegistry.getActivationHandler(portalTag.NAME);
tagRegistry.getActivationHandler(portalTag.NAME);
if (activationHandler != null) {
activationHandler.postActivated(
this, player, data, this.getArgValues(portalTag.NAME));
this, player, data, this.getArgValues(portalTag.NAME));
}
}
if (data.hasActivated()) {
playerData.setNetherPortalCooldown(1000);
playerData.setInPortal(true);
return true;
}
return false;
Expand All @@ -192,12 +189,12 @@ public boolean isLocationInPortal(BlockLocation loc, int additionalArea) {
double playerZ = loc.getPosZ();

return Objects.equals(loc.getWorldName(), this.minLoc.getWorldName())
&& playerX >= this.minLoc.getPosX() - additionalArea
&& playerX < this.maxLoc.getPosX() + 1 + additionalArea
&& playerY >= this.minLoc.getPosY() - additionalArea
&& playerY < this.maxLoc.getPosY() + 1 + additionalArea
&& playerZ >= this.minLoc.getPosZ() - additionalArea
&& playerZ < this.maxLoc.getPosZ() + 1 + additionalArea;
&& playerX >= this.minLoc.getPosX() - additionalArea
&& playerX < this.maxLoc.getPosX() + 1 + additionalArea
&& playerY >= this.minLoc.getPosY() - additionalArea
&& playerY < this.maxLoc.getPosY() + 1 + additionalArea
&& playerZ >= this.minLoc.getPosZ() - additionalArea
&& playerZ < this.maxLoc.getPosZ() + 1 + additionalArea;
}

public void setArgValues(DataTag portalTag) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sekwah.advancedportals.core.repository;

import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.serializeddata.config.CommandPortalConfig;

public interface ConfigRepository {
boolean getUseOnlySpecialAxe();
Expand Down Expand Up @@ -32,4 +33,6 @@ public interface ConfigRepository {
boolean playFailSound();

void storeConfig();

CommandPortalConfig getCommandPortals();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.inject.Singleton;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.serializeddata.config.CommandPortalConfig;
import com.sekwah.advancedportals.core.serializeddata.config.Config;
import java.util.HashMap;

Expand Down Expand Up @@ -95,6 +96,11 @@ public boolean playFailSound() {
return this.config.playFailSound;
}

@Override
public CommandPortalConfig getCommandPortals() {
return this.config.commandPortals;
}

@Override
public void storeConfig() {
this.dataStorage.storeFile(this.config, "config.yaml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ private <U> Object constructFromMappingNode(Class<U> currentClass,
}
} catch (Exception e) {
infoLogger.warning("Failed to set field " + field.getName()
+ " in " + currentClass.getName() + ": "
+ e.getMessage());
+ " in " + currentClass.getName()
+ ": " + e.getMessage());
infoLogger.error(e);
throw new RuntimeException("Failed to set field "
+ field.getName() + " in "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sekwah.advancedportals.core.serializeddata.config;

public class CommandPortalConfig {
public final boolean op = true;
public final boolean console = true;

public final boolean permsWildcard = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public class Config {
public double throwbackStrength = 0.7;

public boolean playFailSound = true;

public CommandPortalConfig commandPortals = new CommandPortalConfig();
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public void playerMove(PlayerContainer player, PlayerLocation toLoc) {
}
}
var playerData = playerDataServices.getPlayerData(player);
if (!notInPortal) {
if (!playerData.isInPortal() && !notInPortal) {
playerData.setInPortal(true);
var strength = configRepository.getThrowbackStrength();
PlayerUtils.throwPlayerBack(player, strength);
}
Expand Down
Loading

0 comments on commit 833399e

Please sign in to comment.