mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Sorry for merge conflicts :)
This commit is contained in:
parent
d04c95514e
commit
7d859661ba
@ -86,73 +86,7 @@ public class CommandIrisObjectAnalyze extends MortarCommand {
|
||||
Player p = sender.player();
|
||||
|
||||
J.a(() -> {
|
||||
IrisObject obj = IrisData.loadAnyObject(args[0]);
|
||||
|
||||
if (obj == null || obj.getLoadFile() == null) {
|
||||
sender.sendMessage("Can't find " + args[0] + " in the " + StudioSVC.WORKSPACE_NAME + " folder");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage("Object Size: " + obj.getW() + " * " + obj.getH() + " * " + obj.getD() + "");
|
||||
sender.sendMessage("Blocks Used: " + NumberFormat.getIntegerInstance().format(obj.getBlocks().size()));
|
||||
|
||||
Queue<BlockData> queue = obj.getBlocks().enqueueValues();
|
||||
Map<Material, Set<BlockData>> unsorted = new HashMap<>();
|
||||
Map<BlockData, Integer> amounts = new HashMap<>();
|
||||
Map<Material, Integer> materials = new HashMap<>();
|
||||
while (queue.hasNext()) {
|
||||
BlockData block = queue.next();
|
||||
|
||||
//unsorted.put(block.getMaterial(), block);
|
||||
|
||||
if (!amounts.containsKey(block)) {
|
||||
amounts.put(block, 1);
|
||||
|
||||
|
||||
} else
|
||||
amounts.put(block, amounts.get(block) + 1);
|
||||
|
||||
if (!materials.containsKey(block.getMaterial())) {
|
||||
materials.put(block.getMaterial(), 1);
|
||||
unsorted.put(block.getMaterial(), new HashSet<>());
|
||||
unsorted.get(block.getMaterial()).add(block);
|
||||
} else {
|
||||
materials.put(block.getMaterial(), materials.get(block.getMaterial()) + 1);
|
||||
unsorted.get(block.getMaterial()).add(block);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<Material> sortedMatsList = amounts.keySet().stream().map(BlockData::getMaterial)
|
||||
.sorted().collect(Collectors.toList());
|
||||
Set<Material> sortedMats = new TreeSet<>(Comparator.comparingInt(materials::get).reversed());
|
||||
sortedMats.addAll(sortedMatsList);
|
||||
sender.sendMessage("== Blocks in object ==");
|
||||
|
||||
int n = 0;
|
||||
for (Material mat : sortedMats) {
|
||||
int amount = materials.get(mat);
|
||||
List<BlockData> set = new ArrayList<>(unsorted.get(mat));
|
||||
set.sort(Comparator.comparingInt(amounts::get).reversed());
|
||||
BlockData data = set.get(0);
|
||||
int dataAmount = amounts.get(data);
|
||||
|
||||
String string = " - " + mat.toString() + "*" + amount;
|
||||
if (data.getAsString(true).contains("[")) {
|
||||
string = string + " --> [" + data.getAsString(true).split("\\[")[1]
|
||||
.replaceAll("true", ChatColor.GREEN + "true" + ChatColor.GRAY)
|
||||
.replaceAll("false", ChatColor.RED + "false" + ChatColor.GRAY) + "*" + dataAmount;
|
||||
}
|
||||
|
||||
sender.sendMessage(string);
|
||||
|
||||
n++;
|
||||
|
||||
if (n >= 10) {
|
||||
sender.sendMessage(" + " + (sortedMats.size() - n) + " other block types");
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.core.command.world;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.plugin.MortarCommand;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CommandLocate extends MortarCommand implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||
if (IrisToolbelt.isIrisWorld(event.getPlayer().getWorld())) {
|
||||
|
||||
// Make sure the command starts with /locate and does not locate stronghold
|
||||
if (event.getMessage().contains("/locate") && event.getMessage().contains("stronghold")) {
|
||||
return;
|
||||
}
|
||||
if (event.getMessage().contains("/locate")) {
|
||||
event.setCancelled(true); // Cancel the vanilla command process
|
||||
String command = event.getMessage().replace("/locate", "ir std goto");
|
||||
Bukkit.dispatchCommand(event.getPlayer(), command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CommandLocate() {
|
||||
super("locate");
|
||||
requiresPermission(Iris.perm);
|
||||
Iris.instance.registerListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(VolmitSender sender, String[] args) {
|
||||
Bukkit.dispatchCommand(sender, "/ir std goto " + Arrays.toString(args));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTabOptions(VolmitSender sender, String[] args, KList<String> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgsUsage() {
|
||||
return "[biome/region/structure]";
|
||||
}
|
||||
}
|
@ -42,6 +42,10 @@ public class DecIris implements DecreeExecutor {
|
||||
|
||||
private DecPregen pregen;
|
||||
|
||||
private DecSettings settings;
|
||||
|
||||
private DecObject object;
|
||||
|
||||
@Decree(description = "Create a new world", aliases = "+")
|
||||
public void create(
|
||||
@Param(aliases = "world-name", description = "The name of the world to create", defaultValue = "IrisWorld")
|
||||
|
86
src/main/java/com/volmit/iris/core/decrees/DecObject.java
Normal file
86
src/main/java/com/volmit/iris/core/decrees/DecObject.java
Normal file
@ -0,0 +1,86 @@
|
||||
package com.volmit.iris.core.decrees;
|
||||
|
||||
import com.volmit.iris.engine.object.objects.IrisObject;
|
||||
import com.volmit.iris.util.decree.DecreeExecutor;
|
||||
import com.volmit.iris.util.decree.DecreeOrigin;
|
||||
import com.volmit.iris.util.decree.annotations.Decree;
|
||||
import com.volmit.iris.util.decree.annotations.Param;
|
||||
import com.volmit.iris.util.scheduling.Queue;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Decree(name = "object", origin = DecreeOrigin.PLAYER, description = "Iris object manipulation")
|
||||
public class DecObject implements DecreeExecutor {
|
||||
|
||||
@Decree(description = "Check the composition of an object")
|
||||
public void analyze(
|
||||
@Param(description = "The object to analyze")
|
||||
IrisObject object
|
||||
) {
|
||||
sender().sendMessage("Object Size: " + object.getW() + " * " + object.getH() + " * " + object.getD() + "");
|
||||
sender().sendMessage("Blocks Used: " + NumberFormat.getIntegerInstance().format(object.getBlocks().size()));
|
||||
|
||||
Queue<BlockData> queue = object.getBlocks().enqueueValues();
|
||||
Map<Material, Set<BlockData>> unsorted = new HashMap<>();
|
||||
Map<BlockData, Integer> amounts = new HashMap<>();
|
||||
Map<Material, Integer> materials = new HashMap<>();
|
||||
while (queue.hasNext()) {
|
||||
BlockData block = queue.next();
|
||||
|
||||
//unsorted.put(block.getMaterial(), block);
|
||||
|
||||
if (!amounts.containsKey(block)) {
|
||||
amounts.put(block, 1);
|
||||
|
||||
|
||||
} else
|
||||
amounts.put(block, amounts.get(block) + 1);
|
||||
|
||||
if (!materials.containsKey(block.getMaterial())) {
|
||||
materials.put(block.getMaterial(), 1);
|
||||
unsorted.put(block.getMaterial(), new HashSet<>());
|
||||
unsorted.get(block.getMaterial()).add(block);
|
||||
} else {
|
||||
materials.put(block.getMaterial(), materials.get(block.getMaterial()) + 1);
|
||||
unsorted.get(block.getMaterial()).add(block);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<Material> sortedMatsList = amounts.keySet().stream().map(BlockData::getMaterial)
|
||||
.sorted().collect(Collectors.toList());
|
||||
Set<Material> sortedMats = new TreeSet<>(Comparator.comparingInt(materials::get).reversed());
|
||||
sortedMats.addAll(sortedMatsList);
|
||||
sender().sendMessage("== Blocks in object ==");
|
||||
|
||||
int n = 0;
|
||||
for (Material mat : sortedMats) {
|
||||
int amount = materials.get(mat);
|
||||
List<BlockData> set = new ArrayList<>(unsorted.get(mat));
|
||||
set.sort(Comparator.comparingInt(amounts::get).reversed());
|
||||
BlockData data = set.get(0);
|
||||
int dataAmount = amounts.get(data);
|
||||
|
||||
String string = " - " + mat.toString() + "*" + amount;
|
||||
if (data.getAsString(true).contains("[")) {
|
||||
string = string + " --> [" + data.getAsString(true).split("\\[")[1]
|
||||
.replaceAll("true", ChatColor.GREEN + "true" + ChatColor.GRAY)
|
||||
.replaceAll("false", ChatColor.RED + "false" + ChatColor.GRAY) + "*" + dataAmount;
|
||||
}
|
||||
|
||||
sender().sendMessage(string);
|
||||
|
||||
n++;
|
||||
|
||||
if (n >= 10) {
|
||||
sender().sendMessage(" + " + (sortedMats.size() - n) + " other block types");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
src/main/java/com/volmit/iris/core/service/LocateSVC.java
Normal file
33
src/main/java/com/volmit/iris/core/service/LocateSVC.java
Normal file
@ -0,0 +1,33 @@
|
||||
package com.volmit.iris.core.service;
|
||||
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.plugin.IrisService;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class LocateSVC implements IrisService {
|
||||
|
||||
@EventHandler
|
||||
public void on(final PlayerCommandPreprocessEvent event) {
|
||||
if (IrisToolbelt.isIrisWorld(event.getPlayer().getWorld())) {
|
||||
VolmitSender sender = new VolmitSender(event.getPlayer());
|
||||
sender.sendMessage(C.YELLOW + "You cannot locate structures in Iris worlds through vanilla commands");
|
||||
sender.sendMessage("You can use:");
|
||||
// TODO: Convert this to have the correct command prefix
|
||||
Bukkit.dispatchCommand(event.getPlayer(), "/ird studio find");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.volmit.iris.util.decree.handlers;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.engine.object.objects.IrisObject;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ObjectHandler implements DecreeParameterHandler<IrisObject> {
|
||||
@Override
|
||||
public KList<IrisObject> getPossibilities() {
|
||||
KMap<String, IrisObject> p = new KMap<>();
|
||||
|
||||
//noinspection ConstantConditions
|
||||
for (File i : Iris.instance.getDataFolder("packs").listFiles()) {
|
||||
if (i.isDirectory()) {
|
||||
IrisData data = new IrisData(i, true);
|
||||
for (IrisObject j : data.getObjectLoader().loadAll(data.getObjectLoader().getPossibleKeys())) {
|
||||
p.putIfAbsent(j.getLoadKey(), j);
|
||||
}
|
||||
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
return p.v();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(IrisObject irisObject) {
|
||||
return irisObject.getLoadKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisObject parse(String in) throws DecreeParsingException, DecreeWhichException {
|
||||
try {
|
||||
KList<IrisObject> options = getPossibilities(in);
|
||||
|
||||
if (options.isEmpty()) {
|
||||
throw new DecreeParsingException("Unable to find Object \"" + in + "\"");
|
||||
} else if (options.size() > 1) {
|
||||
throw new DecreeWhichException();
|
||||
}
|
||||
|
||||
return options.get(0);
|
||||
} catch (DecreeParsingException e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
throw new DecreeParsingException("Unable to find Object \"" + in + "\" because of an uncaught exception: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> type) {
|
||||
return type.equals(IrisObject.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault() {
|
||||
return "object";
|
||||
}
|
||||
}
|
@ -413,60 +413,64 @@ public class VolmitSender implements CommandSender {
|
||||
}
|
||||
|
||||
for (VirtualDecreeCommand i : v.getNodes()) {
|
||||
if (isPlayer()) {
|
||||
//@builder
|
||||
String s = (
|
||||
"<hover:show_text:'"+
|
||||
i.getNames().copy().reverse().convert((f) -> "<#42ecf5>" + f).toString(", ") + "\n"
|
||||
+ "<#3fe05a>✎ <#6ad97d><font:minecraft:uniform>" + i.getDescription() + "<reset>\n"
|
||||
+ "<#bbe03f>✒ <#a8e0a2>" + (i.isNode()
|
||||
? ((i.getNode().getParameters().isEmpty()
|
||||
? "<font:minecraft:uniform>There are no parameters.<reset>"
|
||||
: "<font:minecraft:uniform>Hover over all of the parameters to learn more.<reset>" + "\n"))
|
||||
: "<font:minecraft:uniform>This is a command category. Run <reset><#98eda5>" + i.getPath())
|
||||
+ (i.isNode()
|
||||
? (i.getNode().getParameters().isNotEmpty())
|
||||
? "<#aebef2>✦ <#5ef288><font:minecraft:uniform>"
|
||||
+ i.getParentPath()
|
||||
+ " <#42ecf5>"
|
||||
+ i.getName() + " "
|
||||
+ i.getNode().getParameters().convert((f)
|
||||
-> "<#d665f0>" + f.example())
|
||||
.toString(" ") + "\n"
|
||||
: ""
|
||||
: "")
|
||||
+ (i.isNode() ? "<font:minecraft:uniform>" + pickRandoms(Math.min(i.getNode().getParameters().size() + 1, 5), i) + "<reset>" : "")
|
||||
+ "'><click:" + (i.isNode() ? "suggest_command" : "run_command") + ":" + i.getPath() + " >"
|
||||
+ "<#46826a>⇀<gradient:#42ecf5:#428df5> " + i.getName() + "</click></hover>"
|
||||
+ (i.isNode() ?
|
||||
" " + i.getNode().getParameters().convert((f)
|
||||
-> "<hover:show_text:'"
|
||||
+ f.getNames().convert((ff) -> "<#d665f0>" + ff).toString(", ") + "\n"
|
||||
+ "<#3fe05a>✎ <#6ad97d><font:minecraft:uniform>" + f.getDescription() + "<reset>\n"
|
||||
+ (f.isRequired()
|
||||
? "<#db4321>⚠ <#faa796><font:minecraft:uniform>This parameter is required."
|
||||
: (f.hasDefault()
|
||||
? "<#2181db>✔ <#78dcf0><font:minecraft:uniform>Defaults to \""+f.getParam().defaultValue()+"\" if undefined."
|
||||
: "<#a73abd>✔ <#78dcf0><font:minecraft:uniform>This parameter is optional.")) + "<reset>\n"
|
||||
+ (f.isContextual() ? "<#ff9900>➱ <#ffcc00><font:minecraft:uniform>The value may be derived from environment context <reset>\n" : "")
|
||||
+ "<#cc00ff>✢ <#ff33cc><font:minecraft:uniform>This parameter is of type " + f.getType().getSimpleName()
|
||||
+ "'>"
|
||||
+ (f.isRequired() ? "<red>[" : "")
|
||||
+ "<gradient:#d665f0:#a37feb>" + f.getName()
|
||||
+ (f.isRequired() ? "<red>]<gray>" : "")
|
||||
+ "</hover>").toString(" ")
|
||||
: "<gradient:#afe3d3:#a2dae0> - Category of Commands"
|
||||
)
|
||||
);
|
||||
//@done
|
||||
sendMessageRaw(s);
|
||||
System.out.println(s);
|
||||
} else {
|
||||
sendMessage(i.getPath() + "()");
|
||||
}
|
||||
sendDecreeHelpNode(i);
|
||||
}
|
||||
} else {
|
||||
sendMessage(C.RED + "There are no subcommands in this group! Contact support, this is a command design issue!");
|
||||
}
|
||||
}
|
||||
|
||||
public void sendDecreeHelpNode(VirtualDecreeCommand i){
|
||||
if (isPlayer()) {
|
||||
//@builder
|
||||
String s = (
|
||||
"<hover:show_text:'"+
|
||||
i.getNames().copy().reverse().convert((f) -> "<#42ecf5>" + f).toString(", ") + "\n"
|
||||
+ "<#3fe05a>✎ <#6ad97d><font:minecraft:uniform>" + i.getDescription() + "<reset>\n"
|
||||
+ "<#bbe03f>✒ <#a8e0a2>" + (i.isNode()
|
||||
? ((i.getNode().getParameters().isEmpty()
|
||||
? "<font:minecraft:uniform>There are no parameters.<reset>"
|
||||
: "<font:minecraft:uniform>Hover over all of the parameters to learn more.<reset>" + "\n"))
|
||||
: "<font:minecraft:uniform>This is a command category. Run <reset><#98eda5>" + i.getPath())
|
||||
+ (i.isNode()
|
||||
? (i.getNode().getParameters().isNotEmpty())
|
||||
? "<#aebef2>✦ <#5ef288><font:minecraft:uniform>"
|
||||
+ i.getParentPath()
|
||||
+ " <#42ecf5>"
|
||||
+ i.getName() + " "
|
||||
+ i.getNode().getParameters().convert((f)
|
||||
-> "<#d665f0>" + f.example())
|
||||
.toString(" ") + "\n"
|
||||
: ""
|
||||
: "")
|
||||
+ (i.isNode() ? "<font:minecraft:uniform>" + pickRandoms(Math.min(i.getNode().getParameters().size() + 1, 5), i) + "<reset>" : "")
|
||||
+ "'><click:" + (i.isNode() ? "suggest_command" : "run_command") + ":" + i.getPath() + " >"
|
||||
+ "<#46826a>⇀<gradient:#42ecf5:#428df5> " + i.getName() + "</click></hover>"
|
||||
+ (i.isNode() ?
|
||||
" " + i.getNode().getParameters().convert((f)
|
||||
-> "<hover:show_text:'"
|
||||
+ f.getNames().convert((ff) -> "<#d665f0>" + ff).toString(", ") + "\n"
|
||||
+ "<#3fe05a>✎ <#6ad97d><font:minecraft:uniform>" + f.getDescription() + "<reset>\n"
|
||||
+ (f.isRequired()
|
||||
? "<#db4321>⚠ <#faa796><font:minecraft:uniform>This parameter is required."
|
||||
: (f.hasDefault()
|
||||
? "<#2181db>✔ <#78dcf0><font:minecraft:uniform>Defaults to \""+f.getParam().defaultValue()+"\" if undefined."
|
||||
: "<#a73abd>✔ <#78dcf0><font:minecraft:uniform>This parameter is optional.")) + "<reset>\n"
|
||||
+ (f.isContextual() ? "<#ff9900>➱ <#ffcc00><font:minecraft:uniform>The value may be derived from environment context <reset>\n" : "")
|
||||
+ "<#cc00ff>✢ <#ff33cc><font:minecraft:uniform>This parameter is of type " + f.getType().getSimpleName()
|
||||
+ "'>"
|
||||
+ (f.isRequired() ? "<red>[" : "")
|
||||
+ "<gradient:#d665f0:#a37feb>" + f.getName()
|
||||
+ (f.isRequired() ? "<red>]<gray>" : "")
|
||||
+ "</hover>").toString(" ")
|
||||
: "<gradient:#afe3d3:#a2dae0> - Category of Commands"
|
||||
)
|
||||
);
|
||||
//@done
|
||||
sendMessageRaw(s);
|
||||
System.out.println(s);
|
||||
} else {
|
||||
sendMessage(i.getPath() + "()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user