Allow /spell command to work with multiple players
This commit is contained in:
parent
f40e44e366
commit
d2d33c6159
2
.gitignore
vendored
2
.gitignore
vendored
@ -23,3 +23,5 @@ bin/
|
||||
# fabric
|
||||
|
||||
run/
|
||||
|
||||
remappedSrc/
|
@ -1,5 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
**1.2.2**
|
||||
* Allow ```/spell``` command to work with multiple players
|
||||
|
||||
**1.2.1**
|
||||
* Fix Launching Without ModMenu
|
||||
|
||||
|
@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G
|
||||
fabric_loader_version = 0.7.8+build.189
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.2.1
|
||||
mod_version = 1.2.2
|
||||
maven_group = com.thebrokenrail
|
||||
archives_base_name = sorcerycraft
|
||||
|
||||
|
@ -70,7 +70,9 @@ public class SorceryCraft implements ModInitializer {
|
||||
LootTables.JUNGLE_TEMPLE_CHEST,
|
||||
LootTables.STRONGHOLD_LIBRARY_CHEST,
|
||||
LootTables.PILLAGER_OUTPOST_CHEST,
|
||||
LootTables.WOODLAND_MANSION_CHEST
|
||||
LootTables.WOODLAND_MANSION_CHEST,
|
||||
LootTables.BURIED_TREASURE_CHEST,
|
||||
LootTables.FISHING_TREASURE_GAMEPLAY
|
||||
};
|
||||
|
||||
public static Identifier INTERACT_WITH_CASTING_TABLE_STAT;
|
||||
|
@ -13,10 +13,12 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Texts;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -27,65 +29,75 @@ public class SpellCommand {
|
||||
dispatcher.register(CommandManager.literal("spell")
|
||||
.requires(source -> source.hasPermissionLevel(4))
|
||||
.then(CommandManager.literal("list")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||
.executes(ctx -> {
|
||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||
Map<Identifier, Integer> spellMap = spellPlayer.getDiscoveredSpells();
|
||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName(), Texts.join(spellMap.entrySet(), spell -> SpellHelper.getTranslatedSpell(spell.getKey(), spell.getValue()))), false);
|
||||
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||
for (PlayerEntity player : players) {
|
||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||
Map<Identifier, Integer> spellMap = spellPlayer.getDiscoveredSpells();
|
||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName(), Texts.join(spellMap.entrySet(), spell -> SpellHelper.getTranslatedSpell(spell.getKey(), spell.getValue()))), false);
|
||||
}
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
)
|
||||
.then(CommandManager.literal("forget")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||
.executes(ctx -> {
|
||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
|
||||
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellHelper.getTranslatedSpellChat(entry.getKey(), entry.getValue())), true);
|
||||
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||
for (PlayerEntity player : players) {
|
||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
|
||||
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellHelper.getTranslatedSpellChat(entry.getKey(), entry.getValue())), true);
|
||||
}
|
||||
spellPlayer.setDiscoveredSpells(new HashMap<>());
|
||||
}
|
||||
spellPlayer.setDiscoveredSpells(new HashMap<>());
|
||||
return 1;
|
||||
})
|
||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||
.executes(ctx -> {
|
||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
|
||||
if (spells.containsKey(spell)) {
|
||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellHelper.getTranslatedSpellChat(spell, spells.get(spell))), true);
|
||||
spells.remove(spell);
|
||||
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||
for (PlayerEntity player : players) {
|
||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
|
||||
if (spells.containsKey(spell)) {
|
||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellHelper.getTranslatedSpellChat(spell, spells.get(spell))), true);
|
||||
spells.remove(spell);
|
||||
}
|
||||
spellPlayer.setDiscoveredSpells(spells);
|
||||
}
|
||||
spellPlayer.setDiscoveredSpells(spells);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
.then(CommandManager.literal("discover")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||
.executes(ctx -> {
|
||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||
Map<Identifier, Integer> spellMap = new HashMap<>();
|
||||
Spell[] maxSpells = SpellRegistry.getMaxSpells();
|
||||
for (Spell spell : maxSpells) {
|
||||
spellMap.put(spell.getID(), spell.getLevel());
|
||||
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||
for (PlayerEntity player : players) {
|
||||
Map<Identifier, Integer> spellMap = new HashMap<>();
|
||||
Spell[] maxSpells = SpellRegistry.getMaxSpells();
|
||||
for (Spell spell : maxSpells) {
|
||||
spellMap.put(spell.getID(), spell.getLevel());
|
||||
}
|
||||
SpellHelper.learnSpells(player, spellMap);
|
||||
}
|
||||
SpellHelper.learnSpells(player, spellMap);
|
||||
return 1;
|
||||
})
|
||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||
.then(CommandManager.argument("level", IntegerArgumentType.integer())
|
||||
.executes(ctx -> {
|
||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
|
||||
Map<Identifier, Integer> spellMap = new HashMap<>();
|
||||
spellMap.put(spell, level);
|
||||
SpellHelper.learnSpells(player, spellMap);
|
||||
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||
for (PlayerEntity player : players) {
|
||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
|
||||
Map<Identifier, Integer> spellMap = new HashMap<>();
|
||||
spellMap.put(spell, level);
|
||||
SpellHelper.learnSpells(player, spellMap);
|
||||
}
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
@ -93,25 +105,27 @@ public class SpellCommand {
|
||||
)
|
||||
)
|
||||
.then(CommandManager.literal("apply")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||
.then(CommandManager.argument("level", IntegerArgumentType.integer())
|
||||
.executes(ctx -> {
|
||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
|
||||
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||
for (PlayerEntity player : players) {
|
||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
|
||||
|
||||
ItemStack stack = player.getMainHandStack();
|
||||
ItemStack stack = player.getMainHandStack();
|
||||
|
||||
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
|
||||
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
||||
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
|
||||
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
||||
}
|
||||
|
||||
Map<Identifier, Integer> spellMap = SpellHelper.getSpells(stack);
|
||||
spellMap.put(spell, level);
|
||||
SpellHelper.setSpells(stack, spellMap);
|
||||
|
||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.applied_spell", SpellHelper.getTranslatedSpell(spell, level)), true);
|
||||
}
|
||||
|
||||
Map<Identifier, Integer> spellMap = SpellHelper.getSpells(stack);
|
||||
spellMap.put(spell, level);
|
||||
SpellHelper.setSpells(stack, spellMap);
|
||||
|
||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.applied_spell", SpellHelper.getTranslatedSpell(spell, level)), true);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
@ -119,25 +133,26 @@ public class SpellCommand {
|
||||
)
|
||||
)
|
||||
.then(CommandManager.literal("remove")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||
.executes(ctx -> {
|
||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||
for (PlayerEntity player : players) {
|
||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||
|
||||
ItemStack stack = player.getMainHandStack();
|
||||
ItemStack stack = player.getMainHandStack();
|
||||
|
||||
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
|
||||
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
||||
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
|
||||
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
||||
}
|
||||
|
||||
Map<Identifier, Integer> spellMap = SpellHelper.getSpells(stack);
|
||||
if (spellMap.containsKey(spell)) {
|
||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.removed_spell", SpellHelper.getTranslatedSpell(spell, spellMap.get(spell))), true);
|
||||
spellMap.remove(spell);
|
||||
}
|
||||
SpellHelper.setSpells(stack, spellMap);
|
||||
}
|
||||
|
||||
Map<Identifier, Integer> spellMap = SpellHelper.getSpells(stack);
|
||||
if (spellMap.containsKey(spell)) {
|
||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.removed_spell", SpellHelper.getTranslatedSpell(spell, spellMap.get(spell))), true);
|
||||
spellMap.remove(spell);
|
||||
}
|
||||
SpellHelper.setSpells(stack, spellMap);
|
||||
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
|
@ -47,6 +47,7 @@ public class SpellEntity extends ThrownItemEntity {
|
||||
|
||||
@Override
|
||||
protected void onCollision(HitResult hitResult) {
|
||||
super.onCollision(hitResult);
|
||||
if (!getEntityWorld().isClient()) {
|
||||
Map<Identifier, Integer> spells = SpellHelper.getSpells(getItem());
|
||||
if (!spells.containsKey(Spells.INWARD_SPELL)) {
|
||||
|
Reference in New Issue
Block a user