Advertisement
misamisk

Code

Oct 19th, 2020 (edited)
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.69 KB | None | 0 0
  1. package ua.whitebear60.beehive.cmd;
  2.  
  3. import net.minecraft.command.CommandBase;
  4. import net.minecraft.command.CommandException;
  5. import net.minecraft.command.ICommandSender;
  6. import net.minecraft.server.MinecraftServer;
  7. import net.minecraft.util.text.ITextComponent;
  8. import net.minecraft.util.text.TextComponentString;
  9. import net.minecraft.util.text.TextComponentTranslation;
  10. import net.minecraft.util.text.TextFormatting;
  11. import net.minecraft.util.text.event.ClickEvent;
  12. import net.minecraft.world.GameType;
  13. import org.apache.logging.log4j.LogManager;
  14. import org.apache.logging.log4j.Logger;
  15. import ua.whitebear60.beehive.Reference;
  16.  
  17. import java.util.*;
  18.  
  19. /*
  20.  * Originally coded by HellFirePvP, modified by WhiteBear60 for the Beehive modpack needs
  21.  */
  22.  
  23. public class CommandBeehive extends CommandBase {
  24.   private ITextComponent newLine = new TextComponentString("\n");
  25.  
  26.  
  27.   private static ITextComponent separator = new TextComponentString("===========\n");
  28.  
  29.   private static Logger logger = LogManager.getLogger(Reference.NAME);
  30.   private static final String[] COMMANDS = new String[]{
  31.           "help",
  32.           "start",
  33.           "test"
  34.   };
  35.  
  36.   private List<String> cmdAliases = new ArrayList<>();
  37.  
  38.   public CommandBeehive() {
  39.     this.cmdAliases.add("beehive");
  40.     this.cmdAliases.add("bee");
  41.   }
  42.  
  43.   @Override
  44.   public String getName() {
  45.     return "beehive";
  46.   }
  47.  
  48.   @Override
  49.   public String getUsage(ICommandSender sender) {
  50.     return "/beehive <action>";
  51.   }
  52.  
  53.   @Override
  54.   public List<String> getAliases() {
  55.     return cmdAliases;
  56.   }
  57.  
  58.   @Override
  59.   public boolean isUsernameIndex(String[] args, int index) {
  60.     return index == 1;
  61.   }
  62.  
  63.   @Override
  64.   public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
  65.  
  66.     ITextComponent only_once = new TextComponentTranslation("beehive.cmd.has_tag");
  67.  
  68.     HashSet<String> senderTags = new HashSet<String>(sender.getCommandSenderEntity().getTags());
  69.     if (args.length == 0) {
  70.       senderTags.clear();
  71.       senderTags.addAll(sender.getCommandSenderEntity().getTags());
  72.       logger.info("Displaying help...");
  73.       logger.info("The player tags are: " + senderTags);
  74.       displayHelp(sender);
  75.       return;
  76.     }
  77.     if (args.length == 1) {
  78.       String identifier = args[0];
  79.       if ("help".equalsIgnoreCase(identifier)) {
  80.         displayHelp(sender);
  81.       } else if ("start".equalsIgnoreCase(identifier)) {
  82.         // TODO: Move welcome text here and make it translatable.
  83.         if (senderTags.contains("start1")) {
  84.           sender.sendMessage(only_once);
  85.           logger.warn(sender.getName() + " is trying to execute start command more than once.");
  86.           logger.info("The player tags are: " + senderTags);
  87.         }
  88.         if (!senderTags.contains("start1")) {
  89.           ITextComponent welcomeText1 = new TextComponentTranslation("beehive.welcome");
  90.           welcomeText1.getStyle().setColor(TextFormatting.YELLOW);
  91.           ITextComponent welcomeText2 = new TextComponentTranslation("beehive.welcome.page1.c1");
  92.           welcomeText2.getStyle().setColor(TextFormatting.YELLOW);
  93.           ITextComponent welcomeText3 = new TextComponentTranslation("beehive.welcome.page1.c2");
  94.           welcomeText3.getStyle().setColor(TextFormatting.WHITE);
  95.           ITextComponent welcomeText4 = new TextComponentTranslation("beehive.welcome.page1.c3");
  96.           // /millSpawnVillage byzantines tradingvillage 508 497
  97.           welcomeText4.getStyle().setColor(TextFormatting.GREEN).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/say @a Byzantines village is preparing to spawn"));
  98. //                        sender.sendMessage(welcomeText2);
  99.           ITextComponent welcomeText5 = new TextComponentTranslation("beehive.welcome.page1.c4");
  100.           // /millSpawnVillage seljuk agriculture_village_seljuks 508 497
  101.           welcomeText5.getStyle().setColor(TextFormatting.GREEN).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/say @a Seljuk Turks village is preparing to spawn"));
  102.           ITextComponent welcomeText6 = new TextComponentTranslation("beehive.welcome.page1.c5");
  103.           // /millSpawnVillage japanese seiji 508 497
  104.           welcomeText6.getStyle().setColor(TextFormatting.GREEN).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/say @a Japanese village is preparing to spawn"));
  105.           ITextComponent welcomeText7 = new TextComponentTranslation("beehive.welcome.page1.to_next_page");
  106.           welcomeText7.getStyle().setColor(TextFormatting.AQUA);
  107.           ITextComponent welcomeText8 = new TextComponentTranslation("beehive.welcome.click_here");
  108.           welcomeText8.getStyle().setColor(TextFormatting.GREEN).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/beehive start 1"));
  109.           ITextComponent result = welcomeText1.appendSibling(new TextComponentString(" ")).appendSibling(welcomeText2).appendSibling(new TextComponentString(" ")).appendSibling(welcomeText3).appendSibling(newLine).appendSibling(welcomeText4).appendSibling(newLine).appendSibling(welcomeText5).appendSibling(newLine).appendSibling(welcomeText6).appendSibling(newLine).appendSibling(welcomeText7).appendSibling(new TextComponentString(" ")).appendSibling(welcomeText8);
  110. //          sender.getCommandSenderEntity().addTag("start1");
  111.           sender.sendMessage(result);
  112.         }
  113. //                    BlockPos pos = sender.getPosition();
  114. //                    double px = pos.getX();
  115. //                    double py = 10;
  116. //                    double pz = pos.getZ();
  117. //                    server.getCommandManager().executeCommand( server, "/tp " + sender.getName() + " " + px + " " + py + " " + pz );
  118.       } else if ("test".equalsIgnoreCase(identifier)) {
  119. //                    sender.sendMessage(new TextComponentTranslation("beehive.keyhole.success"));
  120.         sender.sendMessage(new TextComponentString("Test is not implemented yet."));
  121.       }
  122.     } else if (args.length == 2) {
  123.       String identifier = args[1];
  124.       if ("1".equalsIgnoreCase(identifier)) {
  125.         if (senderTags.contains("start2")) {
  126.           sender.sendMessage(only_once);
  127.           logger.warn(sender.getName() + " is trying to execute start command more than once.");
  128.           logger.info("The player tags are: " + senderTags);
  129.         } if (!senderTags.contains("start2")) {
  130.           ITextComponent two_hive = new TextComponentTranslation("beehive.welcome.page2.c1");
  131.           two_hive.getStyle().setColor(TextFormatting.YELLOW);
  132.  
  133.           ITextComponent sizes = new TextComponentTranslation("beehive.welcome.page2.c2");
  134.           sizes.getStyle().setColor(TextFormatting.YELLOW);
  135.  
  136.           ITextComponent tp = new TextComponentTranslation("beehive.welcome.page2.c3");
  137.           tp.getStyle().setColor(TextFormatting.YELLOW);
  138.  
  139.           ITextComponent proceed = new TextComponentTranslation("beehive.welcome.page2.c4");
  140.           proceed.getStyle().setColor(TextFormatting.YELLOW);
  141.  
  142.           ITextComponent click_here = new TextComponentTranslation("beehive.welcome.click_here");
  143.           click_here.getStyle().setColor(TextFormatting.GREEN).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/beehive start 2"));
  144.  
  145. //          sender.getCommandSenderEntity().addTag("start2");
  146.           sender.sendMessage(separator.appendSibling(two_hive).appendSibling(new TextComponentString(" ")).appendSibling(sizes).appendSibling(new TextComponentString(" ")).appendSibling(tp).appendSibling(new TextComponentString(" ")).appendSibling(proceed).appendSibling(new TextComponentString(" ")).appendSibling(click_here));
  147.         }
  148.       }
  149.       if ("2".equalsIgnoreCase(identifier)) {
  150.         if (senderTags.contains("start3")) {
  151.           sender.sendMessage(only_once);
  152.           logger.warn(sender.getName() + " is trying to execute start command more than once.");
  153.           logger.info("The player tags are: " + senderTags);
  154.         } if (!senderTags.contains("start3")) {
  155.  
  156.           ITextComponent has_tp = new TextComponentTranslation("beehive.welcome.page3.c1");
  157.           has_tp.getStyle().setColor(TextFormatting.YELLOW);
  158.           ITextComponent to_tp = new TextComponentTranslation("beehive.welcome.page3.c2");
  159.           to_tp.getStyle().setColor(TextFormatting.YELLOW);
  160.           ITextComponent big = new TextComponentTranslation("beehive.welcome.page3.c3");
  161.           big.getStyle().setColor(TextFormatting.YELLOW);
  162.           ITextComponent small = new TextComponentTranslation("beehive.welcome.page3.c4");
  163.           small.getStyle().setColor(TextFormatting.YELLOW);
  164.           ITextComponent village = new TextComponentTranslation("beehive.welcome.page3.c5");
  165.           village.getStyle().setColor(TextFormatting.YELLOW);
  166.  
  167.           ITextComponent goodluck = new TextComponentTranslation("beehive.goodluck");
  168.           goodluck.getStyle().setColor(TextFormatting.YELLOW);
  169.  
  170. //          sender.getCommandSenderEntity().addTag("start3");
  171.           sender.sendMessage(separator.appendSibling(has_tp).appendSibling(newLine).appendSibling(to_tp).appendSibling(newLine).appendSibling(big).appendSibling(newLine).appendSibling(small).appendSibling(newLine).appendSibling(village).appendSibling(newLine).appendSibling(newLine).appendSibling(goodluck));
  172.           server.commandManager.executeCommand(sender, "/tp " + sender.getName() + " -2 21 -503");
  173.  
  174.           getCommandSenderAsPlayer(sender).setGameType(GameType.SURVIVAL);
  175.  
  176.         }
  177.  
  178.       }
  179.     }
  180.   }
  181.  
  182.   private void displayHelp(ICommandSender sender) {
  183.     sender.sendMessage(new TextComponentString("\nAvialable Subcommands:"));
  184.     sender.sendMessage(new TextComponentString("§a/beehive start§7 - start the map"));
  185.     sender.sendMessage(new TextComponentString("§a/beehive help§7 - display this help"));
  186.   }
  187.  
  188. }
  189.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement