-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a7b55da
Showing
5 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Ninjananas | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# No Creeper Grief | ||
|
||
Spigot plugin that contains in-game utilities related to chests. | ||
|
||
## Features | ||
|
||
### Autostore | ||
A command that lets you store your inventory in the surrounding chests containing similar items. It is inspired by the similar functionnality in Terraria. Chests that cannot be accessed by the player are ignored. | ||
|
||
### Autosort [planned] | ||
Automatically sort your inventory or a chest. | ||
|
||
## Commands | ||
- `/autostore` Store (and sort) items in your inventory to nearby chests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: ChestTricks | ||
main: ninjananas.mc.ChestTricks.Plugin | ||
version: 1.0 | ||
api-version: 1.18 | ||
permissions: | ||
chesttricks.autostore: | ||
default: true | ||
commands: | ||
autostore: | ||
description: Automatically store items in your inventory to nearby chests | ||
usage: /autostore | ||
permission: chesttricks.autostore | ||
permission-message: You can't use this command! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package ninjananas.mc.ChestTricks; | ||
|
||
|
||
import java.util.Vector; | ||
|
||
import org.bukkit.FluidCollisionMode; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.Chest; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.util.RayTraceResult; | ||
|
||
public class AutoStoreCommand implements CommandExecutor { | ||
|
||
public AutoStoreCommand(Plugin plugin) { | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command cmd, String val, String[] args) { | ||
if (! (sender instanceof Player)) { | ||
sender.sendMessage("This command can only be used by players!"); | ||
return false; | ||
} | ||
Player player = (Player) sender; | ||
Location location = player.getEyeLocation(); | ||
|
||
Vector<Chest> chests = new Vector<Chest>(); | ||
|
||
for (double i = -3.0; i < 4.0; i++) { | ||
for (double j = -3.0; j < 4.0; j++) { | ||
for (double k = -3.0; k < 4.0; k++) { | ||
Block block = location.clone().add(i, j, k).getBlock(); | ||
if (block.getType() == Material.CHEST) { | ||
RayTraceResult rayTraceResult = player.getWorld().rayTraceBlocks( | ||
location, | ||
block.getLocation().clone().add(0.5, 0.5, 0.5).subtract(location).toVector(), | ||
20, | ||
FluidCollisionMode.NEVER, | ||
false); | ||
if ( (rayTraceResult != null) & (rayTraceResult.getHitBlock().equals(block)) ) | ||
chests.add((Chest) block.getState()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (Chest chest: chests) { | ||
Inventory chestInventory = chest.getInventory(); | ||
Inventory playerInventory = player.getInventory(); | ||
|
||
ItemStack[] inventoryContent = playerInventory.getStorageContents().clone(); | ||
|
||
for (int i = 0; i < inventoryContent.length; i++) { | ||
if (i < 9) continue; // Skip elements in action bar | ||
ItemStack stack = inventoryContent[i]; | ||
if (stack == null) continue; // Skip empty slots | ||
if (! chestInventory.contains(stack.getType())) continue; // Only store items that are in the chest | ||
|
||
inventoryContent[i] = null; | ||
for (ItemStack failedStack: chestInventory.addItem(stack).values()) | ||
inventoryContent[i] = failedStack; | ||
} | ||
playerInventory.setStorageContents(inventoryContent); | ||
player.updateInventory(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package ninjananas.mc.ChestTricks; | ||
|
||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
|
||
public class Plugin extends JavaPlugin { | ||
|
||
@Override | ||
public void onEnable() { | ||
this.getCommand("autostore").setExecutor(new AutoStoreCommand(this)); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
} | ||
} |