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,31 +29,36 @@ 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");
|
||||
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");
|
||||
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<>());
|
||||
}
|
||||
return 1;
|
||||
})
|
||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||
.executes(ctx -> {
|
||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||
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();
|
||||
@ -60,32 +67,37 @@ public class SpellCommand {
|
||||
spells.remove(spell);
|
||||
}
|
||||
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");
|
||||
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);
|
||||
}
|
||||
return 1;
|
||||
})
|
||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||
.then(CommandManager.argument("level", IntegerArgumentType.integer())
|
||||
.executes(ctx -> {
|
||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||
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,11 +105,12 @@ 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");
|
||||
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||
for (PlayerEntity player : players) {
|
||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
|
||||
|
||||
@ -112,6 +125,7 @@ public class SpellCommand {
|
||||
SpellHelper.setSpells(stack, spellMap);
|
||||
|
||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.applied_spell", SpellHelper.getTranslatedSpell(spell, level)), true);
|
||||
}
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
@ -119,10 +133,11 @@ 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");
|
||||
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||
for (PlayerEntity player : players) {
|
||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||
|
||||
ItemStack stack = player.getMainHandStack();
|
||||
@ -137,7 +152,7 @@ public class SpellCommand {
|
||||
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