forked from ChestShop-authors/ChestShop-3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add setaddmount and setprice commands
- Loading branch information
1 parent
1a57c66
commit eff32a1
Showing
6 changed files
with
166 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/com/Acrobot/ChestShop/Commands/SetAmount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.Acrobot.ChestShop.Commands; | ||
|
||
import com.Acrobot.ChestShop.Configuration.Messages; | ||
import com.Acrobot.ChestShop.Signs.ChestShopSign; | ||
import static com.Acrobot.ChestShop.Permission.ADMIN; | ||
|
||
import com.Acrobot.ChestShop.ChestShop; | ||
import com.Acrobot.ChestShop.Permission; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.Sign; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.block.SignChangeEvent; | ||
import org.bukkit.util.RayTraceResult; | ||
|
||
public class SetAmount implements CommandExecutor { | ||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (!(sender instanceof Player)) { | ||
return false; | ||
} | ||
|
||
if (!Permission.has(sender, Permission.SET_AMOUNT_COMMAND)) { | ||
sender.sendMessage(Messages.ACCESS_DENIED); | ||
return true; | ||
} | ||
|
||
Player player = (Player) sender; | ||
RayTraceResult result = player.rayTraceBlocks(8); | ||
Block signBlock = null; | ||
if (result != null) { | ||
signBlock = result.getHitBlock(); | ||
} | ||
if (signBlock == null || !ChestShopSign.isValid(signBlock)) { | ||
sender.sendMessage(Messages.MUST_LOOK_AT_SHOP_SIGN); | ||
return true; | ||
} | ||
|
||
Sign sign = (Sign) signBlock.getState(); | ||
if (!ChestShopSign.canAccess(player, sign) && !Permission.has(player, ADMIN)) { | ||
sender.sendMessage(Messages.ACCESS_DENIED); | ||
return true; | ||
} | ||
|
||
String newAmountLine = String.join(" ", args); | ||
String[] line = sign.getLines(); | ||
line[1] = newAmountLine; | ||
if (!ChestShopSign.isValidPreparedSign(line)) { | ||
sender.sendMessage(Messages.INVALID_AMOUNT_LINE); | ||
return true; | ||
} | ||
|
||
SignChangeEvent event = new SignChangeEvent(signBlock, player, line); | ||
ChestShop.getPlugin().getServer().getPluginManager().callEvent(event); | ||
if (event.isCancelled()) { | ||
sender.sendMessage(Messages.SHOP_UPDATE_FAILED); | ||
return true; | ||
} | ||
|
||
line = event.getLines(); | ||
|
||
for (int i = 0; i < line.length; i++) { | ||
sign.setLine(i, line[i]); | ||
} | ||
sign.update(); | ||
return true; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/com/Acrobot/ChestShop/Commands/SetPrice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.Acrobot.ChestShop.Commands; | ||
|
||
import com.Acrobot.ChestShop.Configuration.Messages; | ||
import com.Acrobot.ChestShop.Signs.ChestShopSign; | ||
import static com.Acrobot.ChestShop.Permission.ADMIN; | ||
|
||
import com.Acrobot.ChestShop.ChestShop; | ||
import com.Acrobot.ChestShop.Permission; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.Sign; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.block.SignChangeEvent; | ||
import org.bukkit.util.RayTraceResult; | ||
|
||
public class SetPrice implements CommandExecutor { | ||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (!(sender instanceof Player)) { | ||
return false; | ||
} | ||
|
||
if (!Permission.has(sender, Permission.SET_PRICE_COMMAND)) { | ||
sender.sendMessage(Messages.ACCESS_DENIED); | ||
return true; | ||
} | ||
|
||
Player player = (Player) sender; | ||
RayTraceResult result = player.rayTraceBlocks(8); | ||
Block signBlock = null; | ||
if (result != null) { | ||
signBlock = result.getHitBlock(); | ||
} | ||
if (signBlock == null || !ChestShopSign.isValid(signBlock)) { | ||
sender.sendMessage(Messages.MUST_LOOK_AT_SHOP_SIGN); | ||
return true; | ||
} | ||
|
||
Sign sign = (Sign) signBlock.getState(); | ||
if (!ChestShopSign.canAccess(player, sign) && !Permission.has(player, ADMIN)) { | ||
sender.sendMessage(Messages.ACCESS_DENIED); | ||
return true; | ||
} | ||
|
||
String newPriceLine = String.join(" ", args); | ||
String[] line = sign.getLines(); | ||
line[2] = newPriceLine; | ||
if (!ChestShopSign.isValidPreparedSign(line)) { | ||
sender.sendMessage(Messages.INVALID_PRICE_LINE); | ||
return true; | ||
} | ||
|
||
SignChangeEvent event = new SignChangeEvent(signBlock, player, line); | ||
ChestShop.getPlugin().getServer().getPluginManager().callEvent(event); | ||
if (event.isCancelled()) { | ||
sender.sendMessage(Messages.SHOP_UPDATE_FAILED); | ||
return true; | ||
} | ||
|
||
line = event.getLines(); | ||
|
||
for (int i = 0; i < line.length; i++) { | ||
sign.setLine(i, line[i]); | ||
} | ||
sign.update(); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters