4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.bukkit.event.player;
21 |
22 | import org.bukkit.entity.Player;
23 | import org.bukkit.event.Event;
24 | import org.bukkit.event.HandlerList;
25 |
26 | import static com.google.common.base.Preconditions.checkNotNull;
27 |
28 | /**
29 | * This event is an internal event. We do not recommend handling or throwing
30 | * this event or its subclasses as the interface is highly subject to change.
31 | *
32 | * Posted when a player has to be processed, either because a world has been
33 | * loaded, the server has started, or WorldGuard has been reloaded.
34 | */
35 | public class ProcessPlayerEvent extends Event {
36 |
37 | private static final HandlerList handlers = new HandlerList();
38 |
39 | private final Player player;
40 |
41 | public ProcessPlayerEvent(Player player) {
42 | checkNotNull(player);
43 | this.player = player;
44 | }
45 |
46 | public Player getPlayer() {
47 | return player;
48 | }
49 |
50 | @Override
51 | public HandlerList getHandlers() {
52 | return handlers;
53 | }
54 |
55 | public static HandlerList getHandlerList() {
56 | return handlers;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/worldguard-core/src/main/java/com/sk89q/worldguard/blacklist/action/KickAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.blacklist.action;
21 |
22 | import com.sk89q.worldguard.blacklist.BlacklistEntry;
23 | import com.sk89q.worldguard.blacklist.event.BlacklistEvent;
24 |
25 | import static com.google.common.base.Preconditions.checkNotNull;
26 |
27 | public class KickAction implements Action {
28 |
29 | private final BlacklistEntry entry;
30 |
31 | public KickAction(BlacklistEntry entry) {
32 | checkNotNull(entry);
33 | this.entry = entry;
34 | }
35 |
36 | @Override
37 | public ActionResult apply(BlacklistEvent event, boolean silent, boolean repeating, boolean forceRepeat) {
38 | if (silent) {
39 | return ActionResult.INHERIT;
40 | }
41 |
42 | if (event.getPlayer() != null) {
43 | String message = entry.getMessage();
44 |
45 | if (message != null) {
46 | event.getPlayer().kick(String.format(message, event.getTarget().getFriendlyName()));
47 | } else {
48 | event.getPlayer().kick("You can't " + event.getDescription() + " " + event.getTarget().getFriendlyName());
49 | }
50 | }
51 |
52 | return ActionResult.INHERIT;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/protection/events/flags/FlagContextCreateEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.bukkit.protection.events.flags;
21 |
22 | import com.sk89q.worldguard.protection.flags.FlagContext.FlagContextBuilder;
23 | import org.bukkit.event.Event;
24 | import org.bukkit.event.HandlerList;
25 |
26 | public class FlagContextCreateEvent extends Event {
27 |
28 | private FlagContextBuilder builder;
29 |
30 | public FlagContextCreateEvent(FlagContextBuilder builder) {
31 | this.builder = builder;
32 | }
33 |
34 | /**
35 | * Add an object to the flag context with the given key. Keys must be unique.
36 | *
37 | * @param key a unique string to identify the object
38 | * @param value the object to store in the context
39 | * @return true if added successfully, false if the key was already used
40 | */
41 | public boolean addObject(String key, Object value) {
42 | return builder.tryAddToMap(key, value);
43 | }
44 |
45 | private static final HandlerList handlers = new HandlerList();
46 |
47 | @Override
48 | public HandlerList getHandlers() {
49 | return handlers;
50 | }
51 |
52 | public static HandlerList getHandlerList() {
53 | return handlers;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/worldguard-core/src/main/java/com/sk89q/worldguard/blacklist/action/BanAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.blacklist.action;
21 |
22 | import com.sk89q.worldguard.blacklist.BlacklistEntry;
23 | import com.sk89q.worldguard.blacklist.event.BlacklistEvent;
24 |
25 | import static com.google.common.base.Preconditions.checkNotNull;
26 |
27 | public class BanAction implements Action {
28 |
29 | private final BlacklistEntry entry;
30 |
31 | public BanAction(BlacklistEntry entry) {
32 | checkNotNull(entry);
33 | this.entry = entry;
34 | }
35 |
36 | @Override
37 | public ActionResult apply(BlacklistEvent event, boolean silent, boolean repeating, boolean forceRepeat) {
38 | if (silent) {
39 | return ActionResult.INHERIT;
40 | }
41 |
42 | if (event.getPlayer() != null) {
43 | String message = entry.getMessage();
44 |
45 | if (message != null) {
46 | event.getPlayer().ban("Banned: " + String.format(message, event.getTarget().getFriendlyName()));
47 | } else {
48 | event.getPlayer().ban("Banned: You can't " + event.getDescription() + " " + event.getTarget().getFriendlyName());
49 | }
50 | }
51 |
52 | return ActionResult.INHERIT;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/worldguard-core/src/main/java/com/sk89q/worldguard/protection/association/RegionOverlapAssociation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.protection.association;
21 |
22 | import com.sk89q.worldguard.protection.regions.ProtectedRegion;
23 |
24 | import javax.annotation.Nonnull;
25 | import java.util.Set;
26 |
27 | /**
28 | * Determines that the association to a region is {@code OWNER} if the input
29 | * region is in a set of source regions.
30 | */
31 | public class RegionOverlapAssociation extends AbstractRegionOverlapAssociation {
32 |
33 | /**
34 | * Create a new instance.
35 | *
36 | * @param source set of regions that input regions must be contained within
37 | */
38 | public RegionOverlapAssociation(@Nonnull Set source) {
39 | this(source, false);
40 | }
41 |
42 | /**
43 | * Create a new instance.
44 | *
45 | * @param source set of regions that input regions must be contained within
46 | * @param useMaxPriorityAssociation whether to use the max priority from regions to determine association
47 | */
48 | public RegionOverlapAssociation(@Nonnull Set source, boolean useMaxPriorityAssociation) {
49 | super(source, useMaxPriorityAssociation);
50 | calcMaxPriority();
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/NumberFlag.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.protection.flags;
21 |
22 | import static com.google.common.base.Preconditions.checkNotNull;
23 |
24 | import com.google.common.annotations.Beta;
25 |
26 | /**
27 | * Stores an Number.
28 | */
29 | public abstract class NumberFlag extends Flag {
30 |
31 | private static final Number[] EMPTY_NUMBER_ARRAY = new Number[0];
32 | private Number[] suggestions = EMPTY_NUMBER_ARRAY;
33 |
34 | protected NumberFlag(String name, RegionGroup defaultGroup) {
35 | super(name, defaultGroup);
36 | }
37 |
38 | protected NumberFlag(String name) {
39 | super(name);
40 | }
41 |
42 | /**
43 | * Not recommended for public use. Will likely be moved when migrating to piston for commands.
44 | * @param values suggested values
45 | */
46 | @Beta
47 | public void setSuggestedValues(Number[] values) {
48 | this.suggestions = checkNotNull(values);
49 | }
50 |
51 | /**
52 | * Not recommended for public use. Will likely be moved when migrating to piston for commands.
53 | * @return suggested values
54 | */
55 | @Beta
56 | public Number[] getSuggestedValues() {
57 | return suggestions;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/worldguard-core/src/main/java/com/sk89q/worldguard/protection/managers/storage/sql/DomainTableCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.protection.managers.storage.sql;
21 |
22 | import com.sk89q.worldguard.protection.managers.storage.sql.TableCache.GroupNameCache;
23 | import com.sk89q.worldguard.protection.managers.storage.sql.TableCache.UserNameCache;
24 | import com.sk89q.worldguard.protection.managers.storage.sql.TableCache.UserUuidCache;
25 | import com.sk89q.worldguard.util.sql.DataSourceConfig;
26 |
27 | import java.sql.Connection;
28 |
29 | class DomainTableCache {
30 |
31 | private final UserNameCache userNameCache;
32 | private final UserUuidCache userUuidCache;
33 | private final GroupNameCache groupNameCache;
34 |
35 | DomainTableCache(DataSourceConfig config, Connection conn) {
36 | userNameCache = new UserNameCache(config, conn);
37 | userUuidCache = new UserUuidCache(config, conn);
38 | groupNameCache = new GroupNameCache(config, conn);
39 | }
40 |
41 | public UserNameCache getUserNameCache() {
42 | return userNameCache;
43 | }
44 |
45 | public UserUuidCache getUserUuidCache() {
46 | return userUuidCache;
47 | }
48 |
49 | public GroupNameCache getGroupNameCache() {
50 | return groupNameCache;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/worldguard-core/src/main/java/com/sk89q/worldguard/util/collect/LongHashTable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.util.collect;
21 |
22 | import java.util.ArrayList;
23 |
24 | public class LongHashTable extends LongBaseHashTable {
25 |
26 | public void put(int msw, int lsw, V value) {
27 | put(toLong(msw, lsw), value);
28 | }
29 |
30 | public V get(int msw, int lsw) {
31 | return get(toLong(msw, lsw));
32 | }
33 |
34 | public synchronized void put(long key, V value) {
35 | put(new Entry(key, value));
36 | }
37 |
38 | @SuppressWarnings("unchecked")
39 | public synchronized V get(long key) {
40 | Entry entry = ((Entry) getEntry(key));
41 | return entry != null ? entry.value : null;
42 | }
43 |
44 | @SuppressWarnings("unchecked")
45 | public synchronized ArrayList values() {
46 | ArrayList ret = new ArrayList<>();
47 |
48 | ArrayList entries = entries();
49 |
50 | for (EntryBase entry : entries) {
51 | ret.add(((Entry) entry).value);
52 | }
53 | return ret;
54 | }
55 |
56 | private class Entry extends EntryBase {
57 | V value;
58 |
59 | Entry(long k, V v) {
60 | super(k);
61 | this.value = v;
62 | }
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/WaterBreathing.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.session.handler;
21 |
22 | import com.sk89q.worldguard.LocalPlayer;
23 | import com.sk89q.worldguard.session.Session;
24 |
25 | public class WaterBreathing extends Handler {
26 |
27 | public static final Factory FACTORY = new Factory();
28 | public static class Factory extends Handler.Factory {
29 | @Override
30 | public WaterBreathing create(Session session) {
31 | return new WaterBreathing(session);
32 | }
33 | }
34 |
35 | public boolean waterBreathing;
36 |
37 | public WaterBreathing(Session session) {
38 | super(session);
39 | }
40 |
41 | public boolean hasWaterBreathing() {
42 | return waterBreathing;
43 | }
44 |
45 | public void setWaterBreathing(boolean waterBreathing) {
46 | this.waterBreathing = waterBreathing;
47 | }
48 |
49 | public static boolean set(LocalPlayer player, Session session, boolean value) {
50 | WaterBreathing waterBreathing = session.getHandler(WaterBreathing.class);
51 | if (waterBreathing != null) {
52 | waterBreathing.setWaterBreathing(value);
53 | return true;
54 | } else{
55 | return false;
56 | }
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/event/entity/UseEntityEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.bukkit.event.entity;
21 |
22 | import com.sk89q.worldguard.bukkit.cause.Cause;
23 | import org.bukkit.entity.Entity;
24 | import org.bukkit.event.Event;
25 | import org.bukkit.event.HandlerList;
26 |
27 | import javax.annotation.Nonnull;
28 | import javax.annotation.Nullable;
29 |
30 | import static com.google.common.base.Preconditions.checkNotNull;
31 |
32 | /**
33 | * This event is an internal event. We do not recommend handling or throwing
34 | * this event or its subclasses as the interface is highly subject to change.
35 | *
36 | * Thrown when an entity is used.
37 | */
38 | public class UseEntityEvent extends AbstractEntityEvent {
39 |
40 | private static final HandlerList handlers = new HandlerList();
41 |
42 | public UseEntityEvent(@Nullable Event originalEvent, Cause cause, Entity target) {
43 | super(originalEvent, cause, checkNotNull(target));
44 | }
45 |
46 | @Override
47 | @Nonnull
48 | public Entity getEntity() {
49 | return super.getEntity();
50 | }
51 |
52 | @Override
53 | public HandlerList getHandlers() {
54 | return handlers;
55 | }
56 |
57 | public static HandlerList getHandlerList() {
58 | return handlers;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/event/entity/DamageEntityEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.bukkit.event.entity;
21 |
22 | import com.sk89q.worldguard.bukkit.cause.Cause;
23 | import org.bukkit.entity.Entity;
24 | import org.bukkit.event.Event;
25 | import org.bukkit.event.HandlerList;
26 |
27 | import javax.annotation.Nonnull;
28 | import javax.annotation.Nullable;
29 |
30 | import static com.google.common.base.Preconditions.checkNotNull;
31 |
32 | /**
33 | * This event is an internal event. We do not recommend handling or throwing
34 | * this event or its subclasses as the interface is highly subject to change.
35 | *
36 | * Thrown when an entity is damaged.
37 | */
38 | public class DamageEntityEvent extends AbstractEntityEvent {
39 |
40 | private static final HandlerList handlers = new HandlerList();
41 |
42 | public DamageEntityEvent(@Nullable Event originalEvent, Cause cause, Entity target) {
43 | super(originalEvent, cause, checkNotNull(target));
44 | }
45 |
46 | @Override
47 | @Nonnull
48 | public Entity getEntity() {
49 | return super.getEntity();
50 | }
51 |
52 | @Override
53 | public HandlerList getHandlers() {
54 | return handlers;
55 | }
56 |
57 | public static HandlerList getHandlerList() {
58 | return handlers;
59 | }
60 |
61 | }
--------------------------------------------------------------------------------
/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/event/entity/DestroyEntityEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.bukkit.event.entity;
21 |
22 | import com.sk89q.worldguard.bukkit.cause.Cause;
23 | import org.bukkit.entity.Entity;
24 | import org.bukkit.event.Event;
25 | import org.bukkit.event.HandlerList;
26 |
27 | import javax.annotation.Nonnull;
28 | import javax.annotation.Nullable;
29 |
30 | import static com.google.common.base.Preconditions.checkNotNull;
31 |
32 | /**
33 | * This event is an internal event. We do not recommend handling or throwing
34 | * this event or its subclasses as the interface is highly subject to change.
35 | *
36 | * Thrown when an entity is removed.
37 | */
38 | public class DestroyEntityEvent extends AbstractEntityEvent {
39 |
40 | private static final HandlerList handlers = new HandlerList();
41 |
42 | public DestroyEntityEvent(@Nullable Event originalEvent, Cause cause, Entity target) {
43 | super(originalEvent, cause, checkNotNull(target));
44 | }
45 |
46 | @Override
47 | @Nonnull
48 | public Entity getEntity() {
49 | return super.getEntity();
50 | }
51 |
52 | @Override
53 | public HandlerList getHandlers() {
54 | return handlers;
55 | }
56 |
57 | public static HandlerList getHandlerList() {
58 | return handlers;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/RegionGroup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.protection.flags;
21 |
22 | import com.sk89q.worldguard.domains.Association;
23 |
24 | import java.util.Arrays;
25 | import java.util.EnumSet;
26 | import java.util.Set;
27 |
28 | import static com.google.common.base.Preconditions.checkNotNull;
29 |
30 | /**
31 | * A grouping of region membership types.
32 | */
33 | public enum RegionGroup {
34 |
35 | MEMBERS(Association.MEMBER, Association.OWNER),
36 | OWNERS(Association.OWNER),
37 | NON_MEMBERS(Association.NON_MEMBER),
38 | NON_OWNERS(Association.MEMBER, Association.NON_MEMBER),
39 | ALL(Association.OWNER, Association.MEMBER, Association.NON_MEMBER),
40 | NONE();
41 |
42 | private final Set contained;
43 |
44 | RegionGroup(Association... association) {
45 | this.contained = association.length > 0 ? EnumSet.copyOf(Arrays.asList(association)) : EnumSet.noneOf(Association.class);
46 | }
47 |
48 | /**
49 | * Test whether this group contains the given membership status.
50 | *
51 | * @param association membership status
52 | * @return true if contained
53 | */
54 | public boolean contains(Association association) {
55 | checkNotNull(association);
56 | return contained.contains(association);
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/worldguard-core/src/main/java/com/sk89q/worldguard/blacklist/action/TellAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.blacklist.action;
21 |
22 | import com.sk89q.worldguard.blacklist.BlacklistEntry;
23 | import com.sk89q.worldguard.blacklist.event.BlacklistEvent;
24 |
25 | import static com.google.common.base.Preconditions.checkNotNull;
26 |
27 | public class TellAction extends RepeatGuardedAction {
28 |
29 | private final BlacklistEntry entry;
30 |
31 | public TellAction(BlacklistEntry entry) {
32 | checkNotNull(entry);
33 | this.entry = entry;
34 | }
35 |
36 | @Override
37 | protected ActionResult applyNonRepeated(BlacklistEvent event, boolean silent) {
38 | if (silent) {
39 | return ActionResult.INHERIT;
40 | }
41 |
42 | String message = entry.getMessage();
43 |
44 | if (event.getPlayer() != null) {
45 | if (message != null) {
46 | message = message.replaceAll("(?!<\\\\)\\\\n", "\n").replaceAll("\\\\\\\\n", "\\n");
47 | event.getPlayer().print(String.format(message, event.getTarget().getFriendlyName()));
48 | } else {
49 | event.getPlayer().printError("You're not allowed to " + event.getDescription() + " " + event.getTarget().getFriendlyName() + ".");
50 | }
51 | }
52 |
53 | return ActionResult.INHERIT;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/worldguard-core/src/main/java/com/sk89q/worldguard/protection/managers/storage/MemoryRegionDatabase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.protection.managers.storage;
21 |
22 | import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
23 | import com.sk89q.worldguard.protection.managers.RegionDifference;
24 | import com.sk89q.worldguard.protection.regions.ProtectedRegion;
25 |
26 | import java.util.Collections;
27 | import java.util.HashSet;
28 | import java.util.Set;
29 |
30 | /**
31 | * A region database that saves the memory to an in-memory {@link HashSet}.
32 | *
33 | * This implementation is thread-safe. Difference saves
34 | * are not supported.
35 | */
36 | public class MemoryRegionDatabase implements RegionDatabase {
37 |
38 | private Set regions = Collections.emptySet();
39 |
40 | @Override
41 | public String getName() {
42 | return "MEMORY";
43 | }
44 |
45 | @Override
46 | public Set loadAll(FlagRegistry flagRegistry) {
47 | return regions;
48 | }
49 |
50 | @Override
51 | public void saveAll(Set regions) {
52 | this.regions = Collections.unmodifiableSet(new HashSet<>(regions));
53 | }
54 |
55 | @Override
56 | public void saveChanges(RegionDifference difference) throws DifferenceSaveException {
57 | throw new DifferenceSaveException();
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/UUIDFlag.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.protection.flags;
21 |
22 | import javax.annotation.Nullable;
23 | import java.util.UUID;
24 |
25 | public class UUIDFlag extends Flag {
26 |
27 | public UUIDFlag(String name, @Nullable RegionGroup defaultGroup) {
28 | super(name, defaultGroup);
29 | }
30 |
31 | public UUIDFlag(String name) {
32 | super(name);
33 | }
34 |
35 | @Override
36 | public UUID parseInput(FlagContext context) throws InvalidFlagFormatException {
37 | String input = context.getUserInput();
38 | if ("self".equalsIgnoreCase(input)) {
39 | return context.getSender().getUniqueId();
40 | }
41 | try {
42 | return UUID.fromString(input);
43 | } catch (IllegalArgumentException e) {
44 | throw new InvalidFlagFormatException("Not a valid uuid: " + input);
45 | }
46 | }
47 |
48 | @Override
49 | public UUID unmarshal(@Nullable Object o) {
50 | if (!(o instanceof String)) {
51 | return null;
52 | }
53 | try {
54 | return UUID.fromString((String)o);
55 | } catch (IllegalArgumentException e) {
56 | return null;
57 | }
58 | }
59 |
60 | @Override
61 | public Object marshal(UUID o) {
62 | return o.toString();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/chest/BukkitSignChestProtection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WorldGuard, a suite of tools for Minecraft
3 | * Copyright (C) sk89q
4 | * Copyright (C) WorldGuard team and contributors
5 | *
6 | * This program is free software: you can redistribute it and/or modify it
7 | * under the terms of the GNU Lesser General Public License as published by the
8 | * Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 | * for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | package com.sk89q.worldguard.bukkit.chest;
21 |
22 | import com.sk89q.worldedit.bukkit.BukkitAdapter;
23 | import com.sk89q.worldedit.util.Location;
24 | import com.sk89q.worldguard.LocalPlayer;
25 | import com.sk89q.worldguard.chest.SignChestProtection;
26 | import org.bukkit.block.BlockState;
27 | import org.bukkit.block.Sign;
28 |
29 | public class BukkitSignChestProtection extends SignChestProtection {
30 |
31 | private Boolean isProtectedSign(Sign sign, LocalPlayer player) {
32 | if (sign.getLine(0).equalsIgnoreCase("[Lock]")) {
33 | if (player == null) { // No player, no access
34 | return true;
35 | }
36 |
37 | String name = player.getName();
38 | return !name.equalsIgnoreCase(sign.getLine(1).trim())
39 | && !name.equalsIgnoreCase(sign.getLine(2).trim())
40 | && !name.equalsIgnoreCase(sign.getLine(3).trim());
41 | }
42 |
43 | return null;
44 | }
45 |
46 | @Override
47 | public Boolean isProtectedSign(Location block, LocalPlayer player) {
48 | BlockState state = BukkitAdapter.adapt(block).getBlock().getState();
49 | if (!(state instanceof Sign)) {
50 | return null;
51 | }
52 | return isProtectedSign((Sign) state, player);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------