Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Velocity' into Bungee
Browse files Browse the repository at this point in the history
  • Loading branch information
TreemanKing committed Jun 10, 2024
2 parents e4db7a3 + e1a7629 commit b164f1c
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 31 deletions.
38 changes: 27 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import java.nio.file.StandardOpenOption


buildscript {
repositories {
Expand Down Expand Up @@ -30,6 +35,13 @@ allprojects {
buildSubmodules.finalizedBy build
}

tasks.processResources {
def files = ["plugin.yml", "bungee.yml"]
filesMatching(files) {
expand(["pluginVersion": project.version])
}
}

sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

Expand Down Expand Up @@ -127,18 +139,22 @@ tasks.register('copyPlugin') {
dependsOn(build)
doLast {
copy {
println "$buildDir/libs/Advanced-Portals-${getVersion()}.jar"
println "$buildDir/MinecraftServer/plugins/Advanced-Portals-${getVersion()}.jar"
try {
delete fileTree("$buildDir/MinecraftServer/plugins/") {
include "Advanced-Portals*.jar"
}
}
catch (RuntimeException e) {
println e.getLocalizedMessage()
def sourceFilePath = Paths.get("$buildDir/libs/Advanced-Portals-${getVersion()}.jar")
def destinationFilePath = Paths.get("$buildDir/MinecraftServer/plugins/Advanced-Portals.jar")

println "Handling file: $destinationFilePath"

byte[] newContent = Files.readAllBytes(sourceFilePath)

if (Files.exists(destinationFilePath)) {
println "File exists. Overwriting with new binary content."

Files.write(destinationFilePath, newContent, StandardOpenOption.TRUNCATE_EXISTING)
} else {
println "File does not exist. Copying from source."

Files.copy(sourceFilePath, destinationFilePath, StandardCopyOption.REPLACE_EXISTING)
}
from file("$buildDir/libs/Advanced-Portals-${getVersion()}.jar")
into file("$buildDir/MinecraftServer/plugins")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ private void registerDestinationCommand(CommandRegister commandRegister) {
this.destiCommand = new CommandWithSubCommands(this);
this.destiCommand.registerSubCommand("create", new CreateDestiSubCommand());
this.destiCommand.registerSubCommand("remove", new RemoveDestiSubCommand());
this.destiCommand.registerSubCommand("teleport", new TeleportDestiSubCommand(), "tp");
this.destiCommand.registerSubCommand("list", new ListDestiSubCommand());
this.destiCommand.registerSubCommand("show", new ShowDestiSubCommand());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class CommandWithSubCommands implements CommandTemplate {

Expand Down Expand Up @@ -171,7 +172,8 @@ public List<String> filterTabResults(List<String> tabList, String lastArg) {
if(tabList == null) {
return null;
}
tabList.removeIf(arg -> !arg.startsWith(lastArg));
return tabList;
return tabList.stream()
.filter(arg -> arg.startsWith(lastArg))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {

@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
}
}
else {
sender.sendMessage(Lang.translate("command.portal.remove.noname"));
sender.sendMessage(Lang.translate("command.destination.noname"));
}
}

@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.sekwah.advancedportals.core.commands.subcommands.desti;

import com.google.inject.Inject;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
import com.sekwah.advancedportals.core.services.DestinationServices;
import com.sekwah.advancedportals.core.util.Lang;

import java.util.Collections;
import java.util.List;

public class TeleportDestiSubCommand implements SubCommand {

@Inject
DestinationServices destinationServices;
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
if(destinationServices.teleportToDestination(args[1], sender.getPlayerContainer())) {
sender.sendMessage(Lang.translate("messageprefix.positive")
+ Lang.translate("command.destination.teleport.success")
.replaceAll("@destiname", args[1]));
} else {
sender.sendMessage(Lang.translate("messageprefix.negative") +
Lang.translate("command.destination.teleport.error")
.replaceAll("@destiname", args[1]));
}
} else {
sender.sendMessage(Lang.translate("command.destination.noname"));
}
}

@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender);
}

@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
if(args.length > 2) {
return Collections.emptyList();
}
List<String> destiNames = destinationServices.getDestinationNames();
Collections.sort(destiNames);
return destiNames;
}

@Override
public String getBasicHelpText() {
return Lang.translate("command.destination.teleport.help");
}

@Override
public String getDetailedHelpText() {
return Lang.translate("command.destination.teleport.detailedhelp");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class PortalPermissions {
private static final PermissionBuilder PERMISSIONS = new PermissionBuilder("advancedportals");

public static final PermissionBuilder BUILD = PERMISSIONS.createChild("build");
public static final PermissionBuilder DESTI = PERMISSIONS.createChild("desti");
public static final PermissionBuilder CREATE_PORTAL = PERMISSIONS.createChild("createportal");
public static final PermissionBuilder LANG_UPDATE = PERMISSIONS.createChild("langupdate");
public static final PermissionBuilder RELOAD = PERMISSIONS.createChild("reload");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,12 @@ public boolean removeDestination(String name, PlayerContainer playerContainer) {
public Destination getDestination(String name) {
return destinationCache.get(name);
}

public boolean teleportToDestination(String name, PlayerContainer playerContainer) {
if(this.destinationRepository.containsKey(name)) {
playerContainer.teleport(this.destinationRepository.get(name).getLoc());
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ public void postActivated(TagTarget target, PlayerContainer player, ActivationDa

switch (executionCommand) {
case '!':
player.performCommand(formattedCommand.substring(1), CommandLevel.OP);
player.getServer().dispatchCommand(player.getUUID(), formattedCommand.substring(1), CommandLevel.OP);
break;
case '#':
player.performCommand(formattedCommand.substring(1), CommandLevel.CONSOLE);
player.getServer().dispatchCommand(player.getUUID(), formattedCommand.substring(1), CommandLevel.CONSOLE);
break;
case '^':
player.performCommand(formattedCommand.substring(1), CommandLevel.STAR);
player.getServer().dispatchCommand(player.getUUID(), formattedCommand.substring(1), CommandLevel.PERMISSION_WILDCARD);
break;
default:
player.performCommand(formattedCommand, CommandLevel.PLAYER);
player.getServer().dispatchCommand(player.getUUID(), formattedCommand, CommandLevel.PLAYER);
break;
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ public boolean created(TagTarget target, PlayerContainer player, String[] argDat
yield true;
}
case '^' -> {
if (!player.hasPermission("advancedportals.createportal.commandlevel.star")) {
if (!player.hasPermission("advancedportals.createportal.commandlevel.permswild")) {
player.sendMessage(Lang.translate("tag.command.nopermission")
.replaceAll("@CommandLevel", "*"));
yield false;
Expand All @@ -124,7 +124,7 @@ public void destroyed(TagTarget target, PlayerContainer player, String[] argData

public enum CommandLevel{
OP,
STAR,
PERMISSION_WILDCARD,
CONSOLE,
PLAYER
}
Expand Down
7 changes: 7 additions & 0 deletions lang/src/main/resources/lang/en_GB.lang
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ command.portal.show.enabled= Portal markers are now enabled.
command.portal.show.disabled= Portal markers are now disabled.
command.portal.show.unsupported= Portal markers are not supported on this version of minecraft. (1.16+ atm only)

command.destination.noname=No destination by that name was found

command.destination.remove.error= There was a problem removing the destination.
command.destination.remove.complete= The destination has been successfully removed.

Expand All @@ -95,6 +97,11 @@ command.destination.show.enabled= Destination markers are now enabled.
command.destination.show.disabled= Destination markers are now disabled.
command.destination.show.unsupported= Destination markers are not supported on this version of minecraft. (1.16+ atm only)

command.destination.teleport.help=Teleports to specified destination.
command.destination.teleport.detailedhelp=Teleports to destination given by the name of the destination.
command.destination.teleport.error=There was an error teleporting to your destination (@destiname).
command.destination.teleport.success=You have teleported to destination (@destiname).

command.destination.reload.help=Reloads the destination data from the repository.
command.destination.reload.detailedhelp=This command will reload all destination data from the repository, updating the cache with the latest data.
command.destination.reload= Destinations reloaded.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void dispatchCommand(UUID uuid, String command, CommandTag.CommandLevel c
case PLAYER:
server.dispatchCommand(player, command);
break;
case OP, STAR:
case OP, PERMISSION_WILDCARD:
executeCommandWithPermission(player, server, command, commandLevel);
break;
}
Expand All @@ -89,8 +89,8 @@ public String getName() {
// Execute commands with elevated permissions method
private void executeCommandWithPermission (Player player, Server server, String command, CommandTag.CommandLevel commandLevel) {
switch (commandLevel) {
case STAR:
if(player.hasPermission("*")) {
case PERMISSION_WILDCARD:
if (player.hasPermission("*")) {
server.dispatchCommand(player, command);
return;
}
Expand All @@ -103,7 +103,7 @@ private void executeCommandWithPermission (Player player, Server server, String
}
break;
case OP:
if(player.isOp()) {
if (player.isOp()) {
server.dispatchCommand(player, command);
return;
}
Expand Down
10 changes: 5 additions & 5 deletions spigot/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
main: com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin
name: AdvancedPortals
version: 1.0.0
version: ${pluginVersion}
author: sekwah41
description: An advanced portals plugin for bukkit.
api-version: 1.13
Expand Down Expand Up @@ -30,13 +30,13 @@ permissions:
default: false
children:
advancedportals.createportal.commandlevel.op: true
advancedportals.createportal.commandlevel.star: true
advancedportals.createportal.commandlevel.permswild: true
advancedportals.createportal.commandlevel.console: true
advancedportals.createportal.commandlevel.op:
description: Allows you to increase the users level temporaily to op
description: Allows you to increase the users level temporarily to op
default: false
advancedportals.createportal.commandlevel.star:
description: Allows you to increase the users level temporaily to have all perms
advancedportals.createportal.commandlevel.permswild:
description: Allows you to increase the users level temporarily to have all perms
default: false
advancedportals.createportal.commandlevel.console:
description: Executes command in the console
Expand Down

0 comments on commit b164f1c

Please sign in to comment.