use of org.spongepowered.api.item.ItemType in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onBlockPlace.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockPlace(ChangeBlockEvent.Place e, @Root Player p) {
RedProtect.get().logger.debug("default", "RPGlobalListener - Is ChangeBlockEvent event! Cancelled? " + e.isCancelled());
BlockSnapshot b = e.getTransactions().get(0).getFinal();
ItemType item = ItemTypes.NONE;
if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
item = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
} else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
item = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
}
Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getOriginal().getLocation().get());
if (r != null) {
return;
}
if (!RPUtil.canBuildNear(p, b.getLocation().get())) {
e.setCancelled(true);
return;
}
if (item.getName().contains("minecart") || item.getName().contains("boat")) {
if (!RedProtect.get().cfgs.getGlobalFlag(p.getWorld().getName(), "use-minecart") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
RedProtect.get().logger.debug("default", "RPGlobalListener - Can't place minecart/boat!");
}
} else {
if (!bypassBuild(p, b, 1)) {
e.setCancelled(true);
RedProtect.get().logger.debug("default", "RPGlobalListener - Can't Build!");
}
}
}
use of org.spongepowered.api.item.ItemType in project RedProtect by FabioZumbi12.
the class RPMine18 method onAttemptInteractAS.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onAttemptInteractAS(InteractEntityEvent e, @First Player p) {
Entity ent = e.getTargetEntity();
Location<World> l = ent.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r == null) {
// global flags
if (ent.getType().equals(EntityTypes.ARMOR_STAND)) {
if (!RedProtect.get().cfgs.getGlobalFlag(l.getExtent().getName(), "build")) {
e.setCancelled(true);
return;
}
}
return;
}
ItemType itemInHand = ItemTypes.NONE;
if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
itemInHand = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
} else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
itemInHand = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
}
if (!itemInHand.equals(ItemTypes.NONE) && itemInHand.getType().equals(ItemTypes.ARMOR_STAND)) {
if (r != null && !r.canBuild(p)) {
e.setCancelled(true);
RPLang.sendMessage(p, "blocklistener.region.cantbuild");
return;
}
}
// TODO Not working!
if (ent.getType().equals(EntityTypes.ARMOR_STAND)) {
if (r != null && !r.canBuild(p)) {
if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantedit");
e.setCancelled(true);
}
}
}
}
use of org.spongepowered.api.item.ItemType in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onInteractBlock.
// listen all
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
RedProtect.get().logger.debug("player", "RPPlayerListener - InteractBlockEvent canceled? " + event.isCancelled());
BlockSnapshot b = event.getTargetBlock();
BlockState bstate = b.getState();
Location<World> l = null;
if (!b.getState().getType().equals(BlockTypes.AIR)) {
l = b.getLocation().get();
RedProtect.get().logger.debug("player", "RPPlayerListener - Is InteractBlockEvent event. The block is " + bstate.getType().getName());
} else {
l = p.getLocation();
}
Region r = RedProtect.get().rm.getTopRegion(l);
ItemType itemInHand = ItemTypes.NONE;
ItemStack stack = ItemStack.of(ItemTypes.NONE, 1);
if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
stack = p.getItemInHand(HandTypes.MAIN_HAND).get();
itemInHand = stack.getItem();
if (RPUtil.removeGuiItem(stack)) {
p.setItemInHand(HandTypes.MAIN_HAND, ItemStack.of(ItemTypes.NONE, 1));
event.setCancelled(true);
}
} else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
stack = p.getItemInHand(HandTypes.OFF_HAND).get();
itemInHand = stack.getItem();
if (RPUtil.removeGuiItem(stack)) {
p.setItemInHand(HandTypes.OFF_HAND, ItemStack.of(ItemTypes.NONE, 1));
event.setCancelled(true);
}
}
if (itemInHand.getId().equalsIgnoreCase(RedProtect.get().cfgs.getString("wands.infoWandID"))) {
r = RedProtect.get().rm.getTopRegion(l);
if (RedProtect.get().ph.hasUserPerm(p, "RedProtect.get().infowand")) {
if (r == null) {
RPLang.sendMessage(p, "playerlistener.noregion.atblock");
} else if (r.canBuild(p)) {
p.sendMessage(RPUtil.toText(RPLang.get("general.color") + "--------------- [&e" + r.getName() + RPLang.get("general.color") + "] ---------------"));
p.sendMessage(r.info());
p.sendMessage(RPUtil.toText(RPLang.get("general.color") + "-----------------------------------------"));
} else {
p.sendMessage(RPUtil.toText(RPLang.get("playerlistener.region.entered").replace("{region}", r.getName()).replace("{leaders}", RPUtil.UUIDtoPlayer(r.getLeadersDesc()))));
}
event.setCancelled(true);
return;
}
}
// start player checks
if (r == null) {
if (b != null && (bstate instanceof Container || RedProtect.get().cfgs.getStringList("private.allowed-blocks").contains(bstate.getType().getName()))) {
Boolean out = RedProtect.get().cfgs.getBool("private.allow-outside");
if (out && !cont.canOpen(b, p)) {
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantopen");
event.setCancelled(true);
} else {
int x = b.getLocation().get().getBlockX();
int y = b.getLocation().get().getBlockY();
int z = b.getLocation().get().getBlockZ();
RPLang.sendMessage(p, RPLang.get("playerlistener.region.opened").replace("{region}", "X:" + x + " Y:" + y + " Z:" + z));
}
}
}
} else {
// if (r != null) && (b != null) >>
if (b != null) {
if (bstate.getType().equals(BlockTypes.DRAGON_EGG) || bstate.getType().equals(BlockTypes.BED) || bstate.getType().equals(BlockTypes.NOTEBLOCK) || bstate.getType().getName().contains("repeater") || bstate.getType().getName().contains("comparator")) {
if (!r.canBuild(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
}
} else if ((b.getState() instanceof Carrier) || RedProtect.get().cfgs.getStringList("private.allowed-blocks").contains(bstate.getType().getName())) {
if ((r.canChest(p) && !cont.canOpen(b, p) || (!r.canChest(p) && cont.canOpen(b, p)) || (!r.canChest(p) && !cont.canOpen(b, p)))) {
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantopen");
event.setCancelled(true);
} else {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.opened").replace("{region}", RPUtil.UUIDtoPlayer(r.getLeadersDesc())));
}
}
} else if (bstate.getType().getName().contains("lever")) {
if (!r.canLever(p)) {
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantlever");
event.setCancelled(true);
} else {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.levertoggled").replace("{region}", RPUtil.UUIDtoPlayer(r.getLeadersDesc())));
}
}
} else if (bstate.getType().getName().contains("button")) {
if (!r.canButton(p)) {
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantbutton");
event.setCancelled(true);
} else {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.buttonactivated").replace("{region}", RPUtil.UUIDtoPlayer(r.getLeadersDesc())));
}
}
} else if (RPDoor.isOpenable(b)) {
if (!r.canDoor(p)) /* || (r.canDoor(p) && !cont.canOpen(b, p))*/
{
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantdoor");
event.setCancelled(true);
} else {
RPLang.sendMessage(p, "playerlistener.region.opendoor");
RPDoor.ChangeDoor(b, r);
}
} else {
RPDoor.ChangeDoor(b, r);
}
} else if (bstate.getType().getName().contains("rail")) {
if (!r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantplace");
event.setCancelled(true);
}
} else if (bstate.getType().getName().contains("sign") && !r.canSign(p)) {
if (b.get(Keys.SIGN_LINES).isPresent()) {
List<Text> sign = b.get(Keys.SIGN_LINES).get();
for (String tag : RedProtect.get().cfgs.getStringList("region-settings.allow-sign-interact-tags")) {
// check first rule
if (tag.equalsIgnoreCase(sign.get(0).toPlain())) {
return;
}
// check if tag is leaders or members names
if (tag.equalsIgnoreCase("{membername}")) {
for (String leader : r.getLeaders()) {
if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(leader))) {
return;
}
}
for (String member : r.getMembers()) {
if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(member))) {
return;
}
}
for (String admin : r.getAdmins()) {
if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(admin))) {
return;
}
}
}
// check if tag is player name
if (tag.equalsIgnoreCase("{playername}")) {
if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(p.getName()))) {
return;
}
}
}
}
RPLang.sendMessage(p, "playerlistener.region.cantinteract.signs");
event.setCancelled(true);
} else if ((itemInHand.equals(ItemTypes.FLINT_AND_STEEL) || itemInHand.equals(ItemTypes.WATER_BUCKET) || itemInHand.equals(ItemTypes.BUCKET) || itemInHand.equals(ItemTypes.LAVA_BUCKET) || itemInHand.equals(ItemTypes.ITEM_FRAME) || itemInHand.equals(ItemTypes.PAINTING)) && !r.canBuild(p)) {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.cantuse"));
event.setCancelled(true);
} else if (!r.allowMod(p) && !RPUtil.isBukkitBlock(bstate)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
}
}
}
}
use of org.spongepowered.api.item.ItemType in project AdamantineShield by Karanum.
the class ContainerLookupResult method readResult.
protected void readResult(ResultSet results) throws SQLException {
while (results.next()) {
Vector3i pos = new Vector3i(results.getInt("x"), results.getInt("y"), results.getInt("z"));
UUID world = UUID.fromString(results.getString("world"));
ActionType type = ActionType.valueCache[results.getByte("type")];
String cause = results.getString("cause");
String data = results.getString("data");
ItemType item = Sponge.getRegistry().getType(ItemType.class, results.getString("AS_Id.value")).get();
int count = results.getByte("count");
int slot = results.getInt("slot");
boolean rolledBack = results.getBoolean("rolled_back");
long timestamp = results.getLong("time");
lines.add(new LookupLine(pos, world, type, cause, data, item, count, slot, rolledBack, timestamp));
}
}
use of org.spongepowered.api.item.ItemType in project core by CubeEngine.
the class MaterialMatcher method buildVariantMap.
private Map<BlockType, Map<String, BlockState>> buildVariantMap() {
Map<BlockType, Map<String, BlockState>> blockStateItemsByType = new HashMap<>();
for (Entry<String, BlockState> entry : blockStateItems.entrySet()) {
BlockType itemType = entry.getValue().getType();
Map<String, BlockState> itemTypes = blockStateItemsByType.computeIfAbsent(itemType, k -> new HashMap<>());
itemTypes.put(entry.getKey(), entry.getValue());
}
Map<BlockType, Map<String, BlockState>> variants = new HashMap<>();
blockStateItemsByType.entrySet().stream().filter(e -> e.getValue().size() != 1).forEach(e -> {
Map<String, Set<String>> variantNames = new HashMap<>();
Map<List<String>, BlockState> fullVariant = new HashMap<>();
for (Entry<String, BlockState> entry : e.getValue().entrySet()) {
String variant = entry.getKey();
variant = variant.substring(variant.indexOf("[") + 1, variant.indexOf("]"));
// multiple variants
String[] split = variant.split(",");
fullVariant.put(Arrays.asList(split), entry.getValue());
for (String variantEntry : split) {
String[] variantEntryPart = variantEntry.split("=");
Set<String> variantValues = variantNames.computeIfAbsent(variantEntryPart[0], k -> new HashSet<>());
variantValues.add(variantEntryPart[1]);
}
}
for (Entry<String, Set<String>> entry : variantNames.entrySet()) {
if (entry.getKey().equals("axis") || entry.getKey().equals("facing") || entry.getKey().equals("half") || entry.getKey().equals("shape") || entry.getKey().equals("open") || entry.getKey().equals("powered") || entry.getKey().equals("stage") || entry.getKey().equals("decayable")) {
Map<List<String>, BlockState> filtered = new HashMap<>();
for (Entry<List<String>, BlockState> offender : fullVariant.entrySet()) {
List<String> key = new ArrayList<>(offender.getKey());
for (String fv : entry.getValue()) {
key.remove(entry.getKey() + "=" + fv);
}
if (!key.isEmpty()) {
filtered.put(key, offender.getValue());
}
}
fullVariant = filtered;
}
if (entry.getValue().size() == 1) {
String singleVariant = entry.getKey() + "=" + entry.getValue().iterator().next();
fullVariant = fullVariant.entrySet().stream().collect(Collectors.toMap(fv -> {
List<String> split = new ArrayList<>(fv.getKey());
split.remove(singleVariant);
return split;
}, Entry::getValue));
}
}
for (Entry<List<String>, BlockState> variant : fullVariant.entrySet()) {
if (variant.getKey().size() > 1) {
System.out.print(e.getKey().getName() + " Has multiple Variants:");
for (String s : variant.getKey()) {
System.out.print(" " + s);
}
System.out.print("\n");
}
}
variants.put(e.getKey(), fullVariant.entrySet().stream().collect(Collectors.toMap(en -> String.join(" ", en.getKey().stream().map(s -> s.split("=")[1]).collect(toList())), Entry::getValue)));
});
/*
for (Entry<ItemType, Map<String, ItemStack>> variant : variants.entrySet())
{
System.out.print(variant.getKey().getName() + ":\n");
for (Entry<String, ItemStack> entry : variant.getValue().entrySet())
{
System.out.print(" " + entry.getKey() + ": " + entry.getValue().getTranslation().get() + "\n");
}
}
*/
return variants;
}
Aggregations