9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-26 10:29:10 +00:00

[API] Add more annotations

This commit is contained in:
XiaoMoMi
2024-04-22 02:55:19 +08:00
parent 484f4ec24d
commit 6de266a1e5
7 changed files with 492 additions and 43 deletions

View File

@@ -409,6 +409,11 @@ public class ItemManagerImpl implements ItemManager {
return Optional.ofNullable(customProvider.getEntityID(entity)).map(threeDItem2SprinklerMap::get).orElse(null);
}
@Override
public Sprinkler getSprinklerByBlock(@NotNull Block block) {
return Optional.ofNullable(customProvider.getBlockID(block)).map(threeDItem2SprinklerMap::get).orElse(null);
}
@Override
public Sprinkler getSprinklerBy2DItemStack(@NotNull ItemStack itemStack) {
return getSprinklerBy2DItemID(getItemID(itemStack));
@@ -439,13 +444,6 @@ public class ItemManagerImpl implements ItemManager {
return getPotByBlockID(getItemID(itemStack));
}
@Override
public Sprinkler getSprinklerByItemStack(@NotNull ItemStack itemStack) {
if (itemStack.getType() == Material.AIR)
return null;
return getSprinklerBy2DItemID(getItemID(itemStack));
}
@Override
public Fertilizer getFertilizerByID(@NotNull String id) {
return id2FertilizerMap.get(id);
@@ -566,7 +564,7 @@ public class ItemManagerImpl implements ItemManager {
}
method.trigger(potState);
pot.trigger(ActionTrigger.ADD_WATER, potState);
plugin.getWorldManager().addWaterToPot(pot, SimpleLocation.of(potLocation), method.getAmount());
plugin.getWorldManager().addWaterToPot(pot, method.getAmount(), SimpleLocation.of(potLocation));
} else {
pot.trigger(ActionTrigger.FULL, potState);
}
@@ -607,7 +605,7 @@ public class ItemManagerImpl implements ItemManager {
}
method.trigger(potState);
pot.trigger(ActionTrigger.ADD_WATER, potState);
plugin.getWorldManager().addWaterToPot(pot, SimpleLocation.of(potLocation), method.getAmount());
plugin.getWorldManager().addWaterToPot(pot, method.getAmount(), SimpleLocation.of(potLocation));
} else {
pot.trigger(ActionTrigger.FULL, potState);
}
@@ -873,7 +871,7 @@ public class ItemManagerImpl implements ItemManager {
wateringCan.trigger(ActionTrigger.CONSUME_WATER, state);
for (Location location : waterEvent.getLocation()) {
plugin.getWorldManager().addWaterToPot(pot, SimpleLocation.of(location), wateringCan.getWater());
plugin.getWorldManager().addWaterToPot(pot, wateringCan.getWater(), SimpleLocation.of(location));
pot.trigger(ActionTrigger.ADD_WATER, new State(player, itemStack, location));
}
} else {
@@ -955,7 +953,7 @@ public class ItemManagerImpl implements ItemManager {
wateringCan.trigger(ActionTrigger.CONSUME_WATER, state);
for (Location location : waterEvent.getLocation()) {
plugin.getWorldManager().addWaterToPot(pot, SimpleLocation.of(location), wateringCan.getWater());
plugin.getWorldManager().addWaterToPot(pot, wateringCan.getWater(), SimpleLocation.of(location));
pot.trigger(ActionTrigger.ADD_WATER, new State(player, itemStack, location));
}
} else {
@@ -1037,7 +1035,7 @@ public class ItemManagerImpl implements ItemManager {
wateringCan.trigger(ActionTrigger.CONSUME_WATER, state);
for (Location location : waterEvent.getLocation()) {
plugin.getWorldManager().addWaterToPot(pot, SimpleLocation.of(location), wateringCan.getWater());
plugin.getWorldManager().addWaterToPot(pot, wateringCan.getWater(), SimpleLocation.of(location));
pot.trigger(ActionTrigger.ADD_WATER, new State(player, itemStack, location));
}
} else {
@@ -1655,7 +1653,6 @@ public class ItemManagerImpl implements ItemManager {
// add data
plugin.getWorldManager().addFertilizerToPot(pot, fertilizer, simpleLocation);
updatePotState(location, pot, hasWater, fertilizer);
if (interactBlockWrapper.getPlayer().getGameMode() != GameMode.CREATIVE) {
itemInHand.setAmount(itemInHand.getAmount() - 1);
}
@@ -1723,7 +1720,6 @@ public class ItemManagerImpl implements ItemManager {
// add data
plugin.getWorldManager().addFertilizerToPot(pot, fertilizer, simpleLocation);
updatePotState(potLocation, pot, hasWater, fertilizer);
if (interactBlockWrapper.getPlayer().getGameMode() != GameMode.CREATIVE) {
itemInHand.setAmount(itemInHand.getAmount() - 1);
}
@@ -1783,7 +1779,6 @@ public class ItemManagerImpl implements ItemManager {
// add data
plugin.getWorldManager().addFertilizerToPot(pot, fertilizer, simpleLocation);
updatePotState(potLocation, pot, hasWater, fertilizer);
if (furnitureWrapper.getPlayer().getGameMode() != GameMode.CREATIVE) {
itemInHand.setAmount(itemInHand.getAmount() - 1);
}
@@ -1962,7 +1957,7 @@ public class ItemManagerImpl implements ItemManager {
}
method.trigger(potState);
pot.trigger(ActionTrigger.ADD_WATER, potState);
plugin.getWorldManager().addWaterToPot(pot, SimpleLocation.of(potLocation), method.getAmount());
plugin.getWorldManager().addWaterToPot(pot, method.getAmount(), SimpleLocation.of(potLocation));
} else {
pot.trigger(ActionTrigger.FULL, potState);
}
@@ -1989,7 +1984,7 @@ public class ItemManagerImpl implements ItemManager {
}
}
boneMeal.trigger(cropState);
plugin.getWorldManager().addPointToCrop(crop, SimpleLocation.of(cropLocation), boneMeal.getPoint());
plugin.getWorldManager().addPointToCrop(crop, boneMeal.getPoint(), SimpleLocation.of(cropLocation));
return FunctionResult.RETURN;
}
}
@@ -2145,7 +2140,7 @@ public class ItemManagerImpl implements ItemManager {
}
method.trigger(state);
pot.trigger(ActionTrigger.ADD_WATER, state);
plugin.getWorldManager().addWaterToPot(pot, simpleLocation, method.getAmount());
plugin.getWorldManager().addWaterToPot(pot, method.getAmount(), simpleLocation);
} else {
pot.trigger(ActionTrigger.FULL, state);
return FunctionResult.CANCEL_EVENT_AND_RETURN;

View File

@@ -294,7 +294,7 @@ public abstract class AbstractCustomListener implements Listener {
if (id.equals(itemID)) {
storage.setAmount(storage.getAmount() - 1);
boneMeal.trigger(new State(null, itemStack, location));
CustomCropsPlugin.get().getWorldManager().addPointToCrop(config, simpleLocation, boneMeal.getPoint());
CustomCropsPlugin.get().getWorldManager().addPointToCrop(config, boneMeal.getPoint(), simpleLocation);
}
}
}

View File

@@ -306,8 +306,10 @@ public class CChunk implements CustomCropsChunk {
memoryPot.setFertilizer(fertilizer);
addBlockAt(memoryPot, location);
CustomCropsPlugin.get().debug("When adding fertilizer to pot at " + location + ", the pot data doesn't exist.");
CustomCropsPlugin.get().getItemManager().updatePotState(location.getBukkitLocation(), pot, false, fertilizer);
} else {
optionalWorldPot.get().setFertilizer(fertilizer);
CustomCropsPlugin.get().getItemManager().updatePotState(location.getBukkitLocation(), pot, optionalWorldPot.get().getWater() > 0, fertilizer);
}
}

