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

Commit 9443a22

Browse files
committed
Update v1.1.0
Added broadcast customization and controlling
1 parent 60afdce commit 9443a22

File tree

4 files changed

+66
-13
lines changed

4 files changed

+66
-13
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
# [![Xenophilicy](https://file.xenoservers.net/Resources/GitHub-Resources/MaxEnchants/screenshot.png)]()
77

88
## Information
9-
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!
9+
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!
1010

1111
***
1212

1313
## MaxEnchants Details
1414
* **API:** 3.0.0+
15-
* **Version:** 1.0.0
15+
* **Version:** 1.1.0
1616
* **Basic Description:** Enchant items up to level 32k!
17-
* *Easy commands for use*
1817
* *Simple code for editing and debugging*
1918
***
2019

plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: MaxEnchants
22
author: Xenophilicy
3-
version: 1.0.0
3+
version: 1.1.0
44
main: Xenophilicy\MaxEnchants\MaxEnchants
55
api: 3.0.0
66
description: Enable enchants up to level 32k!

resources/config.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,31 @@
1111
# $$ | / \__$$ |
1212
# $$ | $$ $$/
1313
# $$/ $$$$$$/
14-
VERSION: "1.0.0" # Internal use only
14+
VERSION: "1.1.0" # Internal use only
1515

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

20+
# Here you can specify enchantment broadcast message settings
21+
Broadcast:
22+
23+
# Choose who should receive the broadcast messages
24+
# Options are sender, target, console
25+
# Add any number of recipients to this key
26+
# Leave blank if you want no broadcasts
27+
SendTo:
28+
- "sender"
29+
- "console"
30+
31+
# This is the message that will be broadcasted to the selected recipients
32+
# Available tags are:
33+
# {name} → name of enchantment
34+
# {level} → level of enchantment
35+
# {target} → recipient player
36+
# {sender} → command provoker
37+
Message: "§a{sender} added §b{name} §alevel §b{level} §afor {target}"
38+
2039
Command:
2140

2241
# This is name of the command that will be executed to use the plugin

src/Xenophilicy/MaxEnchants/MaxEnchants.php

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,22 @@ public function onEnable(){
3232
$this->config->getAll();
3333
$version = $this->config->get("VERSION");
3434
$this->pluginVersion = $this->getDescription()->getVersion();
35-
if($version < "1.0.0"){
35+
if($version < "1.1.0"){
3636
$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...");
3737
$pluginManager->disablePlugin($this);
3838
}
39+
$include = $this->config->getNested("Broadcast.SendTo");
40+
if($include !== "" && $include !== null){
41+
foreach($include as $inclusion){
42+
if(strtolower($inclusion) == "console" || strtolower($inclusion) == "sender" || strtolower($inclusion) == "target"){
43+
continue;
44+
} else{
45+
$this->getLogger()->critical("Invalid message recipient list, allowed recipients are console, sender, and target. Plugin will remain disabled...");
46+
$pluginManager->disablePlugin($this);
47+
return;
48+
}
49+
}
50+
}
3951
$this->maxLevel = $this->config->get("Max-Level") >= 32767 ? 32767:$this->config->get("Max-Level");
4052
$this->cmdName = str_replace("/","",$this->config->getNested("Command.Name"));
4153
if($this->cmdName == null || $this->cmdName == ""){
@@ -73,7 +85,7 @@ private function buildVanillaEnchantArray() : void{
7385
break;
7486
}
7587
$enchantment = Enchantment::getEnchantment($id);
76-
if ($enchantment instanceof Enchantment) {
88+
if($enchantment instanceof Enchantment){
7789
$this->vanillaEnchants[$enchantment->getName()] = ucwords(strtolower(str_replace("_", " ", $name)));
7890
}
7991
}
@@ -121,7 +133,34 @@ private function enchantItem(CommandSender $sender, array $args) : void{
121133
$item->addEnchantment(new EnchantmentInstance($enchantment, $level));
122134
$player->getInventory()->setItemInHand($item);
123135
$enchantmentName = $this->vanillaEnchants[$enchantment->getName()] ?? $enchantment->getName();
124-
$this->getServer()->broadcastMessage(TF::GREEN."Successfully added ".TF::BLUE.$enchantmentName.TF::GREEN." level ".TF::BLUE.$level.TF::GREEN." for ".$player->getName());
136+
$this->broadcast($enchantmentName, $level, $player, $sender);
137+
return;
138+
}
139+
140+
private function broadcast(string $name, string $level, Player $target, $sender) : void{
141+
$msgString = $this->config->getNested("Broadcast.Message");
142+
$include = $this->config->getNested("Broadcast.SendTo");
143+
$msgString = str_replace("{name}", $name, $msgString);
144+
$msgString = str_replace("{level}", $level, $msgString);
145+
$msgString = str_replace("{target}", $target->getName(), $msgString);
146+
if($sender instanceof Player){
147+
$msgString = str_replace("{sender}", $sender->getName(), $msgString);
148+
} else{
149+
$msgString = str_replace("{sender}", "CONSOLE", $msgString);
150+
}
151+
$msgString = str_replace("&", "§", $msgString);
152+
if($include !== "" && $include !== null && $include !== []){
153+
$include = strtolower(implode(",", $include));
154+
if(strpos($include, "console") !== false){
155+
$this->getLogger()->info(TF::clean($msgString));
156+
}
157+
if(strpos($include, "target") !== false){
158+
$target->sendMessage($msgString);
159+
}
160+
if(strpos($include, "sender") !== false && $sender instanceof Player){
161+
$sender->sendMessage($msgString);
162+
}
163+
}
125164
return;
126165
}
127166

@@ -134,11 +173,7 @@ public function onCommand(CommandSender $sender, Command $command, string $label
134173
$sender->sendMessage(TF::GRAY."-------------------");
135174
}
136175
if($command->getName() == $this->cmdName){
137-
if($sender instanceof Player){
138-
$this->enchantItem($sender, $args);
139-
} else{
140-
$sender->sendMessage(TF::RED."This is an in-game command only!");
141-
}
176+
$this->enchantItem($sender, $args);
142177
}
143178
return true;
144179
}

0 commit comments

Comments
 (0)