Refactor and rename to Thresholds
This commit is contained in:
parent
32a61e7925
commit
cd9d548806
568 changed files with 214858 additions and 215029 deletions
|
@ -1,110 +0,0 @@
|
|||
package dev.zontreck.otemod.commands;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.commands.items.ShareItemInChatCommand;
|
||||
import dev.zontreck.otemod.commands.profilecmds.ChatColorCommand;
|
||||
import dev.zontreck.otemod.commands.profilecmds.NameColorCommand;
|
||||
import dev.zontreck.otemod.commands.profilecmds.NickCommand;
|
||||
import dev.zontreck.otemod.commands.profilecmds.PrefixColorCommand;
|
||||
import dev.zontreck.otemod.commands.profilecmds.PrefixCommand;
|
||||
import dev.zontreck.otemod.commands.vaults.StarterCommand;
|
||||
import dev.zontreck.otemod.commands.vaults.TrashCommand;
|
||||
import dev.zontreck.otemod.commands.vaults.VaultCommand;
|
||||
import dev.zontreck.otemod.commands.zschem.LoadSchem;
|
||||
import dev.zontreck.otemod.commands.zschem.Place;
|
||||
import dev.zontreck.otemod.commands.zschem.PlaceAsAir;
|
||||
import dev.zontreck.otemod.commands.zschem.SaveSchem;
|
||||
import dev.zontreck.otemod.commands.zschem.SetPos1;
|
||||
import dev.zontreck.otemod.commands.zschem.SetPos2;
|
||||
import dev.zontreck.otemod.configs.OTEServerConfig;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
|
||||
@EventBusSubscriber(modid=OTEMod.MOD_ID,bus=Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public class CommandRegistry {
|
||||
public static Map<String,Long> CommandCooldownRegistry = new HashMap<>();
|
||||
|
||||
public static void markUsed(String cmd)
|
||||
{
|
||||
// Command was used, mark the current time
|
||||
CommandCooldownRegistry.put(cmd, Instant.now().getEpochSecond());
|
||||
}
|
||||
|
||||
public static boolean canUse(String cmd)
|
||||
{
|
||||
if(!CommandCooldownRegistry.containsKey(cmd)) return true;
|
||||
long lastUse = CommandCooldownRegistry.get(cmd);
|
||||
switch(cmd)
|
||||
{
|
||||
case "rtp":
|
||||
{
|
||||
if(Instant.now().getEpochSecond() > lastUse+Long.parseLong(String.valueOf(OTEServerConfig.RTP_COOLDOWN))){
|
||||
CommandCooldownRegistry.remove(cmd);
|
||||
return true;
|
||||
}else return false;
|
||||
}
|
||||
default:
|
||||
{
|
||||
CommandCooldownRegistry.remove(cmd);
|
||||
return true; // cooldown not yet made
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public static String getRemaining(String string) {
|
||||
long now = Instant.now().getEpochSecond();
|
||||
if(!CommandCooldownRegistry.containsKey(string))return "0";
|
||||
long used = CommandCooldownRegistry.get(string);
|
||||
long cmd_time = 0L;
|
||||
switch(string)
|
||||
{
|
||||
case "rtp":
|
||||
{
|
||||
cmd_time = Long.parseLong(String.valueOf(OTEServerConfig.RTP_COOLDOWN));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
cmd_time = 0L;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
used+=cmd_time;
|
||||
long diff = used-now;
|
||||
if(diff<0)diff=0L;
|
||||
return String.valueOf(diff);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRegisterCommands(final RegisterCommandsEvent ev)
|
||||
{
|
||||
|
||||
ChatColorCommand.register(ev.getDispatcher());
|
||||
NameColorCommand.register(ev.getDispatcher());
|
||||
PrefixColorCommand.register(ev.getDispatcher());
|
||||
PrefixCommand.register(ev.getDispatcher());
|
||||
NickCommand.register(ev.getDispatcher());
|
||||
|
||||
|
||||
|
||||
VaultCommand.register(ev.getDispatcher());
|
||||
TrashCommand.register(ev.getDispatcher());
|
||||
|
||||
SetPos1.register(ev.getDispatcher());
|
||||
SetPos2.register(ev.getDispatcher());
|
||||
SaveSchem.register(ev.getDispatcher());
|
||||
LoadSchem.register(ev.getDispatcher());
|
||||
Place.register(ev.getDispatcher());
|
||||
PlaceAsAir.register(ev.getDispatcher());
|
||||
|
||||
ShareItemInChatCommand.register(ev.getDispatcher());
|
||||
StarterCommand.register(ev.getDispatcher());
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package dev.zontreck.otemod.commands;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class FlyCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("fly").executes(FlyCommand::Fly));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int Fly(CommandContext<CommandSourceStack> ctx2)
|
||||
{
|
||||
// Request homes
|
||||
// String homeName = "";
|
||||
// CommandSourceStack ctx = ctx2.getSource();
|
||||
// homeName = StringArgumentType.getString(ctx2, "nickname");
|
||||
// if(homeName==null)return 0;
|
||||
CommandSourceStack ctx = ctx2.getSource();
|
||||
|
||||
ServerPlayer p = (ServerPlayer)ctx.getEntity();
|
||||
if(p==null)return 1;
|
||||
|
||||
if(p.getAbilities().mayfly){
|
||||
p.getAbilities().mayfly=false;
|
||||
p.getAbilities().flying=false;
|
||||
p.onUpdateAbilities();
|
||||
|
||||
|
||||
ctx.sendSystemMessage(Component.literal(OTEMod.OTEPrefix + ChatColor.DARK_PURPLE + " Your ability to fly has been disabled"));
|
||||
}else {
|
||||
p.getAbilities().mayfly=true;
|
||||
p.onUpdateAbilities();
|
||||
|
||||
ctx.sendSystemMessage(Component.literal(OTEMod.OTEPrefix + ChatColor.DARK_PURPLE + " You can now fly"));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.antigrief;
|
||||
|
||||
// This will accelerate the healing queue, not do it instantly!
|
||||
// The queue will get processed at a rate of 10* the configured rate.
|
||||
public class HealNow
|
||||
{
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.items;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import dev.zontreck.libzontreck.chat.HoverTip;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.AirItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class ShareItemInChatCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("shareitem").executes(c->share_item(c.getSource())));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int share_item(CommandSourceStack source) {
|
||||
|
||||
if(source.getEntity() instanceof Player)
|
||||
{
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
ItemStack is = play.getItemInHand(InteractionHand.MAIN_HAND);
|
||||
if(is.getItem() instanceof AirItem)
|
||||
{
|
||||
play.displayClientMessage(ChatHelpers.macro(OTEMod.OTEPrefix+" !Dark_Red!You cannot share air in the chat."), false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Profile prof;
|
||||
try {
|
||||
prof = Profile.get_profile_of(play.getUUID().toString());
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
MutableComponent component = ChatHelpers.macro(OTEMod.OTEPrefix).append(is.getDisplayName()).append(ChatHelpers.macro(" !White!-!Dark_Purple! Hover here to see the item that "+prof.name_color+prof.nickname+"!Dark_Purple! shared"));
|
||||
Style style = Style.EMPTY.withFont(Style.DEFAULT_FONT);
|
||||
component = component.withStyle(style.withHoverEvent(HoverTip.getItem(is)));
|
||||
|
||||
ChatHelpers.broadcast(component, OTEMod.THE_SERVER);
|
||||
|
||||
}else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.profilecmds;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import dev.zontreck.libzontreck.LibZontreck;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor.ColorOptions;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.implementation.Messages;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
|
||||
public class ChatColorCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("chat_color")
|
||||
.executes(c->setchatcolor(c.getSource(), ColorOptions.White))
|
||||
.then(Commands.argument("color", EnumArgument.enumArgument(ChatColor.ColorOptions.class))//StringArgumentType.string())
|
||||
.executes(c -> setchatcolor(c.getSource(), c.getArgument("color", ChatColor.ColorOptions.class)))// EnumArgument.getS(c, "color")))
|
||||
)
|
||||
);
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
public static int setchatcolor(CommandSourceStack source, ColorOptions string) {
|
||||
|
||||
// Chat Color has a registry of colors that we can use to map back to our desired color
|
||||
// To code
|
||||
String colorcoded = ChatColor.from(string);
|
||||
|
||||
// Get profile
|
||||
if(!(source.getEntity() instanceof Player)){
|
||||
return 1;
|
||||
}
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
Profile p;
|
||||
try {
|
||||
p = Profile.get_profile_of(play.getStringUUID());
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
return 1;
|
||||
}
|
||||
p.chat_color = colorcoded;
|
||||
p.commit();
|
||||
LibZontreck.PROFILES.put(play.getStringUUID(), p);
|
||||
|
||||
ChatHelpers.broadcastTo(play, ChatHelpers.macro(Messages.CHAT_COLOR_UPDATED), source.getServer());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.profilecmds;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import dev.zontreck.libzontreck.LibZontreck;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor.ColorOptions;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.implementation.Messages;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
|
||||
public class NameColorCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("nick_color")
|
||||
.executes(c->setchatcolor(c.getSource(), ColorOptions.White))
|
||||
.then(Commands.argument("color", EnumArgument.enumArgument(ChatColor.ColorOptions.class))//StringArgumentType.string())
|
||||
.executes(c -> setchatcolor(c.getSource(), c.getArgument("color", ChatColor.ColorOptions.class)))// EnumArgument.getS(c, "color")))
|
||||
)
|
||||
);
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
public static int setchatcolor(CommandSourceStack source, ColorOptions string) {
|
||||
|
||||
// Chat Color has a registry of colors that we can use to map back to our desired color
|
||||
// To code
|
||||
String colorcoded = ChatColor.from(string);
|
||||
|
||||
// Get profile
|
||||
if(!(source.getEntity() instanceof Player)){
|
||||
return 1;
|
||||
}
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
Profile p;
|
||||
try {
|
||||
p = Profile.get_profile_of(play.getStringUUID());
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
return 1;
|
||||
}
|
||||
p.name_color = colorcoded;
|
||||
p.commit();
|
||||
LibZontreck.PROFILES.put(play.getStringUUID(), p);
|
||||
|
||||
|
||||
ChatHelpers.broadcastTo(play, ChatHelpers.macro(Messages.NAME_COLOR_UPDATED), source.getServer());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.profilecmds;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import dev.zontreck.libzontreck.LibZontreck;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.implementation.Messages;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class NickCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("nick")
|
||||
.executes(c->setchatcolor(c.getSource(), c.getSource().getPlayerOrException().getName().getString()))
|
||||
.then(Commands.argument("new_name", StringArgumentType.string())//StringArgumentType.string())
|
||||
.executes(c -> setchatcolor(c.getSource(), StringArgumentType.getString(c, "new_name")))// EnumArgument.getS(c, "color")))
|
||||
)
|
||||
);
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
public static int setchatcolor(CommandSourceStack source, String string) {
|
||||
|
||||
// Get profile
|
||||
if(!(source.getEntity() instanceof Player)){
|
||||
return 1;
|
||||
}
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
|
||||
Profile p;
|
||||
try {
|
||||
p = Profile.get_profile_of(play.getStringUUID());
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
return 1;
|
||||
}
|
||||
p.nickname = string;
|
||||
p.commit();
|
||||
LibZontreck.PROFILES.put(play.getStringUUID(), p);
|
||||
|
||||
|
||||
ChatHelpers.broadcastTo(play, ChatHelpers.macro(Messages.NICK_UPDATED), source.getServer());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.profilecmds;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import dev.zontreck.libzontreck.LibZontreck;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor.ColorOptions;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.implementation.Messages;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
|
||||
public class PrefixColorCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("prefix_color")
|
||||
.executes(c->setchatcolor(c.getSource(), ColorOptions.White))
|
||||
.then(Commands.argument("color", EnumArgument.enumArgument(ChatColor.ColorOptions.class))//StringArgumentType.string())
|
||||
.executes(c -> setchatcolor(c.getSource(), c.getArgument("color", ChatColor.ColorOptions.class)))// EnumArgument.getS(c, "color")))
|
||||
)
|
||||
);
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
public static int setchatcolor(CommandSourceStack source, ColorOptions string) {
|
||||
|
||||
// Chat Color has a registry of colors that we can use to map back to our desired color
|
||||
// To code
|
||||
String colorcoded = ChatColor.from(string);
|
||||
|
||||
// Get profile
|
||||
if(!(source.getEntity() instanceof Player)){
|
||||
return 1;
|
||||
}
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
|
||||
Profile p;
|
||||
try {
|
||||
p = Profile.get_profile_of(play.getStringUUID());
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
return 1;
|
||||
}
|
||||
p.prefix_color = colorcoded;
|
||||
p.commit();
|
||||
LibZontreck.PROFILES.put(play.getStringUUID(), p);
|
||||
|
||||
ChatHelpers.broadcastTo(play, ChatHelpers.macro(Messages.PREFIX_COLOR_UPDATED), source.getServer());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.profilecmds;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import dev.zontreck.libzontreck.LibZontreck;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.implementation.Messages;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class PrefixCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("prefix")
|
||||
.executes(c->setchatcolor(c.getSource(), "Member"))
|
||||
.then(Commands.argument("new_prefix", StringArgumentType.string())//StringArgumentType.string())
|
||||
.executes(c -> setchatcolor(c.getSource(), StringArgumentType.getString(c, "new_prefix")))// EnumArgument.getS(c, "color")))
|
||||
)
|
||||
);
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
public static int setchatcolor(CommandSourceStack source, String string) {
|
||||
|
||||
// Get profile
|
||||
if(!(source.getEntity() instanceof Player)){
|
||||
return 1;
|
||||
}
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
|
||||
Profile p;
|
||||
try {
|
||||
p = Profile.get_profile_of(play.getStringUUID());
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
return 1;
|
||||
}
|
||||
p.prefix = string;
|
||||
p.commit();
|
||||
LibZontreck.PROFILES.put(play.getStringUUID(), p);
|
||||
|
||||
ChatHelpers.broadcastTo(play, ChatHelpers.macro(Messages.PREFIX_UPDATED), source.getServer());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.vaults;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.configs.OTEServerConfig;
|
||||
import dev.zontreck.otemod.implementation.Messages;
|
||||
import dev.zontreck.otemod.implementation.PlayerFirstJoinTag;
|
||||
import dev.zontreck.otemod.implementation.vault.NoMoreVaultException;
|
||||
import dev.zontreck.otemod.implementation.vault.StarterContainer;
|
||||
import dev.zontreck.otemod.implementation.vault.VaultContainer;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.SimpleMenuProvider;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public class StarterCommand
|
||||
{
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("starter").executes(x->openStarterMenu(x.getSource())).then(Commands.argument("player", EntityArgument.player()).executes(x->starterCommand(x.getSource(), EntityArgument.getPlayer(x, "player")))));
|
||||
}
|
||||
|
||||
public static int starterCommand(CommandSourceStack ctx, ServerPlayer player)
|
||||
{
|
||||
if(ctx.hasPermission(ctx.getServer().getOperatorUserPermissionLevel()))
|
||||
{
|
||||
try {
|
||||
vendStarterKit(player);
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static void vendStarterKit(ServerPlayer player) throws UserProfileNotYetExistsException {
|
||||
Profile prof = Profile.get_profile_of(player.getStringUUID());
|
||||
PlayerFirstJoinTag PFJT = PlayerFirstJoinTag.now();
|
||||
PFJT.LastGiven=0L;
|
||||
|
||||
PFJT.save(prof.NBT);
|
||||
|
||||
OTEMod.checkFirstJoin(player);
|
||||
}
|
||||
|
||||
public static int openStarterMenu(CommandSourceStack ctx)
|
||||
{
|
||||
ServerPlayer player = ctx.getPlayer();
|
||||
if(player != null)
|
||||
{
|
||||
if(player.hasPermissions(ctx.getServer().getOperatorUserPermissionLevel()))
|
||||
{
|
||||
try {
|
||||
StarterContainer container = new StarterContainer(player);
|
||||
NetworkHooks.openScreen(player, new SimpleMenuProvider(container.serverMenu, Component.literal("Starter Gear")));
|
||||
|
||||
|
||||
// Add to the master vault registry
|
||||
if(StarterContainer.VAULT_REGISTRY.containsKey(player.getUUID()))StarterContainer.VAULT_REGISTRY.remove(player.getUUID());
|
||||
StarterContainer.VAULT_REGISTRY.put(player.getUUID(), container);
|
||||
} catch (NoMoreVaultException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}else {
|
||||
ChatHelpers.broadcastTo(player, ChatHelpers.macro(Messages.STARTER_FAILURE_PERMISSIONS), ctx.getServer());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
ctx.sendFailure(ChatHelpers.macro(Messages.STARTER_FAILURE_CONSOLE));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
public static void doOpen(ServerPlayer p){
|
||||
|
||||
StarterContainer container;
|
||||
try {
|
||||
container = new StarterContainer(p);
|
||||
} catch (NoMoreVaultException e) {
|
||||
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix+"!Dark_Red!You cannot open anymore vaults. Craft a new vault!"), p.server);
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkHooks.openScreen(p, new SimpleMenuProvider(container.serverMenu, Component.literal("Starter Gear")));
|
||||
|
||||
// Add to the master vault registry
|
||||
if(StarterContainer.VAULT_REGISTRY.containsKey(p.getUUID()))VaultContainer.VAULT_REGISTRY.remove(p.getUUID());
|
||||
StarterContainer.VAULT_REGISTRY.put(p.getUUID(), container);
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.vaults;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.implementation.vault.NoMoreVaultException;
|
||||
import dev.zontreck.otemod.implementation.vault.VaultContainer;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.SimpleMenuProvider;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
public class TrashCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("trash").executes(c-> vault(c.getSource())));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int vault(CommandSourceStack source) {
|
||||
//VaultContainer cont = new VaultContainer(i, source.getPlayer().getUUID());
|
||||
//cont.startOpen(source.getPlayer());
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
|
||||
VaultContainer container;
|
||||
try {
|
||||
container = new VaultContainer(play, -1);
|
||||
} catch (NoMoreVaultException e) {
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix+" !Dark_Red!You cannot open anymore vaults. Craft a new vault!"), play.server);
|
||||
return 0;
|
||||
}
|
||||
|
||||
NetworkHooks.openScreen(play, new SimpleMenuProvider(container.serverMenu, Component.literal("Trash")));
|
||||
|
||||
// Add to the master vault registry
|
||||
if(VaultContainer.VAULT_REGISTRY.containsKey(play.getUUID()))VaultContainer.VAULT_REGISTRY.remove(play.getUUID());
|
||||
VaultContainer.VAULT_REGISTRY.put(play.getUUID(), container);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.vaults;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.implementation.vault.NoMoreVaultException;
|
||||
import dev.zontreck.otemod.implementation.vault.VaultContainer;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.SimpleMenuProvider;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
public class VaultCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("pv").executes(c-> vault(c.getSource(), 0)).then(Commands.argument("number", IntegerArgumentType.integer()).executes(c -> vault(c.getSource(), IntegerArgumentType.getInteger(c, "number")))));
|
||||
dispatcher.register(Commands.literal("vault").executes(c-> vault(c.getSource(), 0)).then(Commands.argument("number", IntegerArgumentType.integer()).executes(c -> vault(c.getSource(), IntegerArgumentType.getInteger(c, "number")))));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int vault(CommandSourceStack source, int i) {
|
||||
//VaultContainer cont = new VaultContainer(i, source.getPlayer().getUUID());
|
||||
//cont.startOpen(source.getPlayer());
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
if(i <0)
|
||||
{
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix+" !Dark_Red!You can only specify a vault number in the positive range"), source.getServer());
|
||||
return 0;
|
||||
}
|
||||
doOpen(play, i);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void doOpen(ServerPlayer p, int i){
|
||||
|
||||
VaultContainer container;
|
||||
try {
|
||||
container = new VaultContainer(p, i);
|
||||
} catch (NoMoreVaultException e) {
|
||||
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix+" !Dark_Red!You cannot open anymore vaults. Craft a new vault!"), p.server);
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkHooks.openScreen(p, new SimpleMenuProvider(container.serverMenu, Component.literal("Vault " + i)));
|
||||
|
||||
// Add to the master vault registry
|
||||
if(VaultContainer.VAULT_REGISTRY.containsKey(p.getUUID()))VaultContainer.VAULT_REGISTRY.remove(p.getUUID());
|
||||
VaultContainer.VAULT_REGISTRY.put(p.getUUID(), container);
|
||||
}
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.zschem;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.integrations.LuckPermsHelper;
|
||||
import dev.zontreck.otemod.permissions.Permissions;
|
||||
import dev.zontreck.otemod.zschem.MemoryHolder;
|
||||
import dev.zontreck.otemod.zschem.MemoryHolder.Container;
|
||||
import dev.zontreck.otemod.zschem.StoredBlock;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.fml.loading.FMLConfig;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class LoadSchem {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("loadzschem").executes(c-> loadSchematicUsage(c.getSource())).then(Commands.argument("name", StringArgumentType.string()).executes(z->loadSchematic(z.getSource(), StringArgumentType.getString(z, "name")))));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int loadSchematic(CommandSourceStack source, String name) {
|
||||
// Perform sanity checks
|
||||
|
||||
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
if(play==null)return 1;
|
||||
|
||||
if(!LuckPermsHelper.hasGroupOrPerm(play, Permissions.zschem, Permissions.zschem_load)){
|
||||
LuckPermsHelper.sendNoPermissionsMessage(play, Permissions.zschem_load, Permissions.zschem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(MemoryHolder.hasPlayerCached(play))
|
||||
{
|
||||
Container cont = MemoryHolder.getContainer(play);
|
||||
if(cont == null)
|
||||
{
|
||||
|
||||
loadSchematicUsage(source);
|
||||
}else {
|
||||
if(cont.Pos1 != OTEMod.ZERO_VECTOR)
|
||||
{
|
||||
// Lets go!
|
||||
List<StoredBlock> blocks = new ArrayList<StoredBlock>();
|
||||
// First we calculate every vector between pos1 and pos2.
|
||||
// Then we subtract pos1 from the vector to acquire a relative position.
|
||||
// Then we save the block with this relative position to the blocks list
|
||||
// Once serialized, it is then possible to add the position. Note that this makes it impossible to rotate a zschem like with worldedit, but thats usually fine for our usecases. once in-game worldedit can be used to rotate.
|
||||
// TODO: Also- It is possible that a rotational implementation can be added in the future
|
||||
|
||||
Path configDir = FMLPaths.GAMEDIR.get().resolve(FMLConfig.defaultConfigPath());
|
||||
configDir = configDir.resolve("ZSchems");
|
||||
File X = configDir.toFile();
|
||||
if(!X.exists())
|
||||
{
|
||||
X.mkdir();
|
||||
}
|
||||
configDir = configDir.resolve(name+"-zschem.nbt");
|
||||
|
||||
if(configDir.toFile().exists()){
|
||||
CompoundTag CT=new CompoundTag();
|
||||
try {
|
||||
CT = NbtIo.readCompressed(configDir.toFile());
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return 1;
|
||||
}
|
||||
|
||||
ListTag blst = CT.getList("blocks", CompoundTag.TAG_COMPOUND);
|
||||
Iterator<Tag> tags = blst.iterator();
|
||||
while(tags.hasNext())
|
||||
{
|
||||
CompoundTag nxt = (CompoundTag)tags.next();
|
||||
StoredBlock sb = new StoredBlock(nxt);
|
||||
ServerLevel pasteLvl = cont.lvl;
|
||||
sb.updateWorld(pasteLvl);
|
||||
|
||||
WorldPosition wp = sb.getWorldPosition();
|
||||
Vector3 superPos = cont.Pos1;
|
||||
wp.Position = superPos.add(wp.Position);
|
||||
sb.setPosition(wp.Position);
|
||||
|
||||
|
||||
blocks.add(sb);
|
||||
|
||||
}
|
||||
|
||||
MemoryHolder.setBlocks(play, blocks);
|
||||
|
||||
}else {
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix + " !Dark_Red!No such ZSchem exists!"), source.getServer());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix+" !Dark_Green!ZSchem loaded from disk!"), OTEMod.THE_SERVER);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro("!Dark_Red! You must set the first position"), OTEMod.THE_SERVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int loadSchematicUsage(CommandSourceStack source)
|
||||
{
|
||||
String usage = OTEMod.OTEPrefix;
|
||||
usage += "!gold! /loadzschem [string:name]";
|
||||
ServerPlayer play=(ServerPlayer)source.getEntity();
|
||||
if(play==null)return 1;
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(usage), OTEMod.THE_SERVER);
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.zschem;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.integrations.LuckPermsHelper;
|
||||
import dev.zontreck.otemod.permissions.Permissions;
|
||||
import dev.zontreck.otemod.zschem.MemoryHolder;
|
||||
import dev.zontreck.otemod.zschem.MemoryHolder.Container;
|
||||
import dev.zontreck.otemod.zschem.StoredBlock;
|
||||
import dev.zontreck.otemod.zschem.WorldProp;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
// This command will place the loaded schematic in world. The schematic will originate from position 1. The positions are relative and are added onto position 1.
|
||||
public class Place {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("placezschem").executes(c-> place(c.getSource())));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int place(CommandSourceStack source) {
|
||||
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
if(play==null)return 1;
|
||||
|
||||
if(!LuckPermsHelper.hasGroupOrPerm(play, Permissions.zschem, Permissions.zschem_place)){
|
||||
LuckPermsHelper.sendNoPermissionsMessage(play, Permissions.zschem_place, Permissions.zschem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!MemoryHolder.hasPlayerCached(play)){
|
||||
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix+" !Dark_Red!You must first load the zschem!"), OTEMod.THE_SERVER);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Container cont = MemoryHolder.getContainer(play);
|
||||
List<StoredBlock> blocks = cont.blocks;
|
||||
Collections.shuffle(blocks);
|
||||
|
||||
if(cont.Pos1 != OTEMod.ZERO_VECTOR)
|
||||
{
|
||||
WorldProp system = WorldProp.acquire(cont.lvl);
|
||||
// Begin the process
|
||||
for (StoredBlock storedBlock : blocks) {
|
||||
// alter the stored block and send it off to the queue system for the relevant world!
|
||||
|
||||
system.customEnqueue(storedBlock);
|
||||
}
|
||||
|
||||
}else {
|
||||
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix+" !Dark_Red!You must first load the zschem!"), OTEMod.THE_SERVER);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix+" !Dark_Green!Enqueued!"), OTEMod.THE_SERVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.zschem;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.integrations.LuckPermsHelper;
|
||||
import dev.zontreck.otemod.permissions.Permissions;
|
||||
import dev.zontreck.otemod.zschem.MemoryHolder;
|
||||
import dev.zontreck.otemod.zschem.MemoryHolder.Container;
|
||||
import dev.zontreck.otemod.zschem.StoredBlock;
|
||||
import dev.zontreck.otemod.zschem.WorldProp;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
// This command will place the loaded schematic in world. The schematic will originate from position 1. The positions are relative and are added onto position 1.
|
||||
public class PlaceAsAir {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("zsetair").executes(c-> place(c.getSource())));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int place(CommandSourceStack source) {
|
||||
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
if(play==null)return 1;
|
||||
|
||||
if(!LuckPermsHelper.hasGroupOrPerm(play, Permissions.zschem, Permissions.zschem_air)){
|
||||
LuckPermsHelper.sendNoPermissionsMessage(play, Permissions.zschem_air, Permissions.zschem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!MemoryHolder.hasPlayerCached(play)){
|
||||
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix+" !Dark_Red!You must first set the positions!"), OTEMod.THE_SERVER);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Container cont = MemoryHolder.getContainer(play);
|
||||
|
||||
if(cont.Pos1 != OTEMod.ZERO_VECTOR && cont.Pos2 != OTEMod.ZERO_VECTOR)
|
||||
{
|
||||
WorldProp system = WorldProp.acquire(cont.lvl);
|
||||
// Begin the process
|
||||
List<Vector3> positions = cont.Pos1.makeCube(cont.Pos2);
|
||||
Collections.shuffle(positions);
|
||||
Iterator<Vector3> v3 = positions.iterator();
|
||||
|
||||
while(v3.hasNext())
|
||||
{
|
||||
Vector3 pos = v3.next();
|
||||
StoredBlock sb = new StoredBlock(pos.asBlockPos(), Blocks.AIR.defaultBlockState(), source.getLevel());
|
||||
system.customEnqueue(sb);
|
||||
}
|
||||
|
||||
|
||||
}else {
|
||||
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix+" !Dark_Red!You must first set the positions!"), OTEMod.THE_SERVER);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix+" !Dark_Green!Enqueued!"), OTEMod.THE_SERVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.zschem;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.integrations.LuckPermsHelper;
|
||||
import dev.zontreck.otemod.permissions.Permissions;
|
||||
import dev.zontreck.otemod.zschem.MemoryHolder;
|
||||
import dev.zontreck.otemod.zschem.MemoryHolder.Container;
|
||||
import dev.zontreck.otemod.zschem.StoredBlock;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.fml.loading.FMLConfig;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SaveSchem {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("savezschem").executes(c-> saveSchematicUsage(c.getSource())).then(Commands.argument("name", StringArgumentType.string()).executes(z->saveSchematic(z.getSource(), StringArgumentType.getString(z, "name")))));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int saveSchematic(CommandSourceStack source, String name) {
|
||||
// Perform sanity checks
|
||||
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
if(play==null)return 1;
|
||||
|
||||
if(!LuckPermsHelper.hasGroupOrPerm(play, Permissions.zschem, Permissions.zschem_save)){
|
||||
LuckPermsHelper.sendNoPermissionsMessage(play, Permissions.zschem_save, Permissions.zschem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(MemoryHolder.hasPlayerCached(play))
|
||||
{
|
||||
Container cont = MemoryHolder.getContainer(play);
|
||||
if(cont == null)
|
||||
{
|
||||
|
||||
saveSchematicUsage(source);
|
||||
}else {
|
||||
if(cont.Pos1 != OTEMod.ZERO_VECTOR && cont.Pos2 != OTEMod.ZERO_VECTOR)
|
||||
{
|
||||
// Lets go!
|
||||
List<StoredBlock> blocks = new ArrayList<StoredBlock>();
|
||||
// First we calculate every vector between pos1 and pos2.
|
||||
// Then we subtract pos1 from the vector to acquire a relative position.
|
||||
// Then we save the block with this relative position to the blocks list
|
||||
// Once serialized, it is then possible to add the position. Note that this makes it impossible to rotate a zschem like with worldedit, but thats usually fine for our usecases. once in-game worldedit can be used to rotate.
|
||||
// TODO: Also- It is possible that a rotational implementation can be added in the future
|
||||
|
||||
List<Vector3> positions = cont.Pos1.makeCube(cont.Pos2);
|
||||
|
||||
for (Vector3 vector3 : positions) {
|
||||
Vector3 v3 = vector3.subtract(cont.Pos1);
|
||||
|
||||
BlockPos current = vector3.asBlockPos();
|
||||
|
||||
StoredBlock sb = new StoredBlock(current, cont.lvl.getBlockState(current), cont.lvl);
|
||||
sb.setPosition(v3);
|
||||
|
||||
blocks.add(sb);
|
||||
}
|
||||
|
||||
CompoundTag savedSchem = new CompoundTag();
|
||||
ListTag lst = new ListTag();
|
||||
for (StoredBlock sBlock : blocks) {
|
||||
lst.add(sBlock.serialize());
|
||||
}
|
||||
savedSchem.put("blocks", lst);
|
||||
|
||||
|
||||
Path configDir = FMLPaths.GAMEDIR.get().resolve(FMLConfig.defaultConfigPath());
|
||||
configDir = configDir.resolve("ZSchems");
|
||||
File X = configDir.toFile();
|
||||
if(!X.exists())
|
||||
{
|
||||
X.mkdir();
|
||||
}
|
||||
configDir = configDir.resolve(name+"-zschem.nbt");
|
||||
|
||||
// Save file!
|
||||
try {
|
||||
NbtIo.writeCompressed(savedSchem, configDir.toFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(OTEMod.OTEPrefix+" !Dark_Green!ZSchem saved to disk!"), OTEMod.THE_SERVER);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro("!Dark_Red! You must first set the positions"), OTEMod.THE_SERVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int saveSchematicUsage(CommandSourceStack source)
|
||||
{
|
||||
String usage = OTEMod.OTEPrefix;
|
||||
usage += "!gold! /savezschem [string:name]";
|
||||
ServerPlayer play=(ServerPlayer)source.getEntity();
|
||||
if(play==null)return 1;
|
||||
ChatHelpers.broadcastTo(play.getUUID(), ChatHelpers.macro(usage), OTEMod.THE_SERVER);
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.zschem;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.integrations.LuckPermsHelper;
|
||||
import dev.zontreck.otemod.permissions.Permissions;
|
||||
import dev.zontreck.otemod.zschem.MemoryHolder;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class SetPos1 {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("zpos1").executes(c-> setzPos1(c.getSource())));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int setzPos1(CommandSourceStack source) {
|
||||
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
if(play==null)return 1;
|
||||
|
||||
if(!LuckPermsHelper.hasGroupOrPerm(play, Permissions.zschem, Permissions.zschem_pos1)){
|
||||
LuckPermsHelper.sendNoPermissionsMessage(play, Permissions.zschem_pos1, Permissions.zschem);
|
||||
return 1;
|
||||
}
|
||||
MemoryHolder.setPos1(play, new Vector3(source.getPosition()));
|
||||
MemoryHolder.setLevel(play, source.getLevel());
|
||||
|
||||
ChatHelpers.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Position 1 set!")), OTEMod.THE_SERVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package dev.zontreck.otemod.commands.zschem;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.integrations.LuckPermsHelper;
|
||||
import dev.zontreck.otemod.permissions.Permissions;
|
||||
import dev.zontreck.otemod.zschem.MemoryHolder;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class SetPos2 {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("zpos2").executes(c-> setzPos2(c.getSource())));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int setzPos2(CommandSourceStack source) {
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
if(play==null)return 1;
|
||||
|
||||
if(!LuckPermsHelper.hasGroupOrPerm(play, Permissions.zschem, Permissions.zschem_pos2)){
|
||||
LuckPermsHelper.sendNoPermissionsMessage(play, Permissions.zschem_pos2, Permissions.zschem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
MemoryHolder.setPos2(play, new Vector3(source.getPosition()));
|
||||
MemoryHolder.setLevel(play, source.getLevel());
|
||||
|
||||
ChatHelpers.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Position 2 set!")), OTEMod.THE_SERVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
Reference in a new issue