Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Update v1.1.0
Browse files Browse the repository at this point in the history
Added broadcast customization and controlling
  • Loading branch information
Xenophilicy committed Mar 12, 2020
1 parent 60afdce commit 9443a22
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 13 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
# [![Xenophilicy](https://file.xenoservers.net/Resources/GitHub-Resources/MaxEnchants/screenshot.png)]()

## Information
MaxEnchants is a simple plugin to allow servers to take full advantage of the enchanting of items. You can enchant items and blocks with any level of enchantment and they will perform just as if that was enchanted with the normal server command! You use the same command to enchant with and the exact same sytax. The only difference here is that the levels can be had up to 32k!
MaxEnchants is a simple plugin to allow servers to take full advantage of the enchanting of items. You can enchant items and blocks with any level of enchantment and they will perform just as if that was enchanted with the normal server command! You use the same command to enchant with and the exact same syntax. The only difference here is that the levels can be had up to 32k!

***

## MaxEnchants Details
* **API:** 3.0.0+
* **Version:** 1.0.0
* **Version:** 1.1.0
* **Basic Description:** Enchant items up to level 32k!
* *Easy commands for use*
* *Simple code for editing and debugging*
***

Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: MaxEnchants
author: Xenophilicy
version: 1.0.0
version: 1.1.0
main: Xenophilicy\MaxEnchants\MaxEnchants
api: 3.0.0
description: Enable enchants up to level 32k!
Expand Down
21 changes: 20 additions & 1 deletion resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,31 @@
# $$ | / \__$$ |
# $$ | $$ $$/
# $$/ $$$$$$/
VERSION: "1.0.0" # Internal use only
VERSION: "1.1.0" # Internal use only

# This is the max allowed enchanting level with the command in-game
# Minecraft: Bedrock Edition has a maximum of 32767 enchantment levels
Max-Level: 5000

# Here you can specify enchantment broadcast message settings
Broadcast:

# Choose who should receive the broadcast messages
# Options are sender, target, console
# Add any number of recipients to this key
# Leave blank if you want no broadcasts
SendTo:
- "sender"
- "console"

# This is the message that will be broadcasted to the selected recipients
# Available tags are:
# {name} → name of enchantment
# {level} → level of enchantment
# {target} → recipient player
# {sender} → command provoker
Message: "§a{sender} added §b{name} §alevel §b{level} §afor {target}"

Command:

# This is name of the command that will be executed to use the plugin
Expand Down
51 changes: 43 additions & 8 deletions src/Xenophilicy/MaxEnchants/MaxEnchants.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,22 @@ public function onEnable(){
$this->config->getAll();
$version = $this->config->get("VERSION");
$this->pluginVersion = $this->getDescription()->getVersion();
if($version < "1.0.0"){
if($version < "1.1.0"){
$this->getLogger()->warning("You have updated MaxEnchants to v".$this->pluginVersion." but have a config from v$version! Please delete your old config for new features to be enabled and to prevent unwanted errors! Plugin will remain disabled...");
$pluginManager->disablePlugin($this);
}
$include = $this->config->getNested("Broadcast.SendTo");
if($include !== "" && $include !== null){
foreach($include as $inclusion){
if(strtolower($inclusion) == "console" || strtolower($inclusion) == "sender" || strtolower($inclusion) == "target"){
continue;
} else{
$this->getLogger()->critical("Invalid message recipient list, allowed recipients are console, sender, and target. Plugin will remain disabled...");
$pluginManager->disablePlugin($this);
return;
}
}
}
$this->maxLevel = $this->config->get("Max-Level") >= 32767 ? 32767:$this->config->get("Max-Level");
$this->cmdName = str_replace("/","",$this->config->getNested("Command.Name"));
if($this->cmdName == null || $this->cmdName == ""){
Expand Down Expand Up @@ -73,7 +85,7 @@ private function buildVanillaEnchantArray() : void{
break;
}
$enchantment = Enchantment::getEnchantment($id);
if ($enchantment instanceof Enchantment) {
if($enchantment instanceof Enchantment){
$this->vanillaEnchants[$enchantment->getName()] = ucwords(strtolower(str_replace("_", " ", $name)));
}
}
Expand Down Expand Up @@ -121,7 +133,34 @@ private function enchantItem(CommandSender $sender, array $args) : void{
$item->addEnchantment(new EnchantmentInstance($enchantment, $level));
$player->getInventory()->setItemInHand($item);
$enchantmentName = $this->vanillaEnchants[$enchantment->getName()] ?? $enchantment->getName();
$this->getServer()->broadcastMessage(TF::GREEN."Successfully added ".TF::BLUE.$enchantmentName.TF::GREEN." level ".TF::BLUE.$level.TF::GREEN." for ".$player->getName());
$this->broadcast($enchantmentName, $level, $player, $sender);
return;
}

private function broadcast(string $name, string $level, Player $target, $sender) : void{
$msgString = $this->config->getNested("Broadcast.Message");
$include = $this->config->getNested("Broadcast.SendTo");
$msgString = str_replace("{name}", $name, $msgString);
$msgString = str_replace("{level}", $level, $msgString);
$msgString = str_replace("{target}", $target->getName(), $msgString);
if($sender instanceof Player){
$msgString = str_replace("{sender}", $sender->getName(), $msgString);
} else{
$msgString = str_replace("{sender}", "CONSOLE", $msgString);
}
$msgString = str_replace("&", "§", $msgString);
if($include !== "" && $include !== null && $include !== []){
$include = strtolower(implode(",", $include));
if(strpos($include, "console") !== false){
$this->getLogger()->info(TF::clean($msgString));
}
if(strpos($include, "target") !== false){
$target->sendMessage($msgString);
}
if(strpos($include, "sender") !== false && $sender instanceof Player){
$sender->sendMessage($msgString);
}
}
return;
}

Expand All @@ -134,11 +173,7 @@ public function onCommand(CommandSender $sender, Command $command, string $label
$sender->sendMessage(TF::GRAY."-------------------");
}
if($command->getName() == $this->cmdName){
if($sender instanceof Player){
$this->enchantItem($sender, $args);
} else{
$sender->sendMessage(TF::RED."This is an in-game command only!");
}
$this->enchantItem($sender, $args);
}
return true;
}
Expand Down

0 comments on commit 9443a22

Please sign in to comment.