Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Resource pack send command - 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YanisBft committed Jul 29, 2021
1 parent 8546120 commit b8d3484
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ An API to help creating plugins for PeaceAndCube
Various useful commands
- ``/removealltags <target> [<except>]`` to remove all scoreboard tags from the target. The tag specified in ``except`` will be ignored.
- ``/chrono (start|end) <target>`` to start or end a player timer.
- ``/resourcepack send <target> <url>`` to send a resource pack to a target.

### Date
- ``Chrono`` provides a player-specific timer that can be started and ended.
Expand Down
74 changes: 74 additions & 0 deletions src/fr/peaceandcube/pacpi/command/ResourcePackCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package fr.peaceandcube.pacpi.command;

import fr.peaceandcube.pacpi.player.PlayerMessages;
import fr.peaceandcube.pacpi.player.PlayerSuggestionProviders;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class ResourcePackCommand implements CommandExecutor, TabExecutor {
public static final Plugin PLUGIN = Bukkit.getPluginManager().getPlugin("pAcPI");

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("pacpi.resourcepack")) {
switch (args[0]) {
case "send":
if (args.length == 3) {
Player player = Bukkit.getPlayer(args[1]);
String url = args[2];

try {
new URL(url);
} catch (MalformedURLException e) {
sender.sendMessage(PlayerMessages.PACK_URL_INVALID);
return true;
}

if (!Bukkit.getOnlinePlayers().contains(player)) {
sender.sendMessage(PlayerMessages.PLAYER_NOT_FOUND);
return true;
}

player.sendMessage(PlayerMessages.PACK_SENT);
Bukkit.getScheduler().runTaskLaterAsynchronously(PLUGIN, new Runnable() {
@Override
public void run() {
player.setResourcePack(url);
}
}, 2 * 20);

return true;
}
}
}

return false;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
List<String> options = new ArrayList<>();

if (sender.hasPermission("pacpi.resourcepack")) {
switch (args.length) {
case 1:
options.add("send");
break;
case 2:
return PlayerSuggestionProviders.getOnlinePlayers(args[1]);
}
}

return options;
}
}
4 changes: 3 additions & 1 deletion src/fr/peaceandcube/pacpi/pAcPI.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package fr.peaceandcube.pacpi;

import fr.peaceandcube.pacpi.command.ResourcePackCommand;
import fr.peaceandcube.pacpi.event.PlayerEventHandler;
import org.bukkit.plugin.java.JavaPlugin;

import fr.peaceandcube.pacpi.command.ChronoCommand;
import fr.peaceandcube.pacpi.command.RemoveAllTagsCommand;

public class pAcPI extends JavaPlugin {

@Override
public void onEnable() {
this.getCommand("removealltags").setExecutor(new RemoveAllTagsCommand());
this.getCommand("chrono").setExecutor(new ChronoCommand());
this.getCommand("resourcepack").setExecutor(new ResourcePackCommand());

this.getServer().getPluginManager().registerEvents(new PlayerEventHandler(), this);
}
Expand Down
4 changes: 4 additions & 0 deletions src/fr/peaceandcube/pacpi/player/PlayerMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class PlayerMessages {
public static final String CHRONO_ENDED = info("Tu as fait un temps de %s !");
public static final String CHRONO_NOT_STARTED = error("%s n'a pas de chrono démarré.");

// resourcepack command
public static final String PACK_URL_INVALID = error("L'adresse du pack de ressources est invalide.");
public static final String PACK_SENT = info("Un pack de ressources va être téléchargé !");

public static String error(String msg) {
return ChatColor.RED + msg;
}
Expand Down
10 changes: 9 additions & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
main: fr.peaceandcube.pacpi.pAcPI
name: pAcPI
version: 1.2.1
version: 1.3.0
author: YanisBft
website: https://github.com/PeaceAndCubeMC/pAcPI
api-version: 1.17
Expand All @@ -16,6 +16,11 @@ commands:
permission: pacpi.chrono
permission-message: §cYou do not have the permission to use this command.
usage: "§eUsage: §r/chrono (start|end) <player>"
resourcepack:
description: Allows you to send resource packs to a player
permission: pacpi.resourcepack
permission-message: §cYou do not have the permission to use this command.
usage: "§eUsage: §r/resourcepack send <player> <url>"

permissions:
pacpi.removealltags:
Expand All @@ -24,3 +29,6 @@ permissions:
pacpi.chrono:
description: Permission to use the /chrono command
default: op
pacpi.resourcepack:
description: Permission to use the /resourcepack command
default: op

0 comments on commit b8d3484

Please sign in to comment.