View File

@@ -424,7 +424,7 @@ public class CWorld implements CustomCropsWorld {
if (chunk.isPresent()) {
chunk.get().addPointToCrop(crop, location, points);
} else {
LogUtils.warn("Invalid operation: Adding points to crop in a not generated chunk");
LogUtils.warn("Invalid operation: Adding point to crop in a not generated chunk");
}
}

View File

@@ -335,7 +335,8 @@ public class WorldManagerImpl implements WorldManager, Listener {
}
@Override
public void addWaterToPot(@NotNull Pot pot, @NotNull SimpleLocation location, int amount) {
public void addWaterToPot(@NotNull Pot pot, int amount, @NotNull SimpleLocation location) {
if (amount <= 0) return;
CWorld cWorld = loadedWorlds.get(location.getWorldName());
if (cWorld == null) {
LogUtils.warn("Unsupported operation: Adding water to pot in unloaded world " + location);
@@ -375,7 +376,7 @@ public class WorldManagerImpl implements WorldManager, Listener {
}
@Override
public void addPointToCrop(@NotNull Crop crop, @NotNull SimpleLocation location, int points) {
public void addPointToCrop(@NotNull Crop crop, int points, @NotNull SimpleLocation location) {
CWorld cWorld = loadedWorlds.get(location.getWorldName());
if (cWorld == null) {
LogUtils.warn("Unsupported operation: Adding point to crop in unloaded world " + location);