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();
|
Player p = sender.player();
|
||||||
|
|
||||||
J.a(() -> {
|
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;
|
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 DecPregen pregen;
|
||||||
|
|
||||||
|
private DecSettings settings;
|
||||||
|
|
||||||
|
private DecObject object;
|
||||||
|
|
||||||
@Decree(description = "Create a new world", aliases = "+")
|
@Decree(description = "Create a new world", aliases = "+")
|
||||||
public void create(
|
public void create(
|
||||||
@Param(aliases = "world-name", description = "The name of the world to create", defaultValue = "IrisWorld")
|
@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,6 +413,14 @@ public class VolmitSender implements CommandSender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (VirtualDecreeCommand i : v.getNodes()) {
|
for (VirtualDecreeCommand i : v.getNodes()) {
|
||||||
|
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()) {
|
if (isPlayer()) {
|
||||||
//@builder
|
//@builder
|
||||||
String s = (
|
String s = (
|
||||||
@ -465,8 +473,4 @@ public class VolmitSender implements CommandSender {
|
|||||||
sendMessage(i.getPath() + "()");
|
sendMessage(i.getPath() + "()");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
sendMessage(C.RED + "There are no subcommands in this group! Contact support, this is a command design issue!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user