Skip to content

Commit

Permalink
Add updated sponge module, sponge 10 (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
Intybyte authored Oct 31, 2024
1 parent aff3e6a commit 43323e6
Show file tree
Hide file tree
Showing 22 changed files with 1,389 additions and 4 deletions.
10 changes: 7 additions & 3 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
<module>paper</module>
<module>bungee</module>
<module>sponge</module>
<module>sponge10</module>
<module>jda</module>
<module>velocity</module>
</modules>
Expand Down
80 changes: 80 additions & 0 deletions sponge10/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License
~
~ Permission is hereby granted, free of charge, to any person obtaining
~ a copy of this software and associated documentation files (the
~ "Software"), to deal in the Software without restriction, including
~ without limitation the rights to use, copy, modify, merge, publish,
~ distribute, sublicense, and/or sell copies of the Software, and to
~ permit persons to whom the Software is furnished to do so, subject to
~ the following conditions:
~
~ The above copyright notice and this permission notice shall be
~ included in all copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
~ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
~ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
~ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
~ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
~ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
~ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>co.aikar</groupId>
<artifactId>acf-parent</artifactId>
<version><!--VERSION-->0.5.1-SNAPSHOT<!--VERSION--></version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>acf-sponge10</artifactId>
<version><!--VERSION-->0.5.1-SNAPSHOT<!--VERSION--></version>

<name>ACF (Sponge 10)</name>

<repositories>
<repository>
<id>spongepowered</id>
<url>https://repo.spongepowered.org/maven/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-core</artifactId>
<version><!--VERSION-->0.5.1-SNAPSHOT<!--VERSION--></version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spongepowered</groupId>
<artifactId>spongeapi</artifactId>
<version>10.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${project.basedir}/../languages/minecraft/</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
96 changes: 96 additions & 0 deletions sponge10/src/main/java/co/aikar/commands/ACFSpongeUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package co.aikar.commands;

import org.jetbrains.annotations.Nullable;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

@SuppressWarnings("WeakerAccess")
public class ACFSpongeUtil {
public static Player findPlayerSmart(CommandIssuer issuer, String search) {
SpongeCommandSource requester = issuer.getIssuer();
if (search == null) {
return null;
}
String name = ACFUtil.replace(search, ":confirm", "");

List<Player> matches = matchPlayer(name);
List<Player> confirmList = new ArrayList<>();
findMatches(search, requester, matches, confirmList);


if (matches.size() > 1 || confirmList.size() > 1) {
String allMatches = matches.stream().map(Player::name).collect(Collectors.joining(", "));
issuer.sendError(MinecraftMessageKeys.MULTIPLE_PLAYERS_MATCH,
"{search}", name, "{all}", allMatches);
return null;
}

if (matches.isEmpty()) {
if (!issuer.getManager().isValidName(name)) {
issuer.sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name);
return null;
}
Player player = ACFUtil.getFirstElement(confirmList);
if (player == null) {
issuer.sendError(MinecraftMessageKeys.NO_PLAYER_FOUND_SERVER, "{search}", name);
return null;
} else {

issuer.sendInfo(MinecraftMessageKeys.PLAYER_IS_VANISHED_CONFIRM, "{vanished}", player.name());
return null;
}
}

return matches.get(0);
}

private static void findMatches(String search, SpongeCommandSource requester, List<Player> matches, List<Player> confirmList) {
// Remove vanished players from smart matching.
Iterator<Player> iter = matches.iterator();
//noinspection Duplicates
while (iter.hasNext()) {
Player player = iter.next();
if (requester instanceof Player && !((Player) requester).canSee(player)) {
if (requester.hasPermission("acf.seevanish")) {
if (!search.endsWith(":confirm")) {
confirmList.add(player);
iter.remove();
}
} else {
iter.remove();
}
}
}
}

public static List<Player> matchPlayer(String partialName) {
List<Player> matchedPlayers = new ArrayList<>();

for (Player iterPlayer : Sponge.server().onlinePlayers()) {
String iterPlayerName = iterPlayer.name();

if (partialName.equalsIgnoreCase(iterPlayerName)) {
// Exact match
matchedPlayers.clear();
matchedPlayers.add(iterPlayer);
break;
}
if (iterPlayerName.toLowerCase(java.util.Locale.ENGLISH).contains(partialName.toLowerCase(java.util.Locale.ENGLISH))) {
// Partial match
matchedPlayers.add(iterPlayer);
}
}

return matchedPlayers;
}

public static boolean isValidName(@Nullable String name) {
return name != null && !name.isEmpty() && ACFPatterns.VALID_NAME_PATTERN.matcher(name).matches();
}

}
46 changes: 46 additions & 0 deletions sponge10/src/main/java/co/aikar/commands/MinecraftMessageKeys.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package co.aikar.commands;

import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;

import java.util.Locale;

public enum MinecraftMessageKeys implements MessageKeyProvider {
INVALID_WORLD,
YOU_MUST_BE_HOLDING_ITEM,
PLAYER_IS_VANISHED_CONFIRM,
USERNAME_TOO_SHORT,
IS_NOT_A_VALID_NAME,
MULTIPLE_PLAYERS_MATCH,
NO_PLAYER_FOUND_SERVER,
NO_PLAYER_FOUND
;

private final MessageKey key = MessageKey.of("acf-minecraft." + this.name().toLowerCase(Locale.ENGLISH));
public MessageKey getMessageKey() {
return key;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package co.aikar.commands;

import org.spongepowered.api.entity.living.player.Player;

@SuppressWarnings("WeakerAccess")
public class SpongeCommandCompletionContext extends CommandCompletionContext<SpongeCommandIssuer> {

SpongeCommandCompletionContext(final RegisteredCommand command, final SpongeCommandIssuer issuer, final String input, final String config, final String[] args) {
super(command, issuer, input, config, args);
}

public SpongeCommandSource getSource() {
return this.issuer.getIssuer();
}

public Player getPlayer() {
return this.issuer.getPlayer();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package co.aikar.commands;

@SuppressWarnings("WeakerAccess")
public class SpongeCommandCompletions extends CommandCompletions<SpongeCommandCompletionContext> {

public SpongeCommandCompletions(final SpongeCommandManager manager) {
super(manager);
}
}
Loading

0 comments on commit 43323e6

Please sign in to comment